Improve resilience of volume change.
[vuplus_xbmc] / xbmc / cores / omxplayer / OMXPlayerAudio.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #ifndef _OMX_PLAYERAUDIO_H_
22 #define _OMX_PLAYERAUDIO_H_
23
24 #include <deque>
25 #include <sys/types.h>
26
27 #include "utils/StdString.h"
28
29 #include "OMXClock.h"
30 #include "DVDStreamInfo.h"
31 #include "OMXAudio.h"
32 #include "OMXAudioCodecOMX.h"
33 #include "threads/Thread.h"
34
35 #include "DVDDemuxers/DVDDemux.h"
36 #include "DVDMessageQueue.h"
37 #include "utils/BitstreamStats.h"
38 #include "xbmc/linux/DllBCM.h"
39
40 using namespace std;
41
42 class OMXPlayerAudio : public CThread
43 {
44 protected:
45   CDVDMessageQueue      m_messageQueue;
46   CDVDMessageQueue      &m_messageParent;
47
48   CDVDStreamInfo            m_hints_current;
49   CDVDStreamInfo            m_hints;
50   OMXClock                  *m_av_clock;
51   COMXAudio                 m_omxAudio;
52   std::string               m_codec_name;
53   bool                      m_use_passthrough;
54   bool                      m_passthrough;
55   bool                      m_use_hw_decode;
56   bool                      m_hw_decode;
57   AEAudioFormat             m_format;
58   CAEChannelInfo            m_channelLayout;
59   COMXAudioCodecOMX         *m_pAudioCodec;
60   int                       m_speed;
61   bool                      m_silence;
62   double                    m_audioClock;
63
64   bool                      m_stalled;
65   bool                      m_started;
66
67   BitstreamStats            m_audioStats;
68
69   struct timespec           m_starttime, m_endtime;
70   bool                      m_buffer_empty;
71   bool                      m_flush;
72   int                       m_nChannels;
73   bool                      m_DecoderOpen;
74
75   DllBcmHost                m_DllBcmHost;
76   bool                      m_bad_state;
77
78   virtual void OnStartup();
79   virtual void OnExit();
80   virtual void Process();
81 private:
82 public:
83   OMXPlayerAudio(OMXClock *av_clock, CDVDMessageQueue& parent);
84   ~OMXPlayerAudio();
85   bool OpenStream(CDVDStreamInfo &hints);
86   void OpenStream(CDVDStreamInfo &hints, COMXAudioCodecOMX *codec);
87   void SendMessage(CDVDMsg* pMsg, int priority = 0) { m_messageQueue.Put(pMsg, priority); }
88   bool AcceptsData() const                          { return !m_messageQueue.IsFull(); }
89   bool HasData() const                              { return m_messageQueue.GetDataSize() > 0; }
90   bool IsInited() const                             { return m_messageQueue.IsInited(); }
91   int  GetLevel() const                             { return m_messageQueue.GetLevel(); }
92   bool IsStalled()                                  { return m_stalled;  }
93   bool IsEOS();
94   void WaitForBuffers();
95   bool CloseStream(bool bWaitForBuffers);
96   bool CodecChange();
97   bool Decode(DemuxPacket *pkt, bool bDropPacket);
98   void Flush();
99   bool AddPacket(DemuxPacket *pkt);
100   AEDataFormat GetDataFormat(CDVDStreamInfo hints);
101   bool Passthrough() const;
102   bool OpenDecoder();
103   void CloseDecoder();
104   double GetDelay();
105   double GetCacheTime();
106   double GetCacheTotal();
107   double GetCurrentPts() { return m_audioClock; };
108   void WaitCompletion();
109   void SubmitEOS();
110   void  RegisterAudioCallback(IAudioCallback* pCallback);
111   void  UnRegisterAudioCallback();
112   bool SetCurrentVolume(float fVolume);
113   void SetSpeed(int iSpeed);
114   int  GetAudioBitrate();
115   std::string GetPlayerInfo();
116
117   bool BadState() { return m_bad_state; }
118 };
119 #endif