source: titan/titan/service.h @ 39651

Last change on this file since 39651 was 39549, checked in by obi, 7 years ago

vusolo add audiofreez

File size: 25.6 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
153        if(flag == 0 && status.aktservice->type == CHANNEL)
154                changechannellist(chnode, channellist);
155
156        //got frontend dev
157        if(flag == 0)
158        {
159                fenode = fegetfree(tpnode, 0, NULL);
160                if(fenode == NULL)
161                {
162                        m_unlock(&status.servicemutex, 2);
163                        return 1;
164                }
165
166                status.aktservice->fedev = fenode;
167
168                //frontend tune
169                if(fenode->felasttransponder != tpnode || tune == 1)
170                {
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                        }
185                }
186        }
187        else if(flag == 1 || flag == 2)
188        {
189                fenode = fegetdummy();
190                status.aktservice->fedev = fenode;
191        }
192
193        if(fenode == NULL)
194        {
195                m_unlock(&status.servicemutex, 2);
196                return 1;
197        }
198
199        //check pmt if not all infos in channellist
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))
201        {
202                //wait for tuner lock
203                if(flag == 0)
204                {
205                        if(fenode->felasttransponder != tpnode)
206                                festatus = fewait(fenode);
207                        else
208                                festatus = fegetunlock(fenode);
209
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                        }
220                }
221
222                checkpmt = 1;
223                if(flag != 1 || (flag == 1 && chnode->pmtpid == 0))
224                {
225                        patbuf = dvbgetpat(fenode, -1);
226                        if(patbuf == NULL) status.secondzap = 1;
227                }
228                debug(200, "1-secondzap=%i", status.secondzap);
229                free(status.aktservice->pmtbuf);
230                status.aktservice->pmtbuf = NULL;
231                status.aktservice->pmtlen = 0;
232                if(patbuf != NULL)
233                        status.aktservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 0);
234                else if(chnode->pmtpid > 0)
235                        status.aktservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 1);
236
237                if(status.aktservice->pmtbuf == NULL) status.secondzap = 2;
238                debug(200, "2-secondzap=%i", status.secondzap);
239                dvbgetinfo(status.aktservice->pmtbuf, chnode);
240
241                if(flag == 0)
242                {
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                        }
250                        else
251                                sendcapmt(status.aktservice, 0, 0);
252                }
253                free(patbuf);
254        }
255
256        if(flag != 0) checkpmt = 1;
257
258        //set mute for scat problem
259#ifdef MIPSEL   
260        if(status.mute != 0)
261        {
262                setmute(0);
263                tmpmute = 1;
264        }
265#else
266        if(status.mute == 0)
267        {
268                tmpmute = 1;
269                //setmute(1);
270                audiosetmute(status.aktservice->audiodev, 1);
271        }
272#endif         
273        audiostop(status.aktservice->audiodev);
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);
282                        dmxpcrnode = dmxopen(fenode, 2);
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        }
305
306        status.aktservice->dmxpcrdev = dmxpcrnode;
307
308        //demux audio start
309        if(chnode->audiopid > 0)
310        {
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                {
315                        dmxclose(status.aktservice->dmxaudiodev, -1);
316                        dmxaudionode = dmxopen(fenode, 2);
317                        if(dmxsetbuffersize(dmxaudionode, getconfigint("dmxaudiobuffersize", NULL)) != 0)
318                        {
319                                dmxclose(dmxaudionode, -1);
320                                dmxaudionode = NULL;
321                        }
322                }
323                if(dmxaudionode != NULL)
324                {
325                        if(dmxsetsource(dmxaudionode, fenode->fedmxsource) != 0)
326                        {
327                                dmxclose(dmxaudionode, -1);
328                                dmxaudionode = NULL;
329                        }
330                        if(dmxsetpesfilter(dmxaudionode, chnode->audiopid, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0) != 0)
331                        {
332                                dmxclose(dmxaudionode, -1);
333                                dmxaudionode = NULL;
334                        }
335                }
336                else
337                        err("demux audio dev not ok");
338        }
339        else
340        {
341                err("dmx audiopid not valid (%d)", chnode->audiopid);
342                dmxclose(status.aktservice->dmxaudiodev, -1);
343        }
344
345        status.aktservice->dmxaudiodev = dmxaudionode;
346
347        //demux video start
348        if(chnode->videopid > 0)
349        {
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                {
354                        dmxclose(status.aktservice->dmxvideodev, -1);
355                        dmxvideonode = dmxopen(fenode, 2);
356                        if(dmxsetbuffersize(dmxvideonode, getconfigint("dmxvideobuffersize", NULL)) != 0)
357                        {
358                                dmxclose(dmxvideonode, -1);
359                                dmxvideonode = NULL;
360                        }
361                        status.aktservice->dmxvideodev = dmxvideonode;
362                }
363                if(dmxvideonode != NULL)
364                {
365                        if(dmxsetsource(dmxvideonode, fenode->fedmxsource) != 0)
366                        {
367                                dmxclose(dmxvideonode, -1);
368                                dmxvideonode = NULL;
369                        }
370                        if(dmxsetpesfilter(dmxvideonode, chnode->videopid, -1, DMX_OUT_DECODER, DMX_PES_VIDEO, 0) != 0)
371                        {
372                                dmxclose(dmxvideonode, -1);
373                                dmxvideonode = NULL;
374                        }
375                }
376                else
377                        err("demux video dev not ok");
378        }
379        else
380        {
381                err("dmx videopid not valid (%d)", chnode->videopid);
382                dmxclose(status.aktservice->dmxvideodev, -1);
383        }
384
385        status.aktservice->dmxvideodev = dmxvideonode;
386       
387        //workaround for some audio channel not playing (for test)
388        usleep(100000);
389
390        //audio start
391        if(dmxaudionode != NULL)
392        {
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                {
397                        audioclose(status.aktservice->audiodev, -1);
398                        audionode = audioopen(fenode->adapter);
399                        status.aktservice->audiodev = audionode;
400                }
401                if(audionode != NULL)
402                {
403                        audioselectsource(audionode, AUDIO_SOURCE_DEMUX);
404                        audiosetbypassmode(audionode, chnode->audiocodec);
405                        if(checkbox("VUSOLO2") == 1) //fixt only audio no video.. blackscreen after zap
406                                audiopause(audionode);
407                        if(status.mute != 1)
408                                audioplay(audionode);
409                }
410                else
411                        err("can't get free audio dev");
412        }
413       
414        //video start
415        if(dmxvideonode != NULL)
416        {
417                if(status.aktservice->videodev != NULL && status.aktservice->videodev->fd >= 0 && status.aktservice->videodev->adapter == fenode->adapter)
418                        videonode = status.aktservice->videodev;
419                else
420                {
421                        videoclose(status.aktservice->videodev, -1);
422                        videonode = videoopen(fenode->adapter, 0);
423                        status.aktservice->videodev = videonode;
424                }
425                if(videonode != NULL)
426                {
427                        videocontinue(videonode);
428                        videoselectsource(videonode, VIDEO_SOURCE_DEMUX);
429                        setencoding(chnode, videonode);
430                       
431                        if(checkbox("VUSOLO2") == 1) //fixt only audio no video.. blackscreen after zap
432                                videofreeze(videonode);
433               
434                        if(videoplay(videonode)!= 0) {
435                                usleep(500000);
436                                videoplay(videonode);
437                        }
438                }
439                else
440                        err("can't get free video dev");
441        }
442
443#ifdef MIPSEL
444        if(tmpmute == 1)
445        {
446                tmpmute = 0;
447                setmute(1);
448        }
449#else   
450        //unset mute if set here
451        if(tmpmute == 1)
452        {
453                tmpmute = 0;
454                audiosetmute(status.aktservice->audiodev, 0);
455                //setmute(0);
456        }
457        if(status.mute != 1)
458                audioplay(status.aktservice->audiodev);
459#endif
460       
461        //check pmt if not done
462        if(checkpmt == 0)
463        {
464                //wait for tuner lock
465                if(flag == 0)
466                {
467                        if(fenode->felasttransponder != tpnode)
468                                festatus = fewait(fenode);
469                        else
470                        {
471                                festatus = fegetunlock(fenode);
472                                if(festatus != 0)
473                                {
474                                        debug(200, "fegetunlock rc:%d ... now fewait", festatus);       
475                                        festatus = fewait(fenode);
476                                }
477                        }
478
479                        if(debug_level == 200)
480                        {
481                                fereadstatus(fenode);
482                                fegetfrontend(fenode);
483                        }
484                        if(festatus != 0)
485                        {
486                                m_unlock(&status.servicemutex, 2);
487                                return 2;
488                        }
489                }
490
491                checkpmt = 1;
492                patbuf = dvbgetpat(fenode, -1);
493                if(patbuf == NULL) status.secondzap = 3;
494                debug(200, "3-secondzap=%i", status.secondzap);
495                free(status.aktservice->pmtbuf);
496                status.aktservice->pmtbuf = NULL;
497                status.aktservice->pmtlen = 0;
498                if(patbuf != NULL)
499                        status.aktservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 0);
500                else if(chnode->pmtpid > 0)
501                        status.aktservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 1);
502
503                if(status.aktservice->pmtbuf == NULL) status.secondzap = 4;
504                debug(200, "4-secondzap=%i", status.secondzap);
505                if(dvbgetinfo(status.aktservice->pmtbuf, chnode) == 1)
506                {
507                        //audio or video pid or codec changed
508                        free(status.aktservice->pmtbuf);
509                        status.aktservice->pmtbuf = NULL;
510                        status.aktservice->pmtlen = -1;
511                }
512
513                if(flag == 0)
514                {
515                        if(status.pmtmode == 1)
516                        {
517                                if(recordcheckcrypt(fenode, CHANNEL) == 0)
518                                        dvbwritepmt(status.aktservice, status.aktservice->pmtbuf);
519                                else
520                                        debug(200, "don't write pmt.tmp, another crypt channel use this frontend");
521                        }
522                        else
523                                sendcapmt(status.aktservice, 0, 0);
524                }
525                free(patbuf);
526        }
527
528        //get ait and parse it for hbbtv url
529        if(flag == 0 && chnode->aitpid > 0)
530        {
531                unsigned char* aitbuf = NULL;
532                aitbuf = dvbgetait(fenode, chnode->aitpid, 0, -1);
533                if(aitbuf != NULL)
534                {
535                        free(chnode->hbbtvurl); chnode->hbbtvurl = NULL;
536                        chnode->hbbtvurl = dvbgethbbtvurl(aitbuf);
537                }
538
539                debug(200, "hbbtvurl=%s", chnode->hbbtvurl);
540                free(aitbuf); aitbuf = NULL;
541        }
542
543        if(flag == 0)
544        {
545                //add channel to history
546                if(status.aktservice->type == CHANNEL)
547                {
548                        addchannelhistory(chnode, status.aktservice->channellist);
549                        if(status.servicetype == 0) //only for tv
550                                createmostzap(chnode->serviceid, chnode->transponderid);
551                }
552                festatus = fewait(fenode);
553                if(festatus != 0)
554                {
555                        m_unlock(&status.servicemutex, 2);
556                        err("festatus=%i", festatus );
557                        return 2;
558                }
559        }
560
561        //wait for epg thread stops
562        if(flag == 0 && status.epgthread != NULL)
563        {
564                i = 0;
565                while(status.epgthread->status != INPAUSE)
566                {
567                        usleep(10000);
568                        i++; if(i > 300) break;
569                }
570                status.epgthread->aktion = START;
571        }
572
573        status.videosizevalid = time(NULL);
574        m_unlock(&status.servicemutex, 2);
575       
576        //auto change channel name
577        if(flag == 0 && status.autochangechannelname == 1)
578                addtimer(&autochangechannelname, START, 1000, 1, NULL, NULL, NULL);
579       
580        //autoresolution
581        if(flag == 0 && ostrcmp(getconfig("av_videomode_autores", NULL), "auto") == 0)
582        {
583                int sec = 7;
584                char* av_videomode_autores_ts = getconfig("av_videomode_autores_ts", NULL);
585                if(av_videomode_autores_ts != NULL)
586                        sec = atoi(av_videomode_autores_ts);
587                if(status.restimer == NULL)
588                        status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
589                else
590                {
591                        status.restimer->aktion = STOP;
592                        status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
593                }                       
594        }
595       
596        if(flag == 0 && status.autosubtitle == 1) subtitlestartlast(); //start subtitle
597        if(flag == 0 && status.timeshifttype == 1)
598        {
599                i = 0;
600                while(status.timeshift > 0)
601                {
602                        usleep(100000);
603                        i++; if(i > 20) break;
604                }
605                timeshiftpause(); //start permanent timeshift record
606        }
607       
608        debug(200, "servicestartreal... ended with 0");
609        return 0;
610}
611
612//second zap on failure
613int servicestart(struct channel* chnode, char* channellist, char* pin, int flag)
614{
615        int ret = 0;
616       
617        ret = servicestartreal(chnode, channellist, pin, flag);
618        debug(200, "servicestart... started");
619        if(status.secondzap != 0 && ret == 0 && (flag == 0 || flag > 2))
620        {
621                debug(200, "first zap not ok, make second zap (%d)", status.secondzap);
622                ret = servicestartreal(chnode, channellist, pin, 6);
623        }
624        debug(200, "servicestart... ended");
625        return ret;
626}
627
628//flag 0: lock
629//flag 1: no lock
630struct service* getservicebyrecname(char* file, int type, int flag)
631{
632        if(file == NULL) return NULL;
633
634        if(flag == 0) m_lock(&status.servicemutex, 2);
635        struct service* snode = service;
636
637        while(snode != NULL)
638        {
639                if(ostrcmp(snode->recname, file) == 0 && (type == 0 || (type == 1 && (snode->type == RECORDDIRECT || snode->type == RECORDTIMER))))
640                {
641                        if(flag == 0) m_unlock(&status.servicemutex, 2);
642                        return snode;
643                }
644                snode = snode->next;
645        }
646        if(flag == 0) m_unlock(&status.servicemutex, 2);
647        return NULL;
648}
649
650struct service* getservicebychannel(struct channel* chnode)
651{
652        m_lock(&status.servicemutex, 2);
653        struct service* snode = service;
654
655        while(snode != NULL)
656        {
657                if(snode->channel == chnode)
658                {
659                        m_unlock(&status.servicemutex, 2);
660                        return snode;
661                }
662                snode = snode->next;
663
664        }
665        m_unlock(&status.servicemutex, 2);
666        return NULL;
667}
668
669//flag 0: lock
670//flag 1: no lock
671struct service* getservicebyrectimestamp(char* timestamp, int flag)
672{
673        if(timestamp == 0) return NULL;
674
675        if(flag == 0) m_lock(&status.servicemutex, 2);
676        struct service* snode = service;
677
678        while(snode != NULL)
679        {
680                if(ostrcmp(snode->rectimestamp, timestamp) == 0)
681                {
682                        if(flag == 0) m_unlock(&status.servicemutex, 2);
683                        return snode;
684                }
685                snode = snode->next;
686        }
687        if(flag == 0) m_unlock(&status.servicemutex, 2);
688        return NULL;
689}
690
691struct service* getservicebyservice(struct service* node, int flag)
692{
693        if(flag == 0) m_lock(&status.servicemutex, 2);
694        struct service* snode = service;
695
696        while(snode != NULL)
697        {
698                if(snode != status.lastservice && snode != node && snode->channel == node->channel)
699                {
700                        if(flag == 0) m_unlock(&status.servicemutex, 2);
701                        return snode;
702                }
703                snode = snode->next;
704        }
705        if(flag == 0) m_unlock(&status.servicemutex, 2);
706        return NULL;
707}
708
709//flag 0: with mutex
710//flag 1: without mutex
711struct service* getservice(int type, int flag)
712{
713        if(flag == 0) m_lock(&status.servicemutex, 2);
714        struct service* snode = service;
715
716        while(snode != NULL)
717        {
718                if(snode->type == type)
719                {
720                        if(flag == 0) m_unlock(&status.servicemutex, 2);
721                        return snode;
722                }
723                snode = snode->next;
724        }
725        if(flag == 0) m_unlock(&status.servicemutex, 2);
726        return NULL;
727}
728
729//flag 0: faststop depends on param faststop
730//flag 1: always normal stop
731//flag 2: from timeshift/player
732//flag 3: same as 0 but no akttolast
733//flag 4: showiframe
734int servicestop(struct service *node, int clear, int flag)
735{
736        int rcret = 0;
737
738        if(node != NULL)
739        {
740                status.tvpic = 0;
741
742                if(status.timeshift == 1 && flag != 2)
743                {
744                        if(status.timeshifttype == 0 && status.asktimeshift == 0)
745                                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);
746
747                        if(rcret == 2) return 1;
748                        timeshiftstop(1);
749                }
750                if(flag != 2 && node->type != NOTHING && node->type != STILLPIC) caservicedel(node, NULL);
751
752
753                truncate("/tmp/ecm.info", 0);
754                unlink("/tmp/pid.info");
755                unlink("/tmp/caids.info");
756               
757                status.videosizevalid = 0;
758
759                if(status.epgthread != NULL) status.epgthread->aktion = PAUSE;
760                subtitlestop(0);
761
762
763                if(node->type == CHANNEL && flag < 2) akttolast();
764
765                if(flag != 2) node->type = NOTHING;
766                if(flag == 4) node->type = STILLPIC;
767               
768                audiostop(node->audiodev);
769                if(checkbox("VUSOLO2") == 1) videoclearbuffer(node->videodev);
770                videostop(node->videodev, clear);
771
772                int fastzap = getconfigint("fastzap", NULL);
773
774                if(flag == 3) flag = 0;
775                if(flag == 4 || flag == 1 || (flag == 0 && (fastzap == 0 || fastzap == 2)))
776                {
777                        audioclose(node->audiodev, -1);
778                        node->audiodev = NULL;
779                        dmxstop(node->dmxaudiodev);
780                        dmxclose(node->dmxaudiodev, -1);
781                        node->dmxaudiodev = NULL;
782                }
783               
784                if(flag == 4 || flag == 1 || (flag == 0 && fastzap == 0))
785                {
786                        videoclose(node->videodev, -1);
787                        node->videodev = NULL;
788                        dmxstop(node->dmxvideodev);
789                        dmxclose(node->dmxvideodev, -1);
790                        node->dmxvideodev = NULL;
791                        dmxstop(node->dmxpcrdev);
792                        dmxclose(node->dmxpcrdev, -1);
793                        node->dmxpcrdev = NULL;
794                        dmxstop(node->dmxsubtitledev);
795                        dmxclose(node->dmxsubtitledev, -1);
796                        node->dmxsubtitledev = NULL;
797                }
798                return 0;
799        }
800        return 1;
801}
802
803void servicechangeaudio(struct channel* chnode, struct audiotrack* tracknode)
804{
805        if(chnode == NULL || tracknode == NULL)
806        {
807                err("NULL detect");
808                return;
809        }
810
811        if(chnode->audiopid == tracknode->audiopid && chnode->audiocodec == tracknode->audiocodec)
812                return;
813
814        chnode->audiopid = tracknode->audiopid;
815        chnode->audiocodec = tracknode->audiocodec;
816
817        status.writechannel = 1;
818        audiostop(status.aktservice->audiodev);
819        audiosetbypassmode(status.aktservice->audiodev, chnode->audiocodec);
820        //clear videobuffer on playback for syncing video / audio
821        if(status.playing == 1) videoclearbuffer(status.aktservice->videodev);
822        dmxsetpesfilter(status.aktservice->dmxaudiodev, chnode->audiopid, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0);
823
824        //don't start audio play, if we are in timeshift record, but not playing mode
825        if(status.timeshifttype == 0 && status.timeshift == 1 && status.playing == 0) return;
826        if(status.timeshifttype == 1 && status.timeshift == 1 && status.playing == 0 && status.timeshiftpos > 0) return;
827
828        if(status.mute != 1)
829                audioplay(status.aktservice->audiodev);
830}
831
832struct service* addservice(struct service* last)
833{
834        struct service *newnode = NULL, *node = NULL;
835
836        newnode = (struct service*)calloc(1, sizeof(struct service));
837        if(newnode == NULL)
838        {
839                err("no memory");
840                return NULL;
841        }
842
843        newnode->recdstfd = -1;
844        newnode->recsrcfd = -1;
845        newnode->tssize = 188;
846
847        m_lock(&status.servicemutex, 2);
848        node = service;
849        if(node != NULL)
850        {
851                if(last == NULL)
852                {
853                        while(node->next != NULL)
854                                node = node->next;
855                        node->next = newnode;
856                }
857                else
858                        last->next = newnode;
859        }
860        else
861                service = newnode;
862
863        m_unlock(&status.servicemutex, 2);
864        return newnode;
865}
866
867struct service* checkservice(struct service* node)
868{
869        struct service* snode = service;
870
871        while(snode != NULL)
872        {
873                if(snode == node)
874                        return snode;
875                snode = snode->next;
876        }
877        return NULL;
878}
879
880//flag 0: set mutex
881//flag 1: not set mutex
882void delservice(struct service* snode, int flag)
883{
884        m_lock(&status.servicemutex, 2);
885        struct service *node = service, *prev = service;
886        struct rectimer *rectimernode = NULL;
887
888        while(node != NULL)
889        {
890                if(node == snode)
891                {
892                        if(node == service)
893                                service = node->next;
894                        else
895                                prev->next = node->next;
896
897                        dmxclose(node->dmxaudiodev, -1);
898                        dmxclose(node->dmxvideodev, -1);
899                        dmxclose(node->dmxpcrdev, -1);
900                        dmxclose(node->dmxsubtitledev, -1);
901                        audioclose(node->audiodev, -1);
902                        videoclose(node->videodev, -1);
903                        close(node->recdstfd);
904                        close(node->recsrcfd);
905                        caservicedel(node, NULL);
906
907                        //check if a rectimer is joined with a service
908                        if(node->type == RECORDTIMER)
909                        {
910                                if(flag == 0)
911                                        m_lock(&status.rectimermutex, 1);
912
913                                rectimernode = getrectimerbyservice(node);
914                                if(rectimernode != NULL)
915                                {
916                                        rectimernode->servicenode = NULL;
917                                        if(rectimernode->status == 0 || rectimernode->status == 1)
918                                        {
919                                                rectimernode->status = 2;
920                                                status.writerectimer = 1;
921                                                writerectimer(getconfig("rectimerfile", NULL), 1);
922                                        }
923                                }
924
925                                if(flag == 0)
926                                        m_unlock(&status.rectimermutex, 1);
927                        }
928
929                        free(node->channellist);
930                        node->channellist = NULL;
931
932                        free(node->recname);
933                        node->recname = NULL;
934
935                        free(node->rectimestamp);
936                        node->rectimestamp = NULL;
937
938                        free(node->pmtbuf);
939                        node->pmtbuf = NULL;
940
941                        free(node);
942                        node = NULL;
943                        break;
944                }
945
946                prev = node;
947                node = node->next;
948        }
949        m_unlock(&status.servicemutex, 2);
950}
951
952void freeservice()
953{
954        struct service *node = service, *prev = service;
955
956        while(node != NULL)
957        {
958                prev = node;
959                node = node->next;
960                if(prev != NULL)
961                        delservice(prev, 0);
962        }
963}
964
965char* servicecheckret(int ret, int flag)
966{
967        char* tmpstr = NULL;
968
969        if(ret != 0)
970        {
971                switch(ret)
972                {
973                        case 1:
974                                tmpstr = ostrcat(_("Can't find a Tuner.\nAll Tuners in use or no Tuner defined."), NULL, 0, 0);
975                                break;
976                        case 2:
977                                tmpstr = ostrcat(_("Tuning to Channel failed!"), NULL, 0, 0);
978                                break;
979                        case 3:
980                                tmpstr = ostrcat(_("Can't open frontend dev or Frontend Type unknown!"), NULL, 0, 0);
981                                break;
982                        case 20:
983                                break;
984                        case 21:
985                                tmpstr = ostrcat(_("Channellist empty or corrupt (channel not found)!"), NULL, 0, 0);
986                                break;
987                        case 22:
988                                break;
989                }
990                if(tmpstr != NULL)
991                        textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0);
992        }
993
994        if(flag != 1)
995        {
996                free(tmpstr);
997                tmpstr = NULL;
998        }
999
1000        return tmpstr;
1001}
1002
1003#ifdef MIPSEL
1004void servicefullHDMIin_start()
1005{
1006        struct dvbdev *videonode = NULL;
1007        struct dvbdev *audionode = NULL;
1008        struct channel *chnode = NULL;
1009       
1010        servicestop(status.aktservice, 1, 1);
1011       
1012        audionode = audioopen(0);
1013        if(audionode != NULL)
1014        {
1015                audioselectsource(audionode, AUDIO_SOURCE_HDMI);
1016                audioplay(audionode);
1017        }
1018        videonode = videoopen(0, 0);
1019        if(videonode != NULL)
1020        {
1021                videoselectsource(videonode, VIDEO_SOURCE_HDMI);
1022                videosetstreamtype(videonode, 0);
1023                videoplay(videonode);
1024        }
1025        status.aktservice->videodev = videonode;
1026        status.aktservice->audiodev = audionode;
1027        status.aktservice->type = HDMIIN;
1028        chnode = getchannel(65535, 0);
1029        if(chnode == NULL)
1030                //chnode = createchannel("HDMIIN", 0, 0, 65535, 99, 0, -1, -1, -1, -1, 0, -1);
1031                chnode = createchannel("HDMIIN", 0, 0, 65535, 0, 0, -1, -1, -1, -1, 0, -1);
1032        status.aktservice->channel = chnode;
1033}
1034#endif
1035
1036#endif
Note: See TracBrowser for help on using the repository browser.