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