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