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

changed API for DVB (likely not the last time ;)

parent 4b9551fc
No related branches found
No related tags found
No related merge requests found
// $Id: Sniffer.cc 296 2007-07-10 20:39:34Z g0dil $
//
// 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/MPEG_DVBBundle/DatagramSection.hh"
#include "Utils/membind.hh"
#include "Socket/DVBDemuxHandles.hh"
#include "Packets/ParseInt.hh"
#include "Packets/Packet.hh"
#include "Packets/PacketData.hh"
#define PID 500
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
namespace {
static const unsigned BLOCK_SIZE = 16;
template <class Iterator>
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;
}
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 << " " << ascii << "\n";
}
stream << std::dec;
}
}
class MySniffer
{
senf::DVBDemuxSectionHandle handle;
public:
MySniffer()
{
struct dmx_sct_filter_params sec_filter;
memset(&sec_filter, 0, sizeof (struct dmx_sct_filter_params));
sec_filter.pid = PID;
sec_filter.filter.filter[0] = 62;
sec_filter.filter.mask[0] = 0xff;
sec_filter.flags = DMX_IMMEDIATE_START;
sec_filter.flags |= DMX_CHECK_CRC;
handle.protocol().setSectionFilter( &sec_filter );
senf::Scheduler::instance().add(
handle, senf::membind(&MySniffer::dumpSection, this));
}
private:
void dumpSection(senf::FileHandle /* ignored */, senf::Scheduler::EventId event)
{
std::string data (handle.read());
senf::DatagramSection section (senf::DatagramSection::create(data));
section.dump(std::cout);
senf::PacketData & datagramData (section.last().data());
hexdump(datagramData.begin(), datagramData.end(), std::cout);
}
};
int main(int argc, char const * argv[])
{
try {
MySniffer sniffer;
senf::Scheduler::instance().process();
}
catch (std::exception const & ex) {
std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
}
return 0;
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// 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:
Import('env')
import SENFSCons
###########################################################################
SENFSCons.Binary(env, 'uledec', 'ULEdec.cc',
LIBS = [ 'Scheduler', 'Packets', 'Socket', 'Utils' ],
OBJECTS = [ '#/Packets/MPEG_DVBBundle/MPEG_DVBBundle.o' ]);
SENFSCons.Binary(env, 'mpedec', 'MPEdec.cc',
LIBS = [ 'Scheduler', 'Packets', 'Socket', 'Utils' ],
OBJECTS = [ '#/Packets/MPEG_DVBBundle/MPEG_DVBBundle.o' ]);
// $Id: Sniffer.cc 296 2007-07-10 20:39:34Z g0dil $
//
// 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/MPEG_DVBBundle/DatagramSection.hh"
#include "Utils/membind.hh"
#include "Socket/DVBDemuxHandles.hh"
#include "Packets/ParseInt.hh"
#include "Packets/Packet.hh"
#include "Packets/PacketData.hh"
#define PID 271
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
namespace {
static const unsigned BLOCK_SIZE = 16;
template <class Iterator>
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;
}
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 << " " << ascii << "\n";
}
stream << std::dec;
}
}
class MySniffer
{
senf::DVBDemuxPESHandle demuxHandle;
senf::DVBDvrHandle dvrHandle;
public:
MySniffer()
{
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(&MySniffer::dumpSection, this));
}
private:
void dumpSection(senf::FileHandle /* ignored */, senf::Scheduler::EventId event)
{
std::string data (dvrHandle.read());
std::cout << data.length() << "\n";
//senf::DatagramSection section (senf::DatagramSection::create(data));
//section.dump(std::cout);
//senf::PacketData & datagramData (section.last().data());
//hexdump(datagramData.begin(), datagramData.end(), std::cout);
}
};
int main(int argc, char const * argv[])
{
try {
MySniffer sniffer;
senf::Scheduler::instance().process();
}
catch (std::exception const & ex) {
std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
}
return 0;
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
// 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:
File added
File added
......@@ -84,7 +84,7 @@ int loop_main (int argc, char const * argv[])
{
try {
senf::PacketSocketHandle sock;
sock.bind(senf::LLSocketAddress("eth0"));
sock.bind(senf::LLSocketAddress("eth1"));
// sock.protocol().promisc("eth0",senf::PacketProtocol::Promiscuous);
while (true) { // forever
......@@ -136,7 +136,7 @@ private:
int scheduler_main(int argc, char const * argv[])
{
try {
Sniffer sniffer ("eth0");
Sniffer sniffer ("eth1");
sniffer.run();
}
catch (std::exception const & ex) {
......
// $Id$
// $Id: DVBSectionHandle.cc 321 2007-07-19 09:00:23Z tho $
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
......@@ -24,8 +24,8 @@
\brief xxx
*/
#include "DVBSectionHandle.hh"
//#include "DVBSectionHandle.ih"
#include "DVBDemuxHandles.hh"
//#include "DVBDemuxHandles.ih"
// Custom includes
#include <sys/types.h>
......@@ -39,14 +39,14 @@
#include "Utils/Exception.hh"
//#include "DVBSectionHandle.mpp"
//#include "DVBDemuxHandles.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// senf::DVBSectionProtocol
// senf::DVBDemuxHandles
prefix_ void senf::DVBSectionProtocol::init_client()
prefix_ void senf::DVBDemuxSectionProtocol::init_client()
const
{
int fd = open("/dev/dvb/adapter0/demux0", O_RDONLY | O_NONBLOCK);
......@@ -55,45 +55,81 @@ prefix_ void senf::DVBSectionProtocol::init_client()
body().fd(fd);
}
prefix_ unsigned senf::DVBSectionProtocol::available()
prefix_ unsigned senf::DVBDemuxSectionProtocol::available()
const
{
return 4096;
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBSectionProtocol::clone()
prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDemuxSectionProtocol::clone()
const
{
return std::auto_ptr<SocketProtocol>(new DVBSectionProtocol());
return std::auto_ptr<SocketProtocol>(new DVBDemuxSectionProtocol());
}
prefix_ void senf::DVBDemuxSectionProtocol::setSectionFilter(struct dmx_sct_filter_params *filter)
const
{
if (::ioctl(body().fd(), DMX_SET_FILTER, filter) < 0)
throw SystemException(errno);
}
prefix_ void senf::DVBSectionProtocol::setSectionFilter(
unsigned short pid,
unsigned char table_id)
// ----------------------------------------------------------------
prefix_ void senf::DVBDemuxPESProtocol::init_client()
const
{
struct dmx_sct_filter_params sec_filter;
memset(&sec_filter, 0, sizeof (struct dmx_sct_filter_params));
sec_filter.pid = pid;
sec_filter.filter.filter[0] = table_id;
sec_filter.filter.mask[0] = 0xff;
sec_filter.flags = DMX_IMMEDIATE_START;
sec_filter.flags |= DMX_CHECK_CRC;
setSectionFilter( &sec_filter );
int fd = open("/dev/dvb/adapter0/demux0", O_RDONLY | O_NONBLOCK);
if (fd < 0)
throw SystemException(errno);
body().fd(fd);
}
prefix_ unsigned senf::DVBDemuxPESProtocol::available()
const
{
return 4096; //???
}
prefix_ void senf::DVBSectionProtocol::setSectionFilter(struct dmx_sct_filter_params *filter)
prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDemuxPESProtocol::clone()
const
{
if (::ioctl(body().fd(), DMX_SET_FILTER, filter) < 0)
return std::auto_ptr<SocketProtocol>(new DVBDemuxPESProtocol());
}
prefix_ void senf::DVBDemuxPESProtocol::setPESFilter(struct dmx_pes_filter_params *filter)
const
{
if (::ioctl(body().fd(), DMX_SET_PES_FILTER, filter) < 0)
throw SystemException(errno);
}
// ----------------------------------------------------------------
prefix_ void senf::DVBDvrProtocol::init_client()
const
{
int fd = open("/dev/dvb/adapter0/dvr0", O_RDONLY | O_NONBLOCK);
if (fd < 0)
throw SystemException(errno);
body().fd(fd);
}
prefix_ unsigned senf::DVBDvrProtocol::available()
const
{
return 188;
}
prefix_ std::auto_ptr<senf::SocketProtocol> senf::DVBDvrProtocol::clone()
const
{
return std::auto_ptr<SocketProtocol>(new DVBDvrProtocol());
}
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "DVBSectionHandle.mpp"
//#include "DVBDemuxHandles.mpp"
// Local Variables:
......
// $Id$
// $Id: DVBDemuxSectionHandle.hh 321 2007-07-19 09:00:23Z tho $
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
......@@ -21,11 +21,11 @@
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/** \file
\brief DVBSectionHandle
\brief DVBHandles
*/
#ifndef HH_DVBSectionHandle_
#define HH_DVBSectionHandle_ 1
#ifndef HH_DVBDemuxHandles_
#define HH_DVBDemuxHandles_ 1
// Custom includes
#include "BSDSocketProtocol.hh"
......@@ -34,9 +34,9 @@
#include "ReadWritePolicy.hh"
#include "BufferingPolicy.hh"
#include "ProtocolClientSocketHandle.hh"
#include "DVBProtocol.hh"
#include "DVBDemuxProtocol.hh"
//#include "DVBSocketHandle.mpp"
//#include "DVBDemuxHandles.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
......@@ -51,13 +51,13 @@ namespace senf {
ReadablePolicy,
NotWriteablePolicy,
SocketBufferingPolicy
>::policy DVBSection_Policy; ///< Socket Policy for DVBSection
>::policy DVBDemux_Policy; ///< Socket Policy for xxxx
/** \brief xxx
*/
class DVBSectionProtocol
: public ConcreteSocketProtocol<DVBSection_Policy>,
public DVBProtocol
class DVBDemuxSectionProtocol
: public ConcreteSocketProtocol<DVBDemux_Policy>,
public DVBDemuxProtocol
{
public:
///////////////////////////////////////////////////////////////////////////
......@@ -80,22 +80,86 @@ namespace senf {
///@}
void setSectionFilter(unsigned short pid, unsigned char table_id) const;
void setSectionFilter(struct dmx_sct_filter_params *filter) const;
};
typedef ProtocolClientSocketHandle<DVBDemuxSectionProtocol> DVBDemuxSectionHandle;
private:
void setSectionFilter(struct dmx_sct_filter_params *filter) const;
// ----------------------------------------------------------------
/** \brief xxx
*/
class DVBDemuxPESProtocol
: public ConcreteSocketProtocol<DVBDemux_Policy>,
public DVBDemuxProtocol
{
public:
///////////////////////////////////////////////////////////////////////////
// internal interface
///\name Constructors
///@{
void init_client() const; ///< xxx
/**< \note This member is implicitly called from the
ProtocolClientSocketHandle::ProtocolClientSocketHandle()
constructor */
///@}
///\name Abstract Interface Implementation
unsigned available() const;
std::auto_ptr<SocketProtocol> clone() const;
///@}
void setPESFilter(struct dmx_pes_filter_params *filter) const;
};
typedef ProtocolClientSocketHandle<DVBSectionProtocol> DVBSectionHandle;
typedef ProtocolClientSocketHandle<DVBDemuxPESProtocol> DVBDemuxPESHandle;
// ----------------------------------------------------------------
/** \brief xxx
*/
class DVBDvrProtocol
: public ConcreteSocketProtocol<DVBDemux_Policy>,
public DVBDemuxProtocol
{
public:
///////////////////////////////////////////////////////////////////////////
// internal interface
///\name Constructors
///@{
void init_client() const; ///< xxx
/**< \note This member is implicitly called from the
ProtocolClientSocketHandle::ProtocolClientSocketHandle()
constructor */
///@}
///\name Abstract Interface Implementation
unsigned available() const;
std::auto_ptr<SocketProtocol> clone() const;
///@}
};
typedef ProtocolClientSocketHandle<DVBDvrProtocol> DVBDvrHandle;
}
///////////////////////////////hh.e////////////////////////////////////////
//#include "DVBSectionHandle.cci"
//#include "DVBSectionHandle.ct"
//#include "DVBSectionHandle.cti"
//#include "DVBDemuxHandles.cci"
//#include "DVBDemuxHandles.ct"
//#include "DVBDemuxHandles.cti"
#endif
......
// $Id$
// $Id: DVBProtocol.cc 321 2007-07-19 09:00:23Z tho $
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
......@@ -24,8 +24,8 @@
\brief xxx
*/
#include "DVBProtocol.hh"
//#include "DVBProtocol.ih"
#include "DVBDemuxProtocol.hh"
//#include "DVBDemuxProtocol.ih"
// Custom includes
#include <sys/socket.h>
......@@ -35,34 +35,34 @@
#include <linux/sockios.h>
#include "SocketHandle.hh"
//#include "DVBProtocol.mpp"
//#include "DVBDemuxProtocol.mpp"
#define prefix_
///////////////////////////////cc.p////////////////////////////////////////
prefix_ void senf::DVBProtocol::setBufferSize(unsigned long size)
prefix_ void senf::DVBDemuxProtocol::setBufferSize(unsigned long size)
const
{
if (::ioctl(body().fd(), DMX_SET_BUFFER_SIZE, size) < 0)
throw SystemException(errno);
}
prefix_ void senf::DVBProtocol::startFiltering()
prefix_ void senf::DVBDemuxProtocol::startFiltering()
const
{
if (::ioctl(body().fd(), DMX_START) < 0)
throw SystemException(errno);
}
prefix_ void senf::DVBProtocol::stopFiltering()
prefix_ void senf::DVBDemuxProtocol::stopFiltering()
const
{
if (::ioctl(body().fd(), DMX_STOP) < 0)
throw SystemException(errno);
}
prefix_ bool senf::DVBProtocol::eof()
prefix_ bool senf::DVBDemuxProtocol::eof()
const
{
return false;
......@@ -70,7 +70,7 @@ prefix_ bool senf::DVBProtocol::eof()
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "DVBProtocol.mpp"
//#include "DVBDemuxProtocol.mpp"
// Local Variables:
......
// $Id$
// $Id: DVBProtocol.hh 321 2007-07-19 09:00:23Z tho $
//
// Copyright (C) 2007
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
......@@ -24,8 +24,8 @@
\brief DVBProtocol public header
*/
#ifndef HH_DVBProtocol_
#define HH_DVBProtocol_ 1
#ifndef HH_DVBDemuxProtocol_
#define HH_DVBDemuxProtocol_ 1
#include <linux/dvb/dmx.h>
......@@ -43,7 +43,7 @@ namespace senf {
/** xxx
*/
class DVBProtocol
class DVBDemuxProtocol
: public virtual SocketProtocol
{
public:
......@@ -66,9 +66,9 @@ namespace senf {
}
///////////////////////////////hh.e////////////////////////////////////////
//#include "DVBProtocol.cci"
//#include "DVBProtocol.ct"
//#include "DVBProtocol.cti"
//#include "DVBDemuxProtocol.cci"
//#include "DVBDemuxProtocol.ct"
//#include "DVBDemuxProtocol.cti"
#endif
......
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