3cf9e5a68b29b4c1d2c48e61696cfde44e68aac8
[senf.git] / senf / Socket / Protocols / DVB / DVBSocketController.hh
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 //     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_DVBSocketController_
25 #define HH_SENF_Socket_Protocols_DVB_DVBSocketController_ 1
26
27 // Custom includes
28 #include <string>
29 #include <linux/dvb/frontend.h>
30 #include "DVBFrontendHandle.hh"
31 #include "DVBDemuxHandles.hh"
32 #include "DVBConfigParser.hh"
33 #include <senf/Scheduler/FdEvent.hh>
34 #include <senf/Utils/Console/ScopedDirectory.hh>
35
36 ///////////////////////////////hh.p////////////////////////////////////////
37 namespace senf {
38
39 #define MPE_TABLEID 62
40
41 /** \brief Helperclass for configuration and controlling DVB devices.
42
43      The DVB API provides two methods for tuning. The first method is
44      synchronous, which means e.g. "tuneTo_sync" will return when the tuning operation on the card
45      succeed, no matter how long it takes. The second (preferred) method is to tune asynchronous.
46      The call "tuneTo" will return immediately and (if a callback was set) call the callback when
47      the tuning operation succeeds. <br>
48
49      Note that you may have to take draw backs in using this API. This dues to the implementation
50      of the DVB device driver which you or your kernel choose. It has shown that the completeness
51      of implementations vary from driver to driver. This wrapper provides the full Frontend API which
52      is defined by <a href="http://www.linuxtv.org/docs/dvbapi/DVB_Frontend_API.html">Convergence</a>.
53      You have to find out which parts of these functionality are implemented by your preferred
54      device driver by your own.
55 */
56 class DVBSocketController : boost::noncopyable
57 {
58 public:
59
60     console::ScopedDirectory<DVBSocketController> dir;
61
62     typedef boost::function<void (const struct dvb_frontend_event & )> Callback;
63                                         ///< Callback which is called when an asynchronous tuning succeeds.
64
65     DVBSocketController(DVBFrontendHandle frontendHandle_ = DVBFrontendHandle(0,0), const Callback & cb = NULL);
66     ~DVBSocketController();
67
68     DVBDemuxSectionHandle createDVBDemuxSectionHandle(  int adapternumber=0, int demuxnumber=0, bool addToConsole=false );
69     DVBDemuxPESHandle createDVBDemuxPESHandle(  int adapternumber=0, int demuxnumber=0, bool addToConsole=false );
70
71     void addToConsole(DVBDemuxSectionHandle sh);
72                                         ///< Adds an DVBDemuxSectionHandle to the console
73                                         /**< Allocates the functionality of DVBDemuxSectionProtocol
74                                              into the folder of the DVBSocketController. If the
75                                              protocol is closed, or all handles are discarded the
76                                              console support will automatically removed.
77                                              \param[in] sh handle of a protocol*/
78
79     void addToConsole(DVBDemuxPESHandle sh);
80                                         ///< Adds an DVBDemuxPESHandle to the console
81                                         /**< Allocates the functionality of DVBDemuxPESProtocol into
82                                              the folder of the DVBSocketController. If the protocol
83                                              is closed, or all handles are discarded the console
84                                              support will automatically removed.
85                                              \param[in] sh handle of a protocol*/
86
87     void tuneToCMD(std::string const & input, std::string const & mode = "async");
88                                         ///< Tunes a DVB device given by the type of the DVBFrontendHandle
89                                         /**< Tunes a DVB device by a channel name or complete
90                                              configuration line. This method was created for use
91                                              in the SENF-Console.
92                                              \param[in] input A channel name or a complete
93                                                configuration line. If a channel name is given
94                                                it would be searched in the config file.
95                                              \param[in] mode The mode in which it will tune
96                                                "sync" or "async"*/
97     void tuneTo(std::string const & channel);
98                                         ///< Tunes a DVB device to a channel
99                                         /**< Tunes a DVB device to a channel whose parameters
100                                              are stored in a config file. The method determines
101                                              the type of DVB device by it self.
102                                              \param[in] channel A channel name which will be
103                                                  looked up in config file.*/
104
105     void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
106                                         ///< Tunes a DVB-S device
107                                         /**< Tunes a DVB-S device in asynchronous mode and calls
108                                              the callback if existing. Needs full configuration */
109
110     void tuneDVB_T(unsigned int frequency,
111                     fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
112                     fe_code_rate_t code_rate_HP, /* high priority stream code rate */
113                     fe_code_rate_t code_rate_LP, /* low priority stream code rate */
114                     fe_modulation_t constellation, /* modulation type (see above) */
115                     fe_transmit_mode_t transmission_mode,
116                     fe_guard_interval_t guard_interval,
117                     fe_hierarchy_t hierarchy_information);
118                                         ///< Tunes a DVB-T device
119                                         /**< Tunes a DVB-T device in asynchronous mode and calls
120                                              the callback if existing. Needs full configuration. */
121
122     void tuneDVB_C(unsigned int frequency,
123                     fe_spectral_inversion_t inversion, unsigned int symbol_rate,
124                     fe_code_rate_t fec_inner, fe_modulation_t modulation);
125                                         ///< Tunes a DVB-C device
126                                         /**< Tunes a DVB-C device in asynchronous mode and calls
127                                              the callback if existing. Needs full configuration. */
128
129     dvb_frontend_event tuneTo_sync(std::string const & channel );
130                                         ///< Tunes a DVB device given by the type of the DVBFrontendHandle
131                                         /**< Tunes a DVB device, given by the type of the
132                                              DVBFrontendHandle, by a channel name in synchronous mode
133                                              \param[in] channel A channel name which will be looked
134                                                  up in config file.
135                                              \returns dvb_frontend_event
136                                              \note The member "dvb_frontend_event.status" should be
137                                                correct by the most device driver implementations.
138                                                But "dvb_frontend_event.parameters" maybe not and is
139                                                definitely not set by: Cinergy T� (2.6.27),
140                                                Terratec Cinergy DT USB XS Diversity (2.6.27) */
141
142     dvb_frontend_event tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
143                                         ///< Tunes a DVB-S device
144                                         /**< Tunes a DVB-S device in synchronous mode. Needs full configuration
145                                              \returns dvb_frontend_event
146                                              \note The member "dvb_frontend_event.status" should be
147                                                correct by the most device driver implementations.
148                                                But "dvb_frontend_event.parameters" maybe not and is
149                                                definitely not set by: Cinergy T� (2.6.27),
150                                                Terratec Cinergy DT USB XS Diversity (2.6.27) */
151
152     dvb_frontend_event tuneDVB_T_sync(unsigned int frequency,
153                 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
154                 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
155                 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
156                 fe_modulation_t constellation, /* modulation type (see above) */
157                 fe_transmit_mode_t transmission_mode,
158                 fe_guard_interval_t guard_interval,
159                 fe_hierarchy_t hierarsourcechy_information);
160                                         ///< Tunes a DVB-T device
161                                         /**< Tunes a DVB-T device in synchronous mode. Needs full
162                                              configuration
163                                              \returns dvb_frontend_event
164                                              \note The member "dvb_frontend_event.status" should be
165                                                correct by the most device driver implementations.
166                                                But "dvb_frontend_event.parameters" maybe not and is
167                                                definitely not set by: Cinergy T� (2.6.27),
168                                                Terratec Cinergy DT USB XS Diversity (2.6.27) */
169
170     dvb_frontend_event tuneDVB_C_sync(unsigned int frequency,
171                 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
172                 fe_code_rate_t fec_inner, fe_modulation_t modulation);
173                                         ///< Tunes a DVB-C device
174                                         /**< Tunes a DVB-C device in synchronous mode. Needs full configuration
175                                              \returns dvb_frontend_event
176                                              \note The member "dvb_frontend_event.status" should be
177                                                correct by the most device driver implementations.
178                                                But "dvb_frontend_event.parameters" maybe not and is
179                                                definitely not set by: Cinergy T� (2.6.27),
180                                                Terratec Cinergy DT USB XS Diversity (2.6.27) */
181
182     fe_type_t getType();                ///< Returns the type of the card. The type is defined in frontend.h
183
184     std::string getTypeString();        ///< Returns the type of the card.
185                                         /**< Returns the type of the card but human readable e.g.
186                                              "DVB-S", "DVB-T" or "DVB-C"*/
187
188     std::string status2String(fe_status_t status);
189                                         ///< Returns a human readable status information
190                                         /**< Returns a human readable version of fe_status_t
191                                              (defined by frontend.h)*/
192
193     unsigned int bitErrorRate();        ///< Returns the bit error rate
194                                         /**< \note This function may not be implemented by your
195                                              specific driver implementation. In this case the
196                                              output is random. This is true for:
197                                                Cinergy T� (2.6.27),
198                                                Terratec Cinergy DT USB XS Diversity (2.6.27) */
199
200     unsigned int signalToNoiseRatio();  ///< Returns the signal to noise ratio
201                                         /**< \note This function may not be implemented by your
202                                              specific driver implementation. In this case the
203                                              output is random. This is true for:
204                                                Cinergy T� (2.6.27),
205                                                Terratec Cinergy DT USB XS Diversity (2.6.27) */
206
207     unsigned int signalStrength();      ///< Returns the signal strength
208                                         /**< Returns the signal to noise ratio
209                                              \note This function may not be implemented by your
210                                              specific driver implementation. In this case the output is
211                                              random.*/
212
213     std::string getTuneInfo(const std::string & conf ="Ssbuf");
214                                         ///< Returns a string which shows actual tuning status
215                                         /**< <br>"S" prints signal strength (in hex)
216                                              <br>"s" prints signal to noise ration (in hex)
217                                              <br>"b" prints bit error rate (in hex)
218                                              <br>"u" prints uncorrected blocks (in hex)
219                                              <br>"f" prints readable overall status e.g. "Has Lock"<br>
220                                              These characters can be used to form the output. Be
221                                              aware, some features may not be supported be your
222                                              current driver implementation and could end in throwing
223                                              an exception! */
224 private:
225     DVBFrontendHandle frontendHandle;
226     fe_type_t type;
227     DVBConfigParser parser;
228     Callback cb;
229     static unsigned int controllerNr;
230     unsigned int sectionNr;
231     unsigned int pesNr;
232     scheduler::FdEvent event;
233     void readEvent(int i);
234     void initConsole();
235 };
236
237 }
238
239 ///////////////////////////////hh.e////////////////////////////////////////
240 //#include "DVBSocketController.cci"
241 //#include "DVBSocketController.ct"
242 //#include "DVBSocketController.cti"
243 #endif