vdr-plugin-softhddevice-drm-gles 1.6.2
Audio Module

Audio and Alsa Interface. More...

Classes

class  cSoftHdAudio
 Audio Interface. More...
 
class  cPidController
 PID Controller. More...
 
class  cSoftHdRingbuffer
 Ringbuffer (FIFO) Implementation. More...
 

Macros

#define atomic_set(ptr, val)   __atomic_store_n(ptr, val, __ATOMIC_SEQ_CST)
 
#define atomic_read(ptr)   __atomic_load_n(ptr, __ATOMIC_SEQ_CST)
 
#define atomic_inc(ptr)   __atomic_add_fetch(ptr, 1, __ATOMIC_SEQ_CST)
 
#define atomic_dec(ptr)   __atomic_sub_fetch(ptr, 1, __ATOMIC_SEQ_CST)
 
#define atomic_add(val, ptr)   __atomic_add_fetch(ptr, val, __ATOMIC_SEQ_CST)
 
#define atomic_sub(val, ptr)   __atomic_sub_fetch(ptr, val, __ATOMIC_SEQ_CST)
 

Typedefs

typedef volatile int atomic_t
 Atomic Wrapper Macros.
 

Functions

static void ReorderAudioFrame (uint16_t *buf, int size, int channels)
 Reorder audio frame.
 
static void AlsaNoopCallback (__attribute__((unused)) const char *file, __attribute__((unused)) int line, __attribute__((unused)) const char *function, __attribute__((unused)) int err, __attribute__((unused)) const char *fmt,...)
 Empty log callback.
 
 cSoftHdAudio::cSoftHdAudio (cSoftHdDevice *)
 Create a new audio context.
 
void cSoftHdAudio::Normalize (uint16_t *, int)
 Normalize audio samples.
 
void cSoftHdAudio::Compress (uint16_t *, int)
 Compress audio samples.
 
void cSoftHdAudio::SoftAmplify (int16_t *, int)
 Amplify the samples in software.
 
void cSoftHdAudio::SetEq (int[18], int)
 Set equalizer bands.
 
int cSoftHdAudio::InitFilter (AVCodecContext *)
 Init audio filters.
 
void cSoftHdAudio::DropSamplesOlderThanPtsMs (int64_t)
 Drop samples older than the given PTS.
 
void cSoftHdAudio::EnqueueFrame (AVFrame *)
 Place samples in audio output queue.
 
void cSoftHdAudio::BuildPauseBurst (void)
 Build a pause spdif burst with the size of the last recognized normal spdif audio.
 
void cSoftHdAudio::EnqueueSpdif (uint16_t *, int, AVFrame *)
 Enqueue prepared spdif bursts in audio output queue.
 
void cSoftHdAudio::Enqueue (uint16_t *, int, AVFrame *)
 Send audio data to ringbuffer.
 
int cSoftHdAudio::Setup (AVCodecContext *, int, int, int)
 Alsa setup wrapper.
 
AVFramecSoftHdAudio::FilterGetFrame (void)
 Get frame from filter sink.
 
int cSoftHdAudio::CheckForFilterReady (AVCodecContext *)
 Check if the filter has changed and is ready, init the filter if needed.
 
void cSoftHdAudio::Filter (AVFrame *, AVCodecContext *)
 Send audio frame to filter and enqueue it.
 
void cSoftHdAudio::FlushBuffers (void)
 Flush audio buffers.
 
int cSoftHdAudio::GetUsedBytes (void)
 Get used bytes in audio ringbuffer.
 
int64_t cSoftHdAudio::GetOutputPtsMs (void)
 Get the output PTS of the ringbuffer.
 
int64_t cSoftHdAudio::GetOutputPtsMsInternal (void)
 
int64_t cSoftHdAudio::GetHardwareOutputPtsMs (void)
 Get the hardware output PTS in milliseconds.
 
int64_t cSoftHdAudio::GetHardwareOutputDelayMs (void)
 Get the hardware delay in milliseconds.
 
int64_t cSoftHdAudio::GetHardwareOutputPtsTimebaseUnits (void)
 Get the hardware output PTS in timebase units.
 
void cSoftHdAudio::SetVolume (int)
 Set mixer volume (0-1000)
 
void cSoftHdAudio::SetPaused (bool)
 Set audio playback pause state.
 
void cSoftHdAudio::SetNormalize (bool, int)
 Set normalize volume parameters.
 
void cSoftHdAudio::SetCompression (bool, int)
 Set volume compression parameters.
 
void cSoftHdAudio::SetStereoDescent (int)
 Set stereo loudness descent.
 
void cSoftHdAudio::SetPassthroughMask (int)
 Set audio passthrough mask.
 
void cSoftHdAudio::LazyInit (void)
 Initialize audio output module (alsa)
 
void cSoftHdAudio::Exit (void)
 Cleanup audio output module (alsa)
 
void cSoftHdAudio::HandleError (int)
 Handle an alsa error.
 
void cSoftHdAudio::FlushAlsaBuffers (void)
 Flush alsa buffers.
 
void cSoftHdAudio::DropAlsaBuffers (void)
 Drop alsa buffers.
 
void cSoftHdAudio::FlushAlsaBuffersInternal (bool)
 Flush alsa buffers internally.
 
virtual void cSoftHdAudio::Action (void)
 Audio thread loop, started with Start().
 
void cSoftHdAudio::Stop (void)
 Stop the thread.
 
bool cSoftHdAudio::CyclicCall (void)
 Cyclic audio playback call.
 
bool cSoftHdAudio::SendAudio (int)
 Write regular audio data from the ringbuffer to the hardware.
 
bool cSoftHdAudio::SendPause (void)
 Write pause to passthrough device.
 
void cSoftHdAudio::SetHwDelayBaseline (void)
 Set the hw delay baseline.
 
void cSoftHdAudio::ResetHwDelayBaseline (void)
 Reset the hw delay baseline.
 
void cSoftHdAudio::ProcessEvents (void)
 Process queued events and forward them to event receiver.
 
charcSoftHdAudio::OpenAlsaDevice (const char *, int)
 Opens an alsa device.
 
charcSoftHdAudio::FindAlsaDevice (const char *, const char *, int)
 Find alsa device giving some search hints.
 
void cSoftHdAudio::AlsaInitPCMDevice (void)
 Search for an alsa pcm device and open it.
 
void cSoftHdAudio::AlsaInitMixer (void)
 Initialize alsa mixer.
 
void cSoftHdAudio::AlsaSetVolume (int)
 Set alsa mixer volume (0-1000)
 
int cSoftHdAudio::AlsaSetup (int channels, int sample_rate, int passthrough)
 Setup alsa audio for requested format.
 
void cSoftHdAudio::AlsaInit (void)
 Initialize the alsa audio output module.
 
void cSoftHdAudio::AlsaExit (void)
 Cleanup the alsa audio output module.
 
void cSoftHdAudio::ClockDriftCompensation (void)
 Calculate clock drift compensation.
 
 cPidController::cPidController (double, double, double, double)
 Create a PID Controller.
 
double cPidController::Update (double, double)
 Calculate the new output value.
 
void cPidController::Reset ()
 Reset the internal state (integral sum and error history).
 
 cSoftHdRingbuffer::cSoftHdRingbuffer (size_t)
 cSoftHdRingbuffer constructor
 
 cSoftHdRingbuffer::~cSoftHdRingbuffer (void)
 cSoftHdRingbuffer destructor
 
void cSoftHdRingbuffer::Reset (void)
 Reset ring buffer pointers.
 
size_t cSoftHdRingbuffer::WriteAdvance (size_t)
 Advance write pointer in ring buffer.
 
size_t cSoftHdRingbuffer::Write (const void *, size_t)
 Write to a ring buffer.
 
size_t cSoftHdRingbuffer::GetWritePointer (void **)
 Get write pointer and free bytes at this position of ring buffer.
 
size_t cSoftHdRingbuffer::ReadAdvance (size_t)
 Advance read pointer in ring buffer.
 
size_t cSoftHdRingbuffer::Read (void *, size_t)
 Read from a ring buffer.
 
size_t cSoftHdRingbuffer::GetReadPointer (const void **)
 Get read pointer and used bytes at this position of ring buffer.
 
size_t cSoftHdRingbuffer::FreeBytes (void)
 Get free bytes in ring buffer.
 
size_t cSoftHdRingbuffer::UsedBytes (void)
 Get used bytes in ring buffer.
 

Detailed Description

Audio and Alsa Interface.

This file defines cSoftHdAudio, which holds all functions we need to deal with audio, e.g.handling the audio stream and sending it to hardware.

Macro Definition Documentation

◆ atomic_add

#define atomic_add (   val,
  ptr 
)    __atomic_add_fetch(ptr, val, __ATOMIC_SEQ_CST)

Definition at line 32 of file ringbuffer.h.

◆ atomic_dec

#define atomic_dec (   ptr)    __atomic_sub_fetch(ptr, 1, __ATOMIC_SEQ_CST)

Definition at line 31 of file ringbuffer.h.

◆ atomic_inc

#define atomic_inc (   ptr)    __atomic_add_fetch(ptr, 1, __ATOMIC_SEQ_CST)

Definition at line 30 of file ringbuffer.h.

◆ atomic_read

#define atomic_read (   ptr)    __atomic_load_n(ptr, __ATOMIC_SEQ_CST)

Definition at line 29 of file ringbuffer.h.

◆ atomic_set

#define atomic_set (   ptr,
  val 
)    __atomic_store_n(ptr, val, __ATOMIC_SEQ_CST)

Definition at line 28 of file ringbuffer.h.

◆ atomic_sub

#define atomic_sub (   val,
  ptr 
)    __atomic_sub_fetch(ptr, val, __ATOMIC_SEQ_CST)

Definition at line 33 of file ringbuffer.h.

Typedef Documentation

◆ atomic_t

Atomic Wrapper Macros.

atomic type, 24 bit useable

Definition at line 26 of file ringbuffer.h.

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

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

◆ AlsaExit()

void cSoftHdAudio::AlsaExit ( void  )
private

Cleanup the alsa audio output module.

Definition at line 1815 of file audio.cpp.

References cSoftHdAudio::m_pAlsaMixer, cSoftHdAudio::m_pAlsaMixerElem, and cSoftHdAudio::m_pAlsaPCMHandle.

Referenced by cSoftHdAudio::Exit().

◆ AlsaInit()

void cSoftHdAudio::AlsaInit ( void  )
private

Initialize the alsa audio output module.

Definition at line 1799 of file audio.cpp.

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

Referenced by cSoftHdAudio::LazyInit().

◆ AlsaInitMixer()

void cSoftHdAudio::AlsaInitMixer ( void  )
private

◆ AlsaInitPCMDevice()

◆ AlsaNoopCallback()

static void AlsaNoopCallback ( __attribute__((unused)) const char file,
__attribute__((unused)) int  line,
__attribute__((unused)) const char function,
__attribute__((unused)) int  err,
__attribute__((unused)) const char fmt,
  ... 
)
static

Empty log callback.

Definition at line 1787 of file audio.cpp.

Referenced by cSoftHdAudio::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
-1something gone wrong
Todo:
FIXME: remove pointer for freq + channels

Definition at line 1683 of file audio.cpp.

References cSoftHdAudio::DropAlsaBuffers(), L_SOUND, LOGDEBUG2, LOGERROR, LOGINFO, LOGWARNING, cSoftHdAudio::m_alsaBufferSizeFrames, cSoftHdAudio::m_alsaUseMmap, cSoftHdAudio::m_downmix, cSoftHdAudio::m_hwNumChannels, cSoftHdAudio::m_hwSampleRate, cSoftHdAudio::m_pAlsaPCMHandle, cSoftHdAudio::MsToFrames(), and cSoftHdAudio::Stop().

Referenced by cSoftHdAudio::InitFilter(), and cSoftHdAudio::Setup().

◆ AlsaSetVolume()

void cSoftHdAudio::AlsaSetVolume ( int  volume)
private

Set alsa mixer volume (0-1000)

Parameters
volumevolume (0 .. 1000)

Definition at line 1661 of file audio.cpp.

References cSoftHdAudio::m_alsaRatio, cSoftHdAudio::m_pAlsaMixer, and cSoftHdAudio::m_pAlsaMixerElem.

Referenced by cSoftHdAudio::SetVolume().

◆ BuildPauseBurst()

void cSoftHdAudio::BuildPauseBurst ( void  )
private

Build a pause spdif burst with the size of the last recognized normal spdif audio.

Definition at line 634 of file audio.cpp.

References IEC61937_NULL, IEC61937_PREAMBLE1, IEC61937_PREAMBLE2, cSoftHdAudio::m_pauseBurst, and cSoftHdAudio::m_spdifBurstSize.

Referenced by cSoftHdAudio::EnqueueSpdif().

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

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

Referenced by cSoftHdAudio::Filter().

◆ ClockDriftCompensation()

void cSoftHdAudio::ClockDriftCompensation ( void  )

◆ Compress()

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

Compress audio samples.

Parameters
samplessample buffer
countnumber of bytes in sample buffer

Definition at line 233 of file audio.cpp.

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

Referenced by cSoftHdAudio::EnqueueFrame().

◆ cPidController()

cPidController::cPidController ( double  kp,
double  ki,
double  kd,
double  maxOutput 
)

Create a PID Controller.

Parameters
kpProportional gain
kiIntegral gain
kdDerivative gain
maxOutputMax allowed output value (absolute)

Definition at line 36 of file pidcontroller.cpp.

References cPidController::integralGain, cPidController::maxIntegral, and cPidController::maxOutput.

◆ cSoftHdAudio()

◆ cSoftHdRingbuffer()

cSoftHdRingbuffer::cSoftHdRingbuffer ( size_t  size)

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

References cSoftHdAudio::HandleError(), L_SOUND, LOGDEBUG2, LOGERROR, cSoftHdAudio::m_mutex, cSoftHdAudio::m_pAlsaPCMHandle, cSoftHdAudio::m_passthrough, cSoftHdAudio::m_paused, cSoftHdAudio::m_pauseMutex, cSoftHdAudio::m_spdifBurstSize, cSoftHdAudio::SendAudio(), and cSoftHdAudio::SendPause().

Referenced by cSoftHdAudio::Action().

◆ DropAlsaBuffers()

void cSoftHdAudio::DropAlsaBuffers ( void  )
private

Drop alsa buffers.

Definition at line 1134 of file audio.cpp.

References cSoftHdAudio::FlushAlsaBuffersInternal().

Referenced by cSoftHdAudio::AlsaSetup().

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

References cSoftHdAudio::GetOutputPtsMsInternal(), cSoftHdAudio::HasInputPts(), L_AV_SYNC, LOGDEBUG2, cSoftHdAudio::m_fillLevel, cSoftHdAudio::m_mutex, cSoftHdAudio::m_pAlsaPCMHandle, cSoftHdAudio::m_pidController, cSoftHdAudio::m_pRingbuffer, cSoftHdAudio::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 608 of file audio.cpp.

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

Referenced by cSoftHdAudio::Filter().

◆ EnqueueSpdif()

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

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
framedecoded frame (used to get frame parameters)

Definition at line 655 of file audio.cpp.

References cSoftHdAudio::BuildPauseBurst(), cSoftHdAudio::Enqueue(), L_SOUND, LOGDEBUG2, cSoftHdAudio::m_pauseBurst, cSoftHdAudio::m_pauseMutex, and cSoftHdAudio::m_spdifBurstSize.

Referenced by cAudioDecoder::DecodePassthrough().

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

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

References cSoftHdAudio::CheckForFilterReady(), cSoftHdAudio::EnqueueFrame(), cSoftHdAudio::FilterGetFrame(), L_SOUND, LOGDEBUG2, LOGERROR, cSoftHdAudio::m_filterChanged, and cSoftHdAudio::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 752 of file audio.cpp.

References LOGERROR, and cSoftHdAudio::m_pBuffersinkCtx.

Referenced by cSoftHdAudio::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 1492 of file audio.cpp.

References LOGWARNING, and cSoftHdAudio::OpenAlsaDevice().

Referenced by cSoftHdAudio::AlsaInitPCMDevice().

◆ FlushAlsaBuffers()

void cSoftHdAudio::FlushAlsaBuffers ( void  )
private

Flush alsa buffers.

Definition at line 1126 of file audio.cpp.

References cSoftHdAudio::FlushAlsaBuffersInternal().

Referenced by cSoftHdAudio::FlushBuffers().

◆ FlushAlsaBuffersInternal()

◆ FlushBuffers()

◆ FreeBytes()

size_t cSoftHdRingbuffer::FreeBytes ( void  )

Get free bytes in ring buffer.

Returns
Number of bytes free in buffer

Definition at line 281 of file ringbuffer.cpp.

References atomic_read, cSoftHdRingbuffer::m_filled, and cSoftHdRingbuffer::m_size.

Referenced by cSoftHdAudio::IsBufferFull().

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

References AV_NOPTS_VALUE, cSoftHdAudio::FramesToMs(), cSoftHdAudio::m_hwSampleRate, cSoftHdAudio::m_inputPts, cSoftHdAudio::m_mutex, and cSoftHdAudio::m_pAlsaPCMHandle.

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

References AV_NOPTS_VALUE, cSoftHdAudio::FramesToMs(), cSoftHdAudio::GetOutputPtsMsInternal(), cSoftHdAudio::m_hwBaseline, cSoftHdAudio::m_hwSampleRate, cSoftHdAudio::m_inputPts, cSoftHdAudio::m_mutex, and cSoftHdAudio::m_pAlsaPCMHandle.

Referenced by cSoftHdPlayer::Action(), cVideoRender::DisplayFrame(), cSoftHdAudio::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 964 of file audio.cpp.

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

Referenced by cSoftHdDevice::GetSTC().

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

References cSoftHdAudio::GetOutputPtsMsInternal(), and cSoftHdAudio::m_mutex.

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

◆ GetOutputPtsMsInternal()

◆ GetReadPointer()

size_t cSoftHdRingbuffer::GetReadPointer ( const void **  rp)

Get read pointer and used bytes at this position of ring buffer.

Parameters
[out]rpRead pointer is placed here
Returns
The number of bytes that could be read from the ring buffer at the read pointer

Definition at line 256 of file ringbuffer.cpp.

References atomic_read, cSoftHdRingbuffer::m_filled, cSoftHdRingbuffer::m_pBufferEnd, and cSoftHdRingbuffer::m_pReadPointer.

Referenced by cSoftHdAudio::SendAudio().

◆ GetUsedBytes()

int cSoftHdAudio::GetUsedBytes ( void  )

Get used bytes in audio ringbuffer.

Definition at line 884 of file audio.cpp.

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

Referenced by cVideoRender::LogDroppedDuped().

◆ GetWritePointer()

size_t cSoftHdRingbuffer::GetWritePointer ( void **  wp)

Get write pointer and free bytes at this position of ring buffer.

Parameters
[out]wpWrite pointer is placed here
Returns
The number of bytes that could be placed in the ring buffer at the write pointer.

Definition at line 151 of file ringbuffer.cpp.

References atomic_read, cSoftHdRingbuffer::m_filled, cSoftHdRingbuffer::m_pBufferEnd, cSoftHdRingbuffer::m_pWritePointer, and cSoftHdRingbuffer::m_size.

◆ HandleError()

void cSoftHdAudio::HandleError ( int  error)
private

Handle an alsa error.

Definition at line 1111 of file audio.cpp.

References AUDIO, LOGERROR, cSoftHdAudio::m_eventQueue, cSoftHdAudio::m_pAlsaPCMHandle, and cSoftHdAudio::m_passthrough.

Referenced by cSoftHdAudio::CyclicCall().

◆ InitFilter()

int cSoftHdAudio::InitFilter ( AVCodecContext audioCtx)
private

Init audio filters.

The following alsa filters are set:

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

Definition at line 401 of file audio.cpp.

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

Referenced by cSoftHdAudio::CheckForFilterReady().

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

References cSoftHdAudio::AlsaInit(), and cSoftHdAudio::m_initialized.

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

◆ Normalize()

◆ OpenAlsaDevice()

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

Opens an alsa device.

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

Definition at line 1440 of file audio.cpp.

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

Referenced by cSoftHdAudio::AlsaInitPCMDevice(), and cSoftHdAudio::FindAlsaDevice().

◆ ProcessEvents()

void cSoftHdAudio::ProcessEvents ( void  )
private

Process queued events and forward them to event receiver.

Definition at line 1424 of file audio.cpp.

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

Referenced by cSoftHdAudio::Action().

◆ Read()

size_t cSoftHdRingbuffer::Read ( void buf,
size_t  cnt 
)

Read from a ring buffer.

Parameters
bufbuffer of cnt bytes to be read
cntNumber of bytes to be read
Returns
Number of bytes that could be read from ring buffer

Definition at line 215 of file ringbuffer.cpp.

References atomic_read, atomic_sub, cSoftHdRingbuffer::m_filled, cSoftHdRingbuffer::m_pBuffer, cSoftHdRingbuffer::m_pBufferEnd, and cSoftHdRingbuffer::m_pReadPointer.

◆ ReadAdvance()

size_t cSoftHdRingbuffer::ReadAdvance ( size_t  cnt)

Advance read pointer in ring buffer.

Parameters
cntNumber of bytes to be advanced
Returns
Number of bytes that could be advanced in ring buffer

Definition at line 178 of file ringbuffer.cpp.

References atomic_read, atomic_sub, cSoftHdRingbuffer::m_filled, cSoftHdRingbuffer::m_pBuffer, cSoftHdRingbuffer::m_pBufferEnd, and cSoftHdRingbuffer::m_pReadPointer.

Referenced by cSoftHdAudio::DropSamplesOlderThanPtsMs(), and cSoftHdAudio::SendAudio().

◆ ReorderAudioFrame()

static void ReorderAudioFrame ( uint16_t buf,
int  size,
int  channels 
)
static

Reorder audio frame.

ffmpeg L R C Ls Rs -> alsa L R Ls Rs C ffmpeg L R C LFE Ls Rs -> alsa L R Ls Rs C LFE ffmpeg L R C LFE Ls Rs Rl Rr -> alsa L R Ls Rs C LFE Rl Rr

Parameters
buf[IN,OUT]sample buffer
sizesize of sample buffer in bytes
channelsnumber of channels interleaved in sample buffer

Definition at line 95 of file audio.cpp.

Referenced by cSoftHdAudio::EnqueueFrame().

◆ Reset() [1/2]

◆ Reset() [2/2]

void cSoftHdRingbuffer::Reset ( void  )

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

References cSoftHdRingbuffer::GetReadPointer(), L_SOUND, LOGDEBUG2, LOGERROR, LOGWARNING, cSoftHdAudio::m_alsaUseMmap, cSoftHdAudio::m_fillLevel, cSoftHdAudio::m_pAlsaPCMHandle, cSoftHdAudio::m_passthrough, cSoftHdAudio::m_pRingbuffer, cSoftHdAudio::m_softVolume, cSoftHdAudio::m_volume, cSoftHdRingbuffer::ReadAdvance(), cSoftHdAudio::SoftAmplify(), and cBufferFillLevelLowPassFilter::WroteFrames().

Referenced by cSoftHdAudio::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 1358 of file audio.cpp.

References LOGERROR, LOGWARNING, cSoftHdAudio::m_alsaUseMmap, cSoftHdAudio::m_pAlsaPCMHandle, cSoftHdAudio::m_pauseBurst, and cSoftHdAudio::m_spdifBurstSize.

Referenced by cSoftHdAudio::CyclicCall().

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

References cSoftHdAudio::m_compression, cSoftHdAudio::m_compressionFactor, and cSoftHdAudio::m_compressionMaxFactor.

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

◆ SetEq()

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

Set equalizer bands.

Parameters
bandsetting frequenz bands
onoffset using equalizer

Definition at line 319 of file audio.cpp.

