1 | /* Reversed from libcoolstream.so, this comes without any warranty */
|
---|
2 |
|
---|
3 | #include "globals.h"
|
---|
4 |
|
---|
5 | #if defined(HAVE_DVBAPI) && defined(WITH_COOLAPI)
|
---|
6 |
|
---|
7 | #include "extapi/coolapi.h"
|
---|
8 |
|
---|
9 | #include "module-dvbapi.h"
|
---|
10 | #include "module-dvbapi-coolapi.h"
|
---|
11 | #include "oscam-string.h"
|
---|
12 |
|
---|
13 | static int8_t dmx_opened;
|
---|
14 | int8_t cool_kal_opened = 0;
|
---|
15 |
|
---|
16 | static void *dmx_device[MAX_COOL_DMX];
|
---|
17 | static dmx_t cdemuxes[MAX_COOL_DMX][MAX_FILTER];
|
---|
18 |
|
---|
19 | extern void *dvbapi_client;
|
---|
20 |
|
---|
21 | LLIST *ll_cool_filter = NULL;
|
---|
22 | LLIST *ll_cool_chanhandle = NULL;
|
---|
23 |
|
---|
24 | #define COOLDEMUX_FD(device, num) (('O' << 24) | ('S' << 16) | (device << 8) | num)
|
---|
25 | #define COOLDEMUX_DMX_DEV(fd) (((fd) >> 8) & 0xFF)
|
---|
26 |
|
---|
27 | static dmx_t *find_demux(int32_t fd, int32_t dmx_dev_num)
|
---|
28 | {
|
---|
29 | if(dmx_dev_num < 0 || dmx_dev_num >= MAX_COOL_DMX)
|
---|
30 | {
|
---|
31 | cs_log("Invalid demux %d", dmx_dev_num);
|
---|
32 | return NULL;
|
---|
33 | }
|
---|
34 |
|
---|
35 | int32_t i, idx;
|
---|
36 |
|
---|
37 | idx = dmx_dev_num;
|
---|
38 | if(fd == 0)
|
---|
39 | {
|
---|
40 | for(i = 0; i < MAX_FILTER; i++)
|
---|
41 | {
|
---|
42 | if(!cdemuxes[idx][i].opened)
|
---|
43 | {
|
---|
44 | cdemuxes[idx][i].fd = COOLDEMUX_FD(dmx_dev_num, i);
|
---|
45 | cs_debug_mask(D_DVBAPI, "opening new fd: %08x", cdemuxes[idx][i].fd);
|
---|
46 | cdemuxes[idx][i].demux_index = dmx_dev_num;
|
---|
47 | return &cdemuxes[idx][i];
|
---|
48 | }
|
---|
49 | }
|
---|
50 | cs_debug_mask(D_DVBAPI, "ERROR: no free demux found");
|
---|
51 | return NULL;
|
---|
52 | }
|
---|
53 |
|
---|
54 | idx = COOLDEMUX_DMX_DEV(fd);
|
---|
55 | for(i = 0; i < MAX_FILTER; i++)
|
---|
56 | {
|
---|
57 | if(cdemuxes[idx][i].fd == fd)
|
---|
58 | { return &cdemuxes[idx][i]; }
|
---|
59 | }
|
---|
60 |
|
---|
61 | cs_debug_mask(D_DVBAPI, "ERROR: CANT FIND Demux %08x", fd);
|
---|
62 |
|
---|
63 | return NULL;
|
---|
64 | }
|
---|
65 |
|
---|
66 | void coolapi_read_data(dmx_t *dmx, dmx_callback_data_t *data)
|
---|
67 | {
|
---|
68 | if(!dmx)
|
---|
69 | {
|
---|
70 | cs_debug_mask(D_DVBAPI, "handle is NULL!");
|
---|
71 | return;
|
---|
72 | }
|
---|
73 |
|
---|
74 | int32_t ret;
|
---|
75 |
|
---|
76 | pthread_setspecific(getclient, dvbapi_client);
|
---|
77 | pthread_mutex_lock(&dmx->mutex);
|
---|
78 | memset(dmx->buffer, 0, 4096);
|
---|
79 | ret = coolapi_read(dmx, data);
|
---|
80 | pthread_mutex_unlock(&dmx->mutex);
|
---|
81 | if(ret > -1)
|
---|
82 | { dvbapi_process_input(dmx->demux_id, dmx->filter_num, dmx->buffer, data->len); }
|
---|
83 | }
|
---|
84 |
|
---|
85 | static void dmx_callback(void *UNUSED(unk), dmx_t *dmx, int32_t type, dmx_callback_data_t *data)
|
---|
86 | {
|
---|
87 | if(!dmx)
|
---|
88 | {
|
---|
89 | cs_debug_mask(D_DVBAPI, "wrong dmx pointer !!!");
|
---|
90 | return;
|
---|
91 | }
|
---|
92 |
|
---|
93 | if(data != NULL)
|
---|
94 | {
|
---|
95 | switch(type)
|
---|
96 | {
|
---|
97 | case 0xE:
|
---|
98 | if(data->type == 1 && data->len > 0)
|
---|
99 | {
|
---|
100 | coolapi_read_data(dmx, data);
|
---|
101 | }
|
---|
102 | else
|
---|
103 | { cs_debug_mask(D_DVBAPI, "unknown callback data %d len %d", data->type, data->len); }
|
---|
104 | break;
|
---|
105 | default:
|
---|
106 | break;
|
---|
107 |
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | int32_t coolapi_set_filter(int32_t fd, int32_t num, int32_t pid, uchar *flt, uchar *mask, int32_t type)
|
---|
113 | {
|
---|
114 | dmx_t *dmx = find_demux(fd, 0);
|
---|
115 | if(!dmx)
|
---|
116 | {
|
---|
117 | cs_debug_mask(D_DVBAPI, "dmx is NULL!");
|
---|
118 | return -1;
|
---|
119 | }
|
---|
120 |
|
---|
121 | int32_t result, channel_found = 0;
|
---|
122 |
|
---|
123 | void *channel = NULL;
|
---|
124 |
|
---|
125 | if(ll_count(ll_cool_chanhandle) > 0)
|
---|
126 | {
|
---|
127 | LL_ITER itr = ll_iter_create(ll_cool_chanhandle);
|
---|
128 | S_COOL_CHANHANDLE *handle_item;
|
---|
129 | while((handle_item = ll_iter_next(&itr)))
|
---|
130 | {
|
---|
131 | if(handle_item->demux_index == dmx->demux_index && handle_item->pid == pid)
|
---|
132 | {
|
---|
133 | channel = handle_item->channel;
|
---|
134 | channel_found = 1;
|
---|
135 | break;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | if(!channel)
|
---|
141 | {
|
---|
142 | buffer_open_arg_t bufarg;
|
---|
143 | int32_t uBufferSize = 8256;
|
---|
144 | memset(&bufarg, 0, sizeof(bufarg));
|
---|
145 |
|
---|
146 | bufarg.type = 3;
|
---|
147 | bufarg.size = uBufferSize;
|
---|
148 | bufarg.unknown3 = (uBufferSize * 7) / 8;
|
---|
149 |
|
---|
150 | result = cnxt_cbuf_open(&dmx->buffer1, &bufarg, NULL, NULL);
|
---|
151 | coolapi_check_error("cnxt_cbuf_open", result);
|
---|
152 |
|
---|
153 | bufarg.type = 0;
|
---|
154 |
|
---|
155 | result = cnxt_cbuf_open(&dmx->buffer2, &bufarg, NULL, NULL);
|
---|
156 | coolapi_check_error("cnxt_cbuf_open", result);
|
---|
157 |
|
---|
158 | channel_open_arg_t chanarg;
|
---|
159 | memset(&chanarg, 0, sizeof(channel_open_arg_t));
|
---|
160 | chanarg.type = 4;
|
---|
161 |
|
---|
162 | result = cnxt_dmx_channel_open(dmx->device, &dmx->channel, &chanarg, dmx_callback, dmx);
|
---|
163 | coolapi_check_error("cnxt_dmx_channel_open", result);
|
---|
164 |
|
---|
165 | result = cnxt_dmx_set_channel_buffer(dmx->channel, 0, dmx->buffer1);
|
---|
166 | coolapi_check_error("cnxt_dmx_set_channel_buffer", result);
|
---|
167 |
|
---|
168 | result = cnxt_dmx_channel_attach(dmx->channel, 0xB, 0, dmx->buffer2);
|
---|
169 | coolapi_check_error("cnxt_dmx_channel_attach", result);
|
---|
170 |
|
---|
171 | result = cnxt_cbuf_attach(dmx->buffer2, 2, dmx->channel);
|
---|
172 | coolapi_check_error("cnxt_cbuf_attach", result);
|
---|
173 |
|
---|
174 | result = cnxt_dmx_set_channel_pid(dmx->channel, pid);
|
---|
175 | coolapi_check_error("cnxt_dmx_set_channel_pid", result);
|
---|
176 |
|
---|
177 | result = cnxt_cbuf_flush(dmx->buffer1, 0);
|
---|
178 | coolapi_check_error("cnxt_cbuf_flush", result);
|
---|
179 | result = cnxt_cbuf_flush(dmx->buffer2, 0);
|
---|
180 | coolapi_check_error("cnxt_cbuf_flush", result);
|
---|
181 |
|
---|
182 | S_COOL_CHANHANDLE *handle_item;
|
---|
183 | if(cs_malloc(&handle_item, sizeof(S_COOL_CHANHANDLE)))
|
---|
184 | {
|
---|
185 | handle_item->pid = pid;
|
---|
186 | handle_item->channel = dmx->channel;
|
---|
187 | handle_item->buffer1 = dmx->buffer1;
|
---|
188 | handle_item->buffer2 = dmx->buffer2;
|
---|
189 | handle_item->demux_index = dmx->demux_index;
|
---|
190 | ll_append(ll_cool_chanhandle, handle_item);
|
---|
191 | }
|
---|
192 | cs_debug_mask(D_DVBAPI, "opened new channel %x", (int32_t) dmx->channel);
|
---|
193 | }
|
---|
194 | else
|
---|
195 | {
|
---|
196 | channel_found = 1;
|
---|
197 | dmx->channel = channel;
|
---|
198 | dmx->buffer1 = NULL;
|
---|
199 | dmx->buffer2 = NULL;
|
---|
200 | }
|
---|
201 |
|
---|
202 | cs_debug_mask(D_DVBAPI, "setting new filter fd=%08x demux=%d channel=%x num=%d pid=%04x flt=%x mask=%x", fd, dmx->demux_index, (int32_t) dmx->channel, num, pid, flt[0], mask[0]);
|
---|
203 |
|
---|
204 | pthread_mutex_lock(&dmx->mutex);
|
---|
205 |
|
---|
206 | filter_set_t filter;
|
---|
207 | dmx->filter_num = num;
|
---|
208 | dmx->pid = pid;
|
---|
209 | dmx->type = type;
|
---|
210 |
|
---|
211 | memset(&filter, 0, sizeof(filter));
|
---|
212 | filter.length = 12;
|
---|
213 | memcpy(filter.filter, flt, 16);
|
---|
214 | memcpy(filter.mask, mask, 16);
|
---|
215 |
|
---|
216 | result = cnxt_dmx_open_filter(dmx->device, &dmx->filter);
|
---|
217 | coolapi_check_error("cnxt_dmx_open_filter", result);
|
---|
218 |
|
---|
219 | result = cnxt_dmx_set_filter(dmx->filter, &filter, NULL);
|
---|
220 | coolapi_check_error("cnxt_dmx_set_filter", result);
|
---|
221 |
|
---|
222 | result = cnxt_dmx_channel_suspend(dmx->channel, 1);
|
---|
223 | coolapi_check_error("cnxt_dmx_channel_suspend", result);
|
---|
224 | result = cnxt_dmx_channel_attach_filter(dmx->channel, dmx->filter);
|
---|
225 | coolapi_check_error("cnxt_dmx_channel_attach_filter", result);
|
---|
226 | result = cnxt_dmx_channel_suspend(dmx->channel, 0);
|
---|
227 | coolapi_check_error("cnxt_dmx_channel_suspend", result);
|
---|
228 |
|
---|
229 | if(channel_found)
|
---|
230 | {
|
---|
231 | result = cnxt_dmx_channel_ctrl(dmx->channel, 0, 0);
|
---|
232 | coolapi_check_error("cnxt_dmx_channel_ctrl", result);
|
---|
233 | }
|
---|
234 |
|
---|
235 | result = cnxt_dmx_channel_ctrl(dmx->channel, 2, 0);
|
---|
236 | coolapi_check_error("cnxt_dmx_channel_ctrl", result);
|
---|
237 |
|
---|
238 | pthread_mutex_unlock(&dmx->mutex);
|
---|
239 |
|
---|
240 | S_COOL_FILTER *filter_item;
|
---|
241 | if(cs_malloc(&filter_item, sizeof(S_COOL_FILTER)))
|
---|
242 | {
|
---|
243 | // fill filter item
|
---|
244 | filter_item->fd = fd;
|
---|
245 | filter_item->pid = pid;
|
---|
246 | filter_item->channel = (int32_t) dmx->channel;
|
---|
247 | memcpy(filter_item->filter16, flt, 16);
|
---|
248 | memcpy(filter_item->mask16, mask, 16);
|
---|
249 |
|
---|
250 | //add filter item
|
---|
251 | ll_append(ll_cool_filter, filter_item);
|
---|
252 | }
|
---|
253 | return 0;
|
---|
254 | }
|
---|
255 |
|
---|
256 | int32_t coolapi_remove_filter(int32_t fd, int32_t num)
|
---|
257 | {
|
---|
258 | dmx_t *dmx = find_demux(fd, 0);
|
---|
259 | if(!dmx)
|
---|
260 | {
|
---|
261 | cs_debug_mask(D_DVBAPI, "dmx is NULL!");
|
---|
262 | return -1;
|
---|
263 | }
|
---|
264 |
|
---|
265 | if(dmx->pid <= 0)
|
---|
266 | { return -1; }
|
---|
267 |
|
---|
268 | int32_t result, filter_on_channel = 0;
|
---|
269 |
|
---|
270 | cs_debug_mask(D_DVBAPI, "removing filter fd=%08x num=%d pid=%04x on channel=%x", fd, num, dmx->pid, (int32_t) dmx->channel);
|
---|
271 |
|
---|
272 | pthread_mutex_lock(&dmx->mutex);
|
---|
273 |
|
---|
274 | if(dmx->filter)
|
---|
275 | {
|
---|
276 | result = cnxt_dmx_channel_suspend(dmx->channel, 1);
|
---|
277 | coolapi_check_error("cnxt_dmx_channel_suspend", result);
|
---|
278 | result = cnxt_dmx_channel_detach_filter(dmx->channel, dmx->filter);
|
---|
279 | coolapi_check_error("cnxt_dmx_channel_detach_filter", result);
|
---|
280 | result = cnxt_dmx_channel_suspend(dmx->channel, 0);
|
---|
281 | coolapi_check_error("cnxt_dmx_channel_suspend", result);
|
---|
282 | result = cnxt_dmx_close_filter(dmx->filter);
|
---|
283 | coolapi_check_error("cnxt_dmx_close_filter", result);
|
---|
284 | dmx->filter = NULL;
|
---|
285 | result = cnxt_dmx_channel_ctrl(dmx->channel, 0, 0);
|
---|
286 | coolapi_check_error("cnxt_dmx_channel_ctrl", result);
|
---|
287 | }
|
---|
288 |
|
---|
289 | LL_ITER itr = ll_iter_create(ll_cool_filter);
|
---|
290 | S_COOL_FILTER *filter_item;
|
---|
291 | while((filter_item = ll_iter_next(&itr)))
|
---|
292 | {
|
---|
293 | if(filter_item->channel == (int32_t) dmx->channel)
|
---|
294 | { filter_on_channel++; }
|
---|
295 | if(filter_item->fd == fd)
|
---|
296 | {
|
---|
297 | ll_iter_remove_data(&itr);
|
---|
298 | filter_on_channel--;
|
---|
299 | }
|
---|
300 | }
|
---|
301 |
|
---|
302 | if(!filter_on_channel)
|
---|
303 | {
|
---|
304 | cs_debug_mask(D_DVBAPI, "closing channel %x", (int32_t) dmx->channel);
|
---|
305 |
|
---|
306 | itr = ll_iter_create(ll_cool_chanhandle);
|
---|
307 | S_COOL_CHANHANDLE *handle_item;
|
---|
308 | while((handle_item = ll_iter_next(&itr)))
|
---|
309 | {
|
---|
310 | if(handle_item->demux_index == dmx->demux_index && handle_item->pid == dmx->pid)
|
---|
311 | {
|
---|
312 | dmx->buffer1 = handle_item->buffer1;
|
---|
313 | dmx->buffer2 = handle_item->buffer2;
|
---|
314 | ll_iter_remove_data(&itr);
|
---|
315 | break;
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 | if(!dmx->buffer1 || !dmx->buffer2)
|
---|
320 | { cs_debug_mask(D_DVBAPI, "WARNING: buffer handle not found!"); }
|
---|
321 |
|
---|
322 | result = cnxt_dmx_channel_ctrl(dmx->channel, 0, 0);
|
---|
323 | coolapi_check_error("cnxt_dmx_channel_ctrl", result);
|
---|
324 |
|
---|
325 | result = cnxt_dmx_set_channel_pid(dmx->channel, 0x1FFF);
|
---|
326 | coolapi_check_error("cnxt_dmx_set_channel_pid", result);
|
---|
327 |
|
---|
328 | result = cnxt_cbuf_flush(dmx->buffer1, 0);
|
---|
329 | coolapi_check_error("cnxt_cbuf_flush", result);
|
---|
330 |
|
---|
331 | result = cnxt_cbuf_flush(dmx->buffer2, 0);
|
---|
332 | coolapi_check_error("cnxt_cbuf_flush", result);
|
---|
333 |
|
---|
334 | result = cnxt_cbuf_detach(dmx->buffer2, 2, dmx->channel);
|
---|
335 | coolapi_check_error("cnxt_cbuf_detach", result);
|
---|
336 | result = cnxt_dmx_channel_detach(dmx->channel, 0xB, 0, dmx->buffer1);
|
---|
337 | coolapi_check_error("cnxt_dmx_channel_detach", result);
|
---|
338 |
|
---|
339 | result = cnxt_dmx_channel_close(dmx->channel);
|
---|
340 | coolapi_check_error("cnxt_dmx_channel_close", result);
|
---|
341 |
|
---|
342 | result = cnxt_cbuf_close(dmx->buffer2);
|
---|
343 | coolapi_check_error("cnxt_cbuf_close", result);
|
---|
344 |
|
---|
345 | result = cnxt_cbuf_close(dmx->buffer1);
|
---|
346 | coolapi_check_error("cnxt_cbuf_close", result);
|
---|
347 | }
|
---|
348 |
|
---|
349 | if(filter_on_channel)
|
---|
350 | {
|
---|
351 | result = cnxt_dmx_channel_ctrl(dmx->channel, 2, 0);
|
---|
352 | coolapi_check_error("cnxt_dmx_channel_ctrl", result);
|
---|
353 | }
|
---|
354 |
|
---|
355 | pthread_mutex_unlock(&dmx->mutex);
|
---|
356 |
|
---|
357 | dmx->pid = -1;
|
---|
358 | return 0;
|
---|
359 | }
|
---|
360 |
|
---|
361 | int32_t coolapi_open_device(int32_t demux_index, int32_t demux_id)
|
---|
362 | {
|
---|
363 | dmx_t *dmx;
|
---|
364 |
|
---|
365 | coolapi_open();
|
---|
366 |
|
---|
367 | dmx = find_demux(0, demux_index);
|
---|
368 | if(!dmx)
|
---|
369 | {
|
---|
370 | cs_log("no free demux found");
|
---|
371 | return 0;
|
---|
372 | }
|
---|
373 |
|
---|
374 | if(!ll_cool_filter)
|
---|
375 | { ll_cool_filter = ll_create("ll_cool_filter"); }
|
---|
376 |
|
---|
377 | if(!ll_cool_chanhandle)
|
---|
378 | { ll_cool_chanhandle = ll_create("ll_cool_chanhandle"); }
|
---|
379 |
|
---|
380 | dmx->demux_index = demux_index;
|
---|
381 | dmx->demux_id = demux_id;
|
---|
382 | dmx->pid = -1;
|
---|
383 |
|
---|
384 | dmx->device = dmx_device[demux_index];
|
---|
385 | dmx->opened = 1;
|
---|
386 |
|
---|
387 | pthread_mutexattr_t attr;
|
---|
388 | pthread_mutexattr_init(&attr);
|
---|
389 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP);
|
---|
390 | pthread_mutex_init(&dmx->mutex, &attr);
|
---|
391 |
|
---|
392 | return dmx->fd;
|
---|
393 | }
|
---|
394 |
|
---|
395 | int32_t coolapi_close_device(int32_t fd)
|
---|
396 | {
|
---|
397 | dmx_t *dmx = find_demux(fd, 0);
|
---|
398 | if(!dmx)
|
---|
399 | {
|
---|
400 | cs_debug_mask(D_DVBAPI, "dmx is NULL!");
|
---|
401 | return -1;
|
---|
402 | }
|
---|
403 |
|
---|
404 | cs_debug_mask(D_DVBAPI, "closing fd=%08x", fd);
|
---|
405 | dmx->opened = 0;
|
---|
406 | pthread_mutex_destroy(&dmx->mutex);
|
---|
407 |
|
---|
408 | memset(dmx, 0, sizeof(dmx_t));
|
---|
409 | return 0;
|
---|
410 | }
|
---|
411 |
|
---|
412 | /* write cw to all demuxes in mask with passed index */
|
---|
413 | int32_t coolapi_write_cw(int32_t mask, uint16_t *STREAMpids, int32_t count, ca_descr_t *ca_descr)
|
---|
414 | {
|
---|
415 | int32_t i, idx = ca_descr->index;
|
---|
416 | int32_t result;
|
---|
417 | void *channel;
|
---|
418 |
|
---|
419 | cs_debug_mask(D_DVBAPI, "cw%d: mask %d index %d pid count %d", ca_descr->parity, mask, idx, count);
|
---|
420 | for(i = 0; i < count; i++)
|
---|
421 | {
|
---|
422 | int32_t pid = STREAMpids[i];
|
---|
423 | int32_t j;
|
---|
424 | for(j = 0; j < MAX_COOL_DMX; j++)
|
---|
425 | {
|
---|
426 | if(mask & (1 << j))
|
---|
427 | {
|
---|
428 | result = cnxt_dmx_get_channel_from_pid(dmx_device[j], pid, &channel);
|
---|
429 | if(result == 0)
|
---|
430 | {
|
---|
431 | cs_debug_mask(D_DVBAPI, "Found demux %d channel %x for pid %04x", j, (int32_t) channel, pid);
|
---|
432 | result = cnxt_dmx_set_channel_key(channel, 0, ca_descr->parity, ca_descr->cw, 8);
|
---|
433 | coolapi_check_error("cnxt_dmx_set_channel_key", result);
|
---|
434 | if(result != 0)
|
---|
435 | {
|
---|
436 | cs_log("set_channel_key failed for demux %d pid %04x", j, pid);
|
---|
437 | }
|
---|
438 | }
|
---|
439 | }
|
---|
440 | }
|
---|
441 | }
|
---|
442 | return 0;
|
---|
443 | }
|
---|
444 |
|
---|
445 | int32_t coolapi_read(dmx_t *dmx, dmx_callback_data_t *data)
|
---|
446 | {
|
---|
447 | if(!dmx)
|
---|
448 | {
|
---|
449 | cs_debug_mask(D_DVBAPI, "dmx is NULL!");
|
---|
450 | return -1;
|
---|
451 | }
|
---|
452 |
|
---|
453 | int32_t result;
|
---|
454 | uint32_t done = 0, toread, len = data->len;
|
---|
455 | uchar *buff = &dmx->buffer[0];
|
---|
456 | uint32_t bytes_used = 0;
|
---|
457 |
|
---|
458 | //cs_debug_mask(D_DVBAPI, "dmx channel %x pid %x len %d", (int) dmx->channel, dmx->pid, len);
|
---|
459 |
|
---|
460 | result = cnxt_cbuf_get_used(data->buf, &bytes_used);
|
---|
461 | coolapi_check_error("cnxt_cbuf_get_used", result);
|
---|
462 | if(bytes_used == 0)
|
---|
463 | { return -1; }
|
---|
464 |
|
---|
465 | result = cnxt_cbuf_read_data(data->buf, buff, 3, &done);
|
---|
466 | coolapi_check_error("cnxt_cbuf_read_data", result);
|
---|
467 |
|
---|
468 | if(done != 3)
|
---|
469 | { return -1; }
|
---|
470 |
|
---|
471 | toread = ((buff[1] << 8) | buff[2]) & 0xFFF;
|
---|
472 | if((toread + 3) > len)
|
---|
473 | { return -1; }
|
---|
474 | result = cnxt_cbuf_read_data(data->buf, buff + 3, toread, &done);
|
---|
475 | coolapi_check_error("cnxt_cbuf_read_data", result);
|
---|
476 | if(done != toread)
|
---|
477 | { return -1; }
|
---|
478 | done += 3;
|
---|
479 |
|
---|
480 | //cs_debug_mask(D_DVBAPI, "bytes read %d\n", done);
|
---|
481 |
|
---|
482 | return 0;
|
---|
483 | }
|
---|
484 |
|
---|
485 | void coolapi_open_all(void)
|
---|
486 | {
|
---|
487 | cnxt_kal_initialize();
|
---|
488 | cnxt_drv_init();
|
---|
489 | cnxt_smc_init(NULL);
|
---|
490 | cool_kal_opened = 1;
|
---|
491 | }
|
---|
492 |
|
---|
493 | void coolapi_open(void)
|
---|
494 | {
|
---|
495 | int32_t result = 0;
|
---|
496 | device_open_arg_t devarg;
|
---|
497 |
|
---|
498 | if(!dmx_opened)
|
---|
499 | {
|
---|
500 | int32_t i;
|
---|
501 |
|
---|
502 | cs_debug_mask(D_DVBAPI, "Open Coolstream DMX API");
|
---|
503 | cnxt_cbuf_init(NULL);
|
---|
504 | cnxt_dmx_init(NULL);
|
---|
505 |
|
---|
506 | memset(&devarg, 0, sizeof(device_open_arg_t));
|
---|
507 |
|
---|
508 | devarg.unknown1 = 1;
|
---|
509 | devarg.unknown3 = 3;
|
---|
510 | devarg.unknown6 = 1;
|
---|
511 | for(i = 0; i < MAX_COOL_DMX; i++)
|
---|
512 | {
|
---|
513 | devarg.number = i;
|
---|
514 | result = cnxt_dmx_open(&dmx_device[i], &devarg, NULL, NULL);
|
---|
515 | coolapi_check_error("cnxt_dmx_open", result);
|
---|
516 | }
|
---|
517 | dmx_opened = 1;
|
---|
518 | }
|
---|
519 | }
|
---|
520 |
|
---|
521 | void coolapi_close_all(void)
|
---|
522 | {
|
---|
523 | if(dmx_opened)
|
---|
524 | {
|
---|
525 | int32_t result;
|
---|
526 | int32_t i, j;
|
---|
527 |
|
---|
528 | for(i = 0; i < MAX_COOL_DMX; i++)
|
---|
529 | {
|
---|
530 | for(j = 0; j < MAX_FILTER; j++)
|
---|
531 | {
|
---|
532 | if(cdemuxes[i][j].fd > 0)
|
---|
533 | {
|
---|
534 | coolapi_remove_filter(cdemuxes[i][j].fd, cdemuxes[i][j].filter_num);
|
---|
535 | coolapi_close_device(cdemuxes[i][j].fd);
|
---|
536 | }
|
---|
537 | }
|
---|
538 | }
|
---|
539 | for(i = 0; i < MAX_COOL_DMX; i++)
|
---|
540 | {
|
---|
541 | result = cnxt_dmx_close(dmx_device[i]);
|
---|
542 | coolapi_check_error("cnxt_dmx_close", result);
|
---|
543 | dmx_device[i] = NULL;
|
---|
544 | }
|
---|
545 | }
|
---|
546 | cool_kal_opened = 0;
|
---|
547 | cnxt_kal_terminate();
|
---|
548 | cnxt_drv_term();
|
---|
549 | }
|
---|
550 | #elif defined(HAVE_DVBAPI) && defined(WITH_SU980)
|
---|
551 | #include "extapi/coolapi.h"
|
---|
552 | void cnxt_css_drv_init(void);
|
---|
553 | void cnxt_css_drv_term(void);
|
---|
554 | void cnxt_smc_term(void);
|
---|
555 |
|
---|
556 | int32_t cool_kal_opened = 0;
|
---|
557 | void coolapi_open_all(void)
|
---|
558 | {
|
---|
559 | cnxt_kal_initialize();
|
---|
560 | cnxt_css_drv_init();
|
---|
561 | cnxt_smc_init(0);
|
---|
562 | cool_kal_opened = 1;
|
---|
563 | }
|
---|
564 |
|
---|
565 | void coolapi_close_all(void)
|
---|
566 | {
|
---|
567 | cnxt_kal_terminate();
|
---|
568 | cool_kal_opened = 0;
|
---|
569 | }
|
---|
570 | #endif
|
---|