read back corrected frequency from frontend during scan (only DVB-T)
[enigma2.git] / lib / dvb / scan.h
1 #ifndef __lib_dvb_scan_h
2 #define __lib_dvb_scan_h
3
4 #include <dvbsi++/service_description_section.h>
5 #include <dvbsi++/network_information_section.h>
6 #include <dvbsi++/bouquet_association_section.h>
7 #include <dvbsi++/program_association_section.h>
8 #include <dvbsi++/program_map_section.h>
9
10 #include <lib/dvb/idemux.h>
11 #include <lib/dvb/esection.h>
12 #include <lib/dvb/db.h>
13
14 struct service
15 {
16         service(unsigned short pmtPid)
17                 :pmtPid(pmtPid), serviceType(0xFF), scrambled(false)
18         {
19         }
20         unsigned short pmtPid;
21         unsigned char serviceType;
22         bool scrambled;
23 };
24
25 class eDVBScan: public Object, public iObject
26 {
27         DECLARE_REF(eDVBScan);
28                 /* chid helper functions: */
29                 
30                 /* heuristically determine if onid/tsid is valid */
31         int isValidONIDTSID(int orbital_position, eOriginalNetworkID onid, eTransportStreamID tsid);
32                 /* build dvb namespace */
33         eDVBNamespace buildNamespace(eOriginalNetworkID onid, eTransportStreamID tsid, unsigned long hash);
34         
35                 /* scan resources */    
36         eUsePtr<iDVBChannel> m_channel;
37         ePtr<iDVBDemux> m_demux;
38         
39                 /* infrastructure */
40         void stateChange(iDVBChannel *);
41         ePtr<eConnection> m_stateChanged_connection;
42
43                 /* state handling */    
44         RESULT nextChannel();
45         
46         RESULT startFilter();   
47         enum { readyPAT=1, readySDT=2, readyNIT=4, readyBAT=8,
48                validPAT=16, validSDT=32, validNIT=64, validBAT=128};
49
50                 /* scan state variables */
51         int m_channel_state;
52         int m_ready, m_ready_all;
53
54         std::map<eDVBChannelID, unsigned int> m_corrected_frequencys;  // yet just used for DVB-T
55
56         std::map<eDVBChannelID, ePtr<iDVBFrontendParameters> > m_new_channels;
57         std::map<eServiceReferenceDVB, ePtr<eDVBService> > m_new_services;
58         std::map<eServiceReferenceDVB, ePtr<eDVBService> >::iterator m_last_service;
59
60         std::map<unsigned short, service> m_pmts_to_read;
61         std::map<unsigned short, service>::iterator m_pmt_in_progress;
62         bool m_pmt_running;
63         bool m_abort_current_pmt;
64
65         std::list<ePtr<iDVBFrontendParameters> > m_ch_toScan, m_ch_scanned, m_ch_unavailable;
66         ePtr<iDVBFrontendParameters> m_ch_current;
67         eDVBChannelID m_chid_current;
68         eTransportStreamID m_pat_tsid;
69
70         ePtr<eTable<ServiceDescriptionSection> > m_SDT;
71         ePtr<eTable<NetworkInformationSection> > m_NIT;
72         ePtr<eTable<BouquetAssociationSection> > m_BAT;
73         ePtr<eTable<ProgramAssociationSection> > m_PAT;
74         ePtr<eTable<ProgramMapSection> > m_PMT;
75
76         void SDTready(int err);
77         void NITready(int err);
78         void BATready(int err);
79         void PATready(int err);
80         void PMTready(int err);
81
82         void addKnownGoodChannel(const eDVBChannelID &chid, iDVBFrontendParameters *feparm);
83         void addChannelToScan(const eDVBChannelID &chid, iDVBFrontendParameters *feparm);
84
85         int sameChannel(iDVBFrontendParameters *ch1, iDVBFrontendParameters *ch2, bool exact=false) const;
86
87         void channelDone();
88         
89         Signal1<void,int> m_event;
90         RESULT processSDT(eDVBNamespace dvbnamespace, const ServiceDescriptionSection &sdt);
91         
92         int m_flags;
93         bool m_usePAT;
94         bool m_scan_debug;
95 public:
96         eDVBScan(iDVBChannel *channel, bool usePAT=true, bool debug=true );
97         ~eDVBScan();
98
99         enum {
100                 scanNetworkSearch = 1, scanSearchBAT = 2,
101                 scanRemoveServices = 4, scanDontRemoveFeeds = 8,
102                 scanDontRemoveUnscanned = 16,
103                 clearToScanOnFirstNIT = 32, scanOnlyFree = 64 };
104
105         void start(const eSmartPtrList<iDVBFrontendParameters> &known_transponders, int flags);
106
107         enum { evtUpdate, evtNewService, evtFinish, evtFail };
108         RESULT connectEvent(const Slot1<void,int> &event, ePtr<eConnection> &connection);
109         void insertInto(iDVBChannelList *db, bool dontRemoveNewFlags=false);
110         
111         void getStats(int &transponders_done, int &transponders_total, int &services);
112         void getLastServiceName(std::string &name);
113         RESULT getFrontend(ePtr<iDVBFrontend> &);
114         RESULT getCurrentTransponder(ePtr<iDVBFrontendParameters> &);
115         eDVBChannelID getCurrentChannelID() { return m_chid_current; }
116 };
117
118 #endif