References cSoftHdAudio::m_equalizerBand, cSoftHdAudio::m_filterChanged, and cSoftHdAudio::m_useEqualizer.

Referenced by cSoftHdAudio::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 1015 of file audio.cpp.

References cSoftHdAudio::m_normalize, and cSoftHdAudio::m_normalizeMaxFactor.

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

◆ SetPassthroughMask()

void cSoftHdAudio::SetPassthroughMask ( int  mask)

Set audio passthrough mask.

Parameters
maskpassthrough mask (as a bitmask)

Definition at line 1056 of file audio.cpp.

References cSoftHdAudio::m_passthrough, and cSoftHdAudio::m_pitchPpm.

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

References L_SOUND, LOGDEBUG2, cSoftHdAudio::m_paused, and cSoftHdAudio::m_pauseMutex.

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

◆ SetStereoDescent()

void cSoftHdAudio::SetStereoDescent ( int  delta)

Set stereo loudness descent.

Parameters
deltavalue (/1000) to reduce stereo volume

Definition at line 1045 of file audio.cpp.

References cSoftHdAudio::m_stereoDescent, cSoftHdAudio::m_volume, and cSoftHdAudio::SetVolume().

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

◆ Setup()

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

Alsa setup wrapper.

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

Parameters
AudioCtxAVCodec audio decoding context
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 729 of file audio.cpp.

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

Referenced by cAudioDecoder::UpdateFormat().

◆ SetVolume()

◆ SoftAmplify()

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

Amplify the samples in software.

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

Definition at line 290 of file audio.cpp.

References cSoftHdAudio::m_amplifier, cSoftHdAudio::m_bytesPerSample, and cSoftHdAudio::m_volume.

Referenced by cSoftHdAudio::SendAudio().

◆ Stop()

void cSoftHdAudio::Stop ( void  )

Stop the thread.

Definition at line 1217 of file audio.cpp.

References LOGDEBUG.

Referenced by cSoftHdAudio::AlsaSetup(), and cSoftHdAudio::Exit().

◆ Update()

double cPidController::Update ( double  currentValue,
double  dt 
)

◆ UsedBytes()

size_t cSoftHdRingbuffer::UsedBytes ( void  )

Get used bytes in ring buffer.

Returns
Number of bytes used in buffer.

Definition at line 291 of file ringbuffer.cpp.

References atomic_read, and cSoftHdRingbuffer::m_filled.

Referenced by cSoftHdAudio::DropSamplesOlderThanPtsMs(), cSoftHdAudio::GetOutputPtsMsInternal(), and cSoftHdAudio::GetUsedBytes().

◆ Write()

size_t cSoftHdRingbuffer::Write ( const void buf,
size_t  cnt 
)

Write to a ring buffer.

Parameters
bufbuffer of cnt bytes to be written
cntNumber of bytes in buffer
Returns
The number of bytes that could be placed in the ring buffer

Definition at line 110 of file ringbuffer.cpp.

References atomic_add, atomic_read, cSoftHdRingbuffer::m_filled, cSoftHdRingbuffer::m_pBuffer, cSoftHdRingbuffer::m_pBufferEnd, cSoftHdRingbuffer::m_pWritePointer, and cSoftHdRingbuffer::m_size.

Referenced by cSoftHdAudio::Enqueue().

◆ WriteAdvance()

size_t cSoftHdRingbuffer::WriteAdvance ( size_t  cnt)

Advance write pointer in ring buffer.

Parameters
cntNumber of bytes to be adavanced
Returns
Number of bytes that could be advanced in ring buffer

Definition at line 73 of file ringbuffer.cpp.

References atomic_add, atomic_read, cSoftHdRingbuffer::m_filled, cSoftHdRingbuffer::m_pBuffer, cSoftHdRingbuffer::m_pBufferEnd, cSoftHdRingbuffer::m_pWritePointer, and cSoftHdRingbuffer::m_size.

◆ ~cSoftHdRingbuffer()

cSoftHdRingbuffer::~cSoftHdRingbuffer ( void  )

cSoftHdRingbuffer destructor

Definition at line 51 of file ringbuffer.cpp.

References cSoftHdRingbuffer::m_pBuffer.