Go to the documentation of this file. 1 #ifndef AUDIOOUTPUTBASE
2 #define AUDIOOUTPUTBASE
10 #include <QWaitCondition>
17 #include "samplerate.h"
20 #define VBAUDIO(str) LOG(VB_AUDIO, LOG_INFO, LOC + (str))
21 #define VBAUDIOTS(str) LOG(VB_AUDIO | VB_TIMESTAMP, LOG_INFO, LOC + (str))
22 #define VBGENERAL(str) LOG(VB_GENERAL, LOG_INFO, LOC + (str))
23 #define VBERROR(str) LOG(VB_GENERAL, LOG_ERR, LOC + (str))
24 #define VBWARN(str) LOG(VB_GENERAL, LOG_WARNING, LOC + (str))
25 #define VBERRENO(str) Error(LOC + (str) + ": " + ENO)
26 #define VBERRNOCONST(str) LOG(VB_GENERAL, LOG_ERR, LOC + (str) + ": " + ENO)
34 struct AVCodecContext;
76 AVCodecID codec,
int profile)
const override;
88 void Reset(
void)
override;
90 void SetSWVolume(
int new_volume,
bool save)
override;
94 bool AddFrames(
void *buffer,
int frames, std::chrono::milliseconds timecode)
override;
95 bool AddData(
void *buffer,
int len, std::chrono::milliseconds timecode,
int frames)
override;
99 void SetTimecode(std::chrono::milliseconds timecode)
override;
101 void Pause(
bool paused)
override;
105 void Drain(
void)
override;
111 virtual void Status(
void);
120 int readOutputData(
unsigned char *read_buffer,
size_t max_length)
override;
135 virtual void WriteAudio(
unsigned char *aubuf,
int size) = 0;
151 int GetAudioData(uchar *buffer,
int buf_size,
bool full_buffer,
152 volatile uint *local_raud =
nullptr);
221 int &samplerate_tmp,
int &channels_tmp);
224 void SetAudiotime(
int frames, std::chrono::milliseconds timecode);
288 alignas(16) std::array<float,kAudioSRCInputSize>
m_srcInBuf {};
AudioOutputSettings * m_outputSettingsRaw
void Reset(void) override
Reset the audiobuffer, timecode and mythmusic visualisation.
soundtouch::SoundTouch * m_pSoundStretch
int GetBytesPerFrame(void) const override
void SetTimecode(std::chrono::milliseconds timecode) override
Set the timecode of the samples most recently added to the audiobuffer.
void Pause(bool paused) override
volatile uint m_raud
Audio circular buffer.
bool AddData(void *buffer, int len, std::chrono::milliseconds timecode, int frames) override
Add data to the audiobuffer and perform any required processing.
int CheckFreeSpace(int &frames)
Check that there's enough space in the audiobuffer to write the provided number of frames.
int audiolen() const
Get the number of bytes in the audiobuffer.
bool m_bufferOutputDataForUse
AsyncLooseLock m_resetActive
QMutex m_avsyncLock
must hold avsync_lock to read or write 'audiotime' and 'audiotime_updated'
bool CanPassthrough(int samplerate, int channels, AVCodecID codec, int profile) const override
Test if we can output digital audio and if sample rate is supported.
virtual void CloseDevice(void)=0
bool m_configureSucceeded
uint m_memoryCorruptionTest2
bool SetupPassthrough(AVCodecID codec, int codec_profile, int &samplerate_tmp, int &channels_tmp)
int audiofree() const
Get the free space in the audiobuffer in bytes.
void KillAudio(void)
Kill the output thread and cleanup.
int readOutputData(unsigned char *read_buffer, size_t max_length) override
std::chrono::milliseconds GetAudiotime(void) override
Calculate the timecode of the samples that are about to become audible.
float GetStretchFactor(void) const override
Get the timetretch factor.
bool IsUpmixing(void) override
Source is currently being upmixed.
void SetEffDsp(int dsprate) override
Set the effective DSP rate.
bool CanDownmix(void) const override
std::chrono::milliseconds m_audbufTimecode
timecode of audio most recently placed into buffer
static const char * quality_string(int q)
void SetAudiotime(int frames, std::chrono::milliseconds timecode)
Set the timecode of the top of the ringbuffer Exclude all other processing elements as they dont vary...
virtual int GetBufferedOnSoundcard(void) const =0
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
int m_kAudioSRCOutputSize
std::chrono::milliseconds m_lengthLastData
std::chrono::milliseconds LengthLastData(void) const override
void Drain(void) override
Block until all available frames have been written to the device.
long m_soundcardBufferSize
int GetChannels(void) const override
std::array< float, kAudioSRCInputSize > m_srcInBuf
AudioOutputBase(const AudioSettings &settings)
AudioOutputSettings * GetOutputSettingsCleaned(bool digital=true) override
Returns capabilities supported by the audio device amended to take into account the digital audio opt...
virtual void StopOutputThread(void)
void Reconfigure(const AudioSettings &settings) override
(Re)Configure AudioOutputBase
virtual AudioOutputSettings * GetOutputSettings(bool)
~AudioOutputBase() override
Destructor.
uint m_memoryCorruptionTest1
int GetAudioData(uchar *buffer, int buf_size, bool full_buffer, volatile uint *local_raud=nullptr)
Copy frames from the audiobuffer into the buffer provided.
std::chrono::seconds m_currentSeconds
bool NeedDecodingBeforePassthrough() const override
AudioOutputSettings * m_outputSettingsDigitalRaw
static const uint kAudioRingBufferSize
Audio Buffer Size – should be divisible by 32,24,16,12,10,8,6,4,2..
void run() override
Main routine for the output thread.
void bufferOutputData(bool y) override
int m_sourceBytesPerFrame
void OutputAudioLoop(void)
Run in the output thread, write frames to the output device as they become available and there's spac...
AudioFormat m_outputFormat
AudioOutputDigitalEncoder * m_encoder
int GetSWVolume(void) override
Get the volume for software volume control.
int audioready() const
Get the scaled number of bytes in the audiobuffer, i.e.
int CopyWithUpmix(char *buffer, int frames, uint &org_waud)
Copy frames into the audiobuffer, upmixing en route if necessary.
SPDIFEncoder * m_spdifEnc
void SetSWVolume(int new_volume, bool save) override
Set the volume for software volume control.
bool CanUpmix(void) override
Upmixing of the current source is available if requested.
virtual void Status(void)
Report status via an OutputEvent.
AudioFormat GetFormat(void) const override
virtual void WriteAudio(unsigned char *aubuf, int size)=0
int m_outputBytesPerFrame
uint m_memoryCorruptionTest0
bool AddFrames(void *buffer, int frames, std::chrono::milliseconds timecode) override
Add frames to the audiobuffer and perform any required processing.
void SetStretchFactor(float factor) override
Set the timestretch factor.
bool CanProcess(AudioFormat) override
void InitSettings(const AudioSettings &settings)
virtual bool OpenDevice(void)=0
bool IsPaused(void) const override
void PauseUntilBuffered(void) override
uint32_t CanProcess(void) override
This is a wrapper around QThread that does several additional things.
virtual bool StartOutputThread(void)
std::array< uchar, kAudioRingBufferSize > m_audioBuffer
main audio buffer
QMutex m_audioBufLock
Writes to the audiobuffer, reconfigures and audiobuffer resets can only take place while holding this...
AudioOutputSource m_source
AudioOutputSettings * GetOutputSettingsUsers(bool digital=false) override
Returns capabilities supported by the audio device amended to take into account the digital audio opt...
void SetStretchFactorLocked(float factor)
Set the timestretch factor.
AudioOutputSettings * m_outputSettings
void GetBufferStatus(uint &fill, uint &total) override
Fill in the number of bytes in the audiobuffer and the total size of the audiobuffer.
std::chrono::milliseconds GetAudioBufferedTime(void) override
Get the difference in timecode between the samples that are about to become audible and the samples m...
std::chrono::milliseconds m_audioTime
timecode of audio leaving the soundcard (same units as timecodes)
std::chrono::milliseconds GetBaseAudBufTimeCode() const
static const uint kAudioSRCInputSize
uint m_memoryCorruptionTest3
bool ToggleUpmix(void) override
Toggle between stereo and upmixed 5.1 if the source material is stereo.
void SetSourceBitrate(int rate) override
Set the bitrate of the source material, reported in periodic OutputEvents.
AudioOutputSettings * m_outputSettingsDigital
AudioOutputSettings * OutputSettings(bool digital=true)