MythTV  master
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 
23 {
24  Q_DECLARE_TR_FUNCTIONS(AudioOutput);
25 
26  public:
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(),
60  bool willsuspendpa = true);
61 
64  pulsewassuspended(false), _frame(NULL) {}
65 
66  virtual ~AudioOutput();
67 
68  // reconfigure sound out for new params
69  virtual void Reconfigure(const AudioSettings &settings) = 0;
70 
71  virtual void SetStretchFactor(float factor);
72  virtual float GetStretchFactor(void) const { return 1.0f; }
73  virtual int GetChannels(void) const { return 2; }
74  virtual AudioFormat GetFormat(void) const { return FORMAT_S16; };
75  virtual int GetBytesPerFrame(void) const { return 4; };
76 
77  virtual AudioOutputSettings* GetOutputSettingsCleaned(bool digital = true);
78  virtual AudioOutputSettings* GetOutputSettingsUsers(bool digital = true);
79  virtual bool CanPassthrough(int samplerate, int channels,
80  int codec, int profile) const;
81  virtual bool CanDownmix(void) const { return false; };
82 
83  // dsprate is in 100 * samples/second
84  virtual void SetEffDsp(int dsprate) = 0;
85 
86  virtual void Reset(void) = 0;
87 
98  virtual bool AddFrames(void *buffer, int frames, int64_t timecode) = 0;
99 
111  virtual bool AddData(void *buffer, int len,
112  int64_t timecode, int frames) = 0;
113 
119  virtual bool NeedDecodingBeforePassthrough(void) const { return true; };
120 
126  virtual int64_t LengthLastData(void) const { return -1; };
127 
128  virtual void SetTimecode(int64_t timecode) = 0;
129  virtual bool IsPaused(void) const = 0;
130  virtual void Pause(bool paused) = 0;
131  virtual void PauseUntilBuffered(void) = 0;
132 
133  // Wait for all data to finish playing
134  virtual void Drain(void) = 0;
135 
136  virtual int64_t GetAudiotime(void) = 0;
137 
139  virtual int64_t GetAudioBufferedTime(void) { return 0; }
140 
141  virtual void SetSourceBitrate(int ) { }
142 
143  QString GetError(void) const { return lastError; }
144  QString GetWarning(void) const { return lastWarn; }
145 
146  virtual void GetBufferStatus(uint &fill, uint &total)
147  { fill = total = 0; }
148 
149  // Only really used by the AudioOutputNULL object
150  virtual void bufferOutputData(bool y) = 0;
151  virtual int readOutputData(unsigned char *read_buffer,
152  int max_length) = 0;
153 
154  virtual bool IsUpmixing(void) { return false; }
155  virtual bool ToggleUpmix(void) { return false; }
156  virtual bool CanUpmix(void) { return false; }
157  bool PulseStatus(void) { return pulsewassuspended; }
158 
164  virtual bool CanProcess(AudioFormat fmt) { return fmt == FORMAT_S16; }
165 
170  virtual uint32_t CanProcess(void) { return 1 << FORMAT_S16; }
171 
186  virtual int DecodeAudio(AVCodecContext *ctx,
187  uint8_t *buffer, int &data_size,
188  const AVPacket *pkt);
192  static const int MAX_SIZE_BUFFER = 384000;
193 
194  protected:
195  void Error(const QString &msg);
196  void SilentError(const QString &msg);
197  void Warn(const QString &msg);
198  void ClearError(void);
199  void ClearWarning(void);
200 
201  QString lastError;
202  QString lastWarn;
205 };
206 
207 #endif
virtual int GetBytesPerFrame(void) const
Definition: audiooutput.h:75
virtual bool NeedDecodingBeforePassthrough(void) const
Definition: audiooutput.h:119
QString GetWarning(void) const
Definition: audiooutput.h:144
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:89
virtual bool ToggleUpmix(void)
Definition: audiooutput.h:155
#define MPUBLIC
Definition: mythexp.h:10
bool PulseStatus(void)
Definition: audiooutput.h:157
QVector< AudioDeviceConfig > ADCVect
Definition: audiooutput.h:42
struct AVFrame AVFrame
virtual bool CanUpmix(void)
Definition: audiooutput.h:156
virtual int64_t LengthLastData(void) const
Definition: audiooutput.h:126
virtual int GetChannels(void) const
Definition: audiooutput.h:73
unsigned int uint
Definition: compat.h:136
bool pulsewassuspended
Definition: audiooutput.h:203
virtual bool CanProcess(AudioFormat fmt)
Definition: audiooutput.h:164
QString lastWarn
Definition: audiooutput.h:202
QString lastError
Definition: audiooutput.h:201
virtual bool CanDownmix(void) const
Definition: audiooutput.h:81
AudioOutputSettings settings
Definition: audiooutput.h:32
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
virtual void GetBufferStatus(uint &fill, uint &total)
Definition: audiooutput.h:146
const char * name
Definition: ParseText.cpp:339
virtual void SetSourceBitrate(int)
Definition: audiooutput.h:141
virtual float GetStretchFactor(void) const
Definition: audiooutput.h:72
AudioOutputSource
Definition: audiosettings.h:17
AudioDeviceConfig(const QString &name, const QString &desc)
Definition: audiooutput.h:36
virtual bool IsUpmixing(void)
Definition: audiooutput.h:154
AVFrame * _frame
Definition: audiooutput.h:204
virtual uint32_t CanProcess(void)
Definition: audiooutput.h:170
virtual AudioFormat GetFormat(void) const
Definition: audiooutput.h:74
const char * frames[3]
Definition: element.c:46
QString GetError(void) const
Definition: audiooutput.h:143
virtual int64_t GetAudioBufferedTime(void)
report amount of audio buffered in milliseconds.
Definition: audiooutput.h:139