source: titan/titan/service.h

Last change on this file was 46515, checked in by obi, 15 months ago

dreambox fix channel not found on streamreleay

File size: 31.7 KB
Line 
1#ifndef SERVICE_H
2#define SERVICE_H
3
4void debugservice()
5{
6        struct service* node = service;
7        int count = 0;
8
9        while(node != NULL)
10        {
11                printf("Service %d\n", count);
12                count++;
13
14                if(node->channel != NULL) printf("%s (%llu)\n", node->channel->name, node->channel->transponderid);
15                if(node->transponder != NULL) printf("TransponderID %llu\n", node->transponder->id);
16                if(node->fedev != NULL) printf("%s (%d)\n", node->fedev->dev, node->fedev->fd);
17                if(node->dmxaudiodev != NULL) printf("%s (%d)\n", node->dmxaudiodev->dev, node->dmxaudiodev->fd);
18                if(node->dmxvideodev != NULL) printf("%s (%d)\n", node->dmxvideodev->dev, node->dmxvideodev->fd);
19                if(node->dmxpcrdev != NULL) printf("%s (%d)\n", node->dmxpcrdev->dev, node->dmxpcrdev->fd);
20                if(node->audiodev != NULL) printf("%s (%d)\n", node->audiodev->dev, node->audiodev->fd);
21                if(node->videodev != NULL) printf("%s (%d)\n", node->videodev->dev, node->videodev->fd);
22                node = node->next;
23        }
24}
25
26void serviceresetchannelinfo(struct channel* chnode)
27{
28        if(chnode == NULL) return;
29
30        freeaudiotrack(chnode);
31        freesubtitle(chnode);
32        freepmt(chnode);
33        freecadesc(chnode);
34        freeesinfo(chnode);
35        chnode->txtpid = 0;
36        chnode->pmtpid = 0;
37        chnode->crypt = 0;
38}
39
40void akttolast()
41{
42        if(status.aktservice->fedev != NULL && status.aktservice->fedev->type == FRONTENDDEVDUMMY) return;
43        status.lastservice->fedev = status.aktservice->fedev;
44        status.lastservice->dmxaudiodev = status.aktservice->dmxaudiodev;
45        status.lastservice->dmxvideodev = status.aktservice->dmxvideodev;
46        status.lastservice->dmxpcrdev = status.aktservice->dmxpcrdev;
47        status.lastservice->dmxsubtitledev = status.aktservice->dmxsubtitledev;
48        status.lastservice->audiodev = status.aktservice->audiodev;
49        status.lastservice->videodev = status.aktservice->videodev;
50        status.lastservice->transponder = status.aktservice->transponder;
51        status.lastservice->channel = status.aktservice->channel;
52        free(status.lastservice->channellist);
53        status.lastservice->channellist = ostrcat(status.aktservice->channellist, NULL, 0, 0);
54}
55
56//flag 0: channel
57//flag 1: playback
58//flag 2: timeshift
59//flag 3: same as 0 but don't check chnode
60//flag 4: same as 0 but new tuning
61//flag 5: same as 3 but new tuning
62//flag 6: same as 5 but second zap
63int servicestartreal(struct channel* chnode, char* channellist, char* pin, int flag)
64{
65        struct transponder* tpnode = NULL;
66        struct dvbdev *fenode = NULL;
67        struct dvbdev *dmxaudionode = NULL;
68        struct dvbdev *dmxvideonode = NULL;
69        struct dvbdev *dmxpcrnode = NULL;
70        struct dvbdev *audionode = NULL;
71        struct dvbdev *videonode = NULL;
72        int ret = 0, festatus = 1, tmpmute = 0, i = 0;
73        unsigned char *patbuf = NULL;
74        int checkpmt = 0, pincheck = 0, stopflag = 0, ageprotect = 0, tune = 0, secondzap = 0;
75        struct epg* epgnode = NULL;
76
77        m_lock(&status.servicemutex, 2);
78
79        status.secondzap = 0;
80
81        if(flag == 4 || flag == 5 || flag == 6) tune = 1;
82        if(flag == 6) secondzap = 1;
83        if(flag == 4) flag = 0;
84
85        //wakeup hdd work
86        if(flag == 1 || flag == 2) wakeup_record_device();
87       
88        if(flag == 0 && status.aktservice->type == CHANNEL && status.aktservice->channel != NULL && chnode == status.aktservice->channel)
89        {
90                m_unlock(&status.servicemutex, 2);
91                return 20;
92        }
93        if(flag == 3 || flag == 5 || flag == 6) flag = 0;
94
95        if(chnode == NULL)
96        {
97                m_unlock(&status.servicemutex, 2);
98                return 21;
99        }
100        debug(200, "servicestartreal... started");
101        //stop running autoresolution
102        if(status.restimer != NULL)
103                status.restimer->aktion = STOP;
104
105        if(secondzap == 0)
106        {
107                ageprotect = getconfigint("ageprotect", NULL);
108                if(ageprotect > 0) epgnode = getepgakt(chnode);
109                if(chnode->protect > 0 || (epgnode != NULL && epgnode->parentalrating >= ageprotect))
110                {
111                        pincheck = screenpincheck(1, pin);
112                        if(pincheck == 1)
113                        {
114                                m_unlock(&status.servicemutex, 2);
115                                return 22;
116                        }
117                }
118        }
119
120        //got transponder
121        if(flag == 0)
122        {
123                if(chnode->transponder == NULL)
124                        tpnode = gettransponder(chnode->transponderid);
125                else
126                        tpnode = chnode->transponder;
127        }
128
129        if(flag == 1 || flag == 2)
130                stopflag = 2;
131        else if(secondzap == 1)
132                stopflag = 3;
133        if(getconfigint("nozapclear", NULL) == 1)
134                ret = servicestop(status.aktservice, 0, stopflag);
135        else
136                ret = servicestop(status.aktservice, 1, stopflag);
137
138        //can't stop service (timeshift ??)
139        if(ret == 1)
140        {
141                m_unlock(&status.servicemutex, 2);
142                return 22;
143        }
144
145        //reset channel info
146        if(flag == 0) serviceresetchannelinfo(chnode);
147
148        status.aktservice->transponder = tpnode;
149        status.aktservice->channel = chnode;
150        status.aktservice->type = CHANNEL;
151        if(status.epgthread != NULL) status.epgthread->aktion = PAUSE;
152        if(flag == 0 && status.aktservice->type == CHANNEL)
153                changechannellist(chnode, channellist);
154
155    if(chnode->streamurl != NULL && chnode->epgurl != NULL)
156    {
157        streamplayer(chnode, 1);
158    }
159
160        //got frontend dev
161        if(chnode->epgurl == NULL && flag == 0)
162        {
163                fenode = fegetfree(tpnode, 0, NULL, chnode);
164                if(fenode == NULL)
165                {
166                        sleep(2);
167                        fenode = fegetfree(tpnode, 0, NULL, chnode);
168                        if(fenode == NULL)
169                        {
170                                m_unlock(&status.servicemutex, 2);
171                                return 1;
172                        }
173                }
174               
175#ifdef DREAMBOX
176        if(chnode->streamurl == NULL)
177        {
178                    if(status.aktservice->fedev != fenode)
179                    {
180                            int fastzap = getconfigint("fastzap", NULL);
181                            if(fastzap == 1)
182                            {
183                                    audioclose(status.aktservice->audiodev, -1);
184                                    status.aktservice->audiodev = NULL;
185                                    dmxstop(status.aktservice->dmxaudiodev);
186                                    dmxclose(status.aktservice->dmxaudiodev, -1);
187                                    status.aktservice->dmxaudiodev = NULL;
188                            }
189                            if(fastzap == 1 || fastzap == 2)
190                            {
191                                    videoclose(status.aktservice->videodev, -1);
192                                    status.aktservice->videodev = NULL;
193                                    dmxstop(status.aktservice->dmxvideodev);
194                                    dmxclose(status.aktservice->dmxvideodev, -1);
195                                    status.aktservice->dmxvideodev = NULL;
196                                    dmxstop(status.aktservice->dmxpcrdev);
197                                    dmxclose(status.aktservice->dmxpcrdev, -1);
198                                    status.aktservice->dmxpcrdev = NULL;
199                                    dmxstop(status.aktservice->dmxsubtitledev);
200                                    dmxclose(status.aktservice->dmxsubtitledev, -1);
201                                    status.aktservice->dmxsubtitledev = NULL;
202                            }
203                    }
204        }
205#endif
206                               
207                status.aktservice->fedev = fenode;
208
209                //frontend tune
210                if(fenode->felasttransponder != tpnode || tune == 1)
211                {
212                        if(fenode->feinfo->type == FE_QPSK)
213                        {
214                                feset(fenode, tpnode);
215                                fetunedvbs(fenode, tpnode);
216                        }
217                        else if(fenode->feinfo->type == FE_QAM)
218                                fetunedvbc(fenode, tpnode);
219                        else if(fenode->feinfo->type == FE_OFDM)
220                                fetunedvbt(fenode, tpnode);
221                        else
222                        {
223                                m_unlock(&status.servicemutex, 2);
224                                return 3;
225                        }
226                }
227        }
228        else if(flag == 1 || flag == 2)
229        {
230                fenode = fegetdummy();
231                status.aktservice->fedev = fenode;
232        }
233
234        if(chnode->streamurl == NULL && fenode == NULL)
235        {
236                m_unlock(&status.servicemutex, 2);
237                return 1;
238        }
239
240        //check pmt if not all infos in channellist
241        if((chnode->audiopid == -1 || chnode->videopid == -1 || chnode->pcrpid == -1 || chnode->audiocodec == -1 || chnode->videocodec == -1 || (getconfigint("av_ac3default", NULL) == YES && chnode->audiocodec != AC3)))
242        {
243                //wait for tuner lock
244                if(chnode->streamurl == NULL && flag == 0)
245                {
246                        if(fenode->felasttransponder != tpnode)
247                                festatus = fewait(fenode);
248                        else
249                                festatus = fegetunlock(fenode);
250
251                        if(debug_level == 200) 
252                        {
253                                fereadstatus(fenode);
254                                fegetfrontend(fenode);
255                        }
256                        if(festatus != 0)
257                        {
258                                m_unlock(&status.servicemutex, 2);
259                                return 2;
260                        }
261                }
262
263                checkpmt = 1;
264                if(flag != 1 || (flag == 1 && chnode->pmtpid == 0))
265                {
266                        patbuf = dvbgetpat(fenode, -1);
267                        if(patbuf == NULL) status.secondzap = 1;
268                }
269
270                debug(200, "1-secondzap=%i", status.secondzap);
271                free(status.aktservice->pmtbuf);
272                status.aktservice->pmtbuf = NULL;
273                status.aktservice->pmtlen = 0;
274                if(patbuf != NULL)
275                        status.aktservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 0);
276                else if(chnode->pmtpid > 0)
277                        status.aktservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 1);
278
279                if(status.aktservice->pmtbuf == NULL) status.secondzap = 2;
280                debug(200, "2-secondzap=%i", status.secondzap);
281                dvbgetinfo(status.aktservice->pmtbuf, chnode);
282
283                if(flag == 0)
284                {
285                        if(status.pmtmode == 1)
286                        {
287                                if(recordcheckcrypt(fenode, CHANNEL) == 0)
288                                        dvbwritepmt(status.aktservice, status.aktservice->pmtbuf);
289                                else
290                                        debug(200, "don't write pmt.tmp, another crypt channel use this frontend");
291                        }
292                        else
293                                sendcapmt(status.aktservice, 0, 0);
294                }
295                free(patbuf);
296        }
297
298        if(flag != 0) checkpmt = 1;
299
300        //set mute for scat problem
301#ifdef MIPSEL   
302        if(status.mute != 0)
303        {
304                setmute(0);
305                tmpmute = 1;
306        }
307#else
308        if(status.mute == 0)
309        {
310                tmpmute = 1;
311                //setmute(1);
312                audiosetmute(status.aktservice->audiodev, 1);
313        }
314#endif
315
316        if(chnode->epgurl == NULL)
317    {
318        audiostop(status.aktservice->audiodev);
319
320        if(checkbox("DM900") == 1 || checkbox("DM920") == 1 || checkbox("DM520") == 1 || checkbox("DM525") == 1 || checkchipset("HI3798MV200") == 1)
321                dmxstop(status.aktservice->dmxaudiodev);
322
323// gost test multibox
324        if(checkchipset("HI3798MV200") == 1  || vubox1 == 1)
325        {
326                videostop(status.aktservice->videodev, 1);
327                dmxstop(status.aktservice->dmxvideodev);
328        }
329
330        //demux pcr start
331        if(flag == 0 && chnode->pcrpid > 0)
332        {
333                if(status.aktservice->dmxpcrdev != NULL && status.aktservice->dmxpcrdev->fd >= 0 && status.aktservice->dmxpcrdev->adapter == fenode->adapter && status.aktservice->dmxpcrdev->devnr == fenode->devnr)
334                        dmxpcrnode = status.aktservice->dmxpcrdev;
335                else
336                {
337                        dmxclose(status.aktservice->dmxpcrdev, -1);
338                        dmxpcrnode = dmxopen(fenode, 2);
339                }
340                if(dmxpcrnode != NULL)
341                {
342                            if(dmxsetsource(dmxpcrnode, fenode->fedmxsource) != 0)
343                            {
344                                    dmxclose(dmxpcrnode, -1);
345                                    dmxpcrnode = NULL;
346                            }
347                            if(dmxsetpesfilter(dmxpcrnode, chnode->pcrpid, -1, DMX_OUT_DECODER, DMX_PES_PCR, 0) != 0)
348                            {
349                                    dmxclose(dmxpcrnode, -1);
350                                    dmxpcrnode = NULL;
351                            }
352                    }
353                    else
354                            err("demux pcr dev not ok");
355            }
356            else
357            {
358                    err("dmx pcrpid not valid (%d)", chnode->pcrpid);
359                    dmxclose(status.aktservice->dmxpcrdev, -1);
360            }
361
362            status.aktservice->dmxpcrdev = dmxpcrnode;
363
364            //demux audio start
365            if(chnode->audiopid > 0)
366            {
367                    if(status.aktservice->dmxaudiodev != NULL && status.aktservice->dmxaudiodev->fd >= 0 && status.aktservice->dmxaudiodev->adapter == fenode->adapter && status.aktservice->dmxaudiodev->devnr == fenode->devnr)
368                            dmxaudionode = status.aktservice->dmxaudiodev;
369                    else
370                    {
371                            dmxclose(status.aktservice->dmxaudiodev, -1);
372                            dmxaudionode = dmxopen(fenode, 2);
373                            if(dmxsetbuffersize(dmxaudionode, getconfigint("dmxaudiobuffersize", NULL)) != 0)
374                            {
375                                    dmxclose(dmxaudionode, -1);
376                                    dmxaudionode = NULL;
377                            }
378                    }
379                    if(dmxaudionode != NULL)
380                    {
381                            if(dmxsetsource(dmxaudionode, fenode->fedmxsource) != 0)
382                            {
383                                    dmxclose(dmxaudionode, -1);
384                                    dmxaudionode = NULL;
385                            }
386                            if(dmxsetpesfilter(dmxaudionode, chnode->audiopid, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0) != 0)
387                            {
388                                    dmxclose(dmxaudionode, -1);
389                                    dmxaudionode = NULL;
390                            }
391                    }
392                    else
393                            err("demux audio dev not ok");
394            }
395            else
396            {
397                    err("dmx audiopid not valid (%d)", chnode->audiopid);
398                dmxclose(status.aktservice->dmxaudiodev, -1);
399            }
400
401            status.aktservice->dmxaudiodev = dmxaudionode;
402
403            //demux video start
404            if(chnode->videopid > 0)
405            {
406                    if(status.aktservice->dmxvideodev != NULL && status.aktservice->dmxvideodev->fd >= 0 && status.aktservice->dmxvideodev->adapter == fenode->adapter && status.aktservice->dmxvideodev->devnr == fenode->devnr)
407                            dmxvideonode = status.aktservice->dmxvideodev;
408                    else
409                    {
410                            dmxclose(status.aktservice->dmxvideodev, -1);
411                            dmxvideonode = dmxopen(fenode, 2);
412                            if(dmxsetbuffersize(dmxvideonode, getconfigint("dmxvideobuffersize", NULL)) != 0)
413                            {
414                                    dmxclose(dmxvideonode, -1);
415                                    dmxvideonode = NULL;
416                            }
417                            status.aktservice->dmxvideodev = dmxvideonode;
418                    }
419                    if(dmxvideonode != NULL)
420                    {
421                            if(dmxsetsource(dmxvideonode, fenode->fedmxsource) != 0)
422                            {
423                                    dmxclose(dmxvideonode, -1);
424                                    dmxvideonode = NULL;
425                            }
426                            if(dmxsetpesfilter(dmxvideonode, chnode->videopid, -1, DMX_OUT_DECODER, DMX_PES_VIDEO, 0) != 0)
427                            {
428                                    dmxclose(dmxvideonode, -1);
429                                    dmxvideonode = NULL;
430                            }
431                    }
432                    else
433                            err("demux video dev not ok");
434            }
435            else
436            {
437                    err("dmx videopid not valid (%d)", chnode->videopid);
438                dmxclose(status.aktservice->dmxvideodev, -1);
439            }
440
441        status.aktservice->dmxvideodev = dmxvideonode;
442       
443        //workaround for some audio channel not playing (for test)
444        usleep(100000);
445
446            //audio start
447            if(dmxaudionode != NULL)
448            {
449                    if(status.aktservice->audiodev != NULL && status.aktservice->audiodev->fd >= 0 && status.aktservice->audiodev->adapter == fenode->adapter)
450                            audionode = status.aktservice->audiodev;
451                    else
452                    {
453                            audioclose(status.aktservice->audiodev, -1);
454                            audionode = audioopen(fenode->adapter);
455                            status.aktservice->audiodev = audionode;
456                    }
457                    if(audionode != NULL)
458                    {
459                            audioselectsource(audionode, AUDIO_SOURCE_DEMUX);
460                            audiosetbypassmode(audionode, chnode->audiocodec);
461                            if(checkchipset("HI3798MV200") == 1 || vubox1 == 1) //fixt only audio no video.. blackscreen after zap
462                                    audiopause(audionode);
463                            if(status.mute != 1)
464                            {
465                                    // needs for ts playback
466                                    if(checkchipset("3798MV200") == 1 || checkbox("DM900") == 1 || checkbox("DM920") == 1 || checkbox("DM520") == 1 || checkbox("DM525") == 1)
467                                            dmxstart(status.aktservice->dmxaudiodev);
468                                    audioplay(audionode);
469                            }
470                    }
471                    else
472                            err("can't get free audio dev");
473            }
474
475            //video start
476            if(dmxvideonode != NULL)
477            {
478                    if(status.aktservice->videodev != NULL && status.aktservice->videodev->fd >= 0 && status.aktservice->videodev->adapter == fenode->adapter)
479                            videonode = status.aktservice->videodev;
480                    else
481                    {
482                            videoclose(status.aktservice->videodev, -1);
483                            videonode = videoopen(fenode->adapter, 0);
484                            status.aktservice->videodev = videonode;
485                    }
486                    if(videonode != NULL)
487                    {
488                            videocontinue(videonode);
489                            videoselectsource(videonode, VIDEO_SOURCE_DEMUX);
490                            setencoding(chnode, videonode);
491
492                            // needs for ts playpack
493                            if(checkchipset("3798MV200") == 1)
494                                    dmxstart(status.aktservice->dmxvideodev);
495
496                            if(vubox1 == 1 ) //fixt only audio no video.. blackscreen after zap
497                                    videofreeze(videonode);
498
499                            if(videoplay(videonode)!= 0) {
500                                    usleep(500000);
501                                    videoplay(videonode);
502                            }
503                    }
504                    else
505                            err("can't get free video dev");
506                    if(checkchipset("HI3798MV200") == 1 || vubox1 == 1)
507                    {
508                            videoslowmotion(videonode, 0);
509                            videofastforward(videonode, 0);
510                            videocontinue(videonode);
511                    }
512            }
513#ifdef MIPSEL
514            if(checkchipset("HI3798MV200") == 1 || vubox1 == 1)
515            {
516                    audiocontinue(audionode);
517            }
518
519            if(tmpmute == 1)
520            {
521                    tmpmute = 0;
522                    setmute(1);
523            }
524#else   
525            //unset mute if set here
526            if(tmpmute == 1)
527            {
528                    tmpmute = 0;
529                    audiosetmute(status.aktservice->audiodev, 0);
530                    //setmute(0);
531            }
532            if(status.mute != 1)
533            {
534                    if(checkbox("DM900") == 1 || checkbox("DM920") == 1 || checkbox("DM520") == 1 || checkbox("DM525") == 1)
535                            dmxstart(status.aktservice->dmxaudiodev);
536                    audioplay(status.aktservice->audiodev);
537            }
538#endif
539
540        if(chnode->streamurl != NULL)
541        {
542            struct stimerthread *startservicethread = NULL;
543            if(!ostrncmp("http://127.0.0.1:17999/", chnode->streamurl, 23))
544                startservicethread = addtimer(&createstartservicethread, START, 1000, 1, (void*)chnode, NULL, NULL);
545            else
546                streamplayer(chnode, 2);
547        }
548
549            //check pmt if not done
550            if(checkpmt == 0)
551            {
552                    //wait for tuner lock
553                    if(flag == 0)
554                    {
555                            if(fenode->felasttransponder != tpnode)
556                                    festatus = fewait(fenode);
557                            else
558                            {
559                                    festatus = fegetunlock(fenode);
560                                    if(festatus != 0)
561                                    {
562                                            debug(200, "fegetunlock rc:%d ... now fewait", festatus);   
563                                            festatus = fewait(fenode);
564                                    }
565                            }
566
567                            if(debug_level == 200)
568                            {
569                                    fereadstatus(fenode);
570                                    fegetfrontend(fenode);
571                            }
572                            if(festatus != 0)
573                            {
574                                    m_unlock(&status.servicemutex, 2);
575                                    return 2;
576                            }
577                    }
578
579                    checkpmt = 1;
580                    patbuf = dvbgetpat(fenode, -1);
581                    if(patbuf == NULL) status.secondzap = 3;
582                    debug(200, "3-secondzap=%i", status.secondzap);     
583                    free(status.aktservice->pmtbuf);
584                    status.aktservice->pmtbuf = NULL;
585                    status.aktservice->pmtlen = 0;
586                    if(patbuf != NULL)
587                            status.aktservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 0);
588                    else if(chnode->pmtpid > 0)
589                            status.aktservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 1);
590
591                    if(status.aktservice->pmtbuf == NULL) status.secondzap = 4;
592                    debug(200, "4-secondzap=%i", status.secondzap);
593                    if(dvbgetinfo(status.aktservice->pmtbuf, chnode) == 1)
594                    {
595                            //audio or video pid or codec changed
596                            free(status.aktservice->pmtbuf);
597                            status.aktservice->pmtbuf = NULL;
598                            status.aktservice->pmtlen = -1;
599                    }
600
601                    if(flag == 0)
602                    {
603                            if(status.pmtmode == 1)
604                            {
605                                    if(recordcheckcrypt(fenode, CHANNEL) == 0)
606                                            dvbwritepmt(status.aktservice, status.aktservice->pmtbuf);
607                                    else
608                                            debug(200, "don't write pmt.tmp, another crypt channel use this frontend");
609                            }
610                            else
611                                    sendcapmt(status.aktservice, 0, 0);
612                    }
613                    free(patbuf);
614            }
615
616            //get ait and parse it for hbbtv url
617            if(flag == 0 && chnode->aitpid > 0)
618            {
619                    unsigned char* aitbuf = NULL;
620                    aitbuf = dvbgetait(fenode, chnode->aitpid, 0, -1);
621                    if(aitbuf != NULL)
622                    {
623                            free(chnode->hbbtvurl); chnode->hbbtvurl = NULL;
624                            chnode->hbbtvurl = dvbgethbbtvurl(aitbuf);
625                    }
626
627                    debug(200, "hbbtvurl=%s", chnode->hbbtvurl);
628                    free(aitbuf); aitbuf = NULL;
629            }
630    }
631
632        if(flag == 0)
633        {
634                //add channel to history
635                if(chnode->streamurl != NULL || status.aktservice->type == CHANNEL)
636                {
637                addchannelhistory(chnode, status.aktservice->channellist);
638                        if(chnode->streamurl == NULL && checkbox("DM900") == 1 && status.servicetype == 0) //only for tv
639                                createmostzap(chnode->serviceid, chnode->transponderid);
640                }
641                festatus = fewait(fenode);
642                if(chnode->streamurl == NULL && festatus != 0)
643                {
644                        m_unlock(&status.servicemutex, 2);
645                        err("festatus=%i", festatus );
646                        return 2;
647                }
648        }
649
650    //wait for epg thread stops
651    if(flag == 0 && status.epgthread != NULL)
652    {
653            i = 0;
654            while(status.epgthread->status != INPAUSE)
655            {
656                    usleep(10000);
657                    i++; if(i > 300) break;
658            }
659            status.epgthread->aktion = START;
660    }
661
662    status.videosizevalid = time(NULL);
663    m_unlock(&status.servicemutex, 2);
664   
665    //auto change channel name
666    if(flag == 0 && status.autochangechannelname == 1)
667            addtimer(&autochangechannelname, START, 1000, 1, NULL, NULL, NULL);
668   
669    //autoresolution
670    if(flag == 0 && ostrcmp(getconfig("av_videomode_autores", NULL), "auto") == 0)
671    {
672            int sec = 7;
673            char* av_videomode_autores_ts = getconfig("av_videomode_autores_ts", NULL);
674            if(av_videomode_autores_ts != NULL)
675                    sec = atoi(av_videomode_autores_ts);
676            if(status.restimer == NULL)
677                    status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
678            else
679            {
680                    status.restimer->aktion = STOP;
681                        status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
682            }                   
683    }
684
685    if(flag == 0 && status.autosubtitle == 1) subtitlestartlast(); //start subtitle
686
687    if(flag == 0 && status.timeshifttype == 1)
688    {
689            i = 0;
690            while(status.timeshift > 0)
691            {
692                    usleep(100000);
693                    i++; if(i > 20) break;
694            }
695            timeshiftpause(); //start permanent timeshift record
696    }
697
698        debug(200, "servicestartreal... ended with 0");
699        return 0;
700}
701
702//second zap on failure
703int servicestart(struct channel* chnode, char* channellist, char* pin, int flag)
704{
705        int ret = 0;
706       
707        ret = servicestartreal(chnode, channellist, pin, flag);
708        debug(200, "servicestart... started");
709        if(status.secondzap != 0 && ret == 0 && (flag == 0 || flag > 2))
710        {
711                debug(200, "first zap not ok, make second zap (%d)", status.secondzap);
712//        if(chnode->streamurl == NULL)
713                ret = servicestartreal(chnode, channellist, pin, 6);
714        }
715        debug(200, "servicestart... ended");
716        return ret;
717}
718
719//flag 0: lock
720//flag 1: no lock
721struct service* getservicebyrecname(char* file, int type, int flag)
722{
723        if(file == NULL) return NULL;
724
725        if(flag == 0) m_lock(&status.servicemutex, 2);
726        struct service* snode = service;
727
728        while(snode != NULL)
729        {
730                if(ostrcmp(snode->recname, file) == 0 && (type == 0 || (type == 1 && (snode->type == RECORDDIRECT || snode->type == RECORDTIMER))))
731                {
732                        if(flag == 0) m_unlock(&status.servicemutex, 2);
733                        return snode;
734                }
735                snode = snode->next;
736        }
737        if(flag == 0) m_unlock(&status.servicemutex, 2);
738        return NULL;
739}
740
741struct service* getservicebychannel(struct channel* chnode)
742{
743        m_lock(&status.servicemutex, 2);
744        struct service* snode = service;
745
746        while(snode != NULL)
747        {
748                if(snode->channel == chnode)
749                {
750                        m_unlock(&status.servicemutex, 2);
751                        return snode;
752                }
753                snode = snode->next;
754
755        }
756        m_unlock(&status.servicemutex, 2);
757        return NULL;
758}
759
760//flag 0: lock
761//flag 1: no lock
762struct service* getservicebyrectimestamp(char* timestamp, int flag)
763{
764        if(timestamp == 0) return NULL;
765
766        if(flag == 0) m_lock(&status.servicemutex, 2);
767        struct service* snode = service;
768
769        while(snode != NULL)
770        {
771                if(ostrcmp(snode->rectimestamp, timestamp) == 0)
772                {
773                        if(flag == 0) m_unlock(&status.servicemutex, 2);
774                        return snode;
775                }
776                snode = snode->next;
777        }
778        if(flag == 0) m_unlock(&status.servicemutex, 2);
779        return NULL;
780}
781
782struct service* getservicebyservice(struct service* node, int flag)
783{
784        if(flag == 0) m_lock(&status.servicemutex, 2);
785        struct service* snode = service;
786
787        while(snode != NULL)
788        {
789                if(snode != status.lastservice && snode != node && snode->channel == node->channel)
790                {
791                        if(flag == 0) m_unlock(&status.servicemutex, 2);
792                        return snode;
793                }
794                snode = snode->next;
795        }
796        if(flag == 0) m_unlock(&status.servicemutex, 2);
797        return NULL;
798}
799
800//flag 0: with mutex
801//flag 1: without mutex
802struct service* getservice(int type, int flag)
803{
804        if(flag == 0) m_lock(&status.servicemutex, 2);
805        struct service* snode = service;
806
807        while(snode != NULL)
808        {
809                if(snode->type == type)
810                {
811                        if(flag == 0) m_unlock(&status.servicemutex, 2);
812                        return snode;
813                }
814                snode = snode->next;
815        }
816        if(flag == 0) m_unlock(&status.servicemutex, 2);
817        return NULL;
818}
819
820//flag 0: faststop depends on param faststop
821//flag 1: always normal stop
822//flag 2: from timeshift/player
823//flag 3: same as 0 but no akttolast
824//flag 4: showiframe
825//flag 5: same as 1 but no akttolast and not clear node->type and not stop epg
826int servicestop(struct service *node, int clear, int flag)
827{
828        int rcret = 0;
829
830        if(node != NULL)
831        {
832                status.tvpic = 0;
833
834        if(status.play == 2/* && getconfigint("lastplayertype", NULL) == 0*/)
835        {
836            printf("servicestop playerstop IpTV flag=%d\n", flag);
837            playerstop();
838            status.play = 0;
839#ifdef DREAMBOX
840                usleep(1000000);
841#endif
842        }
843
844                if(status.timeshift == 1 && flag != 2)
845                {
846                        if(status.timeshifttype == 0 && status.asktimeshift == 0)
847                                rcret = textbox(_("Message"), _("Timeshift is running !!!\nStop it and switch ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 400, 10, 0);
848
849                        if(rcret == 2) return 1;
850                        timeshiftstop(1);
851                }
852                if(flag != 2 && node->type != NOTHING && node->type != STILLPIC) caservicedel(node, NULL);
853
854
855                truncate("/tmp/ecm.info", 0);
856                unlink("/tmp/pid.info");
857                unlink("/tmp/caids.info");
858               
859                status.videosizevalid = 0;
860
861                if(status.epgthread != NULL && flag != 5) status.epgthread->aktion = PAUSE;
862                subtitlestop(0);
863
864                if(node->type == CHANNEL && flag < 2) akttolast();
865
866                if(flag != 2 && flag != 5) node->type = NOTHING;
867                if(flag == 4) node->type = STILLPIC;
868       
869                audiostop(node->audiodev);
870                if(checkbox("DM900") == 1 || checkbox("DM920") == 1 || checkbox("DM520") == 1 || checkbox("DM525") == 1 || checkchipset("HI3798MV200") == 1)
871                        dmxstop(status.aktservice->dmxaudiodev);
872
873                if(checkbox("VUSOLO2_old") == 1)
874                {
875//                      videofreeze(status.aktservice->videodev);
876//                      dmxstart(status.aktservice->dmxaudiodev);
877//                      audioplay(status.aktservice->audiodev);
878//                      audiopause(status.aktservice->audiodev);
879                        videoclearbuffer(status.aktservice->videodev);
880                        audioclearbuffer(status.aktservice->audiodev);
881//                      videoslowmotion(status.aktservice->videodev, 0);
882//                      videofastforward(status.aktservice->videodev, 0);
883                }
884                else if(vubox1 == 1)
885                {
886                        videofreeze(node->videodev);
887                        videoclearbuffer(node->videodev);
888                        audioclearbuffer(node->audiodev);
889                }
890                else
891                {
892
893                        dmxstop(node->dmxaudiodev);
894                        videostop(node->videodev, clear);
895                }
896
897                int     fastzap = getconfigint("fastzap", NULL);
898
899                if(flag == 3) flag = 0;
900                if(flag == 5) flag = 1;
901                if(flag == 4 || flag == 1 || (flag == 0 && (fastzap == 0 || fastzap == 2)))
902                {
903                        audioclose(node->audiodev, -1);
904                        node->audiodev = NULL;
905                        dmxstop(node->dmxaudiodev);
906                        dmxclose(node->dmxaudiodev, -1);
907                        node->dmxaudiodev = NULL;
908                }
909               
910                if(flag == 4 || flag == 1 || (flag == 0 && fastzap == 0))
911                {
912                        printf("[titan] service.h -> servicestop close all\n");
913                        if(checkchipset("HI3798MV200") == 1)
914                        {
915                                videocontinue(node->videodev);
916                        }
917                        videoclose(node->videodev, -1);
918                        node->videodev = NULL;
919                        dmxstop(node->dmxvideodev);
920                        dmxclose(node->dmxvideodev, -1);
921                        node->dmxvideodev = NULL;
922                        dmxstop(node->dmxpcrdev);
923                        dmxclose(node->dmxpcrdev, -1);
924                        node->dmxpcrdev = NULL;
925                        dmxstop(node->dmxsubtitledev);
926                        dmxclose(node->dmxsubtitledev, -1);
927                        node->dmxsubtitledev = NULL;
928                }
929                return 0;
930        }
931        return 1;
932}
933
934void servicechangeaudio(struct channel* chnode, struct audiotrack* tracknode)
935{
936        if(chnode == NULL || tracknode == NULL)
937        {
938                err("NULL detect");
939                return;
940        }
941
942        if(chnode->audiopid == tracknode->audiopid && chnode->audiocodec == tracknode->audiocodec)
943                return;
944
945        chnode->audiopid = tracknode->audiopid;
946        chnode->audiocodec = tracknode->audiocodec;
947
948        status.writechannel = 1;
949        audiostop(status.aktservice->audiodev);
950        audiosetbypassmode(status.aktservice->audiodev, chnode->audiocodec);
951        //clear videobuffer on playback for syncing video / audio
952        if(status.playing == 1) videoclearbuffer(status.aktservice->videodev);
953        dmxsetpesfilter(status.aktservice->dmxaudiodev, chnode->audiopid, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0);
954        if((checkchipset("HI3798MV200") == 1) && status.aktservice->audiodev != NULL)
955                audiopause(status.aktservice->audiodev);
956
957        //don't start audio play, if we are in timeshift record, but not playing mode
958        if(status.timeshifttype == 0 && status.timeshift == 1 && status.playing == 0) return;
959        if(status.timeshifttype == 1 && status.timeshift == 1 && status.playing == 0 && status.timeshiftpos > 0) return;
960
961        if(status.mute != 1)
962                audioplay(status.aktservice->audiodev);
963}
964
965struct service* addservice(struct service* last)
966{
967        struct service *newnode = NULL, *node = NULL;
968
969        newnode = (struct service*)calloc(1, sizeof(struct service));
970        if(newnode == NULL)
971        {
972                err("no memory");
973                return NULL;
974        }
975
976        newnode->recdstfd = -1;
977        newnode->recsrcfd = -1;
978        newnode->tssize = 188;
979
980        m_lock(&status.servicemutex, 2);
981        node = service;
982        if(node != NULL)
983        {
984                if(last == NULL)
985                {
986                        while(node->next != NULL)
987                                node = node->next;
988                        node->next = newnode;
989                }
990                else
991                        last->next = newnode;
992        }
993        else
994                service = newnode;
995
996        m_unlock(&status.servicemutex, 2);
997        return newnode;
998}
999
1000struct service* checkservice(struct service* node)
1001{
1002        struct service* snode = service;
1003
1004        while(snode != NULL)
1005        {
1006                if(snode == node)
1007                        return snode;
1008                snode = snode->next;
1009        }
1010        return NULL;
1011}
1012
1013//flag 0: set mutex
1014//flag 1: not set mutex
1015void delservice(struct service* snode, int flag)
1016{
1017        m_lock(&status.servicemutex, 2);
1018        struct service *node = service, *prev = service;
1019        struct rectimer *rectimernode = NULL;
1020
1021        while(node != NULL)
1022        {
1023                if(node == snode)
1024                {
1025                        if(node == service)
1026                                service = node->next;
1027                        else
1028                                prev->next = node->next;
1029
1030                        dmxclose(node->dmxaudiodev, -1);
1031                        dmxclose(node->dmxvideodev, -1);
1032                        dmxclose(node->dmxpcrdev, -1);
1033                        dmxclose(node->dmxsubtitledev, -1);
1034                        audioclose(node->audiodev, -1);
1035                        videoclose(node->videodev, -1);
1036                        close(node->recdstfd);
1037                        close(node->recsrcfd);
1038                        caservicedel(node, NULL);
1039
1040                        //check if a rectimer is joined with a service
1041                        if(node->type == RECORDTIMER)
1042                        {
1043                                if(flag == 0)
1044                                        m_lock(&status.rectimermutex, 1);
1045
1046                                rectimernode = getrectimerbyservice(node);
1047                                if(rectimernode != NULL)
1048                                {
1049                                        rectimernode->servicenode = NULL;
1050                                        if(rectimernode->status == 0 || rectimernode->status == 1)
1051                                        {
1052                                                rectimernode->status = 2;
1053                                                status.writerectimer = 1;
1054                                                writerectimer(getconfig("rectimerfile", NULL), 1);
1055                                        }
1056                                }
1057
1058                                if(flag == 0)
1059                                        m_unlock(&status.rectimermutex, 1);
1060                        }
1061
1062                        free(node->channellist);
1063                        node->channellist = NULL;
1064
1065                        free(node->recname);
1066                        node->recname = NULL;
1067
1068                        free(node->rectimestamp);
1069                        node->rectimestamp = NULL;
1070
1071                        free(node->pmtbuf);
1072                        node->pmtbuf = NULL;
1073
1074                        free(node);
1075                        node = NULL;
1076                        break;
1077                }
1078
1079                prev = node;
1080                node = node->next;
1081        }
1082        m_unlock(&status.servicemutex, 2);
1083}
1084
1085void freeservice()
1086{
1087        struct service *node = service, *prev = service;
1088
1089        while(node != NULL)
1090        {
1091                prev = node;
1092                node = node->next;
1093                if(prev != NULL)
1094                        delservice(prev, 0);
1095        }
1096}
1097
1098char* servicecheckret(int ret, int flag)
1099{
1100        char* tmpstr = NULL;
1101
1102        if(ret != 0)
1103        {
1104                switch(ret)
1105                {
1106                        case 1:
1107                                tmpstr = ostrcat(_("Can't find a Tuner.\nAll Tuners in use or no Tuner defined."), NULL, 0, 0);
1108                                break;
1109                        case 2:
1110                                tmpstr = ostrcat(_("Tuning to Channel failed!"), NULL, 0, 0);
1111                                break;
1112                        case 3:
1113                                tmpstr = ostrcat(_("Can't open frontend dev or Frontend Type unknown!"), NULL, 0, 0);
1114                                break;
1115                        case 20:
1116                                break;
1117                        case 21:
1118                                tmpstr = ostrcat(_("Channellist empty or corrupt (channel not found)!"), NULL, 0, 0);
1119                                break;
1120                        case 22:
1121                                break;
1122                }
1123                if(tmpstr != NULL)
1124                        textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0);
1125        }
1126
1127        if(flag != 1)
1128        {
1129                free(tmpstr);
1130                tmpstr = NULL;
1131        }
1132
1133        return tmpstr;
1134}
1135
1136#ifdef MIPSEL
1137void servicefullHDMIin_start()
1138{
1139        struct dvbdev *videonode = NULL;
1140        struct dvbdev *audionode = NULL;
1141        struct channel *chnode = NULL;
1142       
1143        servicestop(status.aktservice, 1, 1);
1144       
1145        audionode = audioopen(0);
1146        if(audionode != NULL)
1147        {
1148                audioselectsource(audionode, AUDIO_SOURCE_HDMI);
1149                audioplay(audionode);
1150        }
1151        videonode = videoopen(0, 0);
1152        if(videonode != NULL)
1153        {
1154                videoselectsource(videonode, VIDEO_SOURCE_HDMI);
1155                videosetstreamtype(videonode, 0);
1156                videoplay(videonode);
1157        }
1158        status.aktservice->videodev = videonode;
1159        status.aktservice->audiodev = audionode;
1160        status.aktservice->type = HDMIIN;
1161        chnode = getchannel(65535, 0);
1162        if(chnode == NULL)
1163                //chnode = createchannel("HDMIIN", 0, 0, 65535, 99, 0, -1, -1, -1, -1, 0, -1);
1164                chnode = createchannel("HDMIIN", 0, 0, 65535, 0, 0, -1, -1, -1, -1, 0, -1, NULL, NULL);
1165        status.aktservice->channel = chnode;
1166}
1167#endif
1168
1169void createstartservicethread(struct stimerthread* self, struct channel* chnode)
1170{
1171        printf("createstartservicethread start");
1172
1173        if(status.startservicethread == NULL/* || self != NULL*/)
1174    {
1175       
1176            int count = 585;
1177        status.startservicethread = self;
1178
1179//      while(count < 600)
1180            while(status.httpthread == NULL)
1181            {
1182                    sleep(1);
1183                    count++;
1184            }
1185
1186        streamplayer(chnode, 3);
1187
1188            printf("createstartservicethread end");
1189
1190        status.startservicethread = NULL;
1191    }
1192}
1193
1194#endif
Note: See TracBrowser for help on using the repository browser.