arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Modules Pages
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
M4ACommonDemuxer Class Referenceabstract

Abstract base class for M4A/MP4 demuxers. Provides shared functionality for both file-based and stream-based demuxers. More...

#include <M4ACommonDemuxer.h>

Inheritance diagram for M4ACommonDemuxer:
M4AAudioDemuxer M4AAudioFileDemuxer

Classes

struct  ESDSParser
 A parser for the ESDS segment to extract the relevant aac information. More...
 
struct  Frame
 
struct  M4AAudioConfig
 
class  SampleExtractor
 Extracts audio data based on the sample sizes defined in the stsz box. It collects the data from the mdat box and calls the callback with the extracted frames. More...
 

Public Types

enum class  Codec { Unknown , AAC , ALAC , MP3 }
 
using FrameCallback = std::function< void(const Frame &, void *ref)>
 

Public Member Functions

void begin ()
 
M4AAudioConfig getM4AAudioConfig ()
 
uint32_t getSampleCount () const
 samples in stsz
 
uint32_t getStszFileOffset () const
 File offset of stsz box.
 
void resize (int size)
 
void setAACConfig (int profile, int srIdx, int chCfg)
 Sets the AAC configuration for ADTS header generation.
 
virtual void setCallback (FrameCallback cb)
 Sets the callback for extracted audio frames.
 
void setChunkOffsetsBuffer (BaseBuffer< uint32_t > &buffer)
 Sets the buffer to use for sample sizes.
 
void setM4AAudioConfig (M4AAudioConfig cfg)
 
void setSampleSizesBuffer (BaseBuffer< stsz_sample_size_t > &buffer)
 Sets the buffer to use for sample sizes.
 
virtual void setupParser ()=0
 

Protected Member Functions

bool checkType (uint8_t *buffer, const char *type, int offset)
 Checks if the buffer at the given offset matches the specified type.
 
void onAlac (const MP4Parser::Box &box)
 Handles the alac box.
 
void onEsds (const MP4Parser::Box &box)
 Handles the esds (Elementary Stream Descriptor) box.
 
void onMp4a (const MP4Parser::Box &box)
 Handles the mp4a box.
 
void onStsd (const MP4Parser::Box &box)
 
void onStsz (MP4Parser::Box &box)
 Handles the stsz (Sample Size) box.
 
void printHexDump (const MP4Parser::Box &box)
 
uint32_t readU32Buffer ()
 

Static Protected Member Functions

static uint32_t readU32 (const uint32_t num)
 
static uint32_t readU32 (const uint8_t *p)
 Reads a 32-bit big-endian unsigned integer from a buffer.
 

Protected Attributes

M4AAudioConfig audio_config
 
SingleBuffer< uint8_t > buffer
 Buffer for incremental data.
 
uint32_t chunk_offsets_count = 0
 
size_t default_size = 2 * 1024
 Default buffer size.
 
FrameCallback frame_callback = nullptr
 
MP4Parser parser
 Underlying MP4 parser.
 
uint32_t sample_count = 0
 Number of samples in stsz.
 
SampleExtractor sampleExtractor
 Extractor for audio samples.
 
bool stco_processed = false
 Marks the stco table as processed.
 
bool stsd_processed = false
 
uint32_t stsz_offset = 0
 
bool stsz_processed = false
 Marks the stsz table as processed.
 

Detailed Description

Abstract base class for M4A/MP4 demuxers. Provides shared functionality for both file-based and stream-based demuxers.

Member Function Documentation

◆ checkType()

bool checkType ( uint8_t *  buffer,
const char *  type,
int  offset 
)
inlineprotected

Checks if the buffer at the given offset matches the specified type.

Parameters
bufferPointer to the buffer.
type4-character type string (e.g. "mp4a").
offsetOffset in the buffer to check.
Returns
true if the type matches, false otherwise.

◆ onAlac()

void onAlac ( const MP4Parser::Box box)
inlineprotected

Handles the alac box.

Parameters
boxMP4 box.

◆ onEsds()

void onEsds ( const MP4Parser::Box box)
inlineprotected

Handles the esds (Elementary Stream Descriptor) box.

Parameters
boxMP4 box.

◆ onMp4a()

void onMp4a ( const MP4Parser::Box box)
inlineprotected

Handles the mp4a box.

Parameters
boxMP4 box.

for mp4a we expect to contain a esds: child boxes start at 36

◆ onStsz()

void onStsz ( MP4Parser::Box box)
inlineprotected

Handles the stsz (Sample Size) box.

Parameters
boxMP4 box.

◆ readU32()

static uint32_t readU32 ( const uint8_t *  p)
inlinestaticprotected

Reads a 32-bit big-endian unsigned integer from a buffer.

Parameters
pPointer to buffer.
Returns
32-bit unsigned integer.

◆ setAACConfig()

void setAACConfig ( int  profile,
int  srIdx,
int  chCfg 
)
inline

Sets the AAC configuration for ADTS header generation.

Parameters
profileAAC profile.
srIdxSample rate index.
chCfgChannel configuration.

◆ setCallback()

virtual void setCallback ( FrameCallback  cb)
inlinevirtual

Sets the callback for extracted audio frames.

Parameters
cbFrame callback function.

Reimplemented in M4AAudioDemuxer, and M4AAudioFileDemuxer.

◆ setChunkOffsetsBuffer()

void setChunkOffsetsBuffer ( BaseBuffer< uint32_t > &  buffer)
inline

Sets the buffer to use for sample sizes.

Parameters
bufferReference to the buffer to use.

◆ setSampleSizesBuffer()

void setSampleSizesBuffer ( BaseBuffer< stsz_sample_size_t > &  buffer)
inline

Sets the buffer to use for sample sizes.

Parameters
bufferReference to the buffer to use.

◆ setupParser()

virtual void setupParser ( )
pure virtual

Implemented in M4AAudioDemuxer, and M4AAudioFileDemuxer.

Member Data Documentation

◆ sampleExtractor

SampleExtractor sampleExtractor
protected
Initial value:
{
audio_config}

Extractor for audio samples.


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