vdr-plugin-softhddevice-drm-gles 1.6.7
cSoftHdAudio Class Reference

Audio Interface. More...

#include <audio.h>

Public Member Functions

 cSoftHdAudio (cSoftHdDevice *)
 Create a new audio context.
 
void LazyInit (void)
 Initialize audio output module (alsa)
 
void Exit (void)
 Cleanup audio output module (alsa)
 
int Setup (AVRational, int, int, bool)
 Alsa setup wrapper.
 
void SetPaused (bool)
 Set audio playback pause state.
 
bool IsPaused (void)
 
void Filter (AVFrame *, AVCodecContext *)
 Send audio frame to filter and enqueue it.
 
void EnqueueSpdif (const uint16_t *, int, int64_t pts)
 Enqueue prepared spdif bursts in audio output queue.
 
bool IsBufferFull (void)
 
void FlushBuffers (void)
 Flush audio buffers.
 
int GetUsedRingbufferBytes (void)
 Get used bytes in audio ringbuffer.
 
int GetUsedRingbufferMs (void)
 Get used ms in audio ringbuffer.
 
int64_t GetHardwareOutputPtsMs (void)
 Get the hardware output PTS in milliseconds.
 
int64_t GetHardwareOutputDelayMs (void)
 Get the hardware delay in milliseconds.
 
int64_t GetHardwareOutputPtsTimebaseUnits (void)
 Get the hardware output PTS in timebase units.
 
bool HasInputPts (void)
 
int64_t GetInputPtsMs (void)
 
int64_t GetOutputPtsMs (void)
 Get the output PTS of the ringbuffer.
 
int GetAvResyncBorderMs (void)
 
void SetVolume (int)
 Set mixer volume (0-1000)
 
void SetSoftvol (bool softVolume)
 
void SetNormalize (bool, int)
 Set normalize volume parameters.
 
void SetCompression (bool, int)
 Set volume compression parameters.
 
void SetEqualizer (bool, int[18])
 Set equalizer bands.
 
void SetStereoDescent (int)
 Set stereo loudness descent.
 
void SetPassthroughMask (int mask)
 
void SetAutoAES (bool appendAes)
 
void SetTimebase (AVRational timebase)
 
void SetDownmix (int downMix)
 
int GetPassthroughMask (void) const
 
void DropSamplesOlderThanPtsMs (int64_t)
 Drop samples older than the given PTS.
 
void ClockDriftCompensation (void)
 Calculate clock drift compensation.
 
void ResetHwDelayBaseline (void)
 Reset the hw delay baseline.
 
void SetHwDelayBaseline (void)
 Set the hw delay baseline.
 

Protected Member Functions

virtual void Action (void)
 Audio thread loop, started with Start().
 

Private Member Functions

void Enqueue (const uint16_t *, int, int64_t)
 Send audio data to ringbuffer.
 
void EnqueueFrame (AVFrame *)
 Place samples in audio output queue.
 
bool SendAudio (int)
 Write regular audio data from the ringbuffer to the hardware.
 
bool SendPause (void)
 Write pause to passthrough device.
 
void RebuildPauseBurst (int)
 Rebuild the pause spdif burst with the size of the last recognized normal spdif audio if size changed.
 
void Stop (void)
 Stop the thread.
 
void FlushAlsaBuffers (void)
 Flush alsa buffers.
 
void DropAlsaBuffers (void)
 Drop alsa buffers.
 
bool CyclicCall (void)
 Cyclic audio playback call.
 
void ProcessEvents (void)
 Process queued events and forward them to event receiver.
 
int InitFilter (AVCodecContext *)
 Init audio filters.
 
AVFrameFilterGetFrame (void)
 Get frame from filter sink.
 
int CheckForFilterReady (AVCodecContext *)
 Check if the filter has changed and is ready, init the filter if needed.
 
std::string BuildChannelMapFilter (const AVChannelLayout &)
 Build the "|"-separated mappings list for the channelmap filter.
 
int64_t GetOutputPtsMsInternal (void)
 

Private Attributes

cSoftHdDevicem_pDevice
 pointer to device
 
cSoftHdConfigm_pConfig
 pointer to config
 
cAlsaDevice m_alsa
 alsa device
 
IEventReceiverm_pEventReceiver
 pointer to event receiver
 
cBufferFillLevelLowPassFilter m_fillLevel
 low pass filter for the buffer fill level
 
cPidController m_pidController {3, 0.005, 0, 1000}
 PID controller for clock drift compensation with tuning values coming from educated guesses.
 
std::chrono::steady_clock::time_point m_lastPidInvocation
 last time the PID controller was invoked
 
int m_packetCounter = 0
 packet counter for logging
 
bool m_initialized = false
 class initialized
 
std::mutex m_mutex
 mutex for thread safety
 
std::mutex m_pauseMutex
 mutex for a safe thread pausing
 
std::mutex m_queueMutex
 mutex for queue safety
 
std::vector< Eventm_eventQueue
 event queue for incoming events
 
std::atomic< doublem_pitchPpm = 0
 pitch adjustment in ppm. Positive values are faster
 
int m_pitchAdjustFrameCounter = 0
 counter for pitch adjustment frames
 
int m_volume = 0
 current volume (0 .. 1000)
 
int m_stereoDescent
 volume descent for stereo
 
AVRational m_timebase
 AVCodecContext pkts_timebase.
 
int64_t m_inputPts = AV_NOPTS_VALUE
 pts clock (last pts in ringbuffer)
 
std::atomic< boolm_paused = true
 audio is paused
 
bool m_softVolume
 flag to use soft volume
 
int m_spdifBurstSize = 0
 size of the current spdif burst
 
std::vector< uint16_tm_pauseBurst
 holds the burst data itself
 
int m_hwBaseline = 0
 saves the hw delay (pause bursts) once a real audio frame to correctly do the AV-Sync
 
bool m_firstRealAudioReceived = false
 false, as long as no real audio was sent - used to trigger the baseline set
 
cAudioProcessor m_audioProcessor
 
bool m_useNormalizer
 flag to use volume normalize
 
bool m_useCompressor
 flag to use compress volume
 
bool m_useEqualizer
 flag to use equalizer
 
const charm_pMixerDevice = nullptr
 mixer device name (not used)
 
const charm_pMixerChannel
 mixer channel name
 
int m_filterChanged = 0
 filter has changed
 
int m_filterReady = 0
 filter is ready
 
AVFilterGraphm_pFilterGraph = nullptr
 
AVFilterContextm_pBuffersrcCtx
 
AVFilterContextm_pBuffersinkCtx
 
cSoftHdRingbuffer m_pRingbuffer {RINGBUFFER_SIZE}
 sample ring buffer
 

Static Private Attributes

static constexpr int AUDIO_MIN_BUFFER_FREE = 3072 * 8 * 8
 Minimum free space in audio buffer 8 packets for 8 channels.
 
static constexpr int AV_SYNC_BORDER_MS = 5000
 absolute max a/v difference in ms which should trigger a resync
 
static constexpr int BYTES_PER_SAMPLE = 2
 number of bytes per sample
 
static constexpr unsigned RINGBUFFER_SIZE = 3 * 5 * 7 * 8 * 2 * 1000
 default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8)
 

Detailed Description

Audio Interface.

Definition at line 51 of file audio.h.

Constructor & Destructor Documentation

◆ cSoftHdAudio()

Member Function Documentation

◆ Action()

void cSoftHdAudio::Action ( void  )
protectedvirtual

Audio thread loop, started with Start().

Tries to periodically send frames to the hardware and checks for events (underruns)

Definition at line 993 of file audio.cpp.

References CyclicCall(), LOGDEBUG, and ProcessEvents().

◆ CheckForFilterReady()

int cSoftHdAudio::CheckForFilterReady ( AVCodecContext ctx)
private

Check if the filter has changed and is ready, init the filter if needed.

Parameters
ctxAVCodec audio decoding context
Return values
1error, init failed
0filter initiated

Definition at line 646 of file audio.cpp.

References InitFilter(), L_SOUND, LOGDEBUG2, m_filterChanged, m_filterReady, and m_pFilterGraph.

Referenced by Filter().

◆ ClockDriftCompensation()

void cSoftHdAudio::ClockDriftCompensation ( void  )

Calculate clock drift compensation.

Uses a PID controller to adjust the playback pitch based on the audio buffer fill level. This keeps the buffer level constant and compensates for clock drift between the sender and the audio hardware.

Also updates the low-pass filter for the buffer fill level.

Definition at line 1179 of file audio.cpp.

References cAlsaDevice::FramesToMsDouble(), cAlsaDevice::GetAvailableBufferFrames(), cBufferFillLevelLowPassFilter::GetBufferFillLevelFramesAvg(), cAlsaDevice::GetBufferSizeFrames(), cPidController::GetDTerm(), cPidController::GetITerm(), cPidController::GetPTerm(), cPidController::GetTargetValue(), cAlsaDevice::IsPassthroughActive(), cBufferFillLevelLowPassFilter::IsSettled(), L_SOUND, LOGDEBUG2, m_alsa, m_fillLevel, m_lastPidInvocation, m_packetCounter, m_pidController, m_pitchPpm, cPidController::SetTargetValue(), cPidController::Update(), and cBufferFillLevelLowPassFilter::UpdateAvgBufferFillLevel().

Referenced by cSoftHdDevice::PlayAudio().

◆ CyclicCall()

bool cSoftHdAudio::CyclicCall ( void  )
private

Cyclic audio playback call.

Handles audio output to ALSA, writing samples from the ring buffer to the hardware when space is available.

If passthrough is enabled, the thread continues sending data (pause bursts) even if audio playback is paused. This prevents, that the AV-Receiver looses the lock and may switch to PCM instead.

Returns
true if data was written or the next write should be scheduled immediately

Definition at line 1031 of file audio.cpp.

References AUDIO, cAlsaDevice::FramesToBytes(), cAlsaDevice::GetAvailableBufferFrames(), cAlsaDevice::HandleError(), cAlsaDevice::IsPassthroughActive(), m_alsa, m_eventQueue, m_mutex, m_paused, m_pauseMutex, m_queueMutex, m_spdifBurstSize, SendAudio(), SendPause(), and cAlsaDevice::WaitUntilReady().

Referenced by Action().

◆ DropAlsaBuffers()

void cSoftHdAudio::DropAlsaBuffers ( void  )
private

Drop alsa buffers.

Definition at line 977 of file audio.cpp.

References cAlsaDevice::FlushBuffers(), m_alsa, m_audioProcessor, cAudioProcessor::ResetCompressor(), and cAudioProcessor::ResetNormalizer().

Referenced by Setup().

◆ DropSamplesOlderThanPtsMs()

void cSoftHdAudio::DropSamplesOlderThanPtsMs ( int64_t  ptsMs)

Drop samples older than the given PTS.

Removes audio samples from the ringbuffer that have a presentation timestamp older than the specified ptsMs.

Parameters
ptsMspresentation timestamp in milliseconds - samples older than this will be dropped

Definition at line 421 of file audio.cpp.

References cAlsaDevice::FramesToBytes(), GetOutputPtsMsInternal(), HasInputPts(), L_AV_SYNC, LOGDEBUG2, m_alsa, m_fillLevel, m_mutex, m_pidController, m_pRingbuffer, cAlsaDevice::MsToFrames(), cSoftHdRingbuffer::ReadAdvance(), cBufferFillLevelLowPassFilter::Reset(), cPidController::Reset(), Timestamp2String(), cSoftHdRingbuffer::UsedBytes(), and cBufferFillLevelLowPassFilter::WroteFrames().

Referenced by cVideoRender::DisplayFrame(), and cSoftHdDevice::OnEventReceived().

◆ Enqueue()

◆ EnqueueFrame()

void cSoftHdAudio::EnqueueFrame ( AVFrame frame)
private

Place samples in audio output queue.

Parameters
frameaudio frame

Definition at line 453 of file audio.cpp.

References BYTES_PER_SAMPLE, cAudioProcessor::Compress(), Enqueue(), m_audioProcessor, m_useCompressor, m_useNormalizer, and cAudioProcessor::Normalize().

Referenced by Filter().

◆ EnqueueSpdif()

void cSoftHdAudio::EnqueueSpdif ( const uint16_t buffer,
int  count,
int64_t  pts 
)

Enqueue prepared spdif bursts in audio output queue.

Wrapper for Enqueue(), but builds a new pause burst if necessary

Parameters
bufferdata buffer
countnumber of bytes in data buffer
ptspts of the buffer

Definition at line 511 of file audio.cpp.

References Enqueue(), m_pauseMutex, and RebuildPauseBurst().

Referenced by cAudioDecoder::Passthrough().

◆ Exit()

void cSoftHdAudio::Exit ( void  )

Cleanup audio output module (alsa)

This currently also stops the audio thread.

Todo:
Move stopping the thread to AlsaExit()

Definition at line 949 of file audio.cpp.

References cAlsaDevice::Exit(), L_SOUND, LOGDEBUG2, m_alsa, m_initialized, m_pFilterGraph, and Stop().

Referenced by cSoftHdDevice::OnEnteringState().

◆ Filter()

void cSoftHdAudio::Filter ( AVFrame inframe,
AVCodecContext ctx 
)

Send audio frame to filter and enqueue it.

Parameters
inframeincoming audio frame to be filtered
ctxAVCodec audio decoding context
Return values
1error, send again
0running

Definition at line 679 of file audio.cpp.

References CheckForFilterReady(), EnqueueFrame(), FilterGetFrame(), L_SOUND, LOGDEBUG2, LOGERROR, m_filterChanged, and m_pBuffersrcCtx.

