|
arduino-audio-tools
|
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...
#include <M4ACommonDemuxer.h>
Public Types | |
| using | Codec = M4ACommonDemuxer::Codec |
| using | Frame = M4ACommonDemuxer::Frame |
| using | FrameCallback = std::function< void(const Frame &, void *)> |
| using | M4AAudioConfig = M4ACommonDemuxer::M4AAudioConfig |
Public Member Functions | |
| SampleExtractor (M4AAudioConfig &cfg) | |
| Constructor. Initializes the extractor. | |
| void | begin () |
| Resets the extractor state. | |
| BaseBuffer< uint32_t > & | getChunkOffsetsBuffer () |
| Returns the buffer of chunk offsets. | |
| Frame | getFrame (size_t size, SingleBuffer< uint8_t > &buffer) |
| Constructs a Frame object for the current codec. | |
| BaseBuffer< stsz_sample_size_t > & | getSampleSizesBuffer () |
| Returns the buffer of sample sizes. | |
| void | setCallback (FrameCallback cb) |
| Sets the callback to be called for each extracted frame. | |
| void | setChunkOffsetsBuffer (BaseBuffer< uint32_t > &buffer) |
| Sets the buffer to use for chunk offsets. | |
| void | setFixedSampleCount (uint32_t sampleSize, uint32_t sampleCount) |
| Sets a fixed sample size/count instead of using the sampleSizes table. | |
| void | setMaxSize (size_t size) |
| Sets the maximum box size (e.g., for mdat). This is called before the mdat data is posted. In order to be able to play a file multiple times we just reset the sampleIndex! | |
| void | setReference (void *r) |
| Sets a reference pointer passed to the callback. | |
| void | setSampleSizesBuffer (BaseBuffer< stsz_sample_size_t > &buffer) |
| Sets the buffer to use for sample sizes. | |
| size_t | write (const uint8_t *data, size_t len, bool is_final) |
| Writes data to the extractor, extracting frames as sample sizes are met. Provides the data via the callback. | |
Protected Member Functions | |
| size_t | currentSampleSize () |
| Returns the current sample size. | |
| void | executeCallback (size_t size) |
| Executes the callback for a completed frame. | |
| void | resize (size_t newSize) |
| Resizes the internal buffer if needed. | |
Static Protected Member Functions | |
| static void | writeAdtsHeader (uint8_t *adts, int aacProfile, int sampleRateIdx, int channelCfg, int frameLen) |
| Writes an ADTS header for an AAC frame. | |
Protected Attributes | |
| M4AAudioConfig & | audio_config |
| size_t | box_pos = 0 |
| Current position in the box. | |
| size_t | box_size = 0 |
| Maximum size of the current sample. | |
| SingleBuffer< uint8_t > | buffer |
| Buffer for accumulating sample data. | |
| FrameCallback | callback = nullptr |
| Frame callback. | |
| size_t | current_size = 0 |
| Current sample size. | |
| SingleBuffer< uint32_t > | defaultChunkOffsets |
| Table of chunk offsets. | |
| SingleBuffer< stsz_sample_size_t > | defaultSampleSizes |
| Table of sample sizes. | |
| uint32_t | fixed_sample_count = 0 |
| Fixed sample count (if used). | |
| uint32_t | fixed_sample_size = 0 |
| Fixed sample size (if used). | |
| BaseBuffer< uint32_t > * | p_chunk_offsets = &defaultChunkOffsets |
| BaseBuffer< stsz_sample_size_t > * | p_sample_sizes = &defaultSampleSizes |
| void * | ref = nullptr |
| Reference pointer for callback. | |
| size_t | sampleIndex = 0 |
| Current sample index. | |
| Vector< uint8_t > | tmp |
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.
|
inline |
Constructor. Initializes the extractor.
|
inline |
Resets the extractor state.
|
inlineprotected |
Returns the current sample size.
Executes the callback for a completed frame.
| size | Size of the frame. |
|
inline |
Returns the buffer of chunk offsets.
|
inline |
Constructs a Frame object for the current codec.
| size | Size of the frame. |
| buffer | SingleBuffer with data. |
|
inline |
Returns the buffer of sample sizes.
Resizes the internal buffer if needed.
| newSize | New buffer size. |
|
inline |
Sets the callback to be called for each extracted frame.
| cb | Callback function. |
|
inline |
Sets the buffer to use for chunk offsets.
| buffer | Reference to the buffer to use. |
Sets a fixed sample size/count instead of using the sampleSizes table.
| sampleSize | Size of each sample. |
| sampleCount | Number of samples. |
Sets the maximum box size (e.g., for mdat). This is called before the mdat data is posted. In order to be able to play a file multiple times we just reset the sampleIndex!
| size | Maximum size in bytes. |
Sets a reference pointer passed to the callback.
| r | Reference pointer. |
|
inline |
Sets the buffer to use for sample sizes.
| buffer | Reference to the buffer to use. |
Writes data to the extractor, extracting frames as sample sizes are met. Provides the data via the callback.
| data | Pointer to input data. |
| len | Length of input data. |
| is_final | True if this is the last chunk of the box. |
fill buffer up to the current sample size
|
inlinestaticprotected |
Writes an ADTS header for an AAC frame.
| adts | Output buffer for the header. |
| aacProfile | AAC profile. |
| sampleRateIdx | Sample rate index. |
| channelCfg | Channel configuration. |
| frameLen | Frame length. |
|
protected |
|
protected |
Current position in the box.
|
protected |
Maximum size of the current sample.
|
protected |
Buffer for accumulating sample data.
|
protected |
Frame callback.
|
protected |
Current sample size.
|
protected |
Table of chunk offsets.
|
protected |
Table of sample sizes.
|
protected |
Fixed sample count (if used).
|
protected |
Fixed sample size (if used).
|
protected |
|
protected |
|
protected |
Current sample index.