arduino-audio-tools
Loading...
Searching...
No Matches

AVI Container Decoder which can be fed with small chunks of data. The minimum length must be bigger then the header size! The file structure is documented at https://learn.microsoft.com/en-us/windows/win32/directshow/avi-riff-file-reference. More...

#include <ContainerAVI.h>

Inheritance diagram for DemuxerAVI:
Demuxer ContainerDecoder MimeSource VideoInfoSource AudioDecoder AudioDecoder AudioInfoSource AudioWriter AudioInfoSource AudioWriter AudioInfoSource AudioWriter AudioInfoSource AudioWriter

Public Member Functions

 DemuxerAVI (int bufferSize=1024)
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 ()
WAVFormatX aviAudioInfo ()
 Provides the audio information.
AVIMainHeader aviMainHeader ()
 Provides the information from the main header chunk.
AVIStreamHeader aviStreamHeader (int idx)
 Provides the information from the stream header chunks.
const char * aviVideoFormat ()
BitmapInfoHeader aviVideoInfo ()
 Provides the video information.
virtual bool begin (AudioInfo info) override
bool begin () override
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
void end () override
AudioInfoFormat getAudioInfo () override
Print * getOutput ()
Print * getOutput ()
VideoInfo getVideoInfo () override
bool isMetadataReady ()
 Returns true if all metadata has been parsed and is available.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isValid (const uint8_t *data, size_t len) override
const char * mime () override
 provides the audio mime
const char * mimeVideo ()
 Provides the video mime.
 operator bool () override
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 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.
void setMute (bool mute)
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.
virtual void setOutput (Print &out_stream) override
void setOutputAudio (Print &out_stream) override
void setOutputVideo (Print &out_stream) override
void setOutputVideo (VideoOutput &out_stream) override
void setSendWavHeader (bool flag) override
void setValidationCallback (bool(*cb)(DemuxerAVI &avi))
VideoInfo videoInfo () override
int videoSeconds ()
 Provide the length of the video in seconds.
virtual size_t write (const uint8_t *data, size_t len) override

Public Attributes

int id
 custom id to be used by application

Protected Member Functions

void cleanupStack ()
void consume (int len)
 We remove the processed bytes from the beginning of the buffer.
uint32_t getInt (int offset)
 Provides the int32 at the indicated byte offset.
StrView & getStr (int offset, int len)
 Provides the string at the indicated byte offset with the indicated length.
bool isCurrentStreamAudio ()
bool isCurrentStreamVideo ()
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
bool parse ()
ParseObject parseAVIStreamData ()
ParseObject parseChunk (const char *id)
 We load the indicated chunk from the current data.
bool parseHeader ()
ParseObject parseList (const char *id)
 We load the indicated list from the current data.
void processStack (ParseObject &result)
void sendWavHeader ()
void setupAudioInfo ()
void setupVideoInfo ()
ParseObject tryParseChunk ()
ParseObject tryParseChunk (const char *id)
ParseObject tryParseList ()
 We try to parse the actual state for any list.
ParseObject tryParseList (const char *id)
void writeBlocking (Print *out, uint8_t *data, size_t len)
void writeBlocking (Print *out, uint8_t *data, size_t len)
void writeData ()

Static Protected Member Functions

static VideoFormat toVideoFormat (uint32_t biCompression, uint16_t biBitCount)

Protected Attributes

WAVFormatX audio_info
Vector< StreamContentType > content_types
long current_pos = 0
ParseObject current_stream_data
bool header_is_avi = false
AudioInfo info
bool is_metadata_ready = false
bool is_mute = false
bool is_notify_active = true
bool is_parsing_active = true
bool is_wav_header_sent = false
AVIMainHeader main_header
long movi_end_pos = 0
Vector< AudioInfoSupport * > notify_vector
Stack< ParseObject > object_stack
long open_subchunk_len = 0
Print * p_output_audio = nullptr
Print * p_output_video = nullptr
VideoOutput * p_output_video_video = nullptr
Print * p_print = nullptr
ParseBuffer parse_buffer
ParseState parse_state = ParseHeader
uint32_t riff_file_size = 0
bool send_wav_header = false
bool send_wav_header_explicit = false
Str spaces
Str str
Vector< AVIStreamHeader > stream_header
int stream_header_idx = -1
bool(* validation_cb )(DemuxerAVI &avi) = nullptr
Vector< uint8_t > video_accumulator
char video_format [5] = {0}
BitmapInfoHeader video_info
int video_seconds = 0

Detailed Description

AVI Container Decoder which can be fed with small chunks of data. The minimum length must be bigger then the header size! The file structure is documented at https://learn.microsoft.com/en-us/windows/win32/directshow/avi-riff-file-reference.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ DemuxerAVI()

DemuxerAVI ( int bufferSize = 1024)
inline
Parameters
bufferSizeinternal parse buffer size.

This class only demuxes - it does not decode audio itself. Point setOutputAudio() at an EncodedAudioStream (wrapping whatever AudioDecoder matches the AVI's audio format) if you need the audio track decoded; the raw payload is written through as-is otherwise. Point setOutputVideo() at a Print (e.g. a VideoOutput) to receive the demuxed video track; leave unset to ignore video.

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]

◆ aviAudioInfo()

WAVFormatX aviAudioInfo ( )
inline

Provides the audio information.

◆ aviMainHeader()

AVIMainHeader aviMainHeader ( )
inline

Provides the information from the main header chunk.

◆ aviStreamHeader()

AVIStreamHeader aviStreamHeader ( int idx)
inline

Provides the information from the stream header chunks.

◆ aviVideoFormat()

const char * aviVideoFormat ( )
inline

◆ aviVideoInfo()

BitmapInfoHeader aviVideoInfo ( )
inline

Provides the video information.

◆ begin() [1/2]

virtual bool begin ( AudioInfo info)
inlineoverridevirtualinherited

Reimplemented from AudioWriter.

◆ begin() [2/2]

bool begin ( )
inlineoverridevirtual

Reimplemented from AudioDecoder.

◆ cleanupStack()

void cleanupStack ( )
inlineprotected

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ consume()

void consume ( int len)
inlineprotected

We remove the processed bytes from the beginning of the buffer.

◆ end()

void end ( )
inlineoverridevirtual

Reimplemented from AudioDecoder.

◆ getAudioInfo()

AudioInfoFormat getAudioInfo ( )
inlineoverridevirtual

Common audio info (sample_rate/channels/bits_per_sample), extended with the parsed 'strf' format tag - the same AudioInfoFormat type is also provided by DemuxerMP4. Named getAudioInfo() rather than audioInfo() because AudioDecoder already declares a virtual AudioInfo audioInfo() (returning the plain, unextended type by value) - by-value virtual returns can't be covariantly widened in C++, so reusing that name for a subclass-returning version isn't possible (it would be a hard "invalid covariant return type" error, not silent hiding).

Implements Demuxer.

◆ getInt()

uint32_t getInt ( int offset)
inlineprotected

Provides the int32 at the indicated byte offset.

◆ getOutput() [1/2]

Print * getOutput ( )
inlineinherited

◆ getOutput() [2/2]

Print * getOutput ( )
inlineinherited

◆ getStr()

StrView & getStr ( int offset,
int len )
inlineprotected

Provides the string at the indicated byte offset with the indicated length.

◆ getVideoInfo()

VideoInfo getVideoInfo ( )
inlineoverridevirtual

Common video info (width/height/format/frame_size/total_file_size), analogous to audioInfo() - the same VideoInfo type is also provided by DemuxerMP4. format is decoded from the 'strf' biCompression field (the authoritative codec id; more reliable than the 'strh' handler text for third-party files, available separately via videoFormat()); VideoFormat::UNKNOWN for any codec not covered by the enum.

Implements Demuxer.

◆ isCurrentStreamAudio()

bool isCurrentStreamAudio ( )
inlineprotected

◆ isCurrentStreamVideo()

bool isCurrentStreamVideo ( )
inlineprotected

◆ isMetadataReady()

bool isMetadataReady ( )
inline

Returns true if all metadata has been parsed and is available.

◆ 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.

◆ isValid()

bool isValid ( const uint8_t * data,
size_t len )
inlineoverridevirtual

True if data starts with a RIFF header declaring an AVI file ("RIFF" at offset 0, "AVI " at offset 8) - see Demuxer::isValid().

Reimplemented from Demuxer.

◆ mime()

const char * mime ( )
inlineoverridevirtual

provides the audio mime

Implements Demuxer.

◆ mimeVideo()

const char * mimeVideo ( )
inlinevirtual

Provides the video mime.

Implements Demuxer.

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Implements AudioWriter.

◆ parse()

bool parse ( )
inlineprotected

◆ parseAVIStreamData()

ParseObject parseAVIStreamData ( )
inlineprotected

◆ parseChunk()

ParseObject parseChunk ( const char * id)
inlineprotected

We load the indicated chunk from the current data.

◆ parseHeader()

bool parseHeader ( )
inlineprotected

◆ parseList()

ParseObject parseList ( const char * id)
inlineprotected

We load the indicated list from the current data.

◆ processStack()

void processStack ( ParseObject & result)
inlineprotected

◆ 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.

◆ sendWavHeader()

void sendWavHeader ( )
inlineprotected

Synthesizes a valid WAV header (via the shared WAVHeader writer - also correctly handles ADPCM's extra 'fmt ' extension + 'fact' chunk) from the parsed 'strf' audio_info and sends it to p_output_audio, once, before any real audio payload - so a WAVDecoder-based output can bootstrap itself from it. Length is written as streamed/unknown, since the AVI's audio track length is not known upfront while demuxing.

◆ 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.

◆ 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.

◆ setMute()

void setMute ( bool mute)
inline

◆ 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]

virtual void setOutput ( Print & out_stream)
inlineoverridevirtual

Satisfies the AudioWriter/AudioDecoder interface - needed so EncodedAudioOutput/EncodedAudioStream's polymorphic AudioDecoder* wiring (which calls setOutput() through that base class pointer) still reaches the audio output correctly; delegates to setOutputAudio().

Reimplemented from AudioDecoder.

◆ setOutputAudio()

void setOutputAudio ( Print & out_stream)
inlineoverridevirtual

Defines the audio output stream - e.g. an EncodedAudioStream wrapping an AudioDecoder that matches the AVI's audio format, or any other Print if you want the raw payload as-is.

Implements Demuxer.

◆ setOutputVideo() [1/2]

void setOutputVideo ( Print & out)
inlineoverridevirtual

Defines the video output - e.g. a VideoOutput implementation, or any other Print if you want the raw payload as-is.

Implements Demuxer.

◆ setOutputVideo() [2/2]

void setOutputVideo ( VideoOutput & out)
inlineoverridevirtual

Defines the video output - the VideoOutput-specific counterpart of setOutputVideo(Print&), for a target like PacedVideoOutput/ OutputTinyGPU/OutputOpenCV that implements VideoOutput but not Print (the two are unrelated types - see VideoFrameMeter's own comment). Part of the base interface (unlike other concrete-class-specific extras) so code holding only a Demuxer& (e.g. VideoPlayer) can wire it to an arbitrary VideoOutput& without knowing the concrete container format - every current demuxer already implemented this identically before it was pulled up into the interface.

Implements Demuxer.

◆ setSendWavHeader()

void setSendWavHeader ( bool flag)
inlineoverridevirtual

Overrides the automatic decision of whether a synthetic WAV header (matching the parsed 'strf' audio format) is sent to the audio output before any audio payload. By default this is decided automatically from the parsed format: on whenever isWavFormat() of the parsed 'strf' format is true (PCM/ADPCM, i.e. audio that needs to go through a WAVDecoder), off otherwise (e.g. compressed formats with their own decoder that don't expect a WAV header). Call this to force it either way instead.

Implements Demuxer.

◆ setupAudioInfo()

void setupAudioInfo ( )
inlineprotected

◆ setupVideoInfo()

void setupVideoInfo ( )
inlineprotected

◆ setValidationCallback()

void setValidationCallback ( bool(* cb )(DemuxerAVI &avi))
inline

Register a validation callback which is called after parsing just before playing the audio

◆ toVideoFormat()

VideoFormat toVideoFormat ( uint32_t biCompression,
uint16_t biBitCount )
inlinestaticprotected

Maps a 'strf' biCompression value (+ biBitCount, to disambiguate BI_BITFIELDS) to the corresponding VideoFormat. Covers what MuxerAVI writes plus a few common real-world FOURCC aliases seen in third-party AVI files.

◆ tryParseChunk() [1/2]

ParseObject tryParseChunk ( )
inlineprotected

We parse a chunk and provide the FOURCC id and size: No content data is stored

◆ tryParseChunk() [2/2]

ParseObject tryParseChunk ( const char * id)
inlineprotected

We try to parse the indicated chunk and determine the size: No content data is stored

◆ tryParseList() [1/2]

ParseObject tryParseList ( )
inlineprotected

We try to parse the actual state for any list.

◆ tryParseList() [2/2]

ParseObject tryParseList ( const char * id)
inlineprotected

◆ videoInfo()

VideoInfo videoInfo ( )
inlineoverridevirtualinherited

Fulfills VideoInfoSource::videoInfo(), so any Demuxer can be passed directly to e.g. OutputOpenCV::setVideoInfoSource() - note the reported 'format' is the container's codec (e.g. H264), not necessarily what ends up written to a raw-picture VideoOutput/Print (that depends on whatever decoder sits between the demuxer and the output); consumers that care about the decoded format should still set it explicitly and rely on this only for width/height.

Implements VideoInfoSource.

◆ videoSeconds()

int videoSeconds ( )
inline

Provide the length of the video in seconds.

◆ write()

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

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

◆ writeData()

void writeData ( )
inlineprotected

Member Data Documentation

◆ audio_info

WAVFormatX audio_info
protected

◆ content_types

Vector<StreamContentType> content_types
protected

◆ current_pos

long current_pos = 0
protected

◆ current_stream_data

ParseObject current_stream_data
protected

◆ header_is_avi

bool header_is_avi = false
protected

◆ id

int id
inherited

custom id to be used by application

◆ info

AudioInfo info
protectedinherited

◆ is_metadata_ready

bool is_metadata_ready = false
protected

◆ is_mute

bool is_mute = false
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ is_parsing_active

bool is_parsing_active = true
protected

◆ is_wav_header_sent

bool is_wav_header_sent = false
protected

◆ main_header

AVIMainHeader main_header
protected

◆ movi_end_pos

long movi_end_pos = 0
protected

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ object_stack

Stack<ParseObject> object_stack
protected

◆ open_subchunk_len

long open_subchunk_len = 0
protected

◆ p_output_audio

Print* p_output_audio = nullptr
protected

◆ p_output_video

Print* p_output_video = nullptr
protected

◆ p_output_video_video

VideoOutput* p_output_video_video = nullptr
protected

◆ p_print

Print * p_print = nullptr
protectedinherited

◆ parse_buffer

ParseBuffer parse_buffer
protected

◆ parse_state

ParseState parse_state = ParseHeader
protected

◆ riff_file_size

uint32_t riff_file_size = 0
protected

Total file size (bytes) declared by the RIFF header, normalized from its chunk_size (= file_size - 8) field; 0 if not yet parsed or the declared size looks like an unbounded/streamed placeholder.

◆ send_wav_header

bool send_wav_header = false
protected

◆ send_wav_header_explicit

bool send_wav_header_explicit = false
protected

◆ spaces

Str spaces
protected

◆ str

Str str
protected

◆ stream_header

Vector<AVIStreamHeader> stream_header
protected

◆ stream_header_idx

int stream_header_idx = -1
protected

◆ validation_cb

bool(* validation_cb) (DemuxerAVI &avi) = nullptr
protected

◆ video_accumulator

Vector<uint8_t> video_accumulator
protected

Accumulates one whole video chunk (one frame's worth of Annex-B NAL data) across however many writeData() calls it takes to stream the chunk in - see writeData()'s own comment for why: video decoders (e.g. H264Decoder/TinyH264) aren't guaranteed to handle a NAL unit arriving split across separate write() calls, so this only ever hands them one complete chunk per write() call, the same way DemuxerMP4 already does (it can, trivially, since MP4's sample table gives it each frame's exact size up front).

◆ video_format

char video_format[5] = {0}
protected

◆ video_info

BitmapInfoHeader video_info
protected

◆ video_seconds

int video_seconds = 0
protected

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