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