vdr-plugin-softhddevice-drm-gles 1.6.4-d0291bb
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 *)
 Decode an audio packet.
 
void FlushBuffers (void)
 Flush the audio decoder buffers.
 
void SetPassthroughMask (int)
 Set audio pass-through mask.
 
AVCodecID GetCodecId () const
 

Private Member Functions

int DecodePassthrough (const AVPacket *, AVFrame *)
 Passthrough audio data.
 
int UpdateFormat (void)
 Handle audio format changes.
 
void ResetSpdif (void)
 Rest the internal SPDIF burst buffer.
 

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
 
uint16_t m_spdifOutput [(MAX_FRAME_SIZE *4+16)/2]
 SPDIF output buffer.
 
int m_spdifIndex
 index into SPDIF output buffer
 
int m_spdifRepeatCount
 SPDIF repeat counter.
 
std::mutex m_mutex
 decoder mutex
 

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 100 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 35 of file codec_audio.cpp.

References L_CODEC, LOGDEBUG2, LOGFATAL, m_passthroughMask, and m_pFrame.

◆ ~cAudioDecoder()

cAudioDecoder::~cAudioDecoder ( void  )

Definition at line 45 of file codec_audio.cpp.

References Close(), and m_pFrame.

Member Function Documentation

◆ Close()

void cAudioDecoder::Close ( void  )

Close the audio decoder.

Definition at line 109 of file codec_audio.cpp.

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

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

◆ Decode()

void cAudioDecoder::Decode ( const AVPacket avpkt)

◆ DecodePassthrough()

int cAudioDecoder::DecodePassthrough ( const AVPacket avpkt,
AVFrame frame 
)
private

Passthrough audio data.

Build spdif headers depending on the codec and send the data to the audio device. Currently supported: AC3, EAC3, DTS

Parameters
avpktundecoded audio packet
framedecoded audio frame
Return values
0codec is not supported for passthrough, use Filter to handle the data
-1sth went wrong, data will be discarded
1data accepted if finished, spdif header was created and data was sent to passthrough device

Definition at line 139 of file codec_audio.cpp.

References AC3_FRAME_SIZE, CODEC_AC3, CODEC_DTS, CODEC_EAC3, DTS1_FRAME_SIZE, DTS2_FRAME_SIZE, DTS3_FRAME_SIZE, DTS_PREAMBLE_16BE_1, DTS_PREAMBLE_16BE_2, EAC3_FRAME_SIZE, cSoftHdAudio::EnqueueSpdif(), IEC61937_AC3, IEC61937_DTS1, IEC61937_DTS2, IEC61937_DTS3, IEC61937_EAC3, IEC61937_NULL, IEC61937_PREAMBLE1, IEC61937_PREAMBLE2, LOGERROR, m_currentHwSampleRate, m_currentPassthroughMask, m_pAudio, m_pAudioCtx, m_spdifIndex, m_spdifOutput, m_spdifRepeatCount, ResetSpdif(), and cSoftHdAudio::SetTimebase().

Referenced by Decode().

◆ FlushBuffers()

void cAudioDecoder::FlushBuffers ( void  )

Flush the audio decoder buffers.

Also resets the last PTS and Codec ID

Definition at line 428 of file codec_audio.cpp.

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

Referenced by cSoftHdDevice::FlushAudio().

◆ GetCodecId()

AVCodecID cAudioDecoder::GetCodecId ( ) const
inline

Definition at line 109 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 61 of file codec_audio.cpp.

References 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().

◆ ResetSpdif()

void cAudioDecoder::ResetSpdif ( void  )
private

Rest the internal SPDIF burst buffer.

Definition at line 445 of file codec_audio.cpp.

References m_spdifIndex, and m_spdifRepeatCount.

Referenced by DecodePassthrough(), and FlushBuffers().

◆ 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 456 of file codec_audio.cpp.

