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