43 m_p(reinterpret_cast<const unsigned char*>(data.data())) ,
51 if( (*m_p&0x80) != 0U )
return "top bit of nalu header byte is set" ;
52 if( type() == 0 )
return "nalu header byte is zero" ;
53 if( type_is_fu() && fu_start() && fu_end() )
return "conflicting fragmentation flags" ;
54 if( m_n <= payloadOffset() )
return "packet too small" ;
60 return reason() == nullptr ;
65 std::ostringstream ss ;
66 ss <<
"type=" << type() ;
68 ss <<
" fu-start=" << fu_start() <<
" fu-end=" << fu_end() <<
" fu-type=" << fu_type() ;
71 << std::hex << std::setfill(
'0') << std::setw(2)
72 <<
" p0=0x" <<
static_cast<unsigned int>(m_p[0]) <<
" "
73 <<
" p1=0x" << static_cast<unsigned int>(m_p[1]) <<
" "
74 <<
" p2=0x" <<
static_cast<unsigned int>(m_p[2]) <<
" "
75 <<
" pf=0x" << static_cast<unsigned int>(static_cast<unsigned char>(payloadFirst()))
87 unsigned int n =
static_cast<unsigned char>(*m_p) ;
88 return ( n >> 5 ) & 3U ;
91 unsigned int Gv::RtpAvcPacket::payloadOffset()
const
105 return fu_start() ? 1U : 2U ;
106 else if( type() == FU_B )
107 return fu_start() ? 3U : 4U ;
108 else if( type_is_single() )
111 throw std::runtime_error(
"unsupported RTP-AVC packet type" ) ;
116 G_ASSERT( m_n >= payloadOffset() ) ;
117 return m_n - payloadOffset() ;
122 const char * p =
reinterpret_cast<const char*
>( m_p ) ;
123 return p + payloadOffset() ;
128 if( type_is_fu() && fu_start() )
129 return ( (m_p[0]&0xe0) | (m_p[1]&0x1f) ) ;
131 return m_p[payloadOffset()] ;
136 return payloadBegin() + payloadSize() ;
141 return type() >= SINGLE_NALU_1 && type() <= SINGLE_NALU_23 ;
146 return type() == FU_A || type() == FU_B ;
151 G_ASSERT( m_n >= 2U ) ;
152 return !!( m_p[1] & 0x80 ) ;
157 G_ASSERT( m_n >= 2U ) ;
158 return !!( m_p[1] & 0x40 ) ;
163 G_ASSERT( m_n >= 2U ) ;
164 return m_p[1] & 0x1f ;
const char * payloadBegin() const
Returns the RTP-AVC payload pointer, but the first byte may be wrong so use payloadFirst() to overwri...
static size_t smallest()
The smallest parsable packet.
bool type_is_single() const
Returns true if type() is SINGLE_NALU_x.
unsigned int type() const
Returns the RTP-AVC packet type, matching the Type enum.
bool valid() const
Returns true if a valid packet.
bool fu_start() const
Returns true for the first FU packet in the fragmented NALU.
const char * payloadEnd() const
Returns the RTP-AVC payload end pointer.
RtpAvcPacket(const unsigned char *begin, const unsigned char *end)
Constructor taking in an RTP payload with Payload Type of H264/90000.
bool type_is_picture_parameter_set() const
Returns true if type() is SINGLE_NALU_8.
unsigned int nri() const
Returns the NALU nal_ref_idc value, in the range 0..3.
unsigned int fu_type() const
Returns the type of the fragmented NALU.
char payloadFirst() const
Returns the first RTP-AVC payload byte.
std::string str(bool more=false) const
Returns a summary of the packet header for debugging purposes.
const char * reason() const
Returns the in-valid() reason, or nullptr.
bool type_is_fu() const
Returns true if type() is FU_A or FU_B.
bool fu_end() const
Returns true for the last FU packet in the fragmented NALU.
size_t payloadSize() const
Returns the RTP-AVC payload size.
bool type_is_sequence_parameter_set() const
Returns true if type() is SINGLE_NALU_7.