Skip to content
Snippets Groups Projects
Commit c8a86e34 authored by tho's avatar tho
Browse files

added some documentation for PacketData

parent 138d56ec
No related branches found
No related tags found
No related merge requests found
...@@ -40,122 +40,141 @@ ...@@ -40,122 +40,141 @@
#include "Packets/PacketData.hh" #include "Packets/PacketData.hh"
#include "Packets/ParseInt.hh" #include "Packets/ParseInt.hh"
#include "ULEdec.hh"
#define PID 271 #define PID 271
#define TS_SYNC 0x47 #define TS_SYNC 0x47
#define prefix_ #define prefix_
///////////////////////////////cc.p//////////////////////////////////////// ///////////////////////////////cc.p////////////////////////////////////////
namespace { template <class Iterator>
void ULEdec::hexdump(Iterator i, Iterator const & i_end, std::ostream& stream)
static const unsigned BLOCK_SIZE = 16; {
unsigned offset (0);
template <class Iterator> std::string ascii;
void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream) for (; i != i_end; ++i, ++offset) {
{ switch (offset % BLOCK_SIZE) {
unsigned offset (0); case 0:
std::string ascii; if (!ascii.empty()) {
for (; i != i_end; ++i, ++offset) { stream << " " << ascii << "\n";
switch (offset % BLOCK_SIZE) { ascii = "";
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;
} }
stream << ' ' << std::hex << std::setw(2) << std::setfill('0') stream << " "
<< unsigned(*i); << std::hex << std::setw(4) << std::setfill('0')
ascii += (*i >= ' ' && *i < 126) ? *i : '.'; << offset << ' ';
break;
case BLOCK_SIZE/2:
stream << " ";
ascii += ' ';
break;
} }
if (!ascii.empty()) { stream << ' ' << std::hex << std::setw(2) << std::setfill('0')
for (; (offset % BLOCK_SIZE) != 0; ++offset) { << unsigned(*i);
if ((offset % BLOCK_SIZE) == BLOCK_SIZE/2) ascii += (*i >= ' ' && *i < 126) ? *i : '.';
stream << " "; }
stream << " "; if (!ascii.empty()) {
} for (; (offset % BLOCK_SIZE) != 0; ++offset) {
stream << " " << ascii << "\n"; 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; struct dmx_pes_filter_params pes_filter;
senf::DVBDvrHandle dvrHandle; 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; this->receiver_state = 1; // Idle
unsigned char priv_tscc; }
public:
ULEdec() 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; std::cerr << "invalid ts packet\n";
memset(&pes_filter, 0, sizeof (struct dmx_pes_filter_params)); // drop partly decoded SNDU, reset state, resync on PUSI.
pes_filter.pid = PID; return;
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
} }
handleTSPacket(ts_packet);
}
void ULEdec::handleTSPacket(senf::TransportPacket ts_packet)
{
unsigned char payload_pointer;
private: senf::PacketData &ts_payload (ts_packet.next().data());
void handlePacket(senf::FileHandle, senf::Scheduler::EventId event) BOOST_ASSERT( ts_payload.size() == 184 );
{
char ts_data[188]; switch (this->receiver_state) {
dvrHandle.read(&ts_data[0], &ts_data[188]); case 1: { // Idle State
senf::TransportPacket tsPacket ( // resync on PUSI
senf::TransportPacket::create( boost::begin(ts_data) )); if (ts_packet->pusi() == 0)
// packet.dump(std::cout); return; // skip packet
// senf::PacketData & packetData (packet.last().data());
// hexdump(packetData.begin(), packetData.end(), std::cout);
// Check TS error conditions: sync_byte, transport_error_indicator, scrambling_control. // Synchronize continuity counter
if ( (tsPacket->sync_byte() != TS_SYNC) || this->priv_tscc = ts_packet->continuity_counter();
(tsPacket->transport_error_indicator() == true) ||
(tsPacket->transport_scrmbl_ctrl() != 0)) // a PUSI value of 1 indicates the presence of a Payload Pointer.
{ payload_pointer = ts_payload[0];
std::cerr << "invalid ts packet\n"; if (payload_pointer>181) {
// drop partly decoded SNDU, reset state, resync on PUSI. std::cerr << "invalid payload_pointer\n";
return; return;
} }
payload_pointer++;
unsigned char payload_pointer;
switch (receiver_state) { bool dbit = false;
case 1: // Idle State senf::Packet::size_type sndu_length;
// resync on PUSI while (payload_pointer < 184) {
if (tsPacket->pusi() == 0) sndu_length = ts_payload[payload_pointer] << 8 | ts_payload[payload_pointer+1];
return; // skip packet if (sndu_length & 0x8000) {
// Synchronize continuity counter sndu_length &= 0x7FFF;
priv_tscc = tsPacket->continuity_counter(); dbit = true;
// 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;
} }
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[]) int main(int argc, char const * argv[])
{ {
......
// $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 <stefan.bund@fokus.fraunhofer.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
#include <string>
#include <iostream>
#include <iomanip>
#include <sys/ioctl.h>
#include <linux/sockios.h>
#include <linux/dvb/dmx.h>
#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 <class Iterator>
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:
...@@ -95,10 +95,16 @@ namespace senf { ...@@ -95,10 +95,16 @@ namespace senf {
///\name Sequence interface to raw data ///\name Sequence interface to raw data
///@{ ///@{
iterator begin() const; iterator begin() const; /**< Returns an <em>random access iterator</em> referring
iterator end() const; to the first byte of the packet data. */
size_type size() const; iterator end() const; /**< Returns an <em>random access iterator</em> referring to the
bool empty() const; 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) const;
byte & operator[](size_type n); byte & operator[](size_type n);
...@@ -120,7 +126,8 @@ namespace senf { ...@@ -120,7 +126,8 @@ namespace senf {
void erase(iterator pos); void erase(iterator pos);
void erase(iterator first, iterator last); 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); void resize(size_type n, byte v=0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment