VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Gv::RtpAvcPacket Class Reference

An RTP payload parser for the "H264" payload type. More...

#include <gvrtpavcpacket.h>

Public Types

enum  Type {
  SINGLE_NALU_1 = 1, SINGLE_NALU_23 = 23, STAP_A = 24, STAP_B = 25,
  MTAP16 = 26, MTAP24 = 27, FU_A = 28, FU_B = 29
}
 

Public Member Functions

 RtpAvcPacket (const unsigned char *begin, const unsigned char *end)
 Constructor taking in an RTP payload with Payload Type of H264/90000. More...
 
 RtpAvcPacket (const std::string &data)
 Constructor overload taking a string packet.
 
const char * reason () const
 Returns the in-valid() reason, or nullptr.
 
bool valid () const
 Returns true if a valid packet.
 
std::string str (bool more=false) const
 Returns a summary of the packet header for debugging purposes.
 
unsigned int type () const
 Returns the RTP-AVC packet type, matching the Type enum. More...
 
unsigned int nri () const
 Returns the NALU nal_ref_idc value, in the range 0..3. More...
 
bool type_is_fu () const
 Returns true if type() is FU_A or FU_B.
 
bool type_is_single () const
 Returns true if type() is SINGLE_NALU_x.
 
bool type_is_sequence_parameter_set () const
 Returns true if type() is SINGLE_NALU_7.
 
bool type_is_picture_parameter_set () const
 Returns true if type() is SINGLE_NALU_8.
 
bool fu_start () const
 Returns true for the first FU packet in the fragmented NALU. More...
 
bool fu_end () const
 Returns true for the last FU packet in the fragmented NALU. More...
 
unsigned int fu_type () const
 Returns the type of the fragmented NALU. More...
 
size_t payloadSize () const
 Returns the RTP-AVC payload size.
 
char payloadFirst () const
 Returns the first RTP-AVC payload byte. More...
 
const char * payloadBegin () const
 Returns the RTP-AVC payload pointer, but the first byte may be wrong so use payloadFirst() to overwrite it after copying. More...
 
const char * payloadEnd () const
 Returns the RTP-AVC payload end pointer.
 

Static Public Member Functions

static size_t smallest ()
 The smallest parsable packet.
 

Detailed Description

An RTP payload parser for the "H264" payload type.

Note that the RTP payload type for H264 is not fixed; it is communicated out-of-band by eg. RTSP.

The RTP payload for AVC can either be exactly one AVC NALU, more than one NALU, or just a NALU fragment (ie. single, aggregated or fragmented). The first byte of the RTP payload is cunningly defined so that is can double-up as the first byte of a NALU, ie. the NALU header byte. If the first byte is a valid NALU type (ie. 1-23 in the low bits) then the RTP payload is a single NALU and there is no structure added by the RTP-AVC layer.

Note that AVC NALUs are composed of a single header byte followed by byte-stuffed RBSP data (see Gr::Avc). They are often chained together using a four-byte 00-00-00-01 start code and a three-byte 00-00-01 separator.

See Also
RFC-6184

Definition at line 53 of file gvrtpavcpacket.h.

Constructor & Destructor Documentation

Gv::RtpAvcPacket::RtpAvcPacket ( const unsigned char *  begin,
const unsigned char *  end 
)

Constructor taking in an RTP payload with Payload Type of H264/90000.

The data should start with the RTP H264 header defined in RFC-6184 section 5.2. Precondition: (end-begin) >= smallest().

Definition at line 35 of file gvrtpavcpacket.cpp.

Member Function Documentation

bool Gv::RtpAvcPacket::fu_end ( ) const

Returns true for the last FU packet in the fragmented NALU.

Precondition: fu()

Definition at line 155 of file gvrtpavcpacket.cpp.

bool Gv::RtpAvcPacket::fu_start ( ) const

Returns true for the first FU packet in the fragmented NALU.

Precondition: fu()

Definition at line 149 of file gvrtpavcpacket.cpp.

unsigned int Gv::RtpAvcPacket::fu_type ( ) const

Returns the type of the fragmented NALU.

Precondition: fu()

Definition at line 161 of file gvrtpavcpacket.cpp.

unsigned int Gv::RtpAvcPacket::nri ( ) const

Returns the NALU nal_ref_idc value, in the range 0..3.

This indicates the discardability of the packet; zero indicates that the packet is discardable, and 3 that it is not.

Definition at line 85 of file gvrtpavcpacket.cpp.

const char * Gv::RtpAvcPacket::payloadBegin ( ) const

Returns the RTP-AVC payload pointer, but the first byte may be wrong so use payloadFirst() to overwrite it after copying.

Note that payloadBegin()/payloadEnd() data will only be a NALU if type_is_single(), and RBSP byte stuffing is never used.

Definition at line 120 of file gvrtpavcpacket.cpp.

char Gv::RtpAvcPacket::payloadFirst ( ) const

Returns the first RTP-AVC payload byte.

This byte is split across two bytes in the raw data of an initial fragmentated packet, but to copy the raw data just to fix up the first byte would be too expensive.

Definition at line 126 of file gvrtpavcpacket.cpp.

unsigned int Gv::RtpAvcPacket::type ( ) const

Returns the RTP-AVC packet type, matching the Type enum.

This is also the NALU type iff the value is in the range 1..23 (ie. if type_is_single()).

Definition at line 80 of file gvrtpavcpacket.cpp.


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