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 
21 class MPUBLIC AudioOutput : public VolumeBase, public OutputListeners
22 {
23  Q_DECLARE_TR_FUNCTIONS(AudioOutput)
24 
25  public:
26  class AudioDeviceConfig
27  {
28  public:
29  QString name;
30  QString desc;
33  name(QString()), desc(QString()),
34  settings(AudioOutputSettings(true)) { };
35  AudioDeviceConfig(const QString &name,
36  const QString &desc) :
37  name(name), desc(desc),
38  settings(AudioOutputSettings(true)) { };
39  };
40 
41  typedef QVector<AudioDeviceConfig> ADCVect;
42 
43  static void Cleanup(void);
44  static ADCVect* GetOutputList(void);
45  static AudioDeviceConfig* GetAudioDeviceConfig(
46  QString &name, QString &desc, bool willsuspendpa = false);
47 
48  // opens one of the concrete subclasses
49  static AudioOutput *OpenAudio(
50  const QString &audiodevice, const QString &passthrudevice,
51  AudioFormat format, int channels, int codec, int samplerate,
52  AudioOutputSource source, bool set_initial_vol, bool passthru,
53  int upmixer_startup = 0, AudioOutputSettings *custom = NULL);
54  static AudioOutput *OpenAudio(AudioSettings &settings,
55  bool willsuspendpa = true);
56  static AudioOutput *OpenAudio(
57  const QString &main_device,
58  const QString &passthru_device = QString::null,
59  bool willsuspendpa = true);
60 
63  lastError(QString::null), lastWarn(QString::null), pulsewassuspended(false) {}
64 
65  virtual ~AudioOutput();
66 
67  // reconfigure sound out for new params
68  virtual void Reconfigure(const AudioSettings &settings) = 0;
69 
70  virtual void SetStretchFactor(float factor);
71  virtual float GetStretchFactor(void) const { return 1.0f; }
72  virtual int GetChannels(void) const { return 2; }
73  virtual AudioFormat GetFormat(void) const { return FORMAT_S16; };
74  virtual int GetBytesPerFrame(void) const { return 4; };
75 
76  virtual AudioOutputSettings* GetOutputSettingsCleaned(bool digital = true);
77  virtual AudioOutputSettings* GetOutputSettingsUsers(bool digital = true);
78  virtual bool CanPassthrough(int samplerate, int channels,
79  int codec, int profile) const;
80  virtual bool CanDownmix(void) const { return false; };
81 
82  // dsprate is in 100 * samples/second
83  virtual void SetEffDsp(int dsprate) = 0;
84 
85  virtual void Reset(void) = 0;
86 
87  virtual bool AddFrames(void *buffer, int frames, int64_t timecode) = 0;
101  virtual bool AddData(void *buffer, int len,
102  int64_t timecode, int frames) = 0;
109  virtual bool NeedDecodingBeforePassthrough(void) const { return true; };
116  virtual int64_t LengthLastData(void) const { return -1; };
117 
118  virtual void SetTimecode(int64_t timecode) = 0;
119  virtual bool IsPaused(void) const = 0;
120  virtual void Pause(bool paused) = 0;
121  virtual void PauseUntilBuffered(void) = 0;
122 
123  // Wait for all data to finish playing
124  virtual void Drain(void) = 0;
125 
126  virtual int64_t GetAudiotime(void) = 0;
127 
129  virtual int64_t GetAudioBufferedTime(void) { return 0; }
130 
131  virtual void SetSourceBitrate(int ) { }
132 
133  QString GetError(void) const { return lastError; }
134  QString GetWarning(void) const { return lastWarn; }
135 
136  virtual void GetBufferStatus(uint &fill, uint &total)
137  { fill = total = 0; }
138 
139  // Only really used by the AudioOutputNULL object
140  virtual void bufferOutputData(bool y) = 0;
141  virtual int readOutputData(unsigned char *read_buffer,
142  int max_length) = 0;
143 
144  virtual bool IsUpmixing(void) { return false; }
145  virtual bool ToggleUpmix(void) { return false; }
146  virtual bool CanUpmix(void) { return false; }
147  bool PulseStatus(void) { return pulsewassuspended; }
154  virtual bool CanProcess(AudioFormat fmt) { return fmt == FORMAT_S16; }
160  virtual uint32_t CanProcess(void) { return 1 << FORMAT_S16; }
161 
172  int DecodeAudio(AVCodecContext *ctx,
173  uint8_t *buffer, int &data_size,
174  const AVPacket *pkt);
175 
176  protected:
177  void Error(const QString &msg);
178  void SilentError(const QString &msg);
179  void Warn(const QString &msg);
180  void ClearError(void);
181  void ClearWarning(void);
182 
183  QString lastError;
184  QString lastWarn;
186 };
187 
188 #endif
GLuint buffer
virtual float GetStretchFactor(void) const
Definition: audiooutput.h:71
virtual bool ToggleUpmix(void)
Definition: audiooutput.h:145
AudioOutputSettings settings
Definition: audiooutput.h:31
bool PulseStatus(void)
Definition: audiooutput.h:147
virtual bool CanUpmix(void)
Definition: audiooutput.h:146
GLenum GLsizei len
Q_DECLARE_TR_FUNCTIONS(AudioOutput) public QString desc
Definition: audiooutput.h:23
unsigned int uint
Definition: compat.h:135
bool pulsewassuspended
Definition: audiooutput.h:185
virtual bool CanProcess(AudioFormat fmt)
CanProcess argument: AudioFormat return true if class can handle AudioFormat All AudioOutput derivati...
Definition: audiooutput.h:154
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
QString lastWarn
Definition: audiooutput.h:184
QString lastError
Definition: audiooutput.h:183
GLuint GLfloat GLfloat y
QString GetError(void) const
Definition: audiooutput.h:133
virtual bool NeedDecodingBeforePassthrough(void) const
NeedDecodingBeforePassthrough: returns true if AudioOutput class can determine the length in millisec...
Definition: audiooutput.h:109
VERBOSE_PREAMBLE Most Errors or other very important messages true
Definition: verbosedefs.h:91
AudioDeviceConfig(const QString &name, const QString &desc)
Definition: audiooutput.h:35
virtual int GetChannels(void) const
Definition: audiooutput.h:72
virtual void GetBufferStatus(uint &fill, uint &total)
Definition: audiooutput.h:136
const char * name
Definition: ParseText.cpp:338
virtual void SetSourceBitrate(int)
Definition: audiooutput.h:131
AudioOutputSource
Definition: audiosettings.h:17
virtual bool IsUpmixing(void)
Definition: audiooutput.h:144
virtual int64_t LengthLastData(void) const
LengthLastData: returns the length of the last data added in millisecond.
Definition: audiooutput.h:116
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:160
virtual int GetBytesPerFrame(void) const
Definition: audiooutput.h:74
QString GetWarning(void) const
Definition: audiooutput.h:134
AudioDeviceConfig(void)
Definition: audiooutput.h:32
const char * frames[3]
Definition: element.c:46
virtual bool CanDownmix(void) const
Definition: audiooutput.h:80
virtual AudioFormat GetFormat(void) const
Definition: audiooutput.h:73
virtual int64_t GetAudioBufferedTime(void)
report amount of audio buffered in milliseconds.
Definition: audiooutput.h:129