1 | #ifndef DMXDEV_H |
---|
2 | #define DMXDEV_H |
---|
3 | |
---|
4 | #if DVB_API_VERSION > 3 |
---|
5 | #ifndef DMX_ADD_PID |
---|
6 | #define DMX_ADD_PID _IOW('o', 51, __u16) |
---|
7 | #define DMX_REMOVE_PID _IOW('o', 52, __u16) |
---|
8 | #endif |
---|
9 | #else |
---|
10 | #define DMX_ADD_PID _IO('o', 51) |
---|
11 | #define DMX_REMOVE_PID _IO('o', 52) |
---|
12 | #endif |
---|
13 | |
---|
14 | struct dvbdev* dmxgetlast(int adapter) |
---|
15 | { |
---|
16 | struct dvbdev* node = dvbdev; |
---|
17 | struct dvbdev* lastnode = NULL; |
---|
18 | |
---|
19 | while(node != NULL) |
---|
20 | { |
---|
21 | if(node->type == DEMUXDEV && node->adapter == adapter) |
---|
22 | lastnode = node; |
---|
23 | node = node->next; |
---|
24 | } |
---|
25 | |
---|
26 | return lastnode; |
---|
27 | } |
---|
28 | |
---|
29 | struct dvbdev* dmxopen(struct dvbdev* fenode) |
---|
30 | { |
---|
31 | debug(1000, "in"); |
---|
32 | int fd = -1; |
---|
33 | struct dvbdev* node = dvbdev; |
---|
34 | |
---|
35 | if(fenode == NULL) return NULL; |
---|
36 | |
---|
37 | m_lock(&status.dmxdevmutex, 9); |
---|
38 | |
---|
39 | while(node != NULL) |
---|
40 | { |
---|
41 | if(node->fd == -1 && node->type == DEMUXDEV && node->adapter == fenode->adapter && node->devnr == fenode->devnr) |
---|
42 | break; |
---|
43 | node = node->next; |
---|
44 | } |
---|
45 | |
---|
46 | if(node != NULL) |
---|
47 | { |
---|
48 | if((fd = open(node->dev, O_RDWR)) < 0) |
---|
49 | { |
---|
50 | debug(200, "open dmx failed %s", node->dev); |
---|
51 | node = NULL; |
---|
52 | } |
---|
53 | else |
---|
54 | { |
---|
55 | fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); |
---|
56 | node->fd = fd; |
---|
57 | closeonexec(fd); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | m_unlock(&status.dmxdevmutex, 9); |
---|
62 | debug(1000, "out"); |
---|
63 | return node; |
---|
64 | } |
---|
65 | |
---|
66 | int dmxopendirect(char *dmxdev) |
---|
67 | { |
---|
68 | debug(1000, "in"); |
---|
69 | int fd = -1; |
---|
70 | |
---|
71 | if((fd = open(dmxdev, O_RDWR)) < 0) |
---|
72 | { |
---|
73 | debug(200, "open dmx failed %s", dmxdev); |
---|
74 | } |
---|
75 | else |
---|
76 | fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); |
---|
77 | |
---|
78 | closeonexec(fd); |
---|
79 | debug(1000, "out"); |
---|
80 | return fd; |
---|
81 | } |
---|
82 | |
---|
83 | void dmxclose(struct dvbdev* node, int fd) |
---|
84 | { |
---|
85 | if(node != NULL) |
---|
86 | { |
---|
87 | close(node->fd); |
---|
88 | node->fd = -1; |
---|
89 | } |
---|
90 | else |
---|
91 | close(fd); |
---|
92 | } |
---|
93 | |
---|
94 | int dmxstop(struct dvbdev* node) |
---|
95 | { |
---|
96 | if(node == NULL) |
---|
97 | { |
---|
98 | debug(1000, "out-> NULL detect"); |
---|
99 | return 1; |
---|
100 | } |
---|
101 | |
---|
102 | if(ioctl(node->fd, DMX_STOP) < 0) |
---|
103 | { |
---|
104 | perr("DMX_STOP"); |
---|
105 | return 1; |
---|
106 | } |
---|
107 | |
---|
108 | return 0; |
---|
109 | } |
---|
110 | |
---|
111 | int dmxstart(struct dvbdev* node) |
---|
112 | { |
---|
113 | if(node == NULL) |
---|
114 | { |
---|
115 | debug(1000, "out-> NULL detect"); |
---|
116 | return 1; |
---|
117 | } |
---|
118 | |
---|
119 | if(ioctl(node->fd, DMX_START) < 0) |
---|
120 | { |
---|
121 | perr("DMX_START"); |
---|
122 | return 1; |
---|
123 | } |
---|
124 | |
---|
125 | return 0; |
---|
126 | } |
---|
127 | |
---|
128 | int dmxsetbuffersize(struct dvbdev* node, unsigned long size) |
---|
129 | { |
---|
130 | if(node == NULL) |
---|
131 | { |
---|
132 | debug(1000, "out-> NULL detect"); |
---|
133 | return 1; |
---|
134 | } |
---|
135 | |
---|
136 | if(size == 0) |
---|
137 | size = getconfigint("dmxvideobuffersize", NULL); |
---|
138 | |
---|
139 | debug(200, "DMX_SET_BUFFER_SIZE=%ld", size); |
---|
140 | if(ioctl(node->fd, DMX_SET_BUFFER_SIZE, size) < 0) |
---|
141 | { |
---|
142 | perr("DMX_SET_BUFFER_SIZE"); |
---|
143 | return 1; |
---|
144 | } |
---|
145 | |
---|
146 | return 0; |
---|
147 | } |
---|
148 | |
---|
149 | int dmxsetfilter(struct dvbdev* node, int pid, int secnr, int flag) |
---|
150 | { |
---|
151 | struct dmx_sct_filter_params sctflt; |
---|
152 | |
---|
153 | if(node == NULL) |
---|
154 | { |
---|
155 | debug(1000, "out-> NULL detect"); |
---|
156 | return 1; |
---|
157 | } |
---|
158 | |
---|
159 | memset(&sctflt, 0, sizeof(sctflt)); |
---|
160 | |
---|
161 | if(flag == 1) //pat filter |
---|
162 | { |
---|
163 | sctflt.timeout = 0; |
---|
164 | sctflt.pid = pid; |
---|
165 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
166 | } |
---|
167 | if(flag == 2) //pmt filter |
---|
168 | { |
---|
169 | sctflt.filter.filter[0] = 0x02; |
---|
170 | sctflt.filter.mask[0] = 0xff; |
---|
171 | sctflt.timeout = 0; |
---|
172 | sctflt.pid = pid; |
---|
173 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
174 | } |
---|
175 | if(flag == 3) //date filter |
---|
176 | { |
---|
177 | sctflt.filter.filter[0] = 0x70; |
---|
178 | sctflt.filter.mask[0] = 0xff; |
---|
179 | sctflt.timeout = 0; |
---|
180 | sctflt.pid = pid; |
---|
181 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
182 | } |
---|
183 | if(flag == 4) //nit filter (pid 0x10) |
---|
184 | { |
---|
185 | sctflt.filter.filter[0] = 0x40; |
---|
186 | sctflt.filter.mask[0] = 0xff; |
---|
187 | sctflt.timeout = 0; |
---|
188 | sctflt.pid = pid; |
---|
189 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
190 | } |
---|
191 | if(flag == 5) //eit all filter (pid 0x12) |
---|
192 | { |
---|
193 | sctflt.filter.filter[0] = 0x40; |
---|
194 | sctflt.filter.mask[0] = 0x40; |
---|
195 | sctflt.timeout = 0; |
---|
196 | sctflt.pid = pid; |
---|
197 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
198 | } |
---|
199 | if(flag == 6) //eit schedule, current multiplex (pid 0x12) |
---|
200 | { |
---|
201 | sctflt.filter.filter[0] = 0x50; |
---|
202 | sctflt.filter.mask[0] = 0xf0; |
---|
203 | sctflt.timeout = 0; |
---|
204 | sctflt.pid = pid; |
---|
205 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
206 | } |
---|
207 | if(flag == 7) //eit schedule, other multiplex (pid 0x12) |
---|
208 | { |
---|
209 | sctflt.filter.filter[0] = 0x60; |
---|
210 | sctflt.filter.mask[0] = 0xf0; |
---|
211 | sctflt.timeout = 0; |
---|
212 | sctflt.pid = pid; |
---|
213 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
214 | } |
---|
215 | if(flag == 8) //eit now/next only filter (pid 0x12) |
---|
216 | { |
---|
217 | sctflt.filter.filter[0] = 0x4e; |
---|
218 | sctflt.filter.mask[0] = 0xfe; |
---|
219 | sctflt.timeout = 0; |
---|
220 | sctflt.pid = pid; |
---|
221 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
222 | } |
---|
223 | if(flag == 9) //eit now/next current multiplex (pid 0x12) |
---|
224 | { |
---|
225 | sctflt.filter.filter[0] = 0x4e; |
---|
226 | sctflt.filter.mask[0] = 0xff; |
---|
227 | sctflt.timeout = 0; |
---|
228 | sctflt.pid = pid; |
---|
229 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
230 | } |
---|
231 | if(flag == 10) //eit now/next other multiplex (pid 0x12) |
---|
232 | { |
---|
233 | sctflt.filter.filter[0] = 0x4f; |
---|
234 | sctflt.filter.mask[0] = 0xff; |
---|
235 | sctflt.timeout = 0; |
---|
236 | sctflt.pid = pid; |
---|
237 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
238 | } |
---|
239 | if(flag == 11) //sdt akt (pid 0x11) |
---|
240 | { |
---|
241 | sctflt.filter.filter[0] = 0x42; |
---|
242 | sctflt.filter.mask[0] = 0xff; |
---|
243 | sctflt.filter.filter[1] = 0x00; |
---|
244 | sctflt.filter.mask[1] = 0x00; |
---|
245 | sctflt.filter.filter[2] = 0x00; |
---|
246 | sctflt.filter.mask[2] = 0x00; |
---|
247 | sctflt.filter.filter[3] = 0x00; |
---|
248 | sctflt.filter.mask[3] = 0x00; |
---|
249 | sctflt.filter.filter[4] = secnr; |
---|
250 | sctflt.filter.mask[4] = 0xff; |
---|
251 | sctflt.timeout = 0; |
---|
252 | sctflt.pid = pid; |
---|
253 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
254 | } |
---|
255 | if(flag == 12) //sdt other (pid 0x11) |
---|
256 | { |
---|
257 | sctflt.filter.filter[0] = 0x46; |
---|
258 | sctflt.filter.mask[0] = 0xff; |
---|
259 | sctflt.filter.filter[1] = 0x00; |
---|
260 | sctflt.filter.mask[1] = 0x00; |
---|
261 | sctflt.filter.filter[2] = 0x00; |
---|
262 | sctflt.filter.mask[2] = 0x00; |
---|
263 | sctflt.filter.filter[3] = 0x00; |
---|
264 | sctflt.filter.mask[3] = 0x00; |
---|
265 | sctflt.filter.filter[4] = secnr; |
---|
266 | sctflt.filter.mask[4] = 0xff; |
---|
267 | sctflt.timeout = 0; |
---|
268 | sctflt.pid = pid; |
---|
269 | sctflt.flags = DMX_IMMEDIATE_START | DMX_CHECK_CRC; |
---|
270 | } |
---|
271 | |
---|
272 | debug(200, "DMX_SET_FILTER pid=%d, flag=%d", pid, flag); |
---|
273 | if(ioctl(node->fd, DMX_SET_FILTER, &sctflt) < 0) |
---|
274 | { |
---|
275 | perr("DMX_SET_FILTER"); |
---|
276 | return 1; |
---|
277 | } |
---|
278 | |
---|
279 | return 0; |
---|
280 | } |
---|
281 | |
---|
282 | int dmxaddpid(struct dvbdev* node, int pid) |
---|
283 | { |
---|
284 | if(node == NULL) |
---|
285 | { |
---|
286 | debug(1000, "out-> NULL detect"); |
---|
287 | return 1; |
---|
288 | } |
---|
289 | |
---|
290 | debug(200, "DMX_ADD_PID=%d", pid); |
---|
291 | while(1) |
---|
292 | { |
---|
293 | #if DVB_API_VERSION > 3 |
---|
294 | __u16 p = pid; |
---|
295 | if(ioctl(node->fd, DMX_ADD_PID, &p) < 0) |
---|
296 | #else |
---|
297 | if(ioctl(node->fd, DMX_ADD_PID, pid) < 0) |
---|
298 | #endif |
---|
299 | { |
---|
300 | perr("DMX_ADD_PID"); |
---|
301 | if(errno == EAGAIN || errno == EINTR) |
---|
302 | continue; |
---|
303 | return 1; |
---|
304 | } |
---|
305 | break; |
---|
306 | } |
---|
307 | |
---|
308 | return 0; |
---|
309 | } |
---|
310 | |
---|
311 | int dmxremovepid(struct dvbdev* node, int pid) |
---|
312 | { |
---|
313 | if(node == NULL) |
---|
314 | { |
---|
315 | debug(1000, "out-> NULL detect"); |
---|
316 | return 1; |
---|
317 | } |
---|
318 | |
---|
319 | debug(200, "DMX_REMOVE_PID=%d", pid); |
---|
320 | while(1) |
---|
321 | { |
---|
322 | #if DVB_API_VERSION > 3 |
---|
323 | __u16 p = pid; |
---|
324 | if(ioctl(node->fd, DMX_REMOVE_PID, &p) < 0) |
---|
325 | #else |
---|
326 | if(ioctl(node->fd, DMX_REMOVE_PID, pid) < 0) |
---|
327 | #endif |
---|
328 | { |
---|
329 | perr("DMX_REMOVE_PID"); |
---|
330 | if(errno == EAGAIN || errno == EINTR) |
---|
331 | continue; |
---|
332 | return 1; |
---|
333 | } |
---|
334 | break; |
---|
335 | } |
---|
336 | |
---|
337 | return 0; |
---|
338 | } |
---|
339 | |
---|
340 | int dmxgetstc(struct dvbdev* node, int64_t* stc) |
---|
341 | { |
---|
342 | struct dmx_stc dmxstc; |
---|
343 | |
---|
344 | if(node == NULL) |
---|
345 | { |
---|
346 | debug(1000, "out-> NULL detect"); |
---|
347 | return 1; |
---|
348 | } |
---|
349 | |
---|
350 | memset(&dmxstc, 0, sizeof(struct dmx_stc)); |
---|
351 | dmxstc.num = 0; |
---|
352 | dmxstc.base = 1; |
---|
353 | |
---|
354 | debug(200, "DMX_GET_STC"); |
---|
355 | if(ioctl(node->fd, DMX_GET_STC, &dmxstc) < 0) |
---|
356 | { |
---|
357 | perr("DMX_GET_STC"); |
---|
358 | return 1; |
---|
359 | } |
---|
360 | else |
---|
361 | *stc = (int64_t)dmxstc.stc; |
---|
362 | |
---|
363 | return 0; |
---|
364 | } |
---|
365 | |
---|
366 | int dmxsetsource(struct dvbdev* node, int source) |
---|
367 | { |
---|
368 | if(node == NULL) |
---|
369 | { |
---|
370 | debug(1000, "out-> NULL detect"); |
---|
371 | return 1; |
---|
372 | } |
---|
373 | |
---|
374 | debug(200, "DMX_SET_SOURCE=%d", source); |
---|
375 | if(ioctl(node->fd, DMX_SET_SOURCE, &source) < 0) |
---|
376 | { |
---|
377 | perr("DMX_SET_SOURCE"); |
---|
378 | } |
---|
379 | |
---|
380 | return 0; |
---|
381 | } |
---|
382 | |
---|
383 | int dmxsetpesfilterfd(int fd, int pid, int input, int output, int pestype, int nostart) |
---|
384 | { |
---|
385 | struct dmx_pes_filter_params pesflt; |
---|
386 | memset(&pesflt, 0, sizeof(pesflt)); |
---|
387 | |
---|
388 | if(input == -1) |
---|
389 | { |
---|
390 | if(status.playing == 1) |
---|
391 | pesflt.input = DMX_IN_DVR; |
---|
392 | else |
---|
393 | pesflt.input = DMX_IN_FRONTEND; |
---|
394 | } |
---|
395 | else |
---|
396 | pesflt.input = input; |
---|
397 | |
---|
398 | pesflt.output = output; |
---|
399 | pesflt.pid = pid; |
---|
400 | if(nostart == 0) |
---|
401 | pesflt.flags = DMX_IMMEDIATE_START; |
---|
402 | pesflt.pes_type = pestype; |
---|
403 | |
---|
404 | debug(200, "DMX_SET_PES_FILTER pid=%d, pestype=%d, input=%d, output=%d", pid, pestype, pesflt.input, output); |
---|
405 | if(ioctl(fd, DMX_SET_PES_FILTER, &pesflt) < 0) |
---|
406 | { |
---|
407 | perr("DMX_SET_PES_FILTER"); |
---|
408 | return 1; |
---|
409 | } |
---|
410 | |
---|
411 | return 0; |
---|
412 | } |
---|
413 | |
---|
414 | int dmxsetpesfilter(struct dvbdev* node, int pid, int input, int output, int pestype, int nostart) |
---|
415 | { |
---|
416 | if(node == NULL) |
---|
417 | { |
---|
418 | debug(1000, "out-> NULL detect"); |
---|
419 | return 1; |
---|
420 | } |
---|
421 | return dmxsetpesfilterfd(node->fd, pid, input, output, pestype, nostart); |
---|
422 | } |
---|
423 | |
---|
424 | int dmxgetdev() |
---|
425 | { |
---|
426 | debug(1000, "in"); |
---|
427 | int i, y, z, fd = -1, count = 0; |
---|
428 | char *buf = NULL, *dmxdev = NULL; |
---|
429 | |
---|
430 | dmxdev = getconfig("dmxdev", NULL); |
---|
431 | if(dmxdev == NULL) |
---|
432 | { |
---|
433 | debug(1000, "out -> NULL detect"); |
---|
434 | return count; |
---|
435 | } |
---|
436 | |
---|
437 | buf = malloc(MINMALLOC); |
---|
438 | if(buf == NULL) |
---|
439 | { |
---|
440 | err("no memory"); |
---|
441 | return count; |
---|
442 | } |
---|
443 | |
---|
444 | for(i = 0; i < MAXDVBADAPTER; i++) |
---|
445 | { |
---|
446 | for(y = 0; y < MAXDEMUXDEV; y++) |
---|
447 | { |
---|
448 | sprintf(buf, dmxdev, i, y); |
---|
449 | fd = dmxopendirect(buf); |
---|
450 | if(fd >= 0) |
---|
451 | { |
---|
452 | count++; |
---|
453 | for(z = 0; z < MAXDEMUXDEVOPEN; z++) |
---|
454 | adddvbdev(buf, i, y, -1, DEMUXDEV, NULL, NULL); |
---|
455 | //without this, on atevio7500, if the second tuner is the maintuner |
---|
456 | //no picture (i don't know why) |
---|
457 | dmxsetpesfilterfd(fd, 0, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0); |
---|
458 | dmxclose(NULL, fd); |
---|
459 | } |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | free(buf); |
---|
464 | debug(1000, "out"); |
---|
465 | return count; |
---|
466 | } |
---|
467 | |
---|
468 | #endif |
---|