blob: 9b8698b6ebb04a1c0333ce241b857dd2c477ae84
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 | return 0; |
65 | } |
66 | int CTvDatabase::InitTvDb(const char *path) |
67 | { |
68 | if (path != NULL) { |
69 | if (Tv_Utils_IsFileExist(path) == 0 && config_get_int("TV", "tv_db_created", 0) == 1) { //exist or created |
70 | LOGD("tv db file(%s) exist and created, open it", path); |
71 | if (openDb(path) < 0 ) { |
72 | LOGD("db(%s) open fail", path); |
73 | return -1; |
74 | } |
75 | //setup and path set |
76 | AM_DB_Setup((char *)path, getHandle()); |
77 | if (isFreqListExist() == false) { |
78 | importXmlToDB("/etc/tv_default.xml"); |
79 | LOGD("scan region table is NULL, so import freq XML again\n"); |
80 | } |
81 | } else { |
82 | if (Tv_Utils_IsFileExist(path) == 0) { // if just exist, create flag not set, delete it |
83 | LOGD("tv db file (%s) exist, but delete it", path); |
84 | if (unlink(path) != 0) { |
85 | LOGD("delete tv db file(%s) err=%s", path, strerror(errno)); |
86 | } |
87 | } |
88 | LOGD("tv db file(%s) not exist, create it", path); |
89 | //setup and path set |
90 | sqlite3 *h = NULL; |
91 | AM_DB_Setup((char *)path, h); |
92 | //create db |
93 | AM_DB_GetHandle(&h); |
94 | //create table |
95 | AM_DB_CreateTables(h); |
96 | setHandle(h); |
97 | //clear db |
98 | ClearDbTable(); |
99 | //insert 256 ATV Program |
100 | //load init date |
101 | importXmlToDB("/etc/tv_default.xml"); |
102 | config_set_int("TV", "tv_db_created", 1); |
103 | } |
104 | |
105 | } |
106 | return 0; |
107 | } |
108 | //CTvDatabase::CTvDatabase(char* path, sqlite3 * h) |
109 | //{ |
110 | /*if(path != NULL && h != NULL) |
111 | {//setup and path set |
112 | AM_DB_Setup((char*)path, h); |
113 | mHandle = h; |
114 | }else |
115 | { |
116 | mHandle = NULL; |
117 | }*/ |
118 | //} |
119 | |
120 | CTvDatabase::~CTvDatabase() |
121 | { |
122 | AM_DB_UnSetup(); |
123 | } |
124 | |
125 | int CTvDatabase::getChannelParaList(char *path, Vector<sp<ChannelPara> > &vcp) |
126 | { |
127 | //?????o?????aXML????????£?ˉ1è±???? |
128 | TiXmlDocument myDocument(path); |
129 | bool ret = myDocument.LoadFile(); |
130 | //è?·?????1????′? |
131 | TiXmlElement *RootElement = myDocument.RootElement(); |
132 | //dvbc |
133 | TiXmlElement *channel_list_element = RootElement->FirstChildElement("channel_list"); |
134 | for (TiXmlElement *channel_entry = channel_list_element->FirstChildElement("channel_entry") ; channel_entry != NULL; channel_entry = channel_entry->NextSiblingElement("channel_entry")) { |
135 | sp<ChannelPara> pCp = new ChannelPara(); |
136 | channel_entry->Attribute("frequency", &(pCp->freq)); |
137 | channel_entry->Attribute("modulation", &(pCp->modulation)); |
138 | channel_entry->Attribute("symbol_rate", &(pCp->symbol_rate)); |
139 | vcp.push_back(pCp); |
140 | } |
141 | return vcp.size(); |
142 | } |
143 | |
144 | int CTvDatabase::ClearDbTable() |
145 | { |
146 | LOGD(LOG_TAG, "Clearing database ..."); |
147 | exeSql("delete from net_table"); |
148 | exeSql("delete from ts_table"); |
149 | exeSql("delete from srv_table"); |
150 | exeSql("delete from evt_table"); |
151 | exeSql("delete from booking_table"); |
152 | exeSql("delete from grp_table"); |
153 | exeSql("delete from grp_map_table"); |
154 | exeSql("delete from dimension_table"); |
155 | exeSql("delete from sat_para_table"); |
156 | exeSql("delete from region_table"); |
157 | return 0; |
158 | } |
159 | |
160 | int CTvDatabase::clearDbAllProgramInfoTable() |
161 | { |
162 | LOGD(LOG_TAG, "Clearing clearDbAllProgramInfoTable ..."); |
163 | exeSql("delete from net_table"); |
164 | exeSql("delete from ts_table"); |
165 | exeSql("delete from srv_table"); |
166 | exeSql("delete from evt_table"); |
167 | exeSql("delete from booking_table"); |
168 | exeSql("delete from grp_table"); |
169 | exeSql("delete from grp_map_table"); |
170 | exeSql("delete from dimension_table"); |
171 | exeSql("delete from sat_para_table"); |
172 | return 0; |
173 | } |
174 | |
175 | //showboz now just channellist |
176 | int CTvDatabase::importXmlToDB(const char *xmlPath) |
177 | { |
178 | //delete region table before importing xml |
179 | exeSql("delete from region_table"); |
180 | |
181 | //?????o?????aXML????????£?ˉ1è±???? |
182 | TiXmlDocument myDocument(xmlPath); |
183 | bool ret = myDocument.LoadFile(); |
184 | |
185 | //è?·?????1????′? |
186 | TiXmlElement *RootElement = myDocument.RootElement(); |
187 | beginTransaction();//----------------------------------------------- |
188 | //list-->entry |
189 | for (TiXmlElement *channel_list_element = RootElement->FirstChildElement("channel_list"); channel_list_element != NULL; channel_list_element = channel_list_element->NextSiblingElement("channel_list")) { |
190 | //LOGD("showboz-----channel_list =%d", channel_list_element); |
191 | const char *channel_name = channel_list_element->Attribute("name"); |
192 | const char *channel_fe_type = channel_list_element->Attribute("fe_type"); |
193 | //LOGD("showboz-----channel_list name = %s type=%s", channel_name, channel_fe_type); |
194 | |
195 | for (TiXmlElement *channel_entry = channel_list_element->FirstChildElement("channel_entry") ; channel_entry != NULL; channel_entry = channel_entry->NextSiblingElement("channel_entry")) { |
196 | int freq, symb, channelNum; |
197 | String8 cmd = String8("insert into region_table(name,fe_type,frequency,symbol_rate,modulation,bandwidth,ofdm_mode,logical_channel_num)"); |
198 | cmd += String8("values('") + channel_name + String8("',") + String8::format("%d", StringToIndex(feTypes, channel_fe_type)) + String8(","); |
199 | channel_entry->Attribute("frequency", &freq); |
200 | cmd += String8::format("%d", freq) + String8(","); |
201 | channel_entry->Attribute("symbol_rate", &symb); |
202 | cmd += String8::format("%d", symb) + String8(","); |
203 | //LOGD("showboz---------m=%s,b=%s,o=%s", channel_entry->Attribute("modulation"), channel_entry->Attribute("bandwidth"), channel_entry->Attribute("ofdm_mode")); |
204 | cmd += String8::format("%d", StringToIndex(mods, channel_entry->Attribute("modulation"))) + String8(","); |
205 | cmd += String8::format("%d", StringToIndex(bandwidths, channel_entry->Attribute("bandwidth"))) + String8(","); |
206 | cmd += String8::format("%d", StringToIndex(ofdmModes, channel_entry->Attribute("ofdm_mode"))) + String8(","); |
207 | channel_entry->Attribute("logical_channel_num", &channelNum); |
208 | cmd += String8::format("%d", channelNum) + String8(")"); |
209 | exeSql(cmd.string()); |
210 | } |
211 | } |
212 | |
213 | commitTransaction();//------------------------------------------------------ |
214 | return 0; |
215 | } |
216 | |
217 | bool CTvDatabase::isAtv256ProgInsertForSkyworth() |
218 | { |
219 | String8 select_ts_atvcount = String8("select * from ts_table where src = 4"); |
220 | Cursor c; |
221 | select(select_ts_atvcount, c); |
222 | return c.getCount() < 256 ? false : true; |
223 | } |
224 | |
225 | int CTvDatabase::insert256AtvProgForSkyworth() |
226 | { |
227 | beginTransaction(); |
228 | for (int i = 0; i < 256; i++) { |
229 | 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 ("); |
230 | insert_ts += String8::format("'%d'", i); |
231 | insert_ts += String8(", '4', '-1', '-1', '44250000', '0', '0', '0', '0', '0', '0', '-1', '-1', '-1', '1', '0', '0')"); |
232 | exeSql(insert_ts.string()); |
233 | 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 ("); |
234 | insert_srv += String8::format("'%d'", i); |
235 | insert_srv += String8(" , '4', '-1', "); |
236 | insert_srv += String8::format("'%d'", i); |
237 | 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', "); |
238 | insert_srv += String8::format("'%d'", i); |
239 | insert_srv += String8(" , '0', '0', '0', '-1', '255', '0', '0', '0', '0', '0', '0', '255') "); |
240 | exeSql(insert_srv.string()); |
241 | } |
242 | commitTransaction(); |
243 | return 0; |
244 | } |
245 | |
246 | void CTvDatabase::deleteTvDb() |
247 | { |
248 | if (mpDb != NULL) { |
249 | delete mpDb; |
250 | mpDb = NULL; |
251 | } |
252 | } |
253 | CTvDatabase *CTvDatabase::GetTvDb() |
254 | { |
255 | if (mpDb == NULL) { |
256 | mpDb = new CTvDatabase(); |
257 | } |
258 | return mpDb; |
259 | } |
260 |