Referenced by cAudioDecoder::DecodePCM().

◆ FilterGetFrame()

AVFrame * cSoftHdAudio::FilterGetFrame ( void  )
private

Get frame from filter sink.

Returns
pointer to AVFrame if success, NULL otherwise

Definition at line 613 of file audio.cpp.

References LOGERROR, and m_pBuffersinkCtx.

Referenced by Filter().

◆ FlushAlsaBuffers()

void cSoftHdAudio::FlushAlsaBuffers ( void  )
private

◆ FlushBuffers()

void cSoftHdAudio::FlushBuffers ( void  )

◆ GetAvResyncBorderMs()

int cSoftHdAudio::GetAvResyncBorderMs ( void  )
inline

Definition at line 73 of file audio.h.

References AV_SYNC_BORDER_MS.

Referenced by cVideoRender::FrameDropNecessary().

◆ GetHardwareOutputDelayMs()

int64_t cSoftHdAudio::GetHardwareOutputDelayMs ( void  )

Get the hardware delay in milliseconds.

Returns
delay in milliseconds, or AV_NOPTS_VALUE if not available

Definition at line 815 of file audio.cpp.

References AV_NOPTS_VALUE, cAlsaDevice::FramesToMs(), cAlsaDevice::GetHwDelayFrames(), cAlsaDevice::IsRunning(), m_alsa, m_inputPts, and m_mutex.

Referenced by cVideoRender::LogDroppedDuped().

◆ GetHardwareOutputPtsMs()

int64_t cSoftHdAudio::GetHardwareOutputPtsMs ( void  )

Get the hardware output PTS in milliseconds.

Calculates the presentation timestamp of audio currently being output by the hardware by accounting for ALSA/kernel buffer delays. This represents the PTS of the audio that is actually being played right now.

Returns
PTS in milliseconds, or AV_NOPTS_VALUE if not available

Definition at line 795 of file audio.cpp.

References AV_NOPTS_VALUE, cAlsaDevice::FramesToMs(), cAlsaDevice::GetHwDelayFrames(), GetOutputPtsMsInternal(), cAlsaDevice::IsRunning(), m_alsa, m_hwBaseline, m_inputPts, and m_mutex.

Referenced by cSoftHdPlayer::Action(), cVideoRender::DisplayFrame(), GetHardwareOutputPtsTimebaseUnits(), and cSoftHdPlayer::Play().

◆ GetHardwareOutputPtsTimebaseUnits()

int64_t cSoftHdAudio::GetHardwareOutputPtsTimebaseUnits ( void  )

Get the hardware output PTS in timebase units.

Returns
presentation timestamp in timebase units

Definition at line 832 of file audio.cpp.

References AV_NOPTS_VALUE, GetHardwareOutputPtsMs(), m_alsa, m_timebase, and cAlsaDevice::MsToPts().

Referenced by cSoftHdDevice::GetSTC().

◆ GetInputPtsMs()

int64_t cSoftHdAudio::GetInputPtsMs ( void  )
inline

◆ GetOutputPtsMs()

int64_t cSoftHdAudio::GetOutputPtsMs ( void  )

Get the output PTS of the ringbuffer.

Calculates the presentation timestamp of the next audio sample that will be output from the ringbuffer. This is the input PTS minus the duration of audio currently buffered in the ringbuffer.

Note: This does not account for ALSA/kernel buffer delays. For the actual hardware output PTS, use GetHardwareOutputPtsMs() instead.

Returns
PTS in milliseconds

Definition at line 774 of file audio.cpp.

References GetOutputPtsMsInternal(), and m_mutex.

Referenced by cSoftHdDevice::GetFirstAudioPtsMsToPlay(), cSoftHdDevice::GetFirstVideoPtsMsToPlay(), cSoftHdDevice::IsBufferingThresholdReached(), and cSoftHdDevice::OnEventReceived().

◆ GetOutputPtsMsInternal()

◆ GetPassthroughMask()

int cSoftHdAudio::GetPassthroughMask ( void  ) const
inline

Definition at line 87 of file audio.h.

References cAlsaDevice::GetPassthroughMask(), and m_alsa.

◆ GetUsedRingbufferBytes()

int cSoftHdAudio::GetUsedRingbufferBytes ( void  )

Get used bytes in audio ringbuffer.

Definition at line 745 of file audio.cpp.

References m_mutex, m_pRingbuffer, and cSoftHdRingbuffer::UsedBytes().

Referenced by cVideoRender::LogDroppedDuped().

◆ GetUsedRingbufferMs()

int cSoftHdAudio::GetUsedRingbufferMs ( void  )

Get used ms in audio ringbuffer.

Definition at line 755 of file audio.cpp.

References cAlsaDevice::BytesToFrames(), cAlsaDevice::FramesToMs(), m_alsa, m_mutex, m_pRingbuffer, and cSoftHdRingbuffer::UsedBytes().

Referenced by cVideoRender::LogDroppedDuped().

◆ HasInputPts()

bool cSoftHdAudio::HasInputPts ( void  )
inline

◆ InitFilter()

int cSoftHdAudio::InitFilter ( AVCodecContext audioCtx)
private

Init audio filters.

The following alsa filters are set:

  • abuffer
  • channelmap
  • superequalizer
  • aformat
  • abuffersink
Return values
0everything ok
1didn't support channels, downmix set -> scrap this frame, test next
-1something gone wrong

Definition at line 204 of file audio.cpp.

References BuildChannelMapFilter(), cAlsaDevice::GetDownmix(), cAudioProcessor::GetEqualizerOptions(), cAlsaDevice::GetHwNumChannels(), cAlsaDevice::GetHwSampleRate(), L_SOUND, LOGDEBUG2, LOGERROR, LOGWARNING, m_alsa, m_audioProcessor, m_filterChanged, m_filterReady, m_pBuffersinkCtx, m_pBuffersrcCtx, m_pFilterGraph, m_useEqualizer, and Setup().

Referenced by CheckForFilterReady().

◆ IsBufferFull()

bool cSoftHdAudio::IsBufferFull ( void  )
inline

◆ IsPaused()

bool cSoftHdAudio::IsPaused ( void  )
inline

Definition at line 59 of file audio.h.

References m_paused.

Referenced by cVideoRender::FrameDropNecessary().

◆ LazyInit()

void cSoftHdAudio::LazyInit ( void  )

Initialize audio output module (alsa)

The init is done lazily as soon as there is a STOP->PLAY state change or the mediaplayer wants to play video or audio.

This function can safely be called anytime, because it does nothing, if the init has already be done.

Definition at line 933 of file audio.cpp.

References cAlsaDevice::Init(), LOGFATAL, m_alsa, and m_initialized.

Referenced by cSoftHdDevice::OnEventReceived(), cSoftHdDevice::PlayAudioPkts(), and cSoftHdDevice::PlayVideoPkts().

◆ ProcessEvents()

void cSoftHdAudio::ProcessEvents ( void  )
private

Process queued events and forward them to event receiver.

Definition at line 1161 of file audio.cpp.

References m_eventQueue, m_pEventReceiver, m_queueMutex, and IEventReceiver::OnEventReceived().

Referenced by Action().

◆ RebuildPauseBurst()

void cSoftHdAudio::RebuildPauseBurst ( int  size)
private

Rebuild the pause spdif burst with the size of the last recognized normal spdif audio if size changed.

Parameters
sizespdif burst size in bytes

Definition at line 479 of file audio.cpp.

References L_SOUND, LOGDEBUG2, m_pauseBurst, and m_spdifBurstSize.

Referenced by EnqueueSpdif().

◆ ResetHwDelayBaseline()

void cSoftHdAudio::ResetHwDelayBaseline ( void  )

◆ SendAudio()

bool cSoftHdAudio::SendAudio ( int  freeAlsaBufferFrames)
private

Write regular audio data from the ringbuffer to the hardware.

Parameters
freeAlsaBufferFramesnumber of frames that can be written to the hardware
Return values
trueif data was written or the write should be scheduled again immediately
falseif no data was written

Definition at line 1085 of file audio.cpp.

References cAudioProcessor::Amplify(), cAlsaDevice::BytesToFrames(), cAlsaDevice::CheckWrittenFrames(), cAlsaDevice::FramesToBytes(), cSoftHdRingbuffer::GetReadPointer(), cAlsaDevice::IsPassthroughActive(), m_alsa, m_audioProcessor, m_fillLevel, m_pRingbuffer, m_softVolume, m_volume, cSoftHdRingbuffer::ReadAdvance(), cAlsaDevice::Write(), and cBufferFillLevelLowPassFilter::WroteFrames().

Referenced by CyclicCall().

◆ SendPause()

bool cSoftHdAudio::SendPause ( void  )
private

Write pause to passthrough device.

Returns
true if a complete burst was written, false otherwise

Definition at line 1119 of file audio.cpp.

References cAlsaDevice::BytesToFrames(), cAlsaDevice::CheckWrittenFrames(), m_alsa, m_pauseBurst, m_spdifBurstSize, and cAlsaDevice::Write().

Referenced by CyclicCall().

◆ SetAutoAES()

void cSoftHdAudio::SetAutoAES ( bool  appendAes)
inline

Definition at line 84 of file audio.h.

References m_alsa, and cAlsaDevice::SetAutoAES().

Referenced by cMenuSetupSoft::Store().

◆ SetCompression()

void cSoftHdAudio::SetCompression ( bool  enable,
int  maxfac 
)

Set volume compression parameters.

Parameters
enabletrue, turn on compression
maxfacmax. factor of compression / 1000

Definition at line 894 of file audio.cpp.

References m_audioProcessor, m_useCompressor, and cAudioProcessor::SetCompressor().

Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().

◆ SetDownmix()

void cSoftHdAudio::SetDownmix ( int  downMix)
inline

Definition at line 86 of file audio.h.

References m_alsa, and cAlsaDevice::SetDownmix().

Referenced by cMenuSetupSoft::Store().

◆ SetEqualizer()

void cSoftHdAudio::SetEqualizer ( bool  enable,
int  band[18] 
)

Set equalizer bands.

Parameters
enableset using equalizer
bandsetting frequenz bands

Definition at line 906 of file audio.cpp.

References m_audioProcessor, m_filterChanged, m_useEqualizer, and cAudioProcessor::SetEqualizer().

Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().

◆ SetHwDelayBaseline()

◆ SetNormalize()

void cSoftHdAudio::SetNormalize ( bool  enable,
int  maxfac 
)

Set normalize volume parameters.

Parameters
enabletrue, turn on normalize
maxfacmax. factor of normalize / 1000

Definition at line 882 of file audio.cpp.

References m_audioProcessor, m_useNormalizer, and cAudioProcessor::SetNormalizer().

Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().

◆ SetPassthroughMask()

void cSoftHdAudio::SetPassthroughMask ( int  mask)
inline

Definition at line 83 of file audio.h.

References m_alsa, and cAlsaDevice::SetPassthroughMask().

Referenced by cSoftHdDevice::SetPassthroughMask().

◆ SetPaused()

void cSoftHdAudio::SetPaused ( bool  pause)

Set audio playback pause state.

Parameters
pausetrue to pause, false to resume

Definition at line 868 of file audio.cpp.

References L_SOUND, LOGDEBUG2, m_paused, and m_pauseMutex.

Referenced by cSoftHdDevice::Clear(), cVideoRender::FrameDropNecessary(), cSoftHdDevice::OnEnteringState(), cSoftHdDevice::OnEventReceived(), and cSoftHdDevice::OnLeavingState().

◆ SetSoftvol()

void cSoftHdAudio::SetSoftvol ( bool  softVolume)
inline

Definition at line 76 of file audio.h.

References m_softVolume.

Referenced by cMenuSetupSoft::Store().

◆ SetStereoDescent()

void cSoftHdAudio::SetStereoDescent ( int  delta)

Set stereo loudness descent.

Parameters
deltavalue (/1000) to reduce stereo volume

Definition at line 918 of file audio.cpp.

References m_stereoDescent, m_volume, and SetVolume().

Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().

◆ SetTimebase()

void cSoftHdAudio::SetTimebase ( AVRational  timebase)
inline

Definition at line 85 of file audio.h.

References m_timebase.

Referenced by cAudioDecoder::Passthrough().

◆ Setup()

int cSoftHdAudio::Setup ( AVRational  timebase,
int  samplerate,
int  channels,
bool  passthrough 
)

Alsa setup wrapper.

only used for passthrough atm, setting up PCM goes via Filter()

Parameters
timebasecodec timebase
sampleratestream samplerate
channelsstream nb of channels
passthroughpassthrough enabled
Return values
0everything ok
-1something gone wrong in AlsaSetup
1no parameter change, no setup needed

Definition at line 582 of file audio.cpp.

References cSoftHdConfig::ConfigAudioDownmix, DropAlsaBuffers(), cAlsaDevice::GetDownmix(), cAlsaDevice::GetHwNumChannels(), cAlsaDevice::GetHwSampleRate(), cAlsaDevice::IsPassthroughActive(), LOGERROR, m_alsa, m_pConfig, m_timebase, cAlsaDevice::Setup(), and Stop().

Referenced by cAudioDecoder::CheckUpdateFormat(), and InitFilter().

◆ SetVolume()

void cSoftHdAudio::SetVolume ( int  volume)

◆ Stop()

void cSoftHdAudio::Stop ( void  )
private

Stop the thread.

Definition at line 1011 of file audio.cpp.

References LOGDEBUG.

Referenced by Exit(), and Setup().

Member Data Documentation

◆ AUDIO_MIN_BUFFER_FREE

constexpr int cSoftHdAudio::AUDIO_MIN_BUFFER_FREE = 3072 * 8 * 8
staticconstexprprivate

Minimum free space in audio buffer 8 packets for 8 channels.

Definition at line 98 of file audio.h.

Referenced by IsBufferFull().

◆ AV_SYNC_BORDER_MS

constexpr int cSoftHdAudio::AV_SYNC_BORDER_MS = 5000
staticconstexprprivate

absolute max a/v difference in ms which should trigger a resync

Definition at line 99 of file audio.h.

Referenced by Enqueue(), and GetAvResyncBorderMs().

◆ BYTES_PER_SAMPLE

constexpr int cSoftHdAudio::BYTES_PER_SAMPLE = 2
staticconstexprprivate

number of bytes per sample

Definition at line 100 of file audio.h.

Referenced by EnqueueFrame().

◆ m_alsa

◆ m_audioProcessor

cAudioProcessor cSoftHdAudio::m_audioProcessor
private

◆ m_eventQueue

std::vector<Event> cSoftHdAudio::m_eventQueue
private

event queue for incoming events

Definition at line 116 of file audio.h.

Referenced by CyclicCall(), Enqueue(), and ProcessEvents().

◆ m_fillLevel

cBufferFillLevelLowPassFilter cSoftHdAudio::m_fillLevel
private

low pass filter for the buffer fill level

Definition at line 106 of file audio.h.

Referenced by ClockDriftCompensation(), DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), and SendAudio().

◆ m_filterChanged

int cSoftHdAudio::m_filterChanged = 0
private

filter has changed

Definition at line 155 of file audio.h.

Referenced by CheckForFilterReady(), Filter(), FlushBuffers(), InitFilter(), and SetEqualizer().

◆ m_filterReady

int cSoftHdAudio::m_filterReady = 0
private

filter is ready

Definition at line 156 of file audio.h.

Referenced by CheckForFilterReady(), and InitFilter().

◆ m_firstRealAudioReceived

bool cSoftHdAudio::m_firstRealAudioReceived = false
private

false, as long as no real audio was sent - used to trigger the baseline set

Definition at line 131 of file audio.h.

Referenced by ResetHwDelayBaseline(), and SetHwDelayBaseline().

◆ m_hwBaseline

int cSoftHdAudio::m_hwBaseline = 0
private

saves the hw delay (pause bursts) once a real audio frame to correctly do the AV-Sync

Definition at line 130 of file audio.h.

Referenced by GetHardwareOutputPtsMs(), ResetHwDelayBaseline(), and SetHwDelayBaseline().

◆ m_initialized

bool cSoftHdAudio::m_initialized = false
private

class initialized

Definition at line 112 of file audio.h.

Referenced by Exit(), FlushBuffers(), and LazyInit().

◆ m_inputPts

int64_t cSoftHdAudio::m_inputPts = AV_NOPTS_VALUE
private

pts clock (last pts in ringbuffer)

Definition at line 124 of file audio.h.

Referenced by Enqueue(), FlushBuffers(), GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), GetInputPtsMs(), GetOutputPtsMsInternal(), and HasInputPts().

◆ m_lastPidInvocation

std::chrono::steady_clock::time_point cSoftHdAudio::m_lastPidInvocation
private

last time the PID controller was invoked

Definition at line 108 of file audio.h.

Referenced by ClockDriftCompensation().

◆ m_mutex

◆ m_packetCounter

int cSoftHdAudio::m_packetCounter = 0
private

packet counter for logging

Definition at line 109 of file audio.h.

Referenced by ClockDriftCompensation().

◆ m_pauseBurst

std::vector<uint16_t> cSoftHdAudio::m_pauseBurst
private

holds the burst data itself

Definition at line 129 of file audio.h.

Referenced by RebuildPauseBurst(), and SendPause().

◆ m_paused

std::atomic<bool> cSoftHdAudio::m_paused = true
private

audio is paused

Definition at line 125 of file audio.h.

Referenced by CyclicCall(), IsPaused(), and SetPaused().

◆ m_pauseMutex

std::mutex cSoftHdAudio::m_pauseMutex
private

mutex for a safe thread pausing

Definition at line 114 of file audio.h.

Referenced by CyclicCall(), EnqueueSpdif(), and SetPaused().

◆ m_pBuffersinkCtx

AVFilterContext* cSoftHdAudio::m_pBuffersinkCtx
private

Definition at line 159 of file audio.h.

Referenced by FilterGetFrame(), and InitFilter().

◆ m_pBuffersrcCtx

AVFilterContext* cSoftHdAudio::m_pBuffersrcCtx
private

Definition at line 158 of file audio.h.

Referenced by Filter(), and InitFilter().

◆ m_pConfig

cSoftHdConfig* cSoftHdAudio::m_pConfig
private

pointer to config

Definition at line 103 of file audio.h.

Referenced by cSoftHdAudio(), and Setup().

◆ m_pDevice

cSoftHdDevice* cSoftHdAudio::m_pDevice
private

pointer to device

Definition at line 102 of file audio.h.

◆ m_pEventReceiver

IEventReceiver* cSoftHdAudio::m_pEventReceiver
private

pointer to event receiver

Definition at line 105 of file audio.h.

Referenced by ProcessEvents().

◆ m_pFilterGraph

AVFilterGraph* cSoftHdAudio::m_pFilterGraph = nullptr
private

Definition at line 157 of file audio.h.

Referenced by CheckForFilterReady(), Exit(), and InitFilter().

◆ m_pidController

cPidController cSoftHdAudio::m_pidController {3, 0.005, 0, 1000}
private

PID controller for clock drift compensation with tuning values coming from educated guesses.

Definition at line 107 of file audio.h.

Referenced by ClockDriftCompensation(), DropSamplesOlderThanPtsMs(), and FlushBuffers().

◆ m_pitchAdjustFrameCounter

int cSoftHdAudio::m_pitchAdjustFrameCounter = 0
private

counter for pitch adjustment frames

Definition at line 118 of file audio.h.

Referenced by Enqueue().

◆ m_pitchPpm

std::atomic<double> cSoftHdAudio::m_pitchPpm = 0
private

pitch adjustment in ppm. Positive values are faster

Definition at line 117 of file audio.h.

Referenced by ClockDriftCompensation(), and Enqueue().

◆ m_pMixerChannel

const char* cSoftHdAudio::m_pMixerChannel
private

mixer channel name

Definition at line 152 of file audio.h.

◆ m_pMixerDevice

const char* cSoftHdAudio::m_pMixerDevice = nullptr
private

mixer device name (not used)

Definition at line 151 of file audio.h.

◆ m_pRingbuffer

cSoftHdRingbuffer cSoftHdAudio::m_pRingbuffer {RINGBUFFER_SIZE}
private

◆ m_queueMutex

std::mutex cSoftHdAudio::m_queueMutex
private

mutex for queue safety

Definition at line 115 of file audio.h.

Referenced by CyclicCall(), Enqueue(), and ProcessEvents().

◆ m_softVolume

bool cSoftHdAudio::m_softVolume
private

flag to use soft volume

Definition at line 127 of file audio.h.

Referenced by SendAudio(), SetSoftvol(), and SetVolume().

◆ m_spdifBurstSize

int cSoftHdAudio::m_spdifBurstSize = 0
private

size of the current spdif burst

Definition at line 128 of file audio.h.

Referenced by CyclicCall(), RebuildPauseBurst(), and SendPause().

◆ m_stereoDescent

int cSoftHdAudio::m_stereoDescent
private

volume descent for stereo

Definition at line 121 of file audio.h.

Referenced by SetStereoDescent(), and SetVolume().

◆ m_timebase

AVRational cSoftHdAudio::m_timebase
private

AVCodecContext pkts_timebase.

Definition at line 122 of file audio.h.

Referenced by Enqueue(), GetHardwareOutputPtsTimebaseUnits(), GetInputPtsMs(), GetOutputPtsMsInternal(), SetTimebase(), and Setup().

◆ m_useCompressor

bool cSoftHdAudio::m_useCompressor
private

flag to use compress volume

Definition at line 147 of file audio.h.

Referenced by EnqueueFrame(), and SetCompression().

◆ m_useEqualizer

bool cSoftHdAudio::m_useEqualizer
private

flag to use equalizer

Definition at line 148 of file audio.h.

Referenced by InitFilter(), and SetEqualizer().

◆ m_useNormalizer

bool cSoftHdAudio::m_useNormalizer
private

flag to use volume normalize

Definition at line 146 of file audio.h.

Referenced by EnqueueFrame(), and SetNormalize().

◆ m_volume

int cSoftHdAudio::m_volume = 0
private

current volume (0 .. 1000)

Definition at line 120 of file audio.h.

Referenced by SendAudio(), SetStereoDescent(), and SetVolume().

◆ RINGBUFFER_SIZE

constexpr unsigned cSoftHdAudio::RINGBUFFER_SIZE = 3 * 5 * 7 * 8 * 2 * 1000
staticconstexprprivate

default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8)

Definition at line 166 of file audio.h.


The documentation for this class was generated from the following files: