blob: 8176ad1fcc64e854a333418481d0f6b0bc03794f
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 | static const int EVENT_SCAN_EXIT = 9; |
56 | |
57 | ScannerEvent(): CTvEv(CTvEv::TV_EVENT_SCANNER) |
58 | { |
59 | clear(); |
60 | } |
61 | void clear() |
62 | { |
63 | mType = -1; |
64 | mProgramName[0] = '\0'; |
65 | mMSG[0] = '\0'; |
66 | mAcnt = 0; |
67 | mScnt = 0; |
68 | } |
69 | ~ScannerEvent() |
70 | { |
71 | } |
72 | |
73 | //common |
74 | int mType; |
75 | int mPercent; |
76 | int mTotalChannelCount; |
77 | int mLockedStatus; |
78 | int mChannelNumber; |
79 | //CTvChannel mChannel; |
80 | int mMode; |
81 | int mFrequency; |
82 | int mSymbolRate; |
83 | int mModulation; |
84 | int mBandwidth; |
85 | int mOfdm_mode; |
86 | |
87 | int mAudio; |
88 | int mStandard; |
89 | int mSat_polarisation; |
90 | // |
91 | int mStrength; |
92 | int mSnr; |
93 | char mProgramName[1024]; |
94 | int mprogramType; |
95 | char mMSG[128]; |
96 | //for atv |
97 | int mVideoStd; |
98 | int mAudioStd; |
99 | int mIsAutoStd;//1 is true |
100 | int mAfcData; |
101 | |
102 | |
103 | //for DTV |
104 | int mTsId; |
105 | int mONetId; |
106 | int mServiceId; |
107 | int mVid; |
108 | int mVfmt; |
109 | int mAcnt; |
110 | int mAid[32]; |
111 | int mAfmt[32]; |
112 | char mAlang[32][10]; |
113 | int mAtype[32]; |
114 | int mPcr; |
115 | |
116 | int mScnt; |
117 | int mStype[32]; |
118 | int mSid[32]; |
119 | int mSstype[32]; |
120 | int mSid1[32]; |
121 | int mSid2[32]; |
122 | char mSlang[32][10]; |
123 | |
124 | // ScannerEvent(int type){ |
125 | // this->mType = type; |
126 | // } |
127 | }; |
128 | |
129 | class IObserver { |
130 | public: |
131 | IObserver() {}; |
132 | virtual ~IObserver() {}; |
133 | virtual void onEvent(const ScannerEvent &ev) = 0; |
134 | }; |
135 | //1 VS n |
136 | //int addObserver(IObserver* ob); |
137 | //int removeObserver(IObserver* ob); |
138 | |
139 | //1 VS 1 |
140 | int setObserver(IObserver *ob) |
141 | { |
142 | mpObserver = ob; |
143 | return 0; |
144 | } |
145 | private: |
146 | static AM_Bool_t s_atv_cvbs_lock_check(void *); |
147 | AM_Bool_t atv_cvbs_lock_check(v4l2_std_id *colorStd); |
148 | static void tv_scan_evt_callback(long dev_no, int event_type, void *param, void *data); |
149 | static void am_scan_atv_store(AM_SCAN_Result_t *result); |
150 | void tv_scan_reconnect_dmx_to_fend(int dmx_no, int fend_no); |
151 | int getAtscChannelPara(int attennaType, Vector<sp<CTvChannel> > &vcp); |
152 | void sendEvent(ScannerEvent &evt); |
153 | // |
154 | AM_SCAN_Handle_t mScanHandle; |
155 | volatile bool mbScanStart; |
156 | |
157 | //scan para info |
158 | /** General TV Scan Mode */ |
159 | static const int TV_MODE_ATV = 0; // Only search ATV |
160 | static const int TV_MODE_DTV = 1; // Only search DTV |
161 | static const int TV_MODE_ADTV = 2; // A/DTV will share a same frequency list, like ATSC |
162 | /** DTV scan mode */ |
163 | static const int DTV_MODE_AUTO = 1; |
164 | static const int DTV_MODE_MANUAL = 2; |
165 | static const int DTV_MODE_ALLBAND = 3; |
166 | static const int DTV_MODE_BLIND = 4; |
167 | |
168 | /** DTV scan options, DONOT channge */ |
169 | static const int DTV_OPTION_UNICABLE = 0x10; //Satellite unicable mode |
170 | static const int DTV_OPTION_FTA = 0x20; //Only store free programs |
171 | static const int DTV_OPTION_NO_TV = 0x40; //Only store tv programs |
172 | static const int DTV_OPTION_NO_RADIO = 0x80; //Only store radio programs |
173 | |
174 | /** ATV scan mode */ |
175 | static const int ATV_MODE_AUTO = 1; |
176 | static const int ATV_MODE_MANUAL = 2; |
177 | |
178 | // |
179 | /*subtitle*/ |
180 | static const int TYPE_DVB_SUBTITLE = 1; |
181 | static const int TYPE_DTV_TELETEXT = 2; |
182 | static const int TYPE_ATV_TELETEXT = 3; |
183 | static const int TYPE_DTV_CC = 4; |
184 | static const int TYPE_ATV_CC = 5; |
185 | |
186 | #define AM_SCAN_MAX_SRV_NAME_LANG 4 |
187 | |
188 | typedef struct { |
189 | uint8_t srv_type, eit_sche, eit_pf, rs, free_ca, access_controlled, hidden, hide_guide, plp_id; |
190 | int vid, aid1, aid2, srv_id, pmt_pid, pcr_pid; |
191 | int vfmt, chan_num, afmt_tmp, vfmt_tmp, scrambled_flag, major_chan_num, minor_chan_num, source_id; |
192 | int src, srv_dbid, satpara_dbid; |
193 | char name[(AM_DB_MAX_SRV_NAME_LEN + 4)*AM_SCAN_MAX_SRV_NAME_LANG + 1]; |
194 | char *default_text_lang; |
195 | char *text_langs; |
196 | AM_SI_AudioInfo_t aud_info; |
197 | AM_SI_SubtitleInfo_t sub_info; |
198 | AM_SI_TeletextInfo_t ttx_info; |
199 | int sdt_version; |
200 | } SCAN_ServiceInfo_t; |
201 | |
202 | |
203 | static dvbpsi_pat_t *get_valid_pats(AM_SCAN_TS_t *ts); |
204 | static void scan_process_ts_info(AM_SCAN_Result_t *result, AM_SCAN_TS_t *ts, ScannerEvent *evt); |
205 | static void scan_init_service_info(SCAN_ServiceInfo_t *srv_info); |
206 | static int get_pmt_pid(dvbpsi_pat_t *pats, int program_number); |
207 | static void scan_extract_ca_scrambled_flag(dvbpsi_descriptor_t *p_first_descriptor, int *flag); |
208 | static void scan_extract_srv_info_from_sdt(AM_SCAN_Result_t *result, dvbpsi_sdt_t *sdts, SCAN_ServiceInfo_t *srv_info); |
209 | static void scan_update_service_info(AM_SCAN_Result_t *result, SCAN_ServiceInfo_t *srv_info); |
210 | static void scan_store_dvb_ts_evt_service(SCAN_ServiceInfo_t *srv); |
211 | static void scan_store_dvb_ts(AM_SCAN_Result_t *result, AM_SCAN_TS_t *ts); |
212 | static void dtv_scan_store(AM_SCAN_Result_t *result); |
213 | |
214 | |
215 | private: |
216 | |
217 | // |
218 | IObserver *mpObserver; |
219 | // |
220 | CTvin *mpTvin; |
221 | int mMode; |
222 | int mFendID; |
223 | /** DTV parameters */ |
224 | int mTvMode; |
225 | int mTvOptions; |
226 | int mSat_id; |
227 | int mSource; |
228 | |
229 | //showboz |
230 | //TVSatelliteParams tv_satparams; |
231 | int mTsSourceID; |
232 | CTvChannel mStartChannel; |
233 | Vector<CTvChannel> mvChooseListChannels; |
234 | /** ATV parameters */ |
235 | int mAtvMode; |
236 | int mStartFreq; |
237 | int mDirection; |
238 | int mChannelID; |
239 | |
240 | |
241 | |
242 | //extern for scanner |
243 | //int channelID; //can be used for manual scan |
244 | /** Atv set */ |
245 | int mMinFreq; |
246 | int mMaxFreq; |
247 | long long mCurScanStartFreq; |
248 | long long mCurScanEndFreq; |
249 | int tunerStd; |
250 | /** Tv set */ |
251 | int demuxID;//default 0 |
252 | String8 defaultTextLang; |
253 | String8 orderedTextLangs; |
254 | //showboz |
255 | //Vector<CTvChannel> ChannelList;//VS mvChooseListChannels |
256 | |
257 | /** Dtv-Sx set Unicable settings*/ |
258 | int user_band; |
259 | int ub_freq;//!< kHz |
260 | |
261 | ScannerEvent mCurEv; |
262 | static CTvScanner *m_s_Scanner; |
263 | }; |
264 | #endif //CTVSCANNER_H |
265 |