source: titan/titan/service.h @ 37330

Last change on this file since 37330 was 37330, checked in by obi, 8 years ago

test

File size: 25.5 KB
RevLine 
[7524]1#ifndef SERVICE_H
2#define SERVICE_H
3
[7606]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
[18431]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);
[7606]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);
[7728]19                if(node->dmxpcrdev != NULL) printf("%s (%d)\n", node->dmxpcrdev->dev, node->dmxpcrdev->fd);
[7606]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
[8665]26void serviceresetchannelinfo(struct channel* chnode)
27{
[18583]28        if(chnode == NULL) return;
29
[8665]30        freeaudiotrack(chnode);
31        freesubtitle(chnode);
[8878]32        freepmt(chnode);
33        freecadesc(chnode);
34        freeesinfo(chnode);
[8665]35        chnode->txtpid = 0;
[9033]36        chnode->pmtpid = 0;
[8878]37        chnode->crypt = 0;
[8665]38}
39
[7606]40void akttolast()
41{
[10957]42        if(status.aktservice->fedev != NULL && status.aktservice->fedev->type == FRONTENDDEVDUMMY) return;
[7606]43        status.lastservice->fedev = status.aktservice->fedev;
44        status.lastservice->dmxaudiodev = status.aktservice->dmxaudiodev;
45        status.lastservice->dmxvideodev = status.aktservice->dmxvideodev;
[7728]46        status.lastservice->dmxpcrdev = status.aktservice->dmxpcrdev;
47        status.lastservice->dmxsubtitledev = status.aktservice->dmxsubtitledev;
[7606]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;
[10849]52        free(status.lastservice->channellist);
53        status.lastservice->channellist = ostrcat(status.aktservice->channellist, NULL, 0, 0);
[7606]54}
55
[9713]56//flag 0: channel
57//flag 1: playback
58//flag 2: timeshift
[10957]59//flag 3: same as 0 but don't check chnode
[14611]60//flag 4: same as 0 but new tuning
61//flag 5: same as 3 but new tuning
[21433]62//flag 6: same as 5 but second zap
[19628]63int servicestartreal(struct channel* chnode, char* channellist, char* pin, int flag)
[7524]64{
65        struct transponder* tpnode = NULL;
66        struct dvbdev *fenode = NULL;
[7557]67        struct dvbdev *dmxaudionode = NULL;
68        struct dvbdev *dmxvideonode = NULL;
[24714]69        struct dvbdev *dmxpcrnode = NULL;
[7557]70        struct dvbdev *audionode = NULL;
71        struct dvbdev *videonode = NULL;
[20414]72        int ret = 0, festatus = 1, tmpmute = 0, i = 0;
[9498]73        unsigned char *patbuf = NULL;
[21433]74        int checkpmt = 0, pincheck = 0, stopflag = 0, ageprotect = 0, tune = 0, secondzap = 0;
[10314]75        struct epg* epgnode = NULL;
[7524]76
[8750]77        m_lock(&status.servicemutex, 2);
[8665]78
[19640]79        status.secondzap = 0;
[19628]80
[21433]81        if(flag == 4 || flag == 5 || flag == 6) tune = 1;
82        if(flag == 6) secondzap = 1;
[14645]83        if(flag == 4) flag = 0;
[14611]84
[31912]85        //wakeup hdd work
86        if(flag == 1 || flag == 2) wakeup_record_device();
87       
[10957]88        if(flag == 0 && status.aktservice->type == CHANNEL && status.aktservice->channel != NULL && chnode == status.aktservice->channel)
[8665]89        {
[8750]90                m_unlock(&status.servicemutex, 2);
[8378]91                return 20;
[8665]92        }
[21433]93        if(flag == 3 || flag == 5 || flag == 6) flag = 0;
[7612]94
[7583]95        if(chnode == NULL)
[8665]96        {
[8750]97                m_unlock(&status.servicemutex, 2);
[8378]98                return 21;
[8665]99        }
[26151]100        debug(200, "servicestartreal... started");
[20708]101        //stop running autoresolution
102        if(status.restimer != NULL)
103                status.restimer->aktion = STOP;
[7583]104
[21433]105        if(secondzap == 0)
[8076]106        {
[21433]107                ageprotect = getconfigint("ageprotect", NULL);
108                if(ageprotect > 0) epgnode = getepgakt(chnode);
109                if(chnode->protect > 0 || (epgnode != NULL && epgnode->parentalrating >= ageprotect))
[8665]110                {
[21433]111                        pincheck = screenpincheck(1, pin);
112                        if(pincheck == 1)
113                        {
114                                m_unlock(&status.servicemutex, 2);
115                                return 22;
116                        }
[8665]117                }
[8076]118        }
119
[7667]120        //got transponder
[9713]121        if(flag == 0)
122        {
123                if(chnode->transponder == NULL)
[36337]124                        tpnode = gettransponder(chnode->transponderid);
[9713]125                else
126                        tpnode = chnode->transponder;
127        }
[7583]128
[21433]129        if(flag == 1 || flag == 2)
130                stopflag = 2;
131        else if(secondzap == 1)
132                stopflag = 3;
[8938]133        if(getconfigint("nozapclear", NULL) == 1)
[9713]134                ret = servicestop(status.aktservice, 0, stopflag);
[8938]135        else
[9713]136                ret = servicestop(status.aktservice, 1, stopflag);
[9631]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
[9746]146        if(flag == 0) serviceresetchannelinfo(chnode);
[9713]147
[7667]148        status.aktservice->transponder = tpnode;
149        status.aktservice->channel = chnode;
150        status.aktservice->type = CHANNEL;
[8976]151        if(status.epgthread != NULL) status.epgthread->aktion = PAUSE;
[7667]152
[10849]153        if(flag == 0 && status.aktservice->type == CHANNEL)
154                changechannellist(chnode, channellist);
[7667]155
156        //got frontend dev
[9713]157        if(flag == 0)
[8665]158        {
[10261]159                fenode = fegetfree(tpnode, 0, NULL);
[9713]160                if(fenode == NULL)
161                {
162                        m_unlock(&status.servicemutex, 2);
163                        return 1;
164                }
[8665]165
[9713]166                status.aktservice->fedev = fenode;
[7583]167
[9713]168                //frontend tune
[14611]169                if(fenode->felasttransponder != tpnode || tune == 1)
[7765]170                {
[9713]171                        if(fenode->feinfo->type == FE_QPSK)
172                        {
173                                feset(fenode, tpnode);
174                                fetunedvbs(fenode, tpnode);
175                        }
176                        else if(fenode->feinfo->type == FE_QAM)
177                                fetunedvbc(fenode, tpnode);
178                        else if(fenode->feinfo->type == FE_OFDM)
179                                fetunedvbt(fenode, tpnode);
180                        else
181                        {
182                                m_unlock(&status.servicemutex, 2);
183                                return 3;
184                        }
[7765]185                }
[7583]186        }
[9713]187        else if(flag == 1 || flag == 2)
[9746]188        {
[9713]189                fenode = fegetdummy();
[9746]190                status.aktservice->fedev = fenode;
191        }
[7623]192
[20143]193        if(fenode == NULL)
194        {
195                m_unlock(&status.servicemutex, 2);
196                return 1;
197        }
198
[7623]199        //check pmt if not all infos in channellist
[24714]200        if(chnode->audiopid == -1 || chnode->videopid == -1 || chnode->pcrpid == -1 || chnode->audiocodec == -1 || chnode->videocodec == -1 || (getconfigint("av_ac3default", NULL) == YES && chnode->audiocodec != AC3))
[7623]201        {
202                //wait for tuner lock
[9713]203                if(flag == 0)
204                {
205                        if(fenode->felasttransponder != tpnode)
206                                festatus = fewait(fenode);
207                        else
208                                festatus = fegetunlock(fenode);
[7532]209
[9713]210                        if(debug_level == 200) 
211                        {
212                                fereadstatus(fenode);
213                                fegetfrontend(fenode);
214                        }
215                        if(festatus != 0)
216                        {
217                                m_unlock(&status.servicemutex, 2);
218                                return 2;
219                        }
[8900]220                }
[7583]221
[7623]222                checkpmt = 1;
[19578]223                if(flag != 1 || (flag == 1 && chnode->pmtpid == 0))
[19628]224                {
[19578]225                        patbuf = dvbgetpat(fenode, -1);
[19640]226                        if(patbuf == NULL) status.secondzap = 1;
[19628]227                }
[26131]228                debug(200, "1-secondzap=%i", status.secondzap);
[9498]229                free(status.aktservice->pmtbuf);
[9746]230                status.aktservice->pmtbuf = NULL;
[10583]231                status.aktservice->pmtlen = 0;
[9713]232                if(patbuf != NULL)
[10380]233                        status.aktservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 0);
[9713]234                else if(chnode->pmtpid > 0)
[10380]235                        status.aktservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 1);
[9713]236
[19640]237                if(status.aktservice->pmtbuf == NULL) status.secondzap = 2;
[26131]238                debug(200, "2-secondzap=%i", status.secondzap);
[9498]239                dvbgetinfo(status.aktservice->pmtbuf, chnode);
[9713]240
241                if(flag == 0)
[8991]242                {
[9713]243                        if(status.pmtmode == 1)
244                        {
245                                if(recordcheckcrypt(fenode, CHANNEL) == 0)
246                                        dvbwritepmt(status.aktservice, status.aktservice->pmtbuf);
247                                else
248                                        debug(200, "don't write pmt.tmp, another crypt channel use this frontend");
249                        }
[8991]250                        else
[11160]251                                sendcapmt(status.aktservice, 0, 0);
[8991]252                }
[7623]253                free(patbuf);
[7606]254        }
[7571]255
[9746]256        if(flag != 0) checkpmt = 1;
257
[17962]258        //set mute for scat problem
[31910]259#ifdef MIPSEL   
260        if(status.mute != 0)
261        {
262                setmute(0);
263                tmpmute = 1;
264        }
265#else
[17962]266        if(status.mute == 0)
267        {
268                tmpmute = 1;
[25694]269                //setmute(1);
[25697]270                audiosetmute(status.aktservice->audiodev, 1);
[17962]271        }
[37291]272#endif         
[25695]273        audiostop(status.aktservice->audiodev);
[24714]274        //demux pcr start
275        if(flag == 0 && chnode->pcrpid > 0)
276        {
277                if(status.aktservice->dmxpcrdev != NULL && status.aktservice->dmxpcrdev->fd >= 0 && status.aktservice->dmxpcrdev->adapter == fenode->adapter && status.aktservice->dmxpcrdev->devnr == fenode->devnr)
278                        dmxpcrnode = status.aktservice->dmxpcrdev;
279                else
280                {
281                        dmxclose(status.aktservice->dmxpcrdev, -1);
[35239]282                        dmxpcrnode = dmxopen(fenode, 2);
[24714]283                }
284                if(dmxpcrnode != NULL)
285                {
286                        if(dmxsetsource(dmxpcrnode, fenode->fedmxsource) != 0)
287                        {
288                                dmxclose(dmxpcrnode, -1);
289                                dmxpcrnode = NULL;
290                        }
291                        if(dmxsetpesfilter(dmxpcrnode, chnode->pcrpid, -1, DMX_OUT_DECODER, DMX_PES_PCR, 0) != 0)
292                        {
293                                dmxclose(dmxpcrnode, -1);
294                                dmxpcrnode = NULL;
295                        }
296                }
297                else
298                        err("demux pcr dev not ok");
299        }
300        else
301        {
302                err("dmx pcrpid not valid (%d)", chnode->pcrpid);
303                dmxclose(status.aktservice->dmxpcrdev, -1);
304        }
[17962]305
[24714]306        status.aktservice->dmxpcrdev = dmxpcrnode;
307
[7623]308        //demux audio start
[9033]309        if(chnode->audiopid > 0)
[7583]310        {
[9033]311                if(status.aktservice->dmxaudiodev != NULL && status.aktservice->dmxaudiodev->fd >= 0 && status.aktservice->dmxaudiodev->adapter == fenode->adapter && status.aktservice->dmxaudiodev->devnr == fenode->devnr)
312                        dmxaudionode = status.aktservice->dmxaudiodev;
313                else
314                {
[9694]315                        dmxclose(status.aktservice->dmxaudiodev, -1);
[35239]316                        dmxaudionode = dmxopen(fenode, 2);
[9694]317                        if(dmxsetbuffersize(dmxaudionode, getconfigint("dmxaudiobuffersize", NULL)) != 0)
318                        {
319                                dmxclose(dmxaudionode, -1);
320                                dmxaudionode = NULL;
321                        }
[9033]322                }
323                if(dmxaudionode != NULL)
324                {
[9694]325                        if(dmxsetsource(dmxaudionode, fenode->fedmxsource) != 0)
326                        {
327                                dmxclose(dmxaudionode, -1);
328                                dmxaudionode = NULL;
329                        }
[10103]330                        if(dmxsetpesfilter(dmxaudionode, chnode->audiopid, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0) != 0)
[9694]331                        {
332                                dmxclose(dmxaudionode, -1);
333                                dmxaudionode = NULL;
334                        }
[9033]335                }
336                else
[9713]337                        err("demux audio dev not ok");
[7583]338        }
339        else
[9694]340        {
[9033]341                err("dmx audiopid not valid (%d)", chnode->audiopid);
[9694]342                dmxclose(status.aktservice->dmxaudiodev, -1);
343        }
[7524]344
[9694]345        status.aktservice->dmxaudiodev = dmxaudionode;
346
[7623]347        //demux video start
[9033]348        if(chnode->videopid > 0)
[7583]349        {
[9033]350                if(status.aktservice->dmxvideodev != NULL && status.aktservice->dmxvideodev->fd >= 0 && status.aktservice->dmxvideodev->adapter == fenode->adapter && status.aktservice->dmxvideodev->devnr == fenode->devnr)
351                        dmxvideonode = status.aktservice->dmxvideodev;
352                else
353                {
[9694]354                        dmxclose(status.aktservice->dmxvideodev, -1);
[35239]355                        dmxvideonode = dmxopen(fenode, 2);
[9694]356                        if(dmxsetbuffersize(dmxvideonode, getconfigint("dmxvideobuffersize", NULL)) != 0)
357                        {
358                                dmxclose(dmxvideonode, -1);
359                                dmxvideonode = NULL;
360                        }
[9033]361                        status.aktservice->dmxvideodev = dmxvideonode;
362                }
363                if(dmxvideonode != NULL)
364                {
[9694]365                        if(dmxsetsource(dmxvideonode, fenode->fedmxsource) != 0)
366                        {
367                                dmxclose(dmxvideonode, -1);
368                                dmxvideonode = NULL;
369                        }
[9713]370                        if(dmxsetpesfilter(dmxvideonode, chnode->videopid, -1, DMX_OUT_DECODER, DMX_PES_VIDEO, 0) != 0)
[9694]371                        {
372                                dmxclose(dmxvideonode, -1);
373                                dmxvideonode = NULL;
374                        }
[9033]375                }
376                else
[9713]377                        err("demux video dev not ok");
[7583]378        }
379        else
[9694]380        {
[9033]381                err("dmx videopid not valid (%d)", chnode->videopid);
[9694]382                dmxclose(status.aktservice->dmxvideodev, -1);
383        }
[7532]384
[9694]385        status.aktservice->dmxvideodev = dmxvideonode;
[22470]386       
387        //workaround for some audio channel not playing (for test)
[22502]388        usleep(100000);
[9694]389
[7639]390        //audio start
[9694]391        if(dmxaudionode != NULL)
[7639]392        {
[9694]393                if(status.aktservice->audiodev != NULL && status.aktservice->audiodev->fd >= 0 && status.aktservice->audiodev->adapter == fenode->adapter)
394                        audionode = status.aktservice->audiodev;
395                else
396                {
[7639]397                        audioclose(status.aktservice->audiodev, -1);
[9694]398                        audionode = audioopen(fenode->adapter);
399                        status.aktservice->audiodev = audionode;
400                }
401                if(audionode != NULL)
402                {
[9713]403                        audioselectsource(audionode, AUDIO_SOURCE_DEMUX);
[9694]404                        audiosetbypassmode(audionode, chnode->audiocodec);
[25781]405                        if(status.mute != 1)
[25775]406                                audioplay(audionode);
[9694]407                }
408                else
409                        err("can't get free audio dev");
[7639]410        }
[9694]411       
[7639]412        //video start
[9694]413        if(dmxvideonode != NULL)
[7639]414        {
[9694]415                if(status.aktservice->videodev != NULL && status.aktservice->videodev->fd >= 0 && status.aktservice->videodev->adapter == fenode->adapter)
416                        videonode = status.aktservice->videodev;
417                else
418                {
[7639]419                        videoclose(status.aktservice->videodev, -1);
[20871]420                        videonode = videoopen(fenode->adapter, 0);
[9694]421                        status.aktservice->videodev = videonode;
422                }
423                if(videonode != NULL)
424                {
[37072]425                        videocontinue(videonode);
[9713]426                        videoselectsource(videonode, VIDEO_SOURCE_DEMUX);
[24715]427                        setencoding(chnode, videonode);
[37289]428                       
429                        if(checkbox("VUSOLO2") == 1) //fixt only audio no video.. blackscreen after zap
430                                videofreeze(videonode);
431               
[26095]432                        if(videoplay(videonode)!= 0) {
433                                usleep(500000);
434                                videoplay(videonode);
435                        }
[9694]436                }
437                else
438                        err("can't get free video dev");
[7639]439        }
440
[31910]441#ifdef MIPSEL
442        if(tmpmute == 1)
443        {
444                tmpmute = 0;
445                setmute(1);
446        }
447#else   
[17962]448        //unset mute if set here
449        if(tmpmute == 1)
450        {
451                tmpmute = 0;
[25697]452                audiosetmute(status.aktservice->audiodev, 0);
[25694]453                //setmute(0);
[17962]454        }
[25781]455        if(status.mute != 1)
[25775]456                audioplay(status.aktservice->audiodev);
[31910]457#endif
[25695]458       
[7623]459        //check pmt if not done
460        if(checkpmt == 0)
[7583]461        {
[7623]462                //wait for tuner lock
[9713]463                if(flag == 0)
464                {
465                        if(fenode->felasttransponder != tpnode)
466                                festatus = fewait(fenode);
467                        else
[31970]468                        {
[9713]469                                festatus = fegetunlock(fenode);
[31970]470                                if(festatus != 0)
471                                {
[31973]472                                        debug(200, "fegetunlock rc:%d ... now fewait", festatus);       
473                                        festatus = fewait(fenode);
[31970]474                                }
475                        }
[7532]476
[9713]477                        if(debug_level == 200)
478                        {
479                                fereadstatus(fenode);
480                                fegetfrontend(fenode);
481                        }
482                        if(festatus != 0)
483                        {
484                                m_unlock(&status.servicemutex, 2);
485                                return 2;
486                        }
[8900]487                }
[7623]488
489                checkpmt = 1;
[10380]490                patbuf = dvbgetpat(fenode, -1);
[19640]491                if(patbuf == NULL) status.secondzap = 3;
[26131]492                debug(200, "3-secondzap=%i", status.secondzap);
[9498]493                free(status.aktservice->pmtbuf);
[9746]494                status.aktservice->pmtbuf = NULL;
[10583]495                status.aktservice->pmtlen = 0;
[9713]496                if(patbuf != NULL)
[10380]497                        status.aktservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 0);
[9713]498                else if(chnode->pmtpid > 0)
[10380]499                        status.aktservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 1);
[9713]500
[19640]501                if(status.aktservice->pmtbuf == NULL) status.secondzap = 4;
[26131]502                debug(200, "4-secondzap=%i", status.secondzap);
[10583]503                if(dvbgetinfo(status.aktservice->pmtbuf, chnode) == 1)
504                {
505                        //audio or video pid or codec changed
506                        free(status.aktservice->pmtbuf);
507                        status.aktservice->pmtbuf = NULL;
[21993]508                        status.aktservice->pmtlen = -1;
[10583]509                }
[9713]510
511                if(flag == 0)
[8991]512                {
[9713]513                        if(status.pmtmode == 1)
514                        {
515                                if(recordcheckcrypt(fenode, CHANNEL) == 0)
516                                        dvbwritepmt(status.aktservice, status.aktservice->pmtbuf);
517                                else
518                                        debug(200, "don't write pmt.tmp, another crypt channel use this frontend");
519                        }
[8991]520                        else
[11160]521                                sendcapmt(status.aktservice, 0, 0);
[8991]522                }
[7623]523                free(patbuf);
[7583]524        }
[7532]525
[15914]526        //get ait and parse it for hbbtv url
[18262]527        if(flag == 0 && chnode->aitpid > 0)
[15914]528        {
529                unsigned char* aitbuf = NULL;
[15921]530                aitbuf = dvbgetait(fenode, chnode->aitpid, 0, -1);
[20414]531                if(aitbuf != NULL)
532                {
533                        free(chnode->hbbtvurl); chnode->hbbtvurl = NULL;
534                        chnode->hbbtvurl = dvbgethbbtvurl(aitbuf);
535                }
[15914]536
[15921]537                debug(200, "hbbtvurl=%s", chnode->hbbtvurl);
[15914]538                free(aitbuf); aitbuf = NULL;
539        }
540
[9713]541        if(flag == 0)
[8665]542        {
[14910]543                //add channel to history
[14956]544                if(status.aktservice->type == CHANNEL)
[15781]545                {
[14956]546                        addchannelhistory(chnode, status.aktservice->channellist);
[15781]547                        if(status.servicetype == 0) //only for tv
548                                createmostzap(chnode->serviceid, chnode->transponderid);
549                }
[9713]550                festatus = fewait(fenode);
551                if(festatus != 0)
552                {
553                        m_unlock(&status.servicemutex, 2);
[26131]554                        err("festatus=%i", festatus );
[9713]555                        return 2;
556                }
[8665]557        }
[8568]558
[19277]559        //wait for epg thread stops
[20416]560        if(flag == 0 && status.epgthread != NULL)
[8675]561        {
[20708]562                i = 0;
[8976]563                while(status.epgthread->status != INPAUSE)
564                {
565                        usleep(10000);
[19277]566                        i++; if(i > 300) break;
[8976]567                }
568                status.epgthread->aktion = START;
[8675]569        }
570
[9632]571        status.videosizevalid = time(NULL);
[8750]572        m_unlock(&status.servicemutex, 2);
[9559]573       
[11908]574        //auto change channel name
[20708]575        if(flag == 0 && status.autochangechannelname == 1)
[11908]576                addtimer(&autochangechannelname, START, 1000, 1, NULL, NULL, NULL);
577       
[9559]578        //autoresolution
[14783]579        if(flag == 0 && ostrcmp(getconfig("av_videomode_autores", NULL), "auto") == 0)
[9559]580        {
[9641]581                int sec = 7;
[20708]582                char* av_videomode_autores_ts = getconfig("av_videomode_autores_ts", NULL);
583                if(av_videomode_autores_ts != NULL)
584                        sec = atoi(av_videomode_autores_ts);
[9661]585                if(status.restimer == NULL)
[20708]586                        status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
[9661]587                else
588                {
[9559]589                        status.restimer->aktion = STOP;
[20708]590                        status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
[9665]591                }                       
[9559]592        }
593       
[20416]594        if(flag == 0 && status.autosubtitle == 1) subtitlestartlast(); //start subtitle
595        if(flag == 0 && status.timeshifttype == 1)
[20414]596        {
[20708]597                i = 0;
[20414]598                while(status.timeshift > 0)
599                {
600                        usleep(100000);
601                        i++; if(i > 20) break;
602                }
603                timeshiftpause(); //start permanent timeshift record
604        }
[20413]605       
[26151]606        debug(200, "servicestartreal... ended with 0");
[7583]607        return 0;
[7524]608}
609
[19628]610//second zap on failure
611int servicestart(struct channel* chnode, char* channellist, char* pin, int flag)
612{
613        int ret = 0;
[26151]614       
[19628]615        ret = servicestartreal(chnode, channellist, pin, flag);
[26151]616        debug(200, "servicestart... started");
[19640]617        if(status.secondzap != 0 && ret == 0 && (flag == 0 || flag > 2))
[19629]618        {
[19640]619                debug(200, "first zap not ok, make second zap (%d)", status.secondzap);
[21433]620                ret = servicestartreal(chnode, channellist, pin, 6);
[19629]621        }
[26151]622        debug(200, "servicestart... ended");
[19628]623        return ret;
624}
625
[20510]626//flag 0: lock
627//flag 1: no lock
628struct service* getservicebyrecname(char* file, int type, int flag)
[9631]629{
[20510]630        if(file == NULL) return NULL;
631
632        if(flag == 0) m_lock(&status.servicemutex, 2);
[9631]633        struct service* snode = service;
634
635        while(snode != NULL)
636        {
[20510]637                if(ostrcmp(snode->recname, file) == 0 && (type == 0 || (type == 1 && (snode->type == RECORDDIRECT || snode->type == RECORDTIMER))))
[10007]638                {
[20510]639                        if(flag == 0) m_unlock(&status.servicemutex, 2);
[10007]640                        return snode;
641                }
642                snode = snode->next;
643        }
[20510]644        if(flag == 0) m_unlock(&status.servicemutex, 2);
[10007]645        return NULL;
646}
647
[20510]648struct service* getservicebychannel(struct channel* chnode)
[20164]649{
650        m_lock(&status.servicemutex, 2);
651        struct service* snode = service;
652
653        while(snode != NULL)
654        {
[20510]655                if(snode->channel == chnode)
[20164]656                {
657                        m_unlock(&status.servicemutex, 2);
658                        return snode;
659                }
660                snode = snode->next;
661
662        }
663        m_unlock(&status.servicemutex, 2);
664        return NULL;
665}
666
[17252]667//flag 0: lock
668//flag 1: no lock
[17345]669struct service* getservicebyrectimestamp(char* timestamp, int flag)
[17250]670{
671        if(timestamp == 0) return NULL;
672
[17252]673        if(flag == 0) m_lock(&status.servicemutex, 2);
[17250]674        struct service* snode = service;
675
676        while(snode != NULL)
677        {
[17345]678                if(ostrcmp(snode->rectimestamp, timestamp) == 0)
[17250]679                {
[17252]680                        if(flag == 0) m_unlock(&status.servicemutex, 2);
[17250]681                        return snode;
682                }
683                snode = snode->next;
684        }
[17252]685        if(flag == 0) m_unlock(&status.servicemutex, 2);
[17250]686        return NULL;
687}
688
[11166]689struct service* getservicebyservice(struct service* node, int flag)
690{
691        if(flag == 0) m_lock(&status.servicemutex, 2);
692        struct service* snode = service;
693
694        while(snode != NULL)
695        {
696                if(snode != status.lastservice && snode != node && snode->channel == node->channel)
697                {
698                        if(flag == 0) m_unlock(&status.servicemutex, 2);
699                        return snode;
700                }
701                snode = snode->next;
702        }
703        if(flag == 0) m_unlock(&status.servicemutex, 2);
704        return NULL;
705}
706
[10007]707//flag 0: with mutex
708//flag 1: without mutex
709struct service* getservice(int type, int flag)
710{
711        if(flag == 0) m_lock(&status.servicemutex, 2);
712        struct service* snode = service;
713
714        while(snode != NULL)
715        {
[9713]716                if(snode->type == type)
[10007]717                {
718                        if(flag == 0) m_unlock(&status.servicemutex, 2);
[9631]719                        return snode;
[10007]720                }
[9631]721                snode = snode->next;
722        }
[10007]723        if(flag == 0) m_unlock(&status.servicemutex, 2);
[9631]724        return NULL;
725}
726
[9713]727//flag 0: faststop depends on param faststop
728//flag 1: always normal stop
729//flag 2: from timeshift/player
[21433]730//flag 3: same as 0 but no akttolast
[28974]731//flag 4: showiframe
[7728]732int servicestop(struct service *node, int clear, int flag)
[7532]733{
[9631]734        int rcret = 0;
735
[9665]736        if(node != NULL)
[9631]737        {
[21075]738                status.tvpic = 0;
[28974]739
[9713]740                if(status.timeshift == 1 && flag != 2)
[9665]741                {
[20535]742                        if(status.timeshifttype == 0 && status.asktimeshift == 0)
[20505]743                                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);
[9631]744
[12501]745                        if(rcret == 2) return 1;
[9665]746                        timeshiftstop(1);
747                }
[19032]748                if(flag != 2 && node->type != NOTHING && node->type != STILLPIC) caservicedel(node, NULL);
[9631]749
[28974]750
[9012]751                truncate("/tmp/ecm.info", 0);
752                unlink("/tmp/pid.info");
753                unlink("/tmp/caids.info");
[9632]754               
[9634]755                status.videosizevalid = 0;
[9012]756
[10094]757                if(status.epgthread != NULL) status.epgthread->aktion = PAUSE;
[9012]758                subtitlestop(0);
[9713]759
[28974]760
[21433]761                if(node->type == CHANNEL && flag < 2) akttolast();
[28974]762
[10957]763                if(flag != 2) node->type = NOTHING;
[28974]764                if(flag == 4) node->type = STILLPIC;
765               
[9012]766                audiostop(node->audiodev);
[37330]767                if(checkbox("VUSOLO2") == 1) videoclearbuffer(node->videodev);
[9012]768                videostop(node->videodev, clear);
[37330]769
[11979]770                int fastzap = getconfigint("fastzap", NULL);
[10896]771
[21433]772                if(flag == 3) flag = 0;
[28974]773                if(flag == 4 || flag == 1 || (flag == 0 && (fastzap == 0 || fastzap == 2)))
[7557]774                {
[9012]775                        audioclose(node->audiodev, -1);
776                        node->audiodev = NULL;
777                        dmxstop(node->dmxaudiodev);
778                        dmxclose(node->dmxaudiodev, -1);
779                        node->dmxaudiodev = NULL;
[11979]780                }
781               
[28974]782                if(flag == 4 || flag == 1 || (flag == 0 && fastzap == 0))
[11979]783                {
784                        videoclose(node->videodev, -1);
785                        node->videodev = NULL;
[9012]786                        dmxstop(node->dmxvideodev);
787                        dmxclose(node->dmxvideodev, -1);
788                        node->dmxvideodev = NULL;
789                        dmxstop(node->dmxpcrdev);
790                        dmxclose(node->dmxpcrdev, -1);
791                        node->dmxpcrdev = NULL;
792                        dmxstop(node->dmxsubtitledev);
793                        dmxclose(node->dmxsubtitledev, -1);
794                        node->dmxsubtitledev = NULL;
[7557]795                }
[7532]796                return 0;
797        }
798        return 1;
799}
800
[7667]801void servicechangeaudio(struct channel* chnode, struct audiotrack* tracknode)
[7623]802{
[7667]803        if(chnode == NULL || tracknode == NULL)
[7623]804        {
[23286]805                err("NULL detect");
[7667]806                return;
[7623]807        }
[7532]808
[7667]809        if(chnode->audiopid == tracknode->audiopid && chnode->audiocodec == tracknode->audiocodec)
[7623]810                return;
811
[7667]812        chnode->audiopid = tracknode->audiopid;
813        chnode->audiocodec = tracknode->audiocodec;
[7623]814
815        status.writechannel = 1;
816        audiostop(status.aktservice->audiodev);
817        audiosetbypassmode(status.aktservice->audiodev, chnode->audiocodec);
[9746]818        //clear videobuffer on playback for syncing video / audio
819        if(status.playing == 1) videoclearbuffer(status.aktservice->videodev);
[9713]820        dmxsetpesfilter(status.aktservice->dmxaudiodev, chnode->audiopid, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0);
[20807]821
822        //don't start audio play, if we are in timeshift record, but not playing mode
823        if(status.timeshifttype == 0 && status.timeshift == 1 && status.playing == 0) return;
824        if(status.timeshifttype == 1 && status.timeshift == 1 && status.playing == 0 && status.timeshiftpos > 0) return;
825
[25781]826        if(status.mute != 1)
[25775]827                audioplay(status.aktservice->audiodev);
[7623]828}
829
[7728]830struct service* addservice(struct service* last)
[7532]831{
[9012]832        struct service *newnode = NULL, *node = NULL;
[7532]833
[16380]834        newnode = (struct service*)calloc(1, sizeof(struct service));
[7557]835        if(newnode == NULL)
[7532]836        {
[7557]837                err("no memory");
838                return NULL;
[7532]839        }
840
[9107]841        newnode->recdstfd = -1;
842        newnode->recsrcfd = -1;
[14354]843        newnode->tssize = 188;
[7532]844
[9012]845        m_lock(&status.servicemutex, 2);
846        node = service;
[7557]847        if(node != NULL)
[7532]848        {
[7557]849                if(last == NULL)
[7532]850                {
[7557]851                        while(node->next != NULL)
852                                node = node->next;
853                        node->next = newnode;
[7532]854                }
[7557]855                else
856                        last->next = newnode;
[7532]857        }
[7557]858        else
859                service = newnode;
[7532]860
[9012]861        m_unlock(&status.servicemutex, 2);
[7557]862        return newnode;
[7532]863}
864
[9012]865struct service* checkservice(struct service* node)
866{
867        struct service* snode = service;
868
869        while(snode != NULL)
870        {
871                if(snode == node)
872                        return snode;
873                snode = snode->next;
874        }
875        return NULL;
876}
877
[8665]878//flag 0: set mutex
879//flag 1: not set mutex
880void delservice(struct service* snode, int flag)
[7532]881{
[9032]882        m_lock(&status.servicemutex, 2);
[7557]883        struct service *node = service, *prev = service;
[8663]884        struct rectimer *rectimernode = NULL;
[7532]885
[7557]886        while(node != NULL)
[7532]887        {
[7557]888                if(node == snode)
889                {
890                        if(node == service)
891                                service = node->next;
892                        else
893                                prev->next = node->next;
[7532]894
[7557]895                        dmxclose(node->dmxaudiodev, -1);
896                        dmxclose(node->dmxvideodev, -1);
[7728]897                        dmxclose(node->dmxpcrdev, -1);
898                        dmxclose(node->dmxsubtitledev, -1);
[7557]899                        audioclose(node->audiodev, -1);
900                        videoclose(node->videodev, -1);
[9107]901                        close(node->recdstfd);
902                        close(node->recsrcfd);
[11163]903                        caservicedel(node, NULL);
[7532]904
[8663]905                        //check if a rectimer is joined with a service
[8665]906                        if(node->type == RECORDTIMER)
[8663]907                        {
[8665]908                                if(flag == 0)
[8750]909                                        m_lock(&status.rectimermutex, 1);
[8663]910
911                                rectimernode = getrectimerbyservice(node);
912                                if(rectimernode != NULL)
913                                {
914                                        rectimernode->servicenode = NULL;
[9107]915                                        if(rectimernode->status == 0 || rectimernode->status == 1)
[9345]916                                        {
[10349]917                                                rectimernode->status = 2;
[9345]918                                                status.writerectimer = 1;
919                                                writerectimer(getconfig("rectimerfile", NULL), 1);
920                                        }
[8663]921                                }
922
[8665]923                                if(flag == 0)
[8750]924                                        m_unlock(&status.rectimermutex, 1);
[8663]925                        }
926
[10849]927                        free(node->channellist);
928                        node->channellist = NULL;
929
[8227]930                        free(node->recname);
931                        node->recname = NULL;
932
[17345]933                        free(node->rectimestamp);
934                        node->rectimestamp = NULL;
935
[9498]936                        free(node->pmtbuf);
937                        node->pmtbuf = NULL;
938
[7557]939                        free(node);
940                        node = NULL;
941                        break;
942                }
[7532]943
[7557]944                prev = node;
945                node = node->next;
[7532]946        }
[9012]947        m_unlock(&status.servicemutex, 2);
[7532]948}
949
[7557]950void freeservice()
[7532]951{
[7557]952        struct service *node = service, *prev = service;
[7532]953
[7557]954        while(node != NULL)
[7532]955        {
[7557]956                prev = node;
957                node = node->next;
958                if(prev != NULL)
[8665]959                        delservice(prev, 0);
[7532]960        }
961}
962
[9116]963char* servicecheckret(int ret, int flag)
[8667]964{
[9116]965        char* tmpstr = NULL;
[8667]966
[7571]967        if(ret != 0)
968        {
969                switch(ret)
970                {
971                        case 1:
[23633]972                                tmpstr = ostrcat(_("Can't find a Tuner.\nAll Tuners in use or no Tuner defined."), NULL, 0, 0);
[7571]973                                break;
974                        case 2:
[16286]975                                tmpstr = ostrcat(_("Tuning to Channel failed!"), NULL, 0, 0);
[7571]976                                break;
977                        case 3:
[16286]978                                tmpstr = ostrcat(_("Can't open frontend dev or Frontend Type unknown!"), NULL, 0, 0);
[7763]979                                break;
[8378]980                        case 20:
981                                break;
982                        case 21:
[16286]983                                tmpstr = ostrcat(_("Channellist empty or corrupt (channel not found)!"), NULL, 0, 0);
[7571]984                                break;
[8378]985                        case 22:
986                                break;
[7571]987                }
[9132]988                if(tmpstr != NULL)
[16928]989                        textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0);
990        }
991
[9116]992        if(flag != 1)
993        {
994                free(tmpstr);
995                tmpstr = NULL;
996        }
[16928]997
[9116]998        return tmpstr;
[7571]999}
[7532]1000
[31301]1001#ifdef MIPSEL
1002void servicefullHDMIin_start()
1003{
[34801]1004        struct dvbdev *videonode = NULL;
1005        struct dvbdev *audionode = NULL;
[34918]1006        struct channel *chnode = NULL;
[31301]1007       
[34801]1008        servicestop(status.aktservice, 1, 1);
1009       
1010        audionode = audioopen(0);
1011        if(audionode != NULL)
1012        {
1013                audioselectsource(audionode, AUDIO_SOURCE_HDMI);
1014                audioplay(audionode);
1015        }
1016        videonode = videoopen(0, 0);
1017        if(videonode != NULL)
1018        {
1019                videoselectsource(videonode, VIDEO_SOURCE_HDMI);
1020                videosetstreamtype(videonode, 0);
1021                videoplay(videonode);
1022        }
1023        status.aktservice->videodev = videonode;
1024        status.aktservice->audiodev = audionode;
1025        status.aktservice->type = HDMIIN;
[34846]1026        chnode = getchannel(65535, 0);
1027        if(chnode == NULL)
[36337]1028                //chnode = createchannel("HDMIIN", 0, 0, 65535, 99, 0, -1, -1, -1, -1, 0, -1);
1029                chnode = createchannel("HDMIIN", 0, 0, 65535, 0, 0, -1, -1, -1, -1, 0, -1);
[34846]1030        status.aktservice->channel = chnode;
[31301]1031}
[7532]1032#endif
[31301]1033
1034#endif
Note: See TracBrowser for help on using the repository browser.