blob: 85d861782c3cf1a860e6a202eaadc2a21eb6d537
1 | // |
2 | // |
3 | // amlogic 2013 |
4 | // |
5 | // @ Project : tv |
6 | // @ File Name : |
7 | // @ Date : 2013-11 |
8 | // @ Author : |
9 | // |
10 | // |
11 | #include <am_scan.h> |
12 | #include <am_epg.h> |
13 | #include <am_mem.h> |
14 | #include <am_db.h> |
15 | #include "CTvChannel.h" |
16 | #include "CTvLog.h" |
17 | #include "CTvEv.h" |
18 | #include "tvin/CTvin.h" |
19 | |
20 | #if !defined(_CTVSCANNER_H) |
21 | #define _CTVSCANNER_H |
22 | class CTvScanner { |
23 | public: |
24 | /** ATSC Attenna type */ |
25 | static const int AM_ATSC_ATTENNA_TYPE_AIR = 1; |
26 | static const int AM_ATSC_ATTENNA_TYPE_CABLE_STD = 2; |
27 | static const int AM_ATSC_ATTENNA_TYPE_CABLE_IRC = 3; |
28 | static const int AM_ATSC_ATTENNA_TYPE_CABLE_HRC = 4; |
29 | CTvScanner(CTvin *pTvin); |
30 | ~CTvScanner(); |
31 | void setGlobalScanerObject(CTvScanner *); |
32 | int startScan(); |
33 | int stopScan(); |
34 | int ATVManualScan(int min_freq, int max_freq, int std, int store_Type = 0, int channel_num = 0); |
35 | int autoAtvScan(int min_freq, int max_freq, int std, int search_type); |
36 | int autoDtmbScan(); |
37 | int manualDtmbScan(int beginFreq, int endFreq, int modulation = -1); |
38 | int autoAtscScan(int attennaType, int std); |
39 | int manualDtmbScan(int freq); |
40 | int manualAtscScan(int freq, int attennaType, int std); |
41 | int autoTvScan(); |
42 | int unsubscribeEvent(); |
43 | |
44 | class ScannerEvent: public CTvEv { |
45 | public: |
46 | static const int EVENT_SCAN_PROGRESS = 0; |
47 | static const int EVENT_STORE_BEGIN = 1; |
48 | static const int EVENT_STORE_END = 2; |
49 | static const int EVENT_SCAN_END = 3; |
50 | static const int EVENT_BLINDSCAN_PROGRESS = 4; |
51 | static const int EVENT_BLINDSCAN_NEWCHANNEL = 5; |
52 | static const int EVENT_BLINDSCAN_END = 6; |
53 | static const int EVENT_ATV_PROG_DATA = 7; |
54 | static const int EVENT_DTV_PROG_DATA = 8; |
55 | |
56 | ScannerEvent(): CTvEv(CTvEv::TV_EVENT_SCANNER) |
57 | { |
58 | } |
59 | ~ScannerEvent() |
60 | { |
61 | } |
62 | |
63 | //common |
64 | int mType; |
65 | int mPercent; |
66 | int mTotalChannelCount; |
67 | int mLockedStatus; |
68 | int mChannelNumber; |
69 | //CTvChannel mChannel; |
70 | int mMode; |
71 | int mFrequency; |
72 | int mSymbolRate; |
73 | int mModulation; |
74 | int mBandwidth; |
75 | int mOfdm_mode; |
76 | |
77 | int mAudio; |
78 | int mStandard; |
79 | int mSat_polarisation; |
80 | // |
81 | int mStrength; |
82 | int mSnr; |
83 | char mProgramName[1024]; |
84 | int mprogramType; |
85 | char mMSG[128]; |
86 | //for atv |
87 | int mVideoStd; |
88 | int mAudioStd; |
89 | int mIsAutoStd;//1 is true |
90 | int mAfcData; |
91 | |
92 | |
93 | //for DTV |
94 | int mTsId; |
95 | int mONetId; |
96 | int mServiceId; |
97 | int mVid; |
98 | int mVfmt; |
99 | int mAcnt; |
100 | int mAid[32]; |
101 | int mAfmt[32]; |
102 | char mAlang[32][10]; |
103 | int mAtype[32]; |
104 | int mPcr; |
105 | |
106 | // ScannerEvent(int type){ |
107 | // this->mType = type; |
108 | // } |
109 | }; |
110 | |
111 | class IObserver { |
112 | public: |
113 | IObserver() {}; |
114 | virtual ~IObserver() {}; |
115 | virtual void onEvent(const ScannerEvent &ev) = 0; |
116 | }; |
117 | //1 VS n |
118 | //int addObserver(IObserver* ob); |
119 | //int removeObserver(IObserver* ob); |
120 | |
121 | //1 VS 1 |
122 | int setObserver(IObserver *ob) |
123 | { |
124 | mpObserver = ob; |
125 | return 0; |
126 | } |
127 | private: |
128 | static AM_Bool_t s_atv_cvbs_lock_check(void *); |
129 | AM_Bool_t atv_cvbs_lock_check(v4l2_std_id *colorStd); |
130 | static void tv_scan_evt_callback(long dev_no, int event_type, void *param, void *data); |
131 | static void am_scan_atv_store(AM_SCAN_Result_t *result); |
132 | void tv_scan_reconnect_dmx_to_fend(int dmx_no, int fend_no); |
133 | int getAtscChannelPara(int attennaType, Vector<sp<CTvChannel> > &vcp); |
134 | // |
135 | AM_SCAN_Handle_t mScanHandle; |
136 | volatile bool mbScanStart; |
137 | |
138 | //scan para info |
139 | /** General TV Scan Mode */ |
140 | static const int TV_MODE_ATV = 0; // Only search ATV |
141 | static const int TV_MODE_DTV = 1; // Only search DTV |
142 | static const int TV_MODE_ADTV = 2; // A/DTV will share a same frequency list, like ATSC |
143 | /** DTV scan mode */ |
144 | static const int DTV_MODE_AUTO = 1; |
145 | static const int DTV_MODE_MANUAL = 2; |
146 | static const int DTV_MODE_ALLBAND = 3; |
147 | static const int DTV_MODE_BLIND = 4; |
148 | |
149 | /** DTV scan options, DONOT channge */ |
150 | static const int DTV_OPTION_UNICABLE = 0x10; //Satellite unicable mode |
151 | static const int DTV_OPTION_FTA = 0x20; //Only store free programs |
152 | static const int DTV_OPTION_NO_TV = 0x40; //Only store tv programs |
153 | static const int DTV_OPTION_NO_RADIO = 0x80; //Only store radio programs |
154 | |
155 | /** ATV scan mode */ |
156 | static const int ATV_MODE_AUTO = 1; |
157 | static const int ATV_MODE_MANUAL = 2; |
158 | |
159 | // |
160 | #define AM_SCAN_MAX_SRV_NAME_LANG 4 |
161 | |
162 | typedef struct { |
163 | uint8_t srv_type, eit_sche, eit_pf, rs, free_ca, access_controlled, hidden, hide_guide, plp_id; |
164 | int vid, aid1, aid2, srv_id, pmt_pid, pcr_pid; |
165 | int vfmt, chan_num, afmt_tmp, vfmt_tmp, scrambled_flag, major_chan_num, minor_chan_num, source_id; |
166 | int src, srv_dbid, satpara_dbid; |
167 | char name[(AM_DB_MAX_SRV_NAME_LEN + 4)*AM_SCAN_MAX_SRV_NAME_LANG + 1]; |
168 | char *default_text_lang; |
169 | char *text_langs; |
170 | AM_SI_AudioInfo_t aud_info; |
171 | AM_SI_SubtitleInfo_t sub_info; |
172 | AM_SI_TeletextInfo_t ttx_info; |
173 | int sdt_version; |
174 | } SCAN_ServiceInfo_t; |
175 | |
176 | |
177 | static dvbpsi_pat_t *get_valid_pats(AM_SCAN_TS_t *ts); |
178 | static void scan_process_ts_info(AM_SCAN_Result_t *result, AM_SCAN_TS_t *ts, ScannerEvent *evt); |
179 | static void scan_init_service_info(SCAN_ServiceInfo_t *srv_info); |
180 | static int get_pmt_pid(dvbpsi_pat_t *pats, int program_number); |
181 | static void scan_extract_ca_scrambled_flag(dvbpsi_descriptor_t *p_first_descriptor, int *flag); |
182 | static void scan_extract_srv_info_from_sdt(AM_SCAN_Result_t *result, dvbpsi_sdt_t *sdts, SCAN_ServiceInfo_t *srv_info); |
183 | static void scan_update_service_info(AM_SCAN_Result_t *result, SCAN_ServiceInfo_t *srv_info); |
184 | static void scan_store_dvb_ts_evt_service(SCAN_ServiceInfo_t *srv); |
185 | static void scan_store_dvb_ts(AM_SCAN_Result_t *result, AM_SCAN_TS_t *ts); |
186 | static void dtv_scan_store(AM_SCAN_Result_t *result); |
187 | |
188 | |
189 | private: |
190 | |
191 | // |
192 | IObserver *mpObserver; |
193 | // |
194 | CTvin *mpTvin; |
195 | int mMode; |
196 | int mFendID; |
197 | /** DTV parameters */ |
198 | int mTvMode; |
199 | int mTvOptions; |
200 | int mSat_id; |
201 | int mSource; |
202 | |
203 | //showboz |
204 | //TVSatelliteParams tv_satparams; |
205 | int mTsSourceID; |
206 | CTvChannel mStartChannel; |
207 | Vector<CTvChannel> mvChooseListChannels; |
208 | /** ATV parameters */ |
209 | int mAtvMode; |
210 | int mStartFreq; |
211 | int mDirection; |
212 | int mChannelID; |
213 | |
214 | |
215 | |
216 | //extern for scanner |
217 | //int channelID; //can be used for manual scan |
218 | /** Atv set */ |
219 | int mMinFreq; |
220 | int mMaxFreq; |
221 | long long mCurScanStartFreq; |
222 | long long mCurScanEndFreq; |
223 | int tunerStd; |
224 | /** Tv set */ |
225 | int demuxID;//default 0 |
226 | String8 defaultTextLang; |
227 | String8 orderedTextLangs; |
228 | //showboz |
229 | //Vector<CTvChannel> ChannelList;//VS mvChooseListChannels |
230 | |
231 | /** Dtv-Sx set Unicable settings*/ |
232 | int user_band; |
233 | int ub_freq;//!< kHz |
234 | |
235 | ScannerEvent mCurEv; |
236 | static CTvScanner *m_s_Scanner; |
237 | }; |
238 | #endif //CTVSCANNER_H |
239 |