|
vdr-plugin-softhddevice-drm-gles 1.6.4-d0291bb
|
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 (AVCodecContext *, int, int, int) |
| 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 (uint16_t *, int, AVFrame *) |
| Enqueue prepared spdif bursts in audio output queue. | |
| bool | IsBufferFull (void) |
| void | FlushBuffers (void) |
| Flush audio buffers. | |
| int | GetUsedBytes (void) |
| Get used bytes 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. | |
| int | GetPassthrough (void) const |
| bool | HasInputPts (void) |
| int64_t | GetInputPtsMs (void) |
| int64_t | GetOutputPtsMs (void) |
| Get the output PTS of the ringbuffer. | |
| int | GetAvResyncBorderMs (void) |
| void | SetEq (int[18], int) |
| Set equalizer bands. | |
| void | SetVolume (int) |
| Set mixer volume (0-1000) | |
| void | SetDownmix (int downMix) |
| void | SetSoftvol (bool softVolume) |
| void | SetNormalize (bool, int) |
| Set normalize volume parameters. | |
| void | SetCompression (bool, int) |
| Set volume compression parameters. | |
| void | SetStereoDescent (int) |
| Set stereo loudness descent. | |
| void | SetPassthroughMask (int) |
| Set audio passthrough mask. | |
| void | SetAutoAES (bool appendAes) |
| void | SetTimebase (AVRational *timebase) |
| 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 (uint16_t *, int, AVFrame *) |
| 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 | BuildPauseBurst (void) |
| Build a pause spdif burst with the size of the last recognized normal spdif audio. | |
| void | Stop (void) |
| Stop the thread. | |
| void | Normalize (uint16_t *, int) |
| Normalize audio samples. | |
| void | Compress (uint16_t *, int) |
| Compress audio samples. | |
| void | SoftAmplify (int16_t *, int) |
| Amplify the samples in software. | |
| int | InitFilter (AVCodecContext *) |
| Init audio filters. | |
| AVFrame * | FilterGetFrame (void) |
| Get frame from filter sink. | |
| int | CheckForFilterReady (AVCodecContext *) |
| Check if the filter has changed and is ready, init the filter if needed. | |
| int | AlsaSetup (int, int, int) |
| Setup alsa audio for requested format. | |
| char * | OpenAlsaDevice (const char *, int) |
| Open an alsa device. | |
| char * | FindAlsaDevice (const char *, const char *, int) |
| Find alsa device giving some search hints. | |
| void | AlsaInitPCMDevice (void) |
| Search for an alsa pcm device and open it. | |
| void | AlsaInitMixer (void) |
| Initialize alsa mixer. | |
| void | AlsaSetVolume (int) |
| Set alsa mixer volume (0-1000) | |
| void | AlsaInit (void) |
| Initialize the alsa audio output module. | |
| void | AlsaExit (void) |
| Cleanup the alsa audio output module. | |
| void | FlushAlsaBuffers (void) |
| Flush alsa buffers. | |
| void | DropAlsaBuffers (void) |
| Drop alsa buffers. | |
| void | FlushAlsaBuffersInternal (bool) |
| Flush alsa buffers internally. | |
| bool | CyclicCall (void) |
| Cyclic audio playback call. | |
| void | ProcessEvents (void) |
| Process queued events and forward them to event receiver. | |
| void | HandleError (int) |
| Handle an alsa error. | |
| int64_t | GetOutputPtsMsInternal (void) |
| int64_t | PtsToMs (int64_t pts) |
| int64_t | MsToPts (int64_t ptsMs) |
| int | MsToFrames (int milliseconds) |
| int | FramesToMs (int frames) |
| double | FramesToMsDouble (int frames) |
Private Attributes | |
| cSoftHdDevice * | m_pDevice |
| pointer to device | |
| cSoftHdConfig * | m_pConfig |
| pointer to config | |
| IEventReceiver * | m_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_alsaBufferSizeFrames = 0 |
| alsa buffer size in frames | |
| int | m_packetCounter = 0 |
| packet counter for logging | |
| bool | m_initialized = false |
| class initialized | |
| const int | m_bytesPerSample = 2 |
| number of bytes per sample | |
| unsigned int | m_hwSampleRate = 0 |
| hardware sample rate in Hz | |
| unsigned int | m_hwNumChannels = 0 |
| number of hardware channels | |
| AVRational * | m_pTimebase |
| pointer to AVCodecContext pkts_timebase | |
| std::mutex | m_mutex |
| mutex for thread safety | |
| std::mutex | m_pauseMutex |
| mutex for a safe thread pausing | |
| std::vector< Event > | m_eventQueue |
| event queue for incoming events | |
| std::atomic< double > | m_pitchPpm = 0 |
| pitch adjustment in ppm. Positive values are faster | |
| int | m_pitchAdjustFrameCounter = 0 |
| counter for pitch adjustment frames | |
| int | m_downmix |
| set stereo downmix | |
| int64_t | m_inputPts = AV_NOPTS_VALUE |
| pts clock (last pts in ringbuffer) | |
| std::atomic< bool > | m_paused = true |
| audio is paused | |
| bool | m_softVolume |
| flag to use soft volume | |
| int | m_passthrough |
| passthrough mask | |
| const char * | m_pPCMDevice |
| PCM device name. | |
| const char * | m_pPassthroughDevice |
| passthrough device name | |
| bool | m_appendAES |
| flag ato utomatic append AES | |
| int | m_spdifBurstSize = 0 |
| size of the current spdif burst | |
| std::vector< uint16_t > | m_pauseBurst |
| holds the burst data itself | |
| snd_pcm_sframes_t | 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 | |
| bool | m_normalize |
| flag to use volume normalize | |
| const int | m_normalizeSamples = 4096 |
| number of normalize samples | |
| int | m_normalizeCounter |
| normalize sample counter | |
| uint32_t | m_normalizeAverage [NORMALIZE_MAX_INDEX] |
| average of n last normalize sample blocks | |
| int | m_normalizeIndex |
| index into normalize average table | |
| int | m_normalizeReady |
| index normalize counter | |
| int | m_normalizeFactor |
| current normalize factor | |
| const int | m_normalizeMinFactor = 100 |
| min. normalize factor | |
| int | m_normalizeMaxFactor |
| max. normalize factor | |
| bool | m_compression |
| flag to use compress volume | |
| int | m_compressionFactor = 0 |
| current compression factor | |
| int | m_compressionMaxFactor |
| max. compression factor | |
| int | m_amplifier |
| software volume amplify factor | |
| int | m_stereoDescent |
| volume descent for stereo | |
| int | m_volume = 0 |
| current volume (0 .. 1000) | |
| int | m_useEqualizer |
| flag to use equalizer | |
| float | m_equalizerBand [18] |
| equalizer band | |
| const char * | m_pMixerDevice = nullptr |
| mixer device name (not used) | |
| const char * | m_pMixerChannel |
| mixer channel name | |
| int | m_filterChanged = 0 |
| filter has changed | |
| int | m_filterReady = 0 |
| filter is ready | |
| AVFilterGraph * | m_pFilterGraph = nullptr |
| AVFilterContext * | m_pBuffersrcCtx |
| AVFilterContext * | m_pBuffersinkCtx |
| cSoftHdRingbuffer | m_pRingbuffer {RINGBUFFER_SIZE} |
| sample ring buffer | |
| snd_pcm_t * | m_pAlsaPCMHandle |
| alsa pcm handle | |
| snd_mixer_t * | m_pAlsaMixer = nullptr |
| alsa mixer handle | |
| snd_mixer_elem_t * | m_pAlsaMixerElem = nullptr |
| alsa mixer element | |
| int | m_alsaRatio |
| internal -> mixer ratio * 1000 | |
| bool | m_alsaUseMmap |
| use mmap | |
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 | NORMALIZE_MAX_INDEX = 128 |
| number of normalize average samples | |
| static constexpr int | AV_SYNC_BORDER_MS = 5000 |
| absolute max a/v difference in ms which should trigger a resync | |
| static constexpr unsigned | RINGBUFFER_SIZE = 3 * 5 * 7 * 8 * 2 * 1000 |
| default ring buffer size ~2s 8ch 16bit (3 * 5 * 7 * 8) | |
| cSoftHdAudio::cSoftHdAudio | ( | cSoftHdDevice * | device | ) |
Create a new audio context.
Definition at line 52 of file audio.cpp.
References cSoftHdConfig::ConfigAudioCompression, cSoftHdConfig::ConfigAudioEq, cSoftHdConfig::ConfigAudioEqBand, cSoftHdConfig::ConfigAudioMaxCompression, cSoftHdConfig::ConfigAudioMaxNormalize, cSoftHdConfig::ConfigAudioNormalize, cSoftHdConfig::ConfigAudioStereoDescent, m_pConfig, SetCompression(), SetEq(), SetNormalize(), and SetStereoDescent().
Audio thread loop, started with Start().
Tries to periodically send frames to the hardware and checks for events (underruns)
Definition at line 1319 of file audio.cpp.
References CyclicCall(), LOGDEBUG, and ProcessEvents().
Cleanup the alsa audio output module.
Definition at line 1944 of file audio.cpp.
References m_pAlsaMixer, m_pAlsaMixerElem, and m_pAlsaPCMHandle.
Referenced by Exit().
Initialize the alsa audio output module.
Definition at line 1928 of file audio.cpp.
References AlsaInitMixer(), AlsaInitPCMDevice(), and AlsaNoopCallback().
Referenced by LazyInit().
Initialize alsa mixer.
Definition at line 1727 of file audio.cpp.
References L_SOUND, LOGDEBUG2, LOGERROR, m_alsaRatio, m_pAlsaMixer, m_pAlsaMixerElem, m_pMixerChannel, and m_pMixerDevice.
Referenced by AlsaInit().
Search for an alsa pcm device and open it.
Definition at line 1648 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().
Setup alsa audio for requested format.
| channels | Channels requested |
| sample_rate | SampleRate requested |
| passthrough | use pass-through (AC-3, ...) device |
| 0 | everything ok |
| -1 | something gone wrong |
Definition at line 1803 of file audio.cpp.
References DropAlsaBuffers(), GetAlsaChannelLayoutAsArray(), L_SOUND, LOGDEBUG2, LOGERROR, LOGINFO, LOGWARNING, m_alsaBufferSizeFrames, m_alsaUseMmap, m_downmix, m_hwNumChannels, m_hwSampleRate, m_pAlsaPCMHandle, MsToFrames(), and Stop().
Referenced by InitFilter(), and Setup().
Set alsa mixer volume (0-1000)
| volume | volume (0 .. 1000) |
Definition at line 1781 of file audio.cpp.
References m_alsaRatio, m_pAlsaMixer, and m_pAlsaMixerElem.
Referenced by SetVolume().
Build a pause spdif burst with the size of the last recognized normal spdif audio.
Definition at line 754 of file audio.cpp.
References IEC61937_NULL, IEC61937_PREAMBLE1, IEC61937_PREAMBLE2, m_pauseBurst, and m_spdifBurstSize.
Referenced by EnqueueSpdif().
|
private |
Check if the filter has changed and is ready, init the filter if needed.
| ctx | AVCodec audio decoding context |
| 1 | error, init failed |
| 0 | filter initiated |
Definition at line 905 of file audio.cpp.
References InitFilter(), L_SOUND, LOGDEBUG2, m_filterChanged, m_filterReady, and m_pFilterGraph.
Referenced by Filter().
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 1966 of file audio.cpp.
References FramesToMsDouble(), cBufferFillLevelLowPassFilter::GetBufferFillLevelFramesAvg(), cPidController::GetDTerm(), cPidController::GetITerm(), cPidController::GetPTerm(), cPidController::GetTargetValue(), cBufferFillLevelLowPassFilter::IsSettled(), L_SOUND, LOGDEBUG2, LOGWARNING, m_alsaBufferSizeFrames, m_fillLevel, m_lastPidInvocation, m_packetCounter, m_pAlsaPCMHandle, m_passthrough, m_pidController, m_pitchPpm, cPidController::SetTargetValue(), cPidController::Update(), and cBufferFillLevelLowPassFilter::UpdateAvgBufferFillLevel().
Referenced by cSoftHdDevice::PlayAudio().
Compress audio samples.
| samples | sample buffer |
| count | number of bytes in sample buffer |
Definition at line 162 of file audio.cpp.
References L_SOUND, LOGDEBUG2, m_bytesPerSample, m_compressionFactor, and m_compressionMaxFactor.
Referenced by EnqueueFrame().
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.
Definition at line 1357 of file audio.cpp.
References HandleError(), L_SOUND, LOGDEBUG2, LOGERROR, m_mutex, m_pAlsaPCMHandle, m_passthrough, m_paused, m_pauseMutex, m_spdifBurstSize, SendAudio(), and SendPause().
Referenced by Action().
Drop alsa buffers.
Definition at line 1254 of file audio.cpp.
References FlushAlsaBuffersInternal().
Referenced by AlsaSetup().
Drop samples older than the given PTS.
Removes audio samples from the ringbuffer that have a presentation timestamp older than the specified ptsMs.
| ptsMs | presentation timestamp in milliseconds - samples older than this will be dropped |
Definition at line 698 of file audio.cpp.
References GetOutputPtsMsInternal(), HasInputPts(), L_AV_SYNC, LOGDEBUG2, m_fillLevel, m_mutex, m_pAlsaPCMHandle, m_pidController, m_pRingbuffer, MsToFrames(), cSoftHdRingbuffer::ReadAdvance(), cBufferFillLevelLowPassFilter::Reset(), cPidController::Reset(), Timestamp2String(), cSoftHdRingbuffer::UsedBytes(), and cBufferFillLevelLowPassFilter::WroteFrames().
Referenced by cVideoRender::DisplayFrame(), and cSoftHdDevice::OnEventReceived().
Send audio data to ringbuffer.
| buffer | data buffer |
| count | number of bytes in data buffer |
| frame | decoded frame (used to get frame parameters) |
Definition at line 797 of file audio.cpp.
References AV_NOPTS_VALUE, AV_SYNC_BORDER_MS, L_AV_SYNC, LOGDEBUG2, LOGERROR, m_eventQueue, m_fillLevel, m_inputPts, m_mutex, m_pAlsaPCMHandle, m_pitchAdjustFrameCounter, m_pitchPpm, m_pRingbuffer, PtsToMs(), cBufferFillLevelLowPassFilter::ReceivedFrames(), Timestamp2String(), and cSoftHdRingbuffer::Write().
Referenced by EnqueueFrame(), and EnqueueSpdif().
Place samples in audio output queue.
| frame | audio frame |
Definition at line 730 of file audio.cpp.
References Compress(), Enqueue(), m_bytesPerSample, m_compression, m_normalize, and Normalize().
Referenced by Filter().
Enqueue prepared spdif bursts in audio output queue.
Wrapper for Enqueue(), but builds a new pause burst if necessary
| buffer | data buffer |
| count | number of bytes in data buffer |
| frame | decoded frame (used to get frame parameters) |
Definition at line 775 of file audio.cpp.
References BuildPauseBurst(), Enqueue(), L_SOUND, LOGDEBUG2, m_pauseBurst, m_pauseMutex, and m_spdifBurstSize.
Referenced by cAudioDecoder::DecodePassthrough().
Cleanup audio output module (alsa)
This currently also stops the audio thread.
Definition at line 1210 of file audio.cpp.
References AlsaExit(), L_SOUND, LOGDEBUG2, m_initialized, m_pFilterGraph, and Stop().
Referenced by cSoftHdDevice::OnEnteringState().
| void cSoftHdAudio::Filter | ( | AVFrame * | inframe, |
| AVCodecContext * | ctx | ||
| ) |
Send audio frame to filter and enqueue it.
| inframe | incoming audio frame to be filtered |
| ctx | AVCodec audio decoding context |
| 1 | error, send again |
| 0 | running |
Definition at line 938 of file audio.cpp.
References CheckForFilterReady(), EnqueueFrame(), FilterGetFrame(), L_SOUND, LOGDEBUG2, LOGERROR, m_filterChanged, and m_pBuffersrcCtx.
Referenced by cAudioDecoder::Decode().
Get frame from filter sink.
Definition at line 872 of file audio.cpp.
References LOGERROR, and m_pBuffersinkCtx.
Referenced by Filter().
|
private |
Find alsa device giving some search hints.
| devname | interface identification (e.g. "pcm") |
| hint | string to compare with device name hints |
| passthrough | set, if we want a passthrough device |
Definition at line 1612 of file audio.cpp.
References LOGWARNING, and OpenAlsaDevice().
Referenced by AlsaInitPCMDevice().
Flush alsa buffers.
Definition at line 1246 of file audio.cpp.
References FlushAlsaBuffersInternal().
Referenced by FlushBuffers().
Flush alsa buffers internally.
| drop | force a snd_pcm_drop of the audio frames already in the kernel |
Definition at line 1264 of file audio.cpp.
References L_SOUND, LOGDEBUG2, LOGERROR, m_compressionFactor, m_compressionMaxFactor, m_normalizeAverage, m_normalizeCounter, m_normalizeFactor, m_normalizeReady, m_pAlsaPCMHandle, m_passthrough, and NORMALIZE_MAX_INDEX.
Referenced by DropAlsaBuffers(), and FlushAlsaBuffers().
Flush audio buffers.
Flush the alsa buffers and reset audio: pts, ringbuffer, pidController, fillLevel
Definition at line 981 of file audio.cpp.
References AV_NOPTS_VALUE, FlushAlsaBuffers(), L_SOUND, LOGDEBUG2, m_fillLevel, m_filterChanged, m_initialized, m_inputPts, m_mutex, m_pidController, m_pRingbuffer, cBufferFillLevelLowPassFilter::Reset(), cPidController::Reset(), cSoftHdRingbuffer::Reset(), and cBufferFillLevelLowPassFilter::ResetFramesCounters().
Referenced by cSoftHdDevice::FlushAudio().
Definition at line 212 of file audio.h.
References m_hwSampleRate.
Referenced by GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), GetOutputPtsMsInternal(), and SetHwDelayBaseline().
Definition at line 213 of file audio.h.
References m_hwSampleRate.
Referenced by ClockDriftCompensation().
Definition at line 72 of file audio.h.
References AV_SYNC_BORDER_MS.
Referenced by cVideoRender::DisplayFrame().
Get the hardware delay in milliseconds.
Definition at line 1065 of file audio.cpp.
References AV_NOPTS_VALUE, FramesToMs(), m_hwSampleRate, m_inputPts, m_mutex, and m_pAlsaPCMHandle.
Referenced by cVideoRender::LogDroppedDuped().
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.
Definition at line 1043 of file audio.cpp.
References AV_NOPTS_VALUE, FramesToMs(), GetOutputPtsMsInternal(), m_hwBaseline, m_hwSampleRate, m_inputPts, m_mutex, and m_pAlsaPCMHandle.
Referenced by cSoftHdPlayer::Action(), cVideoRender::DisplayFrame(), GetHardwareOutputPtsTimebaseUnits(), and cSoftHdPlayer::Play().
Get the hardware output PTS in timebase units.
Definition at line 1084 of file audio.cpp.
References AV_NOPTS_VALUE, GetHardwareOutputPtsMs(), and MsToPts().
Referenced by cSoftHdDevice::GetSTC().
Definition at line 70 of file audio.h.
References m_inputPts, and PtsToMs().
Referenced by cSoftHdDevice::IsBufferingThresholdReached().
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.
Definition at line 1022 of file audio.cpp.
References GetOutputPtsMsInternal(), and m_mutex.
Referenced by cSoftHdDevice::GetFirstAudioPtsMsToPlay(), cSoftHdDevice::GetFirstVideoPtsMsToPlay(), cSoftHdDevice::IsBufferingThresholdReached(), and cSoftHdDevice::OnEventReceived().
Definition at line 1029 of file audio.cpp.
References FramesToMs(), m_inputPts, m_pAlsaPCMHandle, m_pRingbuffer, PtsToMs(), and cSoftHdRingbuffer::UsedBytes().
Referenced by DropSamplesOlderThanPtsMs(), GetHardwareOutputPtsMs(), and GetOutputPtsMs().
Definition at line 68 of file audio.h.
References m_passthrough.
Get used bytes in audio ringbuffer.
Definition at line 1004 of file audio.cpp.
References m_pRingbuffer, and cSoftHdRingbuffer::UsedBytes().
Referenced by cVideoRender::LogDroppedDuped().
Handle an alsa error.
Definition at line 1231 of file audio.cpp.
References AUDIO, LOGERROR, m_eventQueue, m_pAlsaPCMHandle, and m_passthrough.
Referenced by CyclicCall().
Definition at line 69 of file audio.h.
References AV_NOPTS_VALUE, and m_inputPts.
Referenced by DropSamplesOlderThanPtsMs(), cSoftHdDevice::IsBufferingThresholdReached(), and cSoftHdDevice::OnEventReceived().
|
private |
Init audio filters.
The following alsa filters are set:
| 0 | everything ok |
| 1 | didn't support channels, downmix set -> scrap this frame, test next |
| -1 | something gone wrong |
Definition at line 473 of file audio.cpp.
References AlsaSetup(), BuildChannelMapFilter(), L_SOUND, LOGDEBUG2, LOGERROR, LOGWARNING, m_downmix, m_equalizerBand, m_filterChanged, m_filterReady, m_hwNumChannels, m_hwSampleRate, m_pAlsaPCMHandle, m_pBuffersinkCtx, m_pBuffersrcCtx, m_pFilterGraph, m_pTimebase, and m_useEqualizer.
Referenced by CheckForFilterReady().
Definition at line 61 of file audio.h.
References AUDIO_MIN_BUFFER_FREE, cSoftHdRingbuffer::FreeBytes(), and m_pRingbuffer.
Referenced by cSoftHdDevice::PlayAudio(), cSoftHdDevice::PlayAudioPkts(), and cSoftHdDevice::Poll().
Definition at line 58 of file audio.h.
References m_paused.
Referenced by cVideoRender::DisplayFrame().
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 1195 of file audio.cpp.
References AlsaInit(), and m_initialized.
Referenced by cSoftHdDevice::OnEventReceived(), cSoftHdDevice::PlayAudioPkts(), and cSoftHdDevice::PlayVideoPkts().
Definition at line 211 of file audio.h.
References m_hwSampleRate.
Referenced by AlsaSetup(), and DropSamplesOlderThanPtsMs().
Definition at line 210 of file audio.h.
References m_pTimebase.
Referenced by GetHardwareOutputPtsTimebaseUnits().
Normalize audio samples.
| samples | sample buffer |
| count | number of bytes in sample buffer |
Definition at line 81 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().
Open an alsa device.
| device | alsa device to be opened |
| passthrough | set, if this is a passthrough device |
Definition at line 1560 of file audio.cpp.
References L_SOUND, LOGDEBUG2, LOGWARNING, m_appendAES, and m_pAlsaPCMHandle.
Referenced by AlsaInitPCMDevice(), and FindAlsaDevice().
Process queued events and forward them to event receiver.
Definition at line 1544 of file audio.cpp.
References m_eventQueue, m_pEventReceiver, and IEventReceiver::OnEventReceived().
Referenced by Action().
Definition at line 209 of file audio.h.
References m_pTimebase.
Referenced by Enqueue(), GetInputPtsMs(), and GetOutputPtsMsInternal().
Reset the hw delay baseline.
Definition at line 1532 of file audio.cpp.
References L_SOUND, LOGDEBUG2, m_firstRealAudioReceived, m_hwBaseline, and m_mutex.
Referenced by cSoftHdDevice::OnEnteringState(), cSoftHdDevice::OnEventReceived(), and cSoftHdDevice::OnLeavingState().
Write regular audio data from the ringbuffer to the hardware.
| freeAlsaBufferFrames | number of frames that can be written to the hardware |
| true | if data was written or the write should be scheduled again immediately |
| false | if no data was written |
Definition at line 1418 of file audio.cpp.
References cSoftHdRingbuffer::GetReadPointer(), L_SOUND, LOGDEBUG2, LOGERROR, LOGWARNING, m_alsaUseMmap, m_fillLevel, m_pAlsaPCMHandle, m_passthrough, m_pRingbuffer, m_softVolume, m_volume, cSoftHdRingbuffer::ReadAdvance(), SoftAmplify(), and cBufferFillLevelLowPassFilter::WroteFrames().
Referenced by CyclicCall().
Write pause to passthrough device.
Definition at line 1478 of file audio.cpp.
References LOGERROR, LOGWARNING, m_alsaUseMmap, m_pAlsaPCMHandle, m_pauseBurst, and m_spdifBurstSize.
Referenced by CyclicCall().
Definition at line 82 of file audio.h.
References m_appendAES.
Referenced by cMenuSetupSoft::Store().
Set volume compression parameters.
| enable | true, turn on compression |
| maxfac | max. factor of compression / 1000 |
Definition at line 1147 of file audio.cpp.
References m_compression, m_compressionFactor, and m_compressionMaxFactor.
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
Set equalizer bands.
| band | setting frequenz bands |
| onoff | set using equalizer |
Definition at line 248 of file audio.cpp.
References m_equalizerBand, m_filterChanged, and m_useEqualizer.
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
Set the hw delay baseline.
Definition at line 1512 of file audio.cpp.
References FramesToMs(), L_SOUND, LOGDEBUG2, m_firstRealAudioReceived, m_hwBaseline, m_pAlsaPCMHandle, and m_passthrough.
Referenced by cSoftHdDevice::OnEventReceived(), and cSoftHdDevice::OnLeavingState().
Set normalize volume parameters.
| enable | true, turn on normalize |
| maxfac | max. factor of normalize / 1000 |
Definition at line 1135 of file audio.cpp.
References m_normalize, and m_normalizeMaxFactor.
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
Set audio passthrough mask.
| mask | passthrough mask (as a bitmask) |
Definition at line 1176 of file audio.cpp.
References m_passthrough, and m_pitchPpm.
Referenced by cSoftHdDevice::SetPassthroughMask().
Set audio playback pause state.
| pause | true to pause, false to resume |
Definition at line 1121 of file audio.cpp.
References L_SOUND, LOGDEBUG2, m_paused, and m_pauseMutex.
Referenced by cSoftHdDevice::Clear(), cVideoRender::DisplayFrame(), cSoftHdDevice::OnEnteringState(), cSoftHdDevice::OnEventReceived(), and cSoftHdDevice::OnLeavingState().
Definition at line 77 of file audio.h.
References m_softVolume.
Referenced by cMenuSetupSoft::Store().
Set stereo loudness descent.
| delta | value (/1000) to reduce stereo volume |
Definition at line 1165 of file audio.cpp.
References m_stereoDescent, m_volume, and SetVolume().
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
|
inline |
Definition at line 83 of file audio.h.
References m_pTimebase.
Referenced by cAudioDecoder::DecodePassthrough().
| int cSoftHdAudio::Setup | ( | AVCodecContext * | ctx, |
| int | samplerate, | ||
| int | channels, | ||
| int | passthrough | ||
| ) |
Alsa setup wrapper.
only used for passthrough atm, setting up PCM goes via Filter()
| AudioCtx | AVCodec audio decoding context |
| samplerate | stream samplerate |
| channels | stream nb of channels |
| passthrough | passthrough enabled |
| 0 | everything ok |
| -1 | something gone wrong in AlsaSetup |
| 1 | no parameter change, no setup needed |
Definition at line 849 of file audio.cpp.
References AlsaSetup(), LOGERROR, m_downmix, m_hwNumChannels, m_hwSampleRate, and m_pTimebase.
Referenced by cAudioDecoder::UpdateFormat().
Set mixer volume (0-1000)
| volume | volume (0 .. 1000) |
Definition at line 1098 of file audio.cpp.
References AlsaSetVolume(), m_amplifier, m_hwNumChannels, m_passthrough, m_softVolume, m_stereoDescent, and m_volume.
Referenced by cSoftHdDevice::OnEventReceived(), SetStereoDescent(), and cSoftHdDevice::SetVolumeDevice().
Amplify the samples in software.
| samples | sample buffer |
| count | number of bytes in sample buffer |
Definition at line 219 of file audio.cpp.
References m_amplifier, m_bytesPerSample, and m_volume.
Referenced by SendAudio().
Stop the thread.
Definition at line 1337 of file audio.cpp.
References LOGDEBUG.
Referenced by AlsaSetup(), and Exit().
Minimum free space in audio buffer 8 packets for 8 channels.
Definition at line 94 of file audio.h.
Referenced by IsBufferFull().
absolute max a/v difference in ms which should trigger a resync
Definition at line 96 of file audio.h.
Referenced by Enqueue(), and GetAvResyncBorderMs().
|
private |
alsa buffer size in frames
Definition at line 103 of file audio.h.
Referenced by AlsaSetup(), and ClockDriftCompensation().
|
private |
internal -> mixer ratio * 1000
Definition at line 190 of file audio.h.
Referenced by AlsaInitMixer(), and AlsaSetVolume().
|
private |
use mmap
Definition at line 191 of file audio.h.
Referenced by AlsaSetup(), SendAudio(), and SendPause().
|
private |
software volume amplify factor
Definition at line 159 of file audio.h.
Referenced by SetVolume(), and SoftAmplify().
|
private |
flag ato utomatic append AES
Definition at line 127 of file audio.h.
Referenced by OpenAlsaDevice(), and SetAutoAES().
number of bytes per sample
Definition at line 108 of file audio.h.
Referenced by Compress(), EnqueueFrame(), Normalize(), and SoftAmplify().
|
private |
flag to use compress volume
Definition at line 153 of file audio.h.
Referenced by EnqueueFrame(), and SetCompression().
|
private |
current compression factor
Definition at line 154 of file audio.h.
Referenced by Compress(), FlushAlsaBuffersInternal(), and SetCompression().
|
private |
max. compression factor
Definition at line 155 of file audio.h.
Referenced by Compress(), FlushAlsaBuffersInternal(), and SetCompression().
|
private |
set stereo downmix
Definition at line 118 of file audio.h.
Referenced by AlsaSetup(), InitFilter(), SetDownmix(), and Setup().
|
private |
|
private |
event queue for incoming events
Definition at line 114 of file audio.h.
Referenced by Enqueue(), HandleError(), and ProcessEvents().
|
private |
low pass filter for the buffer fill level
Definition at line 100 of file audio.h.
Referenced by ClockDriftCompensation(), DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), and SendAudio().
|
private |
filter has changed
Definition at line 173 of file audio.h.
Referenced by CheckForFilterReady(), Filter(), FlushBuffers(), InitFilter(), and SetEq().
|
private |
filter is ready
Definition at line 174 of file audio.h.
Referenced by CheckForFilterReady(), and InitFilter().
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().
|
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().
number of hardware channels
Definition at line 110 of file audio.h.
Referenced by AlsaSetup(), InitFilter(), Setup(), and SetVolume().
hardware sample rate in Hz
Definition at line 109 of file audio.h.
Referenced by AlsaSetup(), FramesToMs(), FramesToMsDouble(), GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), InitFilter(), MsToFrames(), and Setup().
class initialized
Definition at line 107 of file audio.h.
Referenced by Exit(), FlushBuffers(), and LazyInit().
|
private |
pts clock (last pts in ringbuffer)
Definition at line 120 of file audio.h.
Referenced by Enqueue(), FlushBuffers(), GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), GetInputPtsMs(), GetOutputPtsMsInternal(), and HasInputPts().
|
private |
last time the PID controller was invoked
Definition at line 102 of file audio.h.
Referenced by ClockDriftCompensation().
|
private |
mutex for thread safety
Definition at line 112 of file audio.h.
Referenced by CyclicCall(), DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), GetOutputPtsMs(), and ResetHwDelayBaseline().
|
private |
flag to use volume normalize
Definition at line 141 of file audio.h.
Referenced by EnqueueFrame(), and SetNormalize().
|
private |
average of n last normalize sample blocks
Definition at line 144 of file audio.h.
Referenced by FlushAlsaBuffersInternal(), and Normalize().
|
private |
normalize sample counter
Definition at line 143 of file audio.h.
Referenced by FlushAlsaBuffersInternal(), and Normalize().
|
private |
current normalize factor
Definition at line 147 of file audio.h.
Referenced by FlushAlsaBuffersInternal(), and Normalize().
|
private |
index into normalize average table
Definition at line 145 of file audio.h.
Referenced by Normalize().
|
private |
max. normalize factor
Definition at line 149 of file audio.h.
Referenced by Normalize(), and SetNormalize().
|
private |
index normalize counter
Definition at line 146 of file audio.h.
Referenced by FlushAlsaBuffersInternal(), and Normalize().
|
private |
packet counter for logging
Definition at line 104 of file audio.h.
Referenced by ClockDriftCompensation().
|
private |
alsa mixer handle
Definition at line 188 of file audio.h.
Referenced by AlsaExit(), AlsaInitMixer(), and AlsaSetVolume().
|
private |
alsa mixer element
Definition at line 189 of file audio.h.
Referenced by AlsaExit(), AlsaInitMixer(), and AlsaSetVolume().
|
private |
alsa pcm handle
Definition at line 187 of file audio.h.
Referenced by AlsaExit(), AlsaInitPCMDevice(), AlsaSetup(), ClockDriftCompensation(), CyclicCall(), DropSamplesOlderThanPtsMs(), Enqueue(), FlushAlsaBuffersInternal(), GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), GetOutputPtsMsInternal(), HandleError(), InitFilter(), OpenAlsaDevice(), SendAudio(), SendPause(), and SetHwDelayBaseline().
|
private |
passthrough mask
Definition at line 124 of file audio.h.
Referenced by AlsaInitPCMDevice(), ClockDriftCompensation(), CyclicCall(), FlushAlsaBuffersInternal(), GetPassthrough(), HandleError(), SendAudio(), SetHwDelayBaseline(), SetPassthroughMask(), and SetVolume().
|
private |
holds the burst data itself
Definition at line 129 of file audio.h.
Referenced by BuildPauseBurst(), EnqueueSpdif(), and SendPause().
audio is paused
Definition at line 121 of file audio.h.
Referenced by CyclicCall(), IsPaused(), and SetPaused().
|
private |
mutex for a safe thread pausing
Definition at line 113 of file audio.h.
Referenced by CyclicCall(), EnqueueSpdif(), and SetPaused().
|
private |
Definition at line 177 of file audio.h.
Referenced by FilterGetFrame(), and InitFilter().
|
private |
Definition at line 176 of file audio.h.
Referenced by Filter(), and InitFilter().
|
private |
|
private |
|
private |
|
private |
Definition at line 175 of file audio.h.
Referenced by CheckForFilterReady(), Exit(), and InitFilter().
|
private |
PID controller for clock drift compensation with tuning values coming from educated guesses.
Definition at line 101 of file audio.h.
Referenced by ClockDriftCompensation(), DropSamplesOlderThanPtsMs(), and FlushBuffers().
|
private |
|
private |
pitch adjustment in ppm. Positive values are faster
Definition at line 115 of file audio.h.
Referenced by ClockDriftCompensation(), Enqueue(), and SetPassthroughMask().
|
private |
sample ring buffer
Definition at line 184 of file audio.h.
Referenced by DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), GetOutputPtsMsInternal(), GetUsedBytes(), IsBufferFull(), and SendAudio().
|
private |
pointer to AVCodecContext pkts_timebase
Definition at line 111 of file audio.h.
Referenced by InitFilter(), MsToPts(), PtsToMs(), SetTimebase(), and Setup().
|
private |
flag to use soft volume
Definition at line 123 of file audio.h.
Referenced by SendAudio(), SetSoftvol(), and SetVolume().
|
private |
size of the current spdif burst
Definition at line 128 of file audio.h.
Referenced by BuildPauseBurst(), CyclicCall(), EnqueueSpdif(), and SendPause().
|
private |
volume descent for stereo
Definition at line 160 of file audio.h.
Referenced by SetStereoDescent(), and SetVolume().
|
private |
flag to use equalizer
Definition at line 165 of file audio.h.
Referenced by InitFilter(), and SetEq().
|
private |
current volume (0 .. 1000)
Definition at line 161 of file audio.h.
Referenced by SendAudio(), SetStereoDescent(), SetVolume(), and SoftAmplify().
number of normalize average samples
Definition at line 95 of file audio.h.
Referenced by FlushAlsaBuffersInternal(), and Normalize().