Merge pull request #4878 from FernetMenta/xfade
[vuplus_xbmc] / xbmc / cores / AudioEngine / Engines / ActiveAE / ActiveAEStream.h
1 #pragma once
2 /*
3  *      Copyright (C) 2010-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "cores/AudioEngine/Interfaces/AEStream.h"
23 #include "cores/AudioEngine/Utils/AEAudioFormat.h"
24 #include "cores/AudioEngine/Utils/AELimiter.h"
25 #include "cores/AudioEngine/Utils/AEConvert.h"
26
27 namespace ActiveAE
28 {
29
30 class CActiveAEStream : public IAEStream
31 {
32 protected:
33   friend class CActiveAE;
34   friend class CEngineStats;
35   CActiveAEStream(AEAudioFormat *format);
36   virtual ~CActiveAEStream();
37   void FadingFinished();
38   void IncFreeBuffers();
39   void DecFreeBuffers();
40   void ResetFreeBuffers();
41   void InitRemapper();
42   void RemapBuffer();
43
44 public:
45   virtual unsigned int GetSpace();
46   virtual unsigned int AddData(void *data, unsigned int size);
47   virtual double GetDelay();
48   virtual bool IsBuffering();
49   virtual double GetCacheTime();
50   virtual double GetCacheTotal();
51
52   virtual void Pause();
53   virtual void Resume();
54   virtual void Drain(bool wait);
55   virtual bool IsDraining();
56   virtual bool IsDrained();
57   virtual void Flush();
58
59   virtual float GetVolume();
60   virtual float GetReplayGain();
61   virtual float GetAmplification();
62   virtual void SetVolume(float volume);
63   virtual void SetReplayGain(float factor);
64   virtual void SetAmplification(float amplify);
65
66   virtual const unsigned int GetFrameSize() const;
67   virtual const unsigned int GetChannelCount() const;
68   
69   virtual const unsigned int GetSampleRate() const ;
70   virtual const unsigned int GetEncodedSampleRate() const;
71   virtual const enum AEDataFormat GetDataFormat() const;
72   
73   virtual double GetResampleRatio();
74   virtual bool SetResampleRatio(double ratio);
75   virtual void RegisterAudioCallback(IAudioCallback* pCallback);
76   virtual void UnRegisterAudioCallback();
77   virtual void FadeVolume(float from, float to, unsigned int time);
78   virtual bool IsFading();
79   virtual void RegisterSlave(IAEStream *stream);
80
81 protected:
82
83   AEAudioFormat m_format;
84   float m_streamVolume;
85   float m_streamRgain;
86   float m_streamAmplify;
87   double m_streamResampleRatio;
88   unsigned int m_streamSpace;
89   bool m_streamDraining;
90   bool m_streamDrained;
91   bool m_streamFading;
92   int m_streamFreeBuffers;
93   bool m_streamIsBuffering;
94   IAEStream *m_streamSlave;
95   CAEConvert::AEConvertToFn m_convertFn;
96   CCriticalSection m_streamLock;
97   uint8_t *m_leftoverBuffer;
98   int m_leftoverBytes;
99   CSampleBuffer *m_currentBuffer;
100   CSoundPacket *m_remapBuffer;
101   CActiveAEResample *m_remapper;
102
103   // only accessed by engine
104   CActiveAEBufferPool *m_inputBuffers;
105   CActiveAEBufferPoolResample *m_resampleBuffers;
106   std::deque<CSampleBuffer*> m_processingSamples;
107   CActiveAEDataProtocol *m_streamPort;
108   CEvent m_inMsgEvent;
109   CCriticalSection *m_statsLock;
110   bool m_drain;
111   bool m_paused;
112   bool m_started;
113   CAELimiter m_limiter;
114   float m_volume;
115   float m_rgain;
116   float m_amplify;
117   float m_bufferedTime;
118   int m_fadingSamples;
119   float m_fadingBase;
120   float m_fadingTarget;
121   int m_fadingTime;
122   bool m_forceResampler;
123 };
124 }
125