vdr-plugin-softhddevice-drm-gles 1.4.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
cReassemblyBufferAudio Class Reference

Audio stream reassembly buffer. More...

#include <pes.h>

Collaboration diagram for cReassemblyBufferAudio:
Collaboration graph
[legend]

Public Member Functions

 cReassemblyBufferAudio ()
 
AVPacket * PopAvPacket () override
 Pop an audio AVPacket from the reassembly buffer. More...
 
AVCodecID TruncateBufferUntilFirstValidData ()
 Truncate buffer until the first valid audio frame. More...
 
SyncWordInfo FindSyncWord (const uint8_t *, int)
 Find the first audio sync word in data. More...
 
AVCodecID DetectCodecFromSyncWord (const uint8_t *, int)
 Detect audio codec from sync word pattern. More...
 
int GetFrameSizeForCodec (AVCodecID, const uint8_t *)
 Get the frame size for a given codec and frame header. More...
 
- Public Member Functions inherited from cReassemblyBuffer
virtual void Push (const uint8_t *data, int size, int64_t pts)
 
virtual AVPacket * PopAvPacket ()=0
 
bool IsEmpty ()
 
size_t GetSize ()
 
void Reset ()
 Reset the reassembly buffer. More...
 
AVCodecID GetCodec ()
 

Private Member Functions

SyncWordInfo FindTwoConsecutiveFramesWithSameSyncWord ()
 Find two consecutive audio frames with the same sync word. More...
 

Private Attributes

bool m_ptsInvalid = false
 flag indicating if PTS is invalid for current buffer, because it was truncated More...
 

Static Private Attributes

static constexpr int MAX_HEADER_SIZE = 6
 

Additional Inherited Members

- Protected Member Functions inherited from cReassemblyBuffer
 cReassemblyBuffer (const char *identifier)
 
AVPacket * PopAvPacket (int)
 Pop an AVPacket from the reassembly buffer. More...
 
- Protected Attributes inherited from cReassemblyBuffer
AVCodecID m_codec = AV_CODEC_ID_NONE
 detected codec ID More...
 
cPtsTrackingBuffer m_buffer
 fragmentation buffer More...
 
int64_t m_lastPoppedPts = AV_NOPTS_VALUE
 PTS of the last popped AVPacket. More...
 

Detailed Description

Audio stream reassembly buffer.

Reassembles audio elementary streams by detecting sync words and validating frame headers. Supports MP2, AAC (LATM/ADTS), AC3, and E-AC3 codecs.

Definition at line 172 of file pes.h.

Constructor & Destructor Documentation

◆ cReassemblyBufferAudio()

cReassemblyBufferAudio::cReassemblyBufferAudio ( )
inline

Definition at line 174 of file pes.h.

Member Function Documentation

◆ DetectCodecFromSyncWord()

AVCodecID cReassemblyBufferAudio::DetectCodecFromSyncWord ( const uint8_t *  syncWord,
int  size 
)

Detect audio codec from sync word pattern.

Checks if the data starts with a valid sync word for any supported audio codec. Uses the AudioCodecMap to test sync word patterns for MP2, AAC LATM, AAC ADTS, AC3, and E-AC3.

Parameters
syncWordPointer to potential sync word data
sizeSize of available data
Returns
Detected AVCodecID, or AV_CODEC_ID_NONE if no match

Definition at line 595 of file pes.cpp.

References AudioCodecMap.

Referenced by FindSyncWord(), FindTwoConsecutiveFramesWithSameSyncWord(), and TEST_CASE().

◆ FindSyncWord()

SyncWordInfo cReassemblyBufferAudio::FindSyncWord ( const uint8_t *  data,
int  size 
)

Find the first audio sync word in data.

Scans the data byte-by-byte looking for any recognized audio sync word pattern. Checks all supported audio codecs (MP2, AAC LATM, AAC ADTS, AC3, E-AC3).

Parameters
dataPointer to audio data
sizeSize of the data in bytes
Returns
SyncWordInfo with detected codec and position, or AV_CODEC_ID_NONE if not found

Definition at line 573 of file pes.cpp.

References DetectCodecFromSyncWord().