References CODEC_AC3, CODEC_DTS, CODEC_EAC3, L_CODEC, LOGDEBUG2, and m_passthroughMask.

Referenced by cSoftHdDevice::SetPassthroughMask().

◆ UpdateFormat()

int cAudioDecoder::UpdateFormat ( void  )
private

Handle audio format changes.

Setup audio, if format changed

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

Definition at line 305 of file codec_audio.cpp.

References CODEC_AC3, CODEC_DTS, CODEC_EAC3, L_SOUND, LOGDEBUG2, LOGERROR, m_currentHwNumChannels, m_currentHwSampleRate, m_currentNumChannels, m_currentPassthroughMask, m_currentSampleRate, m_passthroughMask, m_pAudio, m_pAudioCtx, m_spdifIndex, m_spdifRepeatCount, and cSoftHdAudio::Setup().

Referenced by Decode().

Member Data Documentation

◆ m_codecId

AVCodecID cAudioDecoder::m_codecId = AV_CODEC_ID_NONE
private

current codec id

Definition at line 114 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 122 of file codec_audio.h.

Referenced by Decode(), Open(), and UpdateFormat().

◆ m_currentHwSampleRate

int cAudioDecoder::m_currentHwSampleRate
private

current hw sample rate

Definition at line 121 of file codec_audio.h.

Referenced by Decode(), DecodePassthrough(), Open(), and UpdateFormat().

◆ m_currentNumChannels

int cAudioDecoder::m_currentNumChannels
private

current number of channels

Definition at line 120 of file codec_audio.h.

Referenced by Decode(), Open(), and UpdateFormat().

◆ m_currentPassthroughMask

int cAudioDecoder::m_currentPassthroughMask
private

current passthrough mask

Definition at line 118 of file codec_audio.h.

Referenced by Decode(), DecodePassthrough(), Open(), and UpdateFormat().

◆ m_currentSampleRate

int cAudioDecoder::m_currentSampleRate
private

current sample rate

Definition at line 119 of file codec_audio.h.

Referenced by Decode(), Open(), and UpdateFormat().

◆ m_lastPts

int64_t cAudioDecoder::m_lastPts = AV_NOPTS_VALUE
private

last seen PTS

Definition at line 116 of file codec_audio.h.

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

◆ m_mutex

std::mutex cAudioDecoder::m_mutex
private

decoder mutex

Definition at line 126 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 117 of file codec_audio.h.

Referenced by cAudioDecoder(), Decode(), Open(), SetPassthroughMask(), and UpdateFormat().

◆ m_pAudio

cSoftHdAudio* cAudioDecoder::m_pAudio
private

audio module

Definition at line 112 of file codec_audio.h.

Referenced by Decode(), DecodePassthrough(), and UpdateFormat().

◆ m_pAudioCtx

AVCodecContext* cAudioDecoder::m_pAudioCtx = nullptr
private

ffmpeg audio codec context

Definition at line 113 of file codec_audio.h.

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

◆ m_pFrame

AVFrame* cAudioDecoder::m_pFrame
private

decoded ffmpeg audio frame

Definition at line 115 of file codec_audio.h.

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

◆ m_spdifIndex

int cAudioDecoder::m_spdifIndex
private

index into SPDIF output buffer

Definition at line 124 of file codec_audio.h.

Referenced by DecodePassthrough(), ResetSpdif(), and UpdateFormat().

◆ m_spdifOutput

uint16_t cAudioDecoder::m_spdifOutput[(MAX_FRAME_SIZE *4+16)/2]
private

SPDIF output buffer.

Definition at line 123 of file codec_audio.h.

Referenced by DecodePassthrough().

◆ m_spdifRepeatCount

int cAudioDecoder::m_spdifRepeatCount
private

SPDIF repeat counter.

Definition at line 125 of file codec_audio.h.

Referenced by DecodePassthrough(), ResetSpdif(), and UpdateFormat().


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