|
arduino-audio-tools
|
H.264 RTP Encoder - Packetizes Annex-B H.264 access units per RFC 6184 for RTSP video streaming. More...
#include <H264RtpEncoder.h>


Public Member Functions | |
| H264RtpEncoder ()=default | |
| H264RtpEncoder (size_t maxFragmentSize) | |
| Constructor with maximum fragment size. | |
| AudioInfo | audioInfo () override |
| provides the actual input AudioInfo | |
| virtual AudioInfo | audioInfoOut () |
| bool | begin () override |
| virtual bool | begin (AudioInfo info) |
| void | end () override |
| virtual uint32_t | frameDurationUs () |
| Optional rtsp function: provide the frame duration in microseconds. | |
| virtual int | frameSize () |
| RTSPFormat & | getFormat () override |
| Get the media format configuration. | |
| const char * | mime () override |
| Provides the mime type of the encoded result. | |
| operator bool () override | |
| int | packetSize () override |
| 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. | |
| int | readBytes (void *dest, int maxBytes) override |
| virtual uint16_t | samplesPerFrame () |
| Optional rtsp function: provide samples per the frame. | |
| void | setAudioInfo (AudioInfo info) override |
| Defines the sample rate, number of channels and bits per sample. | |
| void | setFormat (RTSPFormat &format) override |
| void | setMaxFragmentSize (size_t size) |
| Set the maximum RTP payload size per packet. | |
| void | setMaxQueuedFrames (size_t frames) |
| Maximum number of complete frames buffered when the consumer falls behind. | |
| virtual void | setOutput (Print &out_stream) override |
| Default output assignment (encoders may override to store Print reference) | |
| void | start () override |
| Initialize media source for streaming. | |
| void | stop () override |
| Cleanup media source after streaming. | |
| size_t | write (const uint8_t *data, size_t len) override |
| Process one complete Annex-B access unit (all NAL units of one encoded frame) and queue the resulting RTP fragments. | |
Protected Member Functions | |
| void | appendFragment (const uint8_t *payload, size_t len, bool last) |
| void | cachePps (const uint8_t *nal, size_t len) |
| void | cacheSps (const uint8_t *nal, size_t len) |
| void | clearQueue () |
| void | dropOldestFrame () |
| void | emitNal (const uint8_t *nal, size_t nalLen, bool isLastOfFrame) |
| Queue one NAL unit as a Single NAL Unit packet, or split it into FU-A fragments (RFC 6184 §5.6/§5.8) if it is larger than m_maxFragmentSize. | |
| void | extractNALs (const uint8_t *data, size_t len, Vector< size_t > &offsets, Vector< size_t > &lengths) |
| size_t | findStartCode (const uint8_t *data, size_t len, size_t from) |
Locate the next Annex-B start code (00 00 01 or 00 00 00 01) at or after from. | |
| int | queuePacketSize () |
| int | queueReadBytes (void *dest, int maxBytes) |
| uint32_t | readQueueU32 (size_t pos) |
| void | updateSpropParameterSets () |
| void | writeBlocking (Print *out, uint8_t *data, size_t len) |
Static Protected Member Functions | |
| static String | base64Encode (const uint8_t *data, size_t len) |
Protected Attributes | |
| RTSPFormatH264 | default_format |
| AudioInfo | info |
| bool | m_isStarted = false |
| size_t | m_maxFragmentSize = 1400 |
| size_t | m_maxQueuedFrames = 1 |
| Vector< uint8_t > | m_pps |
| Vector< uint8_t > | m_queue |
| size_t | m_queuedFrames = 0 |
| size_t | m_queueHead = 0 |
| Vector< uint8_t > | m_scratch |
| Vector< uint8_t > | m_sps |
| RTSPFormat * | p_format = nullptr |
H.264 RTP Encoder - Packetizes Annex-B H.264 access units per RFC 6184 for RTSP video streaming.
Like JPEGRtpEncoder, this class plays both roles needed to get a video frame onto the wire:
SPS (type 7) and PPS (type 8) NAL units are cached as soon as they are seen and re-sent (as their own Single NAL Unit packets) immediately before every IDR frame, so clients that join mid-stream or lose a packet can still resync - the same approach used by RFC 6184-based servers in general. The cached SPS is also used to derive profile-level-id and, together with the cached PPS, sprop-parameter-sets for the SDP - pushed into the associated RTSPFormatH264 as soon as both are available (see RTSPFormatH264 for why this can only happen after the first IDR frame).
Usage with RTSPOutput:
|
default |
|
inline |
Constructor with maximum fragment size.
| maxFragmentSize | Maximum RTP payload size per packet (default: 1400 bytes) |
|
inlineoverridevirtualinherited |
provides the actual input AudioInfo
Implements AudioInfoSupport.
Reimplemented in CodecNOP, MP3EncoderShine, BinaryContainerEncoder, and MP3ParserEncoder.
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in MP3EncoderShine, PureDataStream, PWMAudioOutput< PWMDriverT >, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, ResampleStreamT< TInterpolator >, and SupportedRatesStream.
|
inlineoverridevirtual |
Implements AudioWriter.
Reimplemented in OpusOggEncoder, OggContainerEncoder, DecoderBasic, AudioDecoder, AACEncoderFAAC, AACEncoderFDK, AACEncoderVO, OggContainerDecoder, and MetaDataFilterEncoder.
|
inlineprotectedinherited |
|
inlineprotectedinherited |
Queue one NAL unit as a Single NAL Unit packet, or split it into FU-A fragments (RFC 6184 §5.6/§5.8) if it is larger than m_maxFragmentSize.
| isLastOfFrame | True if this is the last NAL unit of the access unit - propagated to its last fragment's isLast flag. |
|
inlineoverridevirtual |
Implements AudioWriter.
|
inlineprotected |
Splits an Annex-B buffer into its individual NAL units (start codes stripped), recording each one's offset/length into data.
Locate the next Annex-B start code (00 00 01 or 00 00 00 01) at or after from.
|
inlinevirtualinherited |
Optional rtsp function: provide the frame duration in microseconds.
Reimplemented in ADPCMEncoder, MP3EncoderShine, OpusOggEncoder, MP3ParserEncoder, and MetaDataFilterEncoder.
|
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.
|
inlineoverridevirtual |
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.
Implements IMediaSource.
|
inlineoverridevirtual |
Provides the mime type of the encoded result.
Implements AudioEncoder.
|
inlineoverridevirtual |
Implements AudioWriter.
|
inlineoverridevirtual |
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).
Reimplemented from IMediaSource.
|
inlineprotectedinherited |
Retrieves the next queued fragment. Call queuePacketSize() first and pass its result as maxBytes so exactly one fragment is read.
Retrieves the next queued fragment. Call packetSize() first and pass its result as maxBytes so exactly one fragment is read.
Implements IMediaSource.
|
inlinevirtualinherited |
Optional rtsp function: provide samples per the frame.
Reimplemented in OpusAudioEncoder, OpusMultiStreamAudioEncoder, MP3EncoderShine, MP3ParserEncoder, and MetaDataFilterEncoder.
|
inlineoverridevirtual |
Defines the sample rate, number of channels and bits per sample.
Reimplemented from AudioEncoder.
|
inlineoverridevirtual |
Associates the RTSPFormat (an RTSPFormatH264) that receives sprop-parameter-sets/profile-level-id once SPS/PPS are known (via the virtual RTSPFormat::setSpropParameterSets()/setProfileLevelId() hooks) and supplies width/height/framerate.
Implements RTSPVideoEncoder.
|
inline |
Set the maximum RTP payload size per packet.
|
inline |
Maximum number of complete frames buffered when the consumer falls behind.
|
inlineoverridevirtualinherited |
Default output assignment (encoders may override to store Print reference)
Implements AudioWriter.
Reimplemented in EncoderBasic, DSFEncoder, WAVEncoder, EncoderBase64, CodecNOP, APTXEncoder, Codec2Encoder, CopyEncoder, G722Encoder, GSMEncoder, ILBCEncoder, LC3Encoder, MP3EncoderLAME, EncoderNetworkFormat, SBCEncoder, AACEncoderFAAC, AACEncoderFDK, AACEncoderVO, ADPCMEncoder, ADPCMEncoderXQ, EncoderALAC, AMRNBEncoder, AMRWBEncoder, CodecChain, FLACEncoder, EncoderFloat, G729Encoder, G7xxEncoder, EncoderL16, EncoderL8, MP3EncoderShine, OpusAudioEncoder, OpusMultiStreamAudioEncoder, MP3ParserEncoder, MetaDataFilterEncoder, BinaryContainerEncoder, OSCContainerEncoder, and OggContainerEncoder.
|
inlineoverridevirtual |
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.
Reimplemented from IMediaSource.
|
inlineoverridevirtual |
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.
Reimplemented from IMediaSource.
|
inlineprotected |
Process one complete Annex-B access unit (all NAL units of one encoded frame) and queue the resulting RTP fragments.
| data | Pointer to Annex-B H.264 data (one or more start-code delimited NAL units belonging to a single frame) |
| len | Length of the data in bytes |
Implements AudioWriter.
|
protected |
|
protectedinherited |
|
protected |
|
protected |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protected |