source: titan/titan/service.h @ 37438

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

test

File size: 25.5 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(status.mute != 1)
406                                audioplay(audionode);
407                }
408                else
409                        err("can't get free audio dev");
410        }
411       
412        //video start
413        if(dmxvideonode != NULL)
414        {
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                {
419                        videoclose(status.aktservice->videodev, -1);
420                        videonode = videoopen(fenode->adapter, 0);
421                        status.aktservice->videodev = videonode;
422                }
423                if(videonode != NULL)
424                {
425                        videocontinue(videonode);
426                        videoselectsource(videonode, VIDEO_SOURCE_DEMUX);
427                        setencoding(chnode, videonode);
428                       
429                        if(checkbox("VUSOLO2") == 1) //fixt only audio no video.. blackscreen after zap
430                                videofreeze(videonode);
431               
432                        if(videoplay(videonode)!= 0) {
433                                usleep(500000);
434                                videoplay(videonode);
435                        }
436                }
437                else
438                        err("can't get free video dev");
439        }
440
441#ifdef MIPSEL
442        if(tmpmute == 1)
443        {
444                tmpmute = 0;
445                setmute(1);
446        }
447#else   
448        //unset mute if set here
449        if(tmpmute == 1)
450        {
451                tmpmute = 0;
452                audiosetmute(status.aktservice->audiodev, 0);
453                //setmute(0);
454        }
455        if(status.mute != 1)
456                audioplay(status.aktservice->audiodev);
457#endif
458       
459        //check pmt if not done
460        if(checkpmt == 0)
461        {
462                //wait for tuner lock
463                if(flag == 0)
464                {
465                        if(fenode->felasttransponder != tpnode)
466                                festatus = fewait(fenode);
467                        else
468                        {
469                                festatus = fegetunlock(fenode);
470                                if(festatus != 0)
471                                {
472                                        debug(200, "fegetunlock rc:%d ... now fewait", festatus);       
473                                        festatus = fewait(fenode);
474                                }
475                        }
476
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                        }
487                }
488
489                checkpmt = 1;
490                patbuf = dvbgetpat(fenode, -1);
491                if(patbuf == NULL) status.secondzap = 3;
492                debug(200, "3-secondzap=%i", status.secondzap);
493                free(status.aktservice->pmtbuf);
494                status.aktservice->pmtbuf = NULL;
495                status.aktservice->pmtlen = 0;
496                if(patbuf != NULL)
497                        status.aktservice->pmtbuf = dvbgetpmt(fenode, patbuf, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 0);
498                else if(chnode->pmtpid > 0)
499                        status.aktservice->pmtbuf = dvbgetpmt(fenode, NULL, chnode->serviceid, &chnode->pmtpid, &status.aktservice->pmtlen, -1, 1);
500
501                if(status.aktservice->pmtbuf == NULL) status.secondzap = 4;
502                debug(200, "4-secondzap=%i", status.secondzap);
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;
508                        status.aktservice->pmtlen = -1;
509                }
510
511                if(flag == 0)
512                {
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                        }
520                        else
521                                sendcapmt(status.aktservice, 0, 0);
522                }
523                free(patbuf);
524        }
525
526        //get ait and parse it for hbbtv url
527        if(flag == 0 && chnode->aitpid > 0)
528        {
529                unsigned char* aitbuf = NULL;
530                aitbuf = dvbgetait(fenode, chnode->aitpid, 0, -1);
531                if(aitbuf != NULL)
532                {
533                        free(chnode->hbbtvurl); chnode->hbbtvurl = NULL;
534                        chnode->hbbtvurl = dvbgethbbtvurl(aitbuf);
535                }
536
537                debug(200, "hbbtvurl=%s", chnode->hbbtvurl);
538                free(aitbuf); aitbuf = NULL;
539        }
540
541        if(flag == 0)
542        {
543                //add channel to history
544                if(status.aktservice->type == CHANNEL)
545                {
546                        addchannelhistory(chnode, status.aktservice->channellist);
547                        if(status.servicetype == 0) //only for tv
548                                createmostzap(chnode->serviceid, chnode->transponderid);
549                }
550                festatus = fewait(fenode);
551                if(festatus != 0)
552                {
553                        m_unlock(&status.servicemutex, 2);
554                        err("festatus=%i", festatus );
555                        return 2;
556                }
557        }
558
559        //wait for epg thread stops
560        if(flag == 0 && status.epgthread != NULL)
561        {
562                i = 0;
563                while(status.epgthread->status != INPAUSE)
564                {
565                        usleep(10000);
566                        i++; if(i > 300) break;
567                }
568                status.epgthread->aktion = START;
569        }
570
571        status.videosizevalid = time(NULL);
572        m_unlock(&status.servicemutex, 2);
573       
574        //auto change channel name
575        if(flag == 0 && status.autochangechannelname == 1)
576                addtimer(&autochangechannelname, START, 1000, 1, NULL, NULL, NULL);
577       
578        //autoresolution
579        if(flag == 0 && ostrcmp(getconfig("av_videomode_autores", NULL), "auto") == 0)
580        {
581                int sec = 7;
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);
585                if(status.restimer == NULL)
586                        status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
587                else
588                {
589                        status.restimer->aktion = STOP;
590                        status.restimer = addtimer(&setaktres, START, 1000, 1, (void*)sec, NULL, NULL);
591                }                       
592        }
593       
594        if(flag == 0 && status.autosubtitle == 1) subtitlestartlast(); //start subtitle
595        if(flag == 0 && status.timeshifttype == 1)
596        {
597                i = 0;
598                while(status.timeshift > 0)
599                {
600                        usleep(100000);
601                        i++; if(i > 20) break;
602                }
603                timeshiftpause(); //start permanent timeshift record
604        }
605       
606        debug(200, "servicestartreal... ended with 0");
607        return 0;
608}
609
610//second zap on failure
611int servicestart(struct channel* chnode, char* channellist, char* pin, int flag)
612{
613        int ret = 0;
614       
615        ret = servicestartreal(chnode, channellist, pin, flag);
616        debug(200, "servicestart... started");
617        if(status.secondzap != 0 && ret == 0 && (flag == 0 || flag > 2))
618        {
619                debug(200, "first zap not ok, make second zap (%d)", status.secondzap);
620                ret = servicestartreal(chnode, channellist, pin, 6);
621        }
622        debug(200, "servicestart... ended");
623        return ret;
624}
625
626//flag 0: lock
627//flag 1: no lock
628struct service* getservicebyrecname(char* file, int type, int flag)
629{
630        if(file == NULL) return NULL;
631
632        if(flag == 0) m_lock(&status.servicemutex, 2);
633        struct service* snode = service;
634
635        while(snode != NULL)
636        {
637                if(ostrcmp(snode->recname, file) == 0 && (type == 0 || (type == 1 && (snode->type == RECORDDIRECT || snode->type == RECORDTIMER))))
638                {
639                        if(flag == 0) m_unlock(&status.servicemutex, 2);
640                        return snode;
641                }
642                snode = snode->next;
643        }
644        if(flag == 0) m_unlock(&status.servicemutex, 2);
645        return NULL;
646}
647
648struct service* getservicebychannel(struct channel* chnode)
649{
650        m_lock(&status.servicemutex, 2);
651        struct service* snode = service;
652
653        while(snode != NULL)
654        {
655                if(snode->channel == chnode)
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
667//flag 0: lock
668//flag 1: no lock
669struct service* getservicebyrectimestamp(char* timestamp, int flag)
670{
671        if(timestamp == 0) return NULL;
672
673        if(flag == 0) m_lock(&status.servicemutex, 2);
674        struct service* snode = service;
675
676        while(snode != NULL)
677        {
678                if(ostrcmp(snode->rectimestamp, timestamp) == 0)
679                {
680                        if(flag == 0) m_unlock(&status.servicemutex, 2);
681                        return snode;
682                }
683                snode = snode->next;
684        }
685        if(flag == 0) m_unlock(&status.servicemutex, 2);
686        return NULL;
687}
688
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
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        {
716                if(snode->type == type)
717                {
718                        if(flag == 0) m_unlock(&status.servicemutex, 2);
719                        return snode;
720                }
721                snode = snode->next;
722        }
723        if(flag == 0) m_unlock(&status.servicemutex, 2);
724        return NULL;
725}
726
727//flag 0: faststop depends on param faststop
728//flag 1: always normal stop
729//flag 2: from timeshift/player
730//flag 3: same as 0 but no akttolast
731//flag 4: showiframe
732int servicestop(struct service *node, int clear, int flag)
733{
734        int rcret = 0;
735
736        if(node != NULL)
737        {
738                status.tvpic = 0;
739
740                if(status.timeshift == 1 && flag != 2)
741                {
742                        if(status.timeshifttype == 0 && status.asktimeshift == 0)
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);
744
745                        if(rcret == 2) return 1;
746                        timeshiftstop(1);
747                }
748                if(flag != 2 && node->type != NOTHING && node->type != STILLPIC) caservicedel(node, NULL);
749
750
751                truncate("/tmp/ecm.info", 0);
752                unlink("/tmp/pid.info");
753                unlink("/tmp/caids.info");
754               
755                status.videosizevalid = 0;
756
757                if(status.epgthread != NULL) status.epgthread->aktion = PAUSE;
758                subtitlestop(0);
759
760
761                if(node->type == CHANNEL && flag < 2) akttolast();
762
763                if(flag != 2) node->type = NOTHING;
764                if(flag == 4) node->type = STILLPIC;
765               
766                audiostop(node->audiodev);
767                if(checkbox("VUSOLO2") == 1) videoclearbuffer(node->videodev);
768                videostop(node->videodev, clear);
769
770                int fastzap = getconfigint("fastzap", NULL);
771
772                if(flag == 3) flag = 0;
773                if(flag == 4 || flag == 1 || (flag == 0 && (fastzap == 0 || fastzap == 2)))
774                {
775                        audioclose(node->audiodev, -1);
776                        node->audiodev = NULL;
777                        dmxstop(node->dmxaudiodev);
778                        dmxclose(node->dmxaudiodev, -1);
779                        node->dmxaudiodev = NULL;
780                }
781               
782                if(flag == 4 || flag == 1 || (flag == 0 && fastzap == 0))
783                {
784                        videoclose(node->videodev, -1);
785                        node->videodev = NULL;
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;
795                }
796                return 0;
797        }
798        return 1;
799}
800
801void servicechangeaudio(struct channel* chnode, struct audiotrack* tracknode)
802{
803        if(chnode == NULL || tracknode == NULL)
804        {
805                err("NULL detect");
806                return;
807        }
808
809        if(chnode->audiopid == tracknode->audiopid && chnode->audiocodec == tracknode->audiocodec)
810                return;
811
812        chnode->audiopid = tracknode->audiopid;
813        chnode->audiocodec = tracknode->audiocodec;
814
815        status.writechannel = 1;
816        audiostop(status.aktservice->audiodev);
817        audiosetbypassmode(status.aktservice->audiodev, chnode->audiocodec);
818        //clear videobuffer on playback for syncing video / audio
819        if(status.playing == 1) videoclearbuffer(status.aktservice->videodev);
820        dmxsetpesfilter(status.aktservice->dmxaudiodev, chnode->audiopid, -1, DMX_OUT_DECODER, DMX_PES_AUDIO, 0);
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
826        if(status.mute != 1)
827                audioplay(status.aktservice->audiodev);
828}
829
830struct service* addservice(struct service* last)
831{
832        struct service *newnode = NULL, *node = NULL;
833
834        newnode = (struct service*)calloc(1, sizeof(struct service));
835        if(newnode == NULL)
836        {
837                err("no memory");
838                return NULL;
839        }
840
841        newnode->recdstfd = -1;
842        newnode->recsrcfd = -1;
843        newnode->tssize = 188;
844
845        m_lock(&status.servicemutex, 2);
846        node = service;
847        if(node != NULL)
848        {
849                if(last == NULL)
850                {
851                        while(node->next != NULL)
852                                node = node->next;
853                        node->next = newnode;
854                }
855                else
856                        last->next = newnode;
857        }
858        else
859                service = newnode;
860
861        m_unlock(&status.servicemutex, 2);
862        return newnode;
863}
864
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
878//flag 0: set mutex
879//flag 1: not set mutex
880void delservice(struct service* snode, int flag)
881{
882        m_lock(&status.servicemutex, 2);
883        struct service *node = service, *prev = service;
884        struct rectimer *rectimernode = NULL;
885
886        while(node != NULL)
887        {
888                if(node == snode)
889                {
890                        if(node == service)
891                                service = node->next;
892                        else
893                                prev->next = node->next;
894
895                        dmxclose(node->dmxaudiodev, -1);
896                        dmxclose(node->dmxvideodev, -1);
897                        dmxclose(node->dmxpcrdev, -1);
898                        dmxclose(node->dmxsubtitledev, -1);
899                        audioclose(node->audiodev, -1);
900                        videoclose(node->videodev, -1);
901                        close(node->recdstfd);
902                        close(node->recsrcfd);
903                        caservicedel(node, NULL);
904
905                        //check if a rectimer is joined with a service
906                        if(node->type == RECORDTIMER)
907                        {
908                                if(flag == 0)
909                                        m_lock(&status.rectimermutex, 1);
910
911                                rectimernode = getrectimerbyservice(node);
912                                if(rectimernode != NULL)
913                                {
914                                        rectimernode->servicenode = NULL;
915                                        if(rectimernode->status == 0 || rectimernode->status == 1)
916                                        {
917                                                rectimernode->status = 2;
918                                                status.writerectimer = 1;
919                                                writerectimer(getconfig("rectimerfile", NULL), 1);
920                                        }
921                                }
922
923                                if(flag == 0)
924                                        m_unlock(&status.rectimermutex, 1);
925                        }
926
927                        free(node->channellist);
928                        node->channellist = NULL;
929
930                        free(node->recname);
931                        node->recname = NULL;
932
933                        free(node->rectimestamp);
934                        node->rectimestamp = NULL;
935
936                        free(node->pmtbuf);
937                        node->pmtbuf = NULL;
938
939                        free(node);
940                        node = NULL;
941                        break;
942                }
943
944                prev = node;
945                node = node->next;
946        }
947        m_unlock(&status.servicemutex, 2);
948}
949
950void freeservice()
951{
952        struct service *node = service, *prev = service;
953
954        while(node != NULL)
955        {
956                prev = node;
957                node = node->next;
958                if(prev != NULL)
959                        delservice(prev, 0);
960        }
961}
962
963char* servicecheckret(int ret, int flag)
964{
965        char* tmpstr = NULL;
966
967        if(ret != 0)
968        {
969                switch(ret)
970                {
971                        case 1:
972                                tmpstr = ostrcat(_("Can't find a Tuner.\nAll Tuners in use or no Tuner defined."), NULL, 0, 0);
973                                break;
974                        case 2:
975                                tmpstr = ostrcat(_("Tuning to Channel failed!"), NULL, 0, 0);
976                                break;
977                        case 3:
978                                tmpstr = ostrcat(_("Can't open frontend dev or Frontend Type unknown!"), NULL, 0, 0);
979                                break;
980                        case 20:
981                                break;
982                        case 21:
983                                tmpstr = ostrcat(_("Channellist empty or corrupt (channel not found)!"), NULL, 0, 0);
984                                break;
985                        case 22:
986                                break;
987                }
988                if(tmpstr != NULL)
989                        textbox(_("Message"), tmpstr, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0);
990        }
991
992        if(flag != 1)
993        {
994                free(tmpstr);
995                tmpstr = NULL;
996        }
997
998        return tmpstr;
999}
1000
1001#ifdef MIPSEL
1002void servicefullHDMIin_start()
1003{
1004        struct dvbdev *videonode = NULL;
1005        struct dvbdev *audionode = NULL;
1006        struct channel *chnode = NULL;
1007       
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;
1026        chnode = getchannel(65535, 0);
1027        if(chnode == NULL)
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);
1030        status.aktservice->channel = chnode;
1031}
1032#endif
1033
1034#endif
Note: See TracBrowser for help on using the repository browser.