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

H.264 video decoder: wraps TinyH264Decoder (https://github.com/pschatzmann/TinyH264) as a VideoOutput, so it can be plugged directly into e.g. DemuxerAVI::setOutputVideo()/ DemuxerMP4::setOutputVideo(). Consumes an Annex-B H.264 bitstream via write() and, once a complete picture has been decoded, writes it - converted to setVideoFormat()'s format (RGB565 by default, the common TFT wire format) - to the Print target configured via setOutput(), one write() call per decoded picture. More...

#include <CodecH264.h>

Inheritance diagram for H264Decoder:
VideoDecoder VideoInfoSource VideoOutput

Public Member Functions

 H264Decoder ()
 
 H264Decoder (Print &out)
 
 H264Decoder (VideoOutput &out)
 
bool begin () override
 
tinyh264::TinyH264Decoder< tinyh264::PSRAMAllocatorESP32< uint8_t > > & driver ()
 
void end () override
 Releases the decoder's picture buffers - see TinyH264Decoder::end().
 
void flush () override
 
bool hasError ()
 
void setMaxRefFrames (int n)
 
void setOutput (Print &out)
 
void setOutput (VideoOutput &out)
 
void setVideoFormat (VideoFormat format) override
 
VideoInfo videoInfo () override
 
size_t write (const uint8_t *data, size_t len) override
 

Protected Member Functions

void writeToOutput ()
 
size_t writeToOutput (uint8_t *data, size_t len)
 

Static Protected Member Functions

static void onFrame (tinyh264::TinyH264Decoder< tinyh264::PSRAMAllocatorESP32< uint8_t > > &decoder, void *userData)
 

Protected Attributes

tinyh264::TinyH264Decoder< tinyh264::PSRAMAllocatorESP32< uint8_t > > decoder_
 
Vector< uint8_t > frame_buffer
 
Printp_out = nullptr
 
VideoOutputp_out_video = nullptr
 
VideoFormat pixel_format = VideoFormat::RGB565
 

Detailed Description

H.264 video decoder: wraps TinyH264Decoder (https://github.com/pschatzmann/TinyH264) as a VideoOutput, so it can be plugged directly into e.g. DemuxerAVI::setOutputVideo()/ DemuxerMP4::setOutputVideo(). Consumes an Annex-B H.264 bitstream via write() and, once a complete picture has been decoded, writes it - converted to setVideoFormat()'s format (RGB565 by default, the common TFT wire format) - to the Print target configured via setOutput(), one write() call per decoded picture.

write()/flush() implement the VideoOutput contract (see Video.h): write() may be called one or more times per frame - bytes are forwarded to the decoder immediately (Annex-B start codes are self-delimiting, so no internal buffering is needed here; a picture may complete partway through any write() call, not just at flush()). flush() is a no-op, kept only because some producers (e.g. DemuxerAVI/DemuxerMP4) call it unconditionally after each frame.

Uses H264_DEFAULT_ALLOCATOR for the decoded picture buffers - see that macro's own comment above for the PSRAM-on-ESP32/heap- elsewhere default it picks, and how to override it.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ H264Decoder() [1/3]

H264Decoder ( )
inline

◆ H264Decoder() [2/3]

H264Decoder ( Print out)
inline

◆ H264Decoder() [3/3]

H264Decoder ( VideoOutput out)
inline

Member Function Documentation

◆ begin()

bool begin ( )
inlineoverridevirtual

Reserves the decoder's picture buffers up front - see TinyH264Decoder::begin().

Implements VideoDecoder.

◆ driver()

tinyh264::TinyH264Decoder< tinyh264::PSRAMAllocatorESP32< uint8_t > > & driver ( )
inline

Direct access to the wrapped TinyH264Decoder, e.g. for its width()/ height()/y()/u()/v()/getY()/getU()/getV() accessors.

◆ end()

void end ( )
inlineoverridevirtual

Releases the decoder's picture buffers - see TinyH264Decoder::end().

Implements VideoDecoder.

◆ flush()

void flush ( )
inlineoverridevirtual

No-op - kept to satisfy the VideoOutput/Print contract; decoding already happens synchronously in write() (see class comment).

Reimplemented from VideoOutput.

◆ hasError()

bool hasError ( )
inline

True if the most recent write() call ended in a bitstream error or hit an unsupported stream feature.

◆ onFrame()

static void onFrame ( tinyh264::TinyH264Decoder< tinyh264::PSRAMAllocatorESP32< uint8_t > > &  decoder,
void *  userData 
)
inlinestaticprotected

◆ setMaxRefFrames()

void setMaxRefFrames ( int  n)
inline

Runtime-active maximum stored reference pictures - see TinyH264Decoder::setMaxRefFrames().

◆ setOutput() [1/2]

void setOutput ( Print out)
inlinevirtual

Defines the target the decoded picture is written to, one write() call per decoded picture, in the format selected via setVideoFormat() (RGB565 by default).

Implements VideoDecoder.

◆ setOutput() [2/2]

void setOutput ( VideoOutput out)
inline

◆ setVideoFormat()

void setVideoFormat ( VideoFormat  format)
inlineoverridevirtual

Selects the pixel format written to setOutput()'s target - RGB565 (the default) is what most TFT display libraries expect; RGB666/ RGB888 for higher color depth displays; I420 to pass the decoded planes through unconverted (tightly packed: Y bytes, then U bytes, then V bytes, no row padding - see TinyH264Decoder::toYUV420()). Any other VideoFormat is logged and ignored (previous format kept).

Implements VideoDecoder.

◆ videoInfo()

VideoInfo videoInfo ( )
inlineoverridevirtual

Reports the format/dimensions of the picture written to setOutput()'s target - format is setVideoFormat()'s most recently selected value (RGB565 if never called); width/height are the most recently decoded picture's (0 before any picture has been decoded).

Implements VideoDecoder.

◆ write()

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

Feeds one chunk of Annex-B H.264 data - may be called more than once per frame (e.g. from a demuxer that hands over payload in pieces). Decodes immediately, invoking setOutput()'s Print once per completed picture from within this call (not deferred to flush()).

Implements VideoOutput.

◆ writeToOutput() [1/2]

void writeToOutput ( )
inlineprotected

◆ writeToOutput() [2/2]

size_t writeToOutput ( uint8_t *  data,
size_t  len 
)
inlineprotected

Member Data Documentation

◆ decoder_

tinyh264::TinyH264Decoder< tinyh264::PSRAMAllocatorESP32<uint8_t> > decoder_
protected

◆ frame_buffer

Vector<uint8_t> frame_buffer
protected

◆ p_out

Print* p_out = nullptr
protected

◆ p_out_video

VideoOutput* p_out_video = nullptr
protected

◆ pixel_format

VideoFormat pixel_format = VideoFormat::RGB565
protected

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