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