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

Motion-JPEG video decoder: wraps JPEGDecoder (https://github.com/Bodmer/JPEGDecoder) as a VideoDecoder, so it can be plugged directly into e.g. DemuxerAVI::setOutputVideo()/ DemuxerMP4::setOutputVideo() - the same role H264Decoder (CodecH264.h) and MPGDecoder (CodecMPG.h) play for their own codecs. Named "MJPEGDecoder" rather than reusing JPEGDecoder's own name to avoid shadowing that (global-namespace) class from within this one. More...

#include <CodecJPEG.h>

Inheritance diagram for MJPEGDecoder:
VideoDecoder VideoInfoSource VideoOutput

Public Member Functions

 MJPEGDecoder ()=default
 
 MJPEGDecoder (Print &out)
 
 MJPEGDecoder (VideoOutput &out)
 
bool begin () override
 Initializes the decoder (allocates its picture buffers, etc).
 
void end () override
 Releases the decoder's resources.
 
void flush () override
 
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 decodeToFrameBuffer ()
 
size_t writeToOutput (const uint8_t *data, size_t len)
 

Protected Attributes

Vector< uint8_t > frame_buffer
 
uint16_t height_ = 0
 
Vector< uint8_t > img_vector
 
JPEGDecoder jpeg_decoder
 
Printp_out = nullptr
 
VideoOutputp_out_video = nullptr
 
size_t pos = 0
 
uint64_t start_ms = 0
 
uint16_t width_ = 0
 

Detailed Description

Motion-JPEG video decoder: wraps JPEGDecoder (https://github.com/Bodmer/JPEGDecoder) as a VideoDecoder, so it can be plugged directly into e.g. DemuxerAVI::setOutputVideo()/ DemuxerMP4::setOutputVideo() - the same role H264Decoder (CodecH264.h) and MPGDecoder (CodecMPG.h) play for their own codecs. Named "MJPEGDecoder" rather than reusing JPEGDecoder's own name to avoid shadowing that (global-namespace) class from within this one.

write()/flush() implement the VideoOutput contract (see Video.h), but unlike H264Decoder/MPGDecoder - which decode incrementally as Annex-B/ PES bytes arrive, with no separate "frame complete" signal needed - a bare JPEG byte stream has no equivalent self-framing a demuxer can use to decode early. write() therefore just accumulates one JPEG image's bytes, and flush() (called by e.g. DemuxerAVI/DemuxerMP4 at each frame boundary) decodes the assembled image directly into a full-frame RGB565 buffer and writes it to the target configured via setOutput(), one write() call per decoded picture - same convention as H264Decoder/ MPGDecoder, so any VideoOutput (OutputTFT_eSPI, OutputTinyGPU, OutputOpenCV, ...) works unchanged regardless of which codec produced the picture.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ MJPEGDecoder() [1/3]

MJPEGDecoder ( )
default

◆ MJPEGDecoder() [2/3]

MJPEGDecoder ( Print out)
inline

◆ MJPEGDecoder() [3/3]

MJPEGDecoder ( VideoOutput out)
inline

Member Function Documentation

◆ begin()

bool begin ( )
inlineoverridevirtual

Initializes the decoder (allocates its picture buffers, etc).

Implements VideoDecoder.

◆ decodeToFrameBuffer()

void decodeToFrameBuffer ( )
inlineprotected

Reads every MCU block JPEGDecoder produces for the image just handed to decodeArray() and copies it into frame_buffer, row by row (source rows are MCUWidth pixels wide even for a right/bottom edge block narrower/shorter than that - only its top-left corner holds valid pixels - so a straight linear copy would misalign those edge blocks).

◆ end()

void end ( )
inlineoverridevirtual

Releases the decoder's resources.

Implements VideoDecoder.

◆ flush()

void flush ( )
inlineoverridevirtual

Decodes the assembled JPEG image and writes the resulting RGB565 frame to setOutput()'s target, then resets for the next frame - a no-op if write() hasn't accumulated anything since the last call.

Reimplemented from VideoOutput.

◆ setOutput() [1/2]

void setOutput ( Print out)
inlinevirtual

Defines the target the decoded picture is written to, one write() call per decoded picture (RGB565 - the only format JPEGDecoder produces).

Implements VideoDecoder.

◆ setOutput() [2/2]

void setOutput ( VideoOutput out)
inline

◆ setVideoFormat()

void setVideoFormat ( VideoFormat  format)
inlineoverridevirtual

JPEGDecoder only ever produces RGB565 - any other value is logged and ignored.

Implements VideoDecoder.

◆ videoInfo()

VideoInfo videoInfo ( )
inlineoverridevirtual

Reports the dimensions of the most recently decoded picture - 0 before any picture has been decoded.

Implements VideoDecoder.

◆ write()

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

Accumulates one JPEG image's bytes - may be called more than once per frame (e.g. from a demuxer that hands over payload in pieces). Decoding happens on flush(), not here.

Implements VideoOutput.

◆ writeToOutput()

size_t writeToOutput ( const uint8_t *  data,
size_t  len 
)
inlineprotected

Member Data Documentation

◆ frame_buffer

Vector<uint8_t> frame_buffer
protected

◆ height_

uint16_t height_ = 0
protected

◆ img_vector

Vector<uint8_t> img_vector
protected

◆ jpeg_decoder

JPEGDecoder jpeg_decoder
protected

◆ p_out

Print* p_out = nullptr
protected

◆ p_out_video

VideoOutput* p_out_video = nullptr
protected

◆ pos

size_t pos = 0
protected

◆ start_ms

uint64_t start_ms = 0
protected

◆ width_

uint16_t width_ = 0
protected

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