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"
49 ///////////////////////////////cc.p////////////////////////////////////////
51 template <class Iterator>
52 void ULEdec::hexdump(Iterator i, Iterator const & i_end, std::ostream& stream)
56 for (; i != i_end; ++i, ++offset) {
57 switch (offset % BLOCK_SIZE) {
60 stream << " " << ascii << "\n";
64 << std::hex << std::setw(4) << std::setfill('0')
72 stream << ' ' << std::hex << std::setw(2) << std::setfill('0')
74 ascii += (*i >= ' ' && *i < 126) ? *i : '.';
77 for (; (offset % BLOCK_SIZE) != 0; ++offset) {
78 if ((offset % BLOCK_SIZE) == BLOCK_SIZE/2)
82 stream << " " << ascii << "\n";
90 struct dmx_pes_filter_params pes_filter;
91 memset(&pes_filter, 0, sizeof (struct dmx_pes_filter_params));
93 pes_filter.input = DMX_IN_FRONTEND;
94 pes_filter.output = DMX_OUT_TS_TAP;
95 pes_filter.pes_type = DMX_PES_OTHER;
96 pes_filter.flags = DMX_IMMEDIATE_START;
97 demuxHandle.protocol().setPESFilter( &pes_filter );
99 senf::Scheduler::instance().add(
100 dvrHandle, senf::membind(&ULEdec::handleEvent, this));
102 this->receiver_state = 1; // Idle
105 void ULEdec::handleEvent(senf::FileHandle, senf::Scheduler::EventId event)
107 senf::TransportPacket ts_packet (
108 senf::TransportPacket::create(188, senf::TransportPacket::noinit));
109 dvrHandle.read( ts_packet.data() );
111 // Check TS error conditions: sync_byte, transport_error_indicator, scrambling_control.
112 if ( (ts_packet->sync_byte() != TS_SYNC) ||
113 (ts_packet->transport_error_indicator() == true) ||
114 (ts_packet->transport_scrmbl_ctrl() != 0))
116 std::cerr << "invalid ts packet\n";
117 // drop partly decoded SNDU, reset state, resync on PUSI.
121 handleTSPacket(ts_packet);
124 void ULEdec::handleTSPacket(senf::TransportPacket ts_packet)
126 unsigned char payload_pointer;
128 senf::PacketData &ts_payload (ts_packet.next().data());
129 BOOST_ASSERT( ts_payload.size() == 184 );
131 switch (this->receiver_state) {
132 case 1: { // Idle State
134 if (ts_packet->pusi() == 0)
135 return; // skip packet
137 // Synchronize continuity counter
138 this->priv_tscc = ts_packet->continuity_counter();
140 // a PUSI value of 1 indicates the presence of a Payload Pointer.
141 payload_pointer = ts_payload[0];
142 if (payload_pointer>181) {
143 std::cerr << "invalid payload_pointer\n";
149 senf::Packet::size_type sndu_length;
150 while (payload_pointer < 184) {
151 sndu_length = ts_payload[payload_pointer] << 8 | ts_payload[payload_pointer+1];
152 if (sndu_length & 0x8000) {
153 sndu_length &= 0x7FFF;
156 this->snduPacket = senf::SNDUPacket::create(sndu_length+2);
157 this->snduPacket->d_bit() = dbit;
158 this->snduPacket->length() = sndu_length;
162 payload_pointer += 2;
172 case 2: { // Reassembly State
179 int main(int argc, char const * argv[])
183 senf::Scheduler::instance().process();
185 catch (std::exception const & ex) {
186 std::cerr << senf::prettyName(typeid(ex)) << ": " << ex.what() << "\n";
192 ///////////////////////////////cc.e////////////////////////////////////////
199 // c-file-style: "senf"
200 // indent-tabs-mode: nil
201 // ispell-local-dictionary: "american"
202 // compile-command: "scons -u test"
203 // comment-column: 40