source: titan/titan/pip.h @ 31136

Last change on this file since 31136 was 31021, checked in by gost, 9 years ago

[titan] nemesis.. zap pip when config pip_zap=1

File size: 13.4 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);
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        char* tmpstr = NULL;
452        struct channel* chnodeP = node->channel;
453        struct channel* chnodeT = status.aktservice->channel;
454        if(node->type == CHANNEL && chnodeP != NULL && chnodeP != chnodeT)
455        {
456                pipstop(node, 0);
457                tmpstr = ostrcat(node->channellist, NULL, 0, 0);
458                servicecheckret(servicestart(chnodeP, tmpstr, NULL, 0), 0);
459                free(tmpstr); tmpstr = NULL;
460               
461                pipstart(chnodeT, NULL, 0);
462                free(node->channellist);
463                node->channellist = ostrcat(status.lastservice->channellist, NULL, 0, 0);
464        }
465        else
466        {
467                return 1;
468        }
469        return 0;
470}
471       
472       
473
474void pipmenu()
475{
476        struct skin* pipscreen = getscreen("pipscreen");
477        struct skin* hdmi = getscreennode(pipscreen, "hdmi");
478        int rcret = 0;
479       
480        int dst_width = getconfigint("pip_dst_width", NULL);
481        int dst_height = getconfigint("pip_dst_height", NULL);
482        int dst_left = getconfigint("pip_dst_left", NULL);
483        int dst_top = getconfigint("pip_dst_top", NULL);
484
485        if(dst_width == 0)
486        {
487                dst_width = 180;
488                dst_height = 144;
489        }
490        if(dst_height == 0)
491        {
492                dst_width = 180;
493                dst_height = 144;
494        }
495        if(dst_left == 0) dst_left = 505;
496        if(dst_top == 0) dst_top = 36;
497               
498        if(status.pipservice->type == HDMIIN)
499                changetext(hdmi, "live TV");
500       
501        while(1)
502        {
503                drawscreen(pipscreen, 0, 0);
504                rcret = waitrc(pipscreen, 0, 0);
505                clearscreen(pipscreen);
506               
507                if(rcret == getrcconfigint("rcexit", NULL))
508                {
509                        pipstop(status.pipservice, 0);
510                        break;
511                }
512                       
513                if(rcret == getrcconfigint("rcok", NULL))
514                {
515                        addconfigint("pip_dst_width", dst_width);
516                        addconfigint("pip_dst_height", dst_height);
517                        addconfigint("pip_dst_left", dst_left);
518                        addconfigint("pip_dst_top", dst_top);
519                        break;
520                }
521               
522                if(rcret == getrcconfigint("rcred", NULL))
523                {
524                        if(status.pipservice->type == HDMIIN)
525                        {
526                                pipstop(status.pipservice, 1);
527                                pipstart(status.aktservice->channel, NULL, 0);
528                                changetext(hdmi, "HDMI-in");
529                        }
530                        else
531                        {
532                                piphdmi(status.pipservice, 0);
533                                changetext(hdmi, "live TV");
534                        }
535                        continue;
536                }
537               
538                if(rcret == getrcconfigint("rcblue", NULL))
539                {
540                        pipswap(status.pipservice);
541                        continue;
542                }
543                       
544                if(rcret == getrcconfigint("rcdown", NULL))
545                {
546                        if(dst_top+1 < 576-dst_height) dst_top++;
547                }
548                if(rcret == getrcconfigint("rcup", NULL))
549                {
550                        if(dst_top-1 > 0) dst_top--;
551                }
552                if(rcret == getrcconfigint("rcleft", NULL))
553                {
554                        if(dst_left-1 > 0) dst_left--;
555                }
556                if(rcret == getrcconfigint("rcright", NULL))
557                {
558                        if(dst_left+1 < 720-dst_width) dst_left++;
559                }
560               
561                if(rcret == getrcconfigint("rcchdown", NULL))
562                {
563                        if(dst_width-4 > 10)
564                        {
565                                dst_width = dst_width - 4;
566                                dst_height = 576 * dst_width / 720;
567                        }
568                }
569                if(rcret == getrcconfigint("rcchup", NULL))
570                {
571                        if(dst_width+4 < 720)
572                        {
573                                dst_width = dst_width + 4;
574                                dst_height = 576 * dst_width / 720;
575                               
576                                if(dst_width + dst_left > 720)
577                                        dst_left = 720 - dst_width;
578                                       
579                                if(dst_height + dst_top > 576)
580                                        dst_top = 576 - dst_height;
581                        }
582                }
583                pippos(status.pipservice->videodev, dst_width, dst_height, dst_left, dst_top, 1);
584        }
585}
586       
587
588#endif
Note: See TracBrowser for help on using the repository browser.