Added RTPPacket Parser to DefaultBundle
pug [Wed, 6 Aug 2008 15:05:01 +0000 (15:05 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@895 270642c3-0616-0410-b53a-bc976706d245

Packets/DefaultBundle/RTPPacket.cc [new file with mode: 0644]
Packets/DefaultBundle/RTPPacket.hh [new file with mode: 0644]
Packets/DefaultBundle/RTPPacket.test.cc [new file with mode: 0644]

diff --git a/Packets/DefaultBundle/RTPPacket.cc b/Packets/DefaultBundle/RTPPacket.cc
new file mode 100644 (file)
index 0000000..a09a89f
--- /dev/null
@@ -0,0 +1,79 @@
+// $Id: main.test.cc 206 2008-08-06 14:20:52Z pug $
+//
+// Copyright (C) 2006
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+// Definition of non-inline non-template functions
+
+// Custom includes
+#include "RTPPacket.hh"
+#include "../../Packets/Packets.hh"
+#include "../../Scheduler/ClockService.hh"
+#include <boost/io/ios_state.hpp>
+
+
+#define prefix_
+
+namespace 
+{
+    std::string ptName(int pt){
+        struct pt_item
+        {
+            int pt;
+            std::string name;
+        };
+        static pt_item ptList[27] = {
+            {0,"PCMU"},{1,"1016"},{2,"G721"},{3,"GSM"},
+            {5,"DVI8"},{6,"DVI16"},{7,"LPC"},{8,"PCMA"},
+            {9,"G722"},{10,"L16"},{11,"L16S"},{14,"MPA"},
+            {25,"CELB"},{26,"JPEG"},{31,"H261"},{32,"MPV"},
+            {33,"MP2T"},{34,"263"},{110,"MPEG AAC"},{111,"11L16"},
+            {112,"11L16S"},{113,"22L16"},{114,"22L16S"},{115,"32L16"},
+            {116,"32L16S"},{127,"HTML"},{-1,""}
+        };
+        int n = 0;
+        while ( ptList[n].pt != -1)
+        {
+            if( ptList[n].pt == pt)
+                return ptList[n].name;
+            ++n;
+        }
+        
+        return "UNKNOWN";
+    }
+}
+
+prefix_ void senf::RTPPacketType::dump(packet p, std::ostream &os)
+{
+    boost::io::ios_all_saver ias(os);
+    os << "Real Time Protocol:\n"
+       << "  Version                            : " << p->version() << "\n"
+       << "  Padding                            : " << p->padding() << "\n"
+       << "  Extension                          : " << p->extension() << "\n"
+       << "  Contributing Source Count(CC)      : " << p->csrcCount() << "\n"
+       << "  Marker                             : " << p->marker() << "\n"
+       << "  Payload Type                       : " << p->payloadType() << " "<< ptName(p->payloadType() ) <<"\n"
+       << "  Sequence number                    : " << p->seqNumber() << "\n"
+       << "  Timestamp                          : " << p->timeStamp() << "\n"
+       << "  Synchronisation Source Identifier  : " << p->synSourceId() << "\n";
+
+}
+
+#undef prefix_
diff --git a/Packets/DefaultBundle/RTPPacket.hh b/Packets/DefaultBundle/RTPPacket.hh
new file mode 100644 (file)
index 0000000..cd17bc3
--- /dev/null
@@ -0,0 +1,73 @@
+// $Id: main.test.cc 206 2008-08-06 14:20:52Z pug $
+//
+// Copyright (C) 2006
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+// Definition of non-inline non-template functions
+
+// Custom includes
+#ifndef RTPPACKET_HH_
+#define RTPPACKET_HH_
+
+#include "../../Packets/Packets.hh"
+#include "../../Socket/Protocols/INet/INet6Address.hh"
+#include "../../Socket/Protocols/INet.hh"
+
+namespace senf {
+    
+    struct RTPPacketParser : public senf::PacketParserBase
+    {
+    SENF_LOG_CLASS_AREA();
+    #   include SENF_PARSER()
+        SENF_PARSER_BITFIELD  ( version,        2, unsigned     );      //Version (RFC 3550)
+        SENF_PARSER_BITFIELD  ( padding,        1, bool         );      //1 if padding behind payload
+        SENF_PARSER_BITFIELD  ( extension,      1, bool         );
+        SENF_PARSER_BITFIELD_RO  ( csrcCount,      4, unsigned     );   //0-15,define the number of contributing sources
+        SENF_PARSER_BITFIELD  ( marker,         1, bool         );      //Marker M=1, used to signal speech silent compression; further use in combination with PT to be defined
+        SENF_PARSER_BITFIELD  ( payloadType,    7, unsigned     );      //Payload Type; e.g. PCM=8 (RFC 3550)
+        SENF_PARSER_FIELD     ( seqNumber,      senf::UInt16Parser );   //random number to identify initial segment of  a stream, increment by 1 used to resequence segments at receiver
+        SENF_PARSER_FIELD     ( timeStamp,      senf::UInt32Parser );   //signals sampling time of 1st byte of payload; initialised; used to calculate Jitter between segments
+        SENF_PARSER_FIELD     ( synSourceId,    senf::UInt32Parser );   //Synchronisation source identifier; identifier of RFTP stream source (random number) in case of conferencing identifier of mixer
+        SENF_PARSER_VECTOR    (csrcOpt, csrcCount, senf::UInt32Parser );
+        
+        bool valid() const {return version() == 2;}
+        SENF_PARSER_FINALIZE(RTPPacketParser);
+    };
+    
+    struct RTPPacketType 
+        : public senf::PacketTypeBase,
+        public senf::PacketTypeMixin<RTPPacketType>
+    {
+    SENF_LOG_CLASS_AREA();
+        typedef senf::PacketTypeMixin<RTPPacketType> mixin;
+        typedef senf::ConcretePacket<RTPPacketType> packet;
+        typedef RTPPacketParser parser;
+    
+        using mixin::nextPacketRange;
+        using mixin::init;
+        using mixin::initSize;
+    
+        static void dump(packet p, std::ostream &os);
+    };
+    
+    typedef RTPPacketType::packet RTPPacket;
+
+}
+#endif
diff --git a/Packets/DefaultBundle/RTPPacket.test.cc b/Packets/DefaultBundle/RTPPacket.test.cc
new file mode 100644 (file)
index 0000000..8a8446f
--- /dev/null
@@ -0,0 +1,46 @@
+// $Id: main.test.cc 206 2008-08-06 14:20:52Z pug $
+//
+// Copyright (C) 2006
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+//     Stefan Bund <g0dil@berlios.de>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the
+// Free Software Foundation, Inc.,
+// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+// Definition of non-inline non-template functions
+
+// Custom includes
+
+#include "../../Packets/Packets.hh"
+#include "../../Utils/auto_unit_test.hh"
+#include <boost/test/test_tools.hpp>
+#include "RTPPacket.hh"
+BOOST_AUTO_UNIT_TEST(RTPPacket_packet)
+{
+    unsigned char data[] = {0x80 , 0x08 , 0x1b , 0xbb , 0x02 , 0xcb , 0xad , 0x80 , 0x50 , 0x48 , 0xa7, 0x8c };
+
+    senf::RTPPacket p (senf::RTPPacket::create(data));
+
+    BOOST_CHECK_EQUAL( p->version(), 2u);
+    BOOST_CHECK_EQUAL( p->padding(), false);
+    BOOST_CHECK_EQUAL( p->extension(), false);
+    BOOST_CHECK_EQUAL( p->csrcCount(), 0u);
+    BOOST_CHECK_EQUAL( p->marker(), false);
+    BOOST_CHECK_EQUAL( p->payloadType(), 8u);
+    BOOST_CHECK_EQUAL( p->seqNumber(), 0x1bbbu);
+    BOOST_CHECK_EQUAL( p->timeStamp(), 0x2cbad80u);
+    BOOST_CHECK_EQUAL( p->synSourceId(), 0x5048a78cu);
+}