4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Anton Gillert <atx@berlios.de>
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.
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.
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.
24 #ifndef DVBSOCKETCONTROLLER_HH_
25 #define DVBSOCKETCONTROLLER_HH_
27 #include "DVBFrontendHandle.hh"
28 #include "DVBDemuxHandles.hh"
31 #include <linux/dvb/frontend.h>
32 #include "senf/Scheduler/Scheduler.hh"
33 #include "DVBConfigParser.hh"
34 #include "senf/Console.hh"
36 #define MPE_TABLEID 62
39 /** \brief Helperclass for configuration and controlling DVB devices.<br><br>
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.
46 * Note that you may have to take draw backs in using this API. This dues to the implementation of the DVB device driver which you or your kernel choose.
47 * It has shown that the completeness of implementations vary from driver to driver.
48 * This wrapper provides the full Frontend API which is defined by <a href="http://www.linuxtv.org/docs/dvbapi/DVB_Frontend_API.html">Convergence </a>.
49 * You have to find out which parts of these functionality are implemented by your preferred device driver by your own.
51 class DVBSocketController : boost::noncopyable
54 senf::console::ScopedDirectory<DVBSocketController> dir;
56 typedef boost::function<void (const struct dvb_frontend_event & )> Callback; ///< Callback which is called when an asynchronous tuning succeeds.
57 /**< Callback which is called when an asynchronous tuning succeeds.*/
59 DVBSocketController(DVBFrontendHandle frontendHandle_ = DVBFrontendHandle(0,0), DVBDemuxSectionHandle sectionHandle_ = DVBDemuxSectionHandle(0,0), const Callback & cb = NULL);
60 ~DVBSocketController();
62 void tuneToCMD( const std::string & input, const std::string & mode = "async");///< Tunes a DVB device given by the type of the DVBFrontendHandle
63 /**< Tunes a DVB device by a channel name or complete configuration line. This method was created for use in Senf-Console.
64 \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.
65 \param[in] mode The mode in which it will tune "sync" or "async"*/
66 void tuneTo(const std::string & channel);
67 ///< Tunes a DVB device to a channel
68 /**< Tunes a DVB device to a channel whose parameters are stored in a configfile. The method determines the type of DVB device by it self.
69 \param[in] channel A channel name which will be looked up in config file.*/
71 void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
72 ///< Tunes a DVB-S device
73 /**< Tunes a DVB-S device in asynchronous mode and calls the callback if existing. Needs full configuration */
74 void tuneDVB_T(unsigned int frequency,
75 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
76 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
77 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
78 fe_modulation_t constellation, /* modulation type (see above) */
79 fe_transmit_mode_t transmission_mode,
80 fe_guard_interval_t guard_interval,
81 fe_hierarchy_t hierarchy_information); ///< Tunes a DVB-T device
82 /**< Tunes a DVB-T device in asynchronous mode and calls the callback if existing. Needs full configuration. */
83 void tuneDVB_C(unsigned int frequency,
84 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
85 fe_code_rate_t fec_inner, fe_modulation_t modulation);
86 ///< Tunes a DVB-C device
87 /**< Tunes a DVB-C device in asynchronous mode and calls the callback if existing. Needs full configuration. */
89 dvb_frontend_event tuneTo_sync( const std::string & channel );
90 ///< Tunes a DVB device given by the type of the DVBFrontendHandle
91 /**< Tunes a DVB device, given by the type of the DVBFrontendHandle, by a channel name in synchronous mode
92 \param[in] channel A channel name which will be looked up in config file.
93 \returns dvb_frontend_event
94 \note The member "dvb_frontend_event.status" should be correct by the
95 most device driver implementations. But "dvb_frontend_event.parameters" maybe not and is definitly not set by:
96 Cinergy T² (2.6.27), Terratec Cinergy DT USB XS Diversity (2.6.27)
99 dvb_frontend_event tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
100 ///< Tunes a DVB-S device
101 /**< Tunes a DVB-S device in synchronous mode. Needs full configuration
102 \returns dvb_frontend_event
103 \note The member "dvb_frontend_event.status" should be correct by the
104 most device driver implementations. But "dvb_frontend_event.parameters" maybe not and is definitly not set by:
105 Cinergy T² (2.6.27), Terratec Cinergy DT USB XS Diversity (2.6.27)
107 dvb_frontend_event tuneDVB_T_sync(unsigned int frequency,
108 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
109 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
110 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
111 fe_modulation_t constellation, /* modulation type (see above) */
112 fe_transmit_mode_t transmission_mode,
113 fe_guard_interval_t guard_interval,
114 fe_hierarchy_t hierarsourcechy_information);
115 ///< Tunes a DVB-T device
116 /**< Tunes a DVB-T device in synchronous mode. Needs full configuration
117 \returns dvb_frontend_event
118 \note The member "dvb_frontend_event.status" should be correct by the
119 most device driver implementations. But "dvb_frontend_event.parameters" maybe not and is definitly not set by:
120 Cinergy T² (2.6.27), Terratec Cinergy DT USB XS Diversity (2.6.27)
122 dvb_frontend_event tuneDVB_C_sync(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 synchronous mode. Needs full configuration
127 \returns dvb_frontend_event
128 \note The member "dvb_frontend_event.status" should be correct by the
129 most device driver implementations. But "dvb_frontend_event.parameters" maybe not and is definitly not set by:
130 Cinergy T² (2.6.27), Terratec Cinergy DT USB XS Diversity (2.6.27)
132 fe_type_t getType(); ///< Returns the type of the card. The type is defined in frontend.h
134 std::string getTypeString(); ///< Returns the type of the card.
135 /**< Returns the type of the card but human readable e.g. "DVB-S", "DVB-T" or "DVB-C"*/
137 std::string status2String(fe_status_t status);
138 ///< Returns a human readable status information
139 /**< Returns a human readable version of fe_status_t (defined by frontend.h)*/
141 unsigned int bitErrorRate(); ///< Returns the bit error rate
142 /**< Returns the bit error rate.
143 \note This function may not be implemented by your specific driver implementation. In this case the output is random. This is true for: Cinergy T² (2.6.27), Terratec Cinergy DT USB XS Diversity (2.6.27)*/
144 unsigned int signalToNoiseRatio();
145 ///< Returns the signal to noise ratio
146 /**< Returns the signal to noise ratio
147 \note This function may not be implemented by your specific driver implementation. In this case the output is random.*/
148 unsigned int signalStrength();
149 ///< Returns the signal strength
150 /**< Returns the signal to noise ratio
151 \note This function may not be implemented by your specific driver implementation. In this case the output is random.*/
153 void setSectionFilter(unsigned short int pid,
154 u_int8_t filter = MPE_TABLEID,
155 unsigned int flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC,
156 u_int8_t mask = 0xff,
158 unsigned int timeout = 0);
159 ///< Set the section filter
160 /**< Set the section filter.*/
162 void setBufferSize(unsigned long size);
163 ///< Set the size of the circular buffer used for filtered data.
164 /**< The default size is two maximum sized sections, i.e. if this
165 function is not called a buffer size of 2 * 4096 bytes will
167 \param[in] size Size of circular buffer. */
169 void startFiltering();
170 ///< Starts filtering
171 /**< Starts filtering.*/
173 void stopFiltering();
175 /**< Stops filtering.*/
177 std::string getTuneInfo(const std::string & conf ="Ssbuf"); ///< Returns a string which shows actual tuning status
178 /**< Returns a string which shows actual tuning status.
179 <br>"S" prints signal strength (in hex)
180 <br>"s" prints singal to noise ration (in hex)
181 <br>"b" prints bit error rate (in hex)
182 <br>"u" prints uncorrected blocks (in hex)
183 <br>"f" prints readable overal status e.g. "Has Lock"<br>
184 These characters can be used to form the output. Be aware, some
185 features may not be supported be your current driver implementation and
186 could end in throwing an exception!*/
188 DVBFrontendHandle frontendHandle;
189 senf::DVBDemuxSectionHandle sectionHandle;
191 DVBConfigParser parser;
193 senf::scheduler::FdEvent event;
195 void readEvent(int i);
200 #endif /*DVBSOCKETCONTROLLER_HH_*/