arduino-audio-tools
Loading...
Searching...
No Matches
ContainerM4A Class Reference

M4A Demuxer that extracts audio from M4A/MP4 containers. The audio is decoded into pcm with the help of the provided decoder. format. More...

#include <ContainerM4A.h>

Inheritance diagram for ContainerM4A:
ContainerDecoder AudioDecoder AudioDecoder AudioInfoSource AudioWriter AudioInfoSource AudioWriter AudioInfoSource AudioWriter AudioInfoSource AudioWriter

Public Member Functions

 ContainerM4A ()
 Default constructor: If no decoder is provided, the raw audio data is provided to the defined output.
 ContainerM4A (MultiDecoder &decoder)
 Constructor with decoder. Sets up the demuxer and decoder notification.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
AudioInfo audioInfo () override
 provides the actual input AudioInfo
AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
virtual bool begin (AudioInfo info) override
bool begin () override
 Initialize the demuxer and decoder.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
void end () override
 End the demuxer and decoder, releasing resources.
M4AAudioDemuxer & getDemuxer ()
Print * getOutput ()
Print * getOutput ()
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isResultPCM () override
 Returns true if the result is PCM (decoder is present).
const char * mime () override
 Provides "audio/mp4".
 operator bool () override
 Returns true if the demuxer is active.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
void setAudioInfo (AudioInfo from) override
 for most decoders this is not needed
void setAudioInfo (AudioInfo from) override
 for most decoders this is not needed
virtual void setChunkOffsetsBuffer (BaseBuffer< uint32_t > &buffer)
 Sets the buffer to use for sample sizes. This is currently not used!
virtual bool setCodecConfig (const uint8_t *data, size_t len)
 Some decoders need e.g. a magic cookie to provide the relevant info for decoding.
virtual bool setCodecConfig (const uint8_t *data, size_t len)
 Some decoders need e.g. a magic cookie to provide the relevant info for decoding.
bool setDecoder (MultiDecoder &decoder)
 Sets the decoder to use for audio frames.
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active).
virtual void setOutput (AudioOutput &out_stream)
 Defines where the decoded result is written to.
virtual void setOutput (AudioStream &out_stream)
 Defines where the decoded result is written to.
void setOutput (Print &out_stream) override
 Set the output stream for decoded or raw audio.
virtual void setSampleSizesBuffer (BaseBuffer< stsz_sample_size_t > &buffer)
 Sets the buffer to use for sample sizes. You can use this to provide a custom buffer that does not rely on RAM (e.g a file based buffer or one using Redis).
size_t write (const uint8_t *data, size_t len) override
 Feed data to the demuxer for parsing.

Public Attributes

int id
 custom id to be used by application

Protected Member Functions

void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
void writeBlocking (Print *out, uint8_t *data, size_t len)
void writeBlocking (Print *out, uint8_t *data, size_t len)

Static Protected Member Functions

static void decodeAudio (const M4AAudioDemuxer::Frame &frame, void *ref)
 Static callback for demuxed audio frames. Handles decoder selection and magic cookie for ALAC.

Protected Attributes

M4AAudioDemuxer demux
 Internal demuxer instance.
AudioInfo info
bool is_active = false
 True if demuxer is active.
bool is_magic_cookie_processed
 True if ALAC magic cookie has been processed.
bool is_notify_active = true
Vector< AudioInfoSupport * > notify_vector
MultiDecoder * p_decoder = nullptr
 Pointer to the MultiDecoder.
Print * p_print = nullptr

Detailed Description

M4A Demuxer that extracts audio from M4A/MP4 containers. The audio is decoded into pcm with the help of the provided decoder. format.

Audio-only, single-track: a thin ContainerDecoder wrapper around M4AAudioDemuxer (which itself inherits its MP4-box parsing from M4ACommonDemuxer), so it plugs directly into AudioPlayer/MultiDecoder the same way any other AudioDecoder does. If you also need the video track out of an interleaved .mp4 - or a second, independent audio track - use DemuxerMP4 (AudioCodecs/ContainerMP4.h) instead; it's a separate, multi-track implementation (own MP4-box handlers, per-track state, chunk-offset-based interleave resolution) rather than a superset of this class, since M4ACommonDemuxer's single-track audio_config model doesn't extend to per-track state without a rework. The two share the same box-parsing shape (stsd/mp4a/esds for AAC, stsd/alac for ALAC's magic cookie) but not code - keep that in mind if a bug is found in one, it may well apply to the other too.

Note
The underlying MP4Parser expects the moov box (sample/format info) to come before the mdat box (audio payload) - i.e. the file must be "faststart", e.g. via 'ffmpeg -movflags +faststart'. If mdat comes first, decoding fails since the needed format info isn't available yet; by default this is logged as an error. Call getDemuxer().getParser().setRequireMoovBeforeMdat(false) to downgrade that to a warning and attempt to continue anyway.
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ ContainerM4A() [1/2]

ContainerM4A ( )
inline

Default constructor: If no decoder is provided, the raw audio data is provided to the defined output.

◆ ContainerM4A() [2/2]

ContainerM4A ( MultiDecoder & decoder)
inline

Constructor with decoder. Sets up the demuxer and decoder notification.

Parameters
decoderReference to a MultiDecoder for PCM output.

Member Function Documentation

◆ addNotifyAudioChange() [1/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ addNotifyAudioChange() [2/2]

virtual void addNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Adds target to be notified about audio changes.

Reimplemented in CodecNOP, CodecNOP, EncodedAudioOutput, and EncodedAudioStream.

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ begin() [1/2]

virtual bool begin ( AudioInfo info)
inlineoverridevirtualinherited

Reimplemented from AudioWriter.

◆ begin() [2/2]

bool begin ( )
inlineoverridevirtual

Initialize the demuxer and decoder.

Returns
true on success.

Reimplemented from AudioDecoder.

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ decodeAudio()

void decodeAudio ( const M4AAudioDemuxer::Frame & frame,
void * ref )
inlinestaticprotected

Static callback for demuxed audio frames. Handles decoder selection and magic cookie for ALAC.

Parameters
frameThe demuxed audio frame.
refReference to the ContainerM4A instance.

◆ end()

void end ( )
inlineoverridevirtual

End the demuxer and decoder, releasing resources.

Reimplemented from AudioDecoder.

◆ getDemuxer()

M4AAudioDemuxer & getDemuxer ( )
inline

◆ getOutput() [1/2]

Print * getOutput ( )
inlineinherited

◆ getOutput() [2/2]

Print * getOutput ( )
inlineinherited

◆ isNotifyActive() [1/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isNotifyActive() [2/2]

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isResultPCM()

bool isResultPCM ( )
inlineoverridevirtual

Returns true if the result is PCM (decoder is present).

Returns
true if PCM output, false otherwise.

Reimplemented from ContainerDecoder.

◆ mime()

const char * mime ( )
inlineoverridevirtual

Provides "audio/mp4".

Implements AudioDecoder.

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Returns true if the demuxer is active.

Returns
true if active, false otherwise.

Implements AudioWriter.

◆ removeNotifyAudioChange() [1/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

◆ removeNotifyAudioChange() [2/2]

virtual bool removeNotifyAudioChange ( AudioInfoSupport & bi)
inlinevirtualinherited

Removes a target in order not to be notified about audio changes.

◆ setAudioInfo() [1/2]

void setAudioInfo ( AudioInfo from)
inlineoverridevirtualinherited

for most decoders this is not needed

Implements AudioWriter.

Reimplemented in CodecNOP, and CodecNOP.

◆ setAudioInfo() [2/2]

void setAudioInfo ( AudioInfo from)
inlineoverridevirtualinherited

for most decoders this is not needed

Implements AudioWriter.

Reimplemented in CodecNOP, and CodecNOP.

◆ setChunkOffsetsBuffer()

virtual void setChunkOffsetsBuffer ( BaseBuffer< uint32_t > & buffer)
inlinevirtual

Sets the buffer to use for sample sizes. This is currently not used!

Parameters
bufferReference to the buffer to use.

◆ setCodecConfig() [1/2]

virtual bool setCodecConfig ( const uint8_t * data,
size_t len )
inlinevirtualinherited

Some decoders need e.g. a magic cookie to provide the relevant info for decoding.

Reimplemented in DecoderALAC, and MultiDecoder.

◆ setCodecConfig() [2/2]

virtual bool setCodecConfig ( const uint8_t * data,
size_t len )
inlinevirtualinherited

Some decoders need e.g. a magic cookie to provide the relevant info for decoding.

Reimplemented in DecoderALAC, and MultiDecoder.

◆ setDecoder()

bool setDecoder ( MultiDecoder & decoder)
inline

Sets the decoder to use for audio frames.

Parameters
decoderReference to a MultiDecoder for PCM output.
Returns
true if set successfully, false otherwise.

◆ setNotifyActive() [1/2]

void setNotifyActive ( bool flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active).

◆ setNotifyActive() [2/2]

void setNotifyActive ( bool flag)
inlineinherited

Deactivate/Reactivate automatic AudioInfo updates: (default is active).

◆ setOutput() [1/3]

virtual void setOutput ( AudioOutput & out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

◆ setOutput() [2/3]

virtual void setOutput ( AudioStream & out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

◆ setOutput() [3/3]

void setOutput ( Print & out_stream)
inlineoverridevirtual

Set the output stream for decoded or raw audio.

Parameters
out_streamOutput AudioStream.

Reimplemented from AudioDecoder.

◆ setSampleSizesBuffer()

virtual void setSampleSizesBuffer ( BaseBuffer< stsz_sample_size_t > & buffer)
inlinevirtual

Sets the buffer to use for sample sizes. You can use this to provide a custom buffer that does not rely on RAM (e.g a file based buffer or one using Redis).

Parameters
bufferReference to the buffer to use.

◆ write()

size_t write ( const uint8_t * data,
size_t len )
inlineoverridevirtual

Feed data to the demuxer for parsing.

Parameters
dataPointer to input data.
lenLength of input data.
Returns
Number of bytes processed (always len).

Implements AudioWriter.

◆ writeBlocking() [1/2]

void writeBlocking ( Print * out,
uint8_t * data,
size_t len )
inlineprotectedinherited

◆ writeBlocking() [2/2]

void writeBlocking ( Print * out,
uint8_t * data,
size_t len )
inlineprotectedinherited

Member Data Documentation

◆ demux

M4AAudioDemuxer demux
protected

Internal demuxer instance.

◆ id

int id
inherited

custom id to be used by application

◆ info

AudioInfo info
protectedinherited

◆ is_active

bool is_active = false
protected

True if demuxer is active.

◆ is_magic_cookie_processed

bool is_magic_cookie_processed
protected
Initial value:
=
false

True if ALAC magic cookie has been processed.

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ p_decoder

MultiDecoder* p_decoder = nullptr
protected

Pointer to the MultiDecoder.

◆ p_print

Print * p_print = nullptr
protectedinherited

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