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

Common base for RTP video payloaders (JPEGRtpEncoder, H264RtpEncoder, ...): an AudioEncoder that accepts complete video frames via write() and, as a packetized IMediaSource, hands the resulting RTP fragments back out through packetSize()/readBytes(). More...

#include <RTSPVideoEncoder.h>

Inheritance diagram for RTSPVideoEncoder:
AudioEncoder IMediaSource AudioWriter MimeSource AudioInfoSupport H264RtpEncoder JPEGRtpEncoder

Public Member Functions

AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual bool begin ()=0
 
virtual bool begin (AudioInfo info)
 
virtual void end ()=0
 
virtual uint32_t frameDurationUs ()
 Optional rtsp function: provide the frame duration in microseconds.
 
virtual int frameSize ()
 
virtual RTSPFormatgetFormat ()=0
 Get the media format configuration.
 
virtual const char * mime ()=0
 Provides the mime type of the encoded result.
 
virtual operator bool ()=0
 
virtual int packetSize ()
 Size of the next queued, ready-to-send fragment, for sources that provide already RTP-payload-ready, self-delimited fragments (e.g. RFC 2435 JPEG) instead of a continuous byte stream. For these sources, readBytes() must always be called with exactly packetSize() as maxBytes, so each call retrieves exactly one complete fragment instead of the transport having to guess where one RTP payload ends and the next begins.
 
virtual int readBytes (void *dest, int maxSamples)=0
 Read media data into provided buffer.
 
virtual uint16_t samplesPerFrame ()
 Optional rtsp function: provide samples per the frame.
 
void setAudioInfo (AudioInfo from) override
 Defines the sample rate, number of channels and bits per sample.
 
virtual void setFormat (RTSPFormat &format)=0
 
virtual void setOutput (Print &out_stream) override
 Default output assignment (encoders may override to store Print reference)
 
virtual void start ()
 Initialize media source for streaming.
 
virtual void stop ()
 Cleanup media source after streaming.
 
virtual size_t write (const uint8_t *data, size_t len)=0
 

Protected Member Functions

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

Protected Attributes

AudioInfo info
 

Detailed Description

Common base for RTP video payloaders (JPEGRtpEncoder, H264RtpEncoder, ...): an AudioEncoder that accepts complete video frames via write() and, as a packetized IMediaSource, hands the resulting RTP fragments back out through packetSize()/readBytes().

