summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tvdb/CTvProgram.cpp (plain)
blob: 49c1d86c1e4612b75a0864fe9e28eb7c03fdfa6a
1//
2//
3// amlogic 2013
4//
5// @ Project : tv
6// @ File Name : CTvProgram.cpp
7// @ Date : 2013-11
8// @ Author :
9//
10//
11#define LOG_TAG "CTvProgram"
12
13#include "CTvProgram.h"
14#include "CTvDatabase.h"
15#include "CTvChannel.h"
16#include "CTvEvent.h"
17
18CTvProgram::CTvProgram(CTvDatabase::Cursor &c)
19{
20 CreateFromCursor(c);
21}
22
23CTvProgram::~CTvProgram()
24{
25 //free mem
26 // video
27 if (mpVideo != NULL) delete mpVideo;
28 // audios
29 int size = mvAudios.size();
30 for (int i = 0; i < size; i++)
31 delete mvAudios[i];
32 // subtitles
33 size = mvSubtitles.size();
34 for (int i = 0; i < size; i++)
35 delete mvSubtitles[i];
36 // teletexts
37 size = mvTeletexts.size();
38 for (int i = 0; i < size; i++)
39 delete mvTeletexts[i];
40}
41
42CTvProgram::CTvProgram(int channelID __unused, int type __unused)
43{
44 mpVideo = NULL;
45}
46
47CTvProgram::CTvProgram()
48{
49 mpVideo = NULL;
50}
51
52int CTvProgram::CreateFromCursor(CTvDatabase::Cursor &c)
53{
54 int i = 0;
55 int col;
56 int num, type;
57 int major, minor;
58 char tmp_buf[256];
59 //LOGD("CTvProgram::CreateFromCursor");
60 col = c.getColumnIndex("db_id");
61 this->id = c.getInt(col);
62
63 col = c.getColumnIndex("source_id");
64 this->sourceID = c.getInt(col);
65
66 col = c.getColumnIndex("src");
67 this->src = c.getInt(col);
68
69 col = c.getColumnIndex("service_id");
70 this->dvbServiceID = c.getInt(col);
71
72 col = c.getColumnIndex("db_ts_id");
73 this->channelID = c.getInt(col);
74
75 col = c.getColumnIndex("name");
76 this->name = c.getString(col);
77
78 col = c.getColumnIndex("chan_num");
79 num = c.getInt(col);
80
81 col = c.getColumnIndex("chan_order");
82 this->chanOrderNum = c.getInt(col);
83
84 col = c.getColumnIndex("major_chan_num");
85 major = c.getInt(col);
86
87 col = c.getColumnIndex("minor_chan_num");
88 minor = c.getInt(col);
89
90 col = c.getColumnIndex("aud_track");
91 this->audioTrack = c.getInt(col);
92
93 //节目号信息初??
94 if (src == CTvChannel::MODE_ATSC || (src == CTvChannel::MODE_ANALOG && major > 0)) {
95 this->major = major;
96 this->minor = minor;
97 this->atscMode = true;
98 this->minorCheck = MINOR_CHECK_NONE;
99 } else {
100 this->major = num;
101 this->minor = 0;
102 this->atscMode = false;
103 this->minorCheck = MINOR_CHECK_NONE;
104 }
105
106 col = c.getColumnIndex("service_type");
107 this->type = c.getInt(col);
108
109 col = c.getColumnIndex("pmt_pid");
110 pmtPID = c.getInt(col);
111
112 //LOGD("CTvProgram::CreateFromCursor type = %d", this->type);
113 col = c.getColumnIndex("skip");
114 this->skip = c.getInt(col);
115
116 col = c.getColumnIndex("lock");
117 this->lock = (c.getInt(col) != 0);
118
119 col = c.getColumnIndex("scrambled_flag");
120 this->scrambled = (c.getInt(col) != 0);
121
122 col = c.getColumnIndex("favor");
123 this->favorite = (c.getInt(col) != 0);
124
125 col = c.getColumnIndex("volume");
126 this->volume = c.getInt(col);
127
128 //Video
129 int pid, fmt;
130 col = c.getColumnIndex("vid_pid");
131 pid = c.getInt(col);
132
133 col = c.getColumnIndex("vid_fmt");
134 fmt = c.getInt(col);
135
136 //LOGD("----------vpid = %d", pid);
137 this->mpVideo = new Video(pid, fmt);
138 //LOGD("----------vpid = %d", this->mpVideo->getPID());
139
140 //Audio
141 String8 strPids;
142 String8 strFmts;
143 String8 strLangs;
144 int count = 0;
145 col = c.getColumnIndex("aud_pids");
146 strPids = c.getString(col);
147
148 col = c.getColumnIndex("aud_fmts");
149 strFmts = c.getString(col);
150
151 col = c.getColumnIndex("aud_langs");
152 strLangs = c.getString(col);
153 col = c.getColumnIndex("current_aud");
154 this->currAudTrackIndex = c.getInt(col);
155
156 char *tmp;
157 Vector<String8> vpid ;
158 Vector<String8> vfmt ;
159 Vector<String8> vlang;
160
161 char *pSave;
162 tmp = strtok_r(strPids.lockBuffer(strPids.length()), " ", &pSave);
163 while (tmp != NULL) {
164 vpid.push_back(String8(tmp));
165 tmp = strtok_r(NULL, " ", &pSave);
166 }
167 strPids.unlockBuffer();
168
169 tmp = strtok_r(strFmts.lockBuffer(strFmts.length()), " ", &pSave);
170 while (tmp != NULL) {
171 vfmt.push_back(String8(tmp));
172 tmp = strtok_r(NULL, " ", &pSave);
173 }
174 strFmts.unlockBuffer();
175
176 tmp = strtok_r(strLangs.lockBuffer(strLangs.length()), " ", &pSave);
177
178 while (tmp != NULL) {
179 vlang.push_back(String8(tmp));
180 tmp = strtok_r(NULL, " ", &pSave);
181 }
182 strLangs.unlockBuffer();
183
184 //check empty aud_langs
185 for (i = vlang.size(); i < (int)vpid.size(); i++) {
186 sprintf(tmp_buf, "Audio%d", i + 1);
187 vlang.push_back(String8(tmp_buf));
188 LOGE("%s, aud_langs is empty, add dummy data (%s).\n", "TV", tmp_buf);
189 }
190
191 //String8 l(vlang[i]);
192 for (i = 0; i < (int)vpid.size(); i++) {
193 int i_pid = atoi(vpid[i]);
194 int i_fmt = atoi(vfmt[i]);
195 mvAudios.push_back(new Audio(i_pid, vlang[i], i_fmt));
196 }
197
198 /* parse subtitles */
199 vpid.clear();
200 vlang.clear();
201 Vector<String8> vcid;
202 Vector<String8> vaid;
203 String8 strCids;
204 String8 strAids;
205
206 col = c.getColumnIndex("sub_pids");
207 strPids = c.getString(col);
208
209 col = c.getColumnIndex("sub_composition_page_ids");
210 strCids = c.getString(col);
211
212 col = c.getColumnIndex("sub_ancillary_page_ids");
213 strAids = c.getString(col);
214
215 col = c.getColumnIndex("sub_langs");
216 strLangs = c.getString(col);
217
218 tmp = strtok_r(strPids.lockBuffer(strPids.length()), " ", &pSave);
219 while (tmp != NULL) {
220 vpid.push_back(String8(tmp));
221 tmp = strtok_r(NULL, " ", &pSave);
222 }
223 strPids.unlockBuffer();
224
225 tmp = strtok_r(strCids.lockBuffer(strCids.length()), " ", &pSave);
226 while (tmp != NULL) {
227 vcid.push_back(String8(tmp));
228 tmp = strtok_r(NULL, " ", &pSave);
229 }
230 strCids.unlockBuffer();
231
232 tmp = strtok_r(strAids.lockBuffer(strAids.length()), " ", &pSave);
233 while (tmp != NULL) {
234 vaid.push_back(String8(tmp));
235 tmp = strtok_r(NULL, " ", &pSave);
236 }
237 strAids.unlockBuffer();
238
239 tmp = strtok_r(strLangs.lockBuffer(strLangs.length()), " ", &pSave);
240 while (tmp != NULL) {
241 vlang.push_back(String8(tmp));
242 tmp = strtok_r(NULL, " ", &pSave);
243 }
244 strLangs.unlockBuffer();
245
246 //Subtitle
247 for (int i = 0; i < (int)vpid.size(); i++) {
248 this->mvSubtitles.push_back(new Subtitle(
249 atoi(vpid[i]),
250 String8(vlang[i]), Subtitle::TYPE_DVB_SUBTITLE,
251 atoi(vcid[i]),
252 atoi(vaid[i])));
253 }
254
255 /*
256 parse teletexts
257 int ttx_count = 0, ttx_sub_count = 0;
258 String8 str_ttx_pids, str_ttx_types, str_mag_nos, str_page_nos, str_ttx_langs;
259 Vector<String8> v_ttx_pids, v_ttx_types, v_mag_nos, v_page_nos, v_ttx_langs;
260 col = c.getColumnIndex("ttx_pids");
261 str_ttx_pids = c.getString(col);
262
263 col = c.getColumnIndex("ttx_types");
264 str_ttx_types = c.getString(col);
265
266 col = c.getColumnIndex("ttx_magazine_nos");
267 str_mag_nos = c.getString(col);
268
269 col = c.getColumnIndex("ttx_page_nos");
270 str_page_nos = c.getString(col);
271
272 col = c.getColumnIndex("ttx_langs");
273 str_ttx_langs = c.getString(col);
274
275 tmp = strtok_r(str_ttx_pids.lockBuffer(str_ttx_pids.length()), " ", &pSave);
276 while (tmp != NULL) {
277 v_ttx_pids.push_back(String8(tmp));
278 tmp = strtok_r(NULL, " ", &pSave);
279 }
280 str_ttx_pids.unlockBuffer();
281
282 tmp = strtok_r(str_ttx_types.lockBuffer(str_ttx_types.length()), " ", &pSave);
283 while (tmp != NULL) {
284 v_ttx_types.push_back(String8(tmp));
285 tmp = strtok_r(NULL, " ", &pSave);
286 }
287 str_ttx_types.unlockBuffer();
288
289 tmp = strtok_r(str_mag_nos.lockBuffer(str_mag_nos.length()), " ", &pSave);
290 while (tmp != NULL) {
291 v_mag_nos.push_back(String8(tmp));
292 tmp = strtok_r(NULL, " ", &pSave);
293 }
294 str_mag_nos.unlockBuffer();
295
296 tmp = strtok_r(str_page_nos.lockBuffer(str_page_nos.length()), " ", &pSave);
297 while (tmp != NULL) {
298 v_page_nos.push_back(String8(tmp));
299 tmp = strtok_r(NULL, " ", &pSave);
300 }
301 str_page_nos.unlockBuffer();
302
303 tmp = strtok_r(str_ttx_langs.lockBuffer(str_ttx_langs.length()), " ", &pSave);
304 while (tmp != NULL) {
305 v_ttx_langs.push_back(String8(tmp));
306 tmp = strtok_r(NULL, " ", &pSave);
307 }
308 str_ttx_langs.unlockBuffer();
309
310 for (int i = 0; i < v_ttx_pids.size(); i++) {
311 int ttype = atoi(v_ttx_types[i]);
312 if (ttype == 0x2 || ttype == 0x5) {
313 this->mvSubtitles.push_back(new Subtitle(
314 atoi(v_ttx_pids[i].string()),
315 String8(v_ttx_langs[i]), Subtitle::TYPE_DTV_TELETEXT,
316 atoi(v_mag_nos[i]),
317 atoi(v_page_nos[i])));
318 } else {
319 this->mvTeletexts.push_back(new Teletext(
320 atoi(v_ttx_pids[i]),
321 String8(v_ttx_langs[i]),
322 atoi(v_mag_nos[i]),
323 atoi(v_page_nos[i])));
324 }
325 }
326 */
327 return 0;
328}
329
330int CTvProgram::selectProgramInChannelByNumber(int channelID, int num, CTvDatabase::Cursor &c)
331{
332 String8 cmd = String8("select * from srv_table where db_ts_id = ") + String8::format("%d", channelID) + String8(" and ");
333 cmd += String8("chan_num = ") + String8::format("%d", num);
334 return CTvDatabase::GetTvDb()->select(cmd, c);
335}
336
337int CTvProgram::selectProgramInChannelByNumber(int channelID, int major, int minor, CTvDatabase::Cursor &c)
338{
339 String8 cmd = String8("select * from srv_table where db_ts_id = ") + String8::format("%d", channelID) + String8(" and ");
340 cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
341
342 return CTvDatabase::GetTvDb()->select(cmd, c);
343}
344
345/**
346 *向数据库添加一个Program,not atscMode
347 */
348CTvProgram::CTvProgram(int channelID, int type, int num, int skipFlag)
349{
350 CTvChannel channel;
351 int ret = CTvChannel::selectByID(channelID, channel);
352 if (ret != 0) {
353 //Log.d(TAG, "Cannot add new program, invalid channel id "+channelID);
354 this->id = -1;
355 } else {
356 CTvDatabase::Cursor c ;
357 selectProgramInChannelByNumber(channelID, num, c);
358
359 if (c.moveToFirst()) {
360 /*Construct*/
361 CreateFromCursor(c);
362 } else {
363 String8 tpids = String8(""), ttypes = String8(""), tmagnums = String8(""), tpgnums = String8(""), tlangs = String8("");
364 String8 spids = String8(""), stypes = String8(""), scpgids = String8(""), sapgids = String8(""), slangs = String8("");
365
366 /*add a new atv program to database*/
367 String8 cmd = String8("insert into srv_table(db_net_id,db_ts_id,service_id,src,name,service_type,");
368 cmd += String8("eit_schedule_flag,eit_pf_flag,running_status,free_ca_mode,volume,aud_track,vid_pid,");
369 cmd += String8("vid_fmt,aud_pids,aud_fmts,aud_langs,skip,lock,chan_num,major_chan_num,");
370 cmd += String8("minor_chan_num,access_controlled,hidden,hide_guide,source_id,favor,current_aud,");
371 cmd += String8("current_sub,sub_pids,sub_types,sub_composition_page_ids,sub_ancillary_page_ids,sub_langs,");
372 cmd += String8("current_ttx,ttx_pids,ttx_types,ttx_magazine_nos,ttx_page_nos,ttx_langs,");
373 cmd += String8("db_sat_para_id,scrambled_flag,lcn,hd_lcn,sd_lcn,default_chan_num,chan_order) ");
374 cmd += String8("values(-1,") + String8::format("%d", channelID) + String8(",65535,") + String8::format("%d", channel.getMode()) + String8(",'',") + String8::format("%d", type) + String8(",");
375 cmd += String8("0,0,0,0,0,0,8191,");
376 int chanNum = num;
377 int majorNum = 0;
378 cmd += String8("-1,'','','',") + String8::format("%d", skipFlag) + String8(",0,") + String8::format("%d", chanNum) + String8(",") + String8::format("%d", majorNum) + String8(",");
379 cmd += String8("") + /*num.getMinor()*/String8("0") + String8(",0,0,0,-1,0,-1,");
380 cmd += String8("-1,'") + spids + String8("','") + stypes + String8("','") + scpgids + String8("','") + sapgids + String8("','") + slangs + String8("',");
381 cmd += String8("-1,'") + tpids + String8("','") + ttypes + String8("','") + tmagnums + String8("','") + tpgnums + String8("','") + tlangs + String8("',");
382 cmd += String8("-1,0,-1,-1,-1,-1,0)");
383 CTvDatabase::GetTvDb()->exeSql(cmd.string());
384
385 CTvDatabase::Cursor cr;
386 selectProgramInChannelByNumber(channelID, num, cr);
387 if (cr.moveToFirst()) {
388 /*Construct*/
389 CreateFromCursor(cr);
390 } else {
391 /*A critical error*/
392 //Log.d(TAG, "Cannot add new program, sqlite error");
393 this->id = -1;
394 }
395 cr.close();
396 }
397 c.close();
398 }
399
400}
401
402/**
403 *向数据库添加一个Program,atscMode
404 */
405CTvProgram::CTvProgram(int channelID, int type, int major, int minor, int skipFlag)
406{
407 CTvChannel channel;
408 int ret = CTvChannel::selectByID(channelID, channel);
409 if (ret != 0) {
410 //Log.d(TAG, "Cannot add new program, invalid channel id "+channelID);
411 this->id = -1;
412 } else {
413 CTvDatabase::Cursor c ;
414 selectProgramInChannelByNumber(channelID, major, minor, c);
415
416 if (c.moveToFirst()) {
417 /*Construct*/
418 CreateFromCursor(c);
419 } else {
420 String8 tpids = String8(""), ttypes = String8(""), tmagnums = String8(""), tpgnums = String8(""), tlangs = String8("");
421 String8 spids = String8(""), stypes = String8(""), scpgids = String8(""), sapgids = String8(""), slangs = String8("");
422
423 /*add a new atv program to database*/
424 String8 cmd = String8("insert into srv_table(db_net_id,db_ts_id,service_id,src,name,service_type,");
425 cmd += String8("eit_schedule_flag,eit_pf_flag,running_status,free_ca_mode,volume,aud_track,vid_pid,");
426 cmd += String8("vid_fmt,aud_pids,aud_fmts,aud_langs,skip,lock,chan_num,major_chan_num,");
427 cmd += String8("minor_chan_num,access_controlled,hidden,hide_guide,source_id,favor,current_aud,");
428 cmd += String8("current_sub,sub_pids,sub_types,sub_composition_page_ids,sub_ancillary_page_ids,sub_langs,");
429 cmd += String8("current_ttx,ttx_pids,ttx_types,ttx_magazine_nos,ttx_page_nos,ttx_langs,");
430 cmd += String8("db_sat_para_id,scrambled_flag,lcn,hd_lcn,sd_lcn,default_chan_num,chan_order) ");
431 cmd += String8("values(-1,") + String8::format("%d", channelID) + String8(",65535,") + String8::format("%d", channel.getMode()) + String8(",'',") + String8::format("%d", type) + String8(",");
432 cmd += String8("0,0,0,0,0,0,8191,");
433 int chanNum = major << 16 | minor;
434 int majorNum = major;
435 cmd += String8("-1,'','','',") + String8::format("%d", skipFlag) + String8(",0,") + String8::format("%d", chanNum) + String8(",") + String8::format("%d", majorNum) + String8(",");
436 cmd += String8("") + String8::format("%d", minor) + String8(",0,0,0,-1,0,-1,");
437 cmd += String8("-1,'") + spids + String8("','") + stypes + String8("','") + scpgids + String8("','") + sapgids + String8("','") + slangs + String8("',");
438 cmd += String8("-1,'") + tpids + String8("','") + ttypes + String8("','") + tmagnums + String8("','") + tpgnums + String8("','") + tlangs + String8("',");
439 cmd += String8("-1,0,-1,-1,-1,-1,0)");
440 CTvDatabase::GetTvDb()->exeSql(cmd.string());
441
442 CTvDatabase::Cursor cr;
443 selectProgramInChannelByNumber(channelID, major, minor, cr);
444 if (cr.moveToFirst()) {
445 /*Construct*/
446 CreateFromCursor(cr);
447 } else {
448 /*A critical error*/
449 //Log.d(TAG, "Cannot add new program, sqlite error");
450 this->id = -1;
451 }
452 cr.close();
453 }
454 c.close();
455 }
456
457}
458
459/**
460 *根据记录ID查找指定TVProgram
461*/
462int CTvProgram::selectByID(int id, CTvProgram &prog)
463{
464 CTvDatabase::Cursor c;
465 String8 sql;
466 sql = String8("select * from srv_table where srv_table.db_id = ") + String8::format("%d", id);
467 CTvDatabase::GetTvDb()->select(sql.string(), c) ;
468 if (c.moveToFirst()) {
469 prog.CreateFromCursor(c);
470 } else {
471 c.close();
472 return -1;
473 }
474 c.close();
475 return 0;
476}
477
478int CTvProgram::updateVolComp(int progID, int volValue)
479{
480 String8 cmd = String8("update srv_table set volume = ") + String8::format("%d", volValue) +
481 String8(" where srv_table.db_id = ") + String8::format("%d", progID);
482 LOGD("%s, cmd = %s\n", "TV", cmd.string());
483 CTvDatabase::GetTvDb()->exeSql(cmd.string());
484
485 return 0;
486}
487
488int CTvProgram::getChannel(CTvChannel &c)
489{
490 return CTvChannel::selectByID(channelID, c);
491}
492
493int CTvProgram::upDateChannel(CTvChannel &c __unused, int std, int Freq, int fineFreq)
494{
495 return CTvChannel::updateByID(channelID, std, Freq, fineFreq);
496}
497
498int CTvProgram::deleteChannelsProgram(CTvChannel &c)
499{
500 String8 cmd;
501 cmd = String8("delete from srv_table where srv_table.db_ts_id = ") + String8::format("%d", c.getID());
502 CTvDatabase::GetTvDb()->exeSql(cmd.string());
503 return 0;
504}
505
506/**
507 *根据节目类型和节目号查找指定TVProgram
508*/
509int CTvProgram::selectByNumber(int type, int num, CTvProgram &prog)
510{
511 String8 cmd;
512
513 cmd = String8("select * from srv_table where ");
514 if (type != TYPE_UNKNOWN) {
515 if (type == TYPE_DTV) {
516 cmd += String8("(service_type = ") + String8::format("%d", TYPE_DTV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") and ");
517 } else {
518 cmd += String8("service_type = ") + String8::format("%d", type) + String8(" and ");
519 }
520 }
521
522 cmd += String8("chan_num = ") + String8::format("%d", num);
523
524 CTvDatabase::Cursor c;
525 CTvDatabase::GetTvDb()->select(cmd, c);
526
527 if (c.moveToFirst()) {
528 prog.CreateFromCursor(c);
529 } else {
530 c.close();
531 return -1;
532 }
533 c.close();
534
535 return 0;
536}
537
538/**
539 *根据节目类型和节目号查找指定TVProgram
540*/
541int CTvProgram::selectByNumber(int type, int major, int minor, CTvProgram &prog, int minor_check)
542{
543 String8 cmd;
544
545 cmd = String8("select * from srv_table where ");
546 if (type != TYPE_UNKNOWN) {
547 if (type == TYPE_DTV) {
548 cmd += String8("(service_type = ") + String8::format("%d", TYPE_TV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") and ");
549 } else {
550 cmd += String8("service_type = ") + String8::format("%d", type) + String8(" and ");
551 }
552 }
553
554 if (minor < 0) {
555 /*recursive call*/
556 /*select dtv program first*/
557 //showbo
558 int ret = selectByNumber(TYPE_DTV, major, 1, prog, MINOR_CHECK_NEAREST_UP);
559 if (ret != 0) {
560 /*then try atv program*/
561 selectByNumber(TYPE_ATV, major, 0 , prog, MINOR_CHECK_NONE);
562 }
563 return 0;
564 } else if (minor >= 1) {
565 if (minor_check == MINOR_CHECK_UP) {
566 cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num >= ") + String8::format("%d", minor) + String8(" ");
567 cmd += String8("order by minor_chan_num DESC limit 1");
568 } else if (minor_check == MINOR_CHECK_DOWN) {
569 cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num <= ") + String8::format("%d", minor) + String8(" ");
570 cmd += String8("order by minor_chan_num limit 1");
571 } else if (minor_check == MINOR_CHECK_NEAREST_UP) {
572 cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num >= ") + String8::format("%d", minor) + String8(" ");
573 cmd += String8("order by minor_chan_num limit 1");
574 } else if (minor_check == MINOR_CHECK_NEAREST_DOWN) {
575 cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num <= ") + String8::format("%d", minor) + String8(" ");
576 cmd += String8("order by minor_chan_num DESC limit 1");
577 } else {
578 cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
579 }
580 } else {
581 cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
582 }
583
584
585 CTvDatabase::Cursor c;
586 CTvDatabase::GetTvDb()->select(cmd, c);
587
588 if (c.moveToFirst()) {
589 prog.CreateFromCursor(c);
590 } else {
591 c.close();
592 return -1;
593 }
594 c.close();
595
596 return 0;
597}
598
599
600/**
601 *列出一个channel的全部TVProgram
602 *@param channelID channel id
603 *@param type 节目类型
604 */
605int CTvProgram::selectByChannel(int channelID, int type, Vector<sp<CTvProgram> > &out)
606{
607 //Vector<CTvProgram*> vp;
608 String8 cmd = String8("select * from srv_table ");
609
610 if (type == TYPE_DTV) {
611 cmd += String8("where (service_type = ") + String8::format("%d", TYPE_TV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") ");
612 } else if (type != TYPE_UNKNOWN) {
613 cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
614 }
615
616 cmd += String8(" and db_ts_id = ") + String8::format("%d", channelID) + String8(" order by chan_order");
617
618 CTvDatabase::Cursor c;
619 int ret = CTvDatabase::GetTvDb()->select(cmd, c);
620
621 LOGD("selectByChannel select ret = %d", ret);
622
623 if (c.moveToFirst()) {
624 do {
625 out.add(new CTvProgram(c));
626 } while (c.moveToNext());
627 }
628 c.close();
629
630 return 0;
631}
632
633void CTvProgram::deleteProgram(int progId)
634{
635 String8 cmd;
636
637 cmd = String8("delete from srv_table where srv_table.db_id = ") + String8::format("%d", progId);
638 CTvDatabase::GetTvDb()->exeSql(cmd.string());
639}
640
641int CTvProgram::CleanAllProgramBySrvType(int srvType)
642{
643 String8 cmd = String8("delete from srv_table where service_type = ") + String8::format("%d", srvType);
644 CTvDatabase::GetTvDb()->exeSql(cmd.string());
645 return 0;
646}
647
648int CTvProgram::selectByType(int type, int skip, Vector<sp<CTvProgram> > &out)
649{
650 String8 cmd = String8("select * from srv_table ");
651 LOGD("%s, type= %d\n", "TV", (int)type);
652
653 if (type == TYPE_UNKNOWN) {
654 cmd += String8("where (service_type = ") + String8::format("%d", TYPE_ATV) +
655 String8(" or service_type = ") + String8::format("%d", TYPE_DTV) +
656 String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) +
657 String8(") ");
658 } else {
659 cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
660 }
661
662 if (skip == PROGRAM_SKIP_NO || skip == PROGRAM_SKIP_YES)
663 cmd += String8(" and skip = ") + String8::format("%d", skip) + String8(" ");
664
665 if (type == TYPE_DTV || type == TYPE_RADIO) {
666 cmd += String8(" order by db_ts_id");
667 } else {
668 cmd += String8(" order by chan_order");
669 }
670
671 CTvDatabase::Cursor c;
672 int ret = CTvDatabase::GetTvDb()->select(cmd, c);
673
674 LOGD("selectByType select ret = %d", ret);
675
676 if (c.moveToFirst()) {
677 do {
678 out.add(new CTvProgram(c));
679 } while (c.moveToNext());
680 }
681 c.close();
682
683 return 0;
684}
685
686int CTvProgram::selectByChanID(int type, int skip, Vector < sp < CTvProgram > > &out)
687{
688 String8 cmd = String8("select * from srv_table ");
689
690 if (type == TYPE_UNKNOWN) {
691 cmd += String8("where (service_type = ") + String8::format("%d", TYPE_ATV) +
692 String8(" or service_type = ") + String8::format("%d", TYPE_DTV) +
693 String8(") ");
694 } else {
695 cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
696 }
697
698 if (skip == PROGRAM_SKIP_NO || skip == PROGRAM_SKIP_YES)
699 cmd += String8(" and skip = ") + String8::format("%d", PROGRAM_SKIP_NO) +
700 String8(" or skip = ") + String8::format("%d", PROGRAM_SKIP_YES) + String8(" ");
701
702 cmd += String8(" order by db_id");
703
704 CTvDatabase::Cursor c;
705 int ret = CTvDatabase::GetTvDb()->select(cmd, c);
706
707 if (c.moveToFirst()) {
708 do {
709 out.add(new CTvProgram(c));
710 } while (c.moveToNext());
711 }
712 c.close();
713
714 return 0;
715}
716
717int CTvProgram::selectAll(bool no_skip, Vector<sp<CTvProgram> > &out)
718{
719 return selectByType(TYPE_UNKNOWN, no_skip, out);
720}
721
722Vector<CTvProgram> CTvProgram::selectByChannel(int channelID __unused)
723{
724 Vector<CTvProgram> vProg;
725 return vProg;
726}
727
728Vector<CTvProgram> CTvProgram::selectByName(int name __unused)
729{
730 Vector<CTvProgram> vProg;
731 return vProg;
732}
733
734void CTvProgram::tvProgramDelByChannelID(int channelID)
735{
736 channelID = channelID;
737}
738
739String8 CTvProgram::getName()
740{
741 return name;
742}
743
744int CTvProgram::getProgSkipFlag()
745{
746 return skip;
747}
748
749/**
750 *取得当前的audio索引
751 *@param defaultLang 用户未选择语言时,默认的全局语言
752 *@return 当前的Audio索引
753 */
754int CTvProgram::getCurrentAudio(String8 defaultLang)
755{
756 CTvDatabase::Cursor c;
757 String8 cmd;
758 cmd = String8("select current_aud from srv_table where db_id = ") + String8::format("%d", this->id);
759 int ret = CTvDatabase::GetTvDb()->select(cmd, c);
760 LOGD("getCurrentAudio a size = %d", mvAudios.size());
761 int id = 0;
762 if (c.moveToFirst()) {
763 id = c.getInt(0);
764 LOGD("getCurrentAudio a id = %d", id);
765 if (id < 0 && mvAudios.size() > 0) {
766 LOGD("getCurrentAudio defaultLang.isEmpty() =%s= %d", defaultLang.string(), defaultLang.isEmpty());
767 if (!defaultLang.isEmpty()) {
768 for (int i = 0; i < (int)mvAudios.size(); i++) {
769 LOGD("getCurrentAudio a mvAudios[i] = %x", (int)mvAudios[i]);
770 if (mvAudios[i]->getLang() == defaultLang) {
771 id = i;
772 break;
773 }
774 }
775 }
776
777 if (id < 0) {
778 /* still not found, using the first */
779 id = 0;
780 }
781 }
782 }
783 LOGD("getCurrentAudio a idsss = %d", id);
784 c.close();
785
786 return id;
787}
788
789int CTvProgram::getAudioChannel()
790{
791 return audioTrack;
792}
793
794int CTvProgram::updateAudioChannel(int progId, int ch)
795{
796 String8 cmd;
797
798 cmd = String8("update srv_table set aud_track =") + "\'" + String8::format("%d", ch) + "\'"
799 + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
800
801 return CTvDatabase::GetTvDb()->exeSql(cmd.string());
802}
803
804int CTvProgram::getSubtitleIndex(int progId)
805{
806 CTvDatabase::Cursor c;
807 String8 cmd = String8("select current_sub from srv_table where db_id = ") + String8::format("%d", progId);
808 int ret = CTvDatabase::GetTvDb()->select(cmd, c);
809 if (c.moveToFirst()) {
810 return c.getInt(0);
811 } else {
812 return -1;
813 }
814}
815
816int CTvProgram::setSubtitleIndex(int progId, int index)
817{
818 String8 cmd = String8("update srv_table set current_sub = ") + String8::format("%d", index) + String8(" where db_id = ") + String8::format("%d", progId);
819 return CTvDatabase::GetTvDb()->exeSql(cmd.string());
820}
821
822int CTvProgram::getCurrAudioTrackIndex()
823{
824 int audTrackIdx = -1;
825
826 if (-1 == currAudTrackIndex) { // no set field "current_aud"
827 audTrackIdx = getCurrentAudio(String8("eng"));
828 setCurrAudioTrackIndex(this->id, audTrackIdx);
829 } else {
830 audTrackIdx = currAudTrackIndex;
831 }
832
833 return audTrackIdx;
834}
835
836void CTvProgram::setCurrAudioTrackIndex(int programId, int audioIndex)
837{
838 String8 cmd;
839
840 cmd = String8("update srv_table set current_aud = ")
841 + String8::format("%d", audioIndex) + String8(" where srv_table.db_id = ") + String8::format("%d", programId);
842
843 CTvDatabase::GetTvDb()->exeSql(cmd.string());
844}
845
846void CTvProgram::setFavoriteFlag(int progId, bool bFavor)
847{
848 String8 cmd;
849
850 cmd = String8("update srv_table set favor = ")
851 + String8::format("%d", bFavor ? 1 : 0) + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
852
853 CTvDatabase::GetTvDb()->exeSql(cmd.string());
854}
855
856void CTvProgram::setSkipFlag(int progId, bool bSkipFlag)
857{
858 String8 cmd;
859
860 cmd = String8("update srv_table set skip = ") + String8::format("%d", bSkipFlag ? 1 : 0)
861 + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
862
863 CTvDatabase::GetTvDb()->exeSql(cmd.string());
864}
865
866void CTvProgram::updateProgramName(int progId, String8 strName)
867{
868 String8 newName = String8("xxx") + strName;
869 String8 cmd;
870
871 cmd = String8("update srv_table set name =") + "\'" + String8::format("%s", newName.string()) + "\'"
872 + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
873
874 CTvDatabase::GetTvDb()->exeSql(cmd.string());
875}
876
877void CTvProgram::swapChanOrder(int ProgId1, int chanOrderNum1, int ProgId2, int chanOrderNum2)
878{
879 String8 cmd;
880
881 cmd = String8("update srv_table set chan_order = ") + String8::format("%d", chanOrderNum2)
882 + String8(" where db_id = ") + String8::format("%d", ProgId1);
883 CTvDatabase::GetTvDb()->exeSql(cmd.string());
884
885 String8 cmd2;
886 cmd2 = String8("update srv_table set chan_order = ") + String8::format("%d", chanOrderNum1)
887 + String8(" where db_id = ") + String8::format("%d", ProgId2);
888 CTvDatabase::GetTvDb()->exeSql(cmd2.string());
889}
890
891void CTvProgram::setLockFlag(int progId, bool bLockFlag)
892{
893 String8 cmd;
894
895 cmd = String8("update srv_table set lock = ") + String8::format("%d", bLockFlag ? 1 : 0)
896 + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
897
898 CTvDatabase::GetTvDb()->exeSql(cmd.string());
899}
900
901bool CTvProgram::getLockFlag()
902{
903 return lock;
904}
905
906