From: tho Date: Mon, 30 Jul 2007 11:48:02 +0000 (+0000) Subject: added some documentation for PacketData X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=9027d68d973f1d8ad8f25d6827166ba2ee9be7a7;p=senf.git added some documentation for PacketData git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@361 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Examples/DVBAdapter/ULEdec.cc b/Examples/DVBAdapter/ULEdec.cc index 609a5c9..a732b96 100644 --- a/Examples/DVBAdapter/ULEdec.cc +++ b/Examples/DVBAdapter/ULEdec.cc @@ -40,122 +40,141 @@ #include "Packets/PacketData.hh" #include "Packets/ParseInt.hh" +#include "ULEdec.hh" + #define PID 271 #define TS_SYNC 0x47 #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// -namespace { - - static const unsigned BLOCK_SIZE = 16; - - template - void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream) - { - unsigned offset (0); - std::string ascii; - for (; i != i_end; ++i, ++offset) { - switch (offset % BLOCK_SIZE) { - case 0: - if (!ascii.empty()) { - stream << " " << ascii << "\n"; - ascii = ""; - } - stream << " " - << std::hex << std::setw(4) << std::setfill('0') - << offset << ' '; - break; - case BLOCK_SIZE/2: - stream << " "; - ascii += ' '; - break; +template +void ULEdec::hexdump(Iterator i, Iterator const & i_end, std::ostream& stream) +{ + unsigned offset (0); + std::string ascii; + for (; i != i_end; ++i, ++offset) { + switch (offset % BLOCK_SIZE) { + case 0: + if (!ascii.empty()) { + stream << " " << ascii << "\n"; + ascii = ""; } - stream << ' ' << std::hex << std::setw(2) << std::setfill('0') - << unsigned(*i); - ascii += (*i >= ' ' && *i < 126) ? *i : '.'; + stream << " " + << std::hex << std::setw(4) << std::setfill('0') + << offset << ' '; + break; + case BLOCK_SIZE/2: + stream << " "; + ascii += ' '; + break; } - if (!ascii.empty()) { - for (; (offset % BLOCK_SIZE) != 0; ++offset) { - if ((offset % BLOCK_SIZE) == BLOCK_SIZE/2) - stream << " "; - stream << " "; - } - stream << " " << ascii << "\n"; + stream << ' ' << std::hex << std::setw(2) << std::setfill('0') + << unsigned(*i); + ascii += (*i >= ' ' && *i < 126) ? *i : '.'; + } + if (!ascii.empty()) { + for (; (offset % BLOCK_SIZE) != 0; ++offset) { + if ((offset % BLOCK_SIZE) == BLOCK_SIZE/2) + stream << " "; + stream << " "; } - stream << std::dec; + stream << " " << ascii << "\n"; } + stream << std::dec; } -class ULEdec +ULEdec::ULEdec() { - senf::DVBDemuxPESHandle demuxHandle; - senf::DVBDvrHandle dvrHandle; + struct dmx_pes_filter_params pes_filter; + memset(&pes_filter, 0, sizeof (struct dmx_pes_filter_params)); + pes_filter.pid = PID; + pes_filter.input = DMX_IN_FRONTEND; + pes_filter.output = DMX_OUT_TS_TAP; + pes_filter.pes_type = DMX_PES_OTHER; + pes_filter.flags = DMX_IMMEDIATE_START; + demuxHandle.protocol().setPESFilter( &pes_filter ); + + senf::Scheduler::instance().add( + dvrHandle, senf::membind(&ULEdec::handleEvent, this)); - unsigned char receiver_state; - unsigned char priv_tscc; -public: - ULEdec() + this->receiver_state = 1; // Idle +} + +void ULEdec::handleEvent(senf::FileHandle, senf::Scheduler::EventId event) +{ + senf::TransportPacket ts_packet ( + senf::TransportPacket::create(188, senf::TransportPacket::noinit)); + dvrHandle.read( ts_packet.data() ); + + // Check TS error conditions: sync_byte, transport_error_indicator, scrambling_control. + if ( (ts_packet->sync_byte() != TS_SYNC) || + (ts_packet->transport_error_indicator() == true) || + (ts_packet->transport_scrmbl_ctrl() != 0)) { - struct dmx_pes_filter_params pes_filter; - memset(&pes_filter, 0, sizeof (struct dmx_pes_filter_params)); - pes_filter.pid = PID; - pes_filter.input = DMX_IN_FRONTEND; - pes_filter.output = DMX_OUT_TS_TAP; - pes_filter.pes_type = DMX_PES_OTHER; - pes_filter.flags = DMX_IMMEDIATE_START; - demuxHandle.protocol().setPESFilter( &pes_filter ); - - senf::Scheduler::instance().add( - dvrHandle, senf::membind(&ULEdec::handlePacket, this)); - - receiver_state = 1; // Idle + std::cerr << "invalid ts packet\n"; + // drop partly decoded SNDU, reset state, resync on PUSI. + return; } + + handleTSPacket(ts_packet); +} + +void ULEdec::handleTSPacket(senf::TransportPacket ts_packet) +{ + unsigned char payload_pointer; -private: - void handlePacket(senf::FileHandle, senf::Scheduler::EventId event) - { - char ts_data[188]; - dvrHandle.read(&ts_data[0], &ts_data[188]); - senf::TransportPacket tsPacket ( - senf::TransportPacket::create( boost::begin(ts_data) )); -// packet.dump(std::cout); -// senf::PacketData & packetData (packet.last().data()); -// hexdump(packetData.begin(), packetData.end(), std::cout); + senf::PacketData &ts_payload (ts_packet.next().data()); + BOOST_ASSERT( ts_payload.size() == 184 ); + + switch (this->receiver_state) { + case 1: { // Idle State + // resync on PUSI + if (ts_packet->pusi() == 0) + return; // skip packet - // Check TS error conditions: sync_byte, transport_error_indicator, scrambling_control. - if ( (tsPacket->sync_byte() != TS_SYNC) || - (tsPacket->transport_error_indicator() == true) || - (tsPacket->transport_scrmbl_ctrl() != 0)) - { - std::cerr << "invalid ts packet\n"; - // drop partly decoded SNDU, reset state, resync on PUSI. + // Synchronize continuity counter + this->priv_tscc = ts_packet->continuity_counter(); + + // a PUSI value of 1 indicates the presence of a Payload Pointer. + payload_pointer = ts_payload[0]; + if (payload_pointer>181) { + std::cerr << "invalid payload_pointer\n"; return; } - - unsigned char payload_pointer; - switch (receiver_state) { - case 1: // Idle State - // resync on PUSI - if (tsPacket->pusi() == 0) - return; // skip packet - // Synchronize continuity counter - priv_tscc = tsPacket->continuity_counter(); - // a PUSI value of 1 indicates the presence of a Payload Pointer. - payload_pointer = ts_data[4]; - if (payload_pointer>181) { - std::cerr << "invalid payload_pointer\n"; - return; + payload_pointer++; + + bool dbit = false; + senf::Packet::size_type sndu_length; + while (payload_pointer < 184) { + sndu_length = ts_payload[payload_pointer] << 8 | ts_payload[payload_pointer+1]; + if (sndu_length & 0x8000) { + sndu_length &= 0x7FFF; + dbit = true; } + this->snduPacket = senf::SNDUPacket::create(sndu_length+2); + this->snduPacket->d_bit() = dbit; + this->snduPacket->length() = sndu_length; + + return; + + payload_pointer += 2; + - // - break; - case 2: // Reassembly State - break; } + + + + // + break; } -}; + case 2: { // Reassembly State + break; + } + } +} + int main(int argc, char const * argv[]) { diff --git a/Examples/DVBAdapter/ULEdec.hh b/Examples/DVBAdapter/ULEdec.hh new file mode 100644 index 0000000..bfd177f --- /dev/null +++ b/Examples/DVBAdapter/ULEdec.hh @@ -0,0 +1,75 @@ +// $Id: ULEdec.cc 355 2007-07-26 14:17:02Z tho $ +// +// Copyright (C) 2006 +// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) +// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Stefan Bund +// +// 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 + +#include +#include +#include +#include +#include +#include + +#include "Scheduler/Scheduler.hh" +#include "Packets/DefaultBundle/EthernetPacket.hh" +#include "Packets/MPEGDVBBundle/TransportPacket.hh" +#include "Packets/MPEGDVBBundle/SNDUPacket.hh" +#include "Utils/membind.hh" +#include "Socket/Protocols/DVB/DVBDemuxHandles.hh" +#include "Packets/ParseInt.hh" +#include "Packets/Packet.hh" +#include "Packets/PacketData.hh" +#include "Packets/ParseInt.hh" + + +class ULEdec +{ +public: + ULEdec(); + +private: + senf::DVBDemuxPESHandle demuxHandle; + senf::DVBDvrHandle dvrHandle; + senf::SNDUPacket snduPacket; + unsigned char receiver_state; + unsigned char priv_tscc; + + static const unsigned BLOCK_SIZE = 16; + + template + void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream); + + void handleEvent(senf::FileHandle, senf::Scheduler::EventId event); + + void handleTSPacket(senf::TransportPacket tsPacket); +}; + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 +// End: diff --git a/Packets/PacketData.hh b/Packets/PacketData.hh index 8a64ec0..2f8a521 100644 --- a/Packets/PacketData.hh +++ b/Packets/PacketData.hh @@ -95,10 +95,16 @@ namespace senf { ///\name Sequence interface to raw data ///@{ - iterator begin() const; - iterator end() const; - size_type size() const; - bool empty() const; + iterator begin() const; /**< Returns an random access iterator referring + to the first byte of the packet data. */ + iterator end() const; /**< Returns an random access iterator referring to the + element past the end of the packet data. */ + size_type size() const; ///< Returns the number of bytes in the packet data. + bool empty() const; ///< Test whether the packet data is empty. + /**< Returns whether the packet data is empty, i.e. + whether its size is 0. This function does not modify + the content of the packet data in any way. To clear + the content use clear() */ byte operator[](size_type n) const; byte & operator[](size_type n); @@ -120,7 +126,8 @@ namespace senf { void erase(iterator pos); void erase(iterator first, iterator last); - void clear(); + void clear(); /**< All bytes of the packet data dropped, + leaving the container with a size of 0. */ void resize(size_type n, byte v=0);