vdr-plugin-softhddevice-drm-gles 1.6.7
cAudioDecoder Class Reference

Audio Decoder. More...

#include <codec_audio.h>

Public Member Functions

 cAudioDecoder (cSoftHdAudio *)
 Create a new audio decoder for the given audio context.
 
 ~cAudioDecoder (void)
 
void Open (AVCodecID, AVCodecParameters *=nullptr, AVRational={ .num=1,.den=90000 })
 Open and initiate the audio decoder.
 
void Close (void)
 Close the audio decoder.
 
void Decode (const AVPacket *)
 Forward an audio packet either to the decoder or passthrough.
 
void FlushBuffers (void)
 Flush the audio decoder buffers.
 
void SetPassthroughMask (int)
 Set audio pass-through mask.
 
AVCodecID GetCodecId () const
 

Private Member Functions

bool OpenSpdifMuxer (AVCodecID, int)
 Open the spdif muxer.
 
void CloseSpdifMuxer (void)
 Close the spdif muxer and free the resources.
 
const std::vector< uint8_t > & BuildIEC61937 (const AVPacket *)
 Prepend an IEC61937 header to the raw audio data by sending the avpkt to the spdif muxer.
 
bool ShouldTryPassthrough (void)
 Test, if passthrough audio should be tried.
 
int Passthrough (const AVPacket *)
 Passthrough audio data.
 
void DecodePCM (const AVPacket *)
 Decode an audio packet.
 
int CheckUpdateFormat (bool)
 Handle audio format changes and setup audio, if format changed.
 

Static Private Member Functions

static int SpdifWriteCallback (void *, uint8_t *, int)
 Callback for the spdif muxer.
 

Private Attributes

cSoftHdAudiom_pAudio
 audio module
 
AVCodecContextm_pAudioCtx = nullptr
 ffmpeg audio codec context
 
AVCodecID m_codecId = AV_CODEC_ID_NONE
 current codec id
 
AVFramem_pFrame
 decoded ffmpeg audio frame
 
int64_t m_lastPts = AV_NOPTS_VALUE
 last seen PTS
 
int m_passthroughMask
 passthrough mask to be set
 
int m_currentPassthroughMask
 current passthrough mask
 
int m_currentSampleRate
 current sample rate
 
int m_currentNumChannels
 current number of channels
 
int m_currentHwSampleRate
 current hw sample rate
 
int m_currentHwNumChannels
 current number of hw channels
 
std::mutex m_mutex
 decoder mutex
 
std::array< uint8_t, 32768 > m_spdifIoBuffer
 spdif I/O buffer
 
AVFormatContextm_spdifFmtCtx = nullptr
 spdif muxer context
 
std::vector< uint8_tm_spdifOutputBuf
 spdif muxer output
 

Static Private Attributes

static constexpr int AUDIO_PASSTHROUGH_NUM_CHANNELS = 2
 fixed passthrough channel number
 
static constexpr int AUDIO_PASSTHROUGH_RATE_HZ = 48000
 fixed passthrough sample rate
 

Detailed Description

Audio Decoder.

FFmpeg Based Audio Decoder Frontend

Handles:

  • Audio packet decoding using FFmpeg
  • SPDIF passthrough
  • Format changes
  • Audio frame delivery to cSoftHdAudio

Definition at line 59 of file codec_audio.h.

Constructor & Destructor Documentation

◆ cAudioDecoder()

cAudioDecoder::cAudioDecoder ( cSoftHdAudio audio)

Create a new audio decoder for the given audio context.

Parameters
audioaudio context

Definition at line 60 of file codec_audio.cpp.

References GetPassthroughMaskString(), L_CODEC, LOGDEBUG2, LOGFATAL, m_passthroughMask, and m_pFrame.

◆ ~cAudioDecoder()

cAudioDecoder::~cAudioDecoder ( void  )

Definition at line 70 of file codec_audio.cpp.

References Close(), and m_pFrame.

Member Function Documentation

◆ BuildIEC61937()

const std::vector< uint8_t > & cAudioDecoder::BuildIEC61937 ( const AVPacket avpkt)
private

Prepend an IEC61937 header to the raw audio data by sending the avpkt to the spdif muxer.

Parameters
avpktinput packet
Returns
output data from the spdif muxer (maybe nullptr, if no output is available)

Definition at line 242 of file codec_audio.cpp.

References av_err2str, LOGERROR, m_spdifFmtCtx, and m_spdifOutputBuf.

Referenced by Passthrough().

◆ CheckUpdateFormat()

int cAudioDecoder::CheckUpdateFormat ( bool  passthrough)
private

Handle audio format changes and setup audio, if format changed.

Return values
0if new audio was correctly set up, otherwise return value of cSoftHdAudio::Setup()

Definition at line 296 of file codec_audio.cpp.

References AUDIO_PASSTHROUGH_NUM_CHANNELS, AUDIO_PASSTHROUGH_RATE_HZ, CloseSpdifMuxer(), GetPassthroughMaskString(), L_SOUND, LOGDEBUG2, LOGERROR, m_currentHwNumChannels, m_currentHwSampleRate, m_currentNumChannels, m_currentPassthroughMask, m_currentSampleRate, m_passthroughMask, m_pAudio, m_pAudioCtx, and cSoftHdAudio::Setup().

Referenced by DecodePCM(), and Passthrough().

◆ Close()

void cAudioDecoder::Close ( void  )

Close the audio decoder.

Definition at line 134 of file codec_audio.cpp.

References AV_NOPTS_VALUE, CloseSpdifMuxer(), L_CODEC, LOGDEBUG2, m_codecId, m_lastPts, m_mutex, and m_pAudioCtx.

Referenced by cSoftHdDevice::PlayAudio(), and ~cAudioDecoder().

◆ CloseSpdifMuxer()

void cAudioDecoder::CloseSpdifMuxer ( void  )
private

Close the spdif muxer and free the resources.

Definition at line 220 of file codec_audio.cpp.

References L_CODEC, LOGDEBUG2, m_spdifFmtCtx, and m_spdifOutputBuf.

Referenced by CheckUpdateFormat(), Close(), and OpenSpdifMuxer().

◆ Decode()

void cAudioDecoder::Decode ( const AVPacket avpkt)

Forward an audio packet either to the decoder or passthrough.

Parameters
avpktaudio packet to decode

Definition at line 349 of file codec_audio.cpp.

References DecodePCM(), m_mutex, Passthrough(), and ShouldTryPassthrough().

Referenced by cSoftHdDevice::PlayAudio(), and cSoftHdDevice::PlayAudioPkts().

◆ DecodePCM()

void cAudioDecoder::DecodePCM ( const AVPacket avpkt)
private

Decode an audio packet.

Parameters
avpktaudio packet to decode

Definition at line 398 of file codec_audio.cpp.

References av_err2str, AV_NOPTS_VALUE, CheckUpdateFormat(), cSoftHdAudio::Filter(), LOGERROR, m_lastPts, m_pAudio, m_pAudioCtx, and m_pFrame.

Referenced by Decode().

◆ FlushBuffers()

void cAudioDecoder::FlushBuffers ( void  )

Flush the audio decoder buffers.

Also resets the last PTS and Codec ID

Definition at line 452 of file codec_audio.cpp.

References AV_NOPTS_VALUE, L_CODEC, LOGDEBUG2, m_codecId, m_lastPts, m_mutex, and m_pAudioCtx.

Referenced by cSoftHdDevice::FlushAudio().

◆ GetCodecId()

AVCodecID cAudioDecoder::GetCodecId ( ) const
inline

Definition at line 68 of file codec_audio.h.

References m_codecId.

Referenced by cSoftHdDevice::PlayAudio().

◆ Open()

void cAudioDecoder::Open ( AVCodecID  codecId,
AVCodecParameters par = nullptr,
AVRational  timebase = { .num = 1, .den = 90000 } 
)

Open and initiate the audio decoder.

Parameters
codecIdaudio codec id
paraudio codec parameters
timebasetimebase
Todo:
FIXME: errors shouldn't be fatal, maybe just disable audio

Definition at line 86 of file codec_audio.cpp.

References GetPassthroughMaskString(), L_CODEC, LOGDEBUG2, LOGERROR, LOGFATAL, m_codecId, m_currentHwNumChannels, m_currentHwSampleRate, m_currentNumChannels, m_currentPassthroughMask, m_currentSampleRate, m_mutex, m_passthroughMask, and m_pAudioCtx.

Referenced by cSoftHdDevice::PlayAudio(), and cSoftHdDevice::SetAudioCodec().

◆ OpenSpdifMuxer()

bool cAudioDecoder::OpenSpdifMuxer ( AVCodecID  codecId,
int  sampleRate 
)
private

Open the spdif muxer.

Parameters
codecIdCodec ID of the stream
sampleRateSamplerate of the stream
Returns
true, if the spdif muxer could be opened false on any error

Definition at line 178 of file codec_audio.cpp.

References CloseSpdifMuxer(), L_CODEC, LOGDEBUG2, LOGERROR, m_spdifFmtCtx, m_spdifIoBuffer, m_spdifOutputBuf, and SpdifWriteCallback().

Referenced by Passthrough().

◆ Passthrough()

int cAudioDecoder::Passthrough ( const AVPacket avpkt)
private

Passthrough audio data.

Build spdif headers depending on the codec and send the data to the audio device.

Parameters
avpktundecoded audio packet
Return values
0codec is not supported for passthrough, sth. went wrong or we need more data to finish a spdif burst packet
1spdif burst was enqueued

Definition at line 370 of file codec_audio.cpp.

References BuildIEC61937(), CheckUpdateFormat(), cSoftHdAudio::EnqueueSpdif(), LOGERROR, m_currentHwSampleRate, m_pAudio, m_pAudioCtx, m_spdifFmtCtx, OpenSpdifMuxer(), and cSoftHdAudio::SetTimebase().

Referenced by Decode().

◆ SetPassthroughMask()

void cAudioDecoder::SetPassthroughMask ( int  mask)

Set audio pass-through mask.

Parameters
maskcodec mask to enable (AC-3, E-AC-3, DTS)

Definition at line 469 of file codec_audio.cpp.

References CODEC_AC3, CODEC_DTS, CODEC_EAC3, and m_passthroughMask.

Referenced by cSoftHdDevice::SetPassthroughMask().

◆ ShouldTryPassthrough()

bool cAudioDecoder::ShouldTryPassthrough ( void  )
private

Test, if passthrough audio should be tried.

To enable passthrough, the current codec must be enabled in the setup

Currently supported: AC3, E-AC-3, DTS

Returns
true, if the data should be passed through

Definition at line 283 of file codec_audio.cpp.

References CODEC_AC3, CODEC_DTS, CODEC_EAC3, m_passthroughMask, and m_pAudioCtx.

Referenced by Decode().

◆ SpdifWriteCallback()

int cAudioDecoder::SpdifWriteCallback ( void opaque,
uint8_t buffer,
int  bufferSize 
)
staticprivate

Callback for the spdif muxer.

This is called, whenever FFmpeg flushes data from the muxer to the AVIOContext. In the current implementation, a flush is forced after every muxer input write.

Definition at line 160 of file codec_audio.cpp.

Referenced by OpenSpdifMuxer().

Member Data Documentation

◆ AUDIO_PASSTHROUGH_NUM_CHANNELS

constexpr int cAudioDecoder::AUDIO_PASSTHROUGH_NUM_CHANNELS = 2
staticconstexprprivate

fixed passthrough channel number

Definition at line 88 of file codec_audio.h.

Referenced by CheckUpdateFormat().

◆ AUDIO_PASSTHROUGH_RATE_HZ

constexpr int cAudioDecoder::AUDIO_PASSTHROUGH_RATE_HZ = 48000
staticconstexprprivate

