vdr-plugin-softhddevice-drm-gles 1.7.3-98a2ef7
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
26#include <vdr/remux.h>
27
28class cSoftHdAudio;
29
43 CODEC_AC3 = (1 << 2),
44 CODEC_EAC3 = (1 << 3),
45 CODEC_DTS = (1 << 4),
46};
47
62public:
64 ~cAudioDecoder(void);
65 void Open(AVCodecID, AVCodecParameters * = nullptr, AVRational = { .num = 1, .den = PTSTICKS });
66 void Close(void);
67 void Decode(const AVPacket *);
68 void FlushBuffers(void);
69 void SetPassthroughMask(int);
70 AVCodecID GetCodecId() const { return m_codecId; };
71
72private:
84 std::mutex m_mutex;
85
86 std::array<uint8_t, 32768> m_spdifIoBuffer;
88 std::vector<uint8_t> m_spdifOutputBuf;
89
90 constexpr static int AUDIO_PASSTHROUGH_NUM_CHANNELS = 2;
91 constexpr static int AUDIO_PASSTHROUGH_RATE_HZ = 48000;
92
93 bool OpenSpdifMuxer(AVCodecID, int);
94 void CloseSpdifMuxer(void);
95 const std::vector<uint8_t> &BuildIEC61937(const AVPacket *);
96#if LIBAVFORMAT_VERSION_MAJOR >= 61
97 static int SpdifWriteCallback(void *, const uint8_t *, int);
98#else
99 static int SpdifWriteCallback(void *, uint8_t *, int);
100#endif
101
102 bool ShouldTryPassthrough(void);
103 int Passthrough(const AVPacket *);
104 void DecodePCM(const AVPacket *);
105 int CheckUpdateFormat(bool);
106};
107
108#endif
Audio Decoder.
Definition codec_audio.h:61
AVFormatContext * m_spdifFmtCtx
spdif muxer context
Definition codec_audio.h:87
bool ShouldTryPassthrough(void)
Test, if passthrough audio should be tried.
AVCodecContext * m_pAudioCtx
ffmpeg audio codec context
Definition codec_audio.h:74
int m_currentHwSampleRate
current hw sample rate
Definition codec_audio.h:82
void FlushBuffers(void)
Flush the audio decoder buffers.
int m_currentHwNumChannels
current number of hw channels
Definition codec_audio.h:83
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:76
int m_currentPassthroughMask
current passthrough mask
Definition codec_audio.h:79
void CloseSpdifMuxer(void)
Close the spdif muxer and free the resources.
int m_passthroughMask
passthrough mask to be set
Definition codec_audio.h:78
AVCodecID m_codecId
current codec id
Definition codec_audio.h:75
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:70
void DecodePCM(const AVPacket *)
Decode an audio packet.
void Open(AVCodecID, AVCodecParameters *=nullptr, AVRational={ .num=1,.den=PTSTICKS })
Open and initiate the audio decoder.
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:90
std::vector< uint8_t > m_spdifOutputBuf
spdif muxer output
Definition codec_audio.h:88
std::mutex m_mutex
decoder mutex
Definition codec_audio.h:84
int64_t m_lastPts
last seen PTS
Definition codec_audio.h:77
int m_currentSampleRate
current sample rate
Definition codec_audio.h:80
static constexpr int AUDIO_PASSTHROUGH_RATE_HZ
fixed passthrough sample rate
Definition codec_audio.h:91
cSoftHdAudio * m_pAudio
audio module
Definition codec_audio.h:73
int m_currentNumChannels
current number of channels
Definition codec_audio.h:81
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:86
void Close(void)
Close the audio decoder.
Audio Interface.
Definition audio.h:51
PassthroughMask
Bits used for the passthrough mask.
Definition codec_audio.h:42
@ CODEC_EAC3
E-AC-3 bit mask.
Definition codec_audio.h:44
@ CODEC_AC3
AC-3 bit mask.
Definition codec_audio.h:43
@ CODEC_DTS
DTS bit mask.
Definition codec_audio.h:45
#define AV_NOPTS_VALUE
Definition misc.h:76