blob: 5f9fd40f0b8cd51fe7038678094c7db9f218c311
1 | // |
2 | // |
3 | // amlogic 2013 |
4 | // |
5 | // @ Project : tv |
6 | // @ File Name : CTvDatabase.cpp |
7 | // @ Date : 2013-11 |
8 | // @ Author : |
9 | // |
10 | // |
11 | #include <assert.h> |
12 | #include <tinyxml.h> |
13 | #include "CTvDatabase.h" |
14 | #include "tvutils/tvutils.h" |
15 | #include "../tvconfig/tvconfig.h" |
16 | |
17 | #ifdef LOG_TAG |
18 | #undef LOG_TAG |
19 | #define LOG_TAG "CTvDatabase" |
20 | #endif |
21 | |
22 | const char *CTvDatabase::DEFAULT_DB_PATH = "/param/tv_default.xml"; |
23 | |
24 | const char *CTvDatabase::DB_VERSION_FIELD = "DATABASE_VERSION"; |
25 | using namespace android; |
26 | |
27 | CTvDatabase *CTvDatabase::mpDb = NULL; |
28 | |
29 | const char CTvDatabase::feTypes[][32] = {"dvbs", "dvbc", "dvbt", "atsc", "analog", "dtmb"}; |
30 | const char CTvDatabase::srvTypes[][32] = {"other", "dtv", "radio", "atv", "other"}; |
31 | const char CTvDatabase::vidFmts[][32] = {"mpeg12", "mpeg4", "h264", "mjpeg", "real", "jpeg", "vc1", "avs"}; |
32 | const char CTvDatabase::audFmts[][32] = {"mpeg", "pcm_s16le", "aac", "ac3", "alaw", "mulaw", "dts", "pcm_s16be", |
33 | "flac", "cook", "pcm_u8", "adpcm", "amr", "raac", "wma", "wma_pro", |
34 | "pcm_bluray", "alac", "vorbis", "aac_latm", "ape", "eac3", "pcm_wifidisplay" |
35 | }; |
36 | const char CTvDatabase::mods[][32] = {"qpsk", "qam16", "qam32", "qam64", "qam128", "qam256", "qamauto", "vsb8", "vsb16", "psk8", "apsk16", "apsk32", "dqpsk"}; |
37 | const char CTvDatabase::bandwidths[][32] = {"8", "7", "6", "auto", "5", "10", "1_712"}; |
38 | const char CTvDatabase::lnbPowers[][32] = {"13v", "18V", "off", "13/18v"}; |
39 | const char CTvDatabase::sig22K[][32] = {"on", "off", "auto"}; |
40 | const char CTvDatabase::tonebursts[][32] = {"none", "bursta", "burstb"}; |
41 | const char CTvDatabase::diseqc10s[][32] = {"lnb1", "lnb2", "lnb3", "lnb4", "none"}; |
42 | const char CTvDatabase::diseqc11s[][32] = {"lnb1", "lnb2", "lnb3", "lnb4", "lnb5", "lnb6", "lnb7", "lnb8", |
43 | "lnb9", "lnb10", "lnb11", "lnb12", "lnb13", "lnb14", "lnb15", "lnb16", "none" |
44 | }; |
45 | const char CTvDatabase::motors[][32] = {"none", "none", "none", "diseqc1.2", "diseqc1.3"}; |
46 | const char CTvDatabase::ofdmModes[][32] = {"dvbt", "dvbt2"}; |
47 | const char CTvDatabase::atvVideoStds[][32] = {"auto", "pal", "ntsc", "secam"}; |
48 | const char CTvDatabase::atvAudioStds[][32] = {"dk", "i", "bg", "m", "l", "auto"}; |
49 | |
50 | CTvDatabase::CTvDatabase() |
51 | { |
52 | } |
53 | |
54 | int CTvDatabase::isFreqListExist() |
55 | { |
56 | String8 cmd = String8("select * from region_table"); |
57 | CTvDatabase::Cursor c; |
58 | select(cmd, c); |
59 | return c.moveToFirst(); |
60 | } |
61 | int CTvDatabase::UnInitTvDb() |
62 | { |
63 | AM_DB_UnSetup(); |
64 | closeDb(); |
65 | return 0; |
66 | } |
67 | int CTvDatabase::InitTvDb(const char *path) |
68 | { |
69 | if (path != NULL) { |
70 | if (Tv_Utils_IsFileExist(path) && config_get_int("TV", "tv_db_created", 0) == 1) { //exist or created |
71 | LOGD("tv db file(%s) exist and created, open it", path); |
72 | if (openDb(path) < 0 ) { |
73 | LOGD("db(%s) open fail", path); |
74 | return -1; |
75 | } |
76 | //setup and path set |
77 | AM_DB_Setup((char *)path, getHandle()); |
78 | if (isFreqListExist() == false) { |
79 | importXmlToDB("/etc/tv_default.xml"); |
80 | LOGD("scan region table is NULL, so import freq XML again\n"); |
81 | } |
82 | } else { |
83 | if (Tv_Utils_IsFileExist(path)) { // if just exist, create flag not set, delete it |
84 | LOGD("tv db file (%s) exist, but delete it", path); |
85 | if (unlink(path) != 0) { |
86 | LOGD("delete tv db file(%s) err=%s", path, strerror(errno)); |
87 | } |
88 | } |
89 | LOGD("tv db file(%s) not exist, create it", path); |
90 | //setup and path set |
91 | sqlite3 *h = NULL; |
92 | AM_DB_Setup((char *)path, h); |
93 | //create db |
94 | AM_DB_GetHandle(&h); |
95 | //create table |
96 | AM_DB_CreateTables(h); |
97 | setHandle(h); |
98 | //clear db |
99 | ClearDbTable(); |
100 | //insert 256 ATV Program |
101 | //load init date |
102 | importXmlToDB("/etc/tv_default.xml"); |
103 | config_set_int("TV", "tv_db_created", 1); |
104 | } |
105 | |
106 | } |
107 | return 0; |
108 | } |
109 | //CTvDatabase::CTvDatabase(char* path, sqlite3 * h) |
110 | //{ |
111 | /*if(path != NULL && h != NULL) |
112 | {//setup and path set |
113 | AM_DB_Setup((char*)path, h); |
114 | mHandle = h; |
115 | }else |
116 | { |
117 | mHandle = NULL; |
118 | }*/ |
119 | //} |
120 | |
121 | CTvDatabase::~CTvDatabase() |
122 | { |
123 | AM_DB_UnSetup(); |
124 | } |
125 | |
126 | int CTvDatabase::getChannelParaList(char *path, Vector<sp<ChannelPara> > &vcp) |
127 | { |
128 | //?????o?????aXML????????£?ˉ1è±???? |
129 | TiXmlDocument myDocument(path); |
130 | bool ret = myDocument.LoadFile(); |
131 | //è?·?????1????′? |
132 | TiXmlElement *RootElement = myDocument.RootElement(); |
133 | //dvbc |
134 | TiXmlElement *channel_list_element = RootElement->FirstChildElement("channel_list"); |
135 | for (TiXmlElement *channel_entry = channel_list_element->FirstChildElement("channel_entry") ; channel_entry != NULL; channel_entry = channel_entry->NextSiblingElement("channel_entry")) { |
136 | sp<ChannelPara> pCp = new ChannelPara(); |
137 | channel_entry->Attribute("frequency", &(pCp->freq)); |
138 | channel_entry->Attribute("modulation", &(pCp->modulation)); |
139 | channel_entry->Attribute("symbol_rate", &(pCp->symbol_rate)); |
140 | vcp.push_back(pCp); |
141 | } |
142 | return vcp.size(); |
143 | } |
144 | |
145 | int CTvDatabase::ClearDbTable() |
146 | { |
147 | LOGD(LOG_TAG, "Clearing database ..."); |
148 | exeSql("delete from net_table"); |
149 | exeSql("delete from ts_table"); |
150 | exeSql("delete from srv_table"); |
151 | exeSql("delete from evt_table"); |
152 | exeSql("delete from booking_table"); |
153 | exeSql("delete from grp_table"); |
154 | exeSql("delete from grp_map_table"); |
155 | exeSql("delete from dimension_table"); |
156 | exeSql("delete from sat_para_table"); |
157 | exeSql("delete from region_table"); |
158 | return 0; |
159 | } |
160 | |
161 | int CTvDatabase::clearDbAllProgramInfoTable() |
162 | { |
163 | LOGD(LOG_TAG, "Clearing clearDbAllProgramInfoTable ..."); |
164 | exeSql("delete from net_table"); |
165 | exeSql("delete from ts_table"); |
166 | exeSql("delete from srv_table"); |
167 | exeSql("delete from evt_table"); |
168 | exeSql("delete from booking_table"); |
169 | exeSql("delete from grp_table"); |
170 | exeSql("delete from grp_map_table"); |
171 | exeSql("delete from dimension_table"); |
172 | exeSql("delete from sat_para_table"); |
173 | return 0; |
174 | } |
175 | |
176 | //showboz now just channellist |
177 | int CTvDatabase::importXmlToDB(const char *xmlPath) |
178 | { |
179 | //delete region table before importing xml |
180 | exeSql("delete from region_table"); |
181 | |
182 | //?????o?????aXML????????£?ˉ1è±???? |
183 | TiXmlDocument myDocument(xmlPath); |
184 | bool ret = myDocument.LoadFile(); |
185 | |
186 | //è?·?????1????′? |
187 | TiXmlElement *RootElement = myDocument.RootElement(); |
188 | beginTransaction();//----------------------------------------------- |
189 | //list-->entry |
190 | for (TiXmlElement *channel_list_element = RootElement->FirstChildElement("channel_list"); channel_list_element != NULL; channel_list_element = channel_list_element->NextSiblingElement("channel_list")) { |
191 | //LOGD("showboz-----channel_list =%d", channel_list_element); |
192 | const char *channel_name = channel_list_element->Attribute("name"); |
193 | const char *channel_fe_type = channel_list_element->Attribute("fe_type"); |
194 | //LOGD("showboz-----channel_list name = %s type=%s", channel_name, channel_fe_type); |
195 | |
196 | for (TiXmlElement *channel_entry = channel_list_element->FirstChildElement("channel_entry") ; channel_entry != NULL; channel_entry = channel_entry->NextSiblingElement("channel_entry")) { |
197 | int freq, symb, channelNum; |
198 | String8 cmd = String8("insert into region_table(name,fe_type,frequency,symbol_rate,modulation,bandwidth,ofdm_mode,logical_channel_num)"); |
199 | cmd += String8("values('") + channel_name + String8("',") + String8::format("%d", StringToIndex(feTypes, channel_fe_type)) + String8(","); |
200 | channel_entry->Attribute("frequency", &freq); |
201 | cmd += String8::format("%d", freq) + String8(","); |
202 | channel_entry->Attribute("symbol_rate", &symb); |
203 | cmd += String8::format("%d", symb) + String8(","); |
204 | //LOGD("showboz---------m=%s,b=%s,o=%s", channel_entry->Attribute("modulation"), channel_entry->Attribute("bandwidth"), channel_entry->Attribute("ofdm_mode")); |
205 | cmd += String8::format("%d", StringToIndex(mods, channel_entry->Attribute("modulation"))) + String8(","); |
206 | cmd += String8::format("%d", StringToIndex(bandwidths, channel_entry->Attribute("bandwidth"))) + String8(","); |
207 | cmd += String8::format("%d", StringToIndex(ofdmModes, channel_entry->Attribute("ofdm_mode"))) + String8(","); |
208 | channel_entry->Attribute("logical_channel_num", &channelNum); |
209 | cmd += String8::format("%d", channelNum) + String8(")"); |
210 | exeSql(cmd.string()); |
211 | } |
212 | } |
213 | |
214 | commitTransaction();//------------------------------------------------------ |
215 | return 0; |
216 | } |
217 | |
218 | bool CTvDatabase::isAtv256ProgInsertForSkyworth() |
219 | { |
220 | String8 select_ts_atvcount = String8("select * from ts_table where src = 4"); |
221 | Cursor c; |
222 | select(select_ts_atvcount, c); |
223 | return c.getCount() < 256 ? false : true; |
224 | } |
225 | |
226 | int CTvDatabase::insert256AtvProgForSkyworth() |
227 | { |
228 | beginTransaction(); |
229 | for (int i = 0; i < 256; i++) { |
230 | String8 insert_ts = String8("insert into ts_table(db_id, src, db_net_id, ts_id, freq, symb, mod, bw, snr, ber, strength, db_sat_para_id, polar, std, aud_mode, flags, dvbt_flag) values ("); |
231 | insert_ts += String8::format("'%d'", i); |
232 | insert_ts += String8(", '4', '-1', '-1', '44250000', '0', '0', '0', '0', '0', '0', '-1', '-1', '-1', '1', '0', '0')"); |
233 | exeSql(insert_ts.string()); |
234 | String8 insert_srv = String8("insert into srv_table(db_id, src, db_net_id, db_ts_id, name, service_id, service_type, eit_schedule_flag, eit_pf_flag, running_status, free_ca_mode, volume, aud_track, pmt_pid, vid_pid, vid_fmt, scrambled_flag, current_aud, aud_pids, aud_fmts, aud_langs, aud_types, current_sub, sub_pids, sub_types, sub_composition_page_ids, sub_ancillary_page_ids, sub_langs, current_ttx, ttx_pids, ttx_types, ttx_magazine_nos, ttx_page_nos, ttx_langs, chan_num, skip, lock, favor, lcn, sd_lcn, hd_lcn, default_chan_num, chan_order, lcn_order, service_id_order, hd_sd_order, db_sat_para_id, dvbt2_plp_id, major_chan_num, minor_chan_num, access_controlled, hidden, hide_guide, source_id, sdt_ver) values ("); |
235 | insert_srv += String8::format("'%d'", i); |
236 | insert_srv += String8(" , '4', '-1', "); |
237 | insert_srv += String8::format("'%d'", i); |
238 | insert_srv += String8(", 'xxxATV Program', '-1', '3', '-1', '-1', '-1', '-1', '50', '1', '-1', '-1', '-1', '0', '-1', '-1', '-1', 'Audio1', '0', '-1', ' ', ' ', ' ', ' ', ' ', '-1', ' ', ' ', ' ', ' ', ' ', '-1', '1', '0', '0', '-1', '-1', '-1', '-1', "); |
239 | insert_srv += String8::format("'%d'", i); |
240 | insert_srv += String8(" , '0', '0', '0', '-1', '255', '0', '0', '0', '0', '0', '0', '255') "); |
241 | exeSql(insert_srv.string()); |
242 | } |
243 | commitTransaction(); |
244 | return 0; |
245 | } |
246 | |
247 | void CTvDatabase::deleteTvDb() |
248 | { |
249 | if (mpDb != NULL) { |
250 | delete mpDb; |
251 | mpDb = NULL; |
252 | } |
253 | } |
254 | CTvDatabase *CTvDatabase::GetTvDb() |
255 | { |
256 | if (mpDb == NULL) { |
257 | mpDb = new CTvDatabase(); |
258 | } |
259 | return mpDb; |
260 | } |
261 |