Demuxer for M4A/MP4 files to extract audio data using an Arduino File. This class locates the mdat and stsz boxes using MP4Parser.
More...
|
| M4AAudioFileDemuxer () |
| Default constructor. Sets up parser callbacks.
|
|
| M4AAudioFileDemuxer (MultiDecoder &decoder) |
| Constructor with decoder.
|
|
void | begin () |
|
bool | begin (File &file) |
| Open and parse the given file.
|
|
void | beginSampleSizeAccess (File *filePtr, uint32_t sampleCount, uint32_t stszOffset) |
| Initializes the demuxer for reading sample sizes from the stsz box.
|
|
bool | copy () |
| Copies the next audio frame from the file using the sample size table and mdat offset. Calls the frame callback if set.
|
|
void | end () |
| End demuxing and reset state.
|
|
M4AAudioConfig | getM4AAudioConfig () |
|
uint32_t | getMdatOffset () const |
|
uint32_t | getNextSampleSize () |
| Provides the next sample size (= frame size) from the stsz box queue.
|
|
uint32_t | getSampleCount () const |
| samples in stsz
|
|
uint32_t | getStszFileOffset () const |
| File offset of stsz box.
|
|
| operator bool () |
| Returns true as long as there are samples to process.
|
|
bool | parseFile () |
| Parses the file and feeds data to the parser until we have all the necessary data: 1) stsd box processed, 2) mdat offset found, 3) stsz offset found. Usually this method is not needed, but it comes in handy if you need to process a file which is not in streaming format!
|
|
void | resize (int size) |
|
uint32_t | sampleIndex () const |
|
void | setAACConfig (int profile, int srIdx, int chCfg) |
| Sets the AAC configuration for ADTS header generation.
|
|
void | setCallback (FrameCallback cb) override |
| Sets the callback for extracted audio frames.
|
|
void | setChunkOffsetsBuffer (BaseBuffer< uint32_t > &buffer) |
| Sets the buffer to use for sample sizes.
|
|
bool | setDecoder (MultiDecoder &decoder) |
| Sets the decoder to use for audio frames. Please note that calls setCallback() to register the decoder callback.
|
|
void | setM4AAudioConfig (M4AAudioConfig cfg) |
|
void | setSamplesBufferSize (int size) |
| Sets the size of the samples buffer (in bytes).
|
|
void | setSampleSizesBuffer (BaseBuffer< stsz_sample_size_t > &buffer) |
| Sets the buffer to use for sample sizes.
|
|
uint32_t | size () const |
|
|
M4AAudioConfig | audio_config |
|
SingleBuffer< uint8_t > | buffer |
| Buffer for sample data.
|
|
uint32_t | chunk_offsets_count = 0 |
|
size_t | default_size = 2 * 1024 |
| Default buffer size.
|
|
uint32_t | fixed_sample_size = 0 |
| Fixed sample size (if nonzero)
|
|
FrameCallback | frame_callback = nullptr |
|
uint64_t | mdat_offset = 0 |
| Offset of mdat box payload.
|
|
uint64_t | mdat_pos = 0 |
| Current position in mdat box.
|
|
uint64_t | mdat_sample_pos = 0 |
|
uint64_t | mdat_size = 0 |
| Size of mdat box payload.
|
|
MultiDecoder * | p_decoder = nullptr |
| Pointer to decoder.
|
|
File * | p_file = nullptr |
| Pointer to the open file.
|
|
MP4Parser | parser |
| Underlying MP4 parser.
|
|
uint32_t | sample_count = 0 |
| Number of samples in stsz.
|
|
uint32_t | sample_index = 0 |
| Current sample index.
|
|
SampleExtractor | sampleExtractor |
| Extractor for audio samples.
|
|
bool | stco_processed = false |
| Marks the stco table as processed.
|
|
bool | stsd_processed = false |
|
SingleBuffer< uint32_t > | stsz_buf |
| Buffer for stsz sample sizes.
|
|
int | stsz_bufsize = 256 |
| Number of sample sizes to buffer.
|
|
uint64_t | stsz_offset = 0 |
| Offset of stsz box.
|
|
bool | stsz_processed = false |
| Marks the stsz table as processed.
|
|
uint64_t | stsz_size = 0 |
| Size of stsz box.
|
|
Demuxer for M4A/MP4 files to extract audio data using an Arduino File. This class locates the mdat and stsz boxes using MP4Parser.
It provides a copy() method to extract frames from the file by reading sample sizes directly from the stsz box in the file. This class is quite memory efficient because no table of sample sizes are kept in memory. It just reads the sample sizes from the stsz box and uses the mdat offset to read the sample data directly from the file.
The result is written to the provided decoder or alternatively will be provided via the frame_callback.
- Author
- Phil Schatzmann
void beginSampleSizeAccess |
( |
File * |
filePtr, |
|
|
uint32_t |
sampleCount, |
|
|
uint32_t |
stszOffset |
|
) |
| |
|
inline |
Initializes the demuxer for reading sample sizes from the stsz box.
This method sets the file pointer, resets the sample index, sets the total sample count, and records the offset of the stsz box in the file. It is typically called before reading sample sizes directly from the file, ensuring the demuxer is properly positioned.
- Parameters
-
filePtr | Pointer to the open file. |
sampleCount | Total number of samples in the file. |
stszOffset | Offset of the stsz box in the file. |