31 m_p(reinterpret_cast<const unsigned char*>(p)) ,
36 m_version = ( m_p[0] & 0xc0 ) >> 6 ;
37 m_padding = !!( m_p[0] & 0x20 ) ;
38 m_extension = !!( m_p[0] & 0x10 ) ;
39 m_cc = m_p[0] & 0x0f ;
40 m_marker = !!( m_p[1] & 0x80 ) ;
41 m_pt = m_p[1] & 0x7f ;
42 m_seq = make_word( &m_p[2] ) ;
43 m_timestamp = make_dword( &m_p[4] ) ;
44 m_src_id = make_dword( &m_p[8] ) ;
46 m_header_size = 12U + 4U*m_cc ;
47 m_ehl = (m_extension && n>=(m_header_size+4U)) ? make_word(&m_p[m_header_size+2U]) : 0U ;
48 m_header_size += (m_ehl*4U) ;
50 m_padsize = m_padding ? m_p[n-1U] : 0U ;
51 m_payload_size = n - m_header_size - m_padsize ;
53 if( m_version != 2U ) m_reason =
"invalid version" ;
54 if( n < (m_header_size+m_padsize) ) m_reason =
"invalid sizes" ;
64 return m_reason.empty() ;
74 std::ostringstream ss ;
77 <<
" v=" << m_version <<
" p=" << m_padding <<
" e=" << m_extension
78 <<
" cc=" << m_cc <<
" m=" << m_marker <<
" pt=" << m_pt
79 <<
" ehl=" << m_ehl <<
" hs=" << m_header_size
80 <<
" pds=" << m_padsize <<
" pls=" << m_payload_size
81 <<
" ts=" << m_timestamp
88 std::ostringstream ss ;
89 ss << G::hexdump<8>(m_p,m_p+m_n) ;
113 unsigned int Gv::RtpPacket::make_word(
const unsigned char * p )
115 return (static_cast<unsigned int>(p[0]) << 8) | p[1] ;
118 unsigned long Gv::RtpPacket::make_dword(
const unsigned char * p )
121 (static_cast<unsigned long>(p[0]) << 24) |
122 (
static_cast<unsigned long>(p[1]) << 16) |
123 (
static_cast<unsigned long>(p[2]) << 8) |
124 (
static_cast<unsigned long>(p[3]) << 0) ;
141 return m_pt >= 96U && m_pt <= 127U ;
146 return m_p + m_header_size ;
151 return m_p + m_header_size + m_payload_size ;
156 return reinterpret_cast<const char*
>( ubegin() ) ;
161 return reinterpret_cast<const char*
>( uend() ) ;
166 return m_header_size ;
171 return m_payload_size ;
const char * end() const
Returns the payload end iterator.
bool valid() const
Returns true if a valid packet.
bool typeJpeg() const
Returns true if the payload type is 26.
static size_t smallest()
Returns the smallest valid packet size.
std::string str() const
Returns a one-line summary of header fields.
size_t size() const
Returns the payload size.
std::string hexdump() const
Returns a complete hex dump.
const char * begin() const
Returns the payload begin iterator.
const unsigned char * ubegin() const
Returns the payload begin iterator.
bool typeDynamic() const
Returns true if the payload type is in the dynamic range, 96 to 127.
const unsigned char * uend() const
Returns the payload end iterator.
unsigned long timestamp() const
Returns the timestamp.
RtpPacket(const char *p, size_t n)
Constructor.
size_t offset() const
Returns the payload offset.
unsigned int seq() const
Returns the sequence number.
bool marker() const
Returns the marker bit.
unsigned int type() const
Returns the payload type.
unsigned long src() const
Returns the source id.
std::string reason() const
Returns the in-valid() reason.