arduino-audio-tools
Loading...
Searching...
No Matches
MTSDecoder Class Reference

MPEG-TS (MTS) decoder. Extracts (demuxes) the indicated audio/video data from a MPEG-TS (MTS) data stream. You can define the relevant stream types via the API: addStreamType(MTSStreamType). By default, the decoder selects the AUDIO_AAC, AUDIO_AAC_LATM stream types. More...

#include <CodecMTS.h>

Inheritance diagram for MTSDecoder:
AudioDecoder AudioWriter AudioInfoSource AudioWriter AudioInfoSource AudioInfoSupport AudioInfoSupport AudioInfoSupport AudioInfoSupport

Public Member Functions

 MTSDecoder ()=default
 Default constructor.
 MTSDecoder (AudioDecoder &dec)
 Provide the AAC decoder (or MP3 Decoder) to receive the extracted content.
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.
void addStreamType (MTSStreamType type)
 Defines the stream type that should be extracted.
AudioInfo audioInfo () override
 provides the actual input AudioInfo
AudioInfo audioInfo () override
 provides the actual input AudioInfo
virtual AudioInfo audioInfoOut ()
virtual AudioInfo audioInfoOut ()
virtual bool begin (AudioInfo info) override
bool begin () override
 Start the prcessor.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
void clearStreamTypes ()
 Clears the stream type filter.
void end () override
 Stops the processing.
Print * getOutput ()
Print * getOutput ()
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
virtual bool isResultPCM ()
 Returns true to indicate that the decoding result is PCM data.
virtual bool isResultPCM ()
 Returns true to indicate that the decoding result is PCM data.
bool isStreamTypeActive (MTSStreamType type)
 Checks if the stream type is active.
const char * mime ()
 Provides the mime type: "video/MP2T";.
virtual 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 resizeBuffer (int size)
 Set a new write buffer size (default is 2000).
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 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.
void setOutput (AudioOutput &out_stream) override
 Defines where the decoded result is written to.
void setOutput (AudioStream &out_stream) override
 Defines where the decoded result is written to.
void setOutput (Print &out_stream) override
 Defines where the decoded result is written to.
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 addPID (uint16_t pid)
void demux ()
 demux the available data
int findSyncWord (const uint8_t *buf, size_t nBytes, uint8_t synch=0xFF, uint8_t syncl=0xF0)
 Finds the mp3/aac sync word.
int getPayloadStart (uint8_t *packet, bool isPES, bool &payloadUnitStartIndicator)
bool isPESStartCodeValid (uint8_t *pes)
 check for PES packet start code prefix
void notifyAudioChange (AudioInfo info)
void notifyAudioChange (AudioInfo info)
bool parse ()
 Parse a single packet and remove the processed data.
void parsePacket (uint8_t *packet, int pid)
 Detailed processing for parsing a single packet.
void parsePAT (uint8_t *pat, int len)
void parsePES (uint8_t *packet, int pid)
void parsePMT (uint8_t *pmt, int len)
int syncPos ()
 Find the position of the next sync byte: Usually on position 0.
const char * toStr (MTSStreamType type)
 Convert the relevant MTSStreamType to a string.
void writeBlocking (Print *out, uint8_t *data, size_t len)
void writeBlocking (Print *out, uint8_t *data, size_t len)

Protected Attributes

SingleBuffer< uint8_t > buffer { 2000 }
int frame_length = 0
AudioInfo info
bool is_active = false
bool is_adts_missing = false
bool is_notify_active = true
Vector< AudioInfoSupport * > notify_vector
int open_pes_data_size = 0
AudioDecoder * p_dec = nullptr
Print * p_print = nullptr
size_t pes_count = 0
Vector< int > pids {0}
uint16_t pmt_pid = 0xFFFF
MTSStreamType selected_stream_type = MTSStreamType::NONE
Vector< MTSStreamType > stream_types

Detailed Description

MPEG-TS (MTS) decoder. Extracts (demuxes) the indicated audio/video data from a MPEG-TS (MTS) data stream. You can define the relevant stream types via the API: addStreamType(MTSStreamType). By default, the decoder selects the AUDIO_AAC, AUDIO_AAC_LATM stream types.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ MTSDecoder() [1/2]

MTSDecoder ( )
default

Default constructor.

◆ MTSDecoder() [2/2]

MTSDecoder ( AudioDecoder & dec)
inline

Provide the AAC decoder (or MP3 Decoder) to receive the extracted content.

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.

◆ addPID()

void addPID ( uint16_t pid)
inlineprotected

Add the PID for which we want to extract the audio data from the PES packets

◆ addStreamType()

void addStreamType ( MTSStreamType type)
inline

Defines the stream type that should be extracted.

◆ audioInfo() [1/2]

◆ audioInfo() [2/2]

◆ audioInfoOut() [1/2]

◆ audioInfoOut() [2/2]

◆ begin() [1/2]

virtual bool begin ( AudioInfo info)
inlineoverridevirtualinherited

Reimplemented from AudioWriter.

◆ begin() [2/2]

bool begin ( )
inlineoverridevirtual

Start the prcessor.

Reimplemented from AudioDecoder.

◆ clearNotifyAudioChange() [1/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearNotifyAudioChange() [2/2]

virtual void clearNotifyAudioChange ( )
inlinevirtualinherited

◆ clearStreamTypes()

void clearStreamTypes ( )
inline

Clears the stream type filter.

◆ demux()

void demux ( )
inlineprotected

demux the available data

◆ end()

void end ( )
inlineoverridevirtual

Stops the processing.

Reimplemented from AudioDecoder.

◆ findSyncWord()

int findSyncWord ( const uint8_t * buf,
size_t nBytes,
uint8_t synch = 0xFF,
uint8_t syncl = 0xF0 )
inlineprotected

Finds the mp3/aac sync word.

◆ getOutput() [1/2]

Print * getOutput ( )
inlineinherited

◆ getOutput() [2/2]

Print * getOutput ( )
inlineinherited

◆ getPayloadStart()

int getPayloadStart ( uint8_t * packet,
bool isPES,
bool & payloadUnitStartIndicator )
inlineprotected

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

◆ isPESStartCodeValid()

bool isPESStartCodeValid ( uint8_t * pes)
inlineprotected

check for PES packet start code prefix

◆ isResultPCM() [1/2]

virtual bool isResultPCM ( )
inlinevirtualinherited

Returns true to indicate that the decoding result is PCM data.

Reimplemented in ContainerM4A, CopyDecoder, and DecoderNetworkFormat.

◆ isResultPCM() [2/2]

virtual bool isResultPCM ( )
inlinevirtualinherited

Returns true to indicate that the decoding result is PCM data.

Reimplemented in ContainerM4A, CopyDecoder, and DecoderNetworkFormat.

◆ isStreamTypeActive()

bool isStreamTypeActive ( MTSStreamType type)
inline

Checks if the stream type is active.

◆ mime()

const char * mime ( )
inlinevirtual

Provides the mime type: "video/MP2T";.

Implements AudioDecoder.

◆ notifyAudioChange() [1/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ notifyAudioChange() [2/2]

void notifyAudioChange ( AudioInfo info)
inlineprotectedinherited

◆ operator bool()

virtual operator bool ( )
inlineoverridevirtual

Implements AudioWriter.

◆ parse()

bool parse ( )
inlineprotected

Parse a single packet and remove the processed data.

◆ parsePacket()

void parsePacket ( uint8_t * packet,
int pid )
inlineprotected

Detailed processing for parsing a single packet.

◆ parsePAT()

void parsePAT ( uint8_t * pat,
int len )
inlineprotected

◆ parsePES()

void parsePES ( uint8_t * packet,
int pid )
inlineprotected

Check for ADTS

Write the data

◆ parsePMT()

void parsePMT ( uint8_t * pmt,
int len )
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.

◆ resizeBuffer()

void resizeBuffer ( int size)
inline

Set a new write buffer size (default is 2000).

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

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

virtual void setOutput ( AudioOutput & out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

◆ setOutput() [2/5]

virtual void setOutput ( AudioStream & out_stream)
inlinevirtualinherited

Defines where the decoded result is written to.

◆ setOutput() [3/5]

void setOutput ( AudioOutput & out_stream)
inlineoverride

Defines where the decoded result is written to.

◆ setOutput() [4/5]

void setOutput ( AudioStream & out_stream)
inlineoverride

Defines where the decoded result is written to.

◆ setOutput() [5/5]

void setOutput ( Print & out_stream)
inlineoverridevirtual

Defines where the decoded result is written to.

Reimplemented from AudioDecoder.

◆ syncPos()

int syncPos ( )
inlineprotected

Find the position of the next sync byte: Usually on position 0.

◆ toStr()

const char * toStr ( MTSStreamType type)
inlineprotected

Convert the relevant MTSStreamType to a string.

◆ write()

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

Member Data Documentation

◆ buffer

SingleBuffer<uint8_t> buffer { 2000 }
protected

◆ frame_length

int frame_length = 0
protected

◆ id

int id
inherited

custom id to be used by application

◆ info

AudioInfo info
protectedinherited

◆ is_active

bool is_active = false
protected

◆ is_adts_missing

bool is_adts_missing = false
protected

◆ is_notify_active

bool is_notify_active = true
protectedinherited

◆ notify_vector

Vector< AudioInfoSupport * > notify_vector
protectedinherited

◆ open_pes_data_size

int open_pes_data_size = 0
protected

◆ p_dec

AudioDecoder* p_dec = nullptr
protected

◆ p_print

Print * p_print = nullptr
protectedinherited

◆ pes_count

size_t pes_count = 0
protected

◆ pids

Vector<int> pids {0}
protected

◆ pmt_pid

uint16_t pmt_pid = 0xFFFF
protected

◆ selected_stream_type

MTSStreamType selected_stream_type = MTSStreamType::NONE
protected

◆ stream_types

Vector<MTSStreamType> stream_types
protected

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