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