|
vdr-plugin-softhddevice-drm-gles 1.7.3-98a2ef7
|
Audio Interface. More...
#include <audio.h>
Public Member Functions | |
| cSoftHdAudio (cSoftHdDevice *) | |
| Create a new audio context. | |
| int | LazyInit (void) |
| Initialize audio output module (alsa) | |
| void | Exit (void) |
| Cleanup audio output module (alsa) | |
| int | Setup (AVRational, int, int, bool) |
| 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 (const uint16_t *, int, int64_t pts) |
| Enqueue prepared spdif bursts in audio output queue. | |
| bool | IsBufferFull (void) |
| bool | IsBufferEmpty (void) |
| void | FlushBuffers (void) |
| Flush audio buffers. | |
| int | GetUsedRingbufferBytes (void) |
| Get used bytes in audio ringbuffer. | |
| int | GetUsedRingbufferMs (void) |
| Get used ms 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. | |
| bool | HasInputPts (void) |
| int64_t | GetInputPtsMs (void) |
| int64_t | GetOutputPtsMs (void) |
| Get the output PTS of the ringbuffer. | |
| int | GetAvResyncBorderMs (void) |
| void | SetTrickSpeed (double, bool, bool) |
| Set the trickspeed. | |
| void | AdvanceTrickSpeedPts (int64_t) |
| Advance the pts in trickspeed mode and delay "playback". | |
| int64_t | GetTrickSpeedPtsTimebaseUnits (void) |
| void | ResetTrickSpeedPts (void) |
| bool | IsForwardTrickSpeed (void) |
| bool | IsSlowTrickSpeed (void) |
| void | SetVolume (int) |
| Set mixer volume (0-1000) | |
| void | SetSoftvol (bool softVolume) |
| void | SetNormalize (bool, int) |
| Set normalize volume parameters. | |
| void | SetCompression (bool, int) |
| Set volume compression parameters. | |
| void | SetEqualizer (bool, int[18]) |
| Set equalizer bands. | |
| void | SetStereoDescent (int) |
| Set stereo loudness descent. | |
| void | SetPassthroughMask (int mask) |
| void | SetAutoAES (bool appendAes) |
| void | SetTimebase (AVRational timebase) |
| void | SetDownmix (int downMix) |
| int | GetPassthroughMask (void) const |
| 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 (const uint16_t *, int, int64_t) |
| 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 | RebuildPauseBurst (int) |
| Rebuild the pause spdif burst with the size of the last recognized normal spdif audio if size changed. | |
| void | Stop (void) |
| Stop the thread. | |
| void | FlushAlsaBuffers (void) |
| Flush alsa buffers. | |
| void | DropAlsaBuffers (void) |
| Drop alsa buffers. | |
| bool | CyclicCall (void) |
| Cyclic audio playback call. | |
| void | ProcessEvents (void) |
| Process queued events and forward them to event receiver. | |
| 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. | |
| std::string | BuildChannelMapFilter (const AVChannelLayout &) |
| Build the "|"-separated mappings list for the channelmap filter. | |
| int64_t | GetOutputPtsMsInternal (void) |
Private Attributes | |
| cSoftHdDevice * | m_pDevice |
| pointer to device | |
| cSoftHdConfig * | m_pConfig |
| pointer to config | |
| cAlsaDevice | m_alsa |
| alsa device | |
| 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_packetCounter = 0 |
| packet counter for logging | |
| bool | m_initialized = false |
| class initialized | |
| std::mutex | m_mutex |
| mutex for thread safety | |
| std::mutex | m_pauseMutex |
| mutex for a safe thread pausing | |
| std::mutex | m_queueMutex |
| mutex for queue safety | |
| 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_volume = 0 |
| current volume (0 .. 1000) | |
| int | m_stereoDescent |
| volume descent for stereo | |
| AVRational | m_timebase |
| AVCodecContext pkts_timebase. | |
| int64_t | m_inputPts = AV_NOPTS_VALUE |
| pts clock (last pts in ringbuffer) | |
| std::atomic< bool > | m_paused = true |
| audio is paused | |
| std::atomic< int64_t > | m_trickSpeedPts = AV_NOPTS_VALUE |
| pts of the last received (undecoded) packet during audio-only trickspeed | |
| std::atomic< double > | m_trickspeedFactor = 0 |
| current trickspeed factor for AdvanceTrickSpeedPts() | |
| std::atomic< bool > | m_trickspeed = false |
| true, if trickspeed is active | |
| std::atomic< bool > | m_forwardTrickspeed = true |
| current trickspeed direction | |
| bool | m_softVolume |
| flag to use soft volume | |
| int | m_spdifBurstSize = 0 |
| size of the current spdif burst | |
| std::vector< uint16_t > | m_pauseBurst |
| holds the burst data itself | |
| int | 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 | |
| cAudioProcessor | m_audioProcessor |
| bool | m_useNormalizer |
| flag to use volume normalize | |
| bool | m_useCompressor |
| flag to use compress volume | |
| bool | m_useEqualizer |
| flag to use equalizer | |
| 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 | |
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 | AV_SYNC_BORDER_MS = 5000 |
| absolute max a/v difference in ms which should trigger a resync | |
| static constexpr int | BYTES_PER_SAMPLE = 2 |
| number of bytes per sample | |
| static constexpr int64_t | PTS_WRAP = 1LL << 33 |
| wraparound mod for a 33-bit PTS | |
| static constexpr double | MAX_TRICKSPEED_STEP_DELAY_MS = 3000 |
| upper bound for a single AdvanceTrickSpeedPts(), in case of large/ erratic pts jumps | |
| 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(), SetEqualizer(), 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 1079 of file audio.cpp.
References CyclicCall(), LOGDEBUG, and ProcessEvents().
Advance the pts in trickspeed mode and delay "playback".
In normal playback, we retrieve the current audio pts by a calculation like: PTS = InputPTS - bufferered data - hardware delay This will work, if we deal with contigous data and ascending pts. In trickspeed (except slow forward), the data which comes from VDR is not contigous. So we can't use the above logic to calculate the current audio pts.
As a consequence we need to do some tricks here: The current pts will immediately be set as soon as the packet arrives (and has a valid pts of course).
We also have to handle the duration, a frame has to be displayed in the device. In case of playback containing video data, the render thread does this for us. In audio-only playback we do the following now: Calculate the difference in ms between the last two audio packets and use the trickspeed factor to calculate the delay. This will cause PlayAudio() to sleep exactly as long as needed. Because we have nothing to sync and don't hear anything anyway, it's enough to keep the pts moving for a correct trickspeed handling process bar display.
| pts | next audio input pts from |
Definition at line 820 of file audio.cpp.
References AV_NOPTS_VALUE, IsForwardTrickSpeed(), IsSlowTrickSpeed(), L_TRICK, LOGDEBUG2, m_alsa, m_timebase, m_trickspeedFactor, m_trickSpeedPts, MAX_TRICKSPEED_STEP_DELAY_MS, and cAlsaDevice::PtsToMs().
Referenced by cSoftHdDevice::PlayAudio().
|
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 647 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 1274 of file audio.cpp.
References cAlsaDevice::FramesToMsDouble(), cAlsaDevice::GetAvailableBufferFrames(), cBufferFillLevelLowPassFilter::GetBufferFillLevelFramesAvg(), cAlsaDevice::GetBufferSizeFrames(), cPidController::GetDTerm(), cPidController::GetITerm(), cPidController::GetPTerm(), cPidController::GetTargetValue(), cAlsaDevice::IsPassthroughActive(), cBufferFillLevelLowPassFilter::IsSettled(), L_SOUND, LOGDEBUG2, m_alsa, m_fillLevel, m_lastPidInvocation, m_packetCounter, m_pidController, m_pitchPpm, cPidController::SetTargetValue(), cPidController::Update(), and cBufferFillLevelLowPassFilter::UpdateAvgBufferFillLevel().
Referenced by cSoftHdDevice::PlayAudio().
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 1117 of file audio.cpp.
References AUDIO, DropSamplesOlderThanPtsMs(), cAlsaDevice::FramesToBytes(), cAlsaDevice::GetAvailableBufferFrames(), GetOutputPtsMs(), cAlsaDevice::HandleError(), cSoftHdDevice::IsAudioOnlyPlayback(), cSoftHdDevice::IsDraining(), IsForwardTrickSpeed(), cAlsaDevice::IsPassthroughActive(), IsSlowTrickSpeed(), L_TRICK, LOGDEBUG2, m_alsa, m_eventQueue, m_mutex, m_paused, m_pauseMutex, m_pDevice, m_queueMutex, m_spdifBurstSize, m_trickspeed, m_trickspeedFactor, SendAudio(), SendPause(), and cAlsaDevice::WaitUntilReady().
Referenced by Action().
Drop alsa buffers.
Definition at line 1063 of file audio.cpp.
References cAlsaDevice::FlushBuffers(), m_alsa, m_audioProcessor, cAudioProcessor::ResetCompressor(), and cAudioProcessor::ResetNormalizer().
Referenced by Setup().
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 420 of file audio.cpp.
References cAlsaDevice::FramesToBytes(), GetOutputPtsMsInternal(), HasInputPts(), L_AV_SYNC, LOGDEBUG2, m_alsa, m_fillLevel, m_mutex, m_pidController, m_pRingbuffer, cAlsaDevice::MsToFrames(), cSoftHdRingbuffer::ReadAdvance(), cBufferFillLevelLowPassFilter::Reset(), cPidController::Reset(), Timestamp2StringMs(), cSoftHdRingbuffer::UsedBytes(), and cBufferFillLevelLowPassFilter::WroteFrames().
Referenced by cSoftHdDevice::CheckAudioPlaybackStartConditions(), CyclicCall(), cVideoRender::DisplayFrame(), cSoftHdDevice::ResumeFromPause(), and cSoftHdDevice::SchedulePlaybackStart().
Send audio data to ringbuffer.
| buffer | data buffer |
| count | number of bytes in data buffer |
| pts | pts to set |
Definition at line 526 of file audio.cpp.
References AV_NOPTS_VALUE, AV_SYNC_BORDER_MS, cAlsaDevice::BytesToFrames(), cAlsaDevice::FramesToBytes(), cAlsaDevice::FramesToPts(), cAlsaDevice::IsPassthroughActive(), L_AV_SYNC, LOGDEBUG2, LOGERROR, m_alsa, m_eventQueue, m_fillLevel, m_inputPts, m_mutex, m_pitchAdjustFrameCounter, m_pitchPpm, m_pRingbuffer, m_queueMutex, m_timebase, cAlsaDevice::PtsToMs(), cBufferFillLevelLowPassFilter::ReceivedFrames(), Timestamp2StringMs(), and cSoftHdRingbuffer::Write().
Referenced by EnqueueFrame(), and EnqueueSpdif().
Place samples in audio output queue.
| frame | audio frame |
Definition at line 452 of file audio.cpp.
References BYTES_PER_SAMPLE, cAudioProcessor::Compress(), Enqueue(), m_audioProcessor, m_useCompressor, m_useNormalizer, and cAudioProcessor::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 |
| pts | pts of the buffer |
Definition at line 510 of file audio.cpp.
References Enqueue(), m_pauseMutex, and RebuildPauseBurst().
Referenced by cAudioDecoder::Passthrough().
Cleanup audio output module (alsa)
This currently also stops the audio thread.
Definition at line 1035 of file audio.cpp.
References cAlsaDevice::Exit(), L_SOUND, LOGDEBUG2, m_alsa, m_initialized, m_pFilterGraph, and Stop().
Referenced by cSoftHdDevice::EnterState().
| 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 680 of file audio.cpp.
References CheckForFilterReady(), EnqueueFrame(), FilterGetFrame(), L_SOUND, LOGDEBUG2, LOGERROR, m_filterChanged, and m_pBuffersrcCtx.
Referenced by cAudioDecoder::DecodePCM().
Get frame from filter sink.
Definition at line 614 of file audio.cpp.
References LOGERROR, and m_pBuffersinkCtx.
Referenced by Filter().
Flush alsa buffers.
Definition at line 1052 of file audio.cpp.
References cAlsaDevice::FlushBuffers(), m_alsa, m_audioProcessor, cAudioProcessor::ResetCompressor(), and cAudioProcessor::ResetNormalizer().
Referenced by FlushBuffers().
Flush audio buffers.
Flush the alsa buffers and reset audio: pts, ringbuffer, pidController, fillLevel
Definition at line 723 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 74 of file audio.h.
References AV_SYNC_BORDER_MS.
Referenced by cVideoRender::FrameDropNecessary().
Get the hardware delay in milliseconds.
Definition at line 892 of file audio.cpp.
References AV_NOPTS_VALUE, cAlsaDevice::FramesToMs(), cAlsaDevice::GetHwDelayFrames(), cAlsaDevice::IsRunning(), m_alsa, m_inputPts, and m_mutex.
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 866 of file audio.cpp.
References AV_NOPTS_VALUE, cAlsaDevice::FramesToMs(), cAlsaDevice::GetHwDelayFrames(), GetOutputPtsMsInternal(), cAlsaDevice::IsRunning(), m_alsa, m_hwBaseline, m_inputPts, m_mutex, m_timebase, PTS_WRAP, and cAlsaDevice::PtsToMs().
Referenced by cSoftHdPlayer::Action(), cVideoRender::DisplayFrame(), GetHardwareOutputPtsTimebaseUnits(), and cSoftHdPlayer::Play().
Get the hardware output PTS in timebase units.
Definition at line 909 of file audio.cpp.
References AV_NOPTS_VALUE, GetHardwareOutputPtsMs(), m_alsa, m_timebase, and cAlsaDevice::MsToPts().
Referenced by cSoftHdDevice::GetSTC().
Definition at line 72 of file audio.h.
References m_alsa, m_inputPts, m_timebase, and cAlsaDevice::PtsToMs().
Referenced by cSoftHdDevice::CheckAudioPlaybackStartConditions(), cSoftHdDevice::CheckPlaybackStartConditions(), and cVideoRender::LogDroppedDuped().
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 775 of file audio.cpp.
References GetOutputPtsMsInternal(), and m_mutex.
Referenced by cSoftHdDevice::CheckAudioPlaybackStartConditions(), cSoftHdDevice::CheckPlaybackStartConditions(), CyclicCall(), cSoftHdDevice::GetFirstAudioPtsMsToPlay(), cSoftHdDevice::GetFirstVideoPtsMsToPlay(), cSoftHdDevice::PausePlayback(), cSoftHdDevice::ResumeFromPause(), and cSoftHdDevice::SchedulePlaybackStart().
Definition at line 843 of file audio.cpp.
References AV_NOPTS_VALUE, cAlsaDevice::BytesToFrames(), cAlsaDevice::FramesToMs(), m_alsa, m_inputPts, m_pRingbuffer, m_timebase, PTS_WRAP, cAlsaDevice::PtsToMs(), and cSoftHdRingbuffer::UsedBytes().
Referenced by DropSamplesOlderThanPtsMs(), GetHardwareOutputPtsMs(), and GetOutputPtsMs().
Definition at line 95 of file audio.h.
References cAlsaDevice::GetPassthroughMask(), and m_alsa.
Definition at line 78 of file audio.h.
References m_trickSpeedPts.
Referenced by cSoftHdDevice::GetSTC().
Get used bytes in audio ringbuffer.
Definition at line 746 of file audio.cpp.
References m_mutex, m_pRingbuffer, and cSoftHdRingbuffer::UsedBytes().
Referenced by cVideoRender::LogDroppedDuped().
Get used ms in audio ringbuffer.
Definition at line 756 of file audio.cpp.
References cAlsaDevice::BytesToFrames(), cAlsaDevice::FramesToMs(), m_alsa, m_mutex, m_pRingbuffer, and cSoftHdRingbuffer::UsedBytes().
Referenced by cVideoRender::LogDroppedDuped().
Definition at line 71 of file audio.h.
References AV_NOPTS_VALUE, and m_inputPts.
Referenced by cSoftHdDevice::CheckAudioPlaybackStartConditions(), cSoftHdDevice::CheckPlaybackStartConditions(), DropSamplesOlderThanPtsMs(), and cSoftHdDevice::SchedulePlaybackStart().
|
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 203 of file audio.cpp.
References BuildChannelMapFilter(), cAlsaDevice::GetDownmix(), cAudioProcessor::GetEqualizerOptions(), cAlsaDevice::GetHwNumChannels(), cAlsaDevice::GetHwSampleRate(), L_SOUND, LOGDEBUG2, LOGERROR, LOGWARNING, m_alsa, m_audioProcessor, m_filterChanged, m_filterReady, m_pBuffersinkCtx, m_pBuffersrcCtx, m_pFilterGraph, m_useEqualizer, and Setup().
Referenced by CheckForFilterReady().
Definition at line 63 of file audio.h.
References cAlsaDevice::GetHwDelayFrames(), m_alsa, m_pRingbuffer, and cSoftHdRingbuffer::UsedBytes().
Referenced by cSoftHdDevice::Flush().
Definition at line 62 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 80 of file audio.h.
References m_forwardTrickspeed.
Referenced by AdvanceTrickSpeedPts(), CyclicCall(), cSoftHdDevice::GetSTC(), and cSoftHdDevice::PlayAudio().
Definition at line 59 of file audio.h.
References m_paused.
Referenced by cSoftHdDevice::CheckAudioPlaybackStartConditions(), cSoftHdDevice::CheckPlaybackStartConditions(), and cVideoRender::FrameDropNecessary().
Definition at line 81 of file audio.h.
References m_trickspeedFactor.
Referenced by AdvanceTrickSpeedPts(), CyclicCall(), cSoftHdDevice::GetSTC(), and cSoftHdDevice::PlayAudio().
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.
| 0 | on success, or if audio is already initialized |
| -1 | on error |
Definition at line 1013 of file audio.cpp.
References cAlsaDevice::Init(), LOGERROR, m_alsa, and m_initialized.
Referenced by cSoftHdDevice::InitAudio(), cSoftHdDevice::PlayAudioPkts(), and cSoftHdDevice::PlayVideoPkts().
Process queued events and forward them to event receiver.
Definition at line 1256 of file audio.cpp.
References m_eventQueue, m_pDevice, m_queueMutex, and cSoftHdDevice::TriggerEvent().
Referenced by Action().
Rebuild the pause spdif burst with the size of the last recognized normal spdif audio if size changed.
| size | spdif burst size in bytes |
Definition at line 478 of file audio.cpp.
References L_SOUND, LOGDEBUG2, m_pauseBurst, and m_spdifBurstSize.
Referenced by EnqueueSpdif().
Reset the hw delay baseline.
Definition at line 1244 of file audio.cpp.
References L_SOUND, LOGDEBUG2, m_firstRealAudioReceived, m_hwBaseline, and m_mutex.
Referenced by cSoftHdDevice::Clear(), cSoftHdDevice::EnterState(), cSoftHdDevice::LeaveState(), and cSoftHdDevice::PausePlayback().
Definition at line 79 of file audio.h.
References AV_NOPTS_VALUE, and m_trickSpeedPts.
Referenced by cSoftHdDevice::EnterState().
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 1180 of file audio.cpp.
References cAudioProcessor::Amplify(), cAlsaDevice::BytesToFrames(), cAlsaDevice::CheckWrittenFrames(), cAlsaDevice::FramesToBytes(), cSoftHdRingbuffer::GetReadPointer(), cAlsaDevice::IsPassthroughActive(), m_alsa, m_audioProcessor, m_fillLevel, m_pRingbuffer, m_softVolume, m_volume, cSoftHdRingbuffer::ReadAdvance(), cAlsaDevice::Write(), and cBufferFillLevelLowPassFilter::WroteFrames().
Referenced by CyclicCall().
Write pause to passthrough device.
Definition at line 1214 of file audio.cpp.
References cAlsaDevice::BytesToFrames(), cAlsaDevice::CheckWrittenFrames(), m_alsa, m_pauseBurst, m_spdifBurstSize, and cAlsaDevice::Write().
Referenced by CyclicCall().
Definition at line 92 of file audio.h.
References m_alsa, and cAlsaDevice::SetAutoAES().
Referenced by cMenuSetupSoft::Store().
Set volume compression parameters.
| enable | true, turn on compression |
| maxfac | max. factor of compression / 1000 |
Definition at line 971 of file audio.cpp.
References m_audioProcessor, m_useCompressor, and cAudioProcessor::SetCompressor().
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
Definition at line 94 of file audio.h.
References m_alsa, and cAlsaDevice::SetDownmix().
Referenced by cMenuSetupSoft::Store().
Set equalizer bands.
| enable | set using equalizer |
| band | setting frequenz bands |
Definition at line 983 of file audio.cpp.
References m_audioProcessor, m_filterChanged, m_useEqualizer, and cAudioProcessor::SetEqualizer().
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
Set the hw delay baseline.
Definition at line 1226 of file audio.cpp.
References cAlsaDevice::FramesToMs(), cAlsaDevice::GetHwDelayFrames(), cAlsaDevice::IsPassthroughActive(), L_SOUND, LOGDEBUG2, m_alsa, m_firstRealAudioReceived, and m_hwBaseline.
Referenced by cSoftHdDevice::LeaveState(), and cSoftHdDevice::ResumeFromPause().
Set normalize volume parameters.
| enable | true, turn on normalize |
| maxfac | max. factor of normalize / 1000 |
Definition at line 959 of file audio.cpp.
References m_audioProcessor, m_useNormalizer, and cAudioProcessor::SetNormalizer().
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
Definition at line 91 of file audio.h.
References m_alsa, and cAlsaDevice::SetPassthroughMask().
Referenced by cSoftHdDevice::SetPassthroughMask().
Set audio playback pause state.
| pause | true to pause, false to resume |
Definition at line 945 of file audio.cpp.
References L_SOUND, LOGDEBUG2, m_paused, and m_pauseMutex.
Referenced by cSoftHdDevice::Clear(), cVideoRender::DisplayFrame(), cSoftHdDevice::EnterState(), cVideoRender::FrameDropNecessary(), cSoftHdDevice::LeaveState(), cSoftHdDevice::PausePlayback(), cSoftHdDevice::PlayAudio(), and cSoftHdDevice::ResumeFromPause().
Definition at line 84 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 995 of file audio.cpp.
References m_stereoDescent, m_volume, and SetVolume().
Referenced by cSoftHdAudio(), and cMenuSetupSoft::Store().
|
inline |
Definition at line 93 of file audio.h.
References m_timebase.
Referenced by cAudioDecoder::Passthrough().
Set the trickspeed.
| speed | trickspeed factor |
| active | true, if trickspeed is currently active |
| forward | true, if this is forward trickspeed |
Definition at line 789 of file audio.cpp.
References m_forwardTrickspeed, m_trickspeed, and m_trickspeedFactor.
Referenced by cSoftHdDevice::LeaveState(), and cSoftHdDevice::SetTrickSpeed().
| int cSoftHdAudio::Setup | ( | AVRational | timebase, |
| int | samplerate, | ||
| int | channels, | ||
| bool | passthrough | ||
| ) |
Alsa setup wrapper.
only used for passthrough atm, setting up PCM goes via Filter()
| timebase | codec timebase |
| 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 583 of file audio.cpp.
References cSoftHdConfig::ConfigAudioDownmix, DropAlsaBuffers(), cAlsaDevice::GetDownmix(), cAlsaDevice::GetHwNumChannels(), cAlsaDevice::GetHwSampleRate(), cAlsaDevice::IsPassthroughActive(), LOGERROR, m_alsa, m_pConfig, m_timebase, cAlsaDevice::Setup(), and Stop().
Referenced by cAudioDecoder::CheckUpdateFormat(), and InitFilter().
Set mixer volume (0-1000)
| volume | volume (0 .. 1000) |
Definition at line 923 of file audio.cpp.
References cAlsaDevice::GetHwNumChannels(), cAlsaDevice::IsPassthroughActive(), m_alsa, m_audioProcessor, m_softVolume, m_stereoDescent, m_volume, cAudioProcessor::SetAmplifier(), and cAlsaDevice::SetVolume().
Referenced by cSoftHdDevice::InitAudio(), SetStereoDescent(), and cSoftHdDevice::SetVolumeDevice().
Minimum free space in audio buffer 8 packets for 8 channels.
Definition at line 106 of file audio.h.
Referenced by IsBufferFull().
absolute max a/v difference in ms which should trigger a resync
Definition at line 107 of file audio.h.
Referenced by Enqueue(), and GetAvResyncBorderMs().
|
private |
alsa device
Definition at line 114 of file audio.h.
Referenced by AdvanceTrickSpeedPts(), BuildChannelMapFilter(), ClockDriftCompensation(), CyclicCall(), DropAlsaBuffers(), DropSamplesOlderThanPtsMs(), Enqueue(), Exit(), FlushAlsaBuffers(), GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), GetHardwareOutputPtsTimebaseUnits(), GetInputPtsMs(), GetOutputPtsMsInternal(), GetPassthroughMask(), GetUsedRingbufferMs(), InitFilter(), IsBufferEmpty(), LazyInit(), SendAudio(), SendPause(), SetAutoAES(), SetDownmix(), SetHwDelayBaseline(), SetPassthroughMask(), Setup(), and SetVolume().
|
private |
Definition at line 158 of file audio.h.
Referenced by DropAlsaBuffers(), EnqueueFrame(), FlushAlsaBuffers(), InitFilter(), SendAudio(), SetCompression(), SetEqualizer(), SetNormalize(), and SetVolume().
|
private |
event queue for incoming events
Definition at line 125 of file audio.h.
Referenced by CyclicCall(), Enqueue(), and ProcessEvents().
|
private |
low pass filter for the buffer fill level
Definition at line 115 of file audio.h.
Referenced by ClockDriftCompensation(), DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), and SendAudio().
|
private |
filter has changed
Definition at line 168 of file audio.h.
Referenced by CheckForFilterReady(), Filter(), FlushBuffers(), InitFilter(), and SetEqualizer().
|
private |
filter is ready
Definition at line 169 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 144 of file audio.h.
Referenced by ResetHwDelayBaseline(), and SetHwDelayBaseline().
current trickspeed direction
Definition at line 138 of file audio.h.
Referenced by IsForwardTrickSpeed(), and SetTrickSpeed().
|
private |
saves the hw delay (pause bursts) once a real audio frame to correctly do the AV-Sync
Definition at line 143 of file audio.h.
Referenced by GetHardwareOutputPtsMs(), ResetHwDelayBaseline(), and SetHwDelayBaseline().
class initialized
Definition at line 121 of file audio.h.
Referenced by Exit(), FlushBuffers(), and LazyInit().
|
private |
pts clock (last pts in ringbuffer)
Definition at line 133 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 117 of file audio.h.
Referenced by ClockDriftCompensation().
|
private |
mutex for thread safety
Definition at line 122 of file audio.h.
Referenced by CyclicCall(), DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), GetHardwareOutputDelayMs(), GetHardwareOutputPtsMs(), GetOutputPtsMs(), GetUsedRingbufferBytes(), GetUsedRingbufferMs(), and ResetHwDelayBaseline().
|
private |
packet counter for logging
Definition at line 118 of file audio.h.
Referenced by ClockDriftCompensation().
|
private |
holds the burst data itself
Definition at line 142 of file audio.h.
Referenced by RebuildPauseBurst(), and SendPause().
audio is paused
Definition at line 134 of file audio.h.
Referenced by CyclicCall(), IsPaused(), and SetPaused().
|
private |
mutex for a safe thread pausing
Definition at line 123 of file audio.h.
Referenced by CyclicCall(), EnqueueSpdif(), and SetPaused().
|
private |
Definition at line 172 of file audio.h.
Referenced by FilterGetFrame(), and InitFilter().
|
private |
Definition at line 171 of file audio.h.
Referenced by Filter(), and InitFilter().
|
private |
pointer to config
Definition at line 113 of file audio.h.
Referenced by cSoftHdAudio(), and Setup().
|
private |
pointer to device
Definition at line 112 of file audio.h.
Referenced by CyclicCall(), and ProcessEvents().
|
private |
Definition at line 170 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 116 of file audio.h.
Referenced by ClockDriftCompensation(), DropSamplesOlderThanPtsMs(), and FlushBuffers().
|
private |
|
private |
pitch adjustment in ppm. Positive values are faster
Definition at line 126 of file audio.h.
Referenced by ClockDriftCompensation(), and Enqueue().
|
private |
sample ring buffer
Definition at line 180 of file audio.h.
Referenced by DropSamplesOlderThanPtsMs(), Enqueue(), FlushBuffers(), GetOutputPtsMsInternal(), GetUsedRingbufferBytes(), GetUsedRingbufferMs(), IsBufferEmpty(), IsBufferFull(), and SendAudio().
|
private |
mutex for queue safety
Definition at line 124 of file audio.h.
Referenced by CyclicCall(), Enqueue(), and ProcessEvents().
|
private |
flag to use soft volume
Definition at line 140 of file audio.h.
Referenced by SendAudio(), SetSoftvol(), and SetVolume().
|
private |
size of the current spdif burst
Definition at line 141 of file audio.h.
Referenced by CyclicCall(), RebuildPauseBurst(), and SendPause().
|
private |
volume descent for stereo
Definition at line 130 of file audio.h.
Referenced by SetStereoDescent(), and SetVolume().
|
private |
AVCodecContext pkts_timebase.
Definition at line 131 of file audio.h.
Referenced by AdvanceTrickSpeedPts(), Enqueue(), GetHardwareOutputPtsMs(), GetHardwareOutputPtsTimebaseUnits(), GetInputPtsMs(), GetOutputPtsMsInternal(), SetTimebase(), and Setup().
true, if trickspeed is active
Definition at line 137 of file audio.h.
Referenced by CyclicCall(), and SetTrickSpeed().
|
private |
current trickspeed factor for AdvanceTrickSpeedPts()
Definition at line 136 of file audio.h.
Referenced by AdvanceTrickSpeedPts(), CyclicCall(), IsSlowTrickSpeed(), and SetTrickSpeed().
|
private |
pts of the last received (undecoded) packet during audio-only trickspeed
Definition at line 135 of file audio.h.
Referenced by AdvanceTrickSpeedPts(), GetTrickSpeedPtsTimebaseUnits(), and ResetTrickSpeedPts().
|
private |
flag to use compress volume
Definition at line 160 of file audio.h.
Referenced by EnqueueFrame(), and SetCompression().
|
private |
flag to use equalizer
Definition at line 161 of file audio.h.
Referenced by InitFilter(), and SetEqualizer().
|
private |
flag to use volume normalize
Definition at line 159 of file audio.h.
Referenced by EnqueueFrame(), and SetNormalize().
|
private |
current volume (0 .. 1000)
Definition at line 129 of file audio.h.
Referenced by SendAudio(), SetStereoDescent(), and SetVolume().
upper bound for a single AdvanceTrickSpeedPts(), in case of large/ erratic pts jumps
Definition at line 110 of file audio.h.
Referenced by AdvanceTrickSpeedPts().
wraparound mod for a 33-bit PTS
Definition at line 109 of file audio.h.
Referenced by GetHardwareOutputPtsMs(), and GetOutputPtsMsInternal().