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

MPEG-1 System (Program) Stream Demuxer, as defined by ISO/IEC 11172-1: splits the pack_header/system_header/PES_packet framing apart and forwards the raw MPEG-1 video (ISO/IEC 11172-2) and MPEG-1 audio (ISO/IEC 11172-3, Layer I/II/III) elementary streams to setOutputVideo()/ setOutputAudio(). Both elementary streams are self-delimiting (the video ES has its own picture_start_code sequence, the audio ES its own frame sync word) so, like DemuxerAVI/DemuxerMP4, no separate decoding is done here - point the outputs at whatever decoder understands the codec (e.g. an MPEG1 video decoder, or an EncodedAudioStream wrapping an MP3/MP2 AudioDecoder). More...

#include <ContainerMPG.h>

Inheritance diagram for DemuxerMPG:
Demuxer ContainerDecoder AudioDecoder AudioWriter AudioInfoSource AudioInfoSupport

Public Member Functions

 DemuxerMPG (int bufferSize=1024)
 
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.
 
const char * mime () override
 The container's MIME type (e.g. "video/avi", "video/mp4").
 
 operator bool () override
 
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
 
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)
 
void setSendWavHeader (bool flag) 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

bool continuePayload ()
 
void deliver (size_t len)
 
void notifyAudioChange (AudioInfo info)
 
bool parse ()
 
bool parsePack ()
 
bool parsePes (uint8_t id, bool isVideo)
 
bool parseSkip ()
 
bool parseSystemHeader ()
 
void probeAudioHeader (const uint8_t *data, size_t len)
 
void probeVideoHeader (const uint8_t *data, size_t len)
 
void writeBlocking (Print *out, uint8_t *data, size_t len)
 

Static Protected Member Functions

static uint64_t readTimestamp (const uint8_t *p)
 

Protected Attributes

uint8_t audio_channels = 0
 
bool audio_header_parsed = false
 
Vector< uint8_t > audio_probe
 
uint32_t audio_sample_rate = 0
 
AudioInfo info
 
bool is_notify_active = true
 
bool is_parsing_active = true
 
bool is_skip_unit = false
 
bool is_video_unit = false
 
Vector< AudioInfoSupport * > notify_vector
 
Printp_output_audio = nullptr
 
Printp_output_video = nullptr
 
VideoOutputp_output_video_video = nullptr
 
Printp_print = nullptr
 
MPGParseBuffer parse_buffer
 
size_t remaining = 0
 
uint32_t total_bytes = 0
 
bool unbounded = false
 
bool unit_open = false
 
float video_fps = 0
 
bool video_frame_open = false
 
bool video_header_parsed = false
 
uint16_t video_height = 0
 
Vector< uint8_t > video_probe
 
uint16_t video_width = 0
 

Static Protected Attributes

static const size_t VIDEO_PROBE_MAX = 64
 

Detailed Description

MPEG-1 System (Program) Stream Demuxer, as defined by ISO/IEC 11172-1: splits the pack_header/system_header/PES_packet framing apart and forwards the raw MPEG-1 video (ISO/IEC 11172-2) and MPEG-1 audio (ISO/IEC 11172-3, Layer I/II/III) elementary streams to setOutputVideo()/ setOutputAudio(). Both elementary streams are self-delimiting (the video ES has its own picture_start_code sequence, the audio ES its own frame sync word) so, like DemuxerAVI/DemuxerMP4, no separate decoding is done here - point the outputs at whatever decoder understands the codec (e.g. an MPEG1 video decoder, or an EncodedAudioStream wrapping an MP3/MP2 AudioDecoder).

Scope (v1): a single MPEG-1 video track (stream_id 0xE0) and a single MPEG-1 audio track (stream_id 0xC0) - the common case for files produced by encoders targeting this container (see MuxerMPG). Only the plain ISO/IEC 11172-1 pack_header (fixed 12 bytes, no stuffing) and PES header (PTS/DTS-or-none, no stuffing bytes, no STD_buffer field) are recognized; MPEG-2-style Program Streams (marker pattern '01' at the start of the pack header) are not supported.

The audio track is forwarded as a plain, continuous elementary-stream byte stream (PES packet boundaries are not required to line up with MP3/ MP2 frame boundaries - the decoder resyncs on its own frame sync word), so setOutputAudio() can point straight at an EncodedAudioStream wrapping any MPEG audio AudioDecoder (e.g. MP3DecoderHelix):

DemuxerMPG demuxer;
EncodedAudioStream audioOut(&i2s, &mp3); // MP3 -> PCM -> i2s
demuxer.setOutputAudio(audioOut);
demuxer.setOutputVideo(videoSink);
demuxer.begin();
// feed raw .mpg bytes:
demuxer.write(mpgData, len);
MPEG-1 System (Program) Stream Demuxer, as defined by ISO/IEC 11172-1: splits the pack_header/system_...
Definition ContainerMPG.h:111
void setOutputAudio(Print &out) override
Definition ContainerMPG.h:153
size_t write(const uint8_t *data, size_t len) override
Definition ContainerMPG.h:196
bool begin() override
Definition ContainerMPG.h:119
void setOutputVideo(Print &out) override
Definition ContainerMPG.h:163
A more natural Stream class to process encoded data (aac, wav, mp3...) which also supports the decodi...
Definition AudioEncoded.h:282
MP3 Decoder using libhelix: https://github.com/pschatzmann/arduino-libhelix This is basically just a ...
Definition CodecMP3Helix.h:20
Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ DemuxerMPG()

DemuxerMPG ( int  bufferSize = 1024)
inline
Parameters
bufferSizeinternal parse buffer size - must be able to hold at least one full pack_header/system_header/PES header (a few dozen bytes)

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin() [1/2]

bool begin ( )
inlineoverridevirtual

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

◆ continuePayload()

bool continuePayload ( )
inlineprotected

◆ deliver()

void deliver ( size_t  len)
inlineprotected

◆ end()

void end ( )
inlineoverridevirtual

Reimplemented from AudioDecoder.

◆ getAudioInfo()

AudioInfoFormat getAudioInfo ( )
inlineoverridevirtual

Common audio info, parsed from the audio ES's own MPEG audio frame header once seen - falls back to 44100/stereo if not yet available.

Implements Demuxer.

◆ getOutput()

Print * getOutput ( )
inlineinherited

◆ getVideoInfo()

VideoInfo getVideoInfo ( )
inlineoverridevirtual

Common video info (width/height/fps/format), parsed from the video ES's own sequence_header (ISO/IEC 11172-2) once seen - all zero/ VideoFormat::MPEG1 until then.

Implements Demuxer.

◆ isNotifyActive()

bool isNotifyActive ( )
inlineinherited

Checks if the automatic AudioInfo update is active.

◆ mime()

const char * mime ( )
inlineoverridevirtual

The container's MIME type (e.g. "video/avi", "video/mp4").

Implements Demuxer.

◆ notifyAudioChange()

void notifyAudioChange ( AudioInfo  info)
inlineprotectedinherited

◆ operator bool()

operator bool ( )
inlineoverridevirtual

Implements AudioWriter.

◆ parse()

bool parse ( )
inlineprotected

Parses/consumes as much as is currently buffered; returns true if progress was made (call again - more units may already be buffered), false if it needs more data (wait for the next write()).

◆ parsePack()

bool parsePack ( )
inlineprotected

◆ parsePes()

bool parsePes ( uint8_t  id,
bool  isVideo 
)
inlineprotected

◆ parseSkip()

bool parseSkip ( )
inlineprotected

program_stream_map / private_stream_1 / padding_stream / private_stream_2: same PES_packet_length-prefixed framing, payload discarded.

◆ parseSystemHeader()

bool parseSystemHeader ( )
inlineprotected

◆ probeAudioHeader()

void probeAudioHeader ( const uint8_t *  data,
size_t  len 
)
inlineprotected

Inspects the first 4 bytes of the audio ES for an MPEG audio frame header (ISO/IEC 11172-3) to determine sample_rate/channels.

◆ probeVideoHeader()

void probeVideoHeader ( const uint8_t *  data,
size_t  len 
)
inlineprotected

Accumulates the first bytes of the video ES looking for its sequence_header (00 00 01 B3) to determine width/height/fps - harmless to keep calling once found, since video_header_parsed then short-circuits it.

◆ readTimestamp()

static uint64_t readTimestamp ( const uint8_t *  p)
inlinestaticprotected

Reads a single 5-byte MPEG-1 timestamp field (PTS or DTS - both use the same bit layout, only the leading 4-bit id nibble differs, which is not part of this 5-byte window) at 'p'.

◆ removeNotifyAudioChange()

virtual bool removeNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

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

Reimplemented in RTSPClient< TcpClient, UdpSocket >.

◆ 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 - needed so EncodedAudioOutput/EncodedAudioStream's polymorphic AudioDecoder* wiring reaches the audio output correctly; delegates to setOutputAudio().

Reimplemented from AudioDecoder.

◆ setOutputAudio()

void setOutputAudio ( Print out)
inlineoverridevirtual

Defines the audio output stream - e.g. an EncodedAudioStream wrapping an MP3/MP2 AudioDecoder, 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 MPEG-1 video ES as-is.

Implements Demuxer.

◆ setOutputVideo() [2/2]

void setOutputVideo ( VideoOutput out)
inline

◆ setSendWavHeader()

void setSendWavHeader ( bool  flag)
inlineoverridevirtual

Not applicable: MPEG-1 audio (Layer I/II/III) is compressed and self-framed (its own sync word), unlike PCM - it never needs a synthetic WAV header. Provided only to satisfy the Demuxer interface.

Implements Demuxer.

◆ 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

◆ audio_channels

uint8_t audio_channels = 0
protected

◆ audio_header_parsed

bool audio_header_parsed = false
protected

◆ audio_probe

Vector<uint8_t> audio_probe
protected

◆ audio_sample_rate

uint32_t audio_sample_rate = 0
protected

◆ id

int id
inherited

custom id to be used by application

◆ info

AudioInfo info
protectedinherited

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ is_parsing_active

bool is_parsing_active = true
protected

◆ is_skip_unit

bool is_skip_unit = false
protected

◆ is_video_unit

bool is_video_unit = false
protected

◆ notify_vector

Vector<AudioInfoSupport*> notify_vector
protectedinherited

◆ 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

MPGParseBuffer parse_buffer
protected

◆ remaining

size_t remaining = 0
protected

◆ total_bytes

uint32_t total_bytes = 0
protected

◆ unbounded

bool unbounded = false
protected

◆ unit_open

bool unit_open = false
protected

◆ video_fps

float video_fps = 0
protected

◆ video_frame_open

bool video_frame_open = false
protected

◆ video_header_parsed

bool video_header_parsed = false
protected

◆ video_height

uint16_t video_height = 0
protected

◆ video_probe

Vector<uint8_t> video_probe
protected

◆ VIDEO_PROBE_MAX

const size_t VIDEO_PROBE_MAX = 64
staticprotected

◆ video_width

uint16_t video_width = 0
protected

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