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::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 
99  virtual bool AddFrames(void *buffer, int frames, int64_t timecode) = 0;
100 
112  virtual bool AddData(void *buffer, int len,
113  int64_t timecode, int frames) = 0;
114 
120  virtual bool NeedDecodingBeforePassthrough(void) const { return true; };
121 
127  virtual int64_t LengthLastData(void) const { return -1; };
128 
129  virtual void SetTimecode(int64_t timecode) = 0;
130  virtual bool IsPaused(void) const = 0;
131  virtual void Pause(bool paused) = 0;
132  virtual void PauseUntilBuffered(void) = 0;
133 
134  // Wait for all data to finish playing
135  virtual void Drain(void) = 0;
136 
137  virtual int64_t GetAudiotime(void) = 0;
138 
140  virtual int64_t GetAudioBufferedTime(void) { return 0; }
141 
142  virtual void SetSourceBitrate(int ) { }
143 
144  QString GetError(void) const { return lastError; }
145  QString GetWarning(void) const { return lastWarn; }
146 
147  virtual void GetBufferStatus(uint &fill, uint &total)
148  { fill = total = 0; }
149 
150  // Only really used by the AudioOutputNULL object
151  virtual void bufferOutputData(bool y) = 0;
152  virtual int readOutputData(unsigned char *read_buffer,
153  int max_length) = 0;
154 
155  virtual bool IsUpmixing(void) { return false; }
156  virtual bool ToggleUpmix(void) { return false; }
157  virtual bool CanUpmix(void) { return false; }
158  bool PulseStatus(void) { return pulsewassuspended; }
159 
165  virtual bool CanProcess(AudioFormat fmt) { return fmt == FORMAT_S16; }
166 
171  virtual uint32_t CanProcess(void) { return 1 << FORMAT_S16; }
172 
187  virtual int DecodeAudio(AVCodecContext *ctx,
188  uint8_t *buffer, int &data_size,
189  const AVPacket *pkt);
193  static const int MAX_SIZE_BUFFER = 384000;
194 
195  protected:
196  void Error(const QString &msg);
197  void SilentError(const QString &msg);
198  void Warn(const QString &msg);
199  void ClearError(void);
200  void ClearWarning(void);
201 
202  QString lastError;
203  QString lastWarn;
205  AVFrame *_frame;
206 };
207 
208 #endif
virtual int GetBytesPerFrame(void) const
Definition: audiooutput.h:76
virtual bool NeedDecodingBeforePassthrough(void) const
Definition: audiooutput.h:120
QString GetWarning(void) const
Definition: audiooutput.h:145
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:89
virtual bool ToggleUpmix(void)
Definition: audiooutput.h:156
#define MPUBLIC
Definition: mythexp.h:10
bool PulseStatus(void)
Definition: audiooutput.h:158
QVector< AudioDeviceConfig > ADCVect
Definition: audiooutput.h:42
virtual bool CanUpmix(void)
Definition: audiooutput.h:157
virtual int64_t LengthLastData(void) const
Definition: audiooutput.h:127
virtual int GetChannels(void) const
Definition: audiooutput.h:74
unsigned int uint
Definition: compat.h:136
bool pulsewassuspended
Definition: audiooutput.h:204
virtual bool CanProcess(AudioFormat fmt)
Definition: audiooutput.h:165
QString lastWarn
Definition: audiooutput.h:203
QString lastError
Definition: audiooutput.h:202
virtual bool CanDownmix(void) const
Definition: audiooutput.h:82
AudioOutputSettings settings
Definition: audiooutput.h:32
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
virtual void GetBufferStatus(uint &fill, uint &total)
Definition: audiooutput.h:147
const char * name
Definition: ParseText.cpp:339
virtual void SetSourceBitrate(int)
Definition: audiooutput.h:142
virtual float GetStretchFactor(void) const
Definition: audiooutput.h:73
AudioOutputSource
Definition: audiosettings.h:17
AudioDeviceConfig(const QString &name, const QString &desc)
Definition: audiooutput.h:36
virtual bool IsUpmixing(void)
Definition: audiooutput.h:155
AVFrame * _frame
Definition: audiooutput.h:205
virtual uint32_t CanProcess(void)
Definition: audiooutput.h:171
virtual AudioFormat GetFormat(void) const
Definition: audiooutput.h:75
const char * frames[3]
Definition: element.c:46
QString GetError(void) const
Definition: audiooutput.h:144
virtual int64_t GetAudioBufferedTime(void)
report amount of audio buffered in milliseconds.
Definition: audiooutput.h:140