PageRenderTime 24ms CodeModel.GetById 9ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/cores/dvdplayer/DVDPlayerAudio.h

http://github.com/xbmc/xbmc
C++ Header | 216 lines | 149 code | 42 blank | 25 comment | 2 complexity | c48006c1454ab11d8fa7fd9be4f263f9 MD5 | raw file
  1/*
  2 *      Copyright (C) 2005-2013 Team XBMC
  3 *      http://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#pragma once
 22#include "threads/Thread.h"
 23
 24#include "DVDAudio.h"
 25#include "DVDClock.h"
 26#include "DVDMessageQueue.h"
 27#include "DVDDemuxers/DVDDemuxUtils.h"
 28#include "DVDStreamInfo.h"
 29#include "utils/BitstreamStats.h"
 30
 31#include "cores/AudioEngine/Utils/AEAudioFormat.h"
 32
 33#include <list>
 34#include <queue>
 35
 36class CDVDPlayer;
 37class CDVDAudioCodec;
 38class IAudioCallback;
 39class CDVDAudioCodec;
 40
 41#define DECODE_FLAG_DROP    1
 42#define DECODE_FLAG_RESYNC  2
 43#define DECODE_FLAG_ERROR   4
 44#define DECODE_FLAG_ABORT   8
 45#define DECODE_FLAG_TIMEOUT 16
 46
 47typedef struct stDVDAudioFrame
 48{
 49  uint8_t* data;
 50  double pts;
 51  double duration;
 52  unsigned int size;
 53
 54  int               channel_count;
 55  int               encoded_channel_count;
 56  CAEChannelInfo    channel_layout;
 57  enum AEDataFormat data_format;
 58  int               bits_per_sample;
 59  int               sample_rate;
 60  int               encoded_sample_rate;
 61  bool              passthrough;
 62} DVDAudioFrame;
 63
 64class CPTSInputQueue
 65{
 66private:
 67  typedef std::list<std::pair<int64_t, double> >::iterator IT;
 68  std::list<std::pair<int64_t, double> > m_list;
 69  CCriticalSection m_sync;
 70public:
 71  void   Add(int64_t bytes, double pts);
 72  double Get(int64_t bytes, bool consume);
 73  void   Flush();
 74};
 75
 76class CDVDPlayerAudio : public CThread
 77{
 78public:
 79  CDVDPlayerAudio(CDVDClock* pClock, CDVDMessageQueue& parent);
 80  virtual ~CDVDPlayerAudio();
 81
 82  bool OpenStream(CDVDStreamInfo &hints);
 83  void OpenStream(CDVDStreamInfo &hints, CDVDAudioCodec* codec);
 84  void CloseStream(bool bWaitForBuffers);
 85
 86  void RegisterAudioCallback(IAudioCallback* pCallback) { m_dvdAudio.RegisterAudioCallback(pCallback); }
 87  void UnRegisterAudioCallback()                        { m_dvdAudio.UnRegisterAudioCallback(); }
 88
 89  void SetSpeed(int speed);
 90  void Flush();
 91
 92  // waits until all available data has been rendered
 93  void WaitForBuffers();
 94  bool AcceptsData() const                              { return !m_messageQueue.IsFull(); }
 95  bool HasData() const                                  { return m_messageQueue.GetDataSize() > 0; }
 96  int  GetLevel() const                                 { return m_messageQueue.GetLevel(); }
 97  bool IsInited() const                                 { return m_messageQueue.IsInited(); }
 98  void SendMessage(CDVDMsg* pMsg, int priority = 0)     { m_messageQueue.Put(pMsg, priority); }
 99
100  //! Switch codec if needed. Called when the sample rate gotten from the
101  //! codec changes, in which case we may want to switch passthrough on/off.
102  bool SwitchCodecIfNeeded();
103
104  void SetVolume(float fVolume)                         { m_dvdAudio.SetVolume(fVolume); }
105  void SetDynamicRangeCompression(long drc)             { m_dvdAudio.SetDynamicRangeCompression(drc); }
106  float GetCurrentAttenuation()                         { return m_dvdAudio.GetCurrentAttenuation(); }
107
108  std::string GetPlayerInfo();
109  int GetAudioBitrate();
110
111  // holds stream information for current playing stream
112  CDVDStreamInfo m_streaminfo;
113
114  CPTSOutputQueue m_ptsOutput;
115  CPTSInputQueue  m_ptsInput;
116
117  double GetCurrentPts()                            { return m_dvdAudio.GetPlayingPts(); }
118
119  bool IsStalled()                                  { return m_stalled;  }
120  bool IsPassthrough() const;
121protected:
122
123  virtual void OnStartup();
124  virtual void OnExit();
125  virtual void Process();
126
127  int DecodeFrame(DVDAudioFrame &audioframe, bool bDropPacket);
128
129  void UpdatePlayerInfo();
130
131  CDVDMessageQueue m_messageQueue;
132  CDVDMessageQueue& m_messageParent;
133
134  double m_audioClock;
135
136  // data for audio decoding
137  struct PacketStatus
138  {
139    PacketStatus()
140    {
141        msg = NULL;
142        Release();
143    }
144
145   ~PacketStatus()
146    {
147        Release();
148    }
149
150    CDVDMsgDemuxerPacket*  msg;
151    uint8_t*               data;
152    int                    size;
153    double                 dts;
154
155    void Attach(CDVDMsgDemuxerPacket* msg2)
156    {
157      if(msg) msg->Release();
158      msg = msg2;
159      msg->Acquire();
160      DemuxPacket* p = msg->GetPacket();
161      data = p->pData;
162      size = p->iSize;
163      dts = p->dts;
164
165    }
166    void Release()
167    {
168      if(msg) msg->Release();
169      msg  = NULL;
170      data = NULL;
171      size = 0;
172      dts  = DVD_NOPTS_VALUE;
173    }
174  } m_decode;
175
176  CDVDAudio m_dvdAudio; // audio output device
177  CDVDClock* m_pClock; // dvd master clock
178  CDVDAudioCodec* m_pAudioCodec; // audio codec
179  BitstreamStats m_audioStats;
180
181  int     m_speed;
182  double  m_droptime;
183  bool    m_stalled;
184  bool    m_started;
185  double  m_duration; // last packets duration
186  bool    m_silence;
187
188  bool OutputPacket(DVDAudioFrame &audioframe);
189
190  //SYNC_DISCON, SYNC_SKIPDUP, SYNC_RESAMPLE
191  int    m_synctype;
192  int    m_setsynctype;
193  int    m_prevsynctype; //so we can print to the log
194
195  double m_error;    //last average error
196
197  int64_t m_errortime; //timestamp of last time we measured
198  int64_t m_freq;
199
200  void   SetSyncType(bool passthrough);
201  void   HandleSyncError(double duration);
202  double m_errorbuff; //place to store average errors
203  int    m_errorcount;//number of errors stored
204  bool   m_syncclock;
205
206  double m_integral; //integral correction for resampler
207  int    m_skipdupcount; //counter for skip/duplicate synctype
208  bool   m_prevskipped;
209  double m_maxspeedadjust;
210  double m_resampleratio; //resample ratio when using SYNC_RESAMPLE, used for the codec info
211
212
213  CCriticalSection m_info_section;
214  std::string      m_info;
215};
216