cc694c62d195ac0e6489c645e975c372e762b446
[senf.git] / Socket / Protocols / DVB / DVBProtocolWrapper.hh
1 // $Id: DVBSocketController.hh 1119 2009-02-16 13:36:59Z tho $
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Anton Gillert <atx@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
24 #ifndef HH_SENF_Socket_Protocols_DVB_DVBProtocolWrapper_
25 #define HH_SENF_Socket_Protocols_DVB_DVBProtocolWrapper_ 1
26 #include "senf/Utils/Console/Console.hh"
27 #include "senf/Utils/Console/Console.hh"
28 #include "DVBDemuxHandles.hh"
29 // Custom includes
30
31 SENF_CONSOLE_REGISTER_ENUM( dmx_input_t, (DMX_IN_FRONTEND)(DMX_IN_DVR) )
32 ;
33 SENF_CONSOLE_REGISTER_ENUM( dmx_output_t, (DMX_OUT_DECODER)(DMX_OUT_TAP)(DMX_OUT_TS_TAP) )
34 ;
35 SENF_CONSOLE_REGISTER_ENUM( dmx_pes_type_t, (DMX_PES_AUDIO0)(DMX_PES_VIDEO0)(DMX_PES_TELETEXT0)(DMX_PES_SUBTITLE0)(DMX_PES_PCR0)
36         (DMX_PES_AUDIO1)(DMX_PES_VIDEO1)(DMX_PES_TELETEXT1)(DMX_PES_SUBTITLE1)(DMX_PES_PCR1)
37         (DMX_PES_AUDIO2)(DMX_PES_VIDEO2)(DMX_PES_TELETEXT2)(DMX_PES_SUBTITLE2)(DMX_PES_PCR2)
38         (DMX_PES_AUDIO3)(DMX_PES_VIDEO3)(DMX_PES_TELETEXT3)(DMX_PES_SUBTITLE3)(DMX_PES_PCR3)
39         (DMX_PES_OTHER))
40 ;
41
42 namespace senf {
43
44     /** \brief Helperclass for configuration and controlling DVB protokoll handles.
45
46
47      */
48
49     class DVBSectionProtocolWrapper : public senf::DVBProtocolWrapper {
50
51 public:
52         enum Flags {CHECK_CRC = DMX_CHECK_CRC,
53             ONESHOT = DMX_ONESHOT,
54             IMMEDIATE_START = DMX_IMMEDIATE_START,
55             KERNEL_CLIENT = DMX_KERNEL_CLIENT};
56         senf::console::ScopedDirectory<DVBSectionProtocolWrapper> dir;
57 private:
58         const senf::DVBDemuxSectionSocketProtocol& protocol;
59 public:
60         DVBSectionProtocolWrapper(senf::DVBDemuxSectionHandle sh) :
61             dir(this), protocol(sh.protocol()) {
62
63             namespace kw = senf::console::kw;
64             dir.add("buffersize", &DVBSectionProtocolWrapper::setBufferSize)
65             .doc("Set the size of the circular buffer used for filtered data.")
66             .arg("size", "in byte");
67
68             dir.add("start", &DVBSectionProtocolWrapper::startFiltering)
69             .doc("Starts filtering");
70
71             dir.add("stop", &DVBSectionProtocolWrapper::setBufferSize)
72             .doc("Stops filtering");
73
74             dir.node().add("filter", boost::function<void (unsigned short int, unsigned, senf::console::FlagCollection<Flags>, unsigned, unsigned, unsigned)>(senf::membind(&DVBSectionProtocolWrapper::setSectionFilter, this)))
75             .arg("pid", "pid to filter")
76             .arg("filter", "filter", kw::default_value = 62, kw::default_doc = "0x3e")
77             .arg("flags", "or-able: CHECK_CRC, ONESHOT, IMMEDIATE_START, KERNEL_CLIENT", kw::default_value = DMX_IMMEDIATE_START | DMX_CHECK_CRC, kw::default_doc = "(IMMEDIATE_START CHECK_CRC)")
78             .arg("mask", "mask", kw::default_value = 0xff, kw::default_doc = "0xff")
79             .arg("mode", "mode", kw::default_value = 0, kw::default_doc = "0x00")
80             .arg("timeout", "timeout", kw::default_value = 0, kw::default_doc = "0x00")
81             .doc("Sets parameters for section filter.");
82
83             dir.add("stop", &DVBSectionProtocolWrapper::setBufferSize)
84             .doc("Stops filtering");
85         }
86         ~DVBSectionProtocolWrapper() {
87         }
88         void setSectionFilter(unsigned short int pid, u_int8_t filter,
89                 unsigned int flags, u_int8_t mask, u_int8_t mode,
90                 unsigned int timeout) {
91             protocol.setSectionFilter(pid, timeout, flags, filter, mask, mode);
92
93         }
94
95         ///< Set the size of the circular buffer used for filtered data.
96         /**< The default size is two maximum sized sections, i.e. if
97          this function is not called a buffer size of 2 * 4096
98          bytes will be used.
99          \param[in] size Size of circular buffer. */
100         void setBufferSize(unsigned long size) {
101             protocol.setBufferSize(size);
102         }
103
104         void startFiltering() ///< Starts filtering
105         {
106             protocol.startFiltering();
107         }
108
109         void stopFiltering() ///< Stops filtering
110         {
111             protocol.stopFiltering();
112         }
113
114     };
115     SENF_CONSOLE_REGISTER_ENUM_MEMBER(DVBSectionProtocolWrapper, Flags,
116             (CHECK_CRC)(ONESHOT)(IMMEDIATE_START)(KERNEL_CLIENT))
117     ;
118
119     class DVBPESProtocolWrapper : public senf::DVBProtocolWrapper {
120
121 public:
122         enum Flags {CHECK_CRC = DMX_CHECK_CRC,
123             ONESHOT = DMX_ONESHOT,
124             IMMEDIATE_START = DMX_IMMEDIATE_START,
125             KERNEL_CLIENT = DMX_KERNEL_CLIENT};
126         senf::console::ScopedDirectory<DVBPESProtocolWrapper> dir;
127 private:
128         const senf::DVBDemuxPESSocketProtocol& protocol;
129 public:
130         DVBPESProtocolWrapper(senf::DVBDemuxPESHandle sh) :
131             dir(this), protocol(sh.protocol()) {
132             namespace kw = senf::console::kw;
133
134             dir.node().add("filter", boost::function<void ( unsigned short int, dmx_input_t, dmx_output_t, dmx_pes_type_t, senf::console::FlagCollection<Flags>)>(senf::membind(&DVBPESProtocolWrapper::setPESFilter, this)))
135             .arg("pid", "pid to filter")
136             .arg("input", "input-filter: DMX_IN_FRONTEND DMX_IN_DVR ")
137             .arg("output", "output-filter: DMX_OUT_DECODER DMX_OUT_TAP DMX_OUT_TS_TAP ")
138             .arg("pesType", "PES type: DMX_PES_AUDIO[0-3] DMX_PES_VIDEO[0-3] DMX_PES_TELETEXT[0-3], DMX_PES_SUBTITLE[0-3], DMX_PES_PCR[0-3], DMX_PES_OTHER")
139             .arg("flags", "or-able: CHECK_CRC, ONESHOT, IMMEDIATE_START, KERNEL_CLIENT", kw::default_value = DMX_IMMEDIATE_START | DMX_CHECK_CRC, kw::default_doc = "(IMMEDIATE_START CHECK_CRC)")
140             .doc("Sets parameters for PES filter.");
141             dir.add("start", &DVBPESProtocolWrapper::startFiltering)
142             .doc("Starts filtering");
143
144             dir.add("stop", &DVBPESProtocolWrapper::stopFiltering)
145             .doc("Stops filtering");
146         }
147         ~DVBPESProtocolWrapper() {
148         }
149         ;
150
151         void setPESFilter(unsigned short int pid, dmx_input_t input,
152                 dmx_output_t output, dmx_pes_type_t pesType, unsigned int flags) {
153             protocol.setPESFilter(pid, input, output, pesType, flags);
154         }
155         void startFiltering() ///< Starts filtering
156         {
157             protocol.startFiltering();
158         }
159
160         void stopFiltering() ///< Stops filtering
161         {
162             protocol.stopFiltering();
163         }
164     };
165     SENF_CONSOLE_REGISTER_ENUM_MEMBER(DVBPESProtocolWrapper, Flags,
166             (CHECK_CRC)(ONESHOT)(IMMEDIATE_START)(KERNEL_CLIENT))
167     ;
168 }
169
170 #endif
171