source: titan/titan/pip.h @ 39992

Last change on this file since 39992 was 39992, checked in by gost, 7 years ago

dm900.. deactivate hdmi-in pip

File size: 15.8 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        struct skin* b3 = getscreennode(pipscreen, "b3");
507        int rcret = 0;
508       
509        int dst_width = getconfigint("pip_dst_width", NULL);
510        int dst_height = getconfigint("pip_dst_height", NULL);
511        int dst_left = getconfigint("pip_dst_left", NULL);
512        int dst_top = getconfigint("pip_dst_top", NULL);
513
514        if(checkbox("DM900") == 1)
515        {
516                b3->hidden = YES;
517                hdmi->hidden = YES;
518        }
519       
520        if(dst_width == 0)
521        {
522                dst_width = 180;
523                dst_height = 144;
524        }
525        if(dst_height == 0)
526        {
527                dst_width = 180;
528                dst_height = 144;
529        }
530        if(dst_left == 0) dst_left = 505;
531        if(dst_top == 0) dst_top = 36;
532               
533        if(status.aktservice->type == HDMIIN)
534                changetext(hdmi, "no function");
535        else if(status.pipservice->type == HDMIIN)
536                changetext(hdmi, "live TV");
537        else
538                changetext(hdmi, "HDMI-in");
539       
540        while(1)
541        {
542                drawscreen(pipscreen, 0, 0);
543                rcret = waitrc(pipscreen, 0, 0);
544                clearscreen(pipscreen);
545               
546                if(rcret == getrcconfigint("rcexit", NULL))
547                {
548                        pipstop(status.pipservice, 0);
549                        break;
550                }
551                       
552                if(rcret == getrcconfigint("rcok", NULL))
553                {
554                        addconfigint("pip_dst_width", dst_width);
555                        addconfigint("pip_dst_height", dst_height);
556                        addconfigint("pip_dst_left", dst_left);
557                        addconfigint("pip_dst_top", dst_top);
558                        break;
559                }
560                if(checkbox("DM900") != 1)
561                {
562                        if(rcret == getrcconfigint("rcred", NULL))
563                        {
564                                if(status.aktservice->type == HDMIIN)
565                                        continue;
566                                if(status.pipservice->type == HDMIIN)
567                                {
568                                        pipstop(status.pipservice, 1);
569                                        pipstart(status.aktservice->channel, NULL, 0);
570                                        changetext(hdmi, "HDMI-in");
571                                }
572                                else
573                                {
574                                        piphdmi(status.pipservice, 0);
575                                        changetext(hdmi, "live TV");
576                                }
577                                continue;
578                        }
579                }
580               
581                if(rcret == getrcconfigint("rcblue", NULL))
582                {
583                        pipswap(status.pipservice);
584                        if(status.aktservice->type == HDMIIN)
585                                changetext(hdmi, "no function");
586                        else if(status.pipservice->type != HDMIIN)
587                                changetext(hdmi, "HDMI-in");
588                        else
589                                changetext(hdmi, "live TV");
590                        continue;
591                }
592                       
593                if(rcret == getrcconfigint("rcdown", NULL))
594                {
595                        if(dst_top+1 < 576-dst_height) dst_top++;
596                }
597                if(rcret == getrcconfigint("rcup", NULL))
598                {
599                        if(dst_top-1 > 0) dst_top--;
600                }
601                if(rcret == getrcconfigint("rcleft", NULL))
602                {
603                        if(dst_left-1 > 0) dst_left--;
604                }
605                if(rcret == getrcconfigint("rcright", NULL))
606                {
607                        if(dst_left+1 < 720-dst_width) dst_left++;
608                }
609               
610                if(rcret == getrcconfigint("rcchdown", NULL))
611                {
612                        if(dst_width-4 > 10)
613                        {
614                                dst_width = dst_width - 4;
615                                dst_height = 576 * dst_width / 720;
616                        }
617                }
618                if(rcret == getrcconfigint("rcchup", NULL))
619                {
620                        if(dst_width+4 < 720)
621                        {
622                                dst_width = dst_width + 4;
623                                dst_height = 576 * dst_width / 720;
624                               
625                                if(dst_width + dst_left > 720)
626                                        dst_left = 720 - dst_width;
627                                       
628                                if(dst_height + dst_top > 576)
629                                        dst_top = 576 - dst_height;
630                        }
631                }
632                pippos(status.pipservice->videodev, dst_width, dst_height, dst_left, dst_top, 1);
633        }
634}
635       
636void pipsetup()
637{
638        struct skin* pipmenu = getscreen("pipsetup");
639        struct skin* kchupdown = getscreennode(pipmenu, "pipzap");
640        struct skin* kpip = getscreennode(pipmenu, "pip");
641        struct skin* k0 = getscreennode(pipmenu, "null");
642       
643        struct skin* listbox = getscreennode(pipmenu, "listbox");
644        struct skin* tmp = NULL;
645
646        int rcret = 0;
647       
648        addchoicebox(k0, "0", _("default"));
649        addchoicebox(k0, "1", _("->swap<-"));
650        setchoiceboxselection(k0, getconfig("pip_swap", NULL));
651       
652        addchoicebox(kpip, "0", _("pip menu"));
653        addchoicebox(kpip, "1", _("pip end"));
654        setchoiceboxselection(kpip, getconfig("pip_screen", NULL));
655       
656        addchoicebox(kchupdown, "0", _("default"));
657        addchoicebox(kchupdown, "1", _("pip zap"));
658        setchoiceboxselection(kchupdown, getconfig("pip_zap", NULL));
659       
660        drawscreen(pipmenu, 0, 0);
661        addscreenrc(pipmenu, listbox);
662        tmp = listbox->select;
663       
664        while(1)
665        {
666                addscreenrc(pipmenu, tmp);
667                rcret = waitrc(pipmenu, 0, 0);
668                tmp = listbox->select;
669               
670                if(rcret == getrcconfigint("rcexit", NULL))
671                        break;
672                if(rcret == getrcconfigint("rcok", NULL))       
673                {
674                        addconfig("pip_swap", k0->ret);
675                        addconfig("pip_screen", kpip->ret);
676                        addconfig("pip_zap", kchupdown->ret);
677                        break;
678                }
679                drawscreen(pipmenu, 0, 0);
680        }
681        delownerrc(pipmenu);
682        clearscreen(pipmenu);
683}
684
685
686#endif
Note: See TracBrowser for help on using the repository browser.