Referenced by FindTwoConsecutiveFramesWithSameSyncWord(), and TEST_CASE().

◆ FindTwoConsecutiveFramesWithSameSyncWord()

SyncWordInfo cReassemblyBufferAudio::FindTwoConsecutiveFramesWithSameSyncWord ( )
private

Find two consecutive audio frames with the same sync word.

Searches the buffer for a valid audio frame followed immediately by another frame of the same codec. This validates that the sync word and frame header are genuine and not false positives in random data.

The function modifies the buffer internally by erasing false positives as it searches. When no sync word is found, it keeps the last MAX_HEADER_SIZE bytes.

Returns
SyncWordInfo with codec ID and position, or AV_CODEC_ID_NONE if not found

Definition at line 526 of file pes.cpp.

References AudioCodecMap, SyncWordInfo::codecId, DetectCodecFromSyncWord(), cPtsTrackingBuffer::Erase(), FindSyncWord(), cPtsTrackingBuffer::GetSize(), cReassemblyBuffer::m_buffer, MAX_HEADER_SIZE, cPtsTrackingBuffer::Peek(), and SyncWordInfo::pos.

Referenced by TruncateBufferUntilFirstValidData().

◆ GetFrameSizeForCodec()

int cReassemblyBufferAudio::GetFrameSizeForCodec ( AVCodecID  codec,
const uint8_t *  data 
)

Get the frame size for a given codec and frame header.

Calculates the frame size by parsing the codec-specific frame header. Only used for testing purposes to expose the AudioCodecMap frame size calculation.

Parameters
codecThe audio codec ID
dataPointer to the frame header data
Returns
Frame size in bytes
Exceptions
std::out_of_rangeif codec is not in AudioCodecMap
std::invalid_argumentif frame header is invalid

Definition at line 619 of file pes.cpp.

References AudioCodecMap.

Referenced by TEST_CASE().

◆ PopAvPacket()

AVPacket * cReassemblyBufferAudio::PopAvPacket ( )
overridevirtual

Pop an audio AVPacket from the reassembly buffer.

Truncates the buffer to the first valid audio frame, detects the codec, and pops a complete audio frame as an AVPacket.

Returns
Allocated AVPacket with one audio frame, or nullptr if no valid frame found

Implements cReassemblyBuffer.

Definition at line 461 of file pes.cpp.

References AudioCodecMap, AV_NOPTS_VALUE, LOGERROR, LOGWARNING, cReassemblyBuffer::m_buffer, cReassemblyBuffer::m_codec, m_ptsInvalid, cPtsTrackingBuffer::Peek(), cReassemblyBuffer::PopAvPacket(), and TruncateBufferUntilFirstValidData().

Referenced by cSoftHdDevice::PlayAudio().

◆ TruncateBufferUntilFirstValidData()

AVCodecID cReassemblyBufferAudio::TruncateBufferUntilFirstValidData ( )

Truncate buffer until the first valid audio frame.

Searches for two consecutive audio frames with the same sync word to validate the frame header, then erases all data before the first valid frame. This removes garbage data and synchronizes to the audio stream.

Returns
Detected codec ID, or AV_CODEC_ID_NONE if no valid frames found

Definition at line 499 of file pes.cpp.

References SyncWordInfo::codecId, cPtsTrackingBuffer::Erase(), FindTwoConsecutiveFramesWithSameSyncWord(), cPtsTrackingBuffer::GetSize(), LOGDEBUG, cReassemblyBuffer::m_buffer, m_ptsInvalid, and SyncWordInfo::pos.

Referenced by PopAvPacket(), and TEST_CASE().

Member Data Documentation

◆ m_ptsInvalid

bool cReassemblyBufferAudio::m_ptsInvalid = false
private

flag indicating if PTS is invalid for current buffer, because it was truncated

Definition at line 183 of file pes.h.

Referenced by PopAvPacket(), and TruncateBufferUntilFirstValidData().

◆ MAX_HEADER_SIZE

constexpr int cReassemblyBufferAudio::MAX_HEADER_SIZE = 6
staticconstexprprivate

Definition at line 182 of file pes.h.

Referenced by FindTwoConsecutiveFramesWithSameSyncWord().


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