H.264 RTP Encoder - Packetizes Annex-B H.264 access units per RFC 6184 for RTSP video streaming.
More...
|
| | 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.
|
| |
|
| 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) |
| |
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:
- As an AudioEncoder, write() accepts one complete Annex-B access unit (all the NAL units for one encoded frame, e.g. the output of a single H264Encoder::encode()/captureH264() call from the codec-h264-ESP32S3 library) per call - there is no cross-call accumulation, since Annex-B has no reliable in-stream "end of frame" marker to detect the way JPEG has 0xFFD9.
- As an IMediaSource, packetSize()/readBytes() hand out the resulting RTP payloads one fragment at a time: NAL units that fit in one packet are sent as Single NAL Unit packets (payload = NAL bytes verbatim); larger ones are split into FU-A fragments, each with its own 2-byte FU header.
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:
- Author
- Phil Schatzmann
| 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.
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 from IMediaSource.