VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvrtppacket.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gvrtppacket.h
19 ///
20 
21 #ifndef GV_RTPPACKET__H
22 #define GV_RTPPACKET__H
23 
24 #include "gdef.h"
25 #include "gexception.h"
26 #include <string>
27 
28 namespace Gv
29 {
30  class RtpPacket ;
31 }
32 
33 /// \class Gv::RtpPacket
34 /// An RTP packet parser, as per RFC 3550 (section 5). An RTP packet contains a
35 /// header, an optional list of sources (eg. separate cameras with their own
36 /// sequence numbers), and a payload.
37 ///
38 /// Payload formats are defined wrt. a profile sepecification, eg. RFC 3551 for
39 /// the "RTP/AVP" profile. The profile defines mappings from a payload type
40 /// to a payload encoding.
41 ///
42 /// See also RFC 2435 for the JPEG profile.
43 ///
45 {
46 public:
47  G_EXCEPTION( Error , "rtp packet error" ) ;
48 
49  RtpPacket( const char * p , size_t n ) ;
50  ///< Constructor. Beware that the data is not copied so it must
51  ///< remain valid for payload methods (begin(), end() etc).
52  ///< Precondition: n >= smallest()
53 
54  static size_t smallest() ;
55  ///< Returns the smallest valid packet size.
56 
57  bool valid() const ;
58  ///< Returns true if a valid packet.
59 
60  std::string reason() const ;
61  ///< Returns the in-valid() reason.
62 
63  std::string str() const ;
64  ///< Returns a one-line summary of header fields.
65 
66  std::string hexdump() const ;
67  ///< Returns a complete hex dump.
68 
69  ///< header...
70 
71  bool marker() const ;
72  ///< Returns the marker bit. The interpretation is
73  ///< defined by the profile.
74 
75  unsigned int seq() const ;
76  ///< Returns the sequence number.
77 
78  unsigned long timestamp() const ;
79  ///< Returns the timestamp.
80 
81  unsigned long src() const ;
82  ///< Returns the source id.
83 
84  ///< payload...
85 
86  unsigned int type() const ;
87  ///< Returns the payload type.
88 
89  bool typeJpeg() const ;
90  ///< Returns true if the payload type is 26.
91 
92  bool typeDynamic() const ;
93  ///< Returns true if the payload type is in the dynamic range,
94  ///< 96 to 127.
95 
96  const char * begin() const ;
97  ///< Returns the payload begin iterator.
98 
99  const char * end() const ;
100  ///< Returns the payload end iterator.
101 
102  size_t offset() const ;
103  ///< Returns the payload offset.
104 
105  size_t size() const ;
106  ///< Returns the payload size.
107 
108  const unsigned char * ubegin() const ;
109  ///< Returns the payload begin iterator.
110 
111  const unsigned char * uend() const ;
112  ///< Returns the payload end iterator.
113 
114 private:
115  RtpPacket( const RtpPacket & ) ;
116  void operator=( const RtpPacket & ) ;
117  static unsigned int make_word( const unsigned char * p ) ;
118  static unsigned long make_dword( const unsigned char * p ) ;
119 
120 private:
121  const unsigned char * m_p ;
122  size_t m_n ;
123  unsigned int m_version ;
124  bool m_padding ;
125  bool m_extension ;
126  unsigned int m_cc ;
127  bool m_marker ;
128  unsigned int m_pt ;
129  unsigned int m_seq ;
130  unsigned long m_timestamp ;
131  unsigned long m_src_id ;
132  unsigned int m_ehl ;
133  unsigned int m_padsize ;
134  size_t m_header_size ;
135  size_t m_payload_size ;
136  std::string m_reason ;
137 } ;
138 
139 #endif
const char * end() const
Returns the payload end iterator.
bool valid() const
Returns true if a valid packet.
Definition: gvrtppacket.cpp:62
bool typeJpeg() const
Returns true if the payload type is 26.
static size_t smallest()
Returns the smallest valid packet size.
Definition: gvrtppacket.cpp:57
std::string str() const
Returns a one-line summary of header fields.
Definition: gvrtppacket.cpp:72
size_t size() const
Returns the payload size.
std::string hexdump() const
Returns a complete hex dump.
Definition: gvrtppacket.cpp:86
const char * begin() const
Returns the payload begin iterator.
const unsigned char * ubegin() const
Returns the payload begin iterator.
An RTP packet parser, as per RFC 3550 (section 5).
Definition: gvrtppacket.h:44
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.
Definition: gvrtppacket.cpp:30
size_t offset() const
Returns the payload offset.
unsigned int seq() const
Returns the sequence number.
Definition: gvrtppacket.cpp:98
bool marker() const
Returns the marker bit.
Definition: gvrtppacket.cpp:93
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.
Definition: gvrtppacket.cpp:67