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

Manages multiple Demuxers with automatic container-format detection - the container-side counterpart of MultiVideoDecoder (Video/MultiVideoDecoder.h), which does the same job one layer down for the video elementary stream's own codec. No demuxers are registered by default and this header has no container-parser dependency of its own (it only needs the Demuxer interface, ContainerCommon.h) - register whichever concrete demuxers (DemuxerAVI/DemuxerMP4/DemuxerMPG) your content actually needs via addDemuxer(). More...

#include <MultiVideoDemuxer.h>

Inheritance diagram for MultiVideoDemuxer:
Demuxer ContainerDecoder MimeSource VideoInfoSource AudioDecoder AudioWriter AudioInfoSource AudioInfoSupport MultiVideoDemuxerFull

Public Member Functions

void addDemuxer (Demuxer &demuxer)
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
bool begin () override
 
virtual bool begin (AudioInfo info) override
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
void end () override
 
AudioInfoFormat getAudioInfo () override
 
PrintgetOutput ()
 
VideoInfo getVideoInfo () override
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual bool isValid (const uint8_t *data, size_t len)
 
const char * mime () override
 
const char * mimeVideo () override
 
 operator bool () override
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
DemuxerselectedDemuxer () const
 
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.
 
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) override
 
void setOutputAudio (Print &out) override
 
void setOutputVideo (Print &out) override
 
void setOutputVideo (VideoOutput &out) override
 
void setSendWavHeader (bool flag) override
 Forwarded to every registered demuxer eagerly (see class comment).
 
VideoInfo videoInfo () override
 
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 notifyAudioChange (AudioInfo info)
 
void select (Demuxer *demuxer)
 
void writeBlocking (Print *out, uint8_t *data, size_t len)
 

Protected Attributes

Vector< Demuxer * > demuxers {0}
 
AudioInfo info
 
bool is_first = true
 
bool is_notify_active = true
 
Vector< AudioInfoSupport * > notify_vector
 
Printp_print = nullptr
 
Demuxerp_selected = nullptr
 

Detailed Description

Manages multiple Demuxers with automatic container-format detection - the container-side counterpart of MultiVideoDecoder (Video/MultiVideoDecoder.h), which does the same job one layer down for the video elementary stream's own codec. No demuxers are registered by default and this header has no container-parser dependency of its own (it only needs the Demuxer interface, ContainerCommon.h) - register whichever concrete demuxers (DemuxerAVI/DemuxerMP4/DemuxerMPG) your content actually needs via addDemuxer().

Drop it in wherever a plain Demuxer& is expected - VideoPlayer in fact uses one internally as its own built-in demuxer, with addDemuxer() registering against it - or feed it via write() directly, and it self-selects the right registered demuxer from the stream's own container signature instead of the caller having to know the file format up front.

Detection runs once, on the very first write() call: each registered demuxer's own Demuxer::isValid() (content-sniffing - a virtual method with a default-false implementation, so a demuxer only takes part if it actually overrides it; DemuxerAVI/DemuxerMP4/DemuxerMPG all do - see their own class comments) is tried, in registration order, against that first call's bytes. Reliable in practice since every real container signature (AVI's "RIFF"/"AVI ", MP4's "ftyp" box, MPG's pack start_code) falls within the first dozen bytes of the file, comfortably inside any realistic first read/write() chunk. Every subsequent write() call, plus every other Demuxer method, is forwarded to that same demuxer for the rest of the stream - never re-detected.

setOutputAudio()/setOutputVideo()/setSendWavHeader() are applied to every registered demuxer eagerly (cheap - just stores pointers/a flag, no allocation) - call addDemuxer() for all of them before these, so whichever one gets selected on the first write() is already wired. Only the actually-selected demuxer's begin() is called (on selection, from inside write()) - matching MultiVideoDecoder's own memory-efficient lazy-init rationale.

Author
Phil Schatzmann

Member Function Documentation

◆ addDemuxer()

void addDemuxer ( Demuxer demuxer)
inline

Registers a demuxer under its own Demuxer::mimeVideo() - see the class comment for when/how it's later selected (content-sniffing via its own Demuxer::isValid()). Call before the first write() reaches this object.

Replaces, rather than adds to, any demuxer already registered under the same mimeVideo() - at most one entry per container format, for the same reason MultiVideoDecoder::addDecoder() does: a stale second entry for the same format would otherwise be permanently unreachable dead weight, never actually selected.

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

Defers actual demuxer init to the first write() (see class comment)

  • always succeeds itself.

Reimplemented from AudioDecoder.

◆ begin() [2/2]

virtual bool begin ( AudioInfo  info)
inlineoverridevirtualinherited

Reimplemented from AudioWriter.

Reimplemented in DecoderBasic, and OggContainerDecoder.

◆ clearNotifyAudioChange()

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

Deletes all change notify subscriptions.

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ end()

void end ( )
inlineoverridevirtual

Reimplemented from AudioDecoder.

◆ getAudioInfo()

AudioInfoFormat getAudioInfo ( )
inlineoverridevirtual

Common audio info of the currently selected demuxer - an empty AudioInfoFormat before the first write()/if none matched.

Implements Demuxer.

◆ getOutput()

Print * getOutput ( )
inlineinherited

◆ getVideoInfo()

VideoInfo getVideoInfo ( )
inlineoverridevirtual

Common video info of the currently selected demuxer - an empty VideoInfo before the first write()/if none matched.

Implements Demuxer.

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ isValid()

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

True if data (the start of the stream, as handed to the first write()) looks like this demuxer's own container format - content-sniffing, not a guarantee (see the concrete class for exactly what's checked). Used by MultiVideoDemuxer to auto-select a registered demuxer (MultiVideoDemuxer.h); not otherwise part of the write()/parse path. Default false, matching VideoDecoder::isValid()'s own default - a demuxer not meant to be auto-detected this way simply never overrides it.

Reimplemented in DemuxerAVI, DemuxerMP4, and DemuxerMPG.

◆ mime()

const char * mime ( )
inlineoverridevirtual

The audio MIME type of the currently selected demuxer's audio track

  • see Demuxer::mime(). nullptr before the first write()/if none matched, or (depending on the concrete demuxer) until enough of the audio track's own metadata has been parsed.

Implements Demuxer.

◆ mimeVideo()

const char * mimeVideo ( )
inlineoverridevirtual

The container MIME type of the currently selected demuxer (e.g. "video/avi") - nullptr before the first write()/if none matched.

Implements Demuxer.

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Implements AudioWriter.

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

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

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ select()

void select ( Demuxer demuxer)
inlineprotected

◆ selectedDemuxer()

Demuxer * selectedDemuxer ( ) const
inline

The demuxer detection picked for the current stream - nullptr before the first write(), or if none matched.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  from)
inlineoverridevirtualinherited

for most decoders this is not needed

Implements AudioWriter.

Reimplemented in DecoderALAC, CodecChain, DSFDecoder, DecoderL8, OpusAudioDecoder, OpusMultiStreamAudioDecoder, CodecNOP, G729Decoder, and G7xxDecoder.

◆ setCodecConfig()

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.

◆ setNotifyActive()

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.

Reimplemented in ADTSDecoder, CodecChain, MTSDecoder, MTSDecoderTSDemux, and MetaDataFilterDecoder.

◆ setOutput() [2/3]

virtual void setOutput ( AudioStream out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

Reimplemented in ADTSDecoder, CodecChain, MTSDecoder, MTSDecoderTSDemux, and MetaDataFilterDecoder.

◆ setOutput() [3/3]

void setOutput ( Print out)
inlineoverridevirtual

Satisfies the AudioWriter/AudioDecoder interface - delegates to setOutputAudio(), matching every concrete Demuxer's own convention.

Reimplemented from AudioDecoder.

◆ setOutputAudio()

void setOutputAudio ( Print out)
inlineoverridevirtual

Defines the audio output stream - forwarded to every registered demuxer eagerly (see class comment).

Implements Demuxer.

◆ setOutputVideo() [1/2]

void setOutputVideo ( Print out)
inlineoverridevirtual

Defines the video output - forwarded to every registered demuxer eagerly (see class comment).

Implements Demuxer.

◆ setOutputVideo() [2/2]

void setOutputVideo ( VideoOutput out)
inlineoverridevirtual

See Demuxer::setOutputVideo(VideoOutput&) - forwarded to every registered demuxer eagerly (same rationale as the Print& overload above).

Implements Demuxer.

◆ setSendWavHeader()

void setSendWavHeader ( bool  flag)
inlineoverridevirtual

Forwarded to every registered demuxer eagerly (see class comment).

Implements Demuxer.

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

◆ write()

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

Implements AudioWriter.

◆ writeBlocking()

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

Member Data Documentation

◆ demuxers

Vector<Demuxer *> demuxers {0}
protected

◆ id

int id
inherited

custom id to be used by application

◆ info

AudioInfo info
protectedinherited

◆ is_first

bool is_first = true
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ p_print

Print* p_print = nullptr
protectedinherited

◆ p_selected

Demuxer* p_selected = nullptr
protected

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