arduino-audio-tools
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
M4AAudioDemuxer Class Reference

A simple M4A audio data demuxer which is providing AAC, MP3 and ALAC frames. More...

#include <M4AAudioDemuxer.h>

Inheritance diagram for M4AAudioDemuxer:
M4ACommonDemuxer

Public Types

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

Public Member Functions

 M4AAudioDemuxer ()
 Constructor. Sets up parser callbacks.
 
int availableForWrite ()
 Returns the available space for writing.
 
bool begin ()
 Initializes the demuxer and resets state.
 
void copyFrom (M4ACommonDemuxer &source)
 
Vector< uint8_t > & getALACMagicCookie ()
 Returns the ALAC magic cookie (codec config).
 
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.
 
void setCallback (FrameCallback cb) override
 Defines the callback that returns the audio frames.
 
void setChunkOffsetsBuffer (BaseBuffer< uint32_t > &buffer)
 Sets the buffer to use for sample sizes.
 
void setM4AAudioConfig (M4AAudioConfig cfg)
 
void setReference (void *ref)
 Sets a reference pointer for callbacks.
 
void setSampleSizesBuffer (BaseBuffer< stsz_sample_size_t > &buffer)
 Sets the buffer to use for sample sizes.
 
void write (const uint8_t *data, size_t len)
 Writes data to the demuxer for parsing.
 

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 ()
 
void setupParser () override
 Setup all parser callbacks.
 

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_tbuffer
 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.
 
voidref = nullptr
 Reference pointer for callbacks.
 
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

A simple M4A audio data demuxer which is providing AAC, MP3 and ALAC frames.

Member Typedef Documentation

◆ FrameCallback

using FrameCallback = std::function<void(const Frame&, void* ref)>
inherited

Member Enumeration Documentation

◆ Codec

enum class Codec
stronginherited
Enumerator
Unknown 
AAC 
ALAC 
MP3 

Constructor & Destructor Documentation

◆ M4AAudioDemuxer()

M4AAudioDemuxer ( )
inline

Constructor. Sets up parser callbacks.

Member Function Documentation

◆ availableForWrite()

int availableForWrite ( )
inline

Returns the available space for writing.

Returns
Number of bytes available for writing.

◆ begin()

bool begin ( )
inline

Initializes the demuxer and resets state.

◆ checkType()

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

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.

◆ copyFrom()

void copyFrom ( M4ACommonDemuxer source)
inline

◆ getALACMagicCookie()

Vector< uint8_t > & getALACMagicCookie ( )
inline

Returns the ALAC magic cookie (codec config).

Returns
Reference to the ALAC magic cookie vector.

◆ getM4AAudioConfig()

M4AAudioConfig getM4AAudioConfig ( )
inlineinherited

◆ getSampleCount()

uint32_t getSampleCount ( ) const
inlineinherited

samples in stsz

◆ getStszFileOffset()

uint32_t getStszFileOffset ( ) const
inlineinherited

File offset of stsz box.

◆ onAlac()

void onAlac ( const MP4Parser::Box box)
inlineprotectedinherited

Handles the alac box.

Parameters
boxMP4 box.

◆ onEsds()

void onEsds ( const MP4Parser::Box box)
inlineprotectedinherited

Handles the esds (Elementary Stream Descriptor) box.

Parameters
boxMP4 box.

◆ onMp4a()

void onMp4a ( const MP4Parser::Box box)
inlineprotectedinherited

Handles the mp4a box.

Parameters
boxMP4 box.

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

◆ onStsd()

void onStsd ( const MP4Parser::Box box)
inlineprotectedinherited

◆ onStsz()

void onStsz ( MP4Parser::Box box)
inlineprotectedinherited

Handles the stsz (Sample Size) box.

Parameters
boxMP4 box.

◆ printHexDump()

void printHexDump ( const MP4Parser::Box box)
inlineprotectedinherited

◆ readU32() [1/2]

static uint32_t readU32 ( const uint32_t  num)
inlinestaticprotectedinherited

◆ readU32() [2/2]

static uint32_t readU32 ( const uint8_t p)
inlinestaticprotectedinherited

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

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

◆ readU32Buffer()

uint32_t readU32Buffer ( )
inlineprotectedinherited

◆ resize()

void resize ( int  size)
inlineinherited

◆ setAACConfig()

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

Sets the AAC configuration for ADTS header generation.

Parameters
profileAAC profile.
srIdxSample rate index.
chCfgChannel configuration.

◆ setCallback()

void setCallback ( FrameCallback  cb)
inlineoverridevirtual

Defines the callback that returns the audio frames.

Parameters
cbFrame callback function.

Reimplemented from M4ACommonDemuxer.

◆ setChunkOffsetsBuffer()

void setChunkOffsetsBuffer ( BaseBuffer< uint32_t > &  buffer)
inlineinherited

Sets the buffer to use for sample sizes.

Parameters
bufferReference to the buffer to use.

◆ setM4AAudioConfig()

void setM4AAudioConfig ( M4AAudioConfig  cfg)
inlineinherited

◆ setReference()

void setReference ( void ref)
inline

Sets a reference pointer for callbacks.

Parameters
refReference pointer.

◆ setSampleSizesBuffer()

void setSampleSizesBuffer ( BaseBuffer< stsz_sample_size_t > &  buffer)
inlineinherited

Sets the buffer to use for sample sizes.

Parameters
bufferReference to the buffer to use.

◆ setupParser()

void setupParser ( )
inlineoverrideprotectedvirtual

Setup all parser callbacks.

Implements M4ACommonDemuxer.

◆ write()

void write ( const uint8_t data,
size_t  len 
)
inline

Writes data to the demuxer for parsing.

Parameters
dataPointer to input data.
lenLength of input data.

Member Data Documentation

◆ audio_config

M4AAudioConfig audio_config
protectedinherited

◆ buffer

SingleBuffer<uint8_t> buffer
protectedinherited

Buffer for incremental data.

◆ chunk_offsets_count

uint32_t chunk_offsets_count = 0
protectedinherited

◆ default_size

size_t default_size = 2 * 1024
protectedinherited

Default buffer size.

◆ frame_callback

FrameCallback frame_callback = nullptr
protectedinherited

◆ parser

MP4Parser parser
protectedinherited

Underlying MP4 parser.

◆ ref

void* ref = nullptr
protected

Reference pointer for callbacks.

◆ sample_count

uint32_t sample_count = 0
protectedinherited

Number of samples in stsz.

◆ sampleExtractor

SampleExtractor sampleExtractor
protectedinherited
Initial value:
{
M4AAudioConfig audio_config
Definition M4ACommonDemuxer.h:443

Extractor for audio samples.

◆ stco_processed

bool stco_processed = false
protectedinherited

Marks the stco table as processed.

◆ stsd_processed

bool stsd_processed = false
protectedinherited

◆ stsz_offset

uint32_t stsz_offset = 0
protectedinherited

◆ stsz_processed

bool stsz_processed = false
protectedinherited

Marks the stsz table as processed.


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