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