Merge pull request #5101 from FernetMenta/ffmpeg-threads
[vuplus_xbmc] / xbmc / cores / dvdplayer / DVDAudio.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #if (defined HAVE_CONFIG_H) && (!defined TARGET_WINDOWS)
24   #include "config.h"
25 #endif
26 #include "threads/CriticalSection.h"
27 #include "PlatformDefs.h"
28 #include <queue>
29
30 #include "cores/AudioEngine/Utils/AEChannelInfo.h"
31 class IAEStream;
32
33 #include "DllAvCodec.h"
34
35 typedef struct stDVDAudioFrame DVDAudioFrame;
36
37 class CPTSOutputQueue
38 {
39 private:
40   typedef struct {double pts; double timestamp; double duration;} TPTSItem;
41   TPTSItem m_current;
42   std::queue<TPTSItem> m_queue;
43   CCriticalSection m_sync;
44
45 public:
46   CPTSOutputQueue();
47   void Add(double pts, double delay, double duration, double timestamp);
48   void Flush();
49   double Current(double timestamp);
50 };
51
52 class CSingleLock;
53 class IAudioCallback;
54
55 class CDVDAudio
56 {
57 public:
58   CDVDAudio(volatile bool& bStop);
59   ~CDVDAudio();
60
61   void RegisterAudioCallback(IAudioCallback* pCallback);
62   void UnRegisterAudioCallback();
63
64   void SetVolume(float fVolume);
65   void SetDynamicRangeCompression(long drc);
66   float GetCurrentAttenuation();
67   void Pause();
68   void Resume();
69   bool Create(const DVDAudioFrame &audioframe, AVCodecID codec, bool needresampler);
70   bool IsValidFormat(const DVDAudioFrame &audioframe);
71   void Destroy();
72   unsigned int AddPackets(const DVDAudioFrame &audioframe);
73   double GetDelay(); // returns the time it takes to play a packet if we add one at this time
74   double GetPlayingPts();
75   void   SetPlayingPts(double pts);
76   double GetCacheTime();  // returns total amount of data cached in audio output at this time
77   double GetCacheTotal(); // returns total amount the audio device can buffer
78   void Flush();
79   void Finish();
80   void Drain();
81
82   void SetSpeed(int iSpeed);
83   void SetResampleRatio(double ratio);
84
85   IAEStream *m_pAudioStream;
86 protected:
87   CPTSOutputQueue m_time;
88   unsigned int AddPacketsRenderer(unsigned char* data, unsigned int len, CSingleLock &lock);
89   uint8_t*     m_pBuffer; // should be [m_dwPacketSize]
90   unsigned int m_iBufferSize;
91   unsigned int m_dwPacketSize;
92   CCriticalSection m_critSection;
93
94   int m_iBitrate;
95   int m_iBitsPerSample;
96   double m_SecondsPerByte;
97   bool m_bPassthrough;
98   CAEChannelInfo m_channelLayout;
99   bool m_bPaused;
100
101   volatile bool& m_bStop;
102   IAudioCallback* m_pAudioCallback; //the viz audio callback
103   //counter that will go from 0 to m_iSpeed-1 and reset, data will only be output when speedstep is 0
104   //int m_iSpeedStep;
105 };