vdr-plugin-softhddevice-drm-gles 1.6.7
codec_audio.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
13#ifndef __CODEC_AUDIO_H
14#define __CODEC_AUDIO_H
15
16#include <array>
17#include <cstdint>
18#include <mutex>
19#include <vector>
20
21extern "C" {
22#include <libavcodec/avcodec.h>
23#include <libavformat/avformat.h>
24}
25
26class cSoftHdAudio;
27
41 CODEC_AC3 = (1 << 2),
42 CODEC_EAC3 = (1 << 3),
43 CODEC_DTS = (1 << 4),
44};
45
60public:
62 ~cAudioDecoder(void);
63 void Open(AVCodecID, AVCodecParameters * = nullptr, AVRational = { .num = 1, .den = 90000 });
64 void Close(void);
65 void Decode(const AVPacket *);
66 void FlushBuffers(void);
67 void SetPassthroughMask(int);
68 AVCodecID GetCodecId() const { return m_codecId; };
69
70private:
82 std::mutex m_mutex;
83
84 std::array<uint8_t, 32768> m_spdifIoBuffer;
86 std::vector<uint8_t> m_spdifOutputBuf;
87
88 constexpr static int AUDIO_PASSTHROUGH_NUM_CHANNELS = 2;
89 constexpr static int AUDIO_PASSTHROUGH_RATE_HZ = 48000;
90
91 bool OpenSpdifMuxer(AVCodecID, int);
92 void CloseSpdifMuxer(void);
93 const std::vector<uint8_t> &BuildIEC61937(const AVPacket *);
94#if LIBAVFORMAT_VERSION_MAJOR >= 61
95 static int SpdifWriteCallback(void *, const uint8_t *, int);
96#else
97 static int SpdifWriteCallback(void *, uint8_t *, int);
98#endif
99
100 bool ShouldTryPassthrough(void);
101 int Passthrough(const AVPacket *);
102 void DecodePCM(const AVPacket *);
103 int CheckUpdateFormat(bool);
104};
105
106#endif
Audio Decoder.
Definition codec_audio.h:59
AVFormatContext * m_spdifFmtCtx
spdif muxer context
Definition codec_audio.h:85
bool ShouldTryPassthrough(void)
Test, if passthrough audio should be tried.
AVCodecContext * m_pAudioCtx
ffmpeg audio codec context
Definition codec_audio.h:72
int m_currentHwSampleRate
current hw sample rate
Definition codec_audio.h:80
void FlushBuffers(void)
Flush the audio decoder buffers.
int m_currentHwNumChannels
current number of hw channels
Definition codec_audio.h:81
void Decode(const AVPacket *)
Forward an audio packet either to the decoder or passthrough.
AVFrame * m_pFrame
decoded ffmpeg audio frame
Definition codec_audio.h:74
int m_currentPassthroughMask
current passthrough mask
Definition codec_audio.h:77
void CloseSpdifMuxer(void)
Close the spdif muxer and free the resources.
int m_passthroughMask
passthrough mask to be set
Definition codec_audio.h:76
AVCodecID m_codecId
current codec id
Definition codec_audio.h:73
static int SpdifWriteCallback(void *, uint8_t *, int)
Callback for the spdif muxer.
int Passthrough(const AVPacket *)
Passthrough audio data.
AVCodecID GetCodecId() const
Definition codec_audio.h:68
void DecodePCM(const AVPacket *)
Decode an audio packet.
int CheckUpdateFormat(bool)
Handle audio format changes and setup audio, if format changed.
void SetPassthroughMask(int)
Set audio pass-through mask.
bool OpenSpdifMuxer(AVCodecID, int)
Open the spdif muxer.
static constexpr int AUDIO_PASSTHROUGH_NUM_CHANNELS
fixed passthrough channel number
Definition codec_audio.h:88
std::vector< uint8_t > m_spdifOutputBuf
spdif muxer output
Definition codec_audio.h:86
std::mutex m_mutex
decoder mutex
Definition codec_audio.h:82
int64_t m_lastPts
last seen PTS
Definition codec_audio.h:75
int m_currentSampleRate
current sample rate
Definition codec_audio.h:78
static constexpr int AUDIO_PASSTHROUGH_RATE_HZ
fixed passthrough sample rate
Definition codec_audio.h:89
cSoftHdAudio * m_pAudio
audio module
Definition codec_audio.h:71
int m_currentNumChannels
current number of channels
Definition codec_audio.h:79
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.
std::array< uint8_t, 32768 > m_spdifIoBuffer
spdif I/O buffer
Definition codec_audio.h:84
void Open(AVCodecID, AVCodecParameters *=nullptr, AVRational={ .num=1,.den=90000 })
Open and initiate the audio decoder.
void Close(void)
Close the audio decoder.
Audio Interface.
Definition audio.h:51
PassthroughMask
Bits used for the passthrough mask.
Definition codec_audio.h:40
@ CODEC_EAC3
E-AC-3 bit mask.
Definition codec_audio.h:42
@ CODEC_AC3
AC-3 bit mask.
Definition codec_audio.h:41
@ CODEC_DTS
DTS bit mask.
Definition codec_audio.h:43
#define AV_NOPTS_VALUE
Definition misc.h:74