MythTV  master
audiooutput.h
Go to the documentation of this file.
1 #ifndef AUDIOOUTPUT
2 #define AUDIOOUTPUT
3 
4 #include <utility>
5 
6 // Qt headers
7 #include <QCoreApplication>
8 #include <QString>
9 #include <QVector>
10 
11 // MythTV headers
12 #include "compat.h"
13 #include "audiosettings.h"
14 #include "audiooutputsettings.h"
15 #include "mythcorecontext.h"
16 #include "volumebase.h"
17 #include "output.h"
18 
19 // forward declaration
20 struct AVCodecContext;
21 struct AVPacket;
22 struct AVFrame;
23 
25 {
26  Q_DECLARE_TR_FUNCTIONS(AudioOutput);
27 
28  public:
30  {
31  public:
32  QString m_name;
33  QString m_desc;
36  m_settings(AudioOutputSettings(true)) { };
37  AudioDeviceConfig(QString name,
38  QString desc) :
39  m_name(std::move(name)), m_desc(std::move(desc)),
40  m_settings(AudioOutputSettings(true)) { };
41  AudioDeviceConfig(const AudioDeviceConfig &) = default;
43  AudioDeviceConfig &operator= (const AudioDeviceConfig &) = default;
44  AudioDeviceConfig &operator= (AudioDeviceConfig &&) = default;
45  };
46 
47  using ADCVect = QVector<AudioDeviceConfig>;
48 
49  static void Cleanup(void);
50  static ADCVect* GetOutputList(void);
51  static AudioDeviceConfig* GetAudioDeviceConfig(
52  QString &name, QString &desc, bool willsuspendpa = false);
53 
54  // opens one of the concrete subclasses
55  static AudioOutput *OpenAudio(
56  const QString &main_device, const QString &passthru_device,
57  AudioFormat format, int channels, AVCodecID codec, int samplerate,
58  AudioOutputSource source, bool set_initial_vol, bool passthru,
59  int upmixer_startup = 0, AudioOutputSettings *custom = nullptr);
60  static AudioOutput *OpenAudio(AudioSettings &settings,
61  bool willsuspendpa = true);
62  static AudioOutput *OpenAudio(
63  const QString &main_device,
64  const QString &passthru_device = QString(),
65  bool willsuspendpa = true);
66 
67  AudioOutput() = default;
68  ~AudioOutput() override;
69 
70  // reconfigure sound out for new params
71  virtual void Reconfigure(const AudioSettings &settings) = 0;
72 
73  virtual void SetStretchFactor(float factor);
74  virtual float GetStretchFactor(void) const { return 1.0F; }
75  virtual int GetChannels(void) const { return 2; }
76  virtual AudioFormat GetFormat(void) const { return FORMAT_S16; };
77  virtual int GetBytesPerFrame(void) const { return 4; };
78 
79  virtual AudioOutputSettings* GetOutputSettingsCleaned(bool digital = true);
80  virtual AudioOutputSettings* GetOutputSettingsUsers(bool digital = true);
81  virtual bool CanPassthrough(int samplerate, int channels,
82  AVCodecID codec, int profile) const;
83  virtual bool CanDownmix(void) const { return false; };
84 
85  // dsprate is in 100 * samples/second
86  virtual void SetEffDsp(int dsprate) = 0;
87 
88  virtual void Reset(void) = 0;
89 
100  virtual bool AddFrames(void *buffer, int frames, int64_t timecode) = 0;
101 
113  virtual bool AddData(void *buffer, int len,
114  int64_t timecode, int frames) = 0;
115 
121  virtual bool NeedDecodingBeforePassthrough(void) const { return true; };
122 
128  virtual int64_t LengthLastData(void) const { return -1; };
129 
130  virtual void SetTimecode(int64_t timecode) = 0;
131  virtual bool IsPaused(void) const = 0;
132  virtual void Pause(bool paused) = 0;
133  virtual void PauseUntilBuffered(void) = 0;
134 
135  // Wait for all data to finish playing
136  virtual void Drain(void) = 0;
137 
138  virtual int64_t GetAudiotime(void) = 0;
139 
141  virtual int64_t GetAudioBufferedTime(void) { return 0; }
142 
143  virtual void SetSourceBitrate(int /*rate*/ ) { }
144 
145  QString GetError(void) const { return m_lastError; }
146  QString GetWarning(void) const { return m_lastWarn; }
147 
148  virtual void GetBufferStatus(uint &fill, uint &total)
149  { fill = total = 0; }
150 
151  // Only really used by the AudioOutputNULL object
152  virtual void bufferOutputData(bool y) = 0;
153  virtual int readOutputData(unsigned char *read_buffer,
154  int max_length) = 0;
155 
156  virtual bool IsUpmixing(void) { return false; }
157  virtual bool ToggleUpmix(void) { return false; }
158  virtual bool CanUpmix(void) { return false; }
159  bool PulseStatus(void) { return m_pulseWasSuspended; }
160 
166  virtual bool CanProcess(AudioFormat fmt) { return fmt == FORMAT_S16; }
167 
172  virtual uint32_t CanProcess(void) { return 1 << FORMAT_S16; }
173 
188  virtual int DecodeAudio(AVCodecContext *ctx,
189  uint8_t *buffer, int &data_size,
190  const AVPacket *pkt);
194  static const int kMaxSizeBuffer = 384000;
195 
196  protected:
197  void Error(const QString &msg);
198  void SilentError(const QString &msg);
199  void Warn(const QString &msg);
200  void ClearError(void);
201  void ClearWarning(void);
202 
203  QString m_lastError;
204  QString m_lastWarn;
205  bool m_pulseWasSuspended {false};
206  AVFrame *m_frame {nullptr};
207 };
208 
209 #endif
QString m_lastWarn
Definition: audiooutput.h:204
virtual int GetBytesPerFrame(void) const
Definition: audiooutput.h:77
virtual bool NeedDecodingBeforePassthrough(void) const
Definition: audiooutput.h:121
QVector< AudioDeviceConfig > ADCVect
Definition: audiooutput.h:47
QString GetWarning(void) const
Definition: audiooutput.h:146
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
virtual bool ToggleUpmix(void)
Definition: audiooutput.h:157
#define MPUBLIC
Definition: mythexp.h:10
bool PulseStatus(void)
Definition: audiooutput.h:159
virtual bool CanUpmix(void)
Definition: audiooutput.h:158
virtual int64_t LengthLastData(void) const
Definition: audiooutput.h:128
struct AVFrame AVFrame
virtual int GetChannels(void) const
Definition: audiooutput.h:75
virtual bool CanProcess(AudioFormat fmt)
Definition: audiooutput.h:166
AudioOutputSettings m_settings
Definition: audiooutput.h:34
virtual bool CanDownmix(void) const
Definition: audiooutput.h:83
unsigned int uint
Definition: compat.h:140
virtual void GetBufferStatus(uint &fill, uint &total)
Definition: audiooutput.h:148
virtual void SetSourceBitrate(int)
Definition: audiooutput.h:143
const char * m_name
Definition: ParseText.cpp:328
virtual float GetStretchFactor(void) const
Definition: audiooutput.h:74
AudioOutputSource
Definition: audiosettings.h:21
virtual bool IsUpmixing(void)
Definition: audiooutput.h:156
virtual uint32_t CanProcess(void)
Definition: audiooutput.h:172
virtual AudioFormat GetFormat(void) const
Definition: audiooutput.h:76
const char * frames[3]
Definition: element.c:46
QString m_lastError
Definition: audiooutput.h:203
QString GetError(void) const
Definition: audiooutput.h:145
AudioDeviceConfig(QString name, QString desc)
Definition: audiooutput.h:37
virtual int64_t GetAudioBufferedTime(void)
report amount of audio buffered in milliseconds.
Definition: audiooutput.h:141