source: titan/titan/pip.h @ 35769

Last change on this file since 35769 was 35239, checked in by gost, 9 years ago

[titan] mipsel/sh4 new dmxopen

File size: 15.6 KB
Line 
1#ifndef PIP_H
2#define PIP_H
3
4//flag 0: channel
5//flag 1: playback
6//flag 3: same as 0 but don't check chnode
7//flag 4: same as 0 but new tuning
8//flag 5: same as 3 but new tuning
9int pipstartreal(struct channel* chnode, char* pin, int flag)
10{
11        struct transponder* tpnode = NULL;
12        struct dvbdev *fenode = NULL;
13        struct dvbdev *dmxvideonode = NULL;
14        struct dvbdev *videonode = NULL;
15        int ret = 0, festatus = 1;
16        unsigned char *patbuf = NULL;
17        int checkpmt = 0, pincheck = 0, ageprotect = 0, tune = 0;
18        struct epg* epgnode = NULL;
19
20        m_lock(&status.servicemutex, 2);
21
22        status.secondzap = 0;
23
24        if(flag == 4 || flag == 5) tune = 1;
25        if(flag == 4) flag = 0;
26
27        if(flag == 0 && status.pipservice->type == CHANNEL && status.pipservice->channel != NULL && chnode == status.pipservice->channel)
28        {
29                m_unlock(&status.servicemutex, 2);
30                return 20;
31        }
32        if(flag == 3 || flag == 5) flag = 0;
33
34        if(chnode == NULL)
35        {
36                m_unlock(&status.servicemutex, 2);
37                return 21;
38        }
39       
40        ageprotect = getconfigint("ageprotect", NULL);
41        if(ageprotect > 0) epgnode = getepgakt(chnode);
42        if(chnode->protect > 0 || (epgnode != NULL && epgnode->parentalrating >= ageprotect))
43        {
44                pincheck = screenpincheck(1, pin);
45                if(pincheck == 1)
46                {
47                        m_unlock(&status.servicemutex, 2);
48                        return 22;
49                }
50        }
51
52        //got transponder
53        if(flag == 0)
54        {
55                if(chnode->transponder == NULL)
56                        tpnode = gettransponder(chnode->transponderid);
57                else
58                        tpnode = chnode->transponder;
59        }
60
61        ret = pipstop(status.pipservice, 0);
62
63        //can't stop service (timeshift ??)
64        if(ret == 1)
65        {
66                m_unlock(&status.servicemutex, 2);
67                return 22;
68        }
69       
70        status.pipservice->transponder = tpnode;
71        status.pipservice->channel = chnode;
72        status.pipservice->type = CHANNEL;
73        free(status.pipservice->channellist);
74        status.pipservice->channellist = ostrcat(status.aktservice->channellist, NULL, 0, 0);
75       
76
77        //got frontend dev
78        if(flag == 0)
79        {
80                fenode = fegetfree(tpnode, 0, NULL);
81                if(fenode == NULL)
82                {
83                        m_unlock(&status.servicemutex, 2);
84                        return 1;
85                }
86
87                status.pipservice->fedev = fenode;
88               
89                //frontend tune
90                if(fenode->felasttransponder != tpnode || tune == 1)
91                {
92                        if(fenode->feinfo->type == FE_QPSK)
93                        {
94                                feset(fenode, tpnode);
95                                fetunedvbs(fenode, tpnode);
96                        }
97                        else if(fenode->feinfo->type == FE_QAM)
98                                fetunedvbc(fenode, tpnode);
99                        else if(fenode->feinfo->type == FE_OFDM)
100                                fetunedvbt(fenode, tpnode);
101                        else
102                        {
103                                m_unlock(&status.servicemutex, 2);
104                                return 3;
105                        }
106                }
107        }
108        else if(flag == 1)
109        {
110                fenode = fegetdummy();
111                status.pipservice->fedev = fenode;
112        }
113
114        if(fenode == NULL)
115        {
116                m_unlock(&status.servicemutex, 2);
117                return 1;
118        }
119
120        //check pmt if not all infos in channellist
121        if(chnode->videopid == -1 || chnode->videocodec == -1)
122        {
123                //wait for tuner lock
124                if(flag == 0)
125                {
126                        if(fenode->felasttransponder != tpnode)
127                                festatus = fewait(fenode);
128                        else
129                                festatus = fegetunlock(fenode);
130
131                        if(debug_level == 200) 
132                        {
133                                fereadstatus(fenode);
134                                fegetfrontend(fenode);
135                        }
136                        if(festatus != 0)
137                        {
138                                m_unlock(&status.servicemutex, 2);
139                                return 2;
140                        }
141                }
142
143                checkpmt = 1;
144                if(flag != 1 || (flag == 1 && chnode->pmtpid == 0))
145                {
146                        patbuf = dvbgetpat(fenode, -1);
147                        if(patbuf == NULL) status.secondzap = 1;
148                }
149                free(status.pipservice->pmtbuf);
150                status.pipservice->pmtbuf = NULL;
151                status.pipservice->pmtlen = 0;
152                if(patbuf != NULL)
153                        status.pipservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.pipservice->pmtlen, -1, 0);
154                else if(chnode->pmtpid > 0)
155                        status.pipservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.pipservice->pmtlen, -1, 1);
156
157                if(status.pipservice->pmtbuf == NULL) status.secondzap = 2;
158                dvbgetinfo(status.pipservice->pmtbuf, chnode);
159
160                if(flag == 0) sendcapmt(status.pipservice, 0, 0);
161                free(patbuf);
162        }
163
164        if(flag != 0) checkpmt = 1;
165
166        //demux video start
167        if(chnode->videopid > 0)
168        {
169                if(status.pipservice->dmxvideodev != NULL && status.pipservice->dmxvideodev->fd >= 0 && status.pipservice->dmxvideodev->adapter == fenode->adapter && status.pipservice->dmxvideodev->devnr == fenode->devnr)
170                        dmxvideonode = status.pipservice->dmxvideodev;
171                else
172                {
173                        dmxclose(status.pipservice->dmxvideodev, -1);
174                        dmxvideonode = dmxopen(fenode, 2);
175                        if(dmxsetbuffersize(dmxvideonode, getconfigint("dmxvideobuffersize", NULL)) != 0)
176                        {
177                                dmxclose(dmxvideonode, -1);
178                                dmxvideonode = NULL;
179                        }
180                        status.pipservice->dmxvideodev = dmxvideonode;
181                }
182                if(dmxvideonode != NULL)
183                {
184                        if(dmxsetsource(dmxvideonode, fenode->fedmxsource) != 0)
185                        {
186                                dmxclose(dmxvideonode, -1);
187                                dmxvideonode = NULL;
188                        }
189                        if(dmxsetpesfilter(dmxvideonode, chnode->videopid, -1, DMX_OUT_DECODER, DMX_PES_VIDEO1, 0) != 0)
190                        {
191                                dmxclose(dmxvideonode, -1);
192                                dmxvideonode = NULL;
193                        }
194                }
195                else
196                        err("demux video dev not ok");
197        }
198        else
199        {
200                err("dmx videopid not valid (%d)", chnode->videopid);
201                dmxclose(status.pipservice->dmxvideodev, -1);
202        }
203
204        status.pipservice->dmxvideodev = dmxvideonode;
205
206        //video start
207        if(dmxvideonode != NULL)
208        {
209                if(status.pipservice->videodev != NULL && status.pipservice->videodev->fd >= 0 && status.pipservice->videodev->adapter == fenode->adapter)
210                        videonode = status.pipservice->videodev;
211                else
212                {
213                        videoclose(status.pipservice->videodev, -1);
214                        videonode = videoopen(fenode->adapter, 1);
215                        status.pipservice->videodev = videonode;
216                }
217                if(videonode != NULL)
218                {
219                        videoselectsource(videonode, VIDEO_SOURCE_DEMUX);
220                        if(chnode->videocodec == VC1)
221                        {
222                                videosetstreamtype(videonode, 1); //transportstream
223                                videosetencoding(videonode, chnode->videocodec);
224                        }
225                        else
226                                videosetstreamtype(videonode, chnode->videocodec);
227                        videoplay(videonode);
228                }
229                else
230                        err("can't get free video dev");
231        }
232
233        //check pmt if not done
234        if(checkpmt == 0)
235        {
236                //wait for tuner lock
237                if(flag == 0)
238                {
239                        if(fenode->felasttransponder != tpnode)
240                                festatus = fewait(fenode);
241                        else
242                                festatus = fegetunlock(fenode);
243
244                        if(debug_level == 200)
245                        {
246                                fereadstatus(fenode);
247                                fegetfrontend(fenode);
248                        }
249                        if(festatus != 0)
250                        {
251                                m_unlock(&status.servicemutex, 2);
252                                return 2;
253                        }
254                }
255                checkpmt = 1;
256                patbuf = dvbgetpat(fenode, -1);
257                if(patbuf == NULL) status.secondzap = 3;
258                free(status.pipservice->pmtbuf);
259                status.pipservice->pmtbuf = NULL;
260                status.pipservice->pmtlen = 0;
261                if(patbuf != NULL)
262                        status.pipservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.pipservice->pmtlen, -1, 0);
263                else if(chnode->pmtpid > 0)
264                        status.pipservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.pipservice->pmtlen, -1, 1);
265
266                if(status.pipservice->pmtbuf == NULL) status.secondzap = 4;
267                if(dvbgetinfo(status.pipservice->pmtbuf, chnode) == 1)
268                {
269                        //audio or video pid or codec changed
270                        free(status.pipservice->pmtbuf);
271                        status.pipservice->pmtbuf = NULL;
272                        status.pipservice->pmtlen = 0;
273                }
274
275                if(flag == 0) sendcapmt(status.pipservice, 0, 0);
276                free(patbuf);
277        }
278        if(flag == 0)
279        {
280                festatus = fewait(fenode);
281                if(festatus != 0)
282                {
283                        m_unlock(&status.servicemutex, 2);
284                        return 2;
285                }
286        }
287        m_unlock(&status.servicemutex, 2);
288        return 0;
289}
290
291int setvmpeg2(struct dvbdev* node, int value, int flag)
292{
293        debug(4440, "in");
294        char* vmpegdev = NULL, *tmpstr = NULL, *buf = NULL;
295        int ret = 0;
296
297        if(node == NULL) return 1;
298        if(flag == 0)  vmpegdev = getconfig("vmpegleftdev", NULL);
299        if(flag == 1)  vmpegdev = getconfig("vmpegtopdev", NULL);
300        if(flag == 2)  vmpegdev = getconfig("vmpegwidthdev", NULL);
301        if(flag == 3)  vmpegdev = getconfig("vmpegheightdev", NULL);
302        if(flag == 99) vmpegdev = getconfig("vmpegapplydev", NULL);
303
304        if(vmpegdev != NULL)
305        {
306                buf = malloc(MINMALLOC);
307                if(buf == NULL)
308                {
309                        err("no mem");
310                        return 1;
311                }
312               
313                tmpstr = malloc(10);
314                if(tmpstr == NULL)
315                {
316                        err("no mem");
317                        free(buf);
318                        return 1;
319                }
320               
321                snprintf(buf, MINMALLOC, vmpegdev, node->devnr);
322                snprintf(tmpstr, 10, "%x", value);
323                debug(444, "set %s to %s", buf, tmpstr);
324                status.tvpic = 1;
325                ret = writesys(buf, tmpstr, 1);
326               
327                free(tmpstr);
328                free(buf);
329                return ret;
330        }
331
332        debug(4440, "out");
333        return 0;
334}
335
336// flag = 0 --> nicht aktivieren
337// flag = 1 --> aktiviere Einstellungen
338int pippos(struct dvbdev* node, int dst_width, int dst_height, int dst_left, int dst_top, int flag)
339{
340        int ret = 0;
341       
342        if(node == NULL) return 1;
343       
344        ret = setvmpeg2(node, dst_left, 0);
345        ret = setvmpeg2(node, dst_top, 1);
346        ret = setvmpeg2(node, dst_width, 2);
347        ret = setvmpeg2(node, dst_height, 3);
348       
349        if(flag == 1) ret = setvmpeg2(node, 0, 99);
350       
351        return ret;
352}
353
354
355//second zap on failure
356//TODO: use flag 6 (same as 5 but no pin question on second tune)
357int pipstart(struct channel* chnode, char* pin, int flag)
358{
359        int ret = 0;
360
361        int dst_width = getconfigint("pip_dst_width", NULL);
362        int dst_height = getconfigint("pip_dst_height", NULL);
363        int dst_left = getconfigint("pip_dst_left", NULL);
364        int dst_top = getconfigint("pip_dst_top", NULL);
365
366        if(dst_width == 0) dst_width = 180;
367        if(dst_height == 0) dst_height = 144;
368        if(dst_left == 0) dst_left = 505;
369        if(dst_top == 0) dst_top = 36;
370
371        if(status.pipservice->type == CHANNEL)
372                pipstop(status.pipservice, 1);
373       
374        ret = pipstartreal(chnode, pin, flag);
375       
376        if(status.secondzap != 0 && ret == 0 && (flag == 0 || flag > 2))
377        {
378                debug(200, "first zap not ok, make second zap (%d)", status.secondzap);
379                ret = pipstartreal(chnode, pin, 5);
380        }
381
382        if(ret == 0)
383        {
384                status.pipservice->fedev->felock++;
385                deltranspondertunablestatus();
386                ret = pippos(status.pipservice->videodev, dst_width, dst_height, dst_left, dst_top, 1);
387                status.pipzap = getconfigint("pip_zap", NULL);
388        }
389
390        return ret;
391}
392
393int pipstop(struct service *node, int flag)
394{
395
396        if(node != NULL)
397        {
398                if(node->dmxvideodev != NULL)
399                {
400                        node->fedev->felock--;
401                        deltranspondertunablestatus();
402                        if(node->type != NOTHING && node->type != STILLPIC) caservicedel(node, NULL);
403                }
404
405                node->type = NOTHING;
406
407                videostop(node->videodev, 1);
408                videoclose(node->videodev, -1);
409               
410                if(flag == 0)
411                        pippos(node->videodev, 0, 0, 0, 0, 1);
412               
413                node->videodev = NULL;
414               
415                if(node->dmxvideodev != NULL)
416                {
417                        dmxstop(node->dmxvideodev);
418                        dmxclose(node->dmxvideodev, -1);
419                        node->dmxvideodev = NULL;
420                }
421                status.pipzap = 0;             
422                return 0;
423        }
424        return 1;
425}
426
427int piphdmi(struct service *node, int flag)
428{
429        struct dvbdev *videonode = NULL;
430       
431        if(node != NULL && node->type != NOTHING && node->type != HDMIIN)
432                pipstop(status.pipservice, 1);
433       
434        videonode = videoopen(0, 1);
435        node->videodev = videonode;
436        node->type = HDMIIN;
437       
438        if(videonode != NULL)
439        {
440                videoselectsource(videonode, VIDEO_SOURCE_HDMI);
441                videosetstreamtype(videonode, 0);
442                videoplay(videonode);
443        }
444        status.pipzap = 0;
445       
446        return 0;
447}
448
449int pipswap(struct service *node)
450{
451        int hdmi = 0;
452        char* tmpstr = NULL;
453        struct channel* chnodeP = node->channel;
454        struct channel* chnodeT = status.aktservice->channel;
455        if(node->type == CHANNEL && chnodeP != NULL && chnodeP != chnodeT)
456        {
457                if(status.aktservice->type == HDMIIN)
458                {
459                        hdmi = 1;
460                        pipstop(node, 1);
461                }
462                else
463                        pipstop(node, 0);
464                tmpstr = ostrcat(node->channellist, NULL, 0, 0);
465                servicecheckret(servicestart(chnodeP, tmpstr, NULL, 0), 0);
466                free(tmpstr); tmpstr = NULL;
467                if(hdmi == 1)
468                {
469                        piphdmi(node, 0);
470                        free(node->channellist);
471                        node->channellist = NULL;
472                        node->channellist = ostrcat(status.lastservice->channellist, NULL, 0, 0);
473                }
474                else
475                {
476                        pipstart(chnodeT, NULL, 0);
477                        free(node->channellist);
478                        node->channellist = NULL;
479                        node->channellist = ostrcat(status.lastservice->channellist, NULL, 0, 0);
480                }
481        }
482#ifdef MIPSEL
483        else if(node->type == HDMIIN)
484        {
485                pipstop(node, 0);
486                servicestop(status.aktservice, 1, 1);
487                servicefullHDMIin_start();
488                pipstart(chnodeT, NULL, 0);
489                free(node->channellist);
490                node->channellist = ostrcat(status.lastservice->channellist, NULL, 0, 0);
491        }
492#endif
493        else
494        {
495                return 1;
496        }
497        return 0;
498}
499       
500       
501
502void pipmenu()
503{
504        struct skin* pipscreen = getscreen("pipscreen");
505        struct skin* hdmi = getscreennode(pipscreen, "hdmi");
506        int rcret = 0;
507       
508        int dst_width = getconfigint("pip_dst_width", NULL);
509        int dst_height = getconfigint("pip_dst_height", NULL);
510        int dst_left = getconfigint("pip_dst_left", NULL);
511        int dst_top = getconfigint("pip_dst_top", NULL);
512
513        if(dst_width == 0)
514        {
515                dst_width = 180;
516                dst_height = 144;
517        }
518        if(dst_height == 0)
519        {
520                dst_width = 180;
521                dst_height = 144;
522        }
523        if(dst_left == 0) dst_left = 505;
524        if(dst_top == 0) dst_top = 36;
525               
526        if(status.aktservice->type == HDMIIN)
527                changetext(hdmi, "no function");
528        else if(status.pipservice->type == HDMIIN)
529                changetext(hdmi, "live TV");
530        else
531                changetext(hdmi, "HDMI-in");
532       
533        while(1)
534        {
535                drawscreen(pipscreen, 0, 0);
536                rcret = waitrc(pipscreen, 0, 0);
537                clearscreen(pipscreen);
538               
539                if(rcret == getrcconfigint("rcexit", NULL))
540                {
541                        pipstop(status.pipservice, 0);
542                        break;
543                }
544                       
545                if(rcret == getrcconfigint("rcok", NULL))
546                {
547                        addconfigint("pip_dst_width", dst_width);
548                        addconfigint("pip_dst_height", dst_height);
549                        addconfigint("pip_dst_left", dst_left);
550                        addconfigint("pip_dst_top", dst_top);
551                        break;
552                }
553               
554                if(rcret == getrcconfigint("rcred", NULL))
555                {
556                        if(status.aktservice->type == HDMIIN)
557                                continue;
558                        if(status.pipservice->type == HDMIIN)
559                        {
560                                pipstop(status.pipservice, 1);
561                                pipstart(status.aktservice->channel, NULL, 0);
562                                changetext(hdmi, "HDMI-in");
563                        }
564                        else
565                        {
566                                piphdmi(status.pipservice, 0);
567                                changetext(hdmi, "live TV");
568                        }
569                        continue;
570                }
571               
572                if(rcret == getrcconfigint("rcblue", NULL))
573                {
574                        pipswap(status.pipservice);
575                        if(status.aktservice->type == HDMIIN)
576                                changetext(hdmi, "no function");
577                        else if(status.pipservice->type != HDMIIN)
578                                changetext(hdmi, "HDMI-in");
579                        else
580                                changetext(hdmi, "live TV");
581                        continue;
582                }
583                       
584                if(rcret == getrcconfigint("rcdown", NULL))
585                {
586                        if(dst_top+1 < 576-dst_height) dst_top++;
587                }
588                if(rcret == getrcconfigint("rcup", NULL))
589                {
590                        if(dst_top-1 > 0) dst_top--;
591                }
592                if(rcret == getrcconfigint("rcleft", NULL))
593                {
594                        if(dst_left-1 > 0) dst_left--;
595                }
596                if(rcret == getrcconfigint("rcright", NULL))
597                {
598                        if(dst_left+1 < 720-dst_width) dst_left++;
599                }
600               
601                if(rcret == getrcconfigint("rcchdown", NULL))
602                {
603                        if(dst_width-4 > 10)
604                        {
605                                dst_width = dst_width - 4;
606                                dst_height = 576 * dst_width / 720;
607                        }
608                }
609                if(rcret == getrcconfigint("rcchup", NULL))
610                {
611                        if(dst_width+4 < 720)
612                        {
613                                dst_width = dst_width + 4;
614                                dst_height = 576 * dst_width / 720;
615                               
616                                if(dst_width + dst_left > 720)
617                                        dst_left = 720 - dst_width;
618                                       
619                                if(dst_height + dst_top > 576)
620                                        dst_top = 576 - dst_height;
621                        }
622                }
623                pippos(status.pipservice->videodev, dst_width, dst_height, dst_left, dst_top, 1);
624        }
625}
626       
627void pipsetup()
628{
629        struct skin* pipmenu = getscreen("pipsetup");
630        struct skin* kchupdown = getscreennode(pipmenu, "pipzap");
631        struct skin* kpip = getscreennode(pipmenu, "pip");
632        struct skin* k0 = getscreennode(pipmenu, "null");
633       
634        struct skin* listbox = getscreennode(pipmenu, "listbox");
635        struct skin* tmp = NULL;
636
637        int rcret = 0;
638       
639        addchoicebox(k0, "0", _("default"));
640        addchoicebox(k0, "1", _("->swap<-"));
641        setchoiceboxselection(k0, getconfig("pip_swap", NULL));
642       
643        addchoicebox(kpip, "0", _("pip menu"));
644        addchoicebox(kpip, "1", _("pip end"));
645        setchoiceboxselection(kpip, getconfig("pip_screen", NULL));
646       
647        addchoicebox(kchupdown, "0", _("default"));
648        addchoicebox(kchupdown, "1", _("pip zap"));
649        setchoiceboxselection(kchupdown, getconfig("pip_zap", NULL));
650       
651        drawscreen(pipmenu, 0, 0);
652        addscreenrc(pipmenu, listbox);
653        tmp = listbox->select;
654       
655        while(1)
656        {
657                addscreenrc(pipmenu, tmp);
658                rcret = waitrc(pipmenu, 0, 0);
659                tmp = listbox->select;
660               
661                if(rcret == getrcconfigint("rcexit", NULL))
662                        break;
663                if(rcret == getrcconfigint("rcok", NULL))       
664                {
665                        addconfig("pip_swap", k0->ret);
666                        addconfig("pip_screen", kpip->ret);
667                        addconfig("pip_zap", kchupdown->ret);
668                        break;
669                }
670                drawscreen(pipmenu, 0, 0);
671        }
672        delownerrc(pipmenu);
673        clearscreen(pipmenu);
674}
675
676
677#endif
Note: See TracBrowser for help on using the repository browser.