source: titan/libeplayer3/playback/playback.c @ 39848

Last change on this file since 39848 was 39848, checked in by obi, 7 years ago

eplayer test

File size: 29.3 KB
Line 
1/*
2 * GPL
3 * duckbox 2010
4 */
5
6/* ***************************** */
7/* Includes                      */
8/* ***************************** */
9
10#include <stdlib.h>
11#include <string.h>
12#include <unistd.h>
13#include <sys/stat.h>
14#include <fcntl.h>
15#include <sys/socket.h>
16#include <netdb.h>
17#include <sys/types.h>
18#include <dirent.h>
19#include <errno.h>
20#include <poll.h>
21#include <stdint.h>
22
23#include "playback.h"
24#include "common.h"
25#include "misc.h"
26
27/* ***************************** */
28/* Makros/Constants              */
29/* ***************************** */
30// SULGE DEBUG
31//#define SAM_WITH_DEBUG
32
33#ifdef SAM_WITH_DEBUG
34#define PLAYBACK_DEBUG
35#else
36#define PLAYBACK_SILENT
37#endif
38
39static short debug_level = 20;
40
41#ifdef PLAYBACK_DEBUG
42#define playback_printf(level, fmt, x...) do { \
43if (debug_level >= level) printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
44#else
45#define playback_printf(level, fmt, x...)
46#endif
47
48#ifndef PLAYBACK_SILENT
49#define playback_err(fmt, x...) do { printf("[%s:%s] " fmt, __FILE__, __FUNCTION__, ## x); } while (0)
50#else
51#define playback_err(fmt, x...)
52#endif
53
54#define cERR_PLAYBACK_NO_ERROR      0
55#define cERR_PLAYBACK_ERROR        -1
56
57#define cMaxSpeed_ff   128 /* fixme: revise */
58#define cMaxSpeed_fr   -320 /* fixme: revise */
59
60/* ***************************** */
61/* Varaibles                     */
62/* ***************************** */
63
64/* ***************************** */
65/* Prototypes                    */
66/* ***************************** */
67extern void set_pause_timeout(uint8_t pause);
68static int32_t PlaybackTerminate(Context_t  *context);
69
70/* ***************************** */
71/* MISC Functions                */
72/* ***************************** */
73int8_t PlaybackDieNow(int8_t val)
74{
75    static int8_t dieNow = 0;
76    if(val)
77    {
78        dieNow = 1;
79    }
80printf("PlaybackDieNow=%d\n", dieNow);
81    return dieNow;
82}
83
84/* ***************************** */
85/* Functions                     */
86/* ***************************** */
87
88static int PlaybackStop(Context_t  *context);
89
90static int PlaybackOpen(Context_t  *context, PlayFiles_t *pFiles)
91{
92    if (context->playback->isPlaying)
93    {
94        PlaybackStop(context);
95    }
96   
97    char *uri = pFiles->szFirstFile;
98   
99    playback_printf(10, "URI=%s\n", uri);
100
101    if (context->playback->isPlaying)
102    { // shouldn't happen
103        playback_err("playback already running\n");
104        return cERR_PLAYBACK_ERROR;
105    }
106
107    char * extension = NULL;
108
109    context->playback->uri = strdup(uri);
110
111    context->playback->isFile = 0;
112    context->playback->isHttp = 0;
113
114    if (!strncmp("file://", uri, 7) || !strncmp("myts://", uri, 7))
115    {
116        context->playback->isFile = 1;
117        if (!strncmp("myts://", uri, 7))
118        {
119            memcpy(context->playback->uri, "file", 4);
120            context->playback->noprobe = 1;
121        }
122        else
123        {
124            context->playback->noprobe = 0;
125        }
126
127        extension = getExtension(context->playback->uri+7);
128        if(!extension)
129        {
130            playback_err("Wrong extension (%s)\n", context->playback->uri+7);
131            return cERR_PLAYBACK_ERROR;
132        }
133        //CHECK FOR SUBTITLES
134        if (context->container && context->container->textSrtContainer)
135            context->container->textSrtContainer->Command(context, CONTAINER_INIT, context->playback->uri+7);
136
137        if (context->container && context->container->textSsaContainer)
138            context->container->textSsaContainer->Command(context, CONTAINER_INIT, context->playback->uri+7);
139
140        if (context->container && context->container->assContainer)
141            context->container->assContainer->Command(context, CONTAINER_INIT, NULL);
142    }
143    else if (strstr(uri, "://"))
144    {
145        context->playback->isHttp = 1;
146        extension = "mp3";
147        if (!strncmp("mms://", uri, 6))
148        {
149            // mms is in reality called rtsp, and ffmpeg expects this
150            char * tUri = (char*)malloc(strlen(uri) + 2);
151            strncpy(tUri+1, uri, strlen(uri)+1);
152            strncpy(tUri, "rtsp", 4);
153            free(context->playback->uri);
154            context->playback->uri = tUri;
155        }
156    }
157    else
158    {
159        playback_err("Unknown stream (%s)\n", uri);
160        return cERR_PLAYBACK_ERROR;
161    }
162
163    pFiles->szFirstFile = context->playback->uri;
164    if ((context->container->Command(context, CONTAINER_ADD, extension) < 0)
165        ||  (!context->container->selectedContainer)
166        ||  (context->container->selectedContainer->Command(context, CONTAINER_INIT, pFiles) < 0))
167    {
168        playback_err("CONTAINER_ADD failed\n");
169        return cERR_PLAYBACK_ERROR;
170    }
171
172    playback_printf(10, "exiting with value 0\n");
173
174    return cERR_PLAYBACK_NO_ERROR;
175}
176
177static int PlaybackClose(Context_t  *context)
178{
179    int ret = cERR_PLAYBACK_NO_ERROR;
180
181    playback_printf(10, "\n");
182
183    if (context->container->Command(context, CONTAINER_DEL, NULL) < 0)
184    {
185        playback_err("container delete failed\n");
186    }
187
188    if (context->container && context->container->textSrtContainer)
189        context->container->textSrtContainer->Command(context, CONTAINER_DEL, NULL);
190
191    if (context->container && context->container->textSsaContainer)
192        context->container->textSsaContainer->Command(context, CONTAINER_DEL, NULL);
193
194    context->manager->audio->Command(context, MANAGER_DEL, NULL);
195    context->manager->video->Command(context, MANAGER_DEL, NULL);
196        context->manager->subtitle->Command(context, MANAGER_DEL, NULL);
197    context->manager->dvbsubtitle->Command(context, MANAGER_DEL, NULL);
198    context->manager->teletext->Command(context, MANAGER_DEL, NULL);
199
200    context->playback->isPaused     = 0;
201    context->playback->isPlaying    = 0;
202    context->playback->isForwarding = 0;
203    context->playback->BackWard     = 0;
204    context->playback->SlowMotion   = 0;
205    context->playback->Speed        = 0;
206    if(context->playback->uri)
207    {
208        free(context->playback->uri);
209        context->playback->uri = NULL;
210    }
211
212    playback_printf(10, "exiting with value %d\n", ret);
213
214    return ret;
215}
216
217static int PlaybackPlay(Context_t  *context)
218{
219    pthread_attr_t attr;
220    int ret = cERR_PLAYBACK_NO_ERROR;
221
222    playback_printf(10, "\n");
223
224    if (!context->playback->isPlaying)
225    {
226        context->playback->AVSync = 1;
227        context->output->Command(context, OUTPUT_AVSYNC, NULL);
228
229        context->playback->isCreationPhase = 1; // allows the created thread to go into wait mode
230        ret = context->output->Command(context, OUTPUT_PLAY, NULL);
231
232        if (ret != 0)
233        {
234            playback_err("OUTPUT_PLAY failed!\n");
235            playback_err("clearing isCreationPhase!\n");
236            context->playback->isCreationPhase = 0;     // allow thread to go into next state
237            context->playback->isPlaying       = 0;
238            context->playback->isPaused        = 0;
239            context->playback->isForwarding    = 0;
240            context->playback->BackWard        = 0;
241            context->playback->SlowMotion      = 0;
242            context->playback->Speed           = 0;
243            context->container->selectedContainer->Command(context, CONTAINER_STOP, NULL);
244        }
245        else
246        {
247            context->playback->isPlaying    = 1;
248            context->playback->isPaused     = 0;
249            context->playback->isForwarding = 0;
250            context->playback->BackWard     = 0;
251            context->playback->SlowMotion   = 0;
252            context->playback->Speed        = 1;
253
254            playback_printf(10, "clearing isCreationPhase!\n");
255
256            context->playback->isCreationPhase = 0;     // allow thread to go into next state
257
258            ret = context->container->selectedContainer->Command(context, CONTAINER_PLAY, NULL);
259            if (ret != 0) {
260                playback_err("CONTAINER_PLAY failed!\n");
261            }
262
263        }
264    }
265    else
266    {
267        playback_err("playback already running\n");
268        ret = cERR_PLAYBACK_ERROR;
269    }
270
271    playback_printf(10, "exiting with value %d\n", ret);
272
273    return ret;
274}
275
276static int PlaybackPause(Context_t  *context)
277{
278    int ret = cERR_PLAYBACK_NO_ERROR;
279
280    playback_printf(10, "\n");
281
282    if (context->playback->isPlaying && !context->playback->isPaused)
283    {
284        set_pause_timeout(1);
285                if(context->playback->SlowMotion)
286                        context->output->Command(context, OUTPUT_CLEAR, NULL);
287
288        context->output->Command(context, OUTPUT_PAUSE, NULL);
289
290        context->playback->isPaused     = 1;
291        //context->playback->isPlaying  = 1;
292        context->playback->isForwarding = 0;
293        context->playback->BackWard     = 0;
294        context->playback->SlowMotion   = 0;
295        context->playback->Speed        = 1;
296    }
297    else
298    {
299        playback_err("playback not playing or already in pause mode\n");
300        ret = cERR_PLAYBACK_ERROR;
301    }
302
303    playback_printf(10, "exiting with value %d\n", ret);
304    return ret;
305}
306
307static int32_t PlaybackContinue(Context_t  *context)
308{
309    int32_t ret = cERR_PLAYBACK_NO_ERROR;
310
311    playback_printf(10, "\n");
312
313    if (context->playback->isPlaying &&
314       (context->playback->isPaused || context->playback->isForwarding ||
315        context->playback->BackWard || context->playback->SlowMotion))
316    {
317
318        set_pause_timeout(0);
319        if(context->playback->SlowMotion)
320            context->output->Command(context, OUTPUT_CLEAR, NULL);
321        context->output->Command(context, OUTPUT_CONTINUE, NULL);
322
323        context->playback->isPaused     = 0;
324        //context->playback->isPlaying  = 1;
325        context->playback->isForwarding = 0;
326        context->playback->BackWard     = 0;
327        context->playback->SlowMotion   = 0;
328        context->playback->Speed        = 1;
329    }
330    else
331    {
332        playback_err("continue not possible\n");
333        ret = cERR_PLAYBACK_ERROR;
334    }
335
336    playback_printf(10, "exiting with value %d\n", ret);
337    return ret;
338}
339
340static int32_t PlaybackStop(Context_t  *context)
341{
342    int32_t ret = cERR_PLAYBACK_NO_ERROR;
343
344    playback_printf(10, "\n");
345   
346    PlaybackDieNow(1);
347
348    if (context && context->playback && context->playback->isPlaying)
349    {
350
351        context->playback->isPaused     = 0;
352        context->playback->isPlaying    = 0;
353        context->playback->isForwarding = 0;
354        context->playback->BackWard     = 0;
355        context->playback->SlowMotion   = 0;
356        context->playback->Speed        = 0;
357
358        context->output->Command(context, OUTPUT_STOP, NULL);
359        context->container->selectedContainer->Command(context, CONTAINER_STOP, NULL);
360
361    }
362    else
363    {
364        playback_err("stop not possible\n");
365        ret = cERR_PLAYBACK_ERROR;
366    }
367
368    playback_printf(10, "exiting with value %d\n", ret);
369    return ret;
370}
371
372static int32_t PlaybackTerminate(Context_t  *context)
373{
374    int32_t ret = cERR_PLAYBACK_NO_ERROR;
375
376    playback_printf(20, "\n");
377   
378    PlaybackDieNow(1);
379
380    if ( context && context->playback && context->playback->isPlaying )
381    {
382        //First Flush and than delete container, else e2 cant read length of file anymore
383
384        if (context->output->Command(context, OUTPUT_FLUSH, NULL) < 0)
385        {
386            playback_err("failed to flush output.\n");
387        }
388
389        ret = context->container->selectedContainer->Command(context, CONTAINER_STOP, NULL);
390
391        context->playback->isPaused     = 0;
392        context->playback->isPlaying    = 0;
393        context->playback->isForwarding = 0;
394        context->playback->BackWard     = 0;
395        context->playback->SlowMotion   = 0;
396        context->playback->Speed        = 0;
397
398    }
399    else
400    {
401        playback_err("%p %p %d\n", context, context->playback, context->playback->isPlaying);
402
403        /* fixme: konfetti: we should return an error here but this seems to be a condition which
404         * can happen and is not a real error, which leads to a dead neutrino. should investigate
405         * here later.
406         */
407    }
408
409    playback_printf(20, "exiting with value %d\n", ret);
410    return ret;
411}
412
413static int PlaybackFastForward(Context_t  *context, int* speed) {
414    int32_t ret = cERR_PLAYBACK_NO_ERROR;
415
416    playback_printf(10, "speed %d\n", *speed);
417
418    /* Audio only forwarding not supported */
419    if (context->playback->isVideo && !context->playback->isHttp && !context->playback->BackWard && (!context->playback->isPaused || context->playback->isPlaying)) {
420
421        if ((*speed <= 0) || (*speed > cMaxSpeed_ff))
422        {
423            playback_err("speed %d out of range (1 - %d) \n", *speed, cMaxSpeed_ff);
424            return cERR_PLAYBACK_ERROR;
425        }
426
427        context->playback->isForwarding = 1;
428        context->playback->Speed = *speed;
429
430        playback_printf(20, "Speed: %d x {%d}\n", *speed, context->playback->Speed);
431
432        context->output->Command(context, OUTPUT_FASTFORWARD, NULL);
433    } else
434    {
435        playback_err("fast forward not possible\n");
436        ret = cERR_PLAYBACK_ERROR;
437    }
438
439    playback_printf(10, "exiting with value %d\n", ret);
440
441    return ret;
442}
443
444static int PlaybackFastBackward(Context_t  *context,int* speed) {
445    int32_t ret = cERR_PLAYBACK_NO_ERROR;
446
447    playback_printf(10, "speed = %d\n", *speed);
448
449    /* Audio only reverse play not supported */
450    if (context->playback->isVideo && !context->playback->isForwarding && (!context->playback->isPaused || context->playback->isPlaying)) {
451
452        if ((*speed > 0) || (*speed < cMaxSpeed_fr))
453        {
454            playback_err("speed %d out of range (0 - %d) \n", *speed, cMaxSpeed_fr);
455            return cERR_PLAYBACK_ERROR;
456        }
457
458        if (*speed == 0)
459        {
460            context->playback->BackWard = 0;
461            context->playback->Speed = 0;    /* reverse end */
462        } else
463        {
464            context->playback->isSeeking = 1;
465            context->playback->Speed = *speed;
466            context->playback->BackWard = 2^(*speed);
467         
468            playback_printf(1, "S %d B %f\n", context->playback->Speed, context->playback->BackWard);
469        }
470
471        context->output->Command(context, OUTPUT_AUDIOMUTE, "1");
472        context->output->Command(context, OUTPUT_CLEAR, NULL);
473        if (context->output->Command(context, OUTPUT_REVERSE, NULL) < 0)
474        {
475            playback_err("OUTPUT_REVERSE failed\n");
476            context->playback->BackWard = 0;
477            context->playback->Speed = 1;
478            context->playback->isSeeking = 0;
479            ret = cERR_PLAYBACK_ERROR;
480        }
481    } else
482    {
483        playback_err("fast backward not possible\n");
484        ret = cERR_PLAYBACK_ERROR;
485    }
486
487    context->playback->isSeeking = 0;
488    playback_printf(10, "exiting with value %d\n", ret);
489
490    return ret;
491}
492
493static int32_t PlaybackSlowMotion(Context_t  *context,int* speed) {
494    int32_t ret = cERR_PLAYBACK_NO_ERROR;
495
496    playback_printf(10, "\n");
497
498    //Audio only forwarding not supported
499    if (context->playback->isVideo && !context->playback->isHttp && context->playback->isPlaying) {
500        if(context->playback->isPaused)
501            PlaybackContinue(context);
502
503        switch(*speed) {
504        case 2:
505            context->playback->SlowMotion = 2;
506            break;
507        case 4:
508            context->playback->SlowMotion = 4;
509            break;
510        case 8:
511            context->playback->SlowMotion = 8;
512            break;
513        }
514
515        playback_printf(20, "SlowMotion: %d x {%d}\n", *speed, context->playback->SlowMotion);
516
517        context->output->Command(context, OUTPUT_SLOWMOTION, NULL);
518    } else
519    {
520        playback_err("slowmotion not possible\n");
521        ret = cERR_PLAYBACK_ERROR;
522    }
523
524    playback_printf(10, "exiting with value %d\n", ret);
525
526    return ret;
527}
528
529static int32_t PlaybackSeek(Context_t  *context, int64_t *pos, uint8_t absolute)
530{
531    int32_t ret = cERR_PLAYBACK_NO_ERROR;
532
533    playback_printf(10, "pos: %lldd\n", *pos);
534
535    if (context->playback->isPlaying && !context->playback->isForwarding && !context->playback->BackWard && !context->playback->SlowMotion && !context->playback->isPaused)
536    {
537        context->playback->isSeeking = 1;
538        context->output->Command(context, OUTPUT_CLEAR, NULL);
539        if (absolute)
540        {
541            context->container->selectedContainer->Command(context, CONTAINER_SEEK_ABS, pos);
542        }
543        else
544        {
545            context->container->selectedContainer->Command(context, CONTAINER_SEEK, pos);
546        }
547        context->playback->isSeeking = 0;
548    }
549    else
550    {
551        playback_err("not possible\n");
552        ret = cERR_PLAYBACK_ERROR;
553    }
554
555    playback_printf(10, "exiting with value %d\n", ret);
556
557    return ret;
558}
559
560static int32_t PlaybackPts(Context_t  *context, int64_t *pts)
561{
562    int32_t ret = cERR_PLAYBACK_NO_ERROR;
563
564    playback_printf(20, "\n");
565
566    *pts = 0;
567
568    if (context->playback->isPlaying)
569    {
570        ret = context->output->Command(context, OUTPUT_PTS, pts);
571    }
572    else
573    {
574        playback_err("not possible\n");
575        ret = cERR_PLAYBACK_ERROR;
576    }
577
578    playback_printf(20, "exiting with value %d\n", ret);
579
580    return ret;
581}
582
583static int32_t PlaybackGetFrameCount(Context_t  *context, int64_t *frameCount)
584{
585    int ret = cERR_PLAYBACK_NO_ERROR;
586
587    playback_printf(20, "\n");
588
589    *frameCount = 0;
590
591    if (context->playback->isPlaying)
592    {
593        ret = context->output->Command(context, OUTPUT_GET_FRAME_COUNT, frameCount);
594    } else
595    {
596        playback_err("not possible\n");
597        ret = cERR_PLAYBACK_ERROR;
598    }
599
600    playback_printf(20, "exiting with value %d\n", ret);
601
602    return ret;
603}
604
605static int32_t PlaybackLength(Context_t  *context, int64_t *length)
606{
607    int32_t ret = cERR_PLAYBACK_NO_ERROR;
608
609    playback_printf(20, "\n");
610
611    *length = -1;
612
613    if (context->playback->isPlaying)
614    {
615        if (context->container && context->container->selectedContainer)
616        {
617            context->container->selectedContainer->Command(context, CONTAINER_LENGTH, length);
618        }
619    }
620    else
621    {
622        playback_err("not possible\n");
623        ret = cERR_PLAYBACK_ERROR;
624    }
625
626    playback_printf(20, "exiting with value %d\n", ret);
627    return ret;
628}
629
630static int32_t PlaybackSwitchAudio(Context_t  *context, int32_t *track)
631{
632    int32_t ret = cERR_PLAYBACK_NO_ERROR;
633    int32_t curtrackid = 0;
634    int32_t nextrackid = 0;
635
636    playback_printf(10, "\n");
637
638    if (context && context->playback && context->playback->isPlaying)
639    {
640        if (context->manager && context->manager->audio)
641        {
642            context->manager->audio->Command(context, MANAGER_GET, &curtrackid);
643            context->manager->audio->Command(context, MANAGER_SET, track);
644            context->manager->audio->Command(context, MANAGER_GET, &nextrackid);
645        }
646        else
647        {
648            playback_err("switch audio not possible\n");
649            ret = cERR_PLAYBACK_ERROR;
650        }
651
652        if(nextrackid != curtrackid)
653        {
654
655            //PlaybackPause(context);
656            if (context->output && context->output->audio)
657            {
658                context->output->audio->Command(context, OUTPUT_SWITCH, (void*)"audio");
659            }
660
661            if (context->container && context->container->selectedContainer)
662            {
663                context->container->selectedContainer->Command(context, CONTAINER_SWITCH_AUDIO, &nextrackid);
664            }
665            //PlaybackContinue(context);
666        }
667    }
668    else
669    {
670        playback_err("switch audio not possible\n");
671        ret = cERR_PLAYBACK_ERROR;
672    }
673
674    playback_printf(10, "exiting with value %d\n", ret);
675    return ret;
676}
677
678static int32_t PlaybackSwitchSubtitle(Context_t  *context, int32_t *track)
679{
680    int32_t ret = cERR_PLAYBACK_NO_ERROR;
681    int32_t curtrackid = -1;
682    int32_t nextrackid = -1;
683
684    playback_printf(10, "Track: %d\n", *track);
685
686        if (context && context->playback && context->playback->isPlaying ) {
687        if (context->manager && context->manager->subtitle) {
688            int trackid;
689           
690            if (context->manager->subtitle->Command(context, MANAGER_SET, track) < 0)
691            {
692                playback_err("manager set track failed\n");
693                        }
694/*
695    if (context && context->playback && context->playback->isPlaying )
696    {
697        int trackid;
698
699        if (context->manager && context->manager->subtitle)
700        {
701            context->manager->subtitle->Command(context, MANAGER_GET, &curtrackid);
702            context->manager->subtitle->Command(context, MANAGER_SET, track);
703            context->manager->subtitle->Command(context, MANAGER_GET, &nextrackid);
704         
705            if (curtrackid != nextrackid && nextrackid > -1)
706            {
707                if (context->output && context->output->subtitle)
708                {
709                    context->output->subtitle->Command(context, OUTPUT_SWITCH, (void*)"subtitle");
710                }
711
712                if (context->container && context->container->selectedContainer)
713                {
714                    context->container->selectedContainer->Command(context, CONTAINER_SWITCH_SUBTITLE, &nextrackid);
715                }
716            }
717
718*/
719#if 0
720                    if (*track == 0xffff) {
721                        //CHECK FOR SUBTITLES
722                        if (context->container && context->container->textSrtContainer)
723                            context->container->textSrtContainer->Command(context, CONTAINER_INIT, context->playback->uri+7);
724       
725                        if (context->container && context->container->textSsaContainer)
726                            context->container->textSsaContainer->Command(context, CONTAINER_INIT, context->playback->uri+7);
727       
728                        if (context->container && context->container->assContainer)
729                            context->container->assContainer->Command(context, CONTAINER_INIT, NULL);
730                    }
731#endif
732            context->manager->subtitle->Command(context, MANAGER_GET, &trackid);
733
734/* konfetti: I make this hack a little bit nicer,
735 * but its still a hack in my opinion ;)
736 */
737            if (context->container && context->container->assContainer)
738                context->container->assContainer->Command(context, CONTAINER_SWITCH_SUBTITLE, &trackid);
739
740            if (trackid >= TEXTSRTOFFSET)
741            {
742                if (context->container && context->container->textSrtContainer)
743                     context->container->textSrtContainer->Command(context, CONTAINER_SWITCH_SUBTITLE, &trackid);
744            }
745            if (trackid >= TEXTSSAOFFSET)
746            {
747                 if (context->container && context->container->textSsaContainer)
748                     context->container->textSsaContainer->Command(context, CONTAINER_SWITCH_SUBTITLE, &trackid);
749            }
750
751        }
752        else
753        {
754            ret = cERR_PLAYBACK_ERROR;
755            playback_err("no subtitle\n");
756        }
757    }
758    else
759    {
760        playback_err("not possible\n");
761        ret = cERR_PLAYBACK_ERROR;
762    }
763
764    playback_printf(10, "exiting with value %d\n", ret);
765
766    return ret;
767}
768
769static int32_t PlaybackSwitchDVBSubtitle(Context_t  *context, int* pid) {
770    int ret = cERR_PLAYBACK_NO_ERROR;
771
772    playback_printf(10, "Track: %d\n", *pid);
773
774    if (context && context->manager && context->manager->dvbsubtitle ) {
775        if (context->manager->dvbsubtitle->Command(context, *pid == 0xffff ? MANAGER_DEL : MANAGER_SET, pid) < 0) {
776                playback_err("dvbsub manager set track failed\n");
777                ret = cERR_PLAYBACK_ERROR;
778        }
779    } else
780        playback_err("no dvbsubtitle\n");
781
782    if (*pid == 0xffff)
783        container_ffmpeg_update_tracks(context, context->playback->uri, 0);
784
785    playback_printf(10, "exiting with value %d\n", ret);
786
787    return ret;
788}
789
790static int32_t PlaybackSwitchTeletext(Context_t  *context, int* pid) {
791    int ret = cERR_PLAYBACK_NO_ERROR;
792
793    playback_printf(10, "Track: %d\n", *pid);
794
795    if (context && context->manager && context->manager->teletext ) {
796        if (context->manager->teletext->Command(context, *pid == 0xffff ? MANAGER_DEL : MANAGER_SET, pid)) {
797                playback_err("ttxsub manager set track failed\n");
798                ret = cERR_PLAYBACK_ERROR;
799        }
800    } else
801        playback_err("no ttxsubtitle\n");
802
803    if (*pid == 0xffff)
804        container_ffmpeg_update_tracks(context, context->playback->uri, 0);
805
806    playback_printf(10, "exiting with value %d\n", ret);
807
808    return ret;
809}
810
811static int32_t PlaybackInfo(Context_t  *context, char **infoString)
812{
813    int32_t ret = cERR_PLAYBACK_NO_ERROR;
814
815    playback_printf(10, "\n");
816
817    /* konfetti comment:
818     * removed if clause here (playback running) because its
819     * not necessary for all container. e.g. in case of ffmpeg
820     * container playback must not play to get the info.
821     */
822    if (context->container && context->container->selectedContainer)
823    {
824        context->container->selectedContainer->Command(context, CONTAINER_INFO, infoString);
825    }
826
827    playback_printf(10, "exiting with value %d\n", ret);
828
829    return ret;
830}
831
832static int32_t Command(void* _context, PlaybackCmd_t command, void *argument)
833{
834    Context_t* context = (Context_t*) _context; /* to satisfy compiler */
835    int32_t ret = cERR_PLAYBACK_NO_ERROR;
836
837    playback_printf(20, "Command %d\n", command);
838
839
840    switch(command)
841    {
842        case PLAYBACK_OPEN:
843        {
844            ret = PlaybackOpen(context, (PlayFiles_t*)argument);
845            break;
846        }
847        case PLAYBACK_CLOSE:
848        {
849            ret = PlaybackClose(context);
850            break;
851        }
852        case PLAYBACK_PLAY:
853        {
854            ret = PlaybackPlay(context);
855            break;
856        }
857        case PLAYBACK_STOP:
858        {
859            ret = PlaybackStop(context);
860            break;
861        }
862        case PLAYBACK_PAUSE:
863        {
864            ret = PlaybackPause(context);
865            break;
866        }
867        case PLAYBACK_CONTINUE:
868        {
869            ret = PlaybackContinue(context);
870            break;
871        }
872        case PLAYBACK_TERM:
873        {
874            ret = PlaybackTerminate(context);
875            break;
876        }
877        case PLAYBACK_SEEK:
878        {
879            ret = PlaybackSeek(context, (int64_t*)argument, 0);
880            break;
881        }
882        case PLAYBACK_SEEK_ABS:
883        {
884            ret = PlaybackSeek(context, (int64_t*)argument, -1);
885            break;
886        }
887        case PLAYBACK_PTS:
888        {
889            ret = PlaybackPts(context, (int64_t*)argument);
890            break;
891        }
892        case PLAYBACK_LENGTH:
893        {
894            ret = PlaybackLength(context, (int64_t*)argument);
895            break;
896        }
897        case PLAYBACK_SWITCH_AUDIO:
898        {
899            ret = PlaybackSwitchAudio(context, (int*)argument);
900            break;
901        }
902        case PLAYBACK_SWITCH_SUBTITLE:
903        {
904            ret = PlaybackSwitchSubtitle(context, (int*)argument);
905            break;
906        }
907        case PLAYBACK_SWITCH_DVBSUBTITLE:
908        {
909            ret = PlaybackSwitchDVBSubtitle(context, (int*)argument);
910            break;
911        }
912        case PLAYBACK_SWITCH_TELETEXT:
913        {
914            ret = PlaybackSwitchTeletext(context, (int*)argument);
915            break;
916        }
917        case PLAYBACK_INFO:
918        {
919            ret = PlaybackInfo(context, (char**)argument);
920            break;
921        }
922            case PLAYBACK_SLOWMOTION:
923            {
924                ret = PlaybackSlowMotion(context,(int*)argument);
925                break;
926            }
927            case PLAYBACK_FASTBACKWARD:
928            {
929                ret = PlaybackFastBackward(context,(int*)argument);
930                break;
931            }
932            case PLAYBACK_FASTFORWARD:
933            {
934                ret = PlaybackFastForward(context,(int*)argument);
935                break;
936            }
937        case PLAYBACK_GET_FRAME_COUNT:
938        {
939            ret = PlaybackGetFrameCount(context, (uint64_t*)argument);
940            break;
941        }
942            case PLAYBACK_FRAMEBUFFER_LOCK:
943            {
944                context->playback->mayWriteToFramebuffer = 0;
945                ret = cERR_PLAYBACK_NO_ERROR;
946                        break;
947            }
948            case PLAYBACK_FRAMEBUFFER_UNLOCK:
949            {
950                context->playback->mayWriteToFramebuffer = 1;
951                ret = cERR_PLAYBACK_NO_ERROR;
952                        break;
953                }
954        default:
955        {
956            playback_err("PlaybackCmd %d not supported!\n", command);
957            ret = cERR_PLAYBACK_ERROR;
958            break;
959                }
960    }
961
962    playback_printf(20, "exiting with value %d\n", ret);
963
964    return ret;
965}
966
967/*
968 * This is very unreadable and must be changed
969 */
970PlaybackHandler_t PlaybackHandler = {
971    "Playback", //name
972    -1,         //fd
973    0,          //isFile
974    0,          //isHttp
975    0,          //isPlaying
976    0,          //isPaused
977    0,          //isForwarding
978    0,          //isSeeking
979    0,          //isCreationPhase
980    0,          //BackWard
981    0,          //SlowMotion
982    0,          //Speed
983    0,          //AVSync
984    0,          //isVideo
985    0,          //isAudio
986    0,          //isSubtitle
987    0,          //isDvbSubtitle
988    0,          //isTeletext
989    1,                  //mayWriteToFramebuffer
990    0,          //abortRequested
991    &Command,   //Command
992    "",         //uri
993    0,          //size
994    0,          //noprobe
995    0,          //isLoopMode
996    0,          //isTSLiveMode
997};
Note: See TracBrowser for help on using the repository browser.