switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Socket / Protocols / DVB / DVBDemuxHandles.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Thorsten Horstmann <tho@berlios.de>
27
28 /** \file
29     \brief DVBDemuxHandles non-inline non-template implementation */
30
31 #include "DVBDemuxHandles.hh"
32 //#include "DVBDemuxHandles.ih"
33
34 // Custom includes
35 #include <boost/format.hpp>
36 #include <sys/socket.h>
37 #include <sys/ioctl.h>
38 #include <fcntl.h>
39 #include <senf/Utils/Exception.hh>
40
41
42 //#include "DVBDemuxHandles.mpp"
43 #define prefix_
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
45
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 // senf::DVBDemuxHandles
48
49 prefix_ void senf::DVBDemuxSectionSocketProtocol::init_client(unsigned short adapter, unsigned short device)
50     const
51 {
52     std::string devDemux = str( boost::format("/dev/dvb/adapter%d/demux%d") % adapter % device);
53     int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
54     if (f < 0) {
55         SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
56     }
57     fd(f);
58 }
59
60 prefix_ unsigned senf::DVBDemuxSectionSocketProtocol::available()
61     const
62 {
63     return 4096;
64 }
65
66 prefix_ void senf::DVBDemuxSectionSocketProtocol::setSectionFilter(unsigned short int pid, unsigned char filter, unsigned int flags, unsigned char mask, unsigned char mode, unsigned int timeout)
67     const
68 {
69     struct dmx_sct_filter_params sec_filter;
70     ::memset(&sec_filter, 0, sizeof(struct dmx_sct_filter_params));
71     sec_filter.pid = pid;
72     sec_filter.filter.filter[0] = filter;
73     sec_filter.filter.mask[0] = mask;
74     sec_filter.filter.mode[0] = mode;
75     sec_filter.flags = flags;
76
77     if (::ioctl(fd(), DMX_SET_FILTER, &sec_filter) < 0)
78         SENF_THROW_SYSTEM_EXCEPTION("Could not set section filter of DVB adapter.");
79 }
80
81 // ----------------------------------------------------------------
82
83 prefix_ void senf::DVBDemuxPESSocketProtocol::init_client(unsigned short adapter, unsigned short device)
84     const
85 {
86     std::string devDemux = str( boost::format(
87             "/dev/dvb/adapter%d/demux%d") % adapter % device);
88     int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
89     if (f < 0)
90         SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
91     fd(f);
92 }
93
94 prefix_ unsigned senf::DVBDemuxPESSocketProtocol::available()
95     const
96 {
97     return 4096; //???
98 }
99
100 prefix_ void senf::DVBDemuxPESSocketProtocol::setPESFilter(unsigned short int pid, dmx_input_t input, dmx_output_t output, dmx_pes_type_t pesType, unsigned int flags)
101     const
102 {
103
104     struct dmx_pes_filter_params pes_filter;
105         ::memset(&pes_filter, 0, sizeof(struct dmx_pes_filter_params));
106         pes_filter.pid = pid;
107         pes_filter.input = input;
108         pes_filter.output = output;
109         pes_filter.pes_type = pesType;
110         pes_filter.flags = flags;
111
112     if (::ioctl(fd(), DMX_SET_PES_FILTER, &pes_filter) < 0)
113         SENF_THROW_SYSTEM_EXCEPTION("Could not set PES filter of DVB adapter.");
114 }
115
116 // ----------------------------------------------------------------
117
118 prefix_ void senf::DVBDvrSocketProtocol::init_client(unsigned short adapter, unsigned short device)
119     const
120 {
121     std::string devDvr = str( boost::format(
122             "/dev/dvb/adapter%d/dvr%d") % adapter % device);
123     int f = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK);
124     if (f < 0)
125         SENF_THROW_SYSTEM_EXCEPTION("Could not open dvr device of DVB adapter ") << devDvr << ".";
126     fd(f);
127 }
128
129 prefix_ unsigned senf::DVBDvrSocketProtocol::available()
130     const
131 {
132     return 188;
133 }
134
135 //-/////////////////////////////////////////////////////////////////////////////////////////////////
136 #undef prefix_
137 //#include "DVBDemuxHandles.mpp"
138
139 \f
140 // Local Variables:
141 // mode: c++
142 // fill-column: 100
143 // c-file-style: "senf"
144 // indent-tabs-mode: nil
145 // ispell-local-dictionary: "american"
146 // compile-command: "scons -u test"
147 // comment-column: 40
148 // End: