vdr-plugin-softhddevice-drm-gles 1.4.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
cSoftHdAudio Class Reference

cSoftHdAudio - Audio class More...

#include <audio.h>

Collaboration diagram for cSoftHdAudio:
Collaboration graph
[legend]

Public Member Functions

 cSoftHdAudio (cSoftHdDevice *)
 cSoftHdAudio constructor More...
 
virtual ~cSoftHdAudio (void)
 cSoftHdAudio denstructor More...
 
void LazyInit (void)
 Initialize audio output module. More...
 
void Exit (void)
 Cleanup audio output module. More...
 
int Setup (AVCodecContext *, int, int, int)
 Setup alsa. More...
 
void SetPaused (bool)
 Set audio playback paused state. More...
 
bool IsPaused (void)
 
void Filter (AVFrame *, AVCodecContext *)
 Send audio frame to filter and enqueue it. More...
 
void Enqueue (uint16_t *, int, AVFrame *)
 Send audio data to ringbuffer. More...
 
bool IsBufferFull (void)
 
void FlushBuffers (void)
 Flush audio buffers. More...
 
int GetUsedBytes (void)
 Get used bytes in audio ringbuffer. More...
 
int GetFreeBytes (void)
 Get free bytes in audio ringbuffer. More...
 
int64_t GetHardwareOutputPtsMs (void)
 Get the hardware output PTS in milliseconds. More...
 
int64_t GetHardwareOutputPtsTimebaseUnits (void)
 Get the hardware output PTS in timebase units. More...
 
int GetPassthrough (void) const
 
bool HasPts (void)
 
int64_t GetInputPtsMs (void)
 
int64_t GetOutputPtsMs (void)
 Get the output PTS of the ringbuffer. More...
 
void SetEq (int[18], int)
 Set equalizer bands. More...
 
void SetVolume (int)
 Set mixer volume (0-1000) More...
 
void SetDownmix (int downMix)
 
void SetSoftvol (bool softVolume)
 
void SetNormalize (bool, int)
 Set normalize volume parameters. More...
 
void SetCompression (bool, int)
 Set volume compression parameters. More...
 
void SetStereoDescent (int)
 Set stereo loudness descent. More...
 
void SetPassthrough (int)
 Set audio passthrough mask. More...
 
void SetAutoAES (bool appendAes)
 
void SetTimebase (AVRational *timebase)
 
void FlushAlsaBuffers (void)
 Flush alsa buffers. More...
 
bool CyclicCall (void)
 Cyclic audio playback call. More...
 
void DropSamplesOlderThanPtsMs (int64_t)
 Drop samples older than the given PTS. More...
 
void ProcessEvents (void)
 Process queued events and forward to event receiver. More...
 

Private Member Functions

AVFrame * FilterGetFrame (void)
 Get frame from filter sink. More...
 
int CheckForFilterReady (AVCodecContext *)
 Check if the filter has changed and is ready, init the filter if needed. More...
 
void Normalize (uint16_t *, int)
 Normalize audio. More...
 
void Compress (uint16_t *, int)
 Compress audio. More...
 
void SoftAmplify (int16_t *, int)
 Software amplifier. More...
 
int InitFilter (AVCodecContext *)
 Init filter. More...
 
void EnqueueFrame (AVFrame *)
 Place samples in audio output queue. More...
 
void XrunRecovery (void)
 xrun recovery More...
 
char * OpenAlsaDevice (const char *, int)
 Open alsa device. More...
 
char * FindAlsaDevice (const char *, const char *, int)
 Find alsa device giving some search hints. More...
 
int AlsaSetup (int channels, int sample_rate, int passthrough)
 Setup alsa audio for requested format. More...
 
void AlsaInitPCMDevice (void)
 Search for an alsa pcm device and open it. More...
 
void AlsaInitMixer (void)
 Initialize alsa mixer. More...
 
void AlsaSetVolume (int)
 Set alsa mixer volume (0-1000) More...
 
void AlsaInit (void)
 Initialize alsa audio output module. More...
 
void AlsaExit (void)
 Cleanup alsa audio output module. More...
 
int64_t PtsToMs (int64_t pts)
 
int64_t MsToPts (int64_t ptsMs)
 
int MsToFrames (int milliseconds)
 
int FramesToMs (int frames)
 
int64_t GetOutputPtsMsInternal (void)
 

Private Attributes

cSoftHdDevicem_pDevice
 pointer to device More...
 
cSoftHdConfigm_pConfig
 pointer to config More...
 
IEventReceiverm_pEventReceiver
 pointer to event receiver More...
 
cAudioThreadm_pAudioThread = nullptr
 pointer to audio thread More...
 
bool m_initialized = false
 class initialized More...
 
const int m_bytesPerSample = 2
 number of bytes per sample More...
 
unsigned int m_hwSampleRate
 hardware sample rate in Hz More...
 
unsigned int m_hwNumChannels
 number of hardware channels More...
 
AVRational * m_pTimebase
 pointer to AVCodecContext pkts_timebase More...
 
std::mutex m_mutex
 mutex for thread safety More...
 
std::mutex m_pauseMutex
 mutex for a safe thread pausing More...
 
std::vector< Eventm_eventQueue
 event queue for incoming events More...
 
int m_downmix
 set stereo downmix More...
 
int64_t m_inputPts
 pts clock (last pts in ringbuffer) More...
 
std::atomic< bool > m_paused = true
 audio is paused More...
 
bool m_softVolume
 flag to use soft volume More...
 
int m_passthrough
 passthrough mask More...
 
const char * m_pPCMDevice
 PCM device name. More...
 
const char * m_pPassthroughDevice
 passthrough device name More...
 
bool m_appendAES
 flag ato utomatic append AES More...
 
bool m_normalize
 flag to use volume normalize More...
 
const int m_normalizeSamples = 4096
 number of normalize samples More...
 
int m_normalizeCounter
 normalize sample counter More...
 
uint32_t m_normalizeAverage [NORMALIZE_MAX_INDEX]
 average of n last normalize sample blocks More...
 
int m_normalizeIndex
 index into normalize average table More...
 
int m_normalizeReady
 index normalize counter More...
 
int m_normalizeFactor
 current normalize factor More...
 
const int m_normalizeMinFactor = 100
 min. normalize factor More...
 
int m_normalizeMaxFactor
 max. normalize factor More...
 
bool m_compression
 flag to use compress volume More...
 
int m_compressionFactor
 current compression factor More...
 
int m_compressionMaxFactor
 max. compression factor More...
 
int m_amplifier
 software volume amplify factor More...
 
int m_stereoDescent
 volume descent for stereo More...
 
int m_volume
 current volume (0 .. 1000) More...
 
int m_useEqualizer
 flag to use equalizer More...
 
float m_equalizerBand [18]
 equalizer band More...
 
const char * m_pMixerDevice
 mixer device name (not used) More...
 
const char * m_pMixerChannel
 mixer channel name More...
 
int m_filterChanged = 0
 filter has changed More...
 
int m_filterReady = 0
 filter is ready More...
 
AVFilterGraph * m_pFilterGraph
 
AVFilterContext * m_pBuffersrcCtx
 
AVFilterContext * m_pBuffersinkCtx
 
cSoftHdRingbuffer m_pRingbuffer {RINGBUFFER_SIZE}
 sample ring buffer More...
 
snd_pcm_t * m_pAlsaPCMHandle
 alsa pcm handle More...
 
snd_mixer_t * m_pAlsaMixer
 alsa mixer handle More...
 
snd_mixer_elem_t * m_pAlsaMixerElem
 alsa mixer element More...
 
int m_alsaRatio
 internal -> mixer ratio * 1000 More...
 
bool m_alsaUseMmap
 use mmap More...
 
bool m_alsaCanPause
 hw supports pause More...
 

Static Private Attributes

static constexpr int AUDIO_MIN_BUFFER_FREE = 3072 * 8 * 8
 Minimum free space in audio buffer 8 packets for 8 channels. More...
 
static constexpr unsigned RINGBUFFER_SIZE = 3 * 5 * 7 * 8 * 2 * 1000
 default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8) More...
 

Detailed Description

cSoftHdAudio - Audio class

Definition at line 45 of file audio.h.

Constructor & Destructor Documentation

◆ cSoftHdAudio()

cSoftHdAudio::cSoftHdAudio ( cSoftHdDevice device)

◆ ~cSoftHdAudio()

cSoftHdAudio::~cSoftHdAudio ( void  )
virtual

cSoftHdAudio denstructor

Definition at line 105 of file audio.cpp.

Member Function Documentation

◆ AlsaExit()

void cSoftHdAudio::AlsaExit ( void  )
private

Cleanup alsa audio output module.

Definition at line 1569 of file audio.cpp.

References m_pAlsaMixer, m_pAlsaMixerElem, and m_pAlsaPCMHandle.

Referenced by Exit().

◆ AlsaInit()

void cSoftHdAudio::AlsaInit ( void  )
private

Initialize alsa audio output module.

Definition at line 1553 of file audio.cpp.

References AlsaInitMixer(), AlsaInitPCMDevice(), and AlsaNoopCallback().

Referenced by LazyInit().

◆ AlsaInitMixer()

void cSoftHdAudio::AlsaInitMixer ( void  )
private

Initialize alsa mixer.

Definition at line 1367 of file audio.cpp.

References L_SOUND, LOGDEBUG2, LOGERROR, m_alsaRatio, m_pAlsaMixer, m_pAlsaMixerElem, m_pMixerChannel, and m_pMixerDevice.

Referenced by AlsaInit().

◆ AlsaInitPCMDevice()

void cSoftHdAudio::AlsaInitPCMDevice ( void  )
private

Search for an alsa pcm device and open it.

Definition at line 1295 of file audio.cpp.

References FindAlsaDevice(), L_SOUND, LOGDEBUG2, LOGERROR, LOGFATAL, LOGINFO, LOGWARNING, m_pAlsaPCMHandle, m_passthrough, m_pPassthroughDevice, m_pPCMDevice, and OpenAlsaDevice().

Referenced by AlsaInit().

◆ AlsaSetup()

int cSoftHdAudio::AlsaSetup ( int  channels,
int  sample_rate,
int  passthrough 
)
private

Setup alsa audio for requested format.

Parameters
channelsChannels requested
sample_rateSampleRate requested
passthroughuse pass-through (AC-3, ...) device
Return values
0everything ok
1didn't support hw channels, downmix set -> retest
-1something gone wrong
Todo:
FIXME: remove pointer for freq + channels

Definition at line 1444 of file audio.cpp.

References FlushAlsaBuffers(), L_SOUND, LOGDEBUG2, LOGERROR, LOGINFO, LOGWARNING, m_alsaCanPause, m_alsaUseMmap, m_downmix, m_hwNumChannels, m_hwSampleRate, m_pAlsaPCMHandle, m_pAudioThread, cAudioThread::Stop(), and XrunRecovery().

Referenced by InitFilter(), and Setup().

◆ AlsaSetVolume()

void cSoftHdAudio::AlsaSetVolume ( int  volume)
private

Set alsa mixer volume (0-1000)

Parameters
volumevolume (0 .. 1000)

Definition at line 1421 of file audio.cpp.

References m_alsaRatio, m_pAlsaMixer, and m_pAlsaMixerElem.

Referenced by SetVolume().

◆ 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 738 of file audio.cpp.

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

Referenced by Filter().

◆ Compress()

void cSoftHdAudio::Compress ( uint16_t *  samples,
int  count 
)
private

Compress audio.

Parameters
samplessample buffer
countnumber of bytes in sample buffer

Definition at line 262 of file audio.cpp.

References L_SOUND, LOGDEBUG2, m_bytesPerSample, m_compressionFactor, and m_compressionMaxFactor.

Referenced by EnqueueFrame().

◆ CyclicCall()

bool cSoftHdAudio::CyclicCall ( void  )

Cyclic audio playback call.

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

Returns
true if data was written, false otherwise

Definition at line 1118 of file audio.cpp.

References AUDIO, cSoftHdRingbuffer::GetReadPointer(), LOGERROR, LOGWARNING, m_alsaUseMmap, m_eventQueue, m_mutex, m_pAlsaPCMHandle, m_passthrough, m_paused, m_pauseMutex, m_pRingbuffer, m_softVolume, m_volume, cSoftHdRingbuffer::ReadAdvance(), and SoftAmplify().

Referenced by cAudioThread::Action().

◆ 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 599 of file audio.cpp.

References GetOutputPtsMsInternal(), HasPts(), L_AV_SYNC, LOGDEBUG2, m_mutex, m_pAlsaPCMHandle, m_pRingbuffer, MsToFrames(), cSoftHdRingbuffer::ReadAdvance(), Timestamp2String(), and cSoftHdRingbuffer::UsedBytes().

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

◆ Enqueue()

void cSoftHdAudio::Enqueue ( uint16_t *  buffer,
int  count,
AVFrame *  frame 
)

Send audio data to ringbuffer.

Parameters
bufferdata buffer
countnumber of bytes in data buffer
framedecoded frame (used to get frame parameters)

Definition at line 657 of file audio.cpp.

References AV_NOPTS_VALUE, LOGERROR, m_inputPts, m_mutex, m_pRingbuffer, and cSoftHdRingbuffer::Write().

Referenced by cAudioDecoder::DecodePassthrough(), and EnqueueFrame().

◆ EnqueueFrame()

void cSoftHdAudio::EnqueueFrame ( AVFrame *  frame)
private

Place samples in audio output queue.

Parameters
frameaudio frame

Definition at line 627 of file audio.cpp.

References Compress(), Enqueue(), m_bytesPerSample, m_compression, m_normalize, Normalize(), and ReorderAudioFrame().

Referenced by Filter().

◆ Exit()

void cSoftHdAudio::Exit ( void  )

Cleanup audio output module.

Definition at line 1036 of file audio.cpp.

References AlsaExit(), L_SOUND, LOGDEBUG2, m_initialized, m_pAudioThread, m_pFilterGraph, and cAudioThread::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 771 of file audio.cpp.

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

Referenced by cAudioDecoder::Decode().

◆ FilterGetFrame()

AVFrame * cSoftHdAudio::FilterGetFrame ( void  )
private

Get frame from filter sink.

Returns
pointer to AVFrame if success, NULL otherwise

Definition at line 705 of file audio.cpp.

References LOGERROR, and m_pBuffersinkCtx.

Referenced by Filter().

◆ FindAlsaDevice()

char * cSoftHdAudio::FindAlsaDevice ( const char *  devname,
const char *  hint,
int  passthrough 
)
private

Find alsa device giving some search hints.

Parameters
devnameinterface identification (e.g. "pcm")
hintstring to compare with device name hints
passthroughset, if we want a passthrough device
Returns
an opened alsa device name if successful, NULL otherwise NOTE: Returned string is allocated and must be freed by caller

Definition at line 1259 of file audio.cpp.

References LOGWARNING, and OpenAlsaDevice().

Referenced by AlsaInitPCMDevice().

◆ FlushAlsaBuffers()

void cSoftHdAudio::FlushAlsaBuffers ( void  )

◆ FlushBuffers()

void cSoftHdAudio::FlushBuffers ( void  )

Flush audio buffers.

Stop alsa player if running, otherwise flush the alsa buffers and force a filter init

Definition at line 815 of file audio.cpp.

References AV_NOPTS_VALUE, FlushAlsaBuffers(), L_SOUND, LOGDEBUG2, m_filterChanged, m_initialized, m_inputPts, m_mutex, m_pRingbuffer, and cSoftHdRingbuffer::Reset().

Referenced by cSoftHdDevice::ClearAudio().

◆ FramesToMs()

int cSoftHdAudio::FramesToMs ( int  frames)
inlineprivate

Definition at line 184 of file audio.h.

References m_hwSampleRate.

Referenced by GetHardwareOutputPtsMs(), and GetOutputPtsMsInternal().

◆ GetFreeBytes()

int cSoftHdAudio::GetFreeBytes ( void  )

Get free bytes in audio ringbuffer.

Definition at line 835 of file audio.cpp.

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

◆ 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 884 of file audio.cpp.

References AV_NOPTS_VALUE, FramesToMs(), GetOutputPtsMsInternal(), L_SOUND, LOGDEBUG2, m_hwSampleRate, m_inputPts, m_mutex, and m_pAlsaPCMHandle.

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

◆ GetHardwareOutputPtsTimebaseUnits()

int64_t cSoftHdAudio::GetHardwareOutputPtsTimebaseUnits ( void  )

Get the hardware output PTS in timebase units.

Returns
presentation timestamp in timebase units

Definition at line 908 of file audio.cpp.

References AV_NOPTS_VALUE, GetHardwareOutputPtsMs(), and MsToPts().

Referenced by cSoftHdDevice::GetSTC().

◆ GetInputPtsMs()

int64_t cSoftHdAudio::GetInputPtsMs ( void  )
inline

Definition at line 66 of file audio.h.

References m_inputPts, and PtsToMs().

Referenced by cSoftHdDevice::IsBufferingThresholdReached().

◆ 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 863 of file audio.cpp.

References GetOutputPtsMsInternal(), and m_mutex.

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

◆ GetOutputPtsMsInternal()

int64_t cSoftHdAudio::GetOutputPtsMsInternal ( void  )
private

◆ GetPassthrough()

int cSoftHdAudio::GetPassthrough ( void  ) const
inline

Definition at line 64 of file audio.h.

References m_passthrough.

Referenced by cAudioDecoder::cAudioDecoder().

◆ GetUsedBytes()

int cSoftHdAudio::GetUsedBytes ( void  )

Get used bytes in audio ringbuffer.

Definition at line 845 of file audio.cpp.

References m_pRingbuffer, and cSoftHdRingbuffer::UsedBytes().

Referenced by cVideoRender::LogDroppedDuped().

◆ HasPts()

bool cSoftHdAudio::HasPts ( void  )
inline

◆ InitFilter()

int cSoftHdAudio::InitFilter ( AVCodecContext *  audioCtx)
private

Init filter.

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

Definition at line 424 of file audio.cpp.

References AlsaSetup(), L_SOUND, LOGDEBUG2, LOGERROR, LOGWARNING, m_downmix, m_equalizerBand, m_filterChanged, m_filterReady, m_hwNumChannels, m_hwSampleRate, m_pBuffersinkCtx, m_pBuffersrcCtx, m_pFilterGraph, m_pTimebase, and m_useEqualizer.

Referenced by CheckForFilterReady().

◆ IsBufferFull()

bool cSoftHdAudio::IsBufferFull ( void  )
inline

◆ IsPaused()

bool cSoftHdAudio::IsPaused ( void  )
inline

Definition at line 54 of file audio.h.

References m_paused.

Referenced by cVideoRender::DisplayFrame().

◆ LazyInit()

void cSoftHdAudio::LazyInit ( void  )

Initialize audio output module.

Definition at line 1025 of file audio.cpp.

References AlsaInit(), and m_initialized.

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

◆ MsToFrames()

int cSoftHdAudio::MsToFrames ( int  milliseconds)
inlineprivate

Definition at line 183 of file audio.h.

References m_hwSampleRate.

Referenced by DropSamplesOlderThanPtsMs().

◆ MsToPts()

int64_t cSoftHdAudio::MsToPts ( int64_t  ptsMs)
inlineprivate

Definition at line 182 of file audio.h.

References m_pTimebase.

Referenced by GetHardwareOutputPtsTimebaseUnits().

◆ Normalize()

void cSoftHdAudio::Normalize ( uint16_t *  samples,
int  count 
)
private

Normalize audio.

Parameters
samplessample buffer
countnumber of bytes in sample buffer

Definition at line 181 of file audio.cpp.

References L_SOUND, LOGDEBUG2, m_bytesPerSample, m_normalizeAverage, m_normalizeCounter, m_normalizeFactor, m_normalizeIndex, m_normalizeMaxFactor, m_normalizeMinFactor, m_normalizeReady, m_normalizeSamples, and NORMALIZE_MAX_INDEX.

Referenced by EnqueueFrame().

◆ OpenAlsaDevice()

char * cSoftHdAudio::OpenAlsaDevice ( const char *  device,
int  passthrough 
)
private

Open alsa device.

Parameters
devicealsa device
passthroughset, if this is a passthrough device
Returns
the alsa device if successful, NULL otherwise

Definition at line 1207 of file audio.cpp.

References L_SOUND, LOGDEBUG2, LOGWARNING, m_appendAES, and m_pAlsaPCMHandle.

Referenced by AlsaInitPCMDevice(), and FindAlsaDevice().

◆ ProcessEvents()

void cSoftHdAudio::ProcessEvents ( void  )

Process queued events and forward to event receiver.

Definition at line 1585 of file audio.cpp.

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

Referenced by cAudioThread::Action().

◆ PtsToMs()

int64_t cSoftHdAudio::PtsToMs ( int64_t  pts)
inlineprivate

Definition at line 181 of file audio.h.

References m_pTimebase.

Referenced by GetInputPtsMs(), and GetOutputPtsMsInternal().

◆ SetAutoAES()

void cSoftHdAudio::SetAutoAES ( bool  appendAes)
inline

Definition at line 77 of file audio.h.

References m_appendAES.

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 987 of file audio.cpp.

References m_compression, m_compressionFactor, and m_compressionMaxFactor.

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

◆ SetDownmix()

void cSoftHdAudio::SetDownmix ( int  downMix)
inline

Definition at line 71 of file audio.h.

References m_downmix.

Referenced by cMenuSetupSoft::Store().

◆ SetEq()

void cSoftHdAudio::SetEq ( int  band[18],
int  onoff 
)

Set equalizer bands.

Parameters
bandsetting frequenz bands
onoffset using equalizer

Definition at line 348 of file audio.cpp.

References m_equalizerBand, m_filterChanged, and m_useEqualizer.

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

◆ 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 975 of file audio.cpp.

References m_normalize, and m_normalizeMaxFactor.

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

◆ SetPassthrough()

void cSoftHdAudio::SetPassthrough ( int  mask)

Set audio passthrough mask.

Parameters
maskpassthrough mask (as a bitmask)

Definition at line 1016 of file audio.cpp.

References m_passthrough.

Referenced by cSoftHdDevice::SetPassthrough().

◆ SetPaused()

void cSoftHdAudio::SetPaused ( bool  pause)

Set audio playback paused state.

Parameters
pausetrue to pause, false to resume

Definition at line 944 of file audio.cpp.

References L_SOUND, LOGDEBUG2, LOGERROR, m_alsaCanPause, m_pAlsaPCMHandle, m_paused, and m_pauseMutex.

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

◆ SetSoftvol()

void cSoftHdAudio::SetSoftvol ( bool  softVolume)
inline

Definition at line 72 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 1005 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 78 of file audio.h.

References m_pTimebase.

Referenced by cAudioDecoder::DecodePassthrough().

◆ Setup()

int cSoftHdAudio::Setup ( AVCodecContext *  ctx,
int  samplerate,
int  channels,
int  passthrough 
)

Setup alsa.

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

Parameters
AudioCtxAVCodec audio decoding context
sampleratestream samplerate
channelsstream nb of channels
passthroughpassthrough enabled
Return values
0everything ok
errsomething gone wrong

Definition at line 682 of file audio.cpp.

References AlsaSetup(), LOGERROR, m_downmix, m_hwNumChannels, m_hwSampleRate, and m_pTimebase.

Referenced by cAudioDecoder::UpdateFormat().

◆ SetVolume()

void cSoftHdAudio::SetVolume ( int  volume)

Set mixer volume (0-1000)

Parameters
volumevolume (0 .. 1000)

Definition at line 921 of file audio.cpp.

References AlsaSetVolume(), m_amplifier, m_hwNumChannels, m_passthrough, m_softVolume, m_stereoDescent, and m_volume.

Referenced by SetStereoDescent(), and cSoftHdDevice::SetVolumeDevice().

◆ SoftAmplify()

void cSoftHdAudio::SoftAmplify ( int16_t *  samples,
int  count 
)
private

Software amplifier.

Parameters
samplessample buffer
countnumber of bytes in sample buffer
Todo:
FIXME: this does hard clipping

Definition at line 319 of file audio.cpp.

References m_amplifier, m_bytesPerSample, and m_volume.

Referenced by CyclicCall().

◆ XrunRecovery()

void cSoftHdAudio::XrunRecovery ( void  )
private

xrun recovery

Definition at line 1059 of file audio.cpp.

References LOGERROR, and m_pAlsaPCMHandle.

Referenced by AlsaSetup().

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 86 of file audio.h.

Referenced by IsBufferFull().

◆ m_alsaCanPause

bool cSoftHdAudio::m_alsaCanPause
private

hw supports pause

Definition at line 170 of file audio.h.

Referenced by AlsaSetup(), cSoftHdAudio(), and SetPaused().

◆ m_alsaRatio

int cSoftHdAudio::m_alsaRatio
private

internal -> mixer ratio * 1000

Definition at line 168 of file audio.h.

Referenced by AlsaInitMixer(), and AlsaSetVolume().

◆ m_alsaUseMmap

bool cSoftHdAudio::m_alsaUseMmap
private

use mmap

Definition at line 169 of file audio.h.

Referenced by AlsaSetup(), and CyclicCall().

◆ m_amplifier

int cSoftHdAudio::m_amplifier
private

software volume amplify factor

Definition at line 132 of file audio.h.

Referenced by SetVolume(), and SoftAmplify().

◆ m_appendAES

bool cSoftHdAudio::m_appendAES
private

flag ato utomatic append AES

Definition at line 113 of file audio.h.

Referenced by cSoftHdAudio(), OpenAlsaDevice(), and SetAutoAES().

◆ m_bytesPerSample

const int cSoftHdAudio::m_bytesPerSample = 2
private

number of bytes per sample

Definition at line 96 of file audio.h.

Referenced by Compress(), EnqueueFrame(), Normalize(), and SoftAmplify().

◆ m_compression

bool cSoftHdAudio::m_compression
private

flag to use compress volume

Definition at line 127 of file audio.h.

Referenced by EnqueueFrame(), and SetCompression().

◆ m_compressionFactor

int cSoftHdAudio::m_compressionFactor
private

current compression factor

Definition at line 128 of file audio.h.

Referenced by Compress(), cSoftHdAudio(), FlushAlsaBuffers(), and SetCompression().

◆ m_compressionMaxFactor

int cSoftHdAudio::m_compressionMaxFactor
private

max. compression factor

Definition at line 129 of file audio.h.

Referenced by Compress(), FlushAlsaBuffers(), and SetCompression().

◆ m_downmix

int cSoftHdAudio::m_downmix
private

set stereo downmix

Definition at line 104 of file audio.h.

Referenced by AlsaSetup(), cSoftHdAudio(), InitFilter(), SetDownmix(), and Setup().

◆ m_equalizerBand

float cSoftHdAudio::m_equalizerBand[18]
private

equalizer band

Definition at line 138 of file audio.h.

Referenced by InitFilter(), and SetEq().

◆ m_eventQueue

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

event queue for incoming events

Definition at line 102 of file audio.h.

Referenced by CyclicCall(), and ProcessEvents().

◆ m_filterChanged

int cSoftHdAudio::m_filterChanged = 0
private

filter has changed

Definition at line 145 of file audio.h.

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

◆ m_filterReady

int cSoftHdAudio::m_filterReady = 0
private

filter is ready

Definition at line 146 of file audio.h.

Referenced by CheckForFilterReady(), and InitFilter().

◆ m_hwNumChannels

unsigned int cSoftHdAudio::m_hwNumChannels
private

number of hardware channels

Definition at line 98 of file audio.h.

Referenced by AlsaSetup(), cSoftHdAudio(), InitFilter(), Setup(), and SetVolume().

◆ m_hwSampleRate

unsigned int cSoftHdAudio::m_hwSampleRate
private

hardware sample rate in Hz

Definition at line 97 of file audio.h.

Referenced by AlsaSetup(), cSoftHdAudio(), FramesToMs(), GetHardwareOutputPtsMs(), InitFilter(), MsToFrames(), and Setup().

◆ m_initialized

bool cSoftHdAudio::m_initialized = false
private

class initialized

Definition at line 95 of file audio.h.

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

◆ m_inputPts

int64_t cSoftHdAudio::m_inputPts
private

pts clock (last pts in ringbuffer)

Definition at line 106 of file audio.h.

Referenced by cSoftHdAudio(), Enqueue(), FlushBuffers(), GetHardwareOutputPtsMs(), GetInputPtsMs(), GetOutputPtsMsInternal(), and HasPts().

◆ m_mutex

std::mutex cSoftHdAudio::m_mutex
private

mutex for thread safety

Definition at line 100 of file audio.h.

Referenced by CyclicCall(), DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), GetFreeBytes(), GetHardwareOutputPtsMs(), and GetOutputPtsMs().

◆ m_normalize

bool cSoftHdAudio::m_normalize
private

flag to use volume normalize

Definition at line 116 of file audio.h.

Referenced by EnqueueFrame(), and SetNormalize().

◆ m_normalizeAverage

uint32_t cSoftHdAudio::m_normalizeAverage[NORMALIZE_MAX_INDEX]
private

average of n last normalize sample blocks

Definition at line 119 of file audio.h.

Referenced by FlushAlsaBuffers(), and Normalize().

◆ m_normalizeCounter

int cSoftHdAudio::m_normalizeCounter
private

normalize sample counter

Definition at line 118 of file audio.h.

Referenced by FlushAlsaBuffers(), and Normalize().

◆ m_normalizeFactor

int cSoftHdAudio::m_normalizeFactor
private

current normalize factor

Definition at line 122 of file audio.h.

Referenced by FlushAlsaBuffers(), and Normalize().

◆ m_normalizeIndex

int cSoftHdAudio::m_normalizeIndex
private

index into normalize average table

Definition at line 120 of file audio.h.

Referenced by Normalize().

◆ m_normalizeMaxFactor

int cSoftHdAudio::m_normalizeMaxFactor
private

max. normalize factor

Definition at line 124 of file audio.h.

Referenced by Normalize(), and SetNormalize().

◆ m_normalizeMinFactor

const int cSoftHdAudio::m_normalizeMinFactor = 100
private

min. normalize factor

Definition at line 123 of file audio.h.

Referenced by Normalize().

◆ m_normalizeReady

int cSoftHdAudio::m_normalizeReady
private

index normalize counter

Definition at line 121 of file audio.h.

Referenced by FlushAlsaBuffers(), and Normalize().

◆ m_normalizeSamples

const int cSoftHdAudio::m_normalizeSamples = 4096
private

number of normalize samples

Definition at line 117 of file audio.h.

Referenced by Normalize().

◆ m_pAlsaMixer

snd_mixer_t* cSoftHdAudio::m_pAlsaMixer
private

alsa mixer handle

Definition at line 166 of file audio.h.

Referenced by AlsaExit(), AlsaInitMixer(), AlsaSetVolume(), and cSoftHdAudio().

◆ m_pAlsaMixerElem

snd_mixer_elem_t* cSoftHdAudio::m_pAlsaMixerElem
private

alsa mixer element

Definition at line 167 of file audio.h.

Referenced by AlsaExit(), AlsaInitMixer(), AlsaSetVolume(), and cSoftHdAudio().

◆ m_pAlsaPCMHandle

snd_pcm_t* cSoftHdAudio::m_pAlsaPCMHandle
private

◆ m_passthrough

int cSoftHdAudio::m_passthrough
private

passthrough mask

Definition at line 110 of file audio.h.

Referenced by AlsaInitPCMDevice(), cSoftHdAudio(), CyclicCall(), GetPassthrough(), SetPassthrough(), and SetVolume().

◆ m_pAudioThread

cAudioThread* cSoftHdAudio::m_pAudioThread = nullptr
private

pointer to audio thread

Definition at line 92 of file audio.h.

Referenced by AlsaSetup(), and Exit().

◆ m_paused

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

audio is paused

Definition at line 107 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 101 of file audio.h.

Referenced by CyclicCall(), and SetPaused().

◆ m_pBuffersinkCtx

AVFilterContext* cSoftHdAudio::m_pBuffersinkCtx
private

Definition at line 149 of file audio.h.

Referenced by FilterGetFrame(), and InitFilter().

◆ m_pBuffersrcCtx

AVFilterContext* cSoftHdAudio::m_pBuffersrcCtx
private

Definition at line 148 of file audio.h.

Referenced by Filter(), and InitFilter().

◆ m_pConfig

cSoftHdConfig* cSoftHdAudio::m_pConfig
private

pointer to config

Definition at line 88 of file audio.h.

Referenced by cSoftHdAudio().

◆ m_pDevice

cSoftHdDevice* cSoftHdAudio::m_pDevice
private

pointer to device

Definition at line 87 of file audio.h.

Referenced by cSoftHdAudio().

◆ m_pEventReceiver

IEventReceiver* cSoftHdAudio::m_pEventReceiver
private

pointer to event receiver

Definition at line 89 of file audio.h.

Referenced by cSoftHdAudio(), and ProcessEvents().

◆ m_pFilterGraph

AVFilterGraph* cSoftHdAudio::m_pFilterGraph
private

Definition at line 147 of file audio.h.

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

◆ m_pMixerChannel

const char* cSoftHdAudio::m_pMixerChannel
private

mixer channel name

Definition at line 142 of file audio.h.

Referenced by AlsaInitMixer(), and cSoftHdAudio().

◆ m_pMixerDevice

const char* cSoftHdAudio::m_pMixerDevice
private

mixer device name (not used)

Definition at line 141 of file audio.h.

Referenced by AlsaInitMixer(), and cSoftHdAudio().

◆ m_pPassthroughDevice

const char* cSoftHdAudio::m_pPassthroughDevice
private

passthrough device name

Definition at line 112 of file audio.h.

Referenced by AlsaInitPCMDevice(), and cSoftHdAudio().

◆ m_pPCMDevice

const char* cSoftHdAudio::m_pPCMDevice
private

PCM device name.

Definition at line 111 of file audio.h.

Referenced by AlsaInitPCMDevice(), and cSoftHdAudio().

◆ m_pRingbuffer

cSoftHdRingbuffer cSoftHdAudio::m_pRingbuffer {RINGBUFFER_SIZE}
private

◆ m_pTimebase

AVRational* cSoftHdAudio::m_pTimebase
private

pointer to AVCodecContext pkts_timebase

Definition at line 99 of file audio.h.

Referenced by InitFilter(), MsToPts(), PtsToMs(), SetTimebase(), and Setup().

◆ m_softVolume

bool cSoftHdAudio::m_softVolume
private

flag to use soft volume

Definition at line 109 of file audio.h.

Referenced by cSoftHdAudio(), CyclicCall(), SetSoftvol(), and SetVolume().

◆ m_stereoDescent

int cSoftHdAudio::m_stereoDescent
private

volume descent for stereo

Definition at line 133 of file audio.h.

Referenced by SetStereoDescent(), and SetVolume().

◆ m_useEqualizer

int cSoftHdAudio::m_useEqualizer
private

flag to use equalizer

Definition at line 137 of file audio.h.

Referenced by InitFilter(), and SetEq().

◆ m_volume

int cSoftHdAudio::m_volume
private

current volume (0 .. 1000)

Definition at line 134 of file audio.h.

Referenced by CyclicCall(), SetStereoDescent(), SetVolume(), and SoftAmplify().

◆ 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 154 of file audio.h.


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