vdr-plugin-softhddevice-drm-gles 1.5.9-20e15de
cBufferFillLevelLowPassFilter Class Reference

#include <filllevel.h>

Public Member Functions

void Reset ()
 Resets the filter state.
 
void ResetFramesCounters ()
 Resets the received and written frames counters.
 
int GetFramesReceived ()
 
int GetFramesPlayed ()
 
void ReceivedFrames (int count)
 
void WroteFrames (int count)
 
double GetBufferFillLevelFramesAvg ()
 
void SetMinBufferSizeFrames (int size)
 
void UpdateAvgBufferFillLevel (int)
 Updates the buffer fill level average.
 
bool IsSettled ()
 

Private Types

enum  State { UNINITIALIZED , SETTLING , SETTLED }
 

Private Member Functions

const char * StateToString (State d)
 Converts the filter state to a string representation.
 

Private Attributes

std::mutex m_mutex
 
State m_state = UNINITIALIZED
 
int m_receivedFrames = 0
 
int m_writtenToAlsaFrames = 0
 
double m_bufferFillLevelFramesAvg = 0
 
double m_bufferFillLevelFramesTargetValue = 0
 
int m_frameCounter = 0
 
double m_floatingAverageAlpha = FLOATING_AVERAGE_ALPHA_NORMAL
 
int m_minBufferSizeFrames = 0
 

Static Private Attributes

static constexpr double FLOATING_AVERAGE_ALPHA_SETTLING = 0.02
 
static constexpr double FLOATING_AVERAGE_ALPHA_NORMAL = 0.002
 
static constexpr int SETTLING_DURATION_PACKETS = 30 / 0.16
 

Detailed Description

Definition at line 23 of file filllevel.h.

Member Enumeration Documentation

◆ State

Enumerator
UNINITIALIZED 
SETTLING 
SETTLED 

Definition at line 37 of file filllevel.h.

Member Function Documentation

◆ GetBufferFillLevelFramesAvg()

double cBufferFillLevelLowPassFilter::GetBufferFillLevelFramesAvg ( )
inline

Definition at line 31 of file filllevel.h.

References m_bufferFillLevelFramesAvg, and m_mutex.

Referenced by cSoftHdAudio::ClockDriftCompensation().

◆ GetFramesPlayed()

int cBufferFillLevelLowPassFilter::GetFramesPlayed ( )
inline

Definition at line 28 of file filllevel.h.

References m_mutex, and m_writtenToAlsaFrames.

◆ GetFramesReceived()

int cBufferFillLevelLowPassFilter::GetFramesReceived ( )
inline

Definition at line 27 of file filllevel.h.

References m_mutex, and m_receivedFrames.

◆ IsSettled()

bool cBufferFillLevelLowPassFilter::IsSettled ( )
inline

Definition at line 34 of file filllevel.h.

References m_mutex, m_state, and SETTLED.

Referenced by cSoftHdAudio::ClockDriftCompensation().

◆ ReceivedFrames()

void cBufferFillLevelLowPassFilter::ReceivedFrames ( int  count)
inline

Definition at line 29 of file filllevel.h.

References m_mutex, and m_receivedFrames.

Referenced by cSoftHdAudio::Enqueue().

◆ Reset()

void cBufferFillLevelLowPassFilter::Reset ( )

Resets the filter state.

Definition at line 26 of file filllevel.cpp.

References m_bufferFillLevelFramesAvg, m_frameCounter, m_state, and UNINITIALIZED.

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

◆ ResetFramesCounters()

void cBufferFillLevelLowPassFilter::ResetFramesCounters ( )

Resets the received and written frames counters.

Definition at line 37 of file filllevel.cpp.

References m_receivedFrames, and m_writtenToAlsaFrames.

Referenced by cSoftHdAudio::FlushBuffers().

◆ SetMinBufferSizeFrames()

void cBufferFillLevelLowPassFilter::SetMinBufferSizeFrames ( int  size)
inline

Definition at line 32 of file filllevel.h.

References m_minBufferSizeFrames, and m_mutex.

◆ StateToString()

const char * cBufferFillLevelLowPassFilter::StateToString ( State  state)
private

Converts the filter state to a string representation.

Parameters
stateThe state to convert
Returns
String representation of the state

Definition at line 92 of file filllevel.cpp.

References SETTLED, SETTLING, and UNINITIALIZED.

◆ UpdateAvgBufferFillLevel()

