source: titan/titan/play.h @ 10958

Last change on this file since 10958 was 10849, checked in by nit, 12 years ago

[titan] add channelswitch to epg witch rcok

File size: 15.0 KB
Line 
1#ifndef PLAY_H
2#define PLAY_H
3
4void screenplaypolicy()
5{
6        int rcret = 0;
7        struct skin* playpolicy = getscreen("playpolicy");
8        char* tmpstr = NULL;
9
10start:
11        changepolicy();
12        tmpstr = getpolicy();
13        changetext(playpolicy, _(tmpstr));
14        free(tmpstr); tmpstr = NULL;
15        drawscreen(playpolicy, 0);
16
17        while(1)
18        {
19                rcret = waitrc(playpolicy, 1000, 0);
20                if(rcret == getrcconfigint("rcok", NULL))
21                        goto start;
22                break;
23        }
24
25        clearscreen(playpolicy);
26}
27
28void screenplayinfobar(char* file, int mode, int flag)
29{
30        if((flag == 2) || (flag == 3))
31        {
32                return;
33        }
34        struct skin* playinfobar = getscreen("playinfobar");
35        struct skin* playinfobarpic = getscreen("playinfobarpic");
36
37        if(mode == 1)
38        {
39                clearscreen(playinfobar);
40                clearscreen(playinfobarpic);
41                drawscreen(skin, 0);
42                return;
43        }
44
45        struct skin* title = getscreennode(playinfobar, "title");
46        struct skin* spos = getscreennode(playinfobar, "pos");
47        struct skin* slen = getscreennode(playinfobar, "len");
48        struct skin* sreverse = getscreennode(playinfobar, "reverse");
49        struct skin* sprogress = getscreennode(playinfobar, "progress");
50        char* tmpstr = NULL;
51        unsigned long long int pos = 0, len = 0, reverse = 0;
52
53        tmpstr = ostrcat(file, "", 0, 0);
54        changetext(title, basename(tmpstr));
55        free(tmpstr); tmpstr = NULL;
56
57        pos = playergetpts() / 90000;
58        len = playergetlength();
59        reverse = len - pos;
60
61        if(len == 0)
62                sprogress->progresssize = 0;
63        else
64                sprogress->progresssize = pos * 100 / len;
65
66        tmpstr = convert_timesec(pos);
67        changetext(spos, tmpstr);
68        free(tmpstr); tmpstr = NULL;
69
70        tmpstr = convert_timesec(len);
71        changetext(slen, tmpstr);
72        free(tmpstr); tmpstr = NULL;
73
74        tmpstr = convert_timesec(reverse);
75        changetext(sreverse, tmpstr);
76        free(tmpstr); tmpstr = NULL;
77
78        drawscreen(playinfobar, 0);
79        drawscreen(playinfobarpic, 0);
80}
81
82void screenplaytracklist(int mode, int flag)
83{
84        //mode 1 = audiotracks
85        //mode 2 = subtitle tracks
86        int i = 0;
87        int rcret = 0, curtrackid = 0;
88        struct skin* track = NULL;
89        if(mode == 1)
90                track = getscreen("audiotrack");
91        else if(mode == 2)
92                track = getscreen("subtitle");
93        struct skin* listbox = getscreennode(track, "listbox");
94        struct skin* tmp = NULL;
95        char** tracklist = NULL;
96        char* curtrackencoding = NULL, *curtrackname = NULL;
97        char* tmpstr = NULL;
98
99        playergetcurtrac(mode, &curtrackid, &curtrackencoding, &curtrackname);
100        tracklist = playergettracklist(mode);
101        if(tracklist != NULL)
102        {
103                while(tracklist[i] != NULL)
104                {
105                        tmp = addlistbox(track, listbox, tmp, 1);
106                        if(tmp != NULL)
107                        {
108                                tmpstr = ostrcat(tmpstr, tracklist[i], 1, 0);
109                                tmpstr = ostrcat(tmpstr, " (", 1, 0);
110                                tmpstr = ostrcat(tmpstr, tracklist[i + 1], 1, 0);
111                                tmpstr = ostrcat(tmpstr, ")", 1, 0);
112                                changetext(tmp, _(tmpstr));
113                                free(tmpstr); tmpstr = NULL;
114                                tmp->type = CHOICEBOX;
115                                tmp->del = 1;
116                                tmp->handle = (char*)(i / 2);
117
118                                if(ostrcmp(curtrackname, tracklist[i]) == 0 && ostrcmp(curtrackencoding, tracklist[i + 1]) == 0)
119                                {
120                                        tmp->handle1 = (char*)(i / 2);
121                                        changeinput(tmp, "running");
122                                }
123                                else
124                                        changeinput(tmp, "");
125                        }
126                        i += 2;
127                }
128        }
129
130        free(curtrackencoding); curtrackencoding = NULL;
131        free(curtrackname); curtrackname = NULL;
132        playerfreetracklist(tracklist); tracklist = NULL;
133
134        listbox->aktline = 1;
135        listbox->aktpage = -1;
136
137        screenplayinfobar(NULL, 1, flag);
138        drawscreen(track, 0);
139        addscreenrc(track, listbox);
140
141        while(1)
142        {
143                rcret = waitrc(track, 0, 0);
144
145                if(rcret == getrcconfigint("rcexit", NULL)) break;
146                if(rcret == getrcconfigint("rcok", NULL))
147                {
148                        if(listbox->select != NULL)
149                        {
150                                if(mode == 1)
151                                        playerchangeaudiotrack((int)listbox->select->handle);
152                                else if(mode == 2)
153                                {
154                                        if(listbox->select->handle1 != NULL)
155                                                playerchangesubtitletrack(-1);
156                                        else   
157                                                playerchangesubtitletrack((int)listbox->select->handle);
158                                }
159                        }
160                        break;
161                }
162        }
163
164        delmarkedscreennodes(track, 1);
165        delownerrc(track);
166        clearscreen(track);
167        blitfb();
168}
169
170void playrcyellow(char* file, int playinfobarstatus, int flag)
171{
172        screenplaytracklist(1, flag);
173        if(playinfobarstatus > 0)
174                screenplayinfobar(file, 0, flag);
175}
176
177void playrctext(char* file, int playinfobarstatus, int flag)
178{
179        screenplaytracklist(2, flag);
180        if(playinfobarstatus > 0)
181                screenplayinfobar(file, 0, flag);
182}
183
184void playrcgreen(char* file, int playinfobarstatus, int flag)
185{
186        screenplayinfobar(file, 1, flag);
187        screenvideomode();
188        drawscreen(skin, 0);
189        if(playinfobarstatus > 0)
190                screenplayinfobar(file, 0, flag);
191}
192
193void playrcblue(char* file, int playinfobarstatus, int flag)
194{
195        screenplayinfobar(file, 1, flag);
196        screenpowerofftimer();
197        drawscreen(skin, 0);
198        if(playinfobarstatus > 0)
199                screenplayinfobar(file, 0, flag);
200}
201
202void playrcok(char* file, int playinfobarstatus, int flag)
203{
204        screenplaypolicy(file, 1);
205        drawscreen(skin, 0);
206        if(playinfobarstatus > 0)
207                screenplayinfobar(file, 0, flag);
208}
209
210void playrcred(char* file, int playinfobarstatus, int flag)
211{
212        screenplayinfobar(file, 1, flag);
213        screenvideosettings();
214        drawscreen(skin, 0);
215        if(playinfobarstatus > 0)
216                screenplayinfobar(file, 0, flag);
217}
218
219void playrcinfo(char* file, int* playinfobarstatus, int* playinfobarcount, int flag)
220{
221        if(*playinfobarstatus == 0)
222        {
223                *playinfobarstatus = 1;
224                *playinfobarcount = 0;
225                screenplayinfobar(file, 0, flag);
226        }
227        else if(*playinfobarstatus == 1)
228        {
229                *playinfobarstatus = 0;
230                screenplayinfobar(NULL, 1, flag);
231        }
232}
233
234void playrcstop(int flag)
235{
236        playerstop();
237        writevfd("Player");
238        screenplayinfobar(NULL, 1, flag);
239}
240
241void playrcff(char* file, int* playinfobarstatus, int* playinfobarcount, int flag)
242{
243        if(status.pause == 0)
244        {
245                status.playspeed++;
246                if(status.playspeed > 7) status.playspeed = 7;
247                if(status.playspeed > 0)
248                {
249                        status.play = 0;
250                        playerff(status.playspeed);
251                        *playinfobarstatus = 2;
252                        *playinfobarcount = 0;
253                        screenplayinfobar(file, 0, flag);
254                }
255                if(status.playspeed < 0)
256                {
257                        status.play = 0;
258                        playerfr(status.playspeed);
259                        *playinfobarstatus = 2;
260                        *playinfobarcount = 0;
261                        screenplayinfobar(file, 0, flag);
262                }
263                if(status.playspeed == 0)
264                {
265                        status.play = 1;
266                        playercontinue();
267                        *playinfobarstatus = 1;
268                        *playinfobarcount = 0;
269                        screenplayinfobar(file, 0, flag);
270                }
271        }
272}
273
274void playrcfr(char* file, int* playinfobarstatus, int* playinfobarcount, int flag)
275{
276        if(status.pause == 0)
277        {
278                status.playspeed--;
279                if(status.playspeed < -7) status.playspeed = -7;
280                if(status.playspeed > 0)
281                {
282                        status.play = 0;
283                        playerff(status.playspeed);
284                        *playinfobarstatus = 2;
285                        *playinfobarcount = 0;
286                        screenplayinfobar(file, 0, flag);
287                }
288                if(status.playspeed < 0)
289                {
290                        status.play = 0;
291                        playerfr(status.playspeed);
292                        *playinfobarstatus = 2;
293                        *playinfobarcount = 0;
294                        screenplayinfobar(file, 0, flag);
295                }
296                if(status.playspeed == 0)
297                {
298                        status.play = 1;
299                        playercontinue();
300                        *playinfobarstatus = 1;
301                        *playinfobarcount = 0;
302                        screenplayinfobar(file, 0, flag);
303                }
304        }
305}
306
307void playrcpause(char* file, int* playinfobarstatus, int* playinfobarcount, int flag)
308{
309        if(status.pause == 1)
310        {
311                status.playspeed = 0;
312                status.play = 1;
313                status.pause = 0;
314                playercontinue();
315                *playinfobarstatus = 1;
316                *playinfobarcount = 0;
317                screenplayinfobar(file, 0, flag);
318        }
319        else
320        {
321                status.playspeed = 0;
322                status.play = 0;
323                status.pause = 1;
324                playerpause();
325                *playinfobarstatus = 2;
326                *playinfobarcount = 0;
327                screenplayinfobar(file, 0, flag);
328        }
329}
330
331void playrcplay(char* file, int* playinfobarstatus, int* playinfobarcount, int flag)
332{
333        playercontinue();
334        status.playspeed = 0;
335        status.pause = 0;
336        status.play = 1;
337        *playinfobarstatus = 1;
338        *playinfobarcount = 0;
339        screenplayinfobar(file, 0, flag);
340}
341
342void playrcjumpf(char* file, int sec, int* playinfobarstatus, int* playinfobarcount, int flag)
343{
344        unsigned long long int pos = 0;
345       
346        if(status.pause == 0 && status.playspeed == 0)
347        {
348                //a jump over the beginning of the
349                //file, freez the player
350                pos = playergetpts() / 90000;
351                if(pos > sec)
352                        playerseek(sec * -1);
353                else
354                        playerseek(pos * -1);
355
356                *playinfobarstatus = 1;
357                *playinfobarcount = 0;
358                screenplayinfobar(file, 0, flag);
359        }
360}
361
362void playrcjumpr(char* file, int sec, int* playinfobarstatus, int* playinfobarcount, int flag)
363{
364        if(status.pause == 0 && status.playspeed == 0)
365        {
366                playerseek(sec);
367                *playinfobarstatus = 1;
368                *playinfobarcount = 0;
369                screenplayinfobar(file, 0, flag);
370        }
371}
372
373void playchangecodec()
374{
375        char** tracklist = NULL;
376
377        if(getconfigint("av_ac3default", NULL) == 1)
378        {
379                int i = 0;
380                tracklist = playergettracklist(1);
381                if(tracklist != NULL)
382                {
383                        while(tracklist[i] != NULL)
384                        {
385                                if(ostrcmp(tracklist[i + 1], "A_AC3") == 0)
386                                        playerchangeaudiotrack(i / 2);
387                                i += 2;
388                        }
389                }
390                playerfreetracklist(tracklist); tracklist = NULL;
391        }
392}
393
394int playcheckdirrcret(char* file, int dirrcret)
395{
396        int ret = 0;
397        char* epgfilename = NULL, *tmpstr = NULL;
398
399        if(dirrcret == 3)
400        {
401                epgfilename = changefilenameext(file, ".epg");
402
403                tmpstr = readfiletomem(epgfilename, 0);
404                if(tmpstr != NULL)
405                        textbox(_("EPG Info"), tmpstr, _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 700, 600, 0, 2);
406
407                free(epgfilename); epgfilename = NULL;
408                free(tmpstr); tmpstr = NULL;
409                ret = 1;
410        }
411        if(dirrcret == 4)
412        {
413                if(textbox(_("Realy Delete ?"), file, _("EXIT"), getrcconfigint("rcexit", NULL), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 2)
414                {
415                        unlink(file);
416                        epgfilename = changefilenameext(file, ".epg");
417                        unlink(epgfilename);
418                        free(epgfilename); epgfilename = NULL;
419                }
420                ret = 1;
421        }
422       
423        return ret;
424}
425
426void playwritevfd(char* file)
427{
428        char* tmpstr = NULL;
429
430        tmpstr = ostrcat(file, "", 0, 0);
431        if(tmpstr != NULL) writevfd(basename(tmpstr));
432        free(tmpstr); tmpstr = NULL;
433}
434
435// flag 0 = dirlist/playing/infobar
436// flag 1 = playing/infobar
437// flag 2 = playing
438void screenplay(int flag)
439{
440        int rcret = 0;
441        char* file = NULL, *tmpstr = NULL;
442        char* tmppolicy = NULL;
443        struct skin* playinfobar = getscreen("playinfobar");
444
445        int skip13 = getconfigint("skip13", NULL);
446        int skip46 = getconfigint("skip46", NULL);
447        int skip79 = getconfigint("skip79", NULL);
448       
449        rcret = servicestop(status.aktservice, 1, 1);
450        if(rcret == 1) return;
451        status.updatevfd = PAUSE;
452        tmppolicy = getpolicy();
453
454playerstart:
455        status.playspeed = 0, status.play = 0, status.pause = 0;
456        int playinfobarcount = 0, playinfobarstatus = 1, dirrcret = 0;
457
458        tmpstr = ostrcat(file, "", 1, 0); file = NULL;
459        file = screendir(getconfig("rec_moviepath", NULL), "*.avi *.dat *.divx *.flv *.mkv *.m4v *.mp4 *.mov *.mpg *.mpeg *.mts *.m2ts *.trp *.ts *.vdr *.vob *.wmv *.rm", basename(tmpstr), &dirrcret, ".epg", "OK", 0, NULL, 0, "EPG", getrcconfigint("rcyellow", NULL), "Del", getrcconfigint("rcred", NULL), 90, 1, 90, 1, 0);
460        free(tmpstr); tmpstr = NULL;
461
462        if(file != NULL)
463        {
464                tmpstr = ostrcat(file, "", 0, 0);
465                if(tmpstr != NULL) addconfig("rec_moviepath", dirname(tmpstr));
466                free(tmpstr); tmpstr = NULL;
467               
468                if(playcheckdirrcret(file, dirrcret) == 1)
469                        goto playerstart;
470
471                drawscreen(skin, 0);
472                playwritevfd(file);
473                rcret = playerstart(file);
474#ifndef SIMULATE
475                if(rcret != 0)
476                {
477                        textbox(_("Message"), _("Can't start playback !"), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
478                        writevfd("Player");
479                        goto playerstart;
480                }
481#endif
482                screenplayinfobar(file, 0, flag);
483
484                //change codec if ac3default and video has ac3
485                //deaktivate, freeze player, makes a seek -5
486                //see eplayer container_ffmpeg_switch_audio
487                //the seek to the beginning of the file freez
488                //eplayer.
489                //playchangecodec();
490
491                while(1)
492                {
493                        while(playerisplaying())
494                        {
495                                rcret = waitrc(playinfobar, 1000, 0);
496                                playinfobarcount++;
497                                if(playinfobarstatus > 0)
498                                        screenplayinfobar(file, 0, flag);
499                                if(playinfobarstatus == 1 && playinfobarcount >= getconfigint("infobartimeout", NULL))
500                                {
501                                        playinfobarstatus = 0;
502                                        screenplayinfobar(NULL, 1, flag);
503                                }
504
505                                if(rcret == getrcconfigint("rcyellow", NULL))
506                                        playrcyellow(file, playinfobarstatus, flag);
507                               
508                                if(rcret == getrcconfigint("rctext", NULL))
509                                        playrctext(file, playinfobarstatus, flag);
510                                       
511                                if(rcret == getrcconfigint("rcgreen", NULL))
512                                        playrcgreen(file, playinfobarstatus, flag);
513                                       
514                                if(rcret == getrcconfigint("rcblue", NULL))
515                                        playrcblue(file, playinfobarstatus, flag);
516                                       
517                                if(rcret == getrcconfigint("rcok", NULL))
518                                        playrcok(file, playinfobarstatus, flag);
519                               
520                                if(rcret == getrcconfigint("rcred", NULL))
521                                        playrcred(file, playinfobarstatus, flag);
522
523                                if(rcret == getrcconfigint("rcinfo", NULL))
524                                        playrcinfo(file, &playinfobarstatus, &playinfobarcount, flag);
525                               
526                                if(rcret == getrcconfigint("rcstop", NULL))
527                                {
528                                        playrcstop(flag);
529                                        goto playerstart;
530                                }
531
532                                if(rcret == getrcconfigint("rcff", NULL))
533                                        playrcff(file, &playinfobarstatus, &playinfobarcount, flag);
534                               
535                                if(rcret == getrcconfigint("rcfr", NULL))
536                                        playrcfr(file, &playinfobarstatus, &playinfobarcount, flag);
537
538                                if(rcret == getrcconfigint("rcpause", NULL))
539                                        playrcpause(file, &playinfobarstatus, &playinfobarcount, flag);
540
541                                if(rcret == getrcconfigint("rcplay", NULL))
542                                        playrcplay(file, &playinfobarstatus, &playinfobarcount, flag);
543
544                                if(rcret == getrcconfigint("rcleft", NULL))
545                                        playrcjumpf(file, 60, &playinfobarstatus, &playinfobarcount, flag);
546                               
547                                if(rcret == getrcconfigint("rc1", NULL))
548                                        playrcjumpf(file, skip13, &playinfobarstatus, &playinfobarcount, flag);
549                               
550                                if(rcret == getrcconfigint("rc4", NULL))
551                                        playrcjumpf(file, skip46, &playinfobarstatus, &playinfobarcount, flag);
552                               
553                                if(rcret == getrcconfigint("rc7", NULL))
554                                        playrcjumpf(file, skip79, &playinfobarstatus, &playinfobarcount, flag);
555                               
556                                if(rcret == getrcconfigint("rcright", NULL))
557                                        playrcjumpr(file, 60, &playinfobarstatus, &playinfobarcount, flag);
558                               
559                                if(rcret == getrcconfigint("rc3", NULL))
560                                        playrcjumpr(file, skip13, &playinfobarstatus, &playinfobarcount, flag);
561                               
562                                if(rcret == getrcconfigint("rc6", NULL))
563                                        playrcjumpr(file, skip46, &playinfobarstatus, &playinfobarcount, flag);
564                               
565                                if(rcret == getrcconfigint("rc9", NULL))
566                                        playrcjumpr(file, skip79, &playinfobarstatus, &playinfobarcount, flag);
567                        }
568                        //don't change this sleep, without this
569                        //the player stops to fast, and a last seek can
570                        //produce a segfault
571                        sleep(1);
572                        playerafterend();
573                        writevfd("Player");
574                        screenplayinfobar(file, 1, flag);
575                        goto playerstart;
576                }
577        }
578
579        tmpstr = ostrcat(status.lastservice->channellist, NULL, 0, 0);
580        servicecheckret(servicestart(status.lastservice->channel, tmpstr, NULL, 0), 0);
581        free(tmpstr); tmpstr = NULL;
582        status.updatevfd = START;
583
584        if(tmppolicy != NULL)
585        {
586                setpolicy(tmppolicy);
587                free(tmppolicy);
588        }
589
590        status.playspeed = 0;
591        status.pause = 0;
592        status.play = 0;
593        free(file);
594}
595
596#endif
Note: See TracBrowser for help on using the repository browser.