Letting RTSPOutput hold a single RTSPVideoEncoder* - and take a single RTSPVideoEncoder& constructor parameter - instead of one pointer/overload per codec keeps it from growing a new member/constructor pair for every additional video format. Any codec-specific data a format needs from its encoder (e.g. H.264's sprop-parameter-sets) goes through virtual methods on RTSPFormat itself (see setSpropParameterSets()/setProfileLevelId()), so encoders only ever need to hold a generic RTSPFormat*.

Author
Phil Schatzmann

Member Function Documentation

◆ audioInfo()

AudioInfo audioInfo ( )
inlineoverridevirtualinherited

provides the actual input AudioInfo

Implements AudioInfoSupport.

Reimplemented in CodecNOP, MP3EncoderShine, BinaryContainerEncoder, and MP3ParserEncoder.

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ begin() [1/2]

virtual bool begin ( )
pure virtualinherited

◆ begin() [2/2]

virtual bool begin ( AudioInfo  info)
inlinevirtualinherited

◆ end()

virtual void end ( )
pure virtualinherited

◆ frameDurationUs()

virtual uint32_t frameDurationUs ( )
inlinevirtualinherited

Optional rtsp function: provide the frame duration in microseconds.

Reimplemented in ADPCMEncoder, MP3EncoderShine, OpusOggEncoder, MP3ParserEncoder, and MetaDataFilterEncoder.

◆ frameSize()

virtual int frameSize ( )
inlinevirtualinherited

Optional rtsp function: provide the encoded size (in bytes) of one frame, once known (e.g. after the encoder has seen real data). Lets an RTSPFormat size its RTP fragments to match one frame instead of a fixed guess, so throughput actually tracks frameDurationUs() - a fragment size covering several frames' worth of bytes sent at one-frame timing overruns real-time bandwidth and, over UDP (no flow control), causes packet loss. Returns 0 if not yet known/not applicable (fixed-frame-size codecs have no need to override this).

Reimplemented in ADPCMEncoder, EncoderALAC, AMRNBEncoder, AMRWBEncoder, and MP3ParserEncoder.

◆ getFormat()

virtual RTSPFormat & getFormat ( )
pure virtualinherited

Get the media format configuration.

Returns the RTSPFormat object that describes the media data characteristics including sample rate, bit depth, number of channels, and RTP packaging parameters. If no format has been explicitly set, creates a default 16-bit PCM format at 16kHz mono.

Returns
Pointer to RTSPFormat describing the media characteristics
Note
Default format: 16-bit PCM, 16000 Hz, 1 channel
See also
setFormat(), RTSPFormatPCM

Implemented in H264RtpEncoder, JPEGRtpEncoder, RTSPMediaCallbackSource, and RTSPMediaSource.

◆ mime()

virtual const char * mime ( )
pure virtualinherited

◆ operator bool()

virtual operator bool ( )
pure virtualinherited

◆ packetSize()

virtual int packetSize ( )
inlinevirtualinherited

Size of the next queued, ready-to-send fragment, for sources that provide already RTP-payload-ready, self-delimited fragments (e.g. RFC 2435 JPEG) instead of a continuous byte stream. For these sources, readBytes() must always be called with exactly packetSize() as maxBytes, so each call retrieves exactly one complete fragment instead of the transport having to guess where one RTP payload ends and the next begins.

Call it once before each readBytes() to size that call, and again right after to tell whether the fragment just read was the last one currently available - a 0 result means the caller should set the RTP marker bit on the fragment it just sent (and may advance the timestamp for the next frame).

Returns
-1 if this source is not packetized (use the plain readBytes() stream instead), 0 if packetized but nothing is queued right now, otherwise the size in bytes of the next fragment

Reimplemented in H264RtpEncoder, JPEGRtpEncoder, and RTSPMediaCallbackSource.

◆ readBytes()

virtual int readBytes ( void *  dest,
int  maxSamples 
)
pure virtualinherited

Read media data into provided buffer.

This is the core method that provides media data to the streaming system. Implementation should fill the destination buffer with media samples in the format specified by getFormat(). The method should be non-blocking and return available data immediately.

Parameters
destPointer to buffer where media data should be written
maxBytesMaximum number of bytes that can be written to dest buffer
Returns
Actual number of bytes written to the buffer (0 if no data available)
Note
Data format must match the RTSPFormat returned by getFormat()
Should return 0 when no media data is available (not block)
Called periodically by the streaming system at the rate specified by format

Implemented in RTSPMediaSource, H264RtpEncoder, JPEGRtpEncoder, and RTSPMediaCallbackSource.

◆ samplesPerFrame()

virtual uint16_t samplesPerFrame ( )
inlinevirtualinherited

Optional rtsp function: provide samples per the frame.

Reimplemented in OpusAudioEncoder, OpusMultiStreamAudioEncoder, MP3EncoderShine, MP3ParserEncoder, and MetaDataFilterEncoder.

◆ setAudioInfo()

void setAudioInfo ( AudioInfo  from)
inlineoverridevirtualinherited

◆ setFormat()

virtual void setFormat ( RTSPFormat format)
pure virtual

Associates the RTSPFormat that supplies width/height/framerate/etc. and, for some codecs, receives codec-specific SDP data back.

Implemented in H264RtpEncoder, and JPEGRtpEncoder.

◆ setOutput()

virtual void setOutput ( Print out_stream)
inlineoverridevirtualinherited

◆ start()

virtual void start ( )
inlinevirtualinherited

Initialize media source for streaming.

Called when streaming is about to begin. Implementations should use this to initialize hardware, allocate buffers, start media capture, or perform any other setup required for media data generation.

Note
Called by RTSPMediaStreamer.start()
Default implementation does nothing (suitable for sources that need no setup)

Reimplemented in H264RtpEncoder, JPEGRtpEncoder, RTSPMediaCallbackSource, and RTSPMediaSource.

◆ stop()

virtual void stop ( )
inlinevirtualinherited

Cleanup media source after streaming.

Called when streaming has ended. Implementations should use this to release hardware resources, deallocate buffers, stop media capture, or perform cleanup operations.

Note
Called by RTSPMediaStreamer.stop()
Default implementation does nothing (suitable for sources that need no cleanup)

Reimplemented in H264RtpEncoder, JPEGRtpEncoder, RTSPMediaCallbackSource, and RTSPMediaSource.

◆ write()

virtual size_t write ( const uint8_t *  data,
size_t  len 
)
pure virtualinherited

◆ writeBlocking()

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

Member Data Documentation

◆ info

AudioInfo info
protectedinherited

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