Added documentation for DVBSocketController
[senf.git] / 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 DVBSOCKETCONTROLLER_HH_
25 #define DVBSOCKETCONTROLLER_HH_
26
27 #include "DVBFrontendHandle.hh"
28 #include "DVBDemuxHandles.hh"
29 // Custom includes
30 #include <string>
31 #include <linux/dvb/frontend.h>
32 #include "senf/Scheduler/Scheduler.hh"
33 #include "DVBConfigParser.hh"
34 #include "senf/Console.hh"
35
36 #define MPE_TABLEID 62
37
38 namespace senf {
39     /** \brief Helperclass for configuration and controlling DVB devices.<br><br>
40      * 
41      * The DVB API provides two methods for tuning. The first method is 
42      * synchronous, which means e.g. "tuneTo_sync" will return when the tuning operation on the card succeed,
43      * no matter how long it takes. The second (preferred) method is to tune asynchronous. The call "tuneTo" will return 
44      * immediately and (if a callback was set) call the callback when the tuning operation succeeds.     
45      *   
46      */
47 class DVBSocketController : boost::noncopyable
48 {
49 public:
50     senf::console::ScopedDirectory<DVBSocketController> dir;
51     
52     typedef boost::function<void (const struct dvb_frontend_event & )> Callback; ///< Callback which is called when an asynchronous tuning succeeds.
53                                                                                  /**< Callback which is called when an asynchronous tuning succeeds.*/
54         
55     DVBSocketController(DVBFrontendHandle frontendHandle_ = DVBFrontendHandle(0,0), DVBDemuxSectionHandle sectionHandle_ = DVBDemuxSectionHandle(0,0), const Callback & cb = NULL);
56         ~DVBSocketController();
57         
58         void tuneToCMD( const std::string & input, const std::string & mode = "async");///< Tunes a DVB device given by the type of the DVBFrontendHandle
59                                                                                     /**< Tunes a DVB device by a channel name or complete configuration line.
60                                                                                     \param[in] input A channel name or a complete configuration line. If a channel name is given it would be searched in the config file.
61                                                                                         \param[in] mode The mode in which it will tune "sync" or "async"*/
62         void tuneTo(const std::string & channel);  
63                                                     ///< Tunes a DVB device given by the type of the DVBFrontendHandle
64                                                 /**< Tunes a DVB device, given by the type of the DVBFrontendHandle, by a channel name in asynchronous mode
65                                                      \param[in] channel A channel name which will be looked up in config file.*/
66         
67         void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
68                                                                                         ///< Tunes a DVB-S device
69                                                                                         /**< Tunes a DVB-S device in asynchronous mode and calls the callback if existing. Needs full configuration */
70         void tuneDVB_T(unsigned int frequency,
71                         fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
72                         fe_code_rate_t code_rate_HP, /* high priority stream code rate */
73                         fe_code_rate_t code_rate_LP, /* low priority stream code rate */
74                         fe_modulation_t constellation, /* modulation type (see above) */
75                         fe_transmit_mode_t transmission_mode,
76                         fe_guard_interval_t guard_interval,
77                         fe_hierarchy_t hierarchy_information);                          ///< Tunes a DVB-T device
78                                                                                         /**< Tunes a DVB-T device in asynchronous mode and calls the callback if existing. Needs full configuration. */
79         void tuneDVB_C(unsigned int frequency,
80                         fe_spectral_inversion_t inversion, unsigned int symbol_rate,
81                         fe_code_rate_t fec_inner, fe_modulation_t modulation); 
82                                                                                         ///< Tunes a DVB-C device
83                                                                                     /**< Tunes a DVB-C device in asynchronous mode and calls the callback if existing. Needs full configuration. */
84         
85         dvb_frontend_event tuneTo_sync( const std::string & channel );
86                                                                         ///< Tunes a DVB device given by the type of the DVBFrontendHandle
87                                                                     /**< Tunes a DVB device, given by the type of the DVBFrontendHandle, by a channel name in synchronous mode
88                                                                         \param[in] channel A channel name which will be looked up in config file.*/
89         
90         dvb_frontend_event tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
91                                                                                 ///< Tunes a DVB-S device
92                                                                                 /**< Tunes a DVB-S device in synchronous mode. Needs full configuration */
93     dvb_frontend_event tuneDVB_T_sync(unsigned int frequency,
94                 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
95                 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
96                 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
97                 fe_modulation_t constellation, /* modulation type (see above) */
98                 fe_transmit_mode_t transmission_mode,
99                 fe_guard_interval_t guard_interval,
100                 fe_hierarchy_t hierarsourcechy_information);                    
101                                                                                 ///< Tunes a DVB-T device
102                                                                                 /**< Tunes a DVB-T device in synchronous mode. Needs full configuration */
103     dvb_frontend_event tuneDVB_C_sync(unsigned int frequency,
104                 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
105                 fe_code_rate_t fec_inner, fe_modulation_t modulation); 
106                                                                                 ///< Tunes a DVB-C device
107                                                                                 /**< Tunes a DVB-C device in synchronous mode. Needs full configuration */
108     
109     fe_type_t getType(); ///< Returns the type of the card. The type is defined in frontend.h
110     
111     std::string getTypeString(); ///< Returns the type of the card.
112                                  /**< Returns the type of the card but human readable e.g. "DVB-S", "DVB-T" or "DVB-C"*/
113     
114     std::string status2String(fe_status_t status);
115                                     ///< Returns a human readable status information
116                                     /**< Returns a human readable version of fe_status_t (defined by frontend.h)*/
117     
118     unsigned int bitErrorRate(); ///< Returns the bit error rate
119                                  /**< Returns the bit error rate. 
120                                  \note This function may not be implemented by your specific driver implementation. In this case the output is random.*/
121     unsigned int signalToNoiseRatio();
122                                     ///< Returns the signal to noise ratio
123                                     /**< Returns the signal to noise ratio
124                                     \note This function may not be implemented by your specific driver implementation. In this case the output is random.*/
125     unsigned int signalStrength();
126                                     ///< Returns the signal strength
127                                     /**< Returns the signal to noise ratio
128                                     \note This function may not be implemented by your specific driver implementation. In this case the output is random.*/
129     
130     void setSectionFilter(unsigned short int pid, 
131                u_int8_t filter = MPE_TABLEID,
132                unsigned int flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC,
133                u_int8_t mask = 0xff, 
134                u_int8_t mode = 0,
135                unsigned int timeout = 0);
136                                     ///< Set the section filter
137                                     /**< Set the section filter.*/
138     
139     void setBufferSize(unsigned long size); 
140                             ///< Set the size of the circular buffer used for filtered data.
141                             /**< The default size is two maximum sized sections, i.e. if this
142                                  function is not called a buffer size of 2 * 4096 bytes will
143                                  be used.
144                                  \param[in] size Size of circular buffer. */
145     
146     void startFiltering();  
147                         ///< Starts filtering
148                         /**< Starts filtering.*/
149     
150     void stopFiltering();
151                         ///< Stops filtering
152                         /**< Stops filtering.*/
153     
154     std::string getTuneInfo(const std::string & conf ="Ssbuf"); ///< Returns a string which shows actual tuning status
155                                                                 /**< Returns a string which shows actual tuning status. 
156                                                                 <br>"S" prints signal strength (in hex)
157                                                                 <br>"s" prints singal to noise ration (in hex)
158                                                                 <br>"b" prints bit error rate (in hex)
159                                                                 <br>"u" prints uncorrected blocks (in hex) 
160                                                                 <br>"f" prints readable overal status e.g. "Has Lock"<br>
161                                                                 These characters can be used to form the output. Be aware, some 
162                                                                 features may not be supported be your current driver implementation and 
163                                                                 could end in throwing an exception!*/
164 private:
165     DVBFrontendHandle frontendHandle;
166     senf::DVBDemuxSectionHandle sectionHandle;
167     fe_type_t type;
168     DVBConfigParser parser;
169     Callback cb;
170     senf::scheduler::FdEvent event;
171     
172     void readEvent(int i);
173     void initConsole();
174 };
175
176 }
177 #endif /*DVBSOCKETCONTROLLER_HH_*/