4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Definition of non-inline non-template functions
28 #include <sys/ioctl.h>
29 #include <linux/sockios.h>
30 #include <linux/dvb/dmx.h>
32 #include "Scheduler/Scheduler.hh"
33 #include "Packets/DefaultBundle/EthernetPacket.hh"
34 #include "Packets/MPEGDVBBundle/TransportPacket.hh"
35 #include "Packets/MPEGDVBBundle/SNDUPacket.hh"
36 #include "Utils/membind.hh"
37 #include "Socket/Protocols/DVB/DVBDemuxHandles.hh"
38 #include "Packets/ParseInt.hh"
39 #include "Packets/Packet.hh"
40 #include "Packets/PacketData.hh"
41 #include "Packets/ParseInt.hh"
47 ///////////////////////////////cc.p////////////////////////////////////////
51 static const unsigned BLOCK_SIZE = 16;
53 template <class Iterator>
54 void hexdump(Iterator i, Iterator const & i_end, std::ostream& stream)
58 for (; i != i_end; ++i, ++offset) {
59 switch (offset % BLOCK_SIZE) {
62 stream << " " << ascii << "\n";
66 << std::hex << std::setw(4) << std::setfill('0')
74 stream << ' ' << std::hex << std::setw(2) << std::setfill('0')
76 ascii += (*i >= ' ' && *i < 126) ? *i : '.';
79 for (; (offset % BLOCK_SIZE) != 0; ++offset) {
80 if ((offset % BLOCK_SIZE) == BLOCK_SIZE/2)
84 stream << " " << ascii << "\n";
93 senf::DVBDemuxPESHandle demuxHandle;
94 senf::DVBDvrHandle dvrHandle;
96 unsigned char receiver_state;
97 unsigned char priv_tscc;
101 struct dmx_pes_filter_params pes_filter;
102 memset(&pes_filter, 0, sizeof (struct dmx_pes_filter_params));
103 pes_filter.pid = PID;
104 pes_filter.input = DMX_IN_FRONTEND;
105 pes_filter.output = DMX_OUT_TS_TAP;
106 pes_filter.pes_type = DMX_PES_OTHER;
107 pes_filter.flags = DMX_IMMEDIATE_START;
108 demuxHandle.protocol().setPESFilter( &pes_filter );
110 senf::Scheduler::instance().add(
111 dvrHandle, senf::membind(&ULEdec::handlePacket, this));
113 receiver_state = 1; // Idle
117 void handlePacket(senf::FileHandle, senf::Scheduler::EventId event)
120 dvrHandle.read(&ts_data[0], &ts_data[188]);
121 senf::TransportPacket tsPacket (
122 senf::TransportPacket::create( boost::begin(ts_data) ));
123 // packet.dump(std::cout);
124 // senf::PacketData & packetData (packet.last().data());
125 // hexdump(packetData.begin(), packetData.end(), std::cout);
127 // Check TS error conditions: sync_byte, transport_error_indicator, scrambling_control.
128 if ( (tsPacket->sync_byte() != TS_SYNC) ||
129 (tsPacket->transport_error_indicator() == true) ||
130 (tsPacket->transport_scrmbl_ctrl() != 0))
132 std::cerr << "invalid ts packet\n";
133 // drop partly decoded SNDU, reset state, resync on PUSI.
137 unsigned char payload_pointer;
138 switch (receiver_state) {
139 case 1: // Idle State
141 if (tsPacket->pusi() == 0)
142 return; // skip packet
143 // Synchronize continuity counter
144 priv_tscc = tsPacket->continuity_counter();
145 // a PUSI value of 1 indicates the presence of a Payload Pointer.
146 payload_pointer = ts_data[4];
147 if (payload_pointer>181) {
148 std::cerr << "invalid payload_pointer\n";
154 case 2: // Reassembly State
160 int main(int argc, char const * argv[])
164 senf::Scheduler::instance().process();
166 catch (std::exception const & ex) {
167 std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
173 ///////////////////////////////cc.e////////////////////////////////////////
180 // c-file-style: "senf"
181 // indent-tabs-mode: nil
182 // ispell-local-dictionary: "american"
183 // compile-command: "scons -u test"
184 // comment-column: 40