MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
audiooutput.h
Go to the documentation of this file.
1 #ifndef AUDIOOUTPUT
2 #define AUDIOOUTPUT
3 
4 // Qt headers
5 #include <QString>
6 #include <QVector>
7 #include <QCoreApplication>
8 
9 // MythTV headers
10 #include "compat.h"
11 #include "audiosettings.h"
12 #include "audiooutputsettings.h"
13 #include "mythcorecontext.h"
14 #include "volumebase.h"
15 #include "output.h"
16 
17 // forward declaration
18 struct AVCodecContext;
19 struct AVPacket;
20 struct AVFrame;
21 
22 class MPUBLIC AudioOutput : public VolumeBase, public OutputListeners
23 {
24  Q_DECLARE_TR_FUNCTIONS(AudioOutput)
25 
26  public:
27  class AudioDeviceConfig
28  {
29  public:
30  QString name;
31  QString desc;
34  name(QString()), desc(QString()),
35  settings(AudioOutputSettings(true)) { };
36  AudioDeviceConfig(const QString &name,
37  const QString &desc) :
38  name(name), desc(desc),
39  settings(AudioOutputSettings(true)) { };
40  };
41 
42  typedef QVector<AudioDeviceConfig> ADCVect;
43 
44  static void Cleanup(void);
45  static ADCVect* GetOutputList(void);
46  static AudioDeviceConfig* GetAudioDeviceConfig(
47  QString &name, QString &desc, bool willsuspendpa = false);
48 
49  // opens one of the concrete subclasses
50  static AudioOutput *OpenAudio(
51  const QString &audiodevice, const QString &passthrudevice,
52  AudioFormat format, int channels, int codec, int samplerate,
53  AudioOutputSource source, bool set_initial_vol, bool passthru,
54  int upmixer_startup = 0, AudioOutputSettings *custom = NULL);
55  static AudioOutput *OpenAudio(AudioSettings &settings,
56  bool willsuspendpa = true);
57  static AudioOutput *OpenAudio(
58  const QString &main_device,
59  const QString &passthru_device = QString::null,
60  bool willsuspendpa = true);
61 
64  lastError(QString::null), lastWarn(QString::null),
65  pulsewassuspended(false), _frame(NULL) {}
66 
67  virtual ~AudioOutput();
68 
69  // reconfigure sound out for new params
70  virtual void Reconfigure(const AudioSettings &settings) = 0;
71 
72  virtual void SetStretchFactor(float factor);
73  virtual float GetStretchFactor(void) const { return 1.0f; }
74  virtual int GetChannels(void) const { return 2; }
75  virtual AudioFormat GetFormat(void) const { return FORMAT_S16; };
76  virtual int GetBytesPerFrame(void) const { return 4; };
77 
78  virtual AudioOutputSettings* GetOutputSettingsCleaned(bool digital = true);
79  virtual AudioOutputSettings* GetOutputSettingsUsers(bool digital = true);
80  virtual bool CanPassthrough(int samplerate, int channels,
81  int codec, int profile) const;
82  virtual bool CanDownmix(void) const { return false; };
83 
84  // dsprate is in 100 * samples/second
85  virtual void SetEffDsp(int dsprate) = 0;
86 
87  virtual void Reset(void) = 0;
88 
89  virtual bool AddFrames(void *buffer, int frames, int64_t timecode) = 0;
103  virtual bool AddData(void *buffer, int len,
104  int64_t timecode, int frames) = 0;
111  virtual bool NeedDecodingBeforePassthrough(void) const { return true; };
118  virtual int64_t LengthLastData(void) const { return -1; };
119 
120  virtual void SetTimecode(int64_t timecode) = 0;
121  virtual bool IsPaused(void) const = 0;
122  virtual void Pause(bool paused) = 0;
123  virtual void PauseUntilBuffered(void) = 0;
124 
125  // Wait for all data to finish playing
126  virtual void Drain(void) = 0;
127 
128  virtual int64_t GetAudiotime(void) = 0;
129 
131  virtual int64_t GetAudioBufferedTime(void) { return 0; }
132 
133  virtual void SetSourceBitrate(int ) { }
134 
135  QString GetError(void) const { return lastError; }
136  QString GetWarning(void) const { return lastWarn; }
137 
138  virtual void GetBufferStatus(uint &fill, uint &total)
139  { fill = total = 0; }
140 
141  // Only really used by the AudioOutputNULL object
142  virtual void bufferOutputData(bool y) = 0;
143  virtual int readOutputData(unsigned char *read_buffer,
144  int max_length) = 0;
145 
146  virtual bool IsUpmixing(void) { return false; }
147  virtual bool ToggleUpmix(void) { return false; }
148  virtual bool CanUpmix(void) { return false; }
149  bool PulseStatus(void) { return pulsewassuspended; }
156  virtual bool CanProcess(AudioFormat fmt) { return fmt == FORMAT_S16; }
162  virtual uint32_t CanProcess(void) { return 1 << FORMAT_S16; }
163 
174  int DecodeAudio(AVCodecContext *ctx,
175  uint8_t *buffer, int &data_size,
176  const AVPacket *pkt);
180  static const int MAX_SIZE_BUFFER = 192000;
181 
182  protected:
183  void Error(const QString &msg);
184  void SilentError(const QString &msg);
185  void Warn(const QString &msg);
186  void ClearError(void);
187  void ClearWarning(void);
188 
189  QString lastError;
190  QString lastWarn;
192  AVFrame *_frame;
193 };
194 
195 #endif
GLuint buffer
virtual float GetStretchFactor(void) const
Definition: audiooutput.h:73
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
virtual bool ToggleUpmix(void)
Definition: audiooutput.h:147
AudioOutputSettings settings
Definition: audiooutput.h:32
bool PulseStatus(void)
Definition: audiooutput.h:149
virtual bool CanUpmix(void)
Definition: audiooutput.h:148
Q_DECLARE_TR_FUNCTIONS(AudioOutput) public QString desc
Definition: audiooutput.h:24
unsigned int uint
Definition: compat.h:139
bool pulsewassuspended
Definition: audiooutput.h:191
virtual bool CanProcess(AudioFormat fmt)
CanProcess argument: AudioFormat return true if class can handle AudioFormat All AudioOutput derivati...
Definition: audiooutput.h:156
QString lastWarn
Definition: audiooutput.h:190
QString lastError
Definition: audiooutput.h:189
GLuint GLfloat GLfloat y
QString GetError(void) const
Definition: audiooutput.h:135
virtual bool NeedDecodingBeforePassthrough(void) const
NeedDecodingBeforePassthrough: returns true if AudioOutput class can determine the length in millisec...
Definition: audiooutput.h:111
AudioDeviceConfig(const QString &name, const QString &desc)
Definition: audiooutput.h:36
virtual int GetChannels(void) const
Definition: audiooutput.h:74
virtual void GetBufferStatus(uint &fill, uint &total)
Definition: audiooutput.h:138
const char * name
Definition: ParseText.cpp:338
virtual void SetSourceBitrate(int)
Definition: audiooutput.h:133
AudioOutputSource
Definition: audiosettings.h:17
VERBOSE_PREAMBLE Most Errors or other very important messages true
Definition: verbosedefs.h:91
virtual bool IsUpmixing(void)
Definition: audiooutput.h:146
AVFrame * _frame
Definition: audiooutput.h:192
virtual int64_t LengthLastData(void) const
LengthLastData: returns the length of the last data added in millisecond.
Definition: audiooutput.h:118
GLint GLenum GLsizei GLint GLenum format
virtual uint32_t CanProcess(void)
CanProcess return bitmask of all AudioFormat handled All AudioOutput derivative must be able to handl...
Definition: audiooutput.h:162
virtual int GetBytesPerFrame(void) const
Definition: audiooutput.h:76
QString GetWarning(void) const
Definition: audiooutput.h:136
AudioDeviceConfig(void)
Definition: audiooutput.h:33
const char * frames[3]
Definition: element.c:46
virtual bool CanDownmix(void) const
Definition: audiooutput.h:82
virtual AudioFormat GetFormat(void) const
Definition: audiooutput.h:75
GLenum GLsizei len
virtual int64_t GetAudioBufferedTime(void)
report amount of audio buffered in milliseconds.
Definition: audiooutput.h:131