fixed passthrough sample rate

Definition at line 89 of file codec_audio.h.

Referenced by CheckUpdateFormat().

◆ m_codecId

AVCodecID cAudioDecoder::m_codecId = AV_CODEC_ID_NONE
private

current codec id

Definition at line 73 of file codec_audio.h.

Referenced by Close(), FlushBuffers(), GetCodecId(), and Open().

◆ m_currentHwNumChannels

int cAudioDecoder::m_currentHwNumChannels
private

current number of hw channels

Definition at line 81 of file codec_audio.h.

Referenced by CheckUpdateFormat(), and Open().

◆ m_currentHwSampleRate

int cAudioDecoder::m_currentHwSampleRate
private

current hw sample rate

Definition at line 80 of file codec_audio.h.

Referenced by CheckUpdateFormat(), Open(), and Passthrough().

◆ m_currentNumChannels

int cAudioDecoder::m_currentNumChannels
private

current number of channels

Definition at line 79 of file codec_audio.h.

Referenced by CheckUpdateFormat(), and Open().

◆ m_currentPassthroughMask

int cAudioDecoder::m_currentPassthroughMask
private

current passthrough mask

Definition at line 77 of file codec_audio.h.

Referenced by CheckUpdateFormat(), and Open().

◆ m_currentSampleRate

int cAudioDecoder::m_currentSampleRate
private

current sample rate

Definition at line 78 of file codec_audio.h.

Referenced by CheckUpdateFormat(), and Open().

◆ m_lastPts

int64_t cAudioDecoder::m_lastPts = AV_NOPTS_VALUE
private

last seen PTS

Definition at line 75 of file codec_audio.h.

Referenced by Close(), DecodePCM(), and FlushBuffers().

◆ m_mutex

std::mutex cAudioDecoder::m_mutex
private

decoder mutex

Definition at line 82 of file codec_audio.h.

Referenced by Close(), Decode(), FlushBuffers(), and Open().

◆ m_passthroughMask

int cAudioDecoder::m_passthroughMask
private

passthrough mask to be set

Definition at line 76 of file codec_audio.h.

Referenced by cAudioDecoder(), CheckUpdateFormat(), Open(), SetPassthroughMask(), and ShouldTryPassthrough().

◆ m_pAudio

cSoftHdAudio* cAudioDecoder::m_pAudio
private

audio module

Definition at line 71 of file codec_audio.h.

Referenced by CheckUpdateFormat(), DecodePCM(), and Passthrough().

◆ m_pAudioCtx

AVCodecContext* cAudioDecoder::m_pAudioCtx = nullptr
private

ffmpeg audio codec context

Definition at line 72 of file codec_audio.h.

Referenced by CheckUpdateFormat(), Close(), DecodePCM(), FlushBuffers(), Open(), Passthrough(), and ShouldTryPassthrough().

◆ m_pFrame

AVFrame* cAudioDecoder::m_pFrame
private

decoded ffmpeg audio frame

Definition at line 74 of file codec_audio.h.

Referenced by cAudioDecoder(), DecodePCM(), and ~cAudioDecoder().

◆ m_spdifFmtCtx

AVFormatContext* cAudioDecoder::m_spdifFmtCtx = nullptr
private

spdif muxer context

Definition at line 85 of file codec_audio.h.

Referenced by BuildIEC61937(), CloseSpdifMuxer(), OpenSpdifMuxer(), and Passthrough().

◆ m_spdifIoBuffer

std::array<uint8_t, 32768> cAudioDecoder::m_spdifIoBuffer
private

spdif I/O buffer

Definition at line 84 of file codec_audio.h.

Referenced by OpenSpdifMuxer().

◆ m_spdifOutputBuf

std::vector<uint8_t> cAudioDecoder::m_spdifOutputBuf
private

spdif muxer output

Definition at line 86 of file codec_audio.h.

Referenced by BuildIEC61937(), CloseSpdifMuxer(), and OpenSpdifMuxer().


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