1 | #ifndef PLAYER_H |
---|
2 | #define PLAYER_H |
---|
3 | |
---|
4 | // playercan bits: |
---|
5 | // 0 policy |
---|
6 | // 1 auditraklist |
---|
7 | // 2 subtitle |
---|
8 | // 3 videomode |
---|
9 | // 4 powerofftimer |
---|
10 | // 5 videosettings |
---|
11 | // 6 stop |
---|
12 | // 7 ff |
---|
13 | // 8 fr |
---|
14 | // 9 pause |
---|
15 | // 10 play |
---|
16 | // 11 jump/seek reverse |
---|
17 | // 12 jump/seek forward |
---|
18 | // 13 changecodec |
---|
19 | // 14 infobar |
---|
20 | // 15 slowmotion |
---|
21 | |
---|
22 | #ifdef EPLAYER3 |
---|
23 | Context_t * player = NULL; |
---|
24 | extern OutputHandler_t OutputHandler; |
---|
25 | extern PlaybackHandler_t PlaybackHandler; |
---|
26 | extern ContainerHandler_t ContainerHandler; |
---|
27 | extern ManagerHandler_t ManagerHandler; |
---|
28 | #endif |
---|
29 | |
---|
30 | #ifdef EPLAYER4 |
---|
31 | GstElement *pipeline = NULL; |
---|
32 | unsigned long long m_gst_startpts = 0; |
---|
33 | CustomData data; |
---|
34 | #endif |
---|
35 | |
---|
36 | //titan player |
---|
37 | |
---|
38 | //flag 0: from play |
---|
39 | //flag 1: from timeshift |
---|
40 | //flag 2: from playrcjumpr |
---|
41 | int playerstartts(char* file, int flag) |
---|
42 | { |
---|
43 | int fd = -1, ret = 0, tssize = 188; |
---|
44 | int16_t pmtpid = 0; |
---|
45 | int serviceid = 0; |
---|
46 | int supermagic = -1; |
---|
47 | int lastpos = 0; |
---|
48 | struct channel* chnode = NULL; |
---|
49 | struct service* snode = NULL; |
---|
50 | struct dvbdev* fenode = NULL; |
---|
51 | struct dvbdev* dvrnode = NULL; |
---|
52 | status.prefillbuffer = 0; |
---|
53 | |
---|
54 | //supermagic = getsupermagic(file); |
---|
55 | |
---|
56 | if(supermagic == NFS_SUPER_MAGIC || supermagic == SMB_SUPER_MAGIC) |
---|
57 | { |
---|
58 | debug(150, "use O_DIRECT to open file %s", file); |
---|
59 | fd = open(file, O_RDONLY | O_LARGEFILE | O_NONBLOCK | O_DIRECT); |
---|
60 | } |
---|
61 | else |
---|
62 | fd = open(file, O_RDONLY | O_LARGEFILE | O_NONBLOCK); |
---|
63 | |
---|
64 | if(fd < 0) |
---|
65 | { |
---|
66 | perr("open player file"); |
---|
67 | return 1; |
---|
68 | } |
---|
69 | |
---|
70 | fenode = fegetdummy(); |
---|
71 | dvrnode = dvropen(fenode); |
---|
72 | if(dvrnode == NULL) |
---|
73 | { |
---|
74 | err("find dvr dev"); |
---|
75 | close(fd); |
---|
76 | return 1; |
---|
77 | } |
---|
78 | |
---|
79 | if(flag == 0 || flag == 2) |
---|
80 | { |
---|
81 | //TODO: funktion to get tssize from file content |
---|
82 | if(cmpfilenameext(file, ".mts") == 0) tssize = 192; |
---|
83 | if(cmpfilenameext(file, ".m2ts") == 0) tssize = 192; |
---|
84 | |
---|
85 | ret = dvbfindpmtpid(fd, &pmtpid, &serviceid, tssize); |
---|
86 | if(ret == 1) |
---|
87 | { |
---|
88 | err("find sid/pmt pid"); |
---|
89 | close(fd); |
---|
90 | dvrclose(dvrnode, -1); |
---|
91 | return 1; |
---|
92 | } |
---|
93 | |
---|
94 | lastpos = 0; |
---|
95 | if(flag == 0 && getconfigint("showlastpos", NULL) == 1) |
---|
96 | { |
---|
97 | char* fileseek = changefilenameext(file, ".se"); |
---|
98 | FILE* fbseek = fopen(fileseek, "r"); |
---|
99 | if(fbseek != NULL) |
---|
100 | { |
---|
101 | ret = textbox(_("Message"), _("Start at last position ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
102 | if(ret == 0 || ret == 1) |
---|
103 | { |
---|
104 | char* skip1 = calloc(1, 20); |
---|
105 | if(skip1 != NULL) |
---|
106 | { |
---|
107 | fscanf(fbseek, "%s", skip1); |
---|
108 | off64_t seekpos = atoll(skip1); |
---|
109 | seekpos = seekpos - (seekpos % tssize); |
---|
110 | lseek64(fd, atoll(skip1), SEEK_SET); |
---|
111 | lastpos = 1; |
---|
112 | } |
---|
113 | free(skip1); skip1 = NULL; |
---|
114 | } |
---|
115 | fclose(fbseek); |
---|
116 | } |
---|
117 | free(fileseek); fileseek = NULL; |
---|
118 | } |
---|
119 | |
---|
120 | status.autoseek = 0; |
---|
121 | |
---|
122 | if(flag == 0) |
---|
123 | { |
---|
124 | delmarkernode(-1); |
---|
125 | char* filemarker = changefilenameext(file, ".ma"); |
---|
126 | getmarker(filemarker); |
---|
127 | free(filemarker); filemarker=NULL; |
---|
128 | } |
---|
129 | |
---|
130 | if(status.playmarker != NULL) |
---|
131 | { |
---|
132 | char* testfile = changefilenameext(file, ".as"); |
---|
133 | FILE* testseek = fopen(testfile, "r"); |
---|
134 | if(testseek != NULL) |
---|
135 | { |
---|
136 | if(lastpos == 0) |
---|
137 | lseek64(fd, status.playmarker->pos, SEEK_SET); |
---|
138 | status.autoseek = 2; |
---|
139 | addtimer(&markerautoseek_thread, START, 10000, 1, NULL, NULL, NULL); |
---|
140 | fclose(testseek); |
---|
141 | } |
---|
142 | free(testfile); testfile = NULL; |
---|
143 | } |
---|
144 | |
---|
145 | delchannel(serviceid, 0, 1); |
---|
146 | chnode = createchannel("player", 0, 0, serviceid, 99, 0, -1, -1, -1, -1, 0, -1); |
---|
147 | if(chnode != NULL) chnode->pmtpid = pmtpid; |
---|
148 | } |
---|
149 | else |
---|
150 | chnode = status.aktservice->channel; |
---|
151 | |
---|
152 | if(chnode == NULL) |
---|
153 | { |
---|
154 | err("create channel"); |
---|
155 | close(fd); |
---|
156 | dvrclose(dvrnode, -1); |
---|
157 | return 1; |
---|
158 | } |
---|
159 | |
---|
160 | if(flag == 1) |
---|
161 | { |
---|
162 | ret = servicestart(chnode, NULL, NULL, 2); |
---|
163 | if(ret != 0) |
---|
164 | { |
---|
165 | err("start play"); |
---|
166 | close(fd); |
---|
167 | dvrclose(dvrnode, -1); |
---|
168 | return 1; |
---|
169 | } |
---|
170 | |
---|
171 | //on permanent timeshift seek to end, and a little back (eof problem) |
---|
172 | if(status.timeshifttype == 1) |
---|
173 | { |
---|
174 | if(status.timeshiftpos > 0) |
---|
175 | lseek64(fd, status.timeshiftpos, SEEK_SET); |
---|
176 | else |
---|
177 | { |
---|
178 | unsigned long long pos = lseek64(fd, 0, SEEK_END); |
---|
179 | pos -= 10000000; |
---|
180 | pos = pos - (pos & tssize); |
---|
181 | lseek64(fd, -pos, SEEK_END); |
---|
182 | } |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | ret = recordstartreal(NULL, fd, dvrnode->fd, RECPLAY, 0, NULL, tssize); |
---|
187 | if(ret != 0) |
---|
188 | { |
---|
189 | err("start play thread"); |
---|
190 | close(fd); |
---|
191 | dvrclose(dvrnode, -1); |
---|
192 | return 1; |
---|
193 | } |
---|
194 | |
---|
195 | snode = getservice(RECORDPLAY, 0); |
---|
196 | if(snode != NULL) |
---|
197 | { |
---|
198 | int dupfd = -1; |
---|
199 | snode->recname = ostrcat(file, NULL, 0, 0); |
---|
200 | |
---|
201 | dupfd = open(snode->recname, O_RDONLY | O_LARGEFILE); |
---|
202 | if(dupfd > -1) |
---|
203 | gettsinfo(dupfd, &snode->lenpts, &snode->startpts, &snode->endpts, &snode->bitrate, snode->tssize); |
---|
204 | |
---|
205 | if(flag == 1) |
---|
206 | { |
---|
207 | snode->lenpts = 0; |
---|
208 | snode->endpts = 0; |
---|
209 | } |
---|
210 | else |
---|
211 | { |
---|
212 | if(getservicebyrecname(file, 1, 0) != NULL) //playfile is recording, so len can change |
---|
213 | { |
---|
214 | snode->lenpts = 0; |
---|
215 | snode->endpts = 0; |
---|
216 | } |
---|
217 | else if(dupfd > -1) |
---|
218 | snode->endoffile = lseek64(dupfd , 0, SEEK_END); |
---|
219 | } |
---|
220 | close(dupfd); |
---|
221 | } |
---|
222 | |
---|
223 | if(flag == 0 || flag == 2) |
---|
224 | { |
---|
225 | ret = servicestart(chnode, NULL, NULL, 1); |
---|
226 | if(ret != 0) |
---|
227 | { |
---|
228 | err("start play"); |
---|
229 | if(snode != NULL) snode->recendtime = 1; |
---|
230 | close(fd); |
---|
231 | dvrclose(dvrnode, -1); |
---|
232 | return 1; |
---|
233 | } |
---|
234 | //status.playercan = 0x7EFF; |
---|
235 | status.playercan = 0xFFFF; |
---|
236 | } |
---|
237 | |
---|
238 | return 0; |
---|
239 | } |
---|
240 | |
---|
241 | //flag 0: from play |
---|
242 | //flag 1: from timeshift |
---|
243 | //flag 2: from playrcjumpr/playerafterendts |
---|
244 | //flag1 0: stop from rcstop |
---|
245 | //flag1 1: stop from servicestop |
---|
246 | void playerstopts(int flag, int flag1) |
---|
247 | { |
---|
248 | int ret = 0; |
---|
249 | struct service* snode = NULL; |
---|
250 | struct channel* node = NULL; |
---|
251 | |
---|
252 | snode = getservice(RECORDPLAY, flag1); |
---|
253 | |
---|
254 | if(snode != NULL && snode->recsrcfd >= 0 && flag == 0 && flag1 == 0) |
---|
255 | { |
---|
256 | char* fileseek = changefilenameext(snode->recname, ".se"); |
---|
257 | FILE* fbseek = fopen(fileseek, "w"); |
---|
258 | if(fbseek != NULL) |
---|
259 | { |
---|
260 | off64_t pos = getcurrentpos(snode); |
---|
261 | if(pos <= 0) |
---|
262 | pos = lseek64(snode->recsrcfd, 0, SEEK_CUR); |
---|
263 | fprintf(fbseek,"%lld", pos); |
---|
264 | fclose(fbseek); |
---|
265 | } |
---|
266 | free(fileseek); fileseek=NULL; |
---|
267 | char* filemarker = changefilenameext(snode->recname, ".ma"); |
---|
268 | ret = putmarker(filemarker); |
---|
269 | free(filemarker); filemarker=NULL; |
---|
270 | delmarkernode(-1); |
---|
271 | } |
---|
272 | |
---|
273 | if(snode != NULL) snode->recendtime = 1; |
---|
274 | |
---|
275 | if(flag == 0 || flag == 2) |
---|
276 | { |
---|
277 | playerslowts(0); |
---|
278 | playerffts(0); |
---|
279 | |
---|
280 | ret = servicestop(status.aktservice, 1, 1); |
---|
281 | if(ret == 1) |
---|
282 | { |
---|
283 | debug(150, "can't stop ts playback service"); |
---|
284 | } |
---|
285 | else |
---|
286 | status.aktservice->channel = NULL; |
---|
287 | |
---|
288 | |
---|
289 | node = gettmpchannel(); |
---|
290 | if(node != NULL && ostrcmp(node->name, "player") == 0) |
---|
291 | delchannel(node->serviceid, node->transponderid, 1); |
---|
292 | } |
---|
293 | } |
---|
294 | |
---|
295 | void playerresetts() |
---|
296 | { |
---|
297 | audiostop(status.aktservice->audiodev); |
---|
298 | videostop(status.aktservice->videodev, 0); |
---|
299 | #ifdef MIPSEL |
---|
300 | videoclearbuffer(status.aktservice->videodev); |
---|
301 | audioclearbuffer(status.aktservice->audiodev); |
---|
302 | #endif |
---|
303 | videoplay(status.aktservice->videodev); |
---|
304 | audioplay(status.aktservice->audiodev); |
---|
305 | } |
---|
306 | |
---|
307 | void playercontinuets() |
---|
308 | { |
---|
309 | videocontinue(status.aktservice->videodev); |
---|
310 | audioplay(status.aktservice->audiodev); |
---|
311 | } |
---|
312 | |
---|
313 | void playerpausets() |
---|
314 | { |
---|
315 | videofreeze(status.aktservice->videodev); |
---|
316 | audiopause(status.aktservice->audiodev); |
---|
317 | } |
---|
318 | |
---|
319 | //flag 0: with lock |
---|
320 | //flag 1: without lock |
---|
321 | int playerseekts(struct service* servicenode, int sekunden, int flag) |
---|
322 | { |
---|
323 | off64_t offset = 0; |
---|
324 | off64_t endoffile = 0; |
---|
325 | off64_t currentpos = 0; |
---|
326 | //off64_t fdptspos = 0; |
---|
327 | //int ret = 0; |
---|
328 | unsigned long long lenpts = 0; |
---|
329 | unsigned long long startpts = 0; |
---|
330 | unsigned long long endpts = 0; |
---|
331 | unsigned long long bitrate = 0; |
---|
332 | //unsigned long long aktpts = 0; |
---|
333 | //unsigned long long fdpts = 0; |
---|
334 | //int aktsekunden = 0; |
---|
335 | int sekundenoff = 0; |
---|
336 | |
---|
337 | if(servicenode == NULL) return 1; |
---|
338 | |
---|
339 | if(servicenode->recsrcfd < 0) |
---|
340 | { |
---|
341 | err("source fd not ok"); |
---|
342 | return 1; |
---|
343 | } |
---|
344 | |
---|
345 | if(flag == 0) m_lock(&status.tsseekmutex, 15); |
---|
346 | |
---|
347 | /* |
---|
348 | ret = videogetpts(status.aktservice->videodev, &aktpts); |
---|
349 | if(ret == 0) |
---|
350 | { |
---|
351 | aktsekunden = aktpts / 90000; |
---|
352 | } |
---|
353 | else |
---|
354 | aktsekunden = 0; |
---|
355 | ret = getpts(servicenode->recsrcfd, 0, 0, 256 * 1024, &fdpts, &fdptspos, -1, servicenode->tssize); |
---|
356 | if(ret == 0 && aktsekunden != 0) |
---|
357 | { |
---|
358 | sekundenoff = fdpts / 90000 - aktsekunden ; |
---|
359 | //currentpos = lseek64(servicenode->recsrcfd, fdptspos, SEEK_SET); |
---|
360 | } |
---|
361 | else |
---|
362 | sekundenoff = 0; |
---|
363 | */ |
---|
364 | |
---|
365 | currentpos = lseek64(servicenode->recsrcfd, 0, SEEK_CUR); |
---|
366 | |
---|
367 | lenpts = servicenode->lenpts; |
---|
368 | startpts = servicenode->startpts; |
---|
369 | endpts = servicenode->endpts; |
---|
370 | bitrate = servicenode->bitrate; |
---|
371 | if(gettsinfo(servicenode->recsrcfd, &lenpts, &startpts, &endpts, &bitrate, servicenode->tssize) != 0) |
---|
372 | { |
---|
373 | err("can't read ts info"); |
---|
374 | lseek64(servicenode->recsrcfd, currentpos, SEEK_SET); |
---|
375 | if(flag == 0) m_unlock(&status.tsseekmutex, 15); |
---|
376 | return 1; |
---|
377 | } |
---|
378 | if(servicenode->endoffile > 0) |
---|
379 | endoffile = servicenode->endoffile - (servicenode->tssize * 2); |
---|
380 | else |
---|
381 | endoffile = lseek64(servicenode->recsrcfd , -servicenode->tssize * 2, SEEK_END); |
---|
382 | |
---|
383 | /* |
---|
384 | ret = videoclearbuffer(status.aktservice->videodev); |
---|
385 | ret = audioclearbuffer(status.aktservice->audiodev); |
---|
386 | ret = videodiscontinuityskip(status.aktservice->videodev, 0); |
---|
387 | */ |
---|
388 | |
---|
389 | if(sekunden >= 0) |
---|
390 | { |
---|
391 | if(sekundenoff != 0) |
---|
392 | offset = (bitrate / 8) * (sekunden - sekundenoff); |
---|
393 | else |
---|
394 | offset = (bitrate / 8) * sekunden - 5000000; |
---|
395 | offset = offset - (offset % servicenode->tssize); |
---|
396 | if(currentpos + offset > endoffile) |
---|
397 | { |
---|
398 | offset = endoffile - currentpos; |
---|
399 | offset = offset - (offset % servicenode->tssize); |
---|
400 | } |
---|
401 | } |
---|
402 | else |
---|
403 | { |
---|
404 | sekunden = sekunden * -1; |
---|
405 | if(sekundenoff != 0) |
---|
406 | offset = (bitrate / 8) * (sekunden + sekundenoff); |
---|
407 | else |
---|
408 | offset = (bitrate / 8) * sekunden; |
---|
409 | if(offset > 0) offset += 5000000; |
---|
410 | offset = offset - (offset % servicenode->tssize); |
---|
411 | if(currentpos - offset < 0) |
---|
412 | offset = currentpos; |
---|
413 | offset = offset * -1; |
---|
414 | } |
---|
415 | offset += currentpos; |
---|
416 | currentpos = lseek64(servicenode->recsrcfd, offset, SEEK_SET); |
---|
417 | |
---|
418 | playerresetts(); |
---|
419 | |
---|
420 | if(flag == 0) m_unlock(&status.tsseekmutex, 15); |
---|
421 | return 0; |
---|
422 | } |
---|
423 | |
---|
424 | void playerffts(int speed) |
---|
425 | { |
---|
426 | #ifdef MIPSEL |
---|
427 | audiostop(status.aktservice->audiodev); |
---|
428 | videoslowmotion(status.aktservice->videodev, 0); |
---|
429 | videofastforward(status.aktservice->videodev, speed); |
---|
430 | videocontinue(status.aktservice->videodev); |
---|
431 | #else |
---|
432 | videofastforward(status.aktservice->videodev, speed); |
---|
433 | #endif |
---|
434 | } |
---|
435 | |
---|
436 | void playerslowts(int speed) |
---|
437 | { |
---|
438 | #ifdef MIPSEL |
---|
439 | audiostop(status.aktservice->audiodev); |
---|
440 | videoslowmotion(status.aktservice->videodev, speed); |
---|
441 | videofastforward(status.aktservice->videodev, 0); |
---|
442 | videocontinue(status.aktservice->videodev); |
---|
443 | #else |
---|
444 | videoslowmotion(status.aktservice->videodev, speed); |
---|
445 | #endif |
---|
446 | } |
---|
447 | |
---|
448 | //flag = 0 --> recordplay |
---|
449 | //flag = 1 --> timeshift |
---|
450 | void playerfrts(int speed, int flag) |
---|
451 | { |
---|
452 | if(flag == 1) |
---|
453 | videocontinue(status.aktservice->videodev); |
---|
454 | if(speed == -2) |
---|
455 | { |
---|
456 | videoclearbuffer(status.aktservice->videodev); |
---|
457 | audioclearbuffer(status.aktservice->audiodev); |
---|
458 | } |
---|
459 | speed *= -1; |
---|
460 | #ifdef MIPSEL |
---|
461 | audiostop(status.aktservice->audiodev); |
---|
462 | videoslowmotion(status.aktservice->videodev, 0); |
---|
463 | videofastforward(status.aktservice->videodev, speed); |
---|
464 | videocontinue(status.aktservice->videodev); |
---|
465 | #else |
---|
466 | videofastforward(status.aktservice->videodev, speed); |
---|
467 | #endif |
---|
468 | } |
---|
469 | |
---|
470 | |
---|
471 | //flag = 0 --> play ts |
---|
472 | //flag = 1 --> timeshift |
---|
473 | //flag = 2 --> timeshift, not in play mode (only recording) |
---|
474 | int playergetinfots(unsigned long long* lenpts, unsigned long long* startpts, unsigned long long* endpts, unsigned long long* aktpts, unsigned long long* bitrate, int flag) |
---|
475 | { |
---|
476 | int ret = 0, dupfd = -1; |
---|
477 | double ratio = 0; |
---|
478 | struct service* snode = NULL; |
---|
479 | unsigned long long lenpts1 = 0; |
---|
480 | unsigned long long startpts1 = 0; |
---|
481 | unsigned long long endpts1 = 0; |
---|
482 | unsigned long long bitrate1 = 0; |
---|
483 | unsigned long long endoffile1 = 0; |
---|
484 | unsigned long long aktpos = 0; |
---|
485 | |
---|
486 | if(flag == 2) |
---|
487 | snode = getservice(RECORDTIMESHIFT, 0); |
---|
488 | else |
---|
489 | snode = getservice(RECORDPLAY, 0); |
---|
490 | |
---|
491 | if(snode == NULL) return 1; |
---|
492 | |
---|
493 | if(snode->lenpts > 0 && snode->startpts > 0 && snode->endpts > 0 && snode->bitrate > 0 && snode->endoffile > 0) |
---|
494 | { |
---|
495 | if(lenpts != NULL) *lenpts = snode->lenpts; |
---|
496 | if(startpts != NULL) *startpts = snode->startpts; |
---|
497 | if(endpts != NULL) *endpts = snode->endpts; |
---|
498 | if(bitrate != NULL) *bitrate = snode->bitrate; |
---|
499 | |
---|
500 | //ret = videogetpts(status.aktservice->videodev, aktpts); |
---|
501 | if(aktpts != NULL) |
---|
502 | { |
---|
503 | m_lock(&status.tsseekmutex, 15); |
---|
504 | if(flag == 2) |
---|
505 | aktpos = lseek64(snode->recdstfd , 0, SEEK_CUR); |
---|
506 | else |
---|
507 | aktpos = lseek64(snode->recsrcfd , 0, SEEK_CUR); |
---|
508 | m_unlock(&status.tsseekmutex, 15); |
---|
509 | |
---|
510 | ratio = (double)snode->endoffile / (double)(snode->endpts - snode->startpts); |
---|
511 | if(ratio == 0) ratio = 1; |
---|
512 | *aktpts = ((double)aktpos / ratio); |
---|
513 | *aktpts += snode->startpts; |
---|
514 | } |
---|
515 | |
---|
516 | return ret; |
---|
517 | } |
---|
518 | |
---|
519 | dupfd = open(snode->recname, O_RDONLY | O_LARGEFILE); |
---|
520 | if(dupfd < 0) |
---|
521 | { |
---|
522 | err("copy source fd not ok"); |
---|
523 | return 1; |
---|
524 | } |
---|
525 | |
---|
526 | lenpts1 = snode->lenpts; |
---|
527 | startpts1 = snode->startpts; |
---|
528 | endpts1 = snode->endpts; |
---|
529 | bitrate1 = snode->bitrate; |
---|
530 | if(gettsinfo(dupfd, &lenpts1, &startpts1, &endpts1, &bitrate1, snode->tssize) != 0) |
---|
531 | { |
---|
532 | err("can't read ts info"); |
---|
533 | return 1; |
---|
534 | } |
---|
535 | |
---|
536 | if(lenpts != NULL) *lenpts = lenpts1; |
---|
537 | if(startpts != NULL) *startpts = startpts1; |
---|
538 | if(endpts != NULL) *endpts = endpts1; |
---|
539 | if(bitrate != NULL) *bitrate = bitrate1; |
---|
540 | |
---|
541 | //ret = videogetpts(status.aktservice->videodev, aktpts); |
---|
542 | if(aktpts != NULL) |
---|
543 | { |
---|
544 | m_lock(&status.tsseekmutex, 15); |
---|
545 | if(flag == 2) |
---|
546 | aktpos = lseek64(snode->recdstfd, 0, SEEK_CUR); |
---|
547 | else |
---|
548 | aktpos = lseek64(snode->recsrcfd, 0, SEEK_CUR); |
---|
549 | m_unlock(&status.tsseekmutex, 15); |
---|
550 | |
---|
551 | if(snode->endoffile <= 0) |
---|
552 | endoffile1 = lseek64(dupfd, 0, SEEK_END); |
---|
553 | else |
---|
554 | endoffile1 = snode->endoffile; |
---|
555 | |
---|
556 | if(endpts1 == 0) |
---|
557 | ratio = 1; |
---|
558 | else |
---|
559 | ratio = (double)endoffile1 / (double)(endpts1 - startpts1); |
---|
560 | |
---|
561 | if(ratio == 0) ratio = 1; |
---|
562 | *aktpts = ((double)aktpos / ratio); |
---|
563 | *aktpts += startpts1; |
---|
564 | } |
---|
565 | |
---|
566 | close(dupfd); |
---|
567 | return ret; |
---|
568 | } |
---|
569 | |
---|
570 | void playerchangeaudiotrackts() |
---|
571 | { |
---|
572 | screenaudiotrack(); |
---|
573 | } |
---|
574 | |
---|
575 | void playerchangesubtitletrackts() |
---|
576 | { |
---|
577 | screensubtitle(); |
---|
578 | } |
---|
579 | |
---|
580 | int playerisplayingts() |
---|
581 | { |
---|
582 | struct service* snode = getservice(RECORDPLAY, 0); |
---|
583 | |
---|
584 | if(snode == NULL) |
---|
585 | return 0; |
---|
586 | return 1; |
---|
587 | } |
---|
588 | |
---|
589 | void playerafterendts() |
---|
590 | { |
---|
591 | playerstopts(2, 0); |
---|
592 | } |
---|
593 | |
---|
594 | //extern player |
---|
595 | int playerstart(char* file) |
---|
596 | { |
---|
597 | char * tmpfile = NULL; |
---|
598 | status.prefillbuffer = 0; |
---|
599 | |
---|
600 | if(file != NULL) |
---|
601 | { |
---|
602 | #ifdef EPLAYER3 |
---|
603 | //use eplayer |
---|
604 | |
---|
605 | if(player != NULL) |
---|
606 | { |
---|
607 | debug(150, "eplayer allready running"); |
---|
608 | playerstop(); |
---|
609 | } |
---|
610 | |
---|
611 | player = calloc(1, sizeof(Context_t)); |
---|
612 | |
---|
613 | if(player == NULL) |
---|
614 | { |
---|
615 | err("no mem"); |
---|
616 | return 1; |
---|
617 | } |
---|
618 | |
---|
619 | if(ostrstr(file, "://") == NULL) |
---|
620 | tmpfile = ostrcat("file://", file, 0, 0); |
---|
621 | else |
---|
622 | tmpfile = ostrcat(file, NULL, 0, 0); |
---|
623 | |
---|
624 | if(tmpfile == NULL) |
---|
625 | { |
---|
626 | err("no mem"); |
---|
627 | free(player); player = NULL; |
---|
628 | return 1; |
---|
629 | } |
---|
630 | // move to mc |
---|
631 | // set_player_sound(0); |
---|
632 | |
---|
633 | if(ostrstr(tmpfile, "file://") == NULL) |
---|
634 | status.playercan = 0x4650; |
---|
635 | else |
---|
636 | status.playercan = 0xFFFF; |
---|
637 | |
---|
638 | player->playback = &PlaybackHandler; |
---|
639 | player->output = &OutputHandler; |
---|
640 | player->container = &ContainerHandler; |
---|
641 | player->manager = &ManagerHandler; |
---|
642 | |
---|
643 | //add container befor open, so we can set buffer size |
---|
644 | char* ext = getfilenameext(tmpfile); |
---|
645 | if(ext != NULL) |
---|
646 | { |
---|
647 | player->container->Command(player, CONTAINER_ADD, ext); |
---|
648 | free(ext); ext = NULL; |
---|
649 | } |
---|
650 | |
---|
651 | //select container_ffmpeg, if we does not found a container with extensions |
---|
652 | if(player->container->selectedContainer == NULL) |
---|
653 | player->container->Command(player, CONTAINER_ADD, "mp3"); |
---|
654 | |
---|
655 | if(player && player->container && player->container->selectedContainer) |
---|
656 | { |
---|
657 | int size = getconfigint("playerbuffersize", NULL); |
---|
658 | int seektime = getconfigint("playerbufferseektime", NULL); |
---|
659 | player->container->selectedContainer->Command(player, CONTAINER_SET_BUFFER_SIZE, (void*)&size); |
---|
660 | player->container->selectedContainer->Command(player, CONTAINER_SET_BUFFER_SEEK_TIME, (void*)&seektime); |
---|
661 | } |
---|
662 | |
---|
663 | debug(150, "eplayername = %s", player->output->Name); |
---|
664 | |
---|
665 | //Registrating output devices |
---|
666 | player->output->Command(player, OUTPUT_ADD, "audio"); |
---|
667 | player->output->Command(player, OUTPUT_ADD, "video"); |
---|
668 | player->output->Command(player, OUTPUT_ADD, "subtitle"); |
---|
669 | |
---|
670 | //for subtitle |
---|
671 | SubtitleOutputDef_t subout; |
---|
672 | |
---|
673 | subout.screen_width = skinfb->width; |
---|
674 | subout.screen_height = skinfb->height; |
---|
675 | subout.framebufferFD = skinfb->fd; |
---|
676 | subout.destination = (uint32_t *)skinfb->fb; |
---|
677 | subout.destStride = skinfb->pitch; |
---|
678 | subout.shareFramebuffer = 1; |
---|
679 | subout.framebufferBlit = blitfb1; |
---|
680 | |
---|
681 | player->output->subtitle->Command(player, (OutputCmd_t)OUTPUT_SET_SUBTITLE_OUTPUT, (void*)&subout); |
---|
682 | |
---|
683 | if(player->playback->Command(player, PLAYBACK_OPEN, tmpfile) < 0) |
---|
684 | { |
---|
685 | free(player); player = NULL; |
---|
686 | free(tmpfile); |
---|
687 | return 1; |
---|
688 | } |
---|
689 | |
---|
690 | player->output->Command(player, OUTPUT_OPEN, NULL); |
---|
691 | player->playback->Command(player, PLAYBACK_PLAY, NULL); |
---|
692 | |
---|
693 | free(tmpfile); |
---|
694 | |
---|
695 | return 0; |
---|
696 | #endif |
---|
697 | |
---|
698 | #ifdef EPLAYER4 |
---|
699 | int flags = 0x47; //(GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_NATIVE_VIDEO | GST_PLAY_FLAG_TEXT); |
---|
700 | |
---|
701 | if(pipeline != NULL) |
---|
702 | { |
---|
703 | debug(150, "eplayer allready running"); |
---|
704 | playerstop(); |
---|
705 | } |
---|
706 | |
---|
707 | if(ostrstr(file, "://") == NULL) |
---|
708 | tmpfile = ostrcat("file://", file, 0, 0); |
---|
709 | else |
---|
710 | tmpfile = ostrcat(file, NULL, 0, 0); |
---|
711 | |
---|
712 | if(tmpfile == NULL) |
---|
713 | { |
---|
714 | err("no mem"); |
---|
715 | free(pipeline); pipeline = NULL; |
---|
716 | return 1; |
---|
717 | } |
---|
718 | |
---|
719 | if(ostrstr(tmpfile, "file://") == NULL) |
---|
720 | status.playercan = 0x7E7F; |
---|
721 | else |
---|
722 | status.playercan = 0x7E7F; |
---|
723 | |
---|
724 | pipeline = gst_element_factory_make("playbin2", "playbin"); |
---|
725 | |
---|
726 | // enable buffersize start |
---|
727 | int size = getconfigint("playerbuffersize", NULL); |
---|
728 | printf("size: %d\n",size); |
---|
729 | |
---|
730 | if(size > 0) |
---|
731 | status.prefillbuffer = 1; |
---|
732 | |
---|
733 | g_object_set(G_OBJECT(pipeline), "buffer-duration", size * GST_SECOND, NULL); |
---|
734 | g_object_set(G_OBJECT(pipeline), "buffer-size", size, NULL); |
---|
735 | // enable buffersizeend |
---|
736 | |
---|
737 | g_object_set(G_OBJECT(pipeline), "uri", tmpfile, NULL); |
---|
738 | g_object_set(G_OBJECT(pipeline), "flags", flags, NULL); |
---|
739 | free(tmpfile); tmpfile = NULL; |
---|
740 | |
---|
741 | /////////////////// |
---|
742 | // srt subs start |
---|
743 | const char *filename = file; |
---|
744 | const char *ext = strrchr(filename, '.'); |
---|
745 | if (!ext) |
---|
746 | ext = filename + strlen(filename); |
---|
747 | |
---|
748 | GstElement *subsink = gst_element_factory_make("subsink", "subtitle_sink"); |
---|
749 | if (!subsink) |
---|
750 | printf("sorry, can't play: missing gst-plugin-subsink\n"); |
---|
751 | else |
---|
752 | { |
---|
753 | // m_subs_to_pull_handler_id = g_signal_connect (subsink, "new-buffer", G_CALLBACK (gstCBsubtitleAvail), this); |
---|
754 | g_object_set (G_OBJECT (subsink), "caps", gst_caps_from_string("text/plain; text/x-plain; text/x-raw; text/x-pango-markup; video/x-dvd-subpicture; subpicture/x-pgs"), NULL); |
---|
755 | g_object_set (G_OBJECT (pipeline), "text-sink", subsink, NULL); |
---|
756 | g_object_set (G_OBJECT (pipeline), "current-text", -1, NULL); |
---|
757 | } |
---|
758 | |
---|
759 | //gpointer this; |
---|
760 | //memset (&this, 0, sizeof (this)); |
---|
761 | |
---|
762 | GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); |
---|
763 | #if GST_VERSION_MAJOR < 1 |
---|
764 | // gst_bus_set_sync_handler(bus, gstBusSyncHandler, this); |
---|
765 | gst_bus_set_sync_handler(bus, GST_BUS_DROP, NULL); |
---|
766 | #else |
---|
767 | // gst_bus_set_sync_handler(bus, gstBusSyncHandler, this, NULL); |
---|
768 | gst_bus_set_sync_handler(bus, GST_BUS_DROP, NULL, NULL); |
---|
769 | #endif |
---|
770 | |
---|
771 | gst_object_unref(bus); |
---|
772 | char srt_filename[ext - filename + 5]; |
---|
773 | strncpy(srt_filename,filename, ext - filename); |
---|
774 | srt_filename[ext - filename] = '\0'; |
---|
775 | strcat(srt_filename, ".srt"); |
---|
776 | |
---|
777 | if(access(srt_filename, R_OK) >= 0) |
---|
778 | { |
---|
779 | printf("found srt1: %s\n",srt_filename); |
---|
780 | printf("found srt2: %s\n",g_filename_to_uri(srt_filename, NULL, NULL)); |
---|
781 | g_object_set(G_OBJECT (pipeline), "suburi", g_filename_to_uri(srt_filename, NULL, NULL), NULL); |
---|
782 | } |
---|
783 | // srt end |
---|
784 | |
---|
785 | /////////////////// |
---|
786 | // CustomData data; |
---|
787 | memset (&data, 0, sizeof (data)); |
---|
788 | data.pipeline = pipeline; |
---|
789 | // GstBus *bus; |
---|
790 | // bus = gst_element_get_bus (pipeline); |
---|
791 | |
---|
792 | // Start playing // |
---|
793 | GstStateChangeReturn ret; |
---|
794 | ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); |
---|
795 | if(ret == GST_STATE_CHANGE_FAILURE) |
---|
796 | { |
---|
797 | g_printerr ("Unable to set the pipeline to the playing state.\n"); |
---|
798 | gst_object_unref (pipeline); |
---|
799 | return -1; |
---|
800 | } |
---|
801 | else if(ret == GST_STATE_CHANGE_NO_PREROLL) |
---|
802 | { |
---|
803 | data.is_live = TRUE; |
---|
804 | } |
---|
805 | |
---|
806 | data.loop = g_main_loop_new (NULL, FALSE); |
---|
807 | data.pipeline = pipeline; |
---|
808 | gst_bus_add_signal_watch (bus); |
---|
809 | // g_signal_connect (bus, "message", G_CALLBACK (cb_message), &data); |
---|
810 | // status.prefillbuffer = 1; |
---|
811 | |
---|
812 | int count = 0; |
---|
813 | m_gst_startpts = 0; |
---|
814 | while(m_gst_startpts == 0 && count < 5) |
---|
815 | { |
---|
816 | count++; |
---|
817 | sleep(1); |
---|
818 | m_gst_startpts = playergetpts(); |
---|
819 | } |
---|
820 | |
---|
821 | return 0; |
---|
822 | #endif |
---|
823 | } |
---|
824 | |
---|
825 | return 1; |
---|
826 | } |
---|
827 | |
---|
828 | #ifdef EPLAYER4 |
---|
829 | int setBufferSize(int size) |
---|
830 | { |
---|
831 | int m_buffer_size = size; |
---|
832 | g_object_set (G_OBJECT (pipeline), "buffer-size", m_buffer_size, NULL); |
---|
833 | return 0; |
---|
834 | } |
---|
835 | #endif |
---|
836 | |
---|
837 | void playerinit(int argc, char* argv[]) |
---|
838 | { |
---|
839 | #ifdef EPLAYER4 |
---|
840 | gst_init(&argc, &argv); |
---|
841 | #endif |
---|
842 | } |
---|
843 | |
---|
844 | #ifdef EPLAYER4 |
---|
845 | int gstbuscall(GstBus *bus, GstMessage *msg, CustomData *data) |
---|
846 | { |
---|
847 | |
---|
848 | int ret = 1; |
---|
849 | if(!pipeline) return 0; |
---|
850 | if(!msg) return ret; |
---|
851 | |
---|
852 | gchar *sourceName = NULL; |
---|
853 | GstObject *source = GST_MESSAGE_SRC(msg); |
---|
854 | |
---|
855 | if(!GST_IS_OBJECT(source)) return ret; |
---|
856 | sourceName = gst_object_get_name(source); |
---|
857 | |
---|
858 | switch(GST_MESSAGE_TYPE(msg)) |
---|
859 | { |
---|
860 | case GST_MESSAGE_EOS: |
---|
861 | debug(150, "gst player eof"); |
---|
862 | ret = 0; |
---|
863 | break; |
---|
864 | case GST_MESSAGE_STATE_CHANGED: |
---|
865 | if(GST_MESSAGE_SRC(msg) != GST_OBJECT(pipeline)) |
---|
866 | break; |
---|
867 | |
---|
868 | GstState old_state, new_state; |
---|
869 | gst_message_parse_state_changed(msg, &old_state, &new_state, NULL); |
---|
870 | |
---|
871 | if(old_state == new_state) break; |
---|
872 | |
---|
873 | debug(150, "gst state change %s -> %s", gst_element_state_get_name(old_state), gst_element_state_get_name(new_state)); |
---|
874 | |
---|
875 | GstStateChange transition = (GstStateChange)GST_STATE_TRANSITION(old_state, new_state); |
---|
876 | |
---|
877 | switch(transition) |
---|
878 | { |
---|
879 | case GST_STATE_CHANGE_NULL_TO_READY: |
---|
880 | break; |
---|
881 | case GST_STATE_CHANGE_READY_TO_PAUSED: |
---|
882 | /* |
---|
883 | GstElement *appsink = gst_bin_get_by_name(GST_BIN(pipeline), "subtitle_sink"); |
---|
884 | if(appsink) |
---|
885 | { |
---|
886 | g_object_set(G_OBJECT(appsink), "max-buffers", 2, NULL); |
---|
887 | g_object_set(G_OBJECT(appsink), "sync", FALSE, NULL); |
---|
888 | g_object_set(G_OBJECT(appsink), "emit-signals", TRUE, NULL); |
---|
889 | gst_object_unref(appsink); |
---|
890 | } |
---|
891 | */ |
---|
892 | break; |
---|
893 | case GST_STATE_CHANGE_PAUSED_TO_PLAYING: |
---|
894 | //if(m_sourceinfo.is_streaming && m_streamingsrc_timeout ) |
---|
895 | //m_streamingsrc_timeout->stop(); |
---|
896 | break; |
---|
897 | case GST_STATE_CHANGE_PLAYING_TO_PAUSED: |
---|
898 | break; |
---|
899 | case GST_STATE_CHANGE_PAUSED_TO_READY: |
---|
900 | break; |
---|
901 | case GST_STATE_CHANGE_READY_TO_NULL: |
---|
902 | ret = 0; |
---|
903 | break; |
---|
904 | } |
---|
905 | break; |
---|
906 | case GST_MESSAGE_ERROR: |
---|
907 | debug(150, "gst player error"); |
---|
908 | |
---|
909 | gchar *gdebug1; |
---|
910 | GError *err; |
---|
911 | |
---|
912 | gst_message_parse_error(msg, &err, &gdebug1); |
---|
913 | g_free(gdebug1); |
---|
914 | |
---|
915 | debug(150, "gst error: %s (%i) from %s", err->message, err->code, sourceName); |
---|
916 | if(err->domain == GST_STREAM_ERROR) |
---|
917 | { |
---|
918 | if(err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND ) |
---|
919 | { |
---|
920 | //if(g_strrstr(sourceName, "videosink")) |
---|
921 | // m_event((iPlayableService*)this, evUser+11); |
---|
922 | //else if ( g_strrstr(sourceName, "audiosink") ) |
---|
923 | // m_event((iPlayableService*)this, evUser+10); |
---|
924 | } |
---|
925 | } |
---|
926 | g_error_free(err); |
---|
927 | break; |
---|
928 | case GST_MESSAGE_INFO: |
---|
929 | debug(150, "gst player info"); |
---|
930 | |
---|
931 | /* |
---|
932 | gchar *gdebug2; |
---|
933 | GError *inf; |
---|
934 | |
---|
935 | gst_message_parse_info(msg, &inf, &gdebug2); |
---|
936 | g_free(gdebug2); |
---|
937 | if(inf->domain == GST_STREAM_ERROR && inf->code == GST_STREAM_ERROR_DECODE ) |
---|
938 | { |
---|
939 | //if(g_strrstr(sourceName, "videosink")) |
---|
940 | // m_event((iPlayableService*)this, evUser+14); |
---|
941 | } |
---|
942 | g_error_free(inf); |
---|
943 | */ |
---|
944 | break; |
---|
945 | case GST_MESSAGE_TAG: |
---|
946 | debug(150, "gst player tag"); |
---|
947 | break; |
---|
948 | //case GST_MESSAGE_ASYNC_DONE: |
---|
949 | // debug(150, "gst player async done"); |
---|
950 | // break; |
---|
951 | case GST_MESSAGE_ELEMENT: |
---|
952 | debug(150, "gst player element"); |
---|
953 | break; |
---|
954 | case GST_MESSAGE_BUFFERING: |
---|
955 | debug(150, "gst player buffering"); |
---|
956 | |
---|
957 | /* |
---|
958 | GstBufferingMode mode; |
---|
959 | gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent)); |
---|
960 | gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft)); |
---|
961 | //m_event((iPlayableService*)this, evBuffering); |
---|
962 | */ |
---|
963 | |
---|
964 | if(status.prefillbuffer == 1) |
---|
965 | { |
---|
966 | // gint percent = 0; |
---|
967 | if (data->is_live) break; |
---|
968 | gst_message_parse_buffering (msg, &status.bufferpercent); |
---|
969 | g_print ("Buffering (%3d%%)\r", status.bufferpercent); |
---|
970 | if (status.bufferpercent < 100) |
---|
971 | { |
---|
972 | gst_element_set_state (data->pipeline, GST_STATE_PAUSED); |
---|
973 | struct skin* waitmsgbar = getscreen("waitmsgbar"); |
---|
974 | struct skin* load = getscreen("loading"); |
---|
975 | |
---|
976 | waitmsgbar->progresssize = status.bufferpercent; |
---|
977 | char* tmpstr = NULL; |
---|
978 | tmpstr = ostrcat(_("Buffering Stream - Cancel with Exit"), " (", 0, 0); |
---|
979 | tmpstr = ostrcat(tmpstr, oitoa(waitmsgbar->progresssize), 1, 0); |
---|
980 | tmpstr = ostrcat(tmpstr, "%)", 1, 0); |
---|
981 | changetext(waitmsgbar, tmpstr); |
---|
982 | free(tmpstr); tmpstr = NULL; |
---|
983 | |
---|
984 | drawscreen(load, 0, 0); |
---|
985 | drawscreen(waitmsgbar, 0, 0); |
---|
986 | } |
---|
987 | else |
---|
988 | { |
---|
989 | drawscreen(skin, 0, 0); |
---|
990 | gst_element_set_state (data->pipeline, GST_STATE_PLAYING); |
---|
991 | status.prefillbuffer = 0; |
---|
992 | } |
---|
993 | |
---|
994 | } |
---|
995 | else if(status.prefillbuffer == 2) |
---|
996 | { |
---|
997 | drawscreen(skin, 0, 0); |
---|
998 | gst_element_set_state (data->pipeline, GST_STATE_PLAYING); |
---|
999 | status.prefillbuffer = 0; |
---|
1000 | } |
---|
1001 | |
---|
1002 | break; |
---|
1003 | |
---|
1004 | /* |
---|
1005 | GstBufferingMode mode; |
---|
1006 | gst_message_parse_buffering(msg, &(status.bufferpercent)); |
---|
1007 | gst_message_parse_buffering_stats(msg, &mode, &(status.avgInRate), &(status.avgOutRate), &(status.bufferingLeft)); |
---|
1008 | |
---|
1009 | // printf("#########################################################\n"); |
---|
1010 | // printf("Buffering %u percent done\n", status.bufferpercent); |
---|
1011 | // printf("avgInRate %d\n", status.avgInRate); |
---|
1012 | // printf("avgOutRate %d\n", status.avgOutRate); |
---|
1013 | // printf("bufferingLeft %lld\n", status.bufferingLeft); |
---|
1014 | |
---|
1015 | if(status.prefillbuffer == 1) |
---|
1016 | { |
---|
1017 | printf("status.prefillbuffer Buffering %u percent done\n", status.bufferpercent); |
---|
1018 | |
---|
1019 | if (status.bufferpercent == 100) |
---|
1020 | { |
---|
1021 | GstState state; |
---|
1022 | gst_element_get_state(pipeline, &state, NULL, 0LL); |
---|
1023 | if (state != GST_STATE_PLAYING) |
---|
1024 | { |
---|
1025 | // eDebug("start playing"); |
---|
1026 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
---|
1027 | } |
---|
1028 | // m_ignore_buffering_messages = 5; |
---|
1029 | status.prefillbuffer = 0; |
---|
1030 | } |
---|
1031 | else if (status.bufferpercent == 0) |
---|
1032 | { |
---|
1033 | // eDebug("start pause"); |
---|
1034 | gst_element_set_state (pipeline, GST_STATE_PAUSED); |
---|
1035 | // m_ignore_buffering_messages = 0; |
---|
1036 | } |
---|
1037 | } |
---|
1038 | */ |
---|
1039 | /* |
---|
1040 | GstBufferingMode mode; |
---|
1041 | printf("GST_STATE_PAUSED\n"); |
---|
1042 | gst_element_set_state (pipeline, GST_STATE_PAUSED); |
---|
1043 | |
---|
1044 | |
---|
1045 | gst_message_parse_buffering(msg, &(m_bufferInfo.bufferPercent)); |
---|
1046 | // eDebug("Buffering %u percent done", m_bufferInfo.bufferPercent); |
---|
1047 | gst_message_parse_buffering_stats(msg, &mode, &(m_bufferInfo.avgInRate), &(m_bufferInfo.avgOutRate), &(m_bufferInfo.bufferingLeft)); |
---|
1048 | m_event((iPlayableService*)this, evBuffering); |
---|
1049 | if (m_use_prefillbuffer && !m_is_live && --m_ignore_buffering_messages <= 0) |
---|
1050 | { |
---|
1051 | if (m_bufferInfo.bufferPercent == 100) |
---|
1052 | { |
---|
1053 | GstState state; |
---|
1054 | gst_element_get_state(pipeline, &state, NULL, 0LL); |
---|
1055 | if (state != GST_STATE_PLAYING) |
---|
1056 | { |
---|
1057 | // eDebug("start playing"); |
---|
1058 | gst_element_set_state (pipeline, GST_STATE_PLAYING); |
---|
1059 | } |
---|
1060 | m_ignore_buffering_messages = 5; |
---|
1061 | } |
---|
1062 | else if (m_bufferInfo.bufferPercent == 0) |
---|
1063 | { |
---|
1064 | // eDebug("start pause"); |
---|
1065 | gst_element_set_state (pipeline, GST_STATE_PAUSED); |
---|
1066 | m_ignore_buffering_messages = 0; |
---|
1067 | } |
---|
1068 | else |
---|
1069 | { |
---|
1070 | m_ignore_buffering_messages = 0; |
---|
1071 | } |
---|
1072 | } |
---|
1073 | |
---|
1074 | */ |
---|
1075 | break; |
---|
1076 | case GST_MESSAGE_STREAM_STATUS: |
---|
1077 | debug(150, "gst player stream status"); |
---|
1078 | |
---|
1079 | /* |
---|
1080 | GstStreamStatusType type; |
---|
1081 | GstElement *owner; |
---|
1082 | |
---|
1083 | gst_message_parse_stream_status(msg, &type, &owner); |
---|
1084 | if(type == GST_STREAM_STATUS_TYPE_CREATE && m_sourceinfo.is_streaming) |
---|
1085 | { |
---|
1086 | if(GST_IS_PAD(source)) |
---|
1087 | owner = gst_pad_get_parent_element(GST_PAD(source)); |
---|
1088 | else if(GST_IS_ELEMENT(source)) |
---|
1089 | owner = GST_ELEMENT(source); |
---|
1090 | else |
---|
1091 | owner = NULL; |
---|
1092 | if(owner) |
---|
1093 | { |
---|
1094 | GstElementFactory *factory = gst_element_get_factory(GST_ELEMENT(owner)); |
---|
1095 | const gchar *name = gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(factory)); |
---|
1096 | if (!strcmp(name, "souphttpsrc")) |
---|
1097 | { |
---|
1098 | //m_streamingsrc_timeout->start(10 * 1000, true); |
---|
1099 | g_object_set(G_OBJECT(owner), "timeout", 10, NULL); |
---|
1100 | } |
---|
1101 | |
---|
1102 | } |
---|
1103 | if(GST_IS_PAD(source)) |
---|
1104 | gst_object_unref(owner); |
---|
1105 | } |
---|
1106 | */ |
---|
1107 | break; |
---|
1108 | default: |
---|
1109 | debug(150, "gst player unknown message"); |
---|
1110 | break; |
---|
1111 | } |
---|
1112 | g_free(sourceName); |
---|
1113 | return ret; |
---|
1114 | } |
---|
1115 | #endif |
---|
1116 | |
---|
1117 | int playergetbuffersize() |
---|
1118 | { |
---|
1119 | int ret = 0; |
---|
1120 | |
---|
1121 | #ifdef EPLAYER3 |
---|
1122 | if(player && player->container && player->container->selectedContainer) |
---|
1123 | player->container->selectedContainer->Command(player, CONTAINER_GET_BUFFER_SIZE, (void*)&ret); |
---|
1124 | #endif |
---|
1125 | |
---|
1126 | return ret; |
---|
1127 | } |
---|
1128 | |
---|
1129 | int playergetbufferstatus() |
---|
1130 | { |
---|
1131 | int ret = 0; |
---|
1132 | |
---|
1133 | #ifdef EPLAYER3 |
---|
1134 | if(player && player->container && player->container->selectedContainer) |
---|
1135 | player->container->selectedContainer->Command(player, CONTAINER_GET_BUFFER_STATUS, (void*)&ret); |
---|
1136 | #endif |
---|
1137 | |
---|
1138 | return ret; |
---|
1139 | } |
---|
1140 | |
---|
1141 | int playerstopbuffer() |
---|
1142 | { |
---|
1143 | int ret = 0; |
---|
1144 | |
---|
1145 | #ifdef EPLAYER3 |
---|
1146 | if(player && player->container && player->container->selectedContainer) |
---|
1147 | player->container->selectedContainer->Command(player, CONTAINER_STOP_BUFFER, NULL); |
---|
1148 | #endif |
---|
1149 | |
---|
1150 | return ret; |
---|
1151 | } |
---|
1152 | |
---|
1153 | int playerisplaying() |
---|
1154 | { |
---|
1155 | #ifdef SIMULATE |
---|
1156 | return 1; |
---|
1157 | #endif |
---|
1158 | |
---|
1159 | #ifdef EPLAYER3 |
---|
1160 | if(player != NULL && player->playback != NULL && player->playback->isPlaying) |
---|
1161 | return 1; |
---|
1162 | #endif |
---|
1163 | |
---|
1164 | #ifdef EPLAYER4 |
---|
1165 | int ret = 1; |
---|
1166 | |
---|
1167 | if(pipeline) |
---|
1168 | { |
---|
1169 | GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); |
---|
1170 | GstMessage *message = NULL; |
---|
1171 | //use global variale, with static var crash |
---|
1172 | // CustomData *data = NULL; |
---|
1173 | while((message = gst_bus_pop(bus))) |
---|
1174 | { |
---|
1175 | ret = gstbuscall(bus, message, &data); |
---|
1176 | gst_message_unref(message); |
---|
1177 | } |
---|
1178 | } |
---|
1179 | else |
---|
1180 | ret = 0; |
---|
1181 | |
---|
1182 | return ret; |
---|
1183 | #endif |
---|
1184 | return 0; |
---|
1185 | } |
---|
1186 | |
---|
1187 | void playerplay() |
---|
1188 | { |
---|
1189 | #ifdef EPLAYER3 |
---|
1190 | if(player && player->playback) |
---|
1191 | player->playback->Command(player, PLAYBACK_PLAY, NULL); |
---|
1192 | #endif |
---|
1193 | |
---|
1194 | #ifdef EPLAYER4 |
---|
1195 | if(pipeline) |
---|
1196 | gst_element_set_state(pipeline, GST_STATE_PLAYING); |
---|
1197 | #endif |
---|
1198 | } |
---|
1199 | |
---|
1200 | int playerstop() |
---|
1201 | { |
---|
1202 | #ifdef EPLAYER3 |
---|
1203 | if(player && player->playback) |
---|
1204 | player->playback->Command(player, PLAYBACK_STOP, NULL); |
---|
1205 | if(player && player->container && player->container->selectedContainer) |
---|
1206 | player->container->selectedContainer->Command(player, CONTAINER_STOP, NULL); |
---|
1207 | if(player && player->output) |
---|
1208 | { |
---|
1209 | player->output->Command(player, OUTPUT_CLOSE, NULL); |
---|
1210 | player->output->Command(player, OUTPUT_DEL, (void*)"audio"); |
---|
1211 | player->output->Command(player, OUTPUT_DEL, (void*)"video"); |
---|
1212 | player->output->Command(player, OUTPUT_DEL, (void*)"subtitle"); |
---|
1213 | } |
---|
1214 | if(player && player->playback) |
---|
1215 | player->playback->Command(player, PLAYBACK_CLOSE, NULL); |
---|
1216 | |
---|
1217 | free(player); |
---|
1218 | player = NULL; |
---|
1219 | // move to mc |
---|
1220 | // set_player_sound(1); |
---|
1221 | #endif |
---|
1222 | |
---|
1223 | #ifdef EPLAYER4 |
---|
1224 | if(pipeline) |
---|
1225 | { |
---|
1226 | gst_element_set_state(pipeline, GST_STATE_NULL); |
---|
1227 | gst_object_unref(GST_OBJECT(pipeline)); |
---|
1228 | pipeline = NULL; |
---|
1229 | } |
---|
1230 | #endif |
---|
1231 | |
---|
1232 | writesysint("/proc/sys/vm/drop_caches", 3, 0); |
---|
1233 | return 0; |
---|
1234 | } |
---|
1235 | |
---|
1236 | void playerafterend() |
---|
1237 | { |
---|
1238 | #ifdef EPLAYER3 |
---|
1239 | if(player != NULL && player->playback != NULL) |
---|
1240 | playerstop(); |
---|
1241 | #endif |
---|
1242 | |
---|
1243 | #ifdef EPLAYER4 |
---|
1244 | if(pipeline) |
---|
1245 | playerstop(); |
---|
1246 | #endif |
---|
1247 | } |
---|
1248 | |
---|
1249 | void playerpause() |
---|
1250 | { |
---|
1251 | #ifdef EPLAYER3 |
---|
1252 | if(player && player->playback) |
---|
1253 | player->playback->Command(player, PLAYBACK_PAUSE, NULL); |
---|
1254 | #endif |
---|
1255 | |
---|
1256 | #ifdef EPLAYER4 |
---|
1257 | if(pipeline) |
---|
1258 | gst_element_set_state(pipeline, GST_STATE_PAUSED); |
---|
1259 | #endif |
---|
1260 | } |
---|
1261 | |
---|
1262 | void playercontinue() |
---|
1263 | { |
---|
1264 | #ifdef EPLAYER3 |
---|
1265 | if(player && player->playback) |
---|
1266 | player->playback->Command(player, PLAYBACK_CONTINUE, NULL); |
---|
1267 | #endif |
---|
1268 | |
---|
1269 | #ifdef EPLAYER4 |
---|
1270 | if(pipeline) |
---|
1271 | gst_element_set_state(pipeline, GST_STATE_PLAYING); |
---|
1272 | #endif |
---|
1273 | } |
---|
1274 | |
---|
1275 | void playerff(int speed) |
---|
1276 | { |
---|
1277 | #ifdef EPLAYER3 |
---|
1278 | int speedmap = 0; |
---|
1279 | |
---|
1280 | if (speed < 1) speed = 1; |
---|
1281 | if (speed > 7) speed = 7; |
---|
1282 | |
---|
1283 | switch(speed) |
---|
1284 | { |
---|
1285 | case 1: speedmap = 1; break; |
---|
1286 | case 2: speedmap = 3; break; |
---|
1287 | case 3: speedmap = 7; break; |
---|
1288 | case 4: speedmap = 15; break; |
---|
1289 | case 5: speedmap = 31; break; |
---|
1290 | case 6: speedmap = 63; break; |
---|
1291 | case 7: speedmap = 127; break; |
---|
1292 | } |
---|
1293 | |
---|
1294 | if(player && player->playback) |
---|
1295 | player->playback->Command(player, PLAYBACK_FASTFORWARD, &speedmap); |
---|
1296 | #endif |
---|
1297 | } |
---|
1298 | |
---|
1299 | void playerslow(int speed) |
---|
1300 | { |
---|
1301 | #ifdef EPLAYER3 |
---|
1302 | int speedmap = 0; |
---|
1303 | |
---|
1304 | if (speed < 1) speed = 1; |
---|
1305 | if (speed > 7) speed = 7; |
---|
1306 | |
---|
1307 | switch(speed) |
---|
1308 | { |
---|
1309 | case 1: speedmap = 1; break; |
---|
1310 | case 2: speedmap = 3; break; |
---|
1311 | case 3: speedmap = 7; break; |
---|
1312 | case 4: speedmap = 15; break; |
---|
1313 | case 5: speedmap = 31; break; |
---|
1314 | case 6: speedmap = 63; break; |
---|
1315 | case 7: speedmap = 127; break; |
---|
1316 | } |
---|
1317 | |
---|
1318 | if(player && player->playback) |
---|
1319 | player->playback->Command(player, PLAYBACK_SLOWMOTION, &speedmap); |
---|
1320 | #endif |
---|
1321 | } |
---|
1322 | |
---|
1323 | void playerfr(int speed) |
---|
1324 | { |
---|
1325 | #ifdef EPLAYER3 |
---|
1326 | int speedmap = 0; |
---|
1327 | |
---|
1328 | if (speed > -1) speed = -1; |
---|
1329 | if (speed < -7) speed = -7; |
---|
1330 | |
---|
1331 | switch(speed) |
---|
1332 | { |
---|
1333 | case -1: speedmap = -5; break; |
---|
1334 | case -2: speedmap = -10; break; |
---|
1335 | case -3: speedmap = -20; break; |
---|
1336 | case -4: speedmap = -40; break; |
---|
1337 | case -5: speedmap = -80; break; |
---|
1338 | case -6: speedmap = -160; break; |
---|
1339 | case -7: speedmap = -320; break; |
---|
1340 | } |
---|
1341 | |
---|
1342 | if(player && player->playback) |
---|
1343 | player->playback->Command(player, PLAYBACK_FASTBACKWARD, &speedmap); |
---|
1344 | #endif |
---|
1345 | } |
---|
1346 | |
---|
1347 | void playerseek(float sec) |
---|
1348 | { |
---|
1349 | #ifdef EPLAYER3 |
---|
1350 | if(player && player->playback) |
---|
1351 | player->playback->Command(player, PLAYBACK_SEEK, (void*)&sec); |
---|
1352 | #endif |
---|
1353 | |
---|
1354 | #ifdef EPLAYER4 |
---|
1355 | gint64 nanos_pts = 0, nanos_len = 0; |
---|
1356 | gint64 pts = 0, len = 0; |
---|
1357 | //GstFormat fmt = GST_FORMAT_TIME; |
---|
1358 | |
---|
1359 | if(pipeline) |
---|
1360 | { |
---|
1361 | len = playergetlength(); |
---|
1362 | nanos_len = len * 1000000000; |
---|
1363 | if(nanos_len < 0) nanos_len = 0; |
---|
1364 | |
---|
1365 | pts = playergetpts(); |
---|
1366 | nanos_pts = pts * 11111; |
---|
1367 | nanos_pts = nanos_pts + (sec * 1000000000); |
---|
1368 | if(nanos_pts < 0) nanos_pts = 0; |
---|
1369 | |
---|
1370 | if(nanos_pts >= nanos_len) |
---|
1371 | playerstop(); |
---|
1372 | else |
---|
1373 | gst_element_seek(pipeline, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, GST_SEEK_TYPE_SET, nanos_pts, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE); |
---|
1374 | } |
---|
1375 | #endif |
---|
1376 | } |
---|
1377 | |
---|
1378 | #ifdef EPLAYER4 |
---|
1379 | audiotype_t gstCheckAudioPad(GstStructure* structure) |
---|
1380 | { |
---|
1381 | if(!structure) |
---|
1382 | return atUnknown; |
---|
1383 | |
---|
1384 | if(gst_structure_has_name(structure, "audio/mpeg")) |
---|
1385 | { |
---|
1386 | gint mpegversion, layer = -1; |
---|
1387 | if(!gst_structure_get_int (structure, "mpegversion", &mpegversion)) |
---|
1388 | return atUnknown; |
---|
1389 | |
---|
1390 | switch(mpegversion) |
---|
1391 | { |
---|
1392 | case 1: |
---|
1393 | { |
---|
1394 | gst_structure_get_int(structure, "layer", &layer); |
---|
1395 | if(layer == 3) |
---|
1396 | return atMP3; |
---|
1397 | else |
---|
1398 | return atMPEG; |
---|
1399 | break; |
---|
1400 | } |
---|
1401 | case 2: |
---|
1402 | return atAAC; |
---|
1403 | case 4: |
---|
1404 | return atAAC; |
---|
1405 | default: |
---|
1406 | return atUnknown; |
---|
1407 | } |
---|
1408 | } |
---|
1409 | |
---|
1410 | else if(gst_structure_has_name(structure, "audio/x-ac3") || gst_structure_has_name(structure, "audio/ac3")) |
---|
1411 | return atAC3; |
---|
1412 | else if(gst_structure_has_name(structure, "audio/x-dts") || gst_structure_has_name(structure, "audio/dts")) |
---|
1413 | return atDTS; |
---|
1414 | #if GST_VERSION_MAJOR < 1 |
---|
1415 | else if(gst_structure_has_name(structure, "audio/x-raw-int")) |
---|
1416 | #else |
---|
1417 | else if(gst_structure_has_name(structure, "audio/x-raw")) |
---|
1418 | #endif |
---|
1419 | return atPCM; |
---|
1420 | |
---|
1421 | return atUnknown; |
---|
1422 | } |
---|
1423 | |
---|
1424 | |
---|
1425 | subtype_t getSubtitleType(GstPad* pad, gchar *g_codec) |
---|
1426 | { |
---|
1427 | g_codec = NULL; |
---|
1428 | subtype_t type = stUnknown; |
---|
1429 | #if GST_VERSION_MAJOR < 1 |
---|
1430 | GstCaps* caps = gst_pad_get_negotiated_caps(pad); |
---|
1431 | #else |
---|
1432 | GstCaps* caps = gst_pad_get_current_caps(pad); |
---|
1433 | #endif |
---|
1434 | if (!caps && !g_codec) |
---|
1435 | { |
---|
1436 | caps = gst_pad_get_allowed_caps(pad); |
---|
1437 | } |
---|
1438 | |
---|
1439 | if (caps && !gst_caps_is_empty(caps)) |
---|
1440 | { |
---|
1441 | GstStructure* str = gst_caps_get_structure(caps, 0); |
---|
1442 | if (str) |
---|
1443 | { |
---|
1444 | const gchar *g_type = gst_structure_get_name(str); |
---|
1445 | // eDebug("getSubtitleType::subtitle probe caps type=%s", g_type ? g_type : "(null)"); |
---|
1446 | if (g_type) |
---|
1447 | { |
---|
1448 | if ( !strcmp(g_type, "video/x-dvd-subpicture") ) |
---|
1449 | type = stVOB; |
---|
1450 | else if ( !strcmp(g_type, "text/x-pango-markup") ) |
---|
1451 | type = stSRT; |
---|
1452 | else if ( !strcmp(g_type, "text/plain") || !strcmp(g_type, "text/x-plain") || !strcmp(g_type, "text/x-raw") ) |
---|
1453 | type = stPlainText; |
---|
1454 | else if ( !strcmp(g_type, "subpicture/x-pgs") ) |
---|
1455 | type = stPGS; |
---|
1456 | else |
---|
1457 | printf("getSubtitleType::unsupported subtitle caps %s (%s)\n", g_type, g_codec ? g_codec : "(null)"); |
---|
1458 | // eDebug("getSubtitleType::unsupported subtitle caps %s (%s)", g_type, g_codec ? g_codec : "(null)"); |
---|
1459 | } |
---|
1460 | } |
---|
1461 | } |
---|
1462 | else if ( g_codec ) |
---|
1463 | { |
---|
1464 | // eDebug("getSubtitleType::subtitle probe codec tag=%s", g_codec); |
---|
1465 | if ( !strcmp(g_codec, "VOB") ) |
---|
1466 | type = stVOB; |
---|
1467 | else if ( !strcmp(g_codec, "SubStation Alpha") || !strcmp(g_codec, "SSA") ) |
---|
1468 | type = stSSA; |
---|
1469 | else if ( !strcmp(g_codec, "ASS") ) |
---|
1470 | type = stASS; |
---|
1471 | else if ( !strcmp(g_codec, "SRT") ) |
---|
1472 | type = stSRT; |
---|
1473 | else if ( !strcmp(g_codec, "UTF-8 plain text") ) |
---|
1474 | type = stPlainText; |
---|
1475 | else |
---|
1476 | printf("getSubtitleType::unsupported subtitle codec %s\n", g_codec); |
---|
1477 | } |
---|
1478 | else |
---|
1479 | printf("getSubtitleType::unidentifiable subtitle stream!\n"); |
---|
1480 | |
---|
1481 | return type; |
---|
1482 | } |
---|
1483 | |
---|
1484 | #endif |
---|
1485 | |
---|
1486 | void playerfreetracklist(char** TrackList) |
---|
1487 | { |
---|
1488 | int i = 0; |
---|
1489 | |
---|
1490 | if(TrackList != NULL) |
---|
1491 | { |
---|
1492 | while(TrackList[i] != NULL) |
---|
1493 | { |
---|
1494 | free(TrackList[i]); |
---|
1495 | free(TrackList[i + 1]); |
---|
1496 | i += 2; |
---|
1497 | } |
---|
1498 | } |
---|
1499 | } |
---|
1500 | |
---|
1501 | char** playergettracklist(int type) |
---|
1502 | { |
---|
1503 | char ** TrackList = NULL; |
---|
1504 | #ifdef EPLAYER3 |
---|
1505 | if(player && player->manager) |
---|
1506 | { |
---|
1507 | switch(type) |
---|
1508 | { |
---|
1509 | case 1: |
---|
1510 | if(player->manager->audio) |
---|
1511 | { |
---|
1512 | player->manager->audio->Command(player, MANAGER_LIST, &TrackList); |
---|
1513 | debug(150, "Audio Track List"); |
---|
1514 | } |
---|
1515 | break; |
---|
1516 | case 2: |
---|
1517 | if(player->manager->subtitle) |
---|
1518 | { |
---|
1519 | player->manager->subtitle->Command(player, MANAGER_LIST, &TrackList); |
---|
1520 | debug(150, "Subtitle Track List"); |
---|
1521 | } |
---|
1522 | break; |
---|
1523 | default: |
---|
1524 | if(player->manager->video) |
---|
1525 | { |
---|
1526 | player->manager->video->Command(player, MANAGER_LIST, &TrackList); |
---|
1527 | debug(150, "Video Track List"); |
---|
1528 | } |
---|
1529 | } |
---|
1530 | |
---|
1531 | int i = 0; |
---|
1532 | if(TrackList != NULL) |
---|
1533 | { |
---|
1534 | while(TrackList[i] != NULL) |
---|
1535 | { |
---|
1536 | string_newline(TrackList[i]); |
---|
1537 | i += 2; |
---|
1538 | } |
---|
1539 | |
---|
1540 | debug(150, "Track List"); |
---|
1541 | i = 0; |
---|
1542 | while(TrackList[i] != NULL) |
---|
1543 | { |
---|
1544 | debug(150, "%s - %s", TrackList[i], TrackList[i + 1]); |
---|
1545 | i += 2; |
---|
1546 | } |
---|
1547 | } |
---|
1548 | } |
---|
1549 | #endif |
---|
1550 | |
---|
1551 | //////////////////////////////NEUER CODE ////////////////////////////// |
---|
1552 | #ifdef EPLAYER4 |
---|
1553 | TrackList = calloc(1, sizeof(char *) * ((100 * 2) + 1)); |
---|
1554 | |
---|
1555 | if(pipeline != NULL) |
---|
1556 | { |
---|
1557 | gint i, n_video = 0, n_audio = 0, n_text = 0; |
---|
1558 | |
---|
1559 | g_object_get(pipeline, "n-video", &n_video, NULL); |
---|
1560 | g_object_get(pipeline, "n-audio", &n_audio, NULL); |
---|
1561 | g_object_get(pipeline, "n-text", &n_text, NULL); |
---|
1562 | |
---|
1563 | switch(type) |
---|
1564 | { |
---|
1565 | case 1: |
---|
1566 | for(i = 0; i < n_audio; i++) |
---|
1567 | { |
---|
1568 | GstTagList *tags = NULL; |
---|
1569 | gchar *g_codec = NULL, *g_lang = NULL; |
---|
1570 | char* tmpstr = NULL; |
---|
1571 | GstPad* pad = 0; |
---|
1572 | |
---|
1573 | g_signal_emit_by_name (pipeline, "get-audio-pad", i, &pad); |
---|
1574 | #if GST_VERSION_MAJOR < 1 |
---|
1575 | GstCaps* caps = gst_pad_get_negotiated_caps(pad); |
---|
1576 | #else |
---|
1577 | GstCaps* caps = gst_pad_get_current_caps(pad); |
---|
1578 | #endif |
---|
1579 | if(!caps) |
---|
1580 | continue; |
---|
1581 | |
---|
1582 | GstStructure* str = gst_caps_get_structure(caps, 0); |
---|
1583 | const gchar *g_type = gst_structure_get_name(str); |
---|
1584 | |
---|
1585 | g_signal_emit_by_name(pipeline, "get-audio-tags", i, &tags); |
---|
1586 | |
---|
1587 | #if GST_VERSION_MAJOR < 1 |
---|
1588 | if(tags && gst_is_tag_list(tags)) |
---|
1589 | #else |
---|
1590 | if(tags && GST_IS_TAG_LIST(tags)) |
---|
1591 | #endif |
---|
1592 | { |
---|
1593 | if(gst_tag_list_get_string(tags, GST_TAG_AUDIO_CODEC, &g_codec)) |
---|
1594 | { |
---|
1595 | printf("Audio Codec: %s\n", g_codec); |
---|
1596 | |
---|
1597 | tmpstr = ostrcat(oitoa(i), ": ", 1, 0); |
---|
1598 | tmpstr = ostrcat(tmpstr, g_codec, 1, 0); |
---|
1599 | if(g_codec != NULL && g_type != NULL) |
---|
1600 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
1601 | tmpstr = ostrcat(tmpstr, (gchar*)g_type, 1, 0); |
---|
1602 | if(g_codec != NULL && g_type != NULL) |
---|
1603 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
1604 | |
---|
1605 | printf("Tracklist tmpstr: %s\n", tmpstr); |
---|
1606 | |
---|
1607 | TrackList[i * 2] = ostrcat(tmpstr, NULL, 0, 0); |
---|
1608 | g_free(tmpstr); tmpstr = NULL; |
---|
1609 | g_free(g_codec); g_codec = NULL; |
---|
1610 | } |
---|
1611 | if(gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang)) |
---|
1612 | { |
---|
1613 | printf("Audio Lang: %s\n", g_lang); |
---|
1614 | TrackList[(i * 2) + 1] = ostrcat(g_lang, NULL, 0, 0); |
---|
1615 | g_free(g_lang); g_lang = NULL; |
---|
1616 | } |
---|
1617 | gst_tag_list_free(tags); |
---|
1618 | } |
---|
1619 | else |
---|
1620 | { |
---|
1621 | printf("Audio Codec: %s\n", g_codec); |
---|
1622 | |
---|
1623 | tmpstr = ostrcat(oitoa(i), ": ", 1, 0); |
---|
1624 | tmpstr = ostrcat(tmpstr, g_codec, 1, 0); |
---|
1625 | if(g_codec != NULL && g_type != NULL) |
---|
1626 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
1627 | tmpstr = ostrcat(tmpstr, (gchar*)g_type, 1, 0); |
---|
1628 | if(g_codec != NULL && g_type != NULL) |
---|
1629 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
1630 | |
---|
1631 | printf("Tracklist tmpstr: %s\n", tmpstr); |
---|
1632 | TrackList[i * 2] = ostrcat(tmpstr, NULL, 0, 0); |
---|
1633 | |
---|
1634 | g_free(tmpstr); tmpstr = NULL; |
---|
1635 | g_free(g_codec); g_codec = NULL; |
---|
1636 | } |
---|
1637 | } |
---|
1638 | break; |
---|
1639 | case 2: |
---|
1640 | for(i = 0; i < n_text; i++) |
---|
1641 | { |
---|
1642 | GstTagList *tags = NULL; |
---|
1643 | gchar *g_codec = NULL, *g_lang = NULL; |
---|
1644 | GstPad* pad = 0; |
---|
1645 | char* tmpstr = NULL; |
---|
1646 | |
---|
1647 | g_signal_emit_by_name (pipeline, "get-text-pad", i, &pad); |
---|
1648 | printf("SubTitle Type: %d\n", getSubtitleType(pad, g_codec)); |
---|
1649 | |
---|
1650 | #if GST_VERSION_MAJOR < 1 |
---|
1651 | GstCaps* caps = gst_pad_get_negotiated_caps(pad); |
---|
1652 | #else |
---|
1653 | GstCaps* caps = gst_pad_get_current_caps(pad); |
---|
1654 | #endif |
---|
1655 | if (!caps && !g_codec) |
---|
1656 | { |
---|
1657 | caps = gst_pad_get_allowed_caps(pad); |
---|
1658 | } |
---|
1659 | |
---|
1660 | GstStructure* str = gst_caps_get_structure(caps, 0); |
---|
1661 | const gchar *g_type = gst_structure_get_name(str); |
---|
1662 | |
---|
1663 | g_signal_emit_by_name(pipeline, "get-text-tags", i, &tags); |
---|
1664 | |
---|
1665 | #if GST_VERSION_MAJOR < 1 |
---|
1666 | if (tags && gst_is_tag_list(tags)) |
---|
1667 | #else |
---|
1668 | if (tags && GST_IS_TAG_LIST(tags)) |
---|
1669 | #endif |
---|
1670 | { |
---|
1671 | if(gst_tag_list_get_string(tags, GST_TAG_SUBTITLE_CODEC, &g_codec)); |
---|
1672 | { |
---|
1673 | printf("SubTitle Codec: %s\n", g_codec); |
---|
1674 | tmpstr = ostrcat(oitoa(i), ": ", 1, 0); |
---|
1675 | tmpstr = ostrcat(tmpstr, g_codec, 1, 0); |
---|
1676 | if(g_codec != NULL && g_type != NULL) |
---|
1677 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
1678 | tmpstr = ostrcat(tmpstr, (gchar*)g_type, 1, 0); |
---|
1679 | if(g_codec != NULL && g_type != NULL) |
---|
1680 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
1681 | |
---|
1682 | printf("Tracklist tmpstr: %s\n", tmpstr); |
---|
1683 | TrackList[i * 2] = ostrcat(tmpstr, NULL, 0, 0); |
---|
1684 | g_free(g_codec); g_codec = NULL; |
---|
1685 | } |
---|
1686 | if(gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang)) |
---|
1687 | { |
---|
1688 | printf("SubTitle Lang: %s\n", g_lang); |
---|
1689 | TrackList[(i * 2) + 1] = ostrcat(g_lang, NULL, 0, 0); |
---|
1690 | g_free(g_lang); g_lang = NULL; |
---|
1691 | } |
---|
1692 | gst_tag_list_free(tags); |
---|
1693 | } |
---|
1694 | else |
---|
1695 | { |
---|
1696 | printf("SubTitle Codec: %s\n", g_codec); |
---|
1697 | |
---|
1698 | tmpstr = ostrcat(oitoa(i), ": ", 1, 0); |
---|
1699 | tmpstr = ostrcat(tmpstr, g_codec, 1, 0); |
---|
1700 | if(g_codec != NULL && g_type != NULL) |
---|
1701 | tmpstr = ostrcat(tmpstr, " (", 1, 0); |
---|
1702 | tmpstr = ostrcat(tmpstr, (gchar*)g_type, 1, 0); |
---|
1703 | if(g_codec != NULL && g_type != NULL) |
---|
1704 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
1705 | |
---|
1706 | printf("Tracklist tmpstr: %s\n", tmpstr); |
---|
1707 | TrackList[i * 2] = ostrcat(tmpstr, NULL, 0, 0); |
---|
1708 | |
---|
1709 | g_free(tmpstr); tmpstr = NULL; |
---|
1710 | g_free(g_codec); g_codec = NULL; |
---|
1711 | } |
---|
1712 | } |
---|
1713 | break; |
---|
1714 | default: |
---|
1715 | for(i = 0; i < n_video; i++) |
---|
1716 | { |
---|
1717 | GstTagList *tags = NULL; |
---|
1718 | gchar *g_codec = NULL, *g_lang = NULL; |
---|
1719 | |
---|
1720 | g_signal_emit_by_name(pipeline, "get-video-tags", i, &tags); |
---|
1721 | |
---|
1722 | #if GST_VERSION_MAJOR < 1 |
---|
1723 | if (tags && gst_is_tag_list(tags)) |
---|
1724 | #else |
---|
1725 | if (tags && GST_IS_TAG_LIST(tags)) |
---|
1726 | #endif |
---|
1727 | { |
---|
1728 | if(gst_tag_list_get_string(tags, GST_TAG_VIDEO_CODEC, &g_codec)); |
---|
1729 | { |
---|
1730 | printf("Video Codec: %s\n", g_codec); |
---|
1731 | TrackList[i * 2] = ostrcat(g_codec, NULL, 0, 0); |
---|
1732 | g_free(g_codec); g_codec = NULL; |
---|
1733 | } |
---|
1734 | if(gst_tag_list_get_string(tags, GST_TAG_LANGUAGE_CODE, &g_lang)) |
---|
1735 | { |
---|
1736 | printf("Video Lang: %s\n", g_lang); |
---|
1737 | TrackList[(i * 2) + 1] = ostrcat(g_lang, NULL, 0, 0); |
---|
1738 | g_free(g_lang); g_lang = NULL; |
---|
1739 | } |
---|
1740 | gst_tag_list_free(tags); |
---|
1741 | } |
---|
1742 | } |
---|
1743 | } |
---|
1744 | } |
---|
1745 | #endif |
---|
1746 | //////////////////////////////NEUER CODE ////////////////////////////// |
---|
1747 | |
---|
1748 | return TrackList; |
---|
1749 | } |
---|
1750 | |
---|
1751 | //*CurTrackEncoding and *CurTrackName be freed |
---|
1752 | void playergetcurtrac(int type, int *CurTrackId, char** CurTrackEncoding, char** CurTrackName) |
---|
1753 | { |
---|
1754 | #ifdef EPLAYER3 |
---|
1755 | if(player && player->manager) |
---|
1756 | { |
---|
1757 | switch(type) |
---|
1758 | { |
---|
1759 | case 1: |
---|
1760 | if(player->manager->audio) |
---|
1761 | { |
---|
1762 | player->manager->audio->Command(player, MANAGER_GET, CurTrackId); |
---|
1763 | player->manager->audio->Command(player, MANAGER_GETENCODING, CurTrackEncoding); |
---|
1764 | player->manager->audio->Command(player, MANAGER_GETNAME, CurTrackName); |
---|
1765 | } |
---|
1766 | break; |
---|
1767 | case 2: |
---|
1768 | if(player->manager->subtitle) |
---|
1769 | { |
---|
1770 | player->manager->subtitle->Command(player, MANAGER_GET, CurTrackId); |
---|
1771 | player->manager->subtitle->Command(player, MANAGER_GETENCODING, CurTrackEncoding); |
---|
1772 | player->manager->subtitle->Command(player, MANAGER_GETNAME, CurTrackName); |
---|
1773 | } |
---|
1774 | break; |
---|
1775 | default: |
---|
1776 | if(player->manager->video) |
---|
1777 | { |
---|
1778 | player->manager->video->Command(player, MANAGER_GET, CurTrackId); |
---|
1779 | player->manager->video->Command(player, MANAGER_GETENCODING, CurTrackEncoding); |
---|
1780 | player->manager->video->Command(player, MANAGER_GETNAME, CurTrackName); |
---|
1781 | } |
---|
1782 | } |
---|
1783 | |
---|
1784 | if(CurTrackId != NULL) |
---|
1785 | debug(150, "Current Track ID: %d", *CurTrackId); |
---|
1786 | if(*CurTrackEncoding != NULL) |
---|
1787 | debug(150, "Current Track Enc: %s", *CurTrackEncoding); |
---|
1788 | if(*CurTrackName != NULL) |
---|
1789 | debug(150, "Current Track Name: %s", *CurTrackName); |
---|
1790 | } |
---|
1791 | #endif |
---|
1792 | |
---|
1793 | #ifdef EPLAYER4 |
---|
1794 | if(pipeline != NULL) |
---|
1795 | { |
---|
1796 | switch(type) |
---|
1797 | { |
---|
1798 | case 1: |
---|
1799 | g_object_get(G_OBJECT(pipeline), "current-audio", CurTrackId, NULL); |
---|
1800 | break; |
---|
1801 | } |
---|
1802 | if(CurTrackId != NULL) { |
---|
1803 | debug(150, "Current Track ID: %d", *CurTrackId); |
---|
1804 | } |
---|
1805 | } |
---|
1806 | #endif |
---|
1807 | } |
---|
1808 | |
---|
1809 | unsigned long long playergetpts() |
---|
1810 | { |
---|
1811 | unsigned long long pts = 0; |
---|
1812 | unsigned long long sec = 0; |
---|
1813 | |
---|
1814 | #ifdef EPLAYER3 |
---|
1815 | if(player && player->playback) |
---|
1816 | { |
---|
1817 | player->playback->Command(player, PLAYBACK_PTS, &pts); |
---|
1818 | sec = pts / 90000; |
---|
1819 | debug(150, "Pts = %02d:%02d:%02d (%llu.0000 sec)", (int)((sec / 60) / 60) % 60, (int)(sec / 60) % 60, (int)sec % 60, sec); |
---|
1820 | } |
---|
1821 | #endif |
---|
1822 | |
---|
1823 | #ifdef EPLAYER4 |
---|
1824 | GstFormat fmt = GST_FORMAT_TIME; //Returns time in nanosecs |
---|
1825 | |
---|
1826 | /* |
---|
1827 | if(pipeline) |
---|
1828 | { |
---|
1829 | gst_element_query_position(pipeline, &fmt, (gint64*)&pts); |
---|
1830 | sec = pts / 1000000000; |
---|
1831 | pts = sec * 90000; |
---|
1832 | debug(150, "Pts = %02d:%02d:%02d (%llu.0000 sec)", (int)((sec / 60) / 60) % 60, (int)(sec / 60) % 60, (int)sec % 60, sec); |
---|
1833 | } |
---|
1834 | */ |
---|
1835 | |
---|
1836 | if(pipeline) |
---|
1837 | { |
---|
1838 | gint64 pos; |
---|
1839 | GstElement *sink; |
---|
1840 | pts = 0; |
---|
1841 | |
---|
1842 | g_object_get(G_OBJECT (pipeline), "audio-sink", &sink, NULL); |
---|
1843 | |
---|
1844 | if(!sink) g_object_get (G_OBJECT (pipeline), "video-sink", &sink, NULL); |
---|
1845 | if(!sink) return 0; |
---|
1846 | |
---|
1847 | gchar *name = gst_element_get_name(sink); |
---|
1848 | gboolean use_get_decoder_time = ostrstr(name, "dvbaudiosink") || ostrstr(name, "dvbvideosink"); |
---|
1849 | g_free(name); |
---|
1850 | |
---|
1851 | if(use_get_decoder_time) g_signal_emit_by_name(sink, "get-decoder-time", &pos); |
---|
1852 | |
---|
1853 | gst_object_unref(sink); |
---|
1854 | |
---|
1855 | if(!use_get_decoder_time && !gst_element_query_position(pipeline, &fmt, &pos)) |
---|
1856 | return 0; |
---|
1857 | |
---|
1858 | /* pos is in nanoseconds. we have 90 000 pts per second. */ |
---|
1859 | pts = pos / 11111; |
---|
1860 | pts = pts - m_gst_startpts; |
---|
1861 | sec = pts / 90000; |
---|
1862 | debug(150, "StartPTS = %llu Pts = %02d:%02d:%02d (%llu.0000 sec)", m_gst_startpts, (int)((sec / 60) / 60) % 60, (int)(sec / 60) % 60, (int)sec % 60, sec); |
---|
1863 | } |
---|
1864 | #endif |
---|
1865 | |
---|
1866 | if(pts < 0) pts = 0; |
---|
1867 | return pts; |
---|
1868 | } |
---|
1869 | |
---|
1870 | double playergetlength() |
---|
1871 | { |
---|
1872 | double length = 0; |
---|
1873 | |
---|
1874 | #ifdef EPLAYER3 |
---|
1875 | if(player && player->playback) |
---|
1876 | { |
---|
1877 | player->playback->Command(player, PLAYBACK_LENGTH, &length); |
---|
1878 | if(length < 0) length = 0; |
---|
1879 | debug(150, "Length = %02d:%02d:%02d (%.4f sec)", (int)((length / 60) / 60) % 60, (int)(length / 60) % 60, (int)length % 60, length); |
---|
1880 | } |
---|
1881 | #endif |
---|
1882 | |
---|
1883 | #ifdef EPLAYER4 |
---|
1884 | GstFormat fmt = GST_FORMAT_TIME; //Returns time in nanosecs |
---|
1885 | gint64 len; |
---|
1886 | |
---|
1887 | if(pipeline) |
---|
1888 | { |
---|
1889 | gst_element_query_duration(pipeline, &fmt, &len); |
---|
1890 | length = len / 1000000000; |
---|
1891 | if(length < 0) length = 0; |
---|
1892 | debug(150, "Length = %02d:%02d:%02d (%.4f sec)", (int)((length / 60) / 60) % 60, (int)(length / 60) % 60, (int)length % 60, length); |
---|
1893 | } |
---|
1894 | #endif |
---|
1895 | |
---|
1896 | return length; |
---|
1897 | } |
---|
1898 | |
---|
1899 | char* playergetinfo(char* tag) |
---|
1900 | { |
---|
1901 | char* ret = NULL; |
---|
1902 | |
---|
1903 | #ifdef EPLAYER3 |
---|
1904 | char *tags[] = {"Title", "Artist", "Album", "Year", "Genre", "Comment", "Track", "Copyright", "TestLibEplayer", NULL}; |
---|
1905 | int i = 0; |
---|
1906 | |
---|
1907 | if(player && player->playback) |
---|
1908 | { |
---|
1909 | while(tags[i] != NULL) |
---|
1910 | { |
---|
1911 | ret = tags[i]; |
---|
1912 | if(ostrcmp(tag, ret) == 0) |
---|
1913 | { |
---|
1914 | player->playback->Command(player, PLAYBACK_INFO, &ret); |
---|
1915 | break; |
---|
1916 | } |
---|
1917 | |
---|
1918 | i++; |
---|
1919 | } |
---|
1920 | } |
---|
1921 | #endif |
---|
1922 | return ret; |
---|
1923 | } |
---|
1924 | |
---|
1925 | void playerchangeaudiotrack(int num) |
---|
1926 | { |
---|
1927 | #ifdef EPLAYER3 |
---|
1928 | if(player && player->playback) |
---|
1929 | player->playback->Command(player, PLAYBACK_SWITCH_AUDIO, (void*)&num); |
---|
1930 | #endif |
---|
1931 | |
---|
1932 | #ifdef EPLAYER4 |
---|
1933 | if(pipeline != NULL) |
---|
1934 | g_object_set(G_OBJECT(pipeline), "current-audio", num, NULL); |
---|
1935 | #endif |
---|
1936 | } |
---|
1937 | |
---|
1938 | void playerchangesubtitletrack(int num) |
---|
1939 | { |
---|
1940 | #ifdef EPLAYER3 |
---|
1941 | if(player && player->playback) |
---|
1942 | player->playback->Command(player, PLAYBACK_SWITCH_SUBTITLE, (void*)&num); |
---|
1943 | #endif |
---|
1944 | } |
---|
1945 | |
---|
1946 | void playerstopsubtitletrack() |
---|
1947 | { |
---|
1948 | #ifdef EPLAYER3 |
---|
1949 | if(player && player->output && player->output->subtitle) |
---|
1950 | player->output->subtitle->Command(player, (OutputCmd_t)OUTPUT_STOP, NULL); |
---|
1951 | if(player && player->container && player->container->assContainer) |
---|
1952 | { |
---|
1953 | player->container->assContainer->Command(player, CONTAINER_STOP, NULL); |
---|
1954 | player->container->assContainer->Command(player, CONTAINER_INIT, NULL); |
---|
1955 | } |
---|
1956 | if(player && player->manager && player->manager->subtitle) |
---|
1957 | { |
---|
1958 | int onlycurrent = 1; |
---|
1959 | player->manager->subtitle->Command(player, MANAGER_DEL, (void*)&onlycurrent); |
---|
1960 | } |
---|
1961 | #endif |
---|
1962 | } |
---|
1963 | |
---|
1964 | int playerjumpts(struct service* servicenode, int sekunden, int *startpts, off64_t *poslastpts, off64_t *bitrate, int vpid, int tssize) |
---|
1965 | { |
---|
1966 | int adaptation = 0; |
---|
1967 | int payload = 0; |
---|
1968 | int pes = 0; |
---|
1969 | int tspid = 0; |
---|
1970 | |
---|
1971 | off64_t pts = 0; |
---|
1972 | uint64_t aktpts = 0; |
---|
1973 | long long unsigned int lenpts = 0; |
---|
1974 | long long unsigned int startpts1 = 0; |
---|
1975 | long long unsigned int endpts = 0; |
---|
1976 | long long unsigned int aktbitrate = 0; |
---|
1977 | off64_t ziehlpts = 0; |
---|
1978 | |
---|
1979 | off64_t curpos = 0; |
---|
1980 | off64_t newpos = 0; |
---|
1981 | off64_t jump = 0; |
---|
1982 | |
---|
1983 | int kleiner = 0; |
---|
1984 | int groesser = 0; |
---|
1985 | int gleich = 0; |
---|
1986 | int len = 0; |
---|
1987 | int i = 0; |
---|
1988 | int ret = 0; |
---|
1989 | |
---|
1990 | if(servicenode == NULL) return -1; |
---|
1991 | |
---|
1992 | int buflen = tssize * 15000; |
---|
1993 | char *buf = malloc(buflen); |
---|
1994 | if(buf == NULL) |
---|
1995 | return -1; |
---|
1996 | |
---|
1997 | curpos = lseek64(servicenode->recsrcfd, 0, SEEK_CUR); |
---|
1998 | int dupfd = open(servicenode->recname, O_RDONLY | O_LARGEFILE); |
---|
1999 | newpos = lseek64(dupfd, curpos, SEEK_SET); |
---|
2000 | |
---|
2001 | if (*startpts == 0) |
---|
2002 | { |
---|
2003 | if(videogetpts(status.aktservice->videodev, &aktpts) == 0) |
---|
2004 | { |
---|
2005 | ziehlpts = (aktpts / 90000) + sekunden; |
---|
2006 | } |
---|
2007 | else |
---|
2008 | return 1; |
---|
2009 | } |
---|
2010 | else |
---|
2011 | { |
---|
2012 | ziehlpts = *startpts + sekunden; |
---|
2013 | } |
---|
2014 | *startpts = ziehlpts; |
---|
2015 | |
---|
2016 | if(*bitrate == 0) |
---|
2017 | { |
---|
2018 | lenpts = servicenode->lenpts; |
---|
2019 | startpts1 = servicenode->startpts; |
---|
2020 | endpts = servicenode->endpts; |
---|
2021 | aktbitrate = servicenode->bitrate; |
---|
2022 | ret = gettsinfo(dupfd, &lenpts, &startpts1, &endpts, &aktbitrate, servicenode->tssize); |
---|
2023 | if(ret != 0) |
---|
2024 | { |
---|
2025 | err("can't read ts info"); |
---|
2026 | } |
---|
2027 | else |
---|
2028 | *bitrate = aktbitrate; |
---|
2029 | newpos = lseek64(dupfd, curpos, SEEK_SET); |
---|
2030 | } |
---|
2031 | else |
---|
2032 | aktbitrate = *bitrate; |
---|
2033 | |
---|
2034 | if(*poslastpts == 0) |
---|
2035 | *poslastpts = curpos; |
---|
2036 | |
---|
2037 | if(sekunden > 0) |
---|
2038 | { |
---|
2039 | err("not implemented"); |
---|
2040 | return 1; |
---|
2041 | } |
---|
2042 | else if(sekunden < 0) |
---|
2043 | { |
---|
2044 | sekunden = sekunden * -1; |
---|
2045 | if(aktbitrate != 0) |
---|
2046 | { |
---|
2047 | jump = (aktbitrate / 8) * sekunden; |
---|
2048 | jump = jump + (curpos - *poslastpts); |
---|
2049 | jump = jump + (jump % servicenode->tssize); |
---|
2050 | newpos = lseek64(dupfd, -jump, SEEK_CUR); |
---|
2051 | } |
---|
2052 | else |
---|
2053 | newpos = lseek64(dupfd, - buflen, SEEK_CUR); |
---|
2054 | if(newpos < 0) |
---|
2055 | newpos = lseek64(dupfd, tssize, SEEK_SET); |
---|
2056 | } |
---|
2057 | len = read(dupfd, buf, buflen); |
---|
2058 | for(i = 0; i < len; i = i + 1) |
---|
2059 | { |
---|
2060 | if (buf[i] == 0x47 && buf[i+tssize] == 0x47) |
---|
2061 | { |
---|
2062 | newpos = lseek64(dupfd, newpos + i, SEEK_SET); |
---|
2063 | break; |
---|
2064 | } |
---|
2065 | } |
---|
2066 | if(i >= len) |
---|
2067 | { |
---|
2068 | newpos = lseek64(dupfd, curpos, SEEK_SET); |
---|
2069 | return 1; |
---|
2070 | } |
---|
2071 | while(1) |
---|
2072 | { |
---|
2073 | len = read(dupfd, buf, buflen); |
---|
2074 | |
---|
2075 | if(len > 0) |
---|
2076 | { |
---|
2077 | for(i = 0; i <= len-tssize; i = i + tssize) |
---|
2078 | { |
---|
2079 | payload = 0; |
---|
2080 | |
---|
2081 | tspid = (buf[i+1] & 0x1F) << 8; |
---|
2082 | tspid = tspid + (buf[i+2] & 0xFF); |
---|
2083 | pes = buf[i+1] & 0x40; |
---|
2084 | |
---|
2085 | if(tspid == vpid) |
---|
2086 | { |
---|
2087 | adaptation = buf[i+3] & 0x30; |
---|
2088 | if(adaptation == 16) |
---|
2089 | { |
---|
2090 | payload = 4; |
---|
2091 | } |
---|
2092 | if(adaptation == 32) |
---|
2093 | { |
---|
2094 | //printf("adaptation field only\n"); |
---|
2095 | } |
---|
2096 | if(adaptation == 48) |
---|
2097 | { |
---|
2098 | payload = buf[i+4] & 0xFF; |
---|
2099 | payload = payload + 5; |
---|
2100 | } |
---|
2101 | if(payload != 0) |
---|
2102 | { |
---|
2103 | if(pes == 64) |
---|
2104 | { |
---|
2105 | if(buf[i+payload+7] & 0x80) //PTS |
---|
2106 | { |
---|
2107 | pts = ((unsigned long long)(buf[i+payload+9] & 0xE)) << 29; |
---|
2108 | pts |= ((unsigned long long)(buf[i+payload+10] & 0xFF)) << 22; |
---|
2109 | pts |= ((unsigned long long)(buf[i+payload+11] & 0xFE)) << 14; |
---|
2110 | pts |= ((unsigned long long)(buf[i+payload+12] & 0xFF)) << 7; |
---|
2111 | pts |= ((unsigned long long)(buf[i+payload+13] & 0xFE)) >> 1; |
---|
2112 | |
---|
2113 | if(pts / 90000 == ziehlpts) |
---|
2114 | { |
---|
2115 | gleich = newpos + i; |
---|
2116 | break; |
---|
2117 | } |
---|
2118 | else if(pts / 90000 > ziehlpts) |
---|
2119 | { |
---|
2120 | groesser = newpos + i; |
---|
2121 | break; |
---|
2122 | } |
---|
2123 | else |
---|
2124 | { |
---|
2125 | kleiner = newpos + i; |
---|
2126 | } |
---|
2127 | } |
---|
2128 | } |
---|
2129 | } |
---|
2130 | } |
---|
2131 | } |
---|
2132 | if(gleich != 0) |
---|
2133 | { |
---|
2134 | close(dupfd); |
---|
2135 | free(buf);buf = NULL; |
---|
2136 | *poslastpts = lseek64(servicenode->recsrcfd, gleich, SEEK_SET); |
---|
2137 | return 0; |
---|
2138 | } |
---|
2139 | else if(groesser != 0 && kleiner != 0) |
---|
2140 | { |
---|
2141 | close(dupfd); |
---|
2142 | free(buf);buf = NULL; |
---|
2143 | *poslastpts = lseek64(servicenode->recsrcfd, kleiner, SEEK_SET); |
---|
2144 | return 0; |
---|
2145 | } |
---|
2146 | else if(groesser != 0) |
---|
2147 | { |
---|
2148 | if((newpos - buflen) < 0) |
---|
2149 | { |
---|
2150 | close(dupfd); |
---|
2151 | free(buf);buf = NULL; |
---|
2152 | *poslastpts = 0; |
---|
2153 | return -1 ; |
---|
2154 | } |
---|
2155 | else |
---|
2156 | { |
---|
2157 | newpos = lseek64(dupfd, -(buflen * 2), SEEK_CUR); |
---|
2158 | } |
---|
2159 | } |
---|
2160 | } |
---|
2161 | else |
---|
2162 | { |
---|
2163 | if(kleiner == 0) |
---|
2164 | { |
---|
2165 | close(dupfd); |
---|
2166 | free(buf);buf = NULL; |
---|
2167 | newpos = lseek64(servicenode->recsrcfd, curpos, SEEK_SET); |
---|
2168 | *poslastpts = 0; |
---|
2169 | return -1; |
---|
2170 | } |
---|
2171 | else |
---|
2172 | { |
---|
2173 | close(dupfd); |
---|
2174 | free(buf);buf = NULL; |
---|
2175 | *poslastpts = lseek64(servicenode->recsrcfd, kleiner, SEEK_SET); |
---|
2176 | return 0; |
---|
2177 | } |
---|
2178 | } |
---|
2179 | } |
---|
2180 | } |
---|
2181 | |
---|
2182 | //praez = 1 .... sekunden |
---|
2183 | // = 2 .... zehntel |
---|
2184 | // = 3 .... hundertstel |
---|
2185 | // = 4 .... volle Uebereinstimmung |
---|
2186 | // |
---|
2187 | //type = 0 .... alle |
---|
2188 | // = 1 .... nur PCR |
---|
2189 | // = 2 .... nur Video |
---|
2190 | // = 3 .... nur Audio |
---|
2191 | // |
---|
2192 | //flag = 0 --> play ts |
---|
2193 | //flag = 1 --> timeshift |
---|
2194 | //flag = 2 --> timeshift, not in play mode (only recording) |
---|
2195 | //flag = 9 --> dataset mode |
---|
2196 | // |
---|
2197 | off64_t playergetptspos(unsigned long long fpts, off64_t pos, int dir, int praez, int type, int flag, char* dsn) |
---|
2198 | { |
---|
2199 | unsigned long long pts; |
---|
2200 | int ret = 0, dupfd = -1, left = 0, tssize = 0, recbsize = 0; |
---|
2201 | unsigned char* buf = NULL; |
---|
2202 | unsigned char *payload; |
---|
2203 | int pid = 0, pusi = 0; |
---|
2204 | unsigned char* packet; |
---|
2205 | struct service* snode; |
---|
2206 | |
---|
2207 | if(type > 3) |
---|
2208 | { |
---|
2209 | printf("type %i nicht unterstützt\n", type); |
---|
2210 | return -1; |
---|
2211 | } |
---|
2212 | |
---|
2213 | if(flag == 2) |
---|
2214 | snode = getservice(RECORDTIMESHIFT, 0); |
---|
2215 | else if(flag != 9) |
---|
2216 | snode = getservice(RECORDPLAY, 0); |
---|
2217 | |
---|
2218 | if(flag == 9) |
---|
2219 | { |
---|
2220 | tssize = 188; |
---|
2221 | recbsize = tssize * 1024 * 10; |
---|
2222 | dupfd = open(dsn, O_RDONLY | O_LARGEFILE ); |
---|
2223 | } |
---|
2224 | else |
---|
2225 | { |
---|
2226 | tssize = snode->tssize; |
---|
2227 | recbsize = snode->tssize * 1024 * 10; |
---|
2228 | dupfd = open(snode->recname, O_RDONLY | O_LARGEFILE); |
---|
2229 | } |
---|
2230 | |
---|
2231 | if(dupfd < 0) |
---|
2232 | { |
---|
2233 | err("copy source fd not ok"); |
---|
2234 | return -1; |
---|
2235 | } |
---|
2236 | |
---|
2237 | buf = malloc(recbsize); |
---|
2238 | if(buf == NULL) |
---|
2239 | { |
---|
2240 | err("no mem"); |
---|
2241 | return -1; |
---|
2242 | } |
---|
2243 | packet = buf; |
---|
2244 | if(dir > 0) |
---|
2245 | pos = lseek64(dupfd, pos, SEEK_SET); |
---|
2246 | else |
---|
2247 | pos = lseek64(dupfd, pos - recbsize, SEEK_SET); |
---|
2248 | |
---|
2249 | ret = read(dupfd, buf, recbsize); |
---|
2250 | close(dupfd); |
---|
2251 | left = 0; |
---|
2252 | |
---|
2253 | if(buf[0] != 0x47) |
---|
2254 | { |
---|
2255 | while(left < tssize) |
---|
2256 | { |
---|
2257 | if(buf[left] == 0x47) break; |
---|
2258 | left++; |
---|
2259 | } |
---|
2260 | if(left >= tssize) |
---|
2261 | { |
---|
2262 | free(buf); |
---|
2263 | return -1; |
---|
2264 | } |
---|
2265 | } |
---|
2266 | pts = 0; |
---|
2267 | while(left <= recbsize - tssize) |
---|
2268 | { |
---|
2269 | if(pts != 0) |
---|
2270 | { |
---|
2271 | switch( praez ) |
---|
2272 | { |
---|
2273 | case 1 : if(fpts / 90000 != pts / 90000) |
---|
2274 | pts = 0; |
---|
2275 | break; |
---|
2276 | case 2 : if(fpts / 9000 != pts / 9000) |
---|
2277 | pts = 0; |
---|
2278 | break; |
---|
2279 | case 3 : if(fpts / 900 != pts / 900) |
---|
2280 | pts = 0; |
---|
2281 | break; |
---|
2282 | case 4 : if(fpts != pts ) |
---|
2283 | pts = 0; |
---|
2284 | break; |
---|
2285 | default : free(buf); return -1; break; |
---|
2286 | } |
---|
2287 | if(pts != 0) |
---|
2288 | { |
---|
2289 | pos = pos + left - tssize; |
---|
2290 | free(buf); |
---|
2291 | return pos; |
---|
2292 | } |
---|
2293 | } |
---|
2294 | packet = buf + left; |
---|
2295 | left = left + tssize; |
---|
2296 | |
---|
2297 | pid = ((packet[1] << 8) | packet[2]) & 0x1FFF; |
---|
2298 | pusi = !!(packet[1] & 0x40); |
---|
2299 | //check for adaption field |
---|
2300 | if(packet[3] & 0x20) |
---|
2301 | { |
---|
2302 | if(type > 1)continue; |
---|
2303 | if(packet[4] >= 183) continue; |
---|
2304 | if(packet[4]) |
---|
2305 | { |
---|
2306 | if(packet[5] & 0x10) //PCR present |
---|
2307 | { |
---|
2308 | pts = ((unsigned long long)(packet[6] & 0xFF)) << 25; |
---|
2309 | pts |= ((unsigned long long)(packet[7] & 0xFF)) << 17; |
---|
2310 | pts |= ((unsigned long long)(packet[8] & 0xFE)) << 9; |
---|
2311 | pts |= ((unsigned long long)(packet[9] & 0xFF)) << 1; |
---|
2312 | pts |= ((unsigned long long)(packet[10] & 0x80)) >> 7; |
---|
2313 | continue; |
---|
2314 | } |
---|
2315 | } |
---|
2316 | payload = packet + packet[4] + 4 + 1; |
---|
2317 | } else |
---|
2318 | payload = packet + 4; |
---|
2319 | |
---|
2320 | if(type == 1) continue; |
---|
2321 | if(!pusi) continue; |
---|
2322 | |
---|
2323 | if (payload[0] || payload[1] || (payload[2] != 1)) |
---|
2324 | continue; |
---|
2325 | |
---|
2326 | //stream use extension mechanism def in ISO 13818-1 Amendment 2 |
---|
2327 | if(payload[3] == 0xFD) |
---|
2328 | { |
---|
2329 | if(payload[7] & 1) //PES extension flag |
---|
2330 | { |
---|
2331 | int offs = 0; |
---|
2332 | if(payload[7] & 0x80) offs += 5; //pts avail |
---|
2333 | if(payload[7] & 0x40) offs += 5; //dts avail |
---|
2334 | if(payload[7] & 0x20) offs += 6; //escr avail |
---|
2335 | if(payload[7] & 0x10) offs += 3; //es rate |
---|
2336 | if(payload[7] & 0x8) offs += 1; //dsm trickmode |
---|
2337 | if(payload[7] & 0x4) offs += 1; //additional copy info |
---|
2338 | if(payload[7] & 0x2) offs += 2; //crc |
---|
2339 | if(payload[8] < offs) continue; |
---|
2340 | |
---|
2341 | uint8_t pef = payload[9 + offs++]; //pes extension field |
---|
2342 | if(pef & 1) //pes extension flag 2 |
---|
2343 | { |
---|
2344 | if(pef & 0x80) offs += 16; //private data flag |
---|
2345 | if(pef & 0x40) offs += 1; //pack header field flag |
---|
2346 | if(pef & 0x20) offs += 2; //program packet sequence counter flag |
---|
2347 | if(pef & 0x10) offs += 2; //P-STD buffer flag |
---|
2348 | if(payload[8] < offs) continue; |
---|
2349 | |
---|
2350 | uint8_t stream_id_extension_len = payload[9 + offs++] & 0x7F; |
---|
2351 | if(stream_id_extension_len >= 1) |
---|
2352 | { |
---|
2353 | if(payload[8] < (offs + stream_id_extension_len)) continue; |
---|
2354 | //stream_id_extension_bit (should not set) |
---|
2355 | if(payload[9 + offs] & 0x80) continue; |
---|
2356 | switch(payload[9 + offs]) |
---|
2357 | { |
---|
2358 | case 0x55 ... 0x5f: break; //VC-1 |
---|
2359 | case 0x71: break; //AC3 / DTS |
---|
2360 | case 0x72: break; //DTS - HD |
---|
2361 | default: |
---|
2362 | printf("skip unknwn stream_id_extension %02x\n", payload[9 + offs]); |
---|
2363 | continue; |
---|
2364 | } |
---|
2365 | } |
---|
2366 | else |
---|
2367 | continue; |
---|
2368 | } |
---|
2369 | else |
---|
2370 | continue; |
---|
2371 | } |
---|
2372 | else |
---|
2373 | continue; |
---|
2374 | } |
---|
2375 | //drop non-audio, non-video packets because other streams |
---|
2376 | //can be non-compliant. |
---|
2377 | //0xC0 = audio, 0xE0 = video |
---|
2378 | else if(((payload[3] & 0xE0) != 0xC0) && ((payload[3] & 0xF0) != 0xE0)) |
---|
2379 | continue; |
---|
2380 | |
---|
2381 | if((payload[7] & 0x80) && ((payload[3] & 0xF0) != 0xE0) && (type == 0 || type == 2)) //PTS video |
---|
2382 | { |
---|
2383 | pts = ((unsigned long long)(payload[9] & 0xE)) << 29; |
---|
2384 | pts |= ((unsigned long long)(payload[10] & 0xFF)) << 22; |
---|
2385 | pts |= ((unsigned long long)(payload[11] & 0xFE)) << 14; |
---|
2386 | pts |= ((unsigned long long)(payload[12] & 0xFF)) << 7; |
---|
2387 | pts |= ((unsigned long long)(payload[13] & 0xFE)) >> 1; |
---|
2388 | continue; |
---|
2389 | } |
---|
2390 | if((payload[7] & 0x80) && ((payload[3] & 0xE0) != 0xC0) && (type == 0 || type == 3)) //PTS audio |
---|
2391 | { |
---|
2392 | pts = ((unsigned long long)(payload[9] & 0xE)) << 29; |
---|
2393 | pts |= ((unsigned long long)(payload[10] & 0xFF)) << 22; |
---|
2394 | pts |= ((unsigned long long)(payload[11] & 0xFE)) << 14; |
---|
2395 | pts |= ((unsigned long long)(payload[12] & 0xFF)) << 7; |
---|
2396 | pts |= ((unsigned long long)(payload[13] & 0xFE)) >> 1; |
---|
2397 | continue; |
---|
2398 | } |
---|
2399 | } |
---|
2400 | free(buf); |
---|
2401 | return recbsize * -1; |
---|
2402 | } |
---|
2403 | |
---|
2404 | #endif |
---|