da8a1890fd9c87a9788e87a51b8003ef3df4265f
[senf.git] / Socket / Protocols / DVB / DVBDemuxHandles.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief DVBDemuxHandles non-inline non-template implementation */
25
26 #include "DVBDemuxHandles.hh"
27 //#include "DVBDemuxHandles.ih"
28
29 // Custom includes
30 #include <boost/format.hpp>
31 #include <sys/socket.h>
32 #include <sys/ioctl.h>
33 #include <fcntl.h>
34 #include "../../../Utils/Exception.hh"
35 // TODO REMOVE V
36 #include <iostream>
37
38 //#include "DVBDemuxHandles.mpp"
39 #define prefix_
40 ///////////////////////////////cc.p////////////////////////////////////////
41
42 ///////////////////////////////////////////////////////////////////////////
43 // senf::DVBDemuxHandles
44
45 prefix_ void senf::DVBDemuxSectionSocketProtocol::init_client(unsigned short adapter, unsigned short device)
46     const
47 {
48     std::string devDemux = str( boost::format(
49             "/dev/dvb/adapter%d/demux%d") % adapter % device);
50     int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
51     if (f < 0){
52         SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
53     }
54     fd(f);
55 }
56
57 prefix_ unsigned senf::DVBDemuxSectionSocketProtocol::available()
58     const
59 {
60     return 4096;
61 }
62
63 prefix_ void senf::DVBDemuxSectionSocketProtocol::setSectionFilter(unsigned short int pid, unsigned char filter, unsigned int flags, unsigned char mask, unsigned char mode, unsigned int timeout)
64     const
65 {
66     struct dmx_sct_filter_params sec_filter;
67     ::memset(&sec_filter, 0, sizeof(struct dmx_sct_filter_params));
68     sec_filter.pid = pid;
69     sec_filter.filter.filter[0] = filter;
70     sec_filter.filter.mask[0] = mask;
71     sec_filter.filter.mode[0] = mode;
72     sec_filter.flags = flags;
73        
74     if (::ioctl(fd(), DMX_SET_FILTER, &sec_filter) < 0)
75         SENF_THROW_SYSTEM_EXCEPTION("Could not set section filter of DVB adapter.");
76 }
77
78 // ----------------------------------------------------------------
79
80 prefix_ void senf::DVBDemuxPESSocketProtocol::init_client(unsigned short adapter, unsigned short device)
81     const
82 {
83     std::string devDemux = str( boost::format(
84             "/dev/dvb/adapter%d/demux%d") % adapter % device);
85     int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
86     if (f < 0)
87         SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
88     fd(f);
89 }
90
91 prefix_ unsigned senf::DVBDemuxPESSocketProtocol::available()
92     const
93 {
94     return 4096; //???
95 }
96
97 prefix_ void senf::DVBDemuxPESSocketProtocol::setPESFilter(struct dmx_pes_filter_params *filter)
98     const
99 {
100     if (::ioctl(fd(), DMX_SET_PES_FILTER, filter) < 0)
101         SENF_THROW_SYSTEM_EXCEPTION("Could not set PES filter of DVB adapter.");
102 }
103
104 // ----------------------------------------------------------------
105
106 prefix_ void senf::DVBDvrSocketProtocol::init_client(unsigned short adapter, unsigned short device)
107     const
108 {
109     std::string devDvr = str( boost::format(
110             "/dev/dvb/adapter%d/dvr%d") % adapter % device);
111     int f = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK);
112     if (f < 0)
113         SENF_THROW_SYSTEM_EXCEPTION("Could not open dvr device of DVB adapter ") << devDvr << ".";
114     fd(f);
115 }
116
117 prefix_ unsigned senf::DVBDvrSocketProtocol::available()
118     const
119 {
120     return 188;
121 }
122
123 ///////////////////////////////cc.e////////////////////////////////////////
124 #undef prefix_
125 //#include "DVBDemuxHandles.mpp"
126
127 \f
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"
135 // comment-column: 40
136 // End: