Fixed whitespace in all files (no tabs)
[senf.git] / Packets / RTCPPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
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
12 //
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.
17 //
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.
22
23 #ifndef HH_RTCPPacket_
24 #define HH_RTCPPacket_ 1
25
26 // Custom includes
27 #include "Packet.hh"
28 #include "ParseInt.hh"
29 #include "ParseArray.hh"
30 #include "ParseListS.hh"
31 #include "ParseVec.hh"
32 #include "PacketRegistry.hh"
33
34 //#include "RTCPPacket.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39
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;
45
46
47     template <class Iterator=nil, class IPacket=nil>
48     struct Parse_RTCP : public ParserBase<Iterator,IPacket>
49     {
50         template <class I, class P=nil>
51         struct rebind { typedef Parse_RTCP<I,P> parser; };
52         typedef Iterator byte_iterator;
53
54         Parse_RTCP() {}
55         Parse_RTCP(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
56
57         ///////////////////////////////////////////////////////////////////////////
58
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;
64
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;
70
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  ); }
76
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()  ); }
82
83         ///////////////////////////////////////////////////////////////////////////
84
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(); }
88
89     };
90
91     template <class Iterator=nil, class IPacket=nil>
92     struct Parse_RTCP_RB : public ParserBase<Iterator,IPacket>
93     {
94         template <class I, class P=nil>
95         struct rebind { typedef Parse_RTCP_RB<I,P> parser; };
96         typedef Iterator byte_iterator;
97
98         Parse_RTCP_RB() {}
99         Parse_RTCP_RB(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
100
101         ///////////////////////////////////////////////////////////////////////////
102
103         typedef Parse_UInt32        < Iterator >                    Parse_32bit;
104         typedef Parse_UInt8         < Iterator >                    Parse_8bit;
105         typedef Parse_Array         < 3, Parse_UInt8<>, Iterator >  Parse_24bit;
106
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); }
113
114         ///////////////////////////////////////////////////////////////////////////
115
116         static unsigned int bytes()  { return 20; }
117
118     };
119
120     template <class Iterator, class IPacket>
121     struct Parse_RTCP_RR : public Parse_RTCP<Iterator, IPacket>
122     {
123         template <class I, class P=nil>
124         struct rebind { typedef Parse_RTCP_RR<I,P> parser; };
125         typedef Iterator byte_iterator;
126
127         Parse_RTCP_RR() {}
128         Parse_RTCP_RR(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
129
130         ///////////////////////////////////////////////////////////////////////////
131
132         typedef Parse_UInt32        < Iterator > Parse_32bit;
133         typedef Parse_Vector        < Parse_RTCP_RB<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator > Parse_rbVec;
134
135         Parse_32bit   ssrc()        const { return Parse_32bit(this->i()+ 4  ); }
136
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 ); }
142
143         Parse_rbVec   rbVec()      const { return Parse_rbVec(this->count(), this->i() + 28 ); }
144
145     };
146
147     template <class Iterator, class IPacket>
148     struct Parse_RTCP_SR : public Parse_RTCP<Iterator, IPacket>
149     {
150         template <class I, class P=nil>
151         struct rebind { typedef Parse_RTCP_SR<I,P> parser; };
152         typedef Iterator byte_iterator;
153
154         Parse_RTCP_SR() {}
155         Parse_RTCP_SR(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
156
157         ///////////////////////////////////////////////////////////////////////////
158
159         typedef Parse_UInt32        < Iterator > Parse_32bit;
160         typedef Parse_Vector        < Parse_RTCP_RB<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator > Parse_rbVec;
161
162         Parse_32bit   ssrc()        const { return Parse_32bit(this->i()+ 4  ); }
163         Parse_rbVec   rbVec()      const { return Parse_rbVec(this->count(), this->i() + 8 ); }
164
165     };
166
167     template  <class Iterator=nil, class IPacket=nil>
168     struct Parse_RTCP_item : public Parse_RTCP<Iterator,IPacket>
169     {
170         template <class I, class P=nil>
171         struct rebind { typedef Parse_RTCP_item<I,P> parser; };
172         typedef Iterator byte_iterator;
173
174         Parse_RTCP_item() {}
175         Parse_RTCP_item(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
176
177
178         ///////////////////////////////////////////////////////////////////////////
179
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;
183
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 ); }
187
188
189
190     };
191
192     template <class List>
193     struct Sentinel_EmptyList {
194         static bool check(List a) { return a.empty(); }
195     };
196
197     template  <class Iterator=nil, class IPacket=nil>
198     struct Parse_RTCP_chunk : public Parse_RTCP<Iterator, IPacket>
199     {
200         template <class I, class P=nil>
201         struct rebind { typedef Parse_RTCP_chunk<I,P> parser; };
202         typedef Iterator byte_iterator;
203
204         Parse_RTCP_chunk() {}
205         Parse_RTCP_chunk(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
206
207         ///////////////////////////////////////////////////////////////////////////
208
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;
212
213         Parse_32bit    ssrc()      const { return Parse_32bit(this->i() ); }
214         Parse_itemList itemList()  const { return Parse_itemList(this->i() + 4 ); }
215
216     };
217
218
219     template <class Iterator, class IPacket>
220     struct Parse_RTCP_SDES : public Parse_RTCP<Iterator, IPacket>
221     {
222         template <class I, class P=nil>
223         struct rebind { typedef Parse_RTCP_SDES<I,P> parser; };
224         typedef Iterator byte_iterator;
225
226         Parse_RTCP_SDES() {}
227         Parse_RTCP_SDES(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
228
229         ///////////////////////////////////////////////////////////////////////////
230
231         typedef Parse_Vector     < Parse_RTCP_chunk<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator > Parse_chunkVec;
232
233         Parse_chunkVec   chunkVec()       const { return Parse_chunkVec(this->count(), this->i()+4 ); }
234
235     };
236
237     template <class Iterator, class IPacket>
238     struct Parse_RTCP_BYE : public Parse_RTCP<Iterator,IPacket>
239     {
240         template <class I, class P=nil>
241         struct rebind { typedef Parse_RTCP_BYE<I,P> parser; };
242         typedef Iterator byte_iterator;
243
244         Parse_RTCP_BYE() {}
245         Parse_RTCP_BYE(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
246
247         ///////////////////////////////////////////////////////////////////////////
248
249         typedef Parse_Vector        < Parse_UInt32<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Count, Iterator >  Parse_ssrcVec;
250
251         Parse_ssrcVec ssrcVec()      const { return Parse_ssrcVec(this->count(), this->i()+4 ); }
252
253     };
254
255
256     template <class Iterator, class IPacket>
257     struct Parse_RTCP_APP : public Parse_RTCP<Iterator,IPacket>
258     {
259         template <class I, class P=nil>
260         struct rebind { typedef Parse_RTCP_APP<I,P> parser; };
261         typedef Iterator byte_iterator;
262
263         Parse_RTCP_APP() {}
264         Parse_RTCP_APP(Iterator const & i) : Parse_RTCP<Iterator,IPacket>(i) {}
265
266
267         ///////////////////////////////////////////////////////////////////////////
268
269         typedef Parse_UInt32       < Iterator >       Parse_32bit;
270         typedef Parse_Vector       < Parse_UInt32<>, typename Parse_RTCP<Iterator,IPacket>::Parse_Length, Iterator >  Parse_dataVec;
271
272         Parse_32bit   ssrc()       const { return Parse_32bit(this->i()+4); }
273         Parse_32bit   name()       const { return Parse_32bit(this->i()+8); }
274 // this->length()-3
275         Parse_dataVec appData()    const { return Parse_dataVec(this->length(), this->i()+12 ); }
276
277     };
278
279
280     class RTCPPacket
281         : public Packet,
282           public Parse_RTCP<Packet::iterator, RTCPPacket>
283     {
284         using Packet::registerInterpreter;
285
286     public:
287         ///////////////////////////////////////////////////////////////////////////
288         // Types
289
290         typedef ptr_t<RTCPPacket>::ptr ptr;
291
292     private:
293         template <class Arg>
294         RTCPPacket(Arg const & arg);
295
296         virtual void v_nextInterpreter() const;
297         virtual void v_finalize();
298
299         friend class Packet;
300     };
301
302 }
303
304
305 ///////////////////////////////hh.e////////////////////////////////////////
306 //#include "RTCPPacket.cci"
307 //#include "RTCPPacket.ct"
308 #include "RTCPPacket.cti"
309 #endif
310
311 \f
312 // Local Variables:
313 // mode: c++
314 // fill-column: 100
315 // c-file-style: "senf"
316 // indent-tabs-mode: nil
317 // ispell-local-dictionary: "american"
318 // End: