4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.b
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #ifndef HH_RTCPPacket_
24 #define HH_RTCPPacket_ 1
28 #include "ParseInt.hh"
29 #include "ParseArray.hh"
30 #include "ParseListS.hh"
31 #include "ParseVec.hh"
32 #include "PacketRegistry.hh"
34 //#include "RTCPPacket.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
40 template <class I=nil,class P=nil> struct Parse_RTCP_RR;
41 template <class I=nil,class P=nil> struct Parse_RTCP_SR;
42 template <class I=nil,class P=nil> struct Parse_RTCP_SDES;
43 template <class I=nil,class P=nil> struct Parse_RTCP_BYE;
44 template <class I=nil,class P=nil> struct Parse_RTCP_APP;
47 template <class Iterator=nil, class IPacket=nil>
48 struct Parse_RTCP : public ParserBase<Iterator,IPacket>
50 template <class I, class P=nil>
51 struct rebind { typedef Parse_RTCP<I,P> parser; };
52 typedef Iterator byte_iterator;
55 Parse_RTCP(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
57 ///////////////////////////////////////////////////////////////////////////
59 typedef Parse_UIntField < 0, 2, Iterator > Parse_Version;
60 typedef Parse_Flag < 2, Iterator > Parse_P;
61 typedef Parse_UIntField < 3, 8, Iterator > Parse_Count;
62 typedef Parse_UInt8 < Iterator > Parse_PT;
63 typedef Parse_UInt16 < Iterator > Parse_Length;
65 typedef Parse_RTCP_RR < Iterator > Parse_RTCP_RR;
66 typedef Parse_RTCP_SR < Iterator > Parse_RTCP_SR;
67 typedef Parse_RTCP_SDES < Iterator > Parse_RTCP_SDES;
68 typedef Parse_RTCP_BYE < Iterator > Parse_RTCP_BYE;
69 typedef Parse_RTCP_APP < Iterator > Parse_RTCP_APP;
71 Parse_Version version() const { return Parse_Version (this->i() ); }
72 Parse_P padding() const { return Parse_P (this->i() ); }
73 Parse_Count count() const { return Parse_Count (this->i() ); }
74 Parse_PT payloadType() const { return Parse_PT (this->i() + 1 ); }
75 Parse_Length length() const { return Parse_Length (this->i() + 2 ); }
77 Parse_RTCP_RR rr() { return Parse_RTCP_RR (this->i() ); }
78 Parse_RTCP_SR sr() { return Parse_RTCP_SR (this->i() ); }
79 Parse_RTCP_SDES sdes() { return Parse_RTCP_SDES (this->i() ); }
80 Parse_RTCP_BYE bye() { return Parse_RTCP_BYE (this->i() ); }
81 Parse_RTCP_APP app() { return Parse_RTCP_APP (this->i() ); }
83 ///////////////////////////////////////////////////////////////////////////
85 unsigned int bytes() const { return 32 + (4 * length()); }
86 static bool check(Iterator const & b, Iterator const & e)
87 { return e-b >= 4 and unsigned(e-b) >= Parse_RTCP<Iterator>(b).bytes(); }
91 template <class Iterator=nil, class IPacket=nil>
92 struct Parse_RTCP_RB : public ParserBase<Iterator,IPacket>
94 template <class I, class P=nil>
95 struct rebind { typedef Parse_RTCP_RB<I,P> parser; };
96 typedef Iterator byte_iterator;
99 Parse_RTCP_RB(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
101 ///////////////////////////////////////////////////////////////////////////
103 typedef Parse_UInt32 < Iterator > Parse_32bit;
104 typedef Parse_UInt8 < Iterator > Parse_8bit;
105 typedef Parse_Array < 3, Parse_UInt8<>, Iterator > Parse_24bit;
107 Parse_32bit ssrc() const { return Parse_32bit(this->i() ); }
108 Parse_8bit fragLost() const { return Parse_8bit(this->i()+4 ); }
109 Parse_24bit cnpl() const { return Parse_24bit(this->i()+5 ); }
110 Parse_32bit ehsnr() const { return Parse_32bit(this->i()+8 ); }
111 Parse_32bit LSR() const { return Parse_32bit(this->i()+12); }
112 Parse_32bit DLSR() const { return Parse_32bit(this->i()+16); }
114 ///////////////////////////////////////////////////////////////////////////
116 static unsigned int bytes() { return 20; }
120 template <class Iterator, class IPacket>
121 struct Parse_RTCP_RR : public Parse_RTCP<Iterator, IPacket>
123 template <class I, class P=nil>
124 struct rebind { typedef Parse_RTCP_RR<I,P> parser; };
125 typedef Iterator byte_iterator;
128 Parse_RTCP_RR(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
130 ///////////////////////////////////////////////////////////////////////////
132 typedef Parse_UInt32 < Iterator > Parse_32bit;
133 typedef Parse_Vector < Parse_RTCP_RB<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator > Parse_rbVec;
135 Parse_32bit ssrc() const { return Parse_32bit(this->i()+ 4 ); }
137 Parse_32bit ntp_msb() const { return Parse_32bit(this->i()+ 8 ); }
138 Parse_32bit ntp_lsb() const { return Parse_32bit(this->i()+ 12 ); }
139 Parse_32bit timestamp() const { return Parse_32bit(this->i()+ 16 ); }
140 Parse_32bit spcount() const { return Parse_32bit(this->i()+ 20 ); }
141 Parse_32bit socount() const { return Parse_32bit(this->i()+ 24 ); }
143 Parse_rbVec rbVec() const { return Parse_rbVec(this->count(), this->i() + 28 ); }
147 template <class Iterator, class IPacket>
148 struct Parse_RTCP_SR : public Parse_RTCP<Iterator, IPacket>
150 template <class I, class P=nil>
151 struct rebind { typedef Parse_RTCP_SR<I,P> parser; };
152 typedef Iterator byte_iterator;
155 Parse_RTCP_SR(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
157 ///////////////////////////////////////////////////////////////////////////
159 typedef Parse_UInt32 < Iterator > Parse_32bit;
160 typedef Parse_Vector < Parse_RTCP_RB<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator > Parse_rbVec;
162 Parse_32bit ssrc() const { return Parse_32bit(this->i()+ 4 ); }
163 Parse_rbVec rbVec() const { return Parse_rbVec(this->count(), this->i() + 8 ); }
167 template <class Iterator=nil, class IPacket=nil>
168 struct Parse_RTCP_item : public Parse_RTCP<Iterator,IPacket>
170 template <class I, class P=nil>
171 struct rebind { typedef Parse_RTCP_item<I,P> parser; };
172 typedef Iterator byte_iterator;
175 Parse_RTCP_item(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
178 ///////////////////////////////////////////////////////////////////////////
180 typedef Parse_UInt8 < Iterator > Parse_8bit;
181 typedef Parse_UInt32 < Iterator > Parse_32bit;
182 typedef Parse_Vector < Parse_UInt8<>, Parse_UInt8<>, Iterator > Parse_desc;
184 Parse_8bit typeField() const { return Parse_8bit(this->i() ); }
185 Parse_8bit length() const { return Parse_8bit(this->i()+1 ); }
186 Parse_desc desc() const { return Parse_desc(this->length(), this->i()+2 ); }
192 template <class List>
193 struct Sentinel_EmptyList {
194 static bool check(List a) { return a.empty(); }
197 template <class Iterator=nil, class IPacket=nil>
198 struct Parse_RTCP_chunk : public Parse_RTCP<Iterator, IPacket>
200 template <class I, class P=nil>
201 struct rebind { typedef Parse_RTCP_chunk<I,P> parser; };
202 typedef Iterator byte_iterator;
204 Parse_RTCP_chunk() {}
205 Parse_RTCP_chunk(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
207 ///////////////////////////////////////////////////////////////////////////
209 typedef Parse_UInt32 < Iterator > Parse_32bit;
210 typedef Parse_UInt8 < Iterator > Parse_8bit;
211 typedef Parse_ListS < Parse_RTCP_item<>, Sentinel_EmptyList<Parse_RTCP_item<> >, Iterator, IPacket> Parse_itemList;
213 Parse_32bit ssrc() const { return Parse_32bit(this->i() ); }
214 Parse_itemList itemList() const { return Parse_itemList(this->i() + 4 ); }
219 template <class Iterator, class IPacket>
220 struct Parse_RTCP_SDES : public Parse_RTCP<Iterator, IPacket>
222 template <class I, class P=nil>
223 struct rebind { typedef Parse_RTCP_SDES<I,P> parser; };
224 typedef Iterator byte_iterator;
227 Parse_RTCP_SDES(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
229 ///////////////////////////////////////////////////////////////////////////
231 typedef Parse_Vector < Parse_RTCP_chunk<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator > Parse_chunkVec;
233 Parse_chunkVec chunkVec() const { return Parse_chunkVec(this->count(), this->i()+4 ); }
237 template <class Iterator, class IPacket>
238 struct Parse_RTCP_BYE : public Parse_RTCP<Iterator,IPacket>
240 template <class I, class P=nil>
241 struct rebind { typedef Parse_RTCP_BYE<I,P> parser; };
242 typedef Iterator byte_iterator;
245 Parse_RTCP_BYE(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
247 ///////////////////////////////////////////////////////////////////////////
249 typedef Parse_Vector < Parse_UInt32<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator > Parse_ssrcVec;
251 Parse_ssrcVec ssrcVec() const { return Parse_ssrcVec(this->count(), this->i()+4 ); }
256 template <class Iterator, class IPacket>
257 struct Parse_RTCP_APP : public Parse_RTCP<Iterator,IPacket>
259 template <class I, class P=nil>
260 struct rebind { typedef Parse_RTCP_APP<I,P> parser; };
261 typedef Iterator byte_iterator;
264 Parse_RTCP_APP(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
267 ///////////////////////////////////////////////////////////////////////////
269 typedef Parse_UInt32 < Iterator > Parse_32bit;
270 typedef Parse_Vector < Parse_UInt32<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Length, Iterator > Parse_dataVec;
272 Parse_32bit ssrc() const { return Parse_32bit(this->i()+4); }
273 Parse_32bit name() const { return Parse_32bit(this->i()+8); }
275 Parse_dataVec appData() const { return Parse_dataVec(this->length(), this->i()+12 ); }
282 public Parse_RTCP<Packet::iterator, RTCPPacket>
284 using Packet::registerInterpreter;
287 ///////////////////////////////////////////////////////////////////////////
290 typedef ptr_t<RTCPPacket>::ptr ptr;
294 RTCPPacket(Arg const & arg);
296 virtual void v_nextInterpreter() const;
297 virtual void v_finalize();
305 ///////////////////////////////hh.e////////////////////////////////////////
306 //#include "RTCPPacket.cci"
307 //#include "RTCPPacket.ct"
308 #include "RTCPPacket.cti"
314 // c-file-style: "satcom"