9d214408192f9b31abe1274ad75fcccfed5722fb
[senf.git] / Socket / Protocols / DVB / DVBSocketController.hh
1 #ifndef DVBSOCKETCONTROLLER_HH_
2 #define DVBSOCKETCONTROLLER_HH_
3
4 #include "DVBFrontendHandle.hh"
5 #include "DVBDemuxHandles.hh"
6 // Custom includes
7 #include <string>
8 #include <linux/dvb/frontend.h>
9 #include <senf/Scheduler/Scheduler.hh>
10 #include "DVBConfigParser.hh"
11 #include <senf/Console.hh>
12
13 #define MPE_TABLEID 62
14
15 namespace senf {
16     std::string status2String(fe_status_t status);
17 class DVBSocketController : boost::noncopyable
18 {
19 public:
20     senf::console::ScopedDirectory<DVBSocketController> dir;
21     
22     typedef boost::function<void (const struct dvb_frontend_event & )> Callback;
23         
24     DVBSocketController(DVBFrontendHandle frontendHandle_ = DVBFrontendHandle(0,0), DVBDemuxSectionHandle sectionHandle_ = DVBDemuxSectionHandle(0,0), const Callback & cb = NULL);
25         ~DVBSocketController();
26         
27         std::string tuneToCMD( const std::string & channel, const std::string & mode = "async");
28         
29         void tuneTo(const std::string & channel);
30         
31         void tuneDVB_S(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
32                                                                                         ///< Tunes a DVB-S device
33                                                                                         /**< Tunes a DVB-S device. Needs full configuration */
34         void tuneDVB_T(unsigned int frequency,
35                         fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
36                         fe_code_rate_t code_rate_HP, /* high priority stream code rate */
37                         fe_code_rate_t code_rate_LP, /* low priority stream code rate */
38                         fe_modulation_t constellation, /* modulation type (see above) */
39                         fe_transmit_mode_t transmission_mode,
40                         fe_guard_interval_t guard_interval,
41                         fe_hierarchy_t hierarchy_information);                                                      ///< Tunes a DVB-T device
42                                                                                         /**< Tunes a DVB-T device. Needs full configuration */
43         void tuneDVB_C(unsigned int frequency,
44                         fe_spectral_inversion_t inversion, unsigned int symbol_rate,
45                         fe_code_rate_t fec_inner, fe_modulation_t modulation); 
46         
47         dvb_frontend_event tuneTo_sync( const std::string & channel );
48         
49         dvb_frontend_event tuneDVB_S_sync(unsigned int frequency, fe_spectral_inversion_t inversion, unsigned int symbole_rate, fe_code_rate_t code_rate);
50                                                                                 ///< Tunes a DVB-S device
51                                                                                 /**< Tunes a DVB-S device. Needs full configuration */
52     dvb_frontend_event tuneDVB_T_sync(unsigned int frequency,
53                 fe_spectral_inversion_t inversion, fe_bandwidth_t bandwidth,
54                 fe_code_rate_t code_rate_HP, /* high priority stream code rate */
55                 fe_code_rate_t code_rate_LP, /* low priority stream code rate */
56                 fe_modulation_t constellation, /* modulation type (see above) */
57                 fe_transmit_mode_t transmission_mode,
58                 fe_guard_interval_t guard_interval,
59                 fe_hierarchy_t hierarsourcechy_information);                                                      ///< Tunes a DVB-T device
60                                                                                 /**< Tunes a DVB-T device. Needs full configuration */
61     dvb_frontend_event tuneDVB_C_sync(unsigned int frequency,
62                 fe_spectral_inversion_t inversion, unsigned int symbol_rate,
63                 fe_code_rate_t fec_inner, fe_modulation_t modulation); 
64     
65     fe_type_t getType();
66     
67     std::string getTypeString();
68     
69     std::string status2String(fe_status_t status);
70     unsigned int bitErrorRate();
71     unsigned int signalToNoiseRatio();
72     unsigned int signalStrength();
73     
74     void setSectionFilter(unsigned short int pid, 
75                unsigned char filter = MPE_TABLEID,
76                unsigned int flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC,
77                unsigned char mask = 0xff, 
78                unsigned char mode = 0,
79                unsigned int timeout = 0);
80     
81     void setBufferSize(unsigned long size); 
82                             ///< set the size of the circular buffer used for filtered data.
83                             /**< The default size is two maximum sized sections, i.e. if this
84                                  function is not called a buffer size of 2 * 4096 bytes will
85                                  be used.
86                                  \param[in] size Size of circular buffer. */
87     
88     void startFiltering();
89     
90     void stopFiltering();
91     
92     std::string getTuneInfo(const std::string & conf ="Ssbuf"); ///< Returns a string which shows actual tuning status
93                                                                 /**< Returns a string which shows actual tuning status. 
94                                                                 "S" prints signal strength (in hex)
95                                                                 "s" prints singal to noise ration (in hex)
96                                                                 "b" prints bit error rate (in hex)
97                                                                 "u" prints uncorrected blocks (in hex) 
98                                                                 "f" prints readable overal status e.g. "Has Lock"
99                                                                 These characters can be used to form the output. Be aware, some 
100                                                                 features may not be supported be your current driver implementation and 
101                                                                 could end in throwing an exception!*/
102 private:
103     DVBFrontendHandle frontendHandle;
104     senf::DVBDemuxSectionHandle sectionHandle;
105     fe_type_t type;
106     DVBConfigParser parser;
107     Callback cb;
108     senf::scheduler::FdEvent event;
109     
110     void readEvent(int i);
111     void initConsole();
112 };
113
114 }
115 #endif /*DVBSOCKETCONTROLLER_HH_*/