summaryrefslogtreecommitdiff
Diffstat
-rw-r--r--Android.mk14
-rw-r--r--screen_source/Android.mk31
-rw-r--r--screen_source/aml_screen.cpp296
-rw-r--r--screen_source/v4l2_vdin.cpp676
-rw-r--r--screen_source/v4l2_vdin.h144
-rw-r--r--tv_callback.h18
-rw-r--r--tv_input.cpp263
-rw-r--r--tvapi/android/Android.mk2
-rw-r--r--tvapi/android/include/ITv.h98
-rw-r--r--tvapi/android/include/ITvClient.h56
-rw-r--r--tvapi/android/include/ITvService.h66
-rw-r--r--tvapi/android/include/Tv.h158
-rw-r--r--tvapi/android/include/tvcmd.h1212
-rw-r--r--tvapi/android/jni/Android.mk135
-rw-r--r--tvapi/android/jni/cfbc_jni.cpp18
-rw-r--r--tvapi/android/jni/cfbc_test.cpp86
-rw-r--r--tvapi/android/jni/com_droidlogic_app_tv_TvControlManager.cpp (renamed from tvapi/android/jni/android_amlogic_tv.cpp)929
-rw-r--r--tvapi/android/libtvbinder/Android.mk48
-rw-r--r--tvapi/android/libtvbinder/ITv.cpp292
-rw-r--r--tvapi/android/libtvbinder/ITvClient.cpp116
-rw-r--r--tvapi/android/libtvbinder/ITvService.cpp100
-rw-r--r--tvapi/android/libtvbinder/Tv.cpp378
-rw-r--r--tvapi/android/tv/Android.mk23
-rw-r--r--tvapi/android/tv/CTv.cpp104
-rw-r--r--tvapi/android/tv/CTv.h54
-rw-r--r--tvapi/android/tvserver/Android.mk164
-rw-r--r--tvapi/android/tvserver/TvService.cpp8911
-rw-r--r--tvapi/android/tvserver/TvService.h170
-rw-r--r--tvapi/android/tvserver/main.cpp46
-rw-r--r--tvapi/android/tvserver/tv_callback.h18
-rw-r--r--[-rwxr-xr-x]tvapi/build/include/.gitignore0
-rw-r--r--tvapi/build/include/xxxconfig.h1
-rw-r--r--tvapi/docs/tv.uml12156
-rw-r--r--tvapi/libtv/Android.mk12
-rw-r--r--tvapi/libtv/audio/CAudioCustomerCtrl.cpp126
-rw-r--r--tvapi/libtv/audio/CAudioCustomerCtrl.h31
-rw-r--r--tvapi/libtv/audio/CTvAudio.cpp30
-rw-r--r--tvapi/libtv/audio/CTvAudio.h76
-rw-r--r--tvapi/libtv/audio/audio_alsa.cpp2073
-rw-r--r--tvapi/libtv/audio/audio_alsa.h257
-rw-r--r--tvapi/libtv/audio/audio_android.cpp1035
-rw-r--r--tvapi/libtv/audio/audio_android.h78
-rw-r--r--tvapi/libtv/audio/audio_android_effect.cpp591
-rw-r--r--tvapi/libtv/audio/audio_android_effect.h65
-rw-r--r--tvapi/libtv/audio/audio_api.cpp2470
-rw-r--r--tvapi/libtv/audio/audio_api.h323
-rw-r--r--tvapi/libtv/audio/audio_effect.cpp356
-rw-r--r--tvapi/libtv/audio/audio_effect.h58
-rw-r--r--tvapi/libtv/include/amstream.h526
-rw-r--r--tvapi/libtv/include/amvecm.h136
-rw-r--r--tvapi/libtv/include/cm.h308
-rw-r--r--tvapi/libtv/include/hdmirx_cec.h316
-rw-r--r--tvapi/libtv/include/ve.h461
-rw-r--r--tvapi/libtv/tv/AutoBackLight.cpp425
-rw-r--r--tvapi/libtv/tv/CAutoPQparam.cpp150
-rw-r--r--tvapi/libtv/tv/CAutoPQparam.h41
-rw-r--r--tvapi/libtv/tv/CAv.cpp116
-rw-r--r--tvapi/libtv/tv/CAv.h24
-rw-r--r--tvapi/libtv/tv/CFbcCommunication.cpp443
-rw-r--r--tvapi/libtv/tv/CFbcCommunication.h25
-rw-r--r--tvapi/libtv/tv/CFrontEnd.cpp198
-rw-r--r--tvapi/libtv/tv/CFrontEnd.h19
-rw-r--r--tvapi/libtv/tv/CTv.cpp13003
-rw-r--r--tvapi/libtv/tv/CTv.h1453
-rw-r--r--tvapi/libtv/tv/CTvBooking.cpp324
-rw-r--r--tvapi/libtv/tv/CTvBooking.h166
-rw-r--r--tvapi/libtv/tv/CTvEpg.cpp24
-rw-r--r--tvapi/libtv/tv/CTvEv.h12
-rw-r--r--tvapi/libtv/tv/CTvLog.h8
-rw-r--r--tvapi/libtv/tv/CTvRecord.cpp552
-rw-r--r--tvapi/libtv/tv/CTvRecord.h92
-rw-r--r--tvapi/libtv/tv/CTvSatellite.h42
-rw-r--r--tvapi/libtv/tv/CTvScanner.cpp335
-rw-r--r--tvapi/libtv/tv/CTvScanner.h26
-rw-r--r--tvapi/libtv/tv/CTvScreenCapture.cpp1279
-rw-r--r--tvapi/libtv/tv/CTvScreenCapture.h351
-rw-r--r--tvapi/libtv/tv/CTvSubtitle.cpp361
-rw-r--r--tvapi/libtv/tv/CTvSubtitle.h484
-rw-r--r--tvapi/libtv/tv/CTvVchipCheck.cpp6
-rw-r--r--tvapi/libtv/tv/CUpgradeFBC.cpp4
-rw-r--r--tvapi/libtv/tv/CUpgradeFBC.h282
-rw-r--r--tvapi/libtv/tv/ScreenCatch.cpp379
-rw-r--r--tvapi/libtv/tvconfig/CIniFile.cpp706
-rw-r--r--tvapi/libtv/tvconfig/tvconfig.conf58
-rw-r--r--tvapi/libtv/tvconfig/tvconfig.cpp106
-rw-r--r--tvapi/libtv/tvconfig/tvconfig.h40
-rw-r--r--tvapi/libtv/tvdb/CTvChannel.cpp694
-rw-r--r--tvapi/libtv/tvdb/CTvChannel.h574
-rw-r--r--tvapi/libtv/tvdb/CTvDatabase.cpp25
-rw-r--r--tvapi/libtv/tvdb/CTvDatabase.h188
-rw-r--r--tvapi/libtv/tvdb/CTvDimension.cpp86
-rw-r--r--tvapi/libtv/tvdb/CTvDimension.h194
-rw-r--r--tvapi/libtv/tvdb/CTvEvent.cpp483
-rw-r--r--tvapi/libtv/tvdb/CTvEvent.h170
-rw-r--r--tvapi/libtv/tvdb/CTvGroup.cpp88
-rw-r--r--tvapi/libtv/tvdb/CTvGroup.h60
-rw-r--r--tvapi/libtv/tvdb/CTvProgram.cpp1806
-rw-r--r--tvapi/libtv/tvdb/CTvProgram.h1066
-rw-r--r--tvapi/libtv/tvdb/CTvRegion.cpp366
-rw-r--r--tvapi/libtv/tvdb/CTvRegion.h84
-rw-r--r--tvapi/libtv/tvin/CHDMIRxCEC.cpp38
-rw-r--r--tvapi/libtv/tvin/CSourceConnectDetect.cpp478
-rw-r--r--tvapi/libtv/tvin/CSourceConnectDetect.h73
-rw-r--r--tvapi/libtv/tvin/CTvin.cpp203
-rw-r--r--tvapi/libtv/tvin/CTvin.h191
-rw-r--r--tvapi/libtv/tvsetting/CBlobDevice.cpp54
-rw-r--r--tvapi/libtv/tvsetting/CBlobDevice.h100
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceE2prom.cpp403
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceE2prom.h152
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceFile.cpp160
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceFile.h52
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceRam.cpp258
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceRam.h74
-rw-r--r--tvapi/libtv/tvsetting/CTvSetting.cpp4658
-rw-r--r--tvapi/libtv/tvsetting/CTvSetting.h30
-rw-r--r--tvapi/libtv/tvsetting/CTvSettingCfg.h782
-rw-r--r--tvapi/libtv/tvsetting/CTvSettingDeviceFactory.cpp10
-rw-r--r--tvapi/libtv/tvsetting/TvKeyData.cpp2726
-rw-r--r--tvapi/libtv/tvsetting/TvKeyData.h64
-rw-r--r--tvapi/libtv/tvsetting/audio_cfg.cpp2575
-rw-r--r--tvapi/libtv/tvsetting/audio_cfg.h239
-rw-r--r--tvapi/libtv/tvutils/CCondition.h2
-rw-r--r--tvapi/libtv/tvutils/CFile.cpp65
-rw-r--r--tvapi/libtv/tvutils/CFile.h3
-rw-r--r--tvapi/libtv/tvutils/CHdmiCecCmd.cpp2
-rw-r--r--tvapi/libtv/tvutils/CMsgQueue.cpp31
-rw-r--r--tvapi/libtv/tvutils/CMsgQueue.h3
-rw-r--r--tvapi/libtv/tvutils/CSerialCommunication.h96
-rw-r--r--tvapi/libtv/tvutils/CSerialPort.cpp18
-rw-r--r--tvapi/libtv/tvutils/CSqlite.cpp8
-rw-r--r--tvapi/libtv/tvutils/CSqlite.h12
-rw-r--r--tvapi/libtv/tvutils/CThread.cpp2
-rw-r--r--tvapi/libtv/tvutils/CTvInput.cpp25
-rw-r--r--tvapi/libtv/tvutils/CTvInput.h4
-rw-r--r--tvapi/libtv/tvutils/serial_base.h34
-rw-r--r--tvapi/libtv/tvutils/serial_operate.cpp66
-rw-r--r--tvapi/libtv/tvutils/serial_operate.h70
-rw-r--r--tvapi/libtv/tvutils/tvutils.cpp3931
-rw-r--r--tvapi/libtv/tvutils/tvutils.h222
-rw-r--r--tvapi/libtv/tvutils/zepoll.cpp2
-rw-r--r--tvapi/libtv/version/version.cpp188
-rw-r--r--tvapi/libtv/version/version.h22
-rw-r--r--tvapi/libtv/vpp/CPQdb.cpp3509
-rw-r--r--tvapi/libtv/vpp/CPQdb.h340
-rw-r--r--tvapi/libtv/vpp/CVpp.cpp5602
-rw-r--r--tvapi/libtv/vpp/CVpp.h230
-rw-r--r--tvapi/tvtests/Android.mk98
-rw-r--r--tvapi/tvtests/android_tvtest.cpp2
-rw-r--r--tvapi/tvtests/comm_test.cpp4
-rw-r--r--tvapi/tvtests/ssm_test.cpp420
-rw-r--r--tvapi/tvtests/tvconfig_test.cpp854
151 files changed, 45277 insertions, 47437 deletions
diff --git a/tvapi/libtv/tvdb/CTvProgram.cpp b/tvapi/libtv/tvdb/CTvProgram.cpp
index c71c757..fdd1c68 100644
--- a/tvapi/libtv/tvdb/CTvProgram.cpp
+++ b/tvapi/libtv/tvdb/CTvProgram.cpp
@@ -1,883 +1,923 @@
-//
-//
-// amlogic 2013
-//
-// @ Project : tv
-// @ File Name : CTvProgram.cpp
-// @ Date : 2013-11
-// @ Author :
-//
-//
-
-
-#include "CTvProgram.h"
-#include "CTvDatabase.h"
-#include "CTvChannel.h"
-#include "CTvEvent.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#define LOG_TAG "CTvProgram"
-#endif
-
-CTvProgram::CTvProgram(CTvDatabase::Cursor &c)
-{
- CreateFromCursor(c);
-}
-
-CTvProgram::~CTvProgram()
-{
- //free mem
- // video
- if(mpVideo != NULL) delete mpVideo;
- // audios
- int size = mvAudios.size();
- for(int i = 0; i < size; i++)
- delete mvAudios[i];
- // subtitles
- size = mvSubtitles.size();
- for(int i = 0; i < size; i++)
- delete mvSubtitles[i];
- // teletexts
- size = mvTeletexts.size();
- for(int i = 0; i < size; i++)
- delete mvTeletexts[i];
-}
-
-CTvProgram::CTvProgram(int channelID, int type)
-{
- mpVideo = NULL;
-}
-
-CTvProgram::CTvProgram()
-{
- mpVideo = NULL;
-}
-int CTvProgram::CreateFromCursor(CTvDatabase::Cursor &c)
-{
- int i = 0;
- int col;
- int num, type;
- int major, minor;
- char tmp_buf[256];
- //LOGD("CTvProgram::CreateFromCursor");
- col = c.getColumnIndex("db_id");
- this->id = c.getInt(col);
-
- col = c.getColumnIndex("source_id");
- this->sourceID = c.getInt(col);
-
- col = c.getColumnIndex("src");
- this->src = c.getInt(col);
-
- col = c.getColumnIndex("service_id");
- this->dvbServiceID = c.getInt(col);
-
- col = c.getColumnIndex("db_ts_id");
- this->channelID = c.getInt(col);
-
- col = c.getColumnIndex("name");
- this->name = c.getString(col);
-
- col = c.getColumnIndex("chan_num");
- num = c.getInt(col);
-
- col = c.getColumnIndex("chan_order");
- this->chanOrderNum = c.getInt(col);
-
- col = c.getColumnIndex("major_chan_num");
- major = c.getInt(col);
-
- col = c.getColumnIndex("minor_chan_num");
- minor = c.getInt(col);
-
- col = c.getColumnIndex("aud_track");
- this->audioTrack = c.getInt(col);
-
- //节目号信息初??
- if (src == CTvChannel::MODE_ATSC || (src == CTvChannel::MODE_ANALOG && major > 0)) {
- this->major = major;
- this->minor = minor;
- this->atscMode = true;
- this->minorCheck = MINOR_CHECK_NONE;
- } else {
- this->major = num;
- this->minor = 0;
- this->atscMode = false;
- this->minorCheck = MINOR_CHECK_NONE;
- }
-
- col = c.getColumnIndex("service_type");
- this->type = c.getInt(col);
-
- col = c.getColumnIndex("pmt_pid");
- pmtPID = c.getInt(col);
-
- //LOGD("CTvProgram::CreateFromCursor type = %d", this->type);
- col = c.getColumnIndex("skip");
- this->skip = c.getInt(col);
-
- col = c.getColumnIndex("lock");
- this->lock = (c.getInt(col) != 0);
-
- col = c.getColumnIndex("scrambled_flag");
- this->scrambled = (c.getInt(col) != 0);
-
- col = c.getColumnIndex("favor");
- this->favorite = (c.getInt(col) != 0);
-
- col = c.getColumnIndex("volume");
- this->volume = c.getInt(col);
-
- //Video
- int pid, fmt;
- col = c.getColumnIndex("vid_pid");
- pid = c.getInt(col);
-
- col = c.getColumnIndex("vid_fmt");
- fmt = c.getInt(col);
-
- //LOGD("----------vpid = %d", pid);
- this->mpVideo = new Video(pid, fmt);
- //LOGD("----------vpid = %d", this->mpVideo->getPID());
-
-
- //Audio
- String8 strPids;
- String8 strFmts;
- String8 strLangs;
- int count = 0;
- col = c.getColumnIndex("aud_pids");
- strPids = c.getString(col);
-
- col = c.getColumnIndex("aud_fmts");
- strFmts = c.getString(col);
-
- col = c.getColumnIndex("aud_langs");
- strLangs = c.getString(col);
- col = c.getColumnIndex("current_aud");
- this->currAudTrackIndex = c.getInt(col);
-
- char *tmp;
- Vector<String8> vpid ;
- Vector<String8> vfmt ;
- Vector<String8> vlang;
-
- tmp = strtok(strPids.lockBuffer(strPids.length()), " ");
- while (tmp != NULL) {
- vpid.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- strPids.unlockBuffer();
-
- tmp = strtok(strFmts.lockBuffer(strFmts.length()), " ");
- while (tmp != NULL) {
- vfmt.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- strFmts.unlockBuffer();
-
- tmp = strtok(strLangs.lockBuffer(strLangs.length()), " ");
-
- while (tmp != NULL) {
- vlang.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- strLangs.unlockBuffer();
-
- //check empty aud_langs
- for(i = vlang.size(); i < vpid.size(); i++) {
- sprintf(tmp_buf, "Audio%d", i + 1);
- vlang.push_back(String8(tmp_buf));
- LOGE("%s, aud_langs is empty, add dummy data (%s).\n", "TV", tmp_buf);
- }
-
- //String8 l(vlang[i]);
- for(i = 0; i < vpid.size(); i++) {
- int i_pid = atoi(vpid[i]);
- int i_fmt = atoi(vfmt[i]);
- mvAudios.push_back(new Audio(i_pid, vlang[i], i_fmt));
- }
-
-
-
- /* parse subtitles */
- vpid.clear();
- vlang.clear();
- Vector<String8> vcid;
- Vector<String8> vaid;
- String8 strCids;
- String8 strAids;
-
- col = c.getColumnIndex("sub_pids");
- strPids = c.getString(col);
-
- col = c.getColumnIndex("sub_composition_page_ids");
- strCids = c.getString(col);
-
- col = c.getColumnIndex("sub_ancillary_page_ids");
- strAids = c.getString(col);
-
-
- col = c.getColumnIndex("sub_langs");
- strLangs = c.getString(col);
-
- tmp = strtok(strPids.lockBuffer(strPids.length()), " ");
- while (tmp != NULL) {
- vpid.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- strPids.unlockBuffer();
-
- tmp = strtok(strCids.lockBuffer(strCids.length()), " ");
- while (tmp != NULL) {
- vcid.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- strCids.unlockBuffer();
-
- tmp = strtok(strAids.lockBuffer(strAids.length()), " ");
- while (tmp != NULL) {
- vaid.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- strAids.unlockBuffer();
-
- tmp = strtok(strLangs.lockBuffer(strLangs.length()), " ");
- while (tmp != NULL) {
- vlang.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- strLangs.unlockBuffer();
-
- //Subtitle
- for(int i = 0; i < vpid.size(); i++) {
- this->mvSubtitles.push_back(new Subtitle(
- atoi(vpid[i]),
- String8(vlang[i]), Subtitle::TYPE_DVB_SUBTITLE,
- atoi(vcid[i]),
- atoi(vaid[i])));
- }
-
- /* parse teletexts */
- int ttx_count = 0, ttx_sub_count = 0;
- String8 str_ttx_pids, str_ttx_types, str_mag_nos, str_page_nos, str_ttx_langs;
- Vector<String8> v_ttx_pids, v_ttx_types, v_mag_nos, v_page_nos, v_ttx_langs;
- col = c.getColumnIndex("ttx_pids");
- str_ttx_pids = c.getString(col);
-
- col = c.getColumnIndex("ttx_types");
- str_ttx_types = c.getString(col);
-
- col = c.getColumnIndex("ttx_magazine_nos");
- str_mag_nos = c.getString(col);
-
- col = c.getColumnIndex("ttx_page_nos");
- str_page_nos = c.getString(col);
-
- col = c.getColumnIndex("ttx_langs");
- str_ttx_langs = c.getString(col);
-
- tmp = strtok(str_ttx_pids.lockBuffer(str_ttx_pids.length()), " ");
- while (tmp != NULL) {
- v_ttx_pids.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- str_ttx_pids.unlockBuffer();
-
- tmp = strtok(str_ttx_types.lockBuffer(str_ttx_types.length()), " ");
- while (tmp != NULL) {
- v_ttx_types.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- str_ttx_types.unlockBuffer();
-
- tmp = strtok(str_mag_nos.lockBuffer(str_mag_nos.length()), " ");
- while (tmp != NULL) {
- v_mag_nos.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- str_mag_nos.unlockBuffer();
-
- tmp = strtok(str_page_nos.lockBuffer(str_page_nos.length()), " ");
- while (tmp != NULL) {
- v_page_nos.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- str_page_nos.unlockBuffer();
-
- tmp = strtok(str_ttx_langs.lockBuffer(str_ttx_langs.length()), " ");
- while (tmp != NULL) {
- v_ttx_langs.push_back(String8(tmp));
- tmp = strtok(NULL, " ");
- }
- str_ttx_langs.unlockBuffer();
-
-
- for(int i = 0; i < v_ttx_pids.size(); i++) {
- int ttype = atoi(v_ttx_types[i]);
- if (ttype == 0x2 || ttype == 0x5) {
- this->mvSubtitles.push_back(new Subtitle(
- atoi(v_ttx_pids[i].string()),
- String8(v_ttx_langs[i]), Subtitle::TYPE_DTV_TELETEXT,
- atoi(v_mag_nos[i]),
- atoi(v_page_nos[i])));
- } else {
- this->mvTeletexts.push_back(new Teletext(
- atoi(v_ttx_pids[i]),
- String8(v_ttx_langs[i]),
- atoi(v_mag_nos[i]),
- atoi(v_page_nos[i])));
- }
- }
- return 0;
-}
-
-int CTvProgram::selectProgramInChannelByNumber(int channelID, int num, CTvDatabase::Cursor &c)
-{
- String8 cmd = String8("select * from srv_table where db_ts_id = ") + String8::format("%d", channelID) + String8(" and ");
- cmd += String8("chan_num = ") + String8::format("%d", num);
- return CTvDatabase::GetTvDb()->select(cmd, c);
-}
-
-
-int CTvProgram::selectProgramInChannelByNumber(int channelID, int major, int minor, CTvDatabase::Cursor &c)
-{
- String8 cmd = String8("select * from srv_table where db_ts_id = ") + String8::format("%d", channelID) + String8(" and ");
- cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
-
- return CTvDatabase::GetTvDb()->select(cmd, c);
-}
-
-/**
- *向数据库添加一个Program,not atscMode
- */
-CTvProgram::CTvProgram(int channelID, int type, int num, int skipFlag)
-{
- CTvChannel channel;
- int ret = CTvChannel::selectByID(channelID, channel);
- if (ret != 0) {
- //Log.d(TAG, "Cannot add new program, invalid channel id "+channelID);
- this->id = -1;
- } else {
- CTvDatabase::Cursor c ;
- selectProgramInChannelByNumber(channelID, num, c);
-
- if(c.moveToFirst()) {
- /*Construct*/
- CreateFromCursor(c);
- } else {
- String8 tpids = String8(""), ttypes = String8(""), tmagnums = String8(""), tpgnums = String8(""), tlangs = String8("");
- String8 spids = String8(""), stypes = String8(""), scpgids = String8(""), sapgids = String8(""), slangs = String8("");
-
- /*add a new atv program to database*/
- String8 cmd = String8("insert into srv_table(db_net_id,db_ts_id,service_id,src,name,service_type,");
- cmd += String8("eit_schedule_flag,eit_pf_flag,running_status,free_ca_mode,volume,aud_track,vid_pid,");
- cmd += String8("vid_fmt,aud_pids,aud_fmts,aud_langs,skip,lock,chan_num,major_chan_num,");
- cmd += String8("minor_chan_num,access_controlled,hidden,hide_guide,source_id,favor,current_aud,");
- cmd += String8("current_sub,sub_pids,sub_types,sub_composition_page_ids,sub_ancillary_page_ids,sub_langs,");
- cmd += String8("current_ttx,ttx_pids,ttx_types,ttx_magazine_nos,ttx_page_nos,ttx_langs,");
- cmd += String8("db_sat_para_id,scrambled_flag,lcn,hd_lcn,sd_lcn,default_chan_num,chan_order) ");
- cmd += String8("values(-1,") + String8::format("%d", channelID) + String8(",65535,") + String8::format("%d", channel.getMode()) + String8(",'',") + String8::format("%d", type) + String8(",");
- cmd += String8("0,0,0,0,0,0,8191,");
- int chanNum = num;
- int majorNum = 0;
- cmd += String8("-1,'','','',") + String8::format("%d", skipFlag) + String8(",0,") + String8::format("%d", chanNum) + String8(",") + String8::format("%d", majorNum) + String8(",");
- cmd += String8("") + /*num.getMinor()*/String8("0") + String8(",0,0,0,-1,0,-1,");
- cmd += String8("-1,'") + spids + String8("','") + stypes + String8("','") + scpgids + String8("','") + sapgids + String8("','") + slangs + String8("',");
- cmd += String8("-1,'") + tpids + String8("','") + ttypes + String8("','") + tmagnums + String8("','") + tpgnums + String8("','") + tlangs + String8("',");
- cmd += String8("-1,0,-1,-1,-1,-1,0)");
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-
- CTvDatabase::Cursor cr;
- selectProgramInChannelByNumber(channelID, num, cr);
- if(cr.moveToFirst()) {
- /*Construct*/
- CreateFromCursor(cr);
- } else {
- /*A critical error*/
- //Log.d(TAG, "Cannot add new program, sqlite error");
- this->id = -1;
- }
- cr.close();
- }
- c.close();
- }
-
-}
-
-
-/**
- *向数据库添加一个Program,atscMode
- */
-CTvProgram::CTvProgram(int channelID, int type, int major, int minor, int skipFlag)
-{
- CTvChannel channel;
- int ret = CTvChannel::selectByID(channelID, channel);
- if (ret != 0) {
- //Log.d(TAG, "Cannot add new program, invalid channel id "+channelID);
- this->id = -1;
- } else {
- CTvDatabase::Cursor c ;
- selectProgramInChannelByNumber(channelID, major, minor, c);
-
- if(c.moveToFirst()) {
- /*Construct*/
- CreateFromCursor(c);
- } else {
- String8 tpids = String8(""), ttypes = String8(""), tmagnums = String8(""), tpgnums = String8(""), tlangs = String8("");
- String8 spids = String8(""), stypes = String8(""), scpgids = String8(""), sapgids = String8(""), slangs = String8("");
-
- /*add a new atv program to database*/
- String8 cmd = String8("insert into srv_table(db_net_id,db_ts_id,service_id,src,name,service_type,");
- cmd += String8("eit_schedule_flag,eit_pf_flag,running_status,free_ca_mode,volume,aud_track,vid_pid,");
- cmd += String8("vid_fmt,aud_pids,aud_fmts,aud_langs,skip,lock,chan_num,major_chan_num,");
- cmd += String8("minor_chan_num,access_controlled,hidden,hide_guide,source_id,favor,current_aud,");
- cmd += String8("current_sub,sub_pids,sub_types,sub_composition_page_ids,sub_ancillary_page_ids,sub_langs,");
- cmd += String8("current_ttx,ttx_pids,ttx_types,ttx_magazine_nos,ttx_page_nos,ttx_langs,");
- cmd += String8("db_sat_para_id,scrambled_flag,lcn,hd_lcn,sd_lcn,default_chan_num,chan_order) ");
- cmd += String8("values(-1,") + String8::format("%d", channelID) + String8(",65535,") + String8::format("%d", channel.getMode()) + String8(",'',") + String8::format("%d", type) + String8(",");
- cmd += String8("0,0,0,0,0,0,8191,");
- int chanNum = major << 16 | minor;
- int majorNum = major;
- cmd += String8("-1,'','','',") + String8::format("%d", skipFlag) + String8(",0,") + String8::format("%d", chanNum) + String8(",") + String8::format("%d", majorNum) + String8(",");
- cmd += String8("") + String8::format("%d", minor) + String8(",0,0,0,-1,0,-1,");
- cmd += String8("-1,'") + spids + String8("','") + stypes + String8("','") + scpgids + String8("','") + sapgids + String8("','") + slangs + String8("',");
- cmd += String8("-1,'") + tpids + String8("','") + ttypes + String8("','") + tmagnums + String8("','") + tpgnums + String8("','") + tlangs + String8("',");
- cmd += String8("-1,0,-1,-1,-1,-1,0)");
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-
- CTvDatabase::Cursor cr;
- selectProgramInChannelByNumber(channelID, major, minor, cr);
- if(cr.moveToFirst()) {
- /*Construct*/
- CreateFromCursor(cr);
- } else {
- /*A critical error*/
- //Log.d(TAG, "Cannot add new program, sqlite error");
- this->id = -1;
- }
- cr.close();
- }
- c.close();
- }
-
-}
-/**
- *根据记录ID查找指定TVProgram
-*/
-
-int CTvProgram::selectByID(int id, CTvProgram &prog)
-{
-
- CTvDatabase::Cursor c;
- String8 sql;
- sql = String8("select * from srv_table where srv_table.db_id = ") + String8::format("%d", id);
- CTvDatabase::GetTvDb()->select(sql.string(), c) ;
- if(c.moveToFirst()) {
- prog.CreateFromCursor(c);
- } else {
- c.close();
- return -1;
- }
- c.close();
- return 0;
-}
-
-int CTvProgram::updateVolComp(int progID, int volValue)
-{
- String8 cmd = String8("update srv_table set volume = ") + String8::format("%d", volValue) +
- String8(" where srv_table.db_id = ") + String8::format("%d", progID);
- LOGD("%s, cmd = %s\n", "TV", cmd.string());
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-
- return 0;
-}
-
-int CTvProgram::getChannel(CTvChannel &c)
-{
- return CTvChannel::selectByID(channelID, c);
-}
-
-int CTvProgram::upDateChannel(CTvChannel &c, int std, int Freq, int fineFreq)
-{
- return CTvChannel::updateByID(channelID, std, Freq, fineFreq);
-}
-
-int CTvProgram::deleteChannelsProgram(CTvChannel &c)
-{
- String8 cmd;
- cmd = String8("delete from srv_table where srv_table.db_ts_id = ") + String8::format("%d", c.getID());
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
- return 0;
-}
-
-
-/**
- *根据节目类型和节目号查找指定TVProgram
-*/
-int CTvProgram::selectByNumber(int type, int num, CTvProgram &prog)
-{
- String8 cmd;
-
- cmd = String8("select * from srv_table where ");
- if(type != TYPE_UNKNOWN) {
- if(type == TYPE_DTV) {
- cmd += String8("(service_type = ") + String8::format("%d", TYPE_TV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") and ");
- } else {
- cmd += String8("service_type = ") + String8::format("%d", type) + String8(" and ");
- }
- }
-
- cmd += String8("chan_num = ") + String8::format("%d", num);
-
- CTvDatabase::Cursor c;
- CTvDatabase::GetTvDb()->select(cmd, c);
-
- if(c.moveToFirst()) {
- prog.CreateFromCursor(c);
- } else {
- c.close();
- return -1;
- }
- c.close();
-
- return 0;
-}
-
-/**
- *根据节目类型和节目号查找指定TVProgram
-*/
-int CTvProgram::selectByNumber(int type, int major, int minor, CTvProgram &prog, int minor_check)
-{
- String8 cmd;
-
- cmd = String8("select * from srv_table where ");
- if(type != TYPE_UNKNOWN) {
- if(type == TYPE_DTV) {
- cmd += String8("(service_type = ") + String8::format("%d", TYPE_TV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") and ");
- } else {
- cmd += String8("service_type = ") + String8::format("%d", type) + String8(" and ");
- }
- }
-
- if (minor < 0) {
- /*recursive call*/
- /*select dtv program first*/
- //showbo
- int ret = selectByNumber(TYPE_DTV, major, 1, prog, MINOR_CHECK_NEAREST_UP);
- if (ret != 0) {
- /*then try atv program*/
- selectByNumber(TYPE_ATV, major, 0 , prog, MINOR_CHECK_NONE);
- }
- return 0;
- } else if (minor >= 1) {
- if (minor_check == MINOR_CHECK_UP) {
- cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num >= ") + String8::format("%d", minor) + String8(" ");
- cmd += String8("order by minor_chan_num DESC limit 1");
- } else if (minor_check == MINOR_CHECK_DOWN) {
- cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num <= ") + String8::format("%d", minor) + String8(" ");
- cmd += String8("order by minor_chan_num limit 1");
- } else if (minor_check == MINOR_CHECK_NEAREST_UP) {
- cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num >= ") + String8::format("%d", minor) + String8(" ");
- cmd += String8("order by minor_chan_num limit 1");
- } else if (minor_check == MINOR_CHECK_NEAREST_DOWN) {
- cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num <= ") + String8::format("%d", minor) + String8(" ");
- cmd += String8("order by minor_chan_num DESC limit 1");
- } else {
- cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
- }
- } else {
- cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
- }
-
-
- CTvDatabase::Cursor c;
- CTvDatabase::GetTvDb()->select(cmd, c);
-
- if(c.moveToFirst()) {
- prog.CreateFromCursor(c);
- } else {
- c.close();
- return -1;
- }
- c.close();
-
- return 0;
-}
-
-
-/**
- *列出一个channel的全部TVProgram
- *@param channelID channel id
- *@param type 节目类型
- */
-int CTvProgram::selectByChannel(int channelID, int type, Vector<sp<CTvProgram> > &out)
-{
-
- //Vector<CTvProgram*> vp;
- String8 cmd = String8("select * from srv_table ");
-
-
- if(type == TYPE_DTV) {
- cmd += String8("where (service_type = ") + String8::format("%d", TYPE_TV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") ");
- } else if(type != TYPE_UNKNOWN) {
- cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
- }
-
- cmd += String8(" and db_ts_id = ") + String8::format("%d", channelID) + String8(" order by chan_order");
-
- CTvDatabase::Cursor c;
- int ret = CTvDatabase::GetTvDb()->select(cmd, c);
-
- LOGD("selectByChannel select ret = %d", ret);
-
- if(c.moveToFirst()) {
- do {
- out.add(new CTvProgram(c));
- } while(c.moveToNext());
- }
- c.close();
-
- return 0;
-}
-
-void CTvProgram::deleteProgram(int progId)
-{
- String8 cmd;
-
- cmd = String8("delete from srv_table where srv_table.db_id = ") + String8::format("%d", progId);
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-}
-
-int CTvProgram::CleanAllProgramBySrvType(int srvType)
-{
- String8 cmd = String8("delete from srv_table where service_type = ") + String8::format("%d", srvType);
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
- return 0;
-}
-
-int CTvProgram::selectByType(int type, int skip, Vector<sp<CTvProgram> > &out)
-{
- String8 cmd = String8("select * from srv_table ");
- LOGD("%s, type= %d\n", "TV", (int)type);
-
- if (type == TYPE_UNKNOWN) {
- cmd += String8("where (service_type = ") + String8::format("%d", TYPE_ATV) +
- String8(" or service_type = ") + String8::format("%d", TYPE_DTV) +
- String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) +
- String8(") ");
- } else {
- cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
- }
-
- if(skip == PROGRAM_SKIP_NO || skip == PROGRAM_SKIP_YES)
- cmd += String8(" and skip = ") + String8::format("%d", skip) + String8(" ");
-
- cmd += String8(" order by chan_order");
-
- CTvDatabase::Cursor c;
- int ret = CTvDatabase::GetTvDb()->select(cmd, c);
-
- LOGD("selectByChannel select ret = %d", ret);
-
- if(c.moveToFirst()) {
- do {
- out.add(new CTvProgram(c));
- } while(c.moveToNext());
- }
- c.close();
-
- return 0;
-}
-
-int CTvProgram::selectByChanID(int type, int skip, Vector < sp < CTvProgram > > &out)
-{
- String8 cmd = String8("select * from srv_table ");
-
- if (type == TYPE_UNKNOWN) {
- cmd += String8("where (service_type = ") + String8::format("%d", TYPE_ATV) +
- String8(" or service_type = ") + String8::format("%d", TYPE_DTV) +
- String8(") ");
- } else {
- cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
- }
-
- if(skip == PROGRAM_SKIP_NO || skip == PROGRAM_SKIP_YES)
- cmd += String8(" and skip = ") + String8::format("%d", PROGRAM_SKIP_NO) +
- String8(" or skip = ") + String8::format("%d", PROGRAM_SKIP_YES) + String8(" ");
-
- cmd += String8(" order by db_id");
-
- CTvDatabase::Cursor c;
- int ret = CTvDatabase::GetTvDb()->select(cmd, c);
-
- if(c.moveToFirst()) {
- do {
- out.add(new CTvProgram(c));
- } while(c.moveToNext());
- }
- c.close();
-
- return 0;
-
-}
-
-int CTvProgram::selectAll(bool no_skip, Vector<sp<CTvProgram> > &out)
-{
- return selectByType(TYPE_UNKNOWN, no_skip, out);
-}
-
-Vector<CTvProgram> CTvProgram::selectByChannel(int channelID)
-{
- Vector<CTvProgram> vProg;
- return vProg;
-}
-
-Vector<CTvProgram> CTvProgram::selectByName(int name)
-{
- Vector<CTvProgram> vProg;
- return vProg;
-}
-
-void CTvProgram::tvProgramDelByChannelID(int channelID)
-{
-
-}
-
-
-String8 CTvProgram::getName()
-{
- return name;
-}
-int CTvProgram::getProgSkipFlag()
-{
- return skip;
-}
-
-/**
- *取得当前的audio索引
- *@param defaultLang 用户未选择语言时,默认的全局语言
- *@return 当前的Audio索引
- */
-int CTvProgram::getCurrentAudio(String8 defaultLang)
-{
- CTvDatabase::Cursor c;
- String8 cmd;
- cmd = String8("select current_aud from srv_table where db_id = ") + String8::format("%d", this->id);
- int ret = CTvDatabase::GetTvDb()->select(cmd, c);
- LOGD("getCurrentAudio a size = %d", mvAudios.size());
- int id = 0;
- if(c.moveToFirst()) {
- id = c.getInt(0);
- LOGD("getCurrentAudio a id = %d", id);
- if (id < 0 && mvAudios.size() > 0) {
- LOGD("getCurrentAudio defaultLang.isEmpty() =%s= %d", defaultLang.string(), defaultLang.isEmpty());
- if(!defaultLang.isEmpty()) {
- for(int i = 0; i < mvAudios.size(); i++) {
- LOGD("getCurrentAudio a mvAudios[i] = %d", mvAudios[i]);
- if(mvAudios[i]->getLang() == defaultLang) {
- id = i;
- break;
- }
- }
- }
-
- if (id < 0) {
- /* still not found, using the first */
- id = 0;
- }
- }
- }
- LOGD("getCurrentAudio a idsss = %d", id);
- c.close();
-
- return id;
-}
-
-int CTvProgram::getCurrAudioTrackIndex()
-{
- int audTrackIdx = -1;
-
- if(-1 == currAudTrackIndex) { // no set field "current_aud"
- audTrackIdx = getCurrentAudio(String8("eng"));
- setCurrAudioTrackIndex(this->id, audTrackIdx);
- } else {
- audTrackIdx = currAudTrackIndex;
- }
-
- return audTrackIdx;
-}
-
-
-void CTvProgram::setCurrAudioTrackIndex(int programId, int audioIndex)
-{
- String8 cmd;
-
- cmd = String8("update srv_table set current_aud = ")
- + String8::format("%d", audioIndex) + String8(" where srv_table.db_id = ") + String8::format("%d", programId);
-
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-}
-
-void CTvProgram::setFavoriteFlag(int progId, bool bFavor)
-{
- String8 cmd;
-
- cmd = String8("update srv_table set favor = ")
- + String8::format("%d", bFavor ? 1 : 0) + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
-
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-
-}
-
-void CTvProgram::setSkipFlag(int progId, bool bSkipFlag)
-{
- String8 cmd;
-
- cmd = String8("update srv_table set skip = ") + String8::format("%d", bSkipFlag ? 1 : 0)
- + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
-
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-}
-
-void CTvProgram::updateProgramName(int progId, String8 strName)
-{
- String8 newName = String8("xxx") + strName;
- String8 cmd;
-
- cmd = String8("update srv_table set name =") + "\'" + String8::format("%s", newName.string()) + "\'"
- + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
-
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-}
-
-void CTvProgram::swapChanOrder(int ProgId1, int chanOrderNum1, int ProgId2, int chanOrderNum2)
-{
- String8 cmd;
-
- cmd = String8("update srv_table set chan_order = ") + String8::format("%d", chanOrderNum2)
- + String8(" where db_id = ") + String8::format("%d", ProgId1);
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-
- String8 cmd2;
- cmd2 = String8("update srv_table set chan_order = ") + String8::format("%d", chanOrderNum1)
- + String8(" where db_id = ") + String8::format("%d", ProgId2);
- CTvDatabase::GetTvDb()->exeSql(cmd2.string());
-}
-
-
-void CTvProgram::setLockFlag(int progId, bool bLockFlag)
-{
- String8 cmd;
-
- cmd = String8("update srv_table set lock = ") + String8::format("%d", bLockFlag ? 1 : 0)
- + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
-
- CTvDatabase::GetTvDb()->exeSql(cmd.string());
-}
-bool CTvProgram::getLockFlag()
-{
- return lock;
-}
-
+//
+//
+// amlogic 2013
+//
+// @ Project : tv
+// @ File Name : CTvProgram.cpp
+// @ Date : 2013-11
+// @ Author :
+//
+//
+
+
+#include "CTvProgram.h"
+#include "CTvDatabase.h"
+#include "CTvChannel.h"
+#include "CTvEvent.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define LOG_TAG "CTvProgram"
+#endif
+
+CTvProgram::CTvProgram(CTvDatabase::Cursor &c)
+{
+ CreateFromCursor(c);
+}
+
+CTvProgram::~CTvProgram()
+{
+ //free mem
+ // video
+ if (mpVideo != NULL) delete mpVideo;
+ // audios
+ int size = mvAudios.size();
+ for (int i = 0; i < size; i++)
+ delete mvAudios[i];
+ // subtitles
+ size = mvSubtitles.size();
+ for (int i = 0; i < size; i++)
+ delete mvSubtitles[i];
+ // teletexts
+ size = mvTeletexts.size();
+ for (int i = 0; i < size; i++)
+ delete mvTeletexts[i];
+}
+
+CTvProgram::CTvProgram(int channelID, int type)
+{
+ mpVideo = NULL;
+}
+
+CTvProgram::CTvProgram()
+{
+ mpVideo = NULL;
+}
+int CTvProgram::CreateFromCursor(CTvDatabase::Cursor &c)
+{
+ int i = 0;
+ int col;
+ int num, type;
+ int major, minor;
+ char tmp_buf[256];
+ //LOGD("CTvProgram::CreateFromCursor");
+ col = c.getColumnIndex("db_id");
+ this->id = c.getInt(col);
+
+ col = c.getColumnIndex("source_id");
+ this->sourceID = c.getInt(col);
+
+ col = c.getColumnIndex("src");
+ this->src = c.getInt(col);
+
+ col = c.getColumnIndex("service_id");
+ this->dvbServiceID = c.getInt(col);
+
+ col = c.getColumnIndex("db_ts_id");
+ this->channelID = c.getInt(col);
+
+ col = c.getColumnIndex("name");
+ this->name = c.getString(col);
+
+ col = c.getColumnIndex("chan_num");
+ num = c.getInt(col);
+
+ col = c.getColumnIndex("chan_order");
+ this->chanOrderNum = c.getInt(col);
+
+ col = c.getColumnIndex("major_chan_num");
+ major = c.getInt(col);
+
+ col = c.getColumnIndex("minor_chan_num");
+ minor = c.getInt(col);
+
+ col = c.getColumnIndex("aud_track");
+ this->audioTrack = c.getInt(col);
+
+ //节目号信息初??
+ if (src == CTvChannel::MODE_ATSC || (src == CTvChannel::MODE_ANALOG && major > 0)) {
+ this->major = major;
+ this->minor = minor;
+ this->atscMode = true;
+ this->minorCheck = MINOR_CHECK_NONE;
+ } else {
+ this->major = num;
+ this->minor = 0;
+ this->atscMode = false;
+ this->minorCheck = MINOR_CHECK_NONE;
+ }
+
+ col = c.getColumnIndex("service_type");
+ this->type = c.getInt(col);
+
+ col = c.getColumnIndex("pmt_pid");
+ pmtPID = c.getInt(col);
+
+ //LOGD("CTvProgram::CreateFromCursor type = %d", this->type);
+ col = c.getColumnIndex("skip");
+ this->skip = c.getInt(col);
+
+ col = c.getColumnIndex("lock");
+ this->lock = (c.getInt(col) != 0);
+
+ col = c.getColumnIndex("scrambled_flag");
+ this->scrambled = (c.getInt(col) != 0);
+
+ col = c.getColumnIndex("favor");
+ this->favorite = (c.getInt(col) != 0);
+
+ col = c.getColumnIndex("volume");
+ this->volume = c.getInt(col);
+
+ //Video
+ int pid, fmt;
+ col = c.getColumnIndex("vid_pid");
+ pid = c.getInt(col);
+
+ col = c.getColumnIndex("vid_fmt");
+ fmt = c.getInt(col);
+
+ //LOGD("----------vpid = %d", pid);
+ this->mpVideo = new Video(pid, fmt);
+ //LOGD("----------vpid = %d", this->mpVideo->getPID());
+
+
+ //Audio
+ String8 strPids;
+ String8 strFmts;
+ String8 strLangs;
+ int count = 0;
+ col = c.getColumnIndex("aud_pids");
+ strPids = c.getString(col);
+
+ col = c.getColumnIndex("aud_fmts");
+ strFmts = c.getString(col);
+
+ col = c.getColumnIndex("aud_langs");
+ strLangs = c.getString(col);
+ col = c.getColumnIndex("current_aud");
+ this->currAudTrackIndex = c.getInt(col);
+
+ char *tmp;
+ Vector<String8> vpid ;
+ Vector<String8> vfmt ;
+ Vector<String8> vlang;
+
+ char *pSave;
+ tmp = strtok_r(strPids.lockBuffer(strPids.length()), " ", &pSave);
+ while (tmp != NULL) {
+ vpid.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ strPids.unlockBuffer();
+
+ tmp = strtok_r(strFmts.lockBuffer(strFmts.length()), " ", &pSave);
+ while (tmp != NULL) {
+ vfmt.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ strFmts.unlockBuffer();
+
+ tmp = strtok_r(strLangs.lockBuffer(strLangs.length()), " ", &pSave);
+
+ while (tmp != NULL) {
+ vlang.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ strLangs.unlockBuffer();
+
+ //check empty aud_langs
+ for (i = vlang.size(); i < vpid.size(); i++) {
+ sprintf(tmp_buf, "Audio%d", i + 1);
+ vlang.push_back(String8(tmp_buf));
+ LOGE("%s, aud_langs is empty, add dummy data (%s).\n", "TV", tmp_buf);
+ }
+
+ //String8 l(vlang[i]);
+ for (i = 0; i < vpid.size(); i++) {
+ int i_pid = atoi(vpid[i]);
+ int i_fmt = atoi(vfmt[i]);
+ mvAudios.push_back(new Audio(i_pid, vlang[i], i_fmt));
+ }
+
+
+
+ /* parse subtitles */
+ vpid.clear();
+ vlang.clear();
+ Vector<String8> vcid;
+ Vector<String8> vaid;
+ String8 strCids;
+ String8 strAids;
+
+ col = c.getColumnIndex("sub_pids");
+ strPids = c.getString(col);
+
+ col = c.getColumnIndex("sub_composition_page_ids");
+ strCids = c.getString(col);
+
+ col = c.getColumnIndex("sub_ancillary_page_ids");
+ strAids = c.getString(col);
+
+
+ col = c.getColumnIndex("sub_langs");
+ strLangs = c.getString(col);
+
+ tmp = strtok_r(strPids.lockBuffer(strPids.length()), " ", &pSave);
+ while (tmp != NULL) {
+ vpid.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ strPids.unlockBuffer();
+
+ tmp = strtok_r(strCids.lockBuffer(strCids.length()), " ", &pSave);
+ while (tmp != NULL) {
+ vcid.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ strCids.unlockBuffer();
+
+ tmp = strtok_r(strAids.lockBuffer(strAids.length()), " ", &pSave);
+ while (tmp != NULL) {
+ vaid.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ strAids.unlockBuffer();
+
+ tmp = strtok_r(strLangs.lockBuffer(strLangs.length()), " ", &pSave);
+ while (tmp != NULL) {
+ vlang.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ strLangs.unlockBuffer();
+
+ //Subtitle
+ for (int i = 0; i < vpid.size(); i++) {
+ this->mvSubtitles.push_back(new Subtitle(
+ atoi(vpid[i]),
+ String8(vlang[i]), Subtitle::TYPE_DVB_SUBTITLE,
+ atoi(vcid[i]),
+ atoi(vaid[i])));
+ }
+
+ /*
+ parse teletexts
+ int ttx_count = 0, ttx_sub_count = 0;
+ String8 str_ttx_pids, str_ttx_types, str_mag_nos, str_page_nos, str_ttx_langs;
+ Vector<String8> v_ttx_pids, v_ttx_types, v_mag_nos, v_page_nos, v_ttx_langs;
+ col = c.getColumnIndex("ttx_pids");
+ str_ttx_pids = c.getString(col);
+
+ col = c.getColumnIndex("ttx_types");
+ str_ttx_types = c.getString(col);
+
+ col = c.getColumnIndex("ttx_magazine_nos");
+ str_mag_nos = c.getString(col);
+
+ col = c.getColumnIndex("ttx_page_nos");
+ str_page_nos = c.getString(col);
+
+ col = c.getColumnIndex("ttx_langs");
+ str_ttx_langs = c.getString(col);
+
+ tmp = strtok_r(str_ttx_pids.lockBuffer(str_ttx_pids.length()), " ", &pSave);
+ while (tmp != NULL) {
+ v_ttx_pids.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ str_ttx_pids.unlockBuffer();
+
+ tmp = strtok_r(str_ttx_types.lockBuffer(str_ttx_types.length()), " ", &pSave);
+ while (tmp != NULL) {
+ v_ttx_types.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ str_ttx_types.unlockBuffer();
+
+ tmp = strtok_r(str_mag_nos.lockBuffer(str_mag_nos.length()), " ", &pSave);
+ while (tmp != NULL) {
+ v_mag_nos.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ str_mag_nos.unlockBuffer();
+
+ tmp = strtok_r(str_page_nos.lockBuffer(str_page_nos.length()), " ", &pSave);
+ while (tmp != NULL) {
+ v_page_nos.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ str_page_nos.unlockBuffer();
+
+ tmp = strtok_r(str_ttx_langs.lockBuffer(str_ttx_langs.length()), " ", &pSave);
+ while (tmp != NULL) {
+ v_ttx_langs.push_back(String8(tmp));
+ tmp = strtok_r(NULL, " ", &pSave);
+ }
+ str_ttx_langs.unlockBuffer();
+
+
+ for (int i = 0; i < v_ttx_pids.size(); i++) {
+ int ttype = atoi(v_ttx_types[i]);
+ if (ttype == 0x2 || ttype == 0x5) {
+ this->mvSubtitles.push_back(new Subtitle(
+ atoi(v_ttx_pids[i].string()),
+ String8(v_ttx_langs[i]), Subtitle::TYPE_DTV_TELETEXT,
+ atoi(v_mag_nos[i]),
+ atoi(v_page_nos[i])));
+ } else {
+ this->mvTeletexts.push_back(new Teletext(
+ atoi(v_ttx_pids[i]),
+ String8(v_ttx_langs[i]),
+ atoi(v_mag_nos[i]),
+ atoi(v_page_nos[i])));
+ }
+ }
+ */
+ return 0;
+}
+
+int CTvProgram::selectProgramInChannelByNumber(int channelID, int num, CTvDatabase::Cursor &c)
+{
+ String8 cmd = String8("select * from srv_table where db_ts_id = ") + String8::format("%d", channelID) + String8(" and ");
+ cmd += String8("chan_num = ") + String8::format("%d", num);
+ return CTvDatabase::GetTvDb()->select(cmd, c);
+}
+
+
+int CTvProgram::selectProgramInChannelByNumber(int channelID, int major, int minor, CTvDatabase::Cursor &c)
+{
+ String8 cmd = String8("select * from srv_table where db_ts_id = ") + String8::format("%d", channelID) + String8(" and ");
+ cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
+
+ return CTvDatabase::GetTvDb()->select(cmd, c);
+}
+
+/**
+ *向数据库添加一个Program,not atscMode
+ */
+CTvProgram::CTvProgram(int channelID, int type, int num, int skipFlag)
+{
+ CTvChannel channel;
+ int ret = CTvChannel::selectByID(channelID, channel);
+ if (ret != 0) {
+ //Log.d(TAG, "Cannot add new program, invalid channel id "+channelID);
+ this->id = -1;
+ } else {
+ CTvDatabase::Cursor c ;
+ selectProgramInChannelByNumber(channelID, num, c);
+
+ if (c.moveToFirst()) {
+ /*Construct*/
+ CreateFromCursor(c);
+ } else {
+ String8 tpids = String8(""), ttypes = String8(""), tmagnums = String8(""), tpgnums = String8(""), tlangs = String8("");
+ String8 spids = String8(""), stypes = String8(""), scpgids = String8(""), sapgids = String8(""), slangs = String8("");
+
+ /*add a new atv program to database*/
+ String8 cmd = String8("insert into srv_table(db_net_id,db_ts_id,service_id,src,name,service_type,");
+ cmd += String8("eit_schedule_flag,eit_pf_flag,running_status,free_ca_mode,volume,aud_track,vid_pid,");
+ cmd += String8("vid_fmt,aud_pids,aud_fmts,aud_langs,skip,lock,chan_num,major_chan_num,");
+ cmd += String8("minor_chan_num,access_controlled,hidden,hide_guide,source_id,favor,current_aud,");
+ cmd += String8("current_sub,sub_pids,sub_types,sub_composition_page_ids,sub_ancillary_page_ids,sub_langs,");
+ cmd += String8("current_ttx,ttx_pids,ttx_types,ttx_magazine_nos,ttx_page_nos,ttx_langs,");
+ cmd += String8("db_sat_para_id,scrambled_flag,lcn,hd_lcn,sd_lcn,default_chan_num,chan_order) ");
+ cmd += String8("values(-1,") + String8::format("%d", channelID) + String8(",65535,") + String8::format("%d", channel.getMode()) + String8(",'',") + String8::format("%d", type) + String8(",");
+ cmd += String8("0,0,0,0,0,0,8191,");
+ int chanNum = num;
+ int majorNum = 0;
+ cmd += String8("-1,'','','',") + String8::format("%d", skipFlag) + String8(",0,") + String8::format("%d", chanNum) + String8(",") + String8::format("%d", majorNum) + String8(",");
+ cmd += String8("") + /*num.getMinor()*/String8("0") + String8(",0,0,0,-1,0,-1,");
+ cmd += String8("-1,'") + spids + String8("','") + stypes + String8("','") + scpgids + String8("','") + sapgids + String8("','") + slangs + String8("',");
+ cmd += String8("-1,'") + tpids + String8("','") + ttypes + String8("','") + tmagnums + String8("','") + tpgnums + String8("','") + tlangs + String8("',");
+ cmd += String8("-1,0,-1,-1,-1,-1,0)");
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+
+ CTvDatabase::Cursor cr;
+ selectProgramInChannelByNumber(channelID, num, cr);
+ if (cr.moveToFirst()) {
+ /*Construct*/
+ CreateFromCursor(cr);
+ } else {
+ /*A critical error*/
+ //Log.d(TAG, "Cannot add new program, sqlite error");
+ this->id = -1;
+ }
+ cr.close();
+ }
+ c.close();
+ }
+
+}
+
+
+/**
+ *向数据库添加一个Program,atscMode
+ */
+CTvProgram::CTvProgram(int channelID, int type, int major, int minor, int skipFlag)
+{
+ CTvChannel channel;
+ int ret = CTvChannel::selectByID(channelID, channel);
+ if (ret != 0) {
+ //Log.d(TAG, "Cannot add new program, invalid channel id "+channelID);
+ this->id = -1;
+ } else {
+ CTvDatabase::Cursor c ;
+ selectProgramInChannelByNumber(channelID, major, minor, c);
+
+ if (c.moveToFirst()) {
+ /*Construct*/
+ CreateFromCursor(c);
+ } else {
+ String8 tpids = String8(""), ttypes = String8(""), tmagnums = String8(""), tpgnums = String8(""), tlangs = String8("");
+ String8 spids = String8(""), stypes = String8(""), scpgids = String8(""), sapgids = String8(""), slangs = String8("");
+
+ /*add a new atv program to database*/
+ String8 cmd = String8("insert into srv_table(db_net_id,db_ts_id,service_id,src,name,service_type,");
+ cmd += String8("eit_schedule_flag,eit_pf_flag,running_status,free_ca_mode,volume,aud_track,vid_pid,");
+ cmd += String8("vid_fmt,aud_pids,aud_fmts,aud_langs,skip,lock,chan_num,major_chan_num,");
+ cmd += String8("minor_chan_num,access_controlled,hidden,hide_guide,source_id,favor,current_aud,");
+ cmd += String8("current_sub,sub_pids,sub_types,sub_composition_page_ids,sub_ancillary_page_ids,sub_langs,");
+ cmd += String8("current_ttx,ttx_pids,ttx_types,ttx_magazine_nos,ttx_page_nos,ttx_langs,");
+ cmd += String8("db_sat_para_id,scrambled_flag,lcn,hd_lcn,sd_lcn,default_chan_num,chan_order) ");
+ cmd += String8("values(-1,") + String8::format("%d", channelID) + String8(",65535,") + String8::format("%d", channel.getMode()) + String8(",'',") + String8::format("%d", type) + String8(",");
+ cmd += String8("0,0,0,0,0,0,8191,");
+ int chanNum = major << 16 | minor;
+ int majorNum = major;
+ cmd += String8("-1,'','','',") + String8::format("%d", skipFlag) + String8(",0,") + String8::format("%d", chanNum) + String8(",") + String8::format("%d", majorNum) + String8(",");
+ cmd += String8("") + String8::format("%d", minor) + String8(",0,0,0,-1,0,-1,");
+ cmd += String8("-1,'") + spids + String8("','") + stypes + String8("','") + scpgids + String8("','") + sapgids + String8("','") + slangs + String8("',");
+ cmd += String8("-1,'") + tpids + String8("','") + ttypes + String8("','") + tmagnums + String8("','") + tpgnums + String8("','") + tlangs + String8("',");
+ cmd += String8("-1,0,-1,-1,-1,-1,0)");
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+
+ CTvDatabase::Cursor cr;
+ selectProgramInChannelByNumber(channelID, major, minor, cr);
+ if (cr.moveToFirst()) {
+ /*Construct*/
+ CreateFromCursor(cr);
+ } else {
+ /*A critical error*/
+ //Log.d(TAG, "Cannot add new program, sqlite error");
+ this->id = -1;
+ }
+ cr.close();
+ }
+ c.close();
+ }
+
+}
+/**
+ *根据记录ID查找指定TVProgram
+*/
+
+int CTvProgram::selectByID(int id, CTvProgram &prog)
+{
+
+ CTvDatabase::Cursor c;
+ String8 sql;
+ sql = String8("select * from srv_table where srv_table.db_id = ") + String8::format("%d", id);
+ CTvDatabase::GetTvDb()->select(sql.string(), c) ;
+ if (c.moveToFirst()) {
+ prog.CreateFromCursor(c);
+ } else {
+ c.close();
+ return -1;
+ }
+ c.close();
+ return 0;
+}
+
+int CTvProgram::updateVolComp(int progID, int volValue)
+{
+ String8 cmd = String8("update srv_table set volume = ") + String8::format("%d", volValue) +
+ String8(" where srv_table.db_id = ") + String8::format("%d", progID);
+ LOGD("%s, cmd = %s\n", "TV", cmd.string());
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+
+ return 0;
+}
+
+int CTvProgram::getChannel(CTvChannel &c)
+{
+ return CTvChannel::selectByID(channelID, c);
+}
+
+int CTvProgram::upDateChannel(CTvChannel &c, int std, int Freq, int fineFreq)
+{
+ return CTvChannel::updateByID(channelID, std, Freq, fineFreq);
+}
+
+int CTvProgram::deleteChannelsProgram(CTvChannel &c)
+{
+ String8 cmd;
+ cmd = String8("delete from srv_table where srv_table.db_ts_id = ") + String8::format("%d", c.getID());
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+ return 0;
+}
+
+
+/**
+ *根据节目类型和节目号查找指定TVProgram
+*/
+int CTvProgram::selectByNumber(int type, int num, CTvProgram &prog)
+{
+ String8 cmd;
+
+ cmd = String8("select * from srv_table where ");
+ if (type != TYPE_UNKNOWN) {
+ if (type == TYPE_DTV) {
+ cmd += String8("(service_type = ") + String8::format("%d", TYPE_DTV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") and ");
+ } else {
+ cmd += String8("service_type = ") + String8::format("%d", type) + String8(" and ");
+ }
+ }
+
+ cmd += String8("chan_num = ") + String8::format("%d", num);
+
+ CTvDatabase::Cursor c;
+ CTvDatabase::GetTvDb()->select(cmd, c);
+
+ if (c.moveToFirst()) {
+ prog.CreateFromCursor(c);
+ } else {
+ c.close();
+ return -1;
+ }
+ c.close();
+
+ return 0;
+}
+
+/**
+ *根据节目类型和节目号查找指定TVProgram
+*/
+int CTvProgram::selectByNumber(int type, int major, int minor, CTvProgram &prog, int minor_check)
+{
+ String8 cmd;
+
+ cmd = String8("select * from srv_table where ");
+ if (type != TYPE_UNKNOWN) {
+ if (type == TYPE_DTV) {
+ cmd += String8("(service_type = ") + String8::format("%d", TYPE_TV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") and ");
+ } else {
+ cmd += String8("service_type = ") + String8::format("%d", type) + String8(" and ");
+ }
+ }
+
+ if (minor < 0) {
+ /*recursive call*/
+ /*select dtv program first*/
+ //showbo
+ int ret = selectByNumber(TYPE_DTV, major, 1, prog, MINOR_CHECK_NEAREST_UP);
+ if (ret != 0) {
+ /*then try atv program*/
+ selectByNumber(TYPE_ATV, major, 0 , prog, MINOR_CHECK_NONE);
+ }
+ return 0;
+ } else if (minor >= 1) {
+ if (minor_check == MINOR_CHECK_UP) {
+ cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num >= ") + String8::format("%d", minor) + String8(" ");
+ cmd += String8("order by minor_chan_num DESC limit 1");
+ } else if (minor_check == MINOR_CHECK_DOWN) {
+ cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num <= ") + String8::format("%d", minor) + String8(" ");
+ cmd += String8("order by minor_chan_num limit 1");
+ } else if (minor_check == MINOR_CHECK_NEAREST_UP) {
+ cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num >= ") + String8::format("%d", minor) + String8(" ");
+ cmd += String8("order by minor_chan_num limit 1");
+ } else if (minor_check == MINOR_CHECK_NEAREST_DOWN) {
+ cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num <= ") + String8::format("%d", minor) + String8(" ");
+ cmd += String8("order by minor_chan_num DESC limit 1");
+ } else {
+ cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
+ }
+ } else {
+ cmd += String8("major_chan_num = ") + String8::format("%d", major) + String8(" and minor_chan_num = ") + String8::format("%d", minor);
+ }
+
+
+ CTvDatabase::Cursor c;
+ CTvDatabase::GetTvDb()->select(cmd, c);
+
+ if (c.moveToFirst()) {
+ prog.CreateFromCursor(c);
+ } else {
+ c.close();
+ return -1;
+ }
+ c.close();
+
+ return 0;
+}
+
+
+/**
+ *列出一个channel的全部TVProgram
+ *@param channelID channel id
+ *@param type 节目类型
+ */
+int CTvProgram::selectByChannel(int channelID, int type, Vector<sp<CTvProgram> > &out)
+{
+
+ //Vector<CTvProgram*> vp;
+ String8 cmd = String8("select * from srv_table ");
+
+
+ if (type == TYPE_DTV) {
+ cmd += String8("where (service_type = ") + String8::format("%d", TYPE_TV) + String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) + String8(") ");
+ } else if (type != TYPE_UNKNOWN) {
+ cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
+ }
+
+ cmd += String8(" and db_ts_id = ") + String8::format("%d", channelID) + String8(" order by chan_order");
+
+ CTvDatabase::Cursor c;
+ int ret = CTvDatabase::GetTvDb()->select(cmd, c);
+
+ LOGD("selectByChannel select ret = %d", ret);
+
+ if (c.moveToFirst()) {
+ do {
+ out.add(new CTvProgram(c));
+ } while (c.moveToNext());
+ }
+ c.close();
+
+ return 0;
+}
+
+void CTvProgram::deleteProgram(int progId)
+{
+ String8 cmd;
+
+ cmd = String8("delete from srv_table where srv_table.db_id = ") + String8::format("%d", progId);
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+}
+
+int CTvProgram::CleanAllProgramBySrvType(int srvType)
+{
+ String8 cmd = String8("delete from srv_table where service_type = ") + String8::format("%d", srvType);
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+ return 0;
+}
+
+int CTvProgram::selectByType(int type, int skip, Vector<sp<CTvProgram> > &out)
+{
+ String8 cmd = String8("select * from srv_table ");
+ LOGD("%s, type= %d\n", "TV", (int)type);
+
+ if (type == TYPE_UNKNOWN) {
+ cmd += String8("where (service_type = ") + String8::format("%d", TYPE_ATV) +
+ String8(" or service_type = ") + String8::format("%d", TYPE_DTV) +
+ String8(" or service_type = ") + String8::format("%d", TYPE_RADIO) +
+ String8(") ");
+ } else {
+ cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
+ }
+
+ if (skip == PROGRAM_SKIP_NO || skip == PROGRAM_SKIP_YES)
+ cmd += String8(" and skip = ") + String8::format("%d", skip) + String8(" ");
+
+ if (type == TYPE_DTV || type == TYPE_RADIO) {
+ cmd += String8(" order by db_ts_id");
+ } else {
+ cmd += String8(" order by chan_order");
+ }
+
+ CTvDatabase::Cursor c;
+ int ret = CTvDatabase::GetTvDb()->select(cmd, c);
+
+ LOGD("selectByType select ret = %d", ret);
+
+ if (c.moveToFirst()) {
+ do {
+ out.add(new CTvProgram(c));
+ } while (c.moveToNext());
+ }
+ c.close();
+
+ return 0;
+}
+
+int CTvProgram::selectByChanID(int type, int skip, Vector < sp < CTvProgram > > &out)
+{
+ String8 cmd = String8("select * from srv_table ");
+
+ if (type == TYPE_UNKNOWN) {
+ cmd += String8("where (service_type = ") + String8::format("%d", TYPE_ATV) +
+ String8(" or service_type = ") + String8::format("%d", TYPE_DTV) +
+ String8(") ");
+ } else {
+ cmd += String8("where service_type = ") + String8::format("%d", type) + String8(" ");
+ }
+
+ if (skip == PROGRAM_SKIP_NO || skip == PROGRAM_SKIP_YES)
+ cmd += String8(" and skip = ") + String8::format("%d", PROGRAM_SKIP_NO) +
+ String8(" or skip = ") + String8::format("%d", PROGRAM_SKIP_YES) + String8(" ");
+
+ cmd += String8(" order by db_id");
+
+ CTvDatabase::Cursor c;
+ int ret = CTvDatabase::GetTvDb()->select(cmd, c);
+
+ if (c.moveToFirst()) {
+ do {
+ out.add(new CTvProgram(c));
+ } while (c.moveToNext());
+ }
+ c.close();
+
+ return 0;
+
+}
+
+int CTvProgram::selectAll(bool no_skip, Vector<sp<CTvProgram> > &out)
+{
+ return selectByType(TYPE_UNKNOWN, no_skip, out);
+}
+
+Vector<CTvProgram> CTvProgram::selectByChannel(int channelID)
+{
+ Vector<CTvProgram> vProg;
+ return vProg;
+}
+
+Vector<CTvProgram> CTvProgram::selectByName(int name)
+{
+ Vector<CTvProgram> vProg;
+ return vProg;
+}
+
+void CTvProgram::tvProgramDelByChannelID(int channelID)
+{
+
+}
+
+
+String8 CTvProgram::getName()
+{
+ return name;
+}
+int CTvProgram::getProgSkipFlag()
+{
+ return skip;
+}
+
+/**
+ *取得当前的audio索引
+ *@param defaultLang 用户未选择语言时,默认的全局语言
+ *@return 当前的Audio索引
+ */
+int CTvProgram::getCurrentAudio(String8 defaultLang)
+{
+ CTvDatabase::Cursor c;
+ String8 cmd;
+ cmd = String8("select current_aud from srv_table where db_id = ") + String8::format("%d", this->id);
+ int ret = CTvDatabase::GetTvDb()->select(cmd, c);
+ LOGD("getCurrentAudio a size = %d", mvAudios.size());
+ int id = 0;
+ if (c.moveToFirst()) {
+ id = c.getInt(0);
+ LOGD("getCurrentAudio a id = %d", id);
+ if (id < 0 && mvAudios.size() > 0) {
+ LOGD("getCurrentAudio defaultLang.isEmpty() =%s= %d", defaultLang.string(), defaultLang.isEmpty());
+ if (!defaultLang.isEmpty()) {
+ for (int i = 0; i < mvAudios.size(); i++) {
+ LOGD("getCurrentAudio a mvAudios[i] = %d", mvAudios[i]);
+ if (mvAudios[i]->getLang() == defaultLang) {
+ id = i;
+ break;
+ }
+ }
+ }
+
+ if (id < 0) {
+ /* still not found, using the first */
+ id = 0;
+ }
+ }
+ }
+ LOGD("getCurrentAudio a idsss = %d", id);
+ c.close();
+
+ return id;
+}
+
+int CTvProgram::getAudioChannel()
+{
+ return audioTrack;
+}
+
+int CTvProgram::updateAudioChannel(int progId, int ch)
+{
+ String8 cmd;
+
+ cmd = String8("update srv_table set aud_track =") + "\'" + String8::format("%d", ch) + "\'"
+ + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
+
+ return CTvDatabase::GetTvDb()->exeSql(cmd.string());
+}
+
+int CTvProgram::getSubtitleIndex(int progId)
+{
+ CTvDatabase::Cursor c;
+ String8 cmd = String8("select current_sub from srv_table where db_id = ") + String8::format("%d", progId);
+ int ret = CTvDatabase::GetTvDb()->select(cmd, c);
+ if (c.moveToFirst()) {
+ return c.getInt(0);
+ } else {
+ return -1;
+ }
+}
+
+int CTvProgram::setSubtitleIndex(int progId, int index)
+{
+ String8 cmd = String8("update srv_table set current_sub = ") + String8::format("%d", index) + String8(" where db_id = ") + String8::format("%d", progId);
+ return CTvDatabase::GetTvDb()->exeSql(cmd.string());
+}
+
+int CTvProgram::getCurrAudioTrackIndex()
+{
+ int audTrackIdx = -1;
+
+ if (-1 == currAudTrackIndex) { // no set field "current_aud"
+ audTrackIdx = getCurrentAudio(String8("eng"));
+ setCurrAudioTrackIndex(this->id, audTrackIdx);
+ } else {
+ audTrackIdx = currAudTrackIndex;
+ }
+
+ return audTrackIdx;
+}
+
+
+void CTvProgram::setCurrAudioTrackIndex(int programId, int audioIndex)
+{
+ String8 cmd;
+
+ cmd = String8("update srv_table set current_aud = ")
+ + String8::format("%d", audioIndex) + String8(" where srv_table.db_id = ") + String8::format("%d", programId);
+
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+}
+
+void CTvProgram::setFavoriteFlag(int progId, bool bFavor)
+{
+ String8 cmd;
+
+ cmd = String8("update srv_table set favor = ")
+ + String8::format("%d", bFavor ? 1 : 0) + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
+
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+
+}
+
+void CTvProgram::setSkipFlag(int progId, bool bSkipFlag)
+{
+ String8 cmd;
+
+ cmd = String8("update srv_table set skip = ") + String8::format("%d", bSkipFlag ? 1 : 0)
+ + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
+
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+}
+
+void CTvProgram::updateProgramName(int progId, String8 strName)
+{
+ String8 newName = String8("xxx") + strName;
+ String8 cmd;
+
+ cmd = String8("update srv_table set name =") + "\'" + String8::format("%s", newName.string()) + "\'"
+ + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
+
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+}
+
+void CTvProgram::swapChanOrder(int ProgId1, int chanOrderNum1, int ProgId2, int chanOrderNum2)
+{
+ String8 cmd;
+
+ cmd = String8("update srv_table set chan_order = ") + String8::format("%d", chanOrderNum2)
+ + String8(" where db_id = ") + String8::format("%d", ProgId1);
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+
+ String8 cmd2;
+ cmd2 = String8("update srv_table set chan_order = ") + String8::format("%d", chanOrderNum1)
+ + String8(" where db_id = ") + String8::format("%d", ProgId2);
+ CTvDatabase::GetTvDb()->exeSql(cmd2.string());
+}
+
+
+void CTvProgram::setLockFlag(int progId, bool bLockFlag)
+{
+ String8 cmd;
+
+ cmd = String8("update srv_table set lock = ") + String8::format("%d", bLockFlag ? 1 : 0)
+ + String8(" where srv_table.db_id = ") + String8::format("%d", progId);
+
+ CTvDatabase::GetTvDb()->exeSql(cmd.string());
+}
+bool CTvProgram::getLockFlag()
+{
+ return lock;
+}
+