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 m_name;
31  QString m_desc;
34  m_settings(AudioOutputSettings(true)) { };
35  AudioDeviceConfig(const QString &name,
36  const QString &desc) :
37  m_name(name), m_desc(desc),
38  m_settings(AudioOutputSettings(true)) { };
39  AudioDeviceConfig(const AudioDeviceConfig &) = default;
41  AudioDeviceConfig &operator= (const AudioDeviceConfig &) = default;
42  AudioDeviceConfig &operator= (AudioDeviceConfig &&) = default;
43  };
44 
45  typedef QVector<AudioDeviceConfig> ADCVect;
46 
47  static void Cleanup(void);
48  static ADCVect* GetOutputList(void);
49  static AudioDeviceConfig* GetAudioDeviceConfig(
50  QString &name, QString &desc, bool willsuspendpa = false);
51 
52  // opens one of the concrete subclasses
53  static AudioOutput *OpenAudio(
54  const QString &main_device, const QString &passthru_device,
55  AudioFormat format, int channels, AVCodecID codec, int samplerate,
56  AudioOutputSource source, bool set_initial_vol, bool passthru,
57  int upmixer_startup = 0, AudioOutputSettings *custom = nullptr);
58  static AudioOutput *OpenAudio(AudioSettings &settings,
59  bool willsuspendpa = true);
60  static AudioOutput *OpenAudio(
61  const QString &main_device,
62  const QString &passthru_device = QString(),
63  bool willsuspendpa = true);
64 
65  AudioOutput() = default;
66  ~AudioOutput() override;
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  AVCodecID 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 /*rate*/ ) { }
142 
143  QString GetError(void) const { return m_lastError; }
144  QString GetWarning(void) const { return m_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 m_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 m_lastError;
202  QString m_lastWarn;
203  bool m_pulsewassuspended {false};
204  AVFrame *m_frame {nullptr};
205 };
206 
207 #endif
QString m_lastWarn
Definition: audiooutput.h:202
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:91
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:45
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:140
virtual bool CanProcess(AudioFormat fmt)
Definition: audiooutput.h:164
AudioOutputSettings m_settings
Definition: audiooutput.h:32
virtual bool CanDownmix(void) const
Definition: audiooutput.h:81
virtual void GetBufferStatus(uint &fill, uint &total)
Definition: audiooutput.h:146
const char * name
Definition: ParseText.cpp:328
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:35
virtual bool IsUpmixing(void)
Definition: audiooutput.h:154
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 m_lastError
Definition: audiooutput.h:201
QString GetError(void) const
Definition: audiooutput.h:143
virtual int64_t GetAudioBufferedTime(void)
report amount of audio buffered in milliseconds.
Definition: audiooutput.h:139