VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvrtpjpegpacket.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 gvrtpjpegpacket.h
19 ///
20 
21 #ifndef GV_RTPJPEGPACKET__H
22 #define GV_RTPJPEGPACKET__H
23 
24 #include "gdef.h"
25 #include <string>
26 #include <vector>
27 
28 namespace Gv
29 {
30  class RtpJpegPacket ;
31 }
32 
33 /// \class Gv::RtpJpegPacket
34 /// An RTP payload parser for the jpeg payload type.
35 /// \see RFC 2435
36 ///
38 {
39 public:
40  struct Payload /// A descriptor for the payload within an RTP JPEG packet.
41  {
42  unsigned int offset ;
43  size_t size ;
44  const char * begin ;
45  const char * end ;
46  } ;
47 
48  static size_t smallest() ;
49  ///< The smallest parsable packet.
50 
51  RtpJpegPacket( const char * begin , const char * end ) ;
52  ///< Constructor taking in an RTP payload with Payload Type of
53  ///< JPEG/90000. The data should start with the RTP JPEG header defined
54  ///< in RFC-2435 section 3.1 and end with the JPEG entropy-coded
55  ///< scan data (see section 3.1.9).
56  ///< Precondition: (end-begin) >= smallest().
57 
58  bool valid() const ;
59  ///< Returns true if a valid packet.
60 
61  std::string reason() const ;
62  ///< Returns the reason if in-valid().
63 
64  std::string str() const ;
65  ///< Returns a summary of the packet header for debugging purposes.
66 
67  ///< header...
68 
69  unsigned int ts() const ;
70  ///< Returns the "type-specific" value.
71 
72  unsigned long fo() const ;
73  ///< Returns the fragment offset.
74 
75  unsigned int type() const ;
76  ///< Returns the type.
77 
78  bool type_is_dynamic() const ;
79  ///< Returns true if type() indicates that the type is defined
80  ///< out-of-band by the session setup process.
81 
82  bool type_has_restart_markers() const ;
83  ///< Returns true if type() indicates the presence of a restart marker header.
84 
85  unsigned int type_base() const ;
86  ///< Returns type() with the special bit reset.
87 
88  unsigned int q() const ;
89  ///< Returns the Q value. Values of 128 or more indicate that
90  ///< the packet holds in-band quantisation tables.
91 
92  bool q_is_special() const ;
93  ///< Returns true if q() indicates in-band quantisation tables.
94 
95  unsigned int dx() const ;
96  ///< Returns the image width in pixels, not MCUs, ie. including the x8.
97 
98  unsigned int dy() const ;
99  ///< Returns the image height in pixels, not MCUs, ie. including the x8.
100 
101  unsigned int ri() const ;
102  ///< Returns the restart interval (JFIF DRI).
103 
104  unsigned int rc() const ;
105  ///< Returns the restart count.
106 
107  Payload payload() const ;
108  ///< Returns the JPEG entropy-coded image scan data, using pointers into
109  ///< the buffer that was passed in to the constructor.
110  ///<
111  ///< Use generateHeader() to create a fully-fledged JFIF structure that can be
112  ///< passed to Gr::JpegReader.
113 
114  typedef std::insert_iterator<std::vector<char> > iterator_t ;
115 
116  static iterator_t generateHeader( iterator_t out , const RtpJpegPacket & , int fudge = 0 ) ;
117  ///< Generates the start of a JFIF buffer; the rest of the JFIF buffer is a
118  ///< simple copy of all the payloads that make up the frame. The JFIF output
119  ///< is emited via a vector back-insert iterator and the iterator's final
120  ///< value is retured.
121 
122  unsigned int payloadOffset() const ;
123  ///< Returns payload().offset.
124 
125  size_t payloadSize() const ;
126  ///< Returns payload().size.
127 
128  const char * payloadBegin() const ;
129  ///< Returns payload().begin.
130 
131  const char * payloadEnd() const ;
132  ///< Returns payload().end.
133 
134 private:
135  RtpJpegPacket( const RtpJpegPacket & ) ;
136  void operator=( const RtpJpegPacket & ) ;
137  static unsigned int make_word( const char * p ) ;
138  static unsigned long make_dword( unsigned long , unsigned long , unsigned long , unsigned long ) ;
139 
140 private:
141  std::string m_reason ;
142  const char * m_p ;
143  size_t m_n ;
144 } ;
145 
146 #endif
std::string reason() const
Returns the reason if in-valid().
unsigned int dx() const
Returns the image width in pixels, not MCUs, ie. including the x8.
An RTP payload parser for the jpeg payload type.
unsigned long fo() const
Returns the fragment offset.
unsigned int type_base() const
Returns type() with the special bit reset.
bool type_has_restart_markers() const
Returns true if type() indicates the presence of a restart marker header.
unsigned int payloadOffset() const
Returns payload().offset.
unsigned int ts() const
Returns the "type-specific" value.
bool q_is_special() const
Returns true if q() indicates in-band quantisation tables.
std::string str() const
Returns a summary of the packet header for debugging purposes.
static iterator_t generateHeader(iterator_t out, const RtpJpegPacket &, int fudge=0)
Generates the start of a JFIF buffer; the rest of the JFIF buffer is a simple copy of all the payload...
A descriptor for the payload within an RTP JPEG packet.
unsigned int ri() const
Returns the restart interval (JFIF DRI).
bool type_is_dynamic() const
Returns true if type() indicates that the type is defined out-of-band by the session setup process...
RtpJpegPacket(const char *begin, const char *end)
Constructor taking in an RTP payload with Payload Type of JPEG/90000.
static size_t smallest()
The smallest parsable packet.
const char * payloadBegin() const
Returns payload().begin.
bool valid() const
Returns true if a valid packet.
const char * payloadEnd() const
Returns payload().end.
unsigned int q() const
Returns the Q value.
Payload payload() const
Returns the JPEG entropy-coded image scan data, using pointers into the buffer that was passed in to ...
unsigned int rc() const
Returns the restart count.
size_t payloadSize() const
Returns payload().size.
unsigned int dy() const
Returns the image height in pixels, not MCUs, ie. including the x8.
unsigned int type() const
Returns the type.