27#include <libavcodec/avcodec.h>
28#include <libavfilter/avfilter.h>
31#include <alsa/asoundlib.h>
33#include <vdr/thread.h>
52 int Setup(AVCodecContext *,
int ,
int ,
int);
55 void Filter(AVFrame *, AVCodecContext *);
70 void SetEq(
int[18],
int);
Fill Level Low Pass Filter.
int m_alsaBufferSizeFrames
alsa buffer size in frames
bool m_appendAES
flag ato utomatic append AES
cSoftHdRingbuffer m_pRingbuffer
sample ring buffer
int m_pitchAdjustFrameCounter
counter for pitch adjustment frames
double FramesToMsDouble(int frames)
int64_t GetInputPtsMs(void)
int m_compressionMaxFactor
max. compression factor
cSoftHdDevice * m_pDevice
pointer to device
const char * m_pPCMDevice
PCM device name.
int GetPassthrough(void) const
int m_volume
current volume (0 .. 1000)
std::mutex m_pauseMutex
mutex for a safe thread pausing
AVFilterContext * m_pBuffersinkCtx
cPidController m_pidController
PID controller for clock drift compensation with tuning values coming from educated guesses.
AVFilterContext * m_pBuffersrcCtx
AVFilterGraph * m_pFilterGraph
int m_passthrough
passthrough mask
const int m_bytesPerSample
number of bytes per sample
const char * m_pMixerChannel
mixer channel name
unsigned int m_hwSampleRate
hardware sample rate in Hz
int64_t PtsToMs(int64_t pts)
cBufferFillLevelLowPassFilter m_fillLevel
low pass filter for the buffer fill level
IEventReceiver * m_pEventReceiver
pointer to event receiver
int GetAvResyncBorderMs(void)
int MsToFrames(int milliseconds)
std::vector< Event > m_eventQueue
event queue for incoming events
AVRational * m_pTimebase
pointer to AVCodecContext pkts_timebase
void SetAutoAES(bool appendAes)
static constexpr int AUDIO_MIN_BUFFER_FREE
Minimum free space in audio buffer 8 packets for 8 channels.
bool m_compression
flag to use compress volume
bool m_normalize
flag to use volume normalize
int m_filterChanged
filter has changed
snd_mixer_elem_t * m_pAlsaMixerElem
alsa mixer element
int64_t m_inputPts
pts clock (last pts in ringbuffer)
int m_normalizeFactor
current normalize factor
cSoftHdConfig * m_pConfig
pointer to config
std::atomic< double > m_pitchPpm
pitch adjustment in ppm. Positive values are faster
int m_amplifier
software volume amplify factor
void SetSoftvol(bool softVolume)
static constexpr int NORMALIZE_MAX_INDEX
number of normalize average samples
const char * m_pPassthroughDevice
passthrough device name
int m_normalizeMaxFactor
max. normalize factor
bool m_alsaUseMmap
use mmap
int m_compressionFactor
current compression factor
int64_t MsToPts(int64_t ptsMs)
int m_spdifBurstSize
size of the current spdif burst
const int m_normalizeMinFactor
min. normalize factor
const int m_normalizeSamples
number of normalize samples
int m_filterReady
filter is ready
int m_normalizeReady
index normalize counter
const char * m_pMixerDevice
mixer device name (not used)
uint32_t m_normalizeAverage[NORMALIZE_MAX_INDEX]
average of n last normalize sample blocks
unsigned int m_hwNumChannels
number of hardware channels
bool m_initialized
class initialized
int FramesToMs(int frames)
int m_stereoDescent
volume descent for stereo
std::mutex m_mutex
mutex for thread safety
static constexpr int AV_SYNC_BORDER_MS
absolute max a/v difference in ms which should trigger a resync
int m_alsaRatio
internal -> mixer ratio * 1000
int m_packetCounter
packet counter for logging
void SetDownmix(int downMix)
static constexpr unsigned RINGBUFFER_SIZE
default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8)
snd_pcm_t * m_pAlsaPCMHandle
alsa pcm handle
int m_downmix
set stereo downmix
int m_useEqualizer
flag to use equalizer
float m_equalizerBand[18]
equalizer band
snd_mixer_t * m_pAlsaMixer
alsa mixer handle
snd_pcm_sframes_t m_hwBaseline
saves the hw delay (pause bursts) once a real audio frame to correctly do the AV-Sync
int m_normalizeIndex
index into normalize average table
std::chrono::steady_clock::time_point m_lastPidInvocation
last time the PID controller was invoked
int m_normalizeCounter
normalize sample counter
std::atomic< bool > m_paused
audio is paused
bool m_firstRealAudioReceived
false, as long as no real audio was sent - used to trigger the baseline set
std::vector< uint16_t > m_pauseBurst
holds the burst data itself
void SetTimebase(AVRational *timebase)
bool m_softVolume
flag to use soft volume
Output Device Implementation.
Ringbuffer (FIFO) Implementation.
State Machine and Event Header File.
Low-pass Filter for Audio Buffer Fill Level Measurement Header File.
void LazyInit(void)
Initialize audio output module (alsa)
char * OpenAlsaDevice(const char *, int)
Opens an alsa device.
bool SendPause(void)
Write pause to passthrough device.
char * FindAlsaDevice(const char *, const char *, int)
Find alsa device giving some search hints.
void ResetHwDelayBaseline(void)
Reset the hw delay baseline.
virtual void Action(void)
Audio thread loop, started with Start().
void Filter(AVFrame *, AVCodecContext *)
Send audio frame to filter and enqueue it.
int AlsaSetup(int channels, int sample_rate, int passthrough)
Setup alsa audio for requested format.
int Setup(AVCodecContext *, int, int, int)
Alsa setup wrapper.
void Enqueue(uint16_t *, int, AVFrame *)
Send audio data to ringbuffer.
void SetPassthroughMask(int)
Set audio passthrough mask.
void SetHwDelayBaseline(void)
Set the hw delay baseline.
void SetStereoDescent(int)
Set stereo loudness descent.
int64_t GetHardwareOutputPtsMs(void)
Get the hardware output PTS in milliseconds.
int64_t GetHardwareOutputPtsTimebaseUnits(void)
Get the hardware output PTS in timebase units.
void EnqueueSpdif(uint16_t *, int, AVFrame *)
Enqueue prepared spdif bursts in audio output queue.
void SetVolume(int)
Set mixer volume (0-1000)
void HandleError(int)
Handle an alsa error.
void FlushAlsaBuffersInternal(bool)
Flush alsa buffers internally.
void ProcessEvents(void)
Process queued events and forward them to event receiver.
bool SendAudio(int)
Write regular audio data from the ringbuffer to the hardware.
void DropSamplesOlderThanPtsMs(int64_t)
Drop samples older than the given PTS.
int64_t GetOutputPtsMs(void)
Get the output PTS of the ringbuffer.
AVFrame * FilterGetFrame(void)
Get frame from filter sink.
size_t FreeBytes(void)
Get free bytes in ring buffer.
void ClockDriftCompensation(void)
Calculate clock drift compensation.
void AlsaExit(void)
Cleanup the alsa audio output module.
void SetCompression(bool, int)
Set volume compression parameters.
void Stop(void)
Stop the thread.
void BuildPauseBurst(void)
Build a pause spdif burst with the size of the last recognized normal spdif audio.
void AlsaInit(void)
Initialize the alsa audio output module.
void Compress(uint16_t *, int)
Compress audio samples.
void AlsaSetVolume(int)
Set alsa mixer volume (0-1000)
int64_t GetOutputPtsMsInternal(void)
void Exit(void)
Cleanup audio output module (alsa)
int GetUsedBytes(void)
Get used bytes in audio ringbuffer.
void SetPaused(bool)
Set audio playback pause state.
void AlsaInitMixer(void)
Initialize alsa mixer.
int64_t GetHardwareOutputDelayMs(void)
Get the hardware delay in milliseconds.
void Normalize(uint16_t *, int)
Normalize audio samples.
void SetEq(int[18], int)
Set equalizer bands.
void DropAlsaBuffers(void)
Drop alsa buffers.
bool CyclicCall(void)
Cyclic audio playback call.
void AlsaInitPCMDevice(void)
Search for an alsa pcm device and open it.
void EnqueueFrame(AVFrame *)
Place samples in audio output queue.
void SoftAmplify(int16_t *, int)
Amplify the samples in software.
void FlushAlsaBuffers(void)
Flush alsa buffers.
void SetNormalize(bool, int)
Set normalize volume parameters.
int CheckForFilterReady(AVCodecContext *)
Check if the filter has changed and is ready, init the filter if needed.
int InitFilter(AVCodecContext *)
Init audio filters.
void FlushBuffers(void)
Flush audio buffers.
PID (proportional, integral, derivative) Controller Header File.
Audio Ringbuffer Header File.