summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tv/CTvEpg.cpp (plain)
blob: d1ead7fc20ec1dd45201f3baf60a5ec98a3409ac
1/*
2 * amlogic 2013
3 *@ Project : tv
4 *@ Date : 2013-12
5 *@ Author :
6*/
7#define LOG_TAG "CTvEpg"
8
9#include "CTvEpg.h"
10#include "CTvChannel.h"
11
12void CTvEpg::epg_evt_callback(long dev_no, int event_type, void *param, void *user_data __unused)
13{
14 CTvEpg *pEpg;
15
16 AM_EPG_GetUserData((AM_EPG_Handle_t)dev_no, (void **)&pEpg);
17
18 if (pEpg == NULL) return;
19
20 if (pEpg->mpObserver == NULL) {
21 return;
22 }
23 switch (event_type) {
24 case AM_EPG_EVT_NEW_TDT:
25 case AM_EPG_EVT_NEW_STT: {
26 int utc_time;
27 AM_EPG_GetUTCTime(&utc_time);
28 pEpg->mCurEpgEv.type = EpgEvent::EVENT_TDT_END;
29 pEpg->mCurEpgEv.time = (long)utc_time;
30 pEpg->mpObserver->onEvent(pEpg->mCurEpgEv);
31 }
32 break;
33 case AM_EPG_EVT_UPDATE_EVENTS:
34 pEpg->mCurEpgEv.type = EpgEvent::EVENT_PROGRAM_EVENTS_UPDATE;
35 pEpg->mCurEpgEv.programID = (int)param;
36 pEpg->mpObserver->onEvent(pEpg->mCurEpgEv);
37 break;
38 case AM_EPG_EVT_UPDATE_PROGRAM_AV:
39 pEpg->mCurEpgEv.type = EpgEvent::EVENT_PROGRAM_AV_UPDATE;
40 pEpg->mCurEpgEv.programID = (int)param;
41 pEpg->mpObserver->onEvent(pEpg->mCurEpgEv);
42 break;
43 case AM_EPG_EVT_UPDATE_PROGRAM_NAME:
44 pEpg->mCurEpgEv.type = EpgEvent::EVENT_PROGRAM_NAME_UPDATE;
45 pEpg->mCurEpgEv.programID = (int)param;
46 pEpg->mpObserver->onEvent(pEpg->mCurEpgEv);
47 break;
48 case AM_EPG_EVT_UPDATE_TS:
49 pEpg->mCurEpgEv.type = EpgEvent::EVENT_CHANNEL_UPDATE;
50 pEpg->mCurEpgEv.channelID = (int)param;
51 pEpg->mpObserver->onEvent(pEpg->mCurEpgEv);
52 break;
53 default:
54 break;
55 }
56}
57
58void CTvEpg::Init(int fend, int dmx, int fend_mod, char *textLanguages, char *dvb_text_coding)
59{
60 mFend_dev_id = fend;
61 mDmx_dev_id = dmx;
62 mFend_mod = fend_mod;
63 epg_create(fend, dmx, fend_mod, textLanguages);
64 epg_set_dvb_text_coding(dvb_text_coding);
65}
66
67void CTvEpg::epg_create(int fend_id, int dmx_id, int src, char *textLangs)
68{
69 AM_EPG_CreatePara_t para;
70 AM_ErrorCode_t ret;
71 AM_FEND_OpenPara_t fend_para;
72 AM_DMX_OpenPara_t dmx_para;
73
74 LOGD("Opening demux%d ...", dmx_id);
75 memset(&dmx_para, 0, sizeof(dmx_para));
76 AM_DMX_Open(dmx_id, &dmx_para);
77
78 para.fend_dev = fend_id;
79 para.dmx_dev = dmx_id;
80 para.source = src;
81 para.hdb = NULL;
82
83
84 snprintf(para.text_langs, sizeof(para.text_langs), "%s", textLangs);
85
86
87 ret = AM_EPG_Create(&para, &mEpgScanHandle);
88 if (ret != AM_SUCCESS) {
89 LOGD("AM_EPG_Create failed");
90 return;
91 }
92
93 /*注册EIT通知事件*/
94 AM_EVT_Subscribe((long)mEpgScanHandle, AM_EPG_EVT_NEW_TDT, epg_evt_callback, NULL);
95 AM_EVT_Subscribe((long)mEpgScanHandle, AM_EPG_EVT_NEW_STT, epg_evt_callback, NULL);
96 AM_EVT_Subscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_EVENTS, epg_evt_callback, NULL);
97 AM_EVT_Subscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_PROGRAM_AV, epg_evt_callback, NULL);
98 AM_EVT_Subscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_PROGRAM_NAME, epg_evt_callback, NULL);
99 AM_EVT_Subscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_TS, epg_evt_callback, NULL);
100 AM_EPG_SetUserData(mEpgScanHandle, (void *)this);
101}
102
103
104
105void CTvEpg::epg_destroy()
106{
107 /*反注册EIT通知事件*/
108 AM_EVT_Unsubscribe((long)mEpgScanHandle, AM_EPG_EVT_NEW_TDT, epg_evt_callback, NULL);
109 AM_EVT_Unsubscribe((long)mEpgScanHandle, AM_EPG_EVT_NEW_STT, epg_evt_callback, NULL);
110 AM_EVT_Unsubscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_EVENTS, epg_evt_callback, NULL);
111 AM_EVT_Unsubscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_PROGRAM_AV, epg_evt_callback, NULL);
112 AM_EVT_Unsubscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_PROGRAM_NAME, epg_evt_callback, NULL);
113 AM_EVT_Unsubscribe((long)mEpgScanHandle, AM_EPG_EVT_UPDATE_TS, epg_evt_callback, NULL);
114 AM_EPG_Destroy(mEpgScanHandle);
115 AM_DMX_Close(mDmx_dev_id);
116}
117
118
119void CTvEpg::epg_change_mode(int op, int mode)
120{
121 AM_ErrorCode_t ret;
122 ret = AM_EPG_ChangeMode(mEpgScanHandle, op, mode);
123 if (ret != AM_SUCCESS)
124 LOGD("AM_EPG_ChangeMode failed");
125}
126
127
128
129void CTvEpg::epg_monitor_service(int srv_id)
130{
131 int ret = AM_EPG_MonitorService(mEpgScanHandle, srv_id);
132 if (ret != AM_SUCCESS)
133 LOGD("AM_EPG_MonitorService failed");
134}
135
136
137
138void CTvEpg::epg_set_dvb_text_coding(char *coding)
139{
140 if (!strcmp(coding, "standard")) {
141 AM_SI_SetDefaultDVBTextCoding("");
142 } else {
143 AM_SI_SetDefaultDVBTextCoding(coding);
144 }
145}
146
147
148
149/*Start scan the sections.*/
150void CTvEpg::startScan(int mode)
151{
152 epg_change_mode(MODE_ADD, mode);
153}
154
155/*Stop scan the sections.*/
156void CTvEpg::stopScan(int mode)
157{
158 epg_change_mode(MODE_REMOVE, mode);
159}
160
161
162/*Enter a channel.*/
163void CTvEpg::enterChannel(int chan_id)
164{
165
166 if (chan_id == mCurScanChannelId)
167 return;
168 //already enter,leave it
169 if (mCurScanChannelId != INVALID_ID) {
170 leaveChannel();
171 }
172
173 if (mFend_mod == CTvChannel::MODE_ATSC) {
174 startScan(SCAN_PSIP_ETT | SCAN_PSIP_EIT | SCAN_MGT | SCAN_VCT | SCAN_RRT | SCAN_STT);
175 } else {
176 startScan(SCAN_EIT_ALL | SCAN_SDT | SCAN_NIT | SCAN_TDT | SCAN_CAT);
177 }
178
179 mCurScanChannelId = chan_id;
180}
181
182/*Leave the channel.*/
183void CTvEpg::leaveChannel()
184{
185
186 stopScan(SCAN_ALL);
187 mCurScanChannelId = INVALID_ID;
188}
189
190/*Enter the program.*/
191void CTvEpg::enterProgram(int prog_id)
192{
193 if (prog_id == mCurScanProgramId)
194 return;
195
196 if (mCurScanProgramId != INVALID_ID) {
197 leaveProgram();
198 }
199
200 mCurScanProgramId = prog_id;
201 epg_monitor_service(mCurScanProgramId);//---------db_id
202 startScan(SCAN_PAT | SCAN_PMT);
203}
204
205/*Leave the program.*/
206void CTvEpg::leaveProgram()
207{
208 if (mCurScanProgramId == INVALID_ID)
209 return;
210
211 stopScan(SCAN_PAT | SCAN_PMT);
212 epg_monitor_service(-1);
213 mCurScanProgramId = INVALID_ID;
214}
215