void cBufferFillLevelLowPassFilter::UpdateAvgBufferFillLevel ( int  hardwareBufferFillLevelFrames)

Updates the buffer fill level average.

Calculates the current buffer fill level based on received frames, written frames, and the hardware buffer fill level. Applies a low-pass filter (exponential moving average) to smooth the value. This is necessary, because the packets coming from VDR have a few milliseconds jitter.

Handles state transitions:

  • UNINITIALIZED -> SETTLING: Initializes the average and sets a faster alpha.
  • SETTLING -> SETTLED: After a duration, switches to a slower alpha and fixes the target value.
Parameters
hardwareBufferFillLevelFramesCurrent fill level reported by the hardware (ALSA)

Definition at line 57 of file filllevel.cpp.

References FLOATING_AVERAGE_ALPHA_NORMAL, FLOATING_AVERAGE_ALPHA_SETTLING, m_bufferFillLevelFramesAvg, m_bufferFillLevelFramesTargetValue, m_floatingAverageAlpha, m_frameCounter, m_minBufferSizeFrames, m_mutex, m_receivedFrames, m_state, m_writtenToAlsaFrames, SETTLED, SETTLING, SETTLING_DURATION_PACKETS, and UNINITIALIZED.

Referenced by cSoftHdAudio::ClockDriftCompensation().

◆ WroteFrames()

void cBufferFillLevelLowPassFilter::WroteFrames ( int  count)
inline

Definition at line 30 of file filllevel.h.

References m_mutex, and m_writtenToAlsaFrames.

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

Member Data Documentation

◆ FLOATING_AVERAGE_ALPHA_NORMAL

constexpr double cBufferFillLevelLowPassFilter::FLOATING_AVERAGE_ALPHA_NORMAL = 0.002
staticconstexprprivate

Definition at line 44 of file filllevel.h.

Referenced by UpdateAvgBufferFillLevel().

◆ FLOATING_AVERAGE_ALPHA_SETTLING

constexpr double cBufferFillLevelLowPassFilter::FLOATING_AVERAGE_ALPHA_SETTLING = 0.02
staticconstexprprivate

Definition at line 43 of file filllevel.h.

Referenced by UpdateAvgBufferFillLevel().

◆ m_bufferFillLevelFramesAvg

double cBufferFillLevelLowPassFilter::m_bufferFillLevelFramesAvg = 0
private

Definition at line 51 of file filllevel.h.

Referenced by GetBufferFillLevelFramesAvg(), Reset(), and UpdateAvgBufferFillLevel().

◆ m_bufferFillLevelFramesTargetValue

double cBufferFillLevelLowPassFilter::m_bufferFillLevelFramesTargetValue = 0
private

Definition at line 52 of file filllevel.h.

Referenced by UpdateAvgBufferFillLevel().

◆ m_floatingAverageAlpha

double cBufferFillLevelLowPassFilter::m_floatingAverageAlpha = FLOATING_AVERAGE_ALPHA_NORMAL
private

Definition at line 54 of file filllevel.h.

Referenced by UpdateAvgBufferFillLevel().

◆ m_frameCounter

int cBufferFillLevelLowPassFilter::m_frameCounter = 0
private

Definition at line 53 of file filllevel.h.

Referenced by Reset(), and UpdateAvgBufferFillLevel().

◆ m_minBufferSizeFrames

int cBufferFillLevelLowPassFilter::m_minBufferSizeFrames = 0
private

Definition at line 55 of file filllevel.h.

Referenced by SetMinBufferSizeFrames(), and UpdateAvgBufferFillLevel().

◆ m_mutex

std::mutex cBufferFillLevelLowPassFilter::m_mutex
private

◆ m_receivedFrames

int cBufferFillLevelLowPassFilter::m_receivedFrames = 0
private

◆ m_state

State cBufferFillLevelLowPassFilter::m_state = UNINITIALIZED
private

Definition at line 48 of file filllevel.h.

Referenced by IsSettled(), Reset(), and UpdateAvgBufferFillLevel().

◆ m_writtenToAlsaFrames

int cBufferFillLevelLowPassFilter::m_writtenToAlsaFrames = 0
private

◆ SETTLING_DURATION_PACKETS

constexpr int cBufferFillLevelLowPassFilter::SETTLING_DURATION_PACKETS = 30 / 0.16
staticconstexprprivate

Definition at line 45 of file filllevel.h.

Referenced by UpdateAvgBufferFillLevel().


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