hopefully this commit will not break other things....
tho [Fri, 11 Apr 2008 08:42:11 +0000 (08:42 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@803 270642c3-0616-0410-b53a-bc976706d245

Packets/MPEGDVBBundle/TransportPacket.cc
Packets/MPEGDVBBundle/TransportPacket.hh
Packets/MPEGDVBBundle/TransportPacket.test.cc

index bb065ea..15fef02 100644 (file)
@@ -28,6 +28,7 @@
 
 // Custom includes
 #include <iomanip>
+#include <boost/io/ios_state.hpp>
 
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
@@ -40,9 +41,23 @@ prefix_ void senf::TransportPacketParser::init_fields()
     transport_scrmbl_ctrl() = 0;
     adaptation_field_ctrl() = 0x1u;
 }
+
+prefix_ senf::UInt8Parser senf::TransportPacketParser::pointer_field()
+    const
+{
+    return pointer_field_().get<1>(); 
+}
+
+prefix_ void senf::TransportPacketParser::setPUSI(bool pusi)
+    const
+{
+    if (pusi) pointer_field_().init<1>();
+    else      pointer_field_().init<0>();
+}
             
 prefix_ void senf::TransportPacketType::dump(packet p, std::ostream & os)
 {
+    boost::io::ios_all_saver ias(os);
     os << "TransportPacket:\n"
        << std::hex
        << "  syncByte: 0x" << unsigned(p->sync_byte()) << "\n"
@@ -55,8 +70,8 @@ prefix_ void senf::TransportPacketType::dump(packet p, std::ostream & os)
        << "  transport_scrambling_control: 0x" << unsigned(p->transport_scrmbl_ctrl()) << "\n"
        << "  adaptation_field_control: 0x" << unsigned(p->adaptation_field_ctrl()) << "\n"
        << "  continuity_counter: 0x" << unsigned(p->continuity_counter()) << "\n";
-//    if (p->pusi())
-//        os << "  payload_pointer: 0x" << unsigned(p->payload_pointer()) << "\n";
+    if (p->pusi())
+        os << "  pointer_field: 0x" << unsigned(p->pointer_field()) << "\n";
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////
index 2bf00b3..5ff4889 100644 (file)
@@ -27,7 +27,6 @@
 #define HH_TransportPacket_ 1
 
 // Custom includes
-#include <algorithm>
 #include "../../Packets/Packets.hh"
 
 //#include "TransportPacket.mpp"
 
 namespace senf {
 
+//    struct PSIPayloadPacketParser : public PacketParserBase
+//    {
+//        static const size_type fixed_bytes = 184;
+//
+//    };
+
+
     /** \brief Parse a Transport Stream packet
 
         Parser implementing the header of a MPEG Transport Stream packet.
@@ -43,29 +49,31 @@ namespace senf {
      */
     struct TransportPacketParser : public PacketParserBase
     {
-#       include SENF_FIXED_PARSER()
+#       include SENF_PARSER()
 
-        SENF_PARSER_FIELD    ( sync_byte,                  UInt8Parser  );
+        SENF_PARSER_FIELD       ( sync_byte,                  UInt8Parser );
 
-        SENF_PARSER_BITFIELD ( transport_error_indicator,   1, bool     );
-        SENF_PARSER_BITFIELD ( pusi,                        1, bool     );
-        SENF_PARSER_BITFIELD ( transport_priority,          1, bool     );
-        SENF_PARSER_BITFIELD ( pid,                        13, unsigned );
-        SENF_PARSER_BITFIELD ( transport_scrmbl_ctrl,       2, unsigned );
-        SENF_PARSER_BITFIELD ( adaptation_field_ctrl,       2, unsigned );
-        SENF_PARSER_BITFIELD ( continuity_counter,          4, unsigned );
+        SENF_PARSER_BITFIELD    ( transport_error_indicator,  1, bool     );
+        SENF_PARSER_BITFIELD_RO ( pusi,                       1, bool     );
+        SENF_PARSER_BITFIELD    ( transport_priority,         1, bool     );
+        SENF_PARSER_BITFIELD    ( pid,                       13, unsigned );
+        SENF_PARSER_BITFIELD    ( transport_scrmbl_ctrl,      2, unsigned );
+        SENF_PARSER_BITFIELD    ( adaptation_field_ctrl,      2, unsigned );
+        SENF_PARSER_BITFIELD    ( continuity_counter,         4, unsigned );
 
+        SENF_PARSER_PRIVATE_VARIANT ( pointer_field_, pusi,
+                (senf::VoidPacketParser) (UInt8Parser) );
+        
         SENF_PARSER_FINALIZE( TransportPacketParser );
         
+        UInt8Parser pointer_field() const;
         void init_fields() const;
+        void setPUSI(bool pusi) const;
+
         SENF_PARSER_INIT() {
             defaultInit();
             init_fields();
         }
-    
-//        UInt8Parser payload_pointer() const {
-//            return parse<UInt8Parser>( TransportPacketParser::fixed_bytes ); 
-//        }
     };
     
     /** \brief Transport Stream packet
index 0fee6b2..7879ff0 100644 (file)
 
 #include "../../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
+#include <senf/Utils/hexdump.hh>
 
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
 using namespace senf;
 
-BOOST_AUTO_UNIT_TEST(transportPacket_packet)
+BOOST_AUTO_UNIT_TEST(transportPacket_parse)
 {
     // TransportStream-Packet containing a ULE encoded IPv6 ping packet,
     // captured with dvbsnoop
     unsigned char data[] = { 
-            0x47, 0x41, 0x0f, 0x1e, 0x00, 0x80, 0x4c, 0x86,
-            0xdd, 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 
-            0x40, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
-            0x00, 0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68,
-            0xaf, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
-            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
-            0x04 ,0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58,
-            0xe1, 0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01,
-            0x00, 0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10,
-            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,
-            0x00, 0x1d, 0xc4, 0xe8, 0xc1, 0xff, 0xff, 0xff,
+            // Transport Packet Header
+            0x47, 0x41, 0x0f, 0x1e, 
+            // Payload Pointer
+            0x00, 
+            // SNDU Header
+            0x80, 0x4c, 0x86, 0xdd,
+            // IPv6 Packet
+            0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
+            0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
+            0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
+            0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
+            0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
+            0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
+            // SNDU footer (crc-32)
+            0x1d, 0xc4, 0xe8, 0xc1, 
+            // Transport Packet stuffing
             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -64,10 +73,10 @@ BOOST_AUTO_UNIT_TEST(transportPacket_packet)
             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
-            0xff, 0xff, 0xff, 0xff
+            0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
     };
             
-    senf::TransportPacket p (senf::TransportPacket::create(data));
+    TransportPacket p (TransportPacket::create(data));
 
     BOOST_CHECK_EQUAL(   p->sync_byte(),                TransportPacketType::SYNC_BYTE+0 );
     BOOST_CHECK(       ! p->transport_error_indicator()                                  );
@@ -77,6 +86,38 @@ BOOST_AUTO_UNIT_TEST(transportPacket_packet)
     BOOST_CHECK_EQUAL(   p->transport_scrmbl_ctrl(),    0x0u                             );
     BOOST_CHECK_EQUAL(   p->adaptation_field_ctrl(),    0x1u                             );
     BOOST_CHECK_EQUAL(   p->continuity_counter(),       0x0eu                            );
+    BOOST_CHECK_EQUAL(   p->pointer_field(),          0x0u                             );
+}
+
+
+BOOST_AUTO_UNIT_TEST(transportPacket_create_with_pusi)
+{
+    TransportPacket ts_packet (TransportPacket::create());
+    ts_packet->setPUSI(true);
+    ts_packet->pid() = 0x010fu;
+    ts_packet->continuity_counter() = 0x0eu;
+    
+    unsigned char payload_data[] = {  // see test above 
+            // SNDU Header
+            0x80, 0x4c, 0x86, 0xdd,
+            // IPv6 Packet
+            0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
+            0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
+            0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
+            0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
+            0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
+            0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
+            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
+            // SNDU footer (crc-32)
+            0x1d, 0xc4, 0xe8, 0xc1
+    };
+    senf::DataPacket payload (senf::DataPacket::createAfter( ts_packet, payload_data));
+    
+    //TransportPacketType::addStuffingPacketAfter( ts_packet);
+    
+    //senf::hexdump(ts_packet.data().begin(), ts_packet.data().end(), std::cout);
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////