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