psi2ts: payload pointer handling still missing :(
tho [Tue, 25 Mar 2008 12:21:49 +0000 (12:21 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@761 270642c3-0616-0410-b53a-bc976706d245

Examples/psi2tsModule/psi2ts.cc
Examples/psi2tsModule/psi2ts.hh
Examples/psi2tsModule/psi2ts.test.cc

index 2ff2538..f8da4fb 100644 (file)
@@ -43,8 +43,9 @@ namespace {
 }
 
 
-prefix_ Psi2TsModule::Psi2TsModule()
+prefix_ Psi2TsModule::Psi2TsModule(unsigned pid)
 {
+    pid_ = pid;
     continuity_counter_ = 0;
     state_ = IDLE;
     route( input, output );
@@ -62,12 +63,17 @@ prefix_ void Psi2TsModule::onRequest()
     do {
         senf::TransportPacket tsPacket (senf::TransportPacket::create(188));
         tsPacket->continuity_counter() = next_continuity_counter();
+        tsPacket->pid() = pid_;
         if (state_ == IDLE) {
             state_ = PROC;
             tsPacket->pusi() = true;
         }
         senf::PacketData & payloadData (tsPacket.next().data());
-        std::copy( begin, end, payloadData.begin() );
+        std::fill(
+                std::copy( begin, end, payloadData.begin() ),
+                payloadData.end(),
+                0xff
+        );
         tsPacket.finalize();
         
         output.write( tsPacket);
index 2f48a16..1b136db 100644 (file)
@@ -44,7 +44,7 @@ class Psi2TsModule
 public: 
     senf::ppi::connector::PassiveInput<> input;
     senf::ppi::connector::ActiveOutput<senf::TransportPacket> output;
-    Psi2TsModule(); 
+    Psi2TsModule(unsigned pid); 
     void onRequest();
     
 private:
@@ -53,6 +53,7 @@ private:
     unsigned continuity_counter_;
     unsigned next_continuity_counter();
     state state_;
+    unsigned pid_;
         
 };
 
index e34aa91..000dc74 100644 (file)
@@ -49,36 +49,109 @@ void check_transportpacket_header(senf::TransportPacket tsPacket, bool pusi, uns
         
 }
 
+template<class InputIterator, class T>
+bool equal_elements(InputIterator first, InputIterator last, const T& value)
+{
+    return std::find_if( first, last, boost::lambda::_1 != value) == last;
+}
+        
+
 BOOST_AUTO_UNIT_TEST(one_section_to_one_transportpacket)
 {
     senf::ppi::module::debug::ActiveSource source;
     senf::ppi::module::debug::PassiveSink sink;
-    Psi2TsModule psi2ts;
+    unsigned PID = 42;
+    Psi2TsModule psi2ts (PID);
     
-    senf::ppi::connect(source, psi2ts);
-    senf::ppi::connect(psi2ts, sink);
+    senf::ppi::connect( source, psi2ts);
+    senf::ppi::connect( psi2ts, sink);
     senf::ppi::init();
     
-    std::string payload_data ( "psi2ts_test: one_section_to_one_transportpacket");
-    senf::Packet payload (senf::DataPacket::create(payload_data));
-    payload.finalize();
+    std::string sec_data ( "psi2ts_test: one_section_to_one_transportpacket");
+    senf::Packet sec_packet (senf::DataPacket::create(sec_data));
+    sec_packet.finalize();
     
-    source.submit(payload);
+    source.submit(sec_packet);
     BOOST_CHECK_EQUAL( sink.size(), 1u);
 
-    senf::TransportPacket tsPacket = sink.pop_front().as<senf::TransportPacket>();
-    check_transportpacket_header( tsPacket, true, 0, 1);
-    senf::PacketData & ts_data = tsPacket.next().data();
+    senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
+    check_transportpacket_header( ts_packet, true, PID, 1);
+    senf::PacketData & ts_payload_data = ts_packet.next().data();
     BOOST_CHECK_EQUAL_COLLECTIONS( 
-            ts_data.begin(), 
-            boost::next( ts_data.begin(), payload_data.size()),
-            payload_data.begin(),
-            payload_data.end());
-//    BOOST_CHECK( std::find_if( 
-//            boost::next( ts_data.begin(), payload_data.size()), 
-//            ts_data.end(),
-//            boost::lambda::_1 != 0xffu) == ts_data.end() );
+            ts_payload_data.begin(), 
+            boost::next( ts_payload_data.begin(), sec_data.size()),
+            sec_data.begin(),
+            sec_data.end());
+    BOOST_CHECK( equal_elements(
+            boost::next( ts_payload_data.begin(), ts_payload_data.size()), 
+            ts_payload_data.end(),
+            0xffu));
+}
+
+BOOST_AUTO_UNIT_TEST(one_section_to_two_transportpackets)
+{
+    senf::ppi::module::debug::ActiveSource source;
+    senf::ppi::module::debug::PassiveSink sink;
+    unsigned PID = 42;
+    Psi2TsModule psi2ts (PID);
+    
+    senf::ppi::connect( source, psi2ts);
+    senf::ppi::connect( psi2ts, sink);
+    senf::ppi::init();
+    
+    std::string sec_data ( 184, 0x42);
+    std::string sec_data2 ( "psi2ts_test: one_section_to_two_transportpackets");
+    sec_data.append( sec_data2);
+    senf::Packet sec_packet (senf::DataPacket::create(sec_data));
+    sec_packet.finalize();
+    
+    source.submit( sec_packet);
+    BOOST_CHECK_EQUAL( sink.size(), 2u);
+
+    senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
+    check_transportpacket_header( ts_packet, true, PID, 1);
+    senf::PacketData & ts_payload_data1 = ts_packet.next().data();
+    BOOST_CHECK( equal_elements( ts_payload_data1.begin(), ts_payload_data1.end(), 0x42));
+    
+    ts_packet = sink.pop_front().as<senf::TransportPacket>();
+    check_transportpacket_header( ts_packet, false, PID, 2);
+    senf::PacketData & ts_payload_data2 = ts_packet.next().data();
+    BOOST_CHECK_EQUAL_COLLECTIONS( 
+            ts_payload_data2.begin(), 
+            boost::next( ts_payload_data2.begin(), sec_data2.size()),
+            sec_data2.begin(),
+            sec_data2.end());
+    BOOST_CHECK( equal_elements(
+            boost::next( ts_payload_data2.begin(), sec_data2.size()), 
+            ts_payload_data2.end(),
+            0xffu));
+}
+
+BOOST_AUTO_UNIT_TEST(many_sections_to_many_transportpackets)
+{
+    senf::ppi::module::debug::ActiveSource source;
+    senf::ppi::module::debug::PassiveSink sink;
+    unsigned PID = 42;
+    Psi2TsModule psi2ts (PID);
+    
+    senf::ppi::connect( source, psi2ts);
+    senf::ppi::connect( psi2ts, sink);
+    senf::ppi::init();
+    
+    std::string sec_data ( "many_sections_to_many_transportpackets");
+    senf::Packet sec_packet (senf::DataPacket::create(sec_data));
+    sec_packet.finalize();
+    
+    unsigned NUMBER_OF_SECTIONS = 42u;
+    for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
+        source.submit( sec_packet);
+    }
+    BOOST_CHECK_EQUAL( sink.size(), NUMBER_OF_SECTIONS);
 
+    for (unsigned i=1; i<=NUMBER_OF_SECTIONS; i++) {
+        senf::TransportPacket ts_packet = sink.pop_front().as<senf::TransportPacket>();
+        check_transportpacket_header( ts_packet, true, PID, i%16);    
+    }
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////