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.
24 #define HH_RTPPacket_ 1
28 #include "ParseInt.hh"
29 #include "ParseArray.hh"
30 #include "ParseVec.hh"
31 #include "PacketRegistry.hh"
33 //#include "RTPPacket.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
39 template <class Iterator=nil, class IPacket=nil>
40 struct Parse_RTP : public ParserBase<Iterator,IPacket>
42 template <class I, class P=nil>
43 struct rebind { typedef Parse_RTP<I,P> parser; };
44 typedef Iterator byte_iterator;
47 Parse_RTP(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
49 ///////////////////////////////////////////////////////////////////////////
51 typedef Parse_UIntField < 0, 2, Iterator > Parse_Version;
52 typedef Parse_Flag < 2, Iterator > Parse_P;
53 typedef Parse_Flag < 3, Iterator > Parse_X;
54 typedef Parse_UIntField < 4, 8, Iterator > Parse_CC;
55 typedef Parse_Flag < 0, Iterator > Parse_M;
56 typedef Parse_UIntField < 1, 8, Iterator > Parse_PT;
57 typedef Parse_UInt16 < Iterator > Parse_Seq;
58 typedef Parse_UInt32 < Iterator > Parse_32bit;
59 typedef Parse_Vector < Parse_32bit, Parse_CC, Iterator > Parse_CCVec;
61 Parse_Version version() const { return Parse_Version (this->i() ); }
62 Parse_P padding() const { return Parse_P (this->i() ); }
63 Parse_X extension() const { return Parse_X (this->i() ); }
64 Parse_CC csrcCount() const { return Parse_CC (this->i() ); }
65 Parse_M marker() const { return Parse_M (this->i() + 1 ); }
66 Parse_PT payloadType() const { return Parse_PT (this->i() + 1 ); }
67 Parse_Seq seqNumber() const { return Parse_Seq (this->i() + 2 ); }
68 Parse_32bit timestamp() const { return Parse_32bit (this->i() + 4 ); }
69 Parse_32bit ssrc() const { return Parse_32bit (this->i() + 8 ); }
70 Parse_CCVec csrcList() const { return Parse_CCVec (csrcCount(), this->i() + 12 ); }
74 ///////////////////////////////////////////////////////////////////////////
76 unsigned int bytes() const { return 12 + ( 4 * csrcCount()); }
77 static bool check(Iterator const & b, Iterator const & e)
78 { return e-b>= 12 and unsigned(e-b) >= Parse_RTP<Iterator>(b).bytes(); }
83 typedef boost::uint16_t key_t;
88 public Parse_RTP<Packet::iterator, RTPPacket>,
89 public PacketRegistryMixin<RTPTypes,RTPPacket>
91 using Packet::registerInterpreter;
92 using PacketRegistryMixin<RTPTypes,RTPPacket>::registerInterpreter;
94 ///////////////////////////////////////////////////////////////////////////
97 typedef ptr_t<RTPPacket>::ptr ptr;
99 ///////////////////////////////////////////////////////////////////////////
101 typedef Parse_UInt8 < Packet::iterator > Parse_paddingOctet;
103 Parse_paddingOctet paddingOctet() const {
104 return Parse_paddingOctet( end() -1 );
109 RTPPacket(Arg const & arg);
111 virtual void v_nextInterpreter() const;
112 virtual void v_finalize();
113 virtual void v_dump(std::ostream & os) const;
120 template <class Iterator=nil, class IPacket=nil>
121 struct Parse_RTPExtensionBase : public ParserBase<Iterator,IPacket>
123 template <class I, class P=nil>
124 struct rebind { typedef Parse_RTPExtensionBase<I,P> parser; };
125 typedef Iterator byte_iterator;
127 Parse_RTPExtensionBase() {}
128 Parse_RTPExtensionBase(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
130 ///////////////////////////////////////////////////////////////////////////
132 typedef Parse_UInt16 < Iterator > Parse_16bit;
134 Parse_16bit proDef() const { return Parse_16bit(this->i()); };
135 Parse_16bit length() const { return Parse_16bit(this->i()+2); };
137 unsigned int bytes() const { return 4 + length(); }
138 static bool check(Iterator const & b, Iterator const & e)
139 { return e-b>=4 && unsigned(e-b) >= Parse_RTPExtensionBase<Iterator>(b).bytes(); }
144 class RTPExtensionBasePacket
146 public PacketRegistryMixin<RTPTypes, RTPExtensionBasePacket>
148 using PacketRegistryMixin<RTPTypes,RTPExtensionBasePacket>::registerInterpreter;
149 using Packet::registerInterpreter;
151 ///////////////////////////////////////////////////////////////////////////
152 typedef ptr_t<RTPExtensionBasePacket>::ptr ptr;
156 RTPExtensionBasePacket(Arg const & arg);
159 virtual void v_nextInterpreter() const;
160 virtual void v_finalize() = 0;
161 virtual void v_dump(std::ostream & os) const;
168 template <class Iterator=nil, class IPacket=nil>
169 struct Parse_RTPUnknownExtension : public Parse_RTPExtensionBase<Iterator,IPacket>
171 template <class I, class P=nil>
172 struct rebind { typedef Parse_RTPUnknownExtension<I,P> parser; };
173 typedef Iterator byte_iterator;
175 Parse_RTPUnknownExtension() {}
176 Parse_RTPUnknownExtension(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
178 ///////////////////////////////////////////////////////////////////////////
180 typedef Parse_UInt16 < Iterator > Parse_16bit;
181 typedef Parse_UInt8 < Iterator > Parse_8bit;
182 typedef Parse_Vector < Parse_8bit, Parse_16bit, Iterator > Parse_ext;
184 Parse_ext ext() const { return Parse_ext (this->length(), this->i() + 4 ); }
188 class RTPUnknownExtensionPacket
189 : public RTPExtensionBasePacket,
190 public Parse_RTPUnknownExtension<Packet::iterator, RTPUnknownExtensionPacket>
193 ///////////////////////////////////////////////////////////////////////////
196 typedef ptr_t<RTPUnknownExtensionPacket>::ptr ptr;
198 ///////////////////////////////////////////////////////////////////////////
202 RTPUnknownExtensionPacket(Arg const & arg);
204 //virtual void v_nextInterpreter() const;
205 virtual void v_finalize();
207 friend class RTPExtensionBasePacket;
214 ///////////////////////////////hh.e////////////////////////////////////////
215 //#include RTPPacket.cci"
216 //#include "RTPPacket.ct"
217 #include "RTPPacket.cti"
224 // c-file-style: "senf"
225 // indent-tabs-mode: nil
226 // ispell-local-dictionary: "american"