aefab8fbdcb4340fc01bb821d4baa893393d353e
[senf.git] / senf / 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 <senf/Utils/Exception.hh>
35
36
37 //#include "DVBDemuxHandles.mpp"
38 #define prefix_
39 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 // senf::DVBDemuxHandles
43
44 prefix_ void senf::DVBDemuxSectionSocketProtocol::init_client(unsigned short adapter, unsigned short device)
45     const
46 {
47     std::string devDemux = str( boost::format("/dev/dvb/adapter%d/demux%d") % adapter % device);
48     int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
49     if (f < 0) {
50         SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
51     }
52     fd(f);
53 }
54
55 prefix_ unsigned senf::DVBDemuxSectionSocketProtocol::available()
56     const
57 {
58     return 4096;
59 }
60
61 prefix_ void senf::DVBDemuxSectionSocketProtocol::setSectionFilter(unsigned short int pid, unsigned char filter, unsigned int flags, unsigned char mask, unsigned char mode, unsigned int timeout)
62     const
63 {
64     struct dmx_sct_filter_params sec_filter;
65     ::memset(&sec_filter, 0, sizeof(struct dmx_sct_filter_params));
66     sec_filter.pid = pid;
67     sec_filter.filter.filter[0] = filter;
68     sec_filter.filter.mask[0] = mask;
69     sec_filter.filter.mode[0] = mode;
70     sec_filter.flags = flags;
71
72     if (::ioctl(fd(), DMX_SET_FILTER, &sec_filter) < 0)
73         SENF_THROW_SYSTEM_EXCEPTION("Could not set section filter of DVB adapter.");
74 }
75
76 // ----------------------------------------------------------------
77
78 prefix_ void senf::DVBDemuxPESSocketProtocol::init_client(unsigned short adapter, unsigned short device)
79     const
80 {
81     std::string devDemux = str( boost::format(
82             "/dev/dvb/adapter%d/demux%d") % adapter % device);
83     int f = open(devDemux.c_str(), O_RDONLY | O_NONBLOCK);
84     if (f < 0)
85         SENF_THROW_SYSTEM_EXCEPTION("Could not open demux device of DVB adapter ") << devDemux << ".";
86     fd(f);
87 }
88
89 prefix_ unsigned senf::DVBDemuxPESSocketProtocol::available()
90     const
91 {
92     return 4096; //???
93 }
94
95 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)
96     const
97 {
98
99     struct dmx_pes_filter_params pes_filter;
100         ::memset(&pes_filter, 0, sizeof(struct dmx_pes_filter_params));
101         pes_filter.pid = pid;
102         pes_filter.input = input;
103         pes_filter.output = output;
104         pes_filter.pes_type = pesType;
105         pes_filter.flags = flags;
106
107     if (::ioctl(fd(), DMX_SET_PES_FILTER, &pes_filter) < 0)
108         SENF_THROW_SYSTEM_EXCEPTION("Could not set PES filter of DVB adapter.");
109 }
110
111 // ----------------------------------------------------------------
112
113 prefix_ void senf::DVBDvrSocketProtocol::init_client(unsigned short adapter, unsigned short device)
114     const
115 {
116     std::string devDvr = str( boost::format(
117             "/dev/dvb/adapter%d/dvr%d") % adapter % device);
118     int f = open(devDvr.c_str(), O_RDONLY | O_NONBLOCK);
119     if (f < 0)
120         SENF_THROW_SYSTEM_EXCEPTION("Could not open dvr device of DVB adapter ") << devDvr << ".";
121     fd(f);
122 }
123
124 prefix_ unsigned senf::DVBDvrSocketProtocol::available()
125     const
126 {
127     return 188;
128 }
129
130 //-/////////////////////////////////////////////////////////////////////////////////////////////////
131 #undef prefix_
132 //#include "DVBDemuxHandles.mpp"
133
134 \f
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // comment-column: 40
143 // End: