source: titan/titan/titan.c @ 32945

Last change on this file since 32945 was 32945, checked in by obi, 9 years ago

fix reboot after record when streaming

File size: 32.1 KB
Line 
1#include "struct.h"
2#include "header.h"
3#include "debug.h"
4#include "crc32.h"
5#include "sock.h"
6
7#define SYSCODE 0UL
8#define HTTPAUTH "aXBrLUdaRmg6RkhaVkJHaG56ZnZFaEZERlRHenVpZjU2NzZ6aGpHVFVHQk5Iam0="
9
10struct clist *config[LISTHASHSIZE] = {NULL};
11struct clist *ownconfig[LISTHASHSIZE] = {NULL};
12struct clist *rcconfig[LISTHASHSIZE] = {NULL};
13struct clist *skinconfig[LISTHASHSIZE] = {NULL};
14struct skin *skin = NULL;
15struct fb *fb = NULL;
16struct fb* skinfb = NULL;
17struct fb* accelfb = NULL;
18struct fb* fb1 = NULL;
19struct fb* lcdskinfb = NULL;
20struct fb* oledskinfb = NULL;
21struct font *font = NULL;
22struct rc *rc = NULL;
23struct dvbdev *dvbdev = NULL;
24struct dvbdev *dvbdevsim = NULL;
25struct channel *channel = NULL;
26struct transponder *transponder = NULL;
27struct provider *provider = NULL;
28struct sat *sat = NULL;
29struct service *service = NULL;
30struct mainbouquet *mainbouquet = NULL;
31struct mainplaylist *mainplaylist = NULL;
32struct pic *pic = NULL;
33struct rcmap *rcmap = NULL;
34struct inetwork *inetwork = NULL;
35struct stimerthread *stimerthread = NULL;
36struct rectimer *rectimer = NULL;
37struct subpage* subpage = NULL, *oldsubpage = NULL;
38struct epgscanlist* epgscanlist = NULL;
39struct screensaver* screensaver = NULL;
40struct channelcache* channelcache[CHANNELCACHEMAX] = {NULL};
41struct transpondercache* transpondercache[TRANSPONDERCACHEMAX] = {NULL};
42struct hdd* hdd = NULL;
43struct queue* queue = NULL;
44struct caservice caservice[MAXCASERVICE];
45struct channelhistory channelhistory[MAXCHANNELHISTORY];
46struct mostzap* mostzap = NULL;
47struct mediadbfilter* mediadbfilter = NULL;
48struct mediadbcategory* mediadbcategory = NULL;
49struct mediadb* mediadb = NULL;
50struct mediadbcache* mediadbcache[MEDIADBCACHEMAX] = {NULL};
51struct unicable* unicable = NULL;
52struct oldentry* oldentry = NULL;
53struct newsletter* newsletter = NULL;
54struct extepgcache* extepgcache = NULL;
55struct extepgchannel* extepgchannel = NULL;
56struct extepgconfig* extepgconfig = NULL;
57struct lastsubtitle* lastsubtitle = NULL;
58struct style* style = NULL;
59struct download* bgdownload[MAXBGDOWNLOAD] = {NULL};
60struct channelslot *channelslot = NULL;
61
62#ifdef SH4
63#include "sh4port.h"
64#endif
65
66#ifdef MIPSEL
67#include "mipselport.h"
68#endif
69
70#ifdef I386
71#include "i386port.h"
72#endif
73
74#include "oldentry.h"
75#include "tpk.h"
76#include "queue.h"
77#include "channelcache.h"
78#include "transpondercache.h"
79#include "strconvert.h"
80#include "numinput.h"
81#include "textinput.h"
82#include "radiotext.h"
83#include "list.h"
84#include "config.h"
85#include "defaults.h"
86#include "ownconfig.h"
87#include "rcconfig.h"
88#include "skinconfig.h"
89#include "thumb.h"
90#include "global.h"
91#include "security.h"
92#include "stream.h"
93#include "dvbdev.h"
94#include "rotorcalc.h"
95#include "frontenddev.h"
96#include "dmxdev.h"
97#include "videodev.h"
98#include "audiodev.h"
99#include "cidev.h"
100#include "cadev.h"
101#include "scdev.h"
102#include "ca.h"
103#include "dvrdev.h"
104#include "cam.h"
105#include "dvb.h"
106#include "fb.h"
107#include "font.h"
108#include "rcmap.h"
109#include "rc.h"
110#include "sat.h"
111#include "transponder.h"
112#include "provider.h"
113#include "channel.h"
114#include "bouquets.h"
115#include "mainbouquets.h"
116#include "playlist.h"
117#include "mainplaylist.h"
118#include "pic.h"
119#include "filelist.h"
120#include "skinfunc.h"
121#include "style.h"
122#include "skin.h"
123#include "inputhelp.h"
124#include "rcfunc.h"
125#include "listbox.h"
126#include "choicebox.h"
127#include "vfd.h"
128#include "timerthread.h"
129#include "service.h"
130#include "pip.h"
131#include "player.h"
132#include "dvdplayer.h"
133#include "timeshift.h"
134#include "record.h"
135#include "zap.h"
136#include "showiframe.h"
137#include "epgrecord.h"
138#include "multiepg.h"
139#include "gmultiepg.h"
140#include "epg.h"
141#include "eit.h"
142#include "extepg.h"
143#include "epgscan.h"
144#include "menulist.h"
145#include "videomode.h"
146#include "inetwork.h"
147#include "keyactions.h"
148#include "scart.h"
149#include "standby.h"
150#include "dir.h"
151#include "spinner.h"
152#include "lnbconfig.h"
153#include "diseqcconfig.h"
154#include "tunerconfig.h"
155#include "epgsettings.h"
156#include "listedit.h"
157#include "channellist.h"
158#include "vfdisplay.h"
159#include "videosettings.h"
160#include "textbox.h"
161#include "autores.h"
162#include "language.h"
163#include "about.h"
164#include "serviceinfo.h"
165#include "avsettings.h"
166#include "mute.h"
167#include "volume.h"
168#include "timezone.h"
169#include "adjust.h"
170#include "skinadjust.h"
171#include "blindscanadjust.h"
172#include "moduleconfig.h"
173#include "scconfig.h"
174#include "possetup.h"
175#include "rectimer.h"
176#include "pin.h"
177#include "plugin.h"
178#include "recordpath.h"
179#include "subtitle.h"
180#include "audiotrack.h"
181#include "linkedchannel.h"
182#include "powerofftimer.h"
183#include "skinselector.h"
184#include "play.h"
185#include "satfinder.h"
186#include "menu.h"
187#include "channelbynr.h"
188#include "infobar.h"
189#include "network.h"
190#include "harddisk.h"
191#include "httpdfunc.h"
192#include "httpd.h"
193#include "download.h"
194#include "copyfile.h"
195#include "screensaver.h"
196#include "screensaveradjust.h"
197#include "scan.h"
198#include "restoredefault.h"
199#include "help.h"
200#include "httpdsettings.h"
201#include "epgsearch.h"
202#include "inadyn.h"
203#include "rguid.h"
204#include "channelhistroy.h"
205#include "mostzap.h"
206#include "settings_redbutton.h"
207#include "settings_bluebutton.h"
208#include "extensions.h"
209#include "system_update.h"
210#include "system_backup.h"
211#include "system_backup_restore.h"
212#include "info.h"
213#include "softcam.h"
214#include "id3.h"
215#include "mediadbcache.h"
216#include "mediadb.h"
217#include "mediadbsettings.h"
218#include "colorpicker.h"
219#include "ocrypt.h"
220#include "unlock.h"
221#include "md5.h"
222#include "rc4.h"
223#include "textinputhist.h"
224#include "system_infos.h"
225#include "system_infos_sysinfo.h"
226#include "unicable.h"
227#include "newsletter.h"
228#include "dirsort.h"
229#include "shortepg.h"
230#include "mediadbedit.h"
231#include "tpchoice.h"
232#include "marker.h"
233#include "timeshiftsettings.h"
234#include "log.h"
235#include "bgdownload.h"
236#include "fancontrol.h"
237#include "channelslot.h"
238#include "hwtest.h"
239#include "settings_autostart.h"
240#include "settings_overclocking.h"
241#include "settings_pluginbutton.h"
242#include "bcm.h"
243#include "settings_mediabutton.h"
244#include "oled.h"
245#ifdef MIPSEL
246#include "cec.h"
247#include "encoder.h"
248#endif
249
250
251#define TIMECODE ""
252
253// mipsel start
254/* Apparently, surfaces must be 64-byte aligned */
255#define ACCEL_ALIGNMENT_SHIFT   6
256#define ACCEL_ALIGNMENT_MASK    ((1<<ACCEL_ALIGNMENT_SHIFT)-1)
257
258#define ACCEL_DEBUG
259
260//gAccel *gAccel::instance;
261#define BCM_ACCEL
262
263#ifdef BCM_ACCEL
264extern int bcm_accel_init(void);
265extern void bcm_accel_close(void);
266extern void bcm_accel_blit(
267                int src_addr, int src_width, int src_height, int src_stride, int src_format,
268                int dst_addr, int dst_width, int dst_height, int dst_stride,
269                int src_x, int src_y, int width, int height,
270                int dst_x, int dst_y, int dwidth, int dheight,
271                int pal_addr, int flags);
272extern void bcm_accel_fill(
273                int dst_addr, int dst_width, int dst_height, int dst_stride,
274                int x, int y, int width, int height,
275                unsigned long color);
276extern bool bcm_accel_has_alphablending();
277#endif
278// mipsel end
279
280void demomodethread(struct stimerthread* self)
281{
282        textbox(_("Message"), _("!!! This is a DEMO Version !!!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 600, 0, 1);
283}
284
285int createstartscreen()
286{
287        addscreen("<screen name=framebuffer/>", 0, 0);
288        if(skin == NULL)
289        {
290                err("can't set framebuffer skin");
291                return 1;
292        }
293        addscreen("<screen name=skinerror/>", 0, 0);
294        status.skinerr = getscreen("skinerror");
295        skin->width = skinfb->width;
296        skin->height = skinfb->height;
297        skin->iwidth = skinfb->width;
298        skin->iheight = skinfb->height;
299        skin->rwidth = skinfb->width;
300        skin->rheight = skinfb->height;
301        skin->bgcol = 0;
302        skin->transparent = 255;
303        skin->flag = 1;
304
305        return 0;
306}
307
308//exitcode: 1 power off
309//exitcode: 2 restart
310//exitcode: 3 Gui restart
311//flag: 0 do not check record
312//flag: 1 check record
313//flag: 2 check record / don't write config
314//flag: 3 check record with timeout
315//flag: 4 check record with increase fixpowerofftime
316//flag: 5 check record with increase powerofftime
317void oshutdown(int exitcode, int flag)
318{
319        struct dvbdev* dvbnode = dvbdev;
320        struct service* servicenode = service;
321        void* threadstatus;
322        int i = 0, faststop = 0, ret = 0;
323        char* tmpstr = NULL;
324        struct skin* logo = getscreen("logo");
325        pthread_attr_t writethreadattr = {};
326        pthread_t writethread = '\0';
327
328        //stop permanent timeshift
329        if(status.timeshift == 1)
330                timeshiftstop(3);
331
332        //check if record running
333        if((flag == 1 || flag == 2 || flag == 3 || flag == 4 || flag == 5) && (status.streaming > 0 || status.recording > 0 || getrectimerbytimediff(300) != NULL))
334        {
335                if(flag == 4 && status.fixpowerofftime > 1)
336                {
337                                status.fixpowerofftime = time(NULL) + 900; //check powerofftimer again in 15min
338                                return;
339                }
340                if(flag == 5 && status.sd_timer != NULL && status.sd_timer->active)
341                {
342                                status.sd_timer->shutdown_time = time(NULL) + 900; //check powerofftimer again in 15min
343                                return;
344                }
345
346                if(textbox(_("Message"), _("Found running record\nor record is starting in next time.\nReally shutdown ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) != 1)
347                        return;
348        }
349
350        //check if download is running
351        for(i = 0; i < MAXBGDOWNLOAD; i++)
352        {
353                if(bgdownload[i] != NULL && bgdownload[i]->ret == -1)
354                {
355                        if(textbox(_("Message"), _("Found running download\nReally shutdown ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) != 1)
356                                return;
357                        break;
358                }
359        }
360
361        ret = servicestop(status.aktservice, 1, 1);
362        if(ret == 1) return;
363       
364        if(exitcode == 1)
365                tmpstr = getconfig("userpowerofflogo", NULL);
366        else if(exitcode == 2)
367                tmpstr = getconfig("userrestartlogo", NULL);
368        else if(exitcode == 3)
369                tmpstr = getconfig("userguirestartlogo", NULL);
370       
371        if(tmpstr != NULL) {
372                if(file_exist(tmpstr) == 0)
373                        tmpstr = NULL;
374        }       
375        if(tmpstr == NULL) {   
376                if(exitcode == 1)
377                        tmpstr = getconfig("powerofflogo", NULL);
378                else if(exitcode == 2)
379                        tmpstr = getconfig("restartlogo", NULL);
380                else if(exitcode == 3)
381                        tmpstr = getconfig("guirestartlogo", NULL);
382        }
383                       
384        if(tmpstr != NULL)
385        {
386                changepic(logo, tmpstr);
387                tmpstr = NULL;
388                drawscreen(logo, 0, 0);
389        }
390        else
391                clearfball();
392
393        //stop all records
394        while(servicenode != NULL)
395        {
396                servicenode->recendtime = 1;
397                servicenode = servicenode->next;
398        }
399
400        faststop = getconfigint("faststop", NULL);
401
402        // Free memory, semaphores, etc. and say goodbye
403        if(faststop == 0) cleanupvfd();
404
405        if(status.servicetype != 99) //don't save tmp servicetype
406        {
407                tmpstr = oitoa(status.servicetype);
408                addconfig("servicetype", tmpstr);
409                free(tmpstr); tmpstr = NULL;
410        }
411
412        status.sec = 0;
413
414        if(flag != 2)
415        {
416                //start write thread
417                pthread_attr_init(&writethreadattr);
418                pthread_attr_setstacksize(&writethreadattr, 50000);
419                pthread_attr_setdetachstate(&writethreadattr, PTHREAD_CREATE_JOINABLE);
420
421                int epgsave = getconfigint("epgsave", NULL);
422                if((epgsave == 1 && exitcode == 3) || epgsave == 2)
423                        ret = pthread_create(&writethread, &writethreadattr, writeallconfigthread1, NULL); //do not save epg
424                else
425                        ret = pthread_create(&writethread, &writethreadattr, writeallconfigthread0, NULL); //save epg
426                if(ret)
427                {
428                        err("create write thread");
429                }
430        }
431       
432        //stop fan
433        if(checkbox("ATEMIO-NEMESIS") == 1)
434                writesys("/proc/stb/fp/fan", "1", 1);
435               
436        //reset ci devices
437        while(dvbnode != NULL)
438        {
439                if(dvbnode->type == CIDEV && dvbnode->fd > -1)
440                {
441                        if(dvbnode->caslot != NULL) dvbnode->caslot->status = 101;
442                        usleep(10000);
443                        careset(dvbnode, dvbnode->devnr);
444                }
445                dvbnode = dvbnode->next;
446        }
447
448        if(faststop == 0)
449        {
450                //wait for write thread
451                if(writethread != '\0')
452                        pthread_join(writethread, &threadstatus);
453                pthread_attr_destroy(&writethreadattr);
454
455                //stop timer thread
456                i = 0;
457                status.timerthreadaktion = STOP;
458                while(status.timerthreadstatus != DEACTIVE)
459                {
460                        usleep(100000);
461                        i++; if(i > 20) break;
462                }
463
464                if(i > 20)
465                {
466                        err("detect hanging timer thread");
467                }
468                else if(status.timerthread != '\0')
469                        pthread_join(status.timerthread, &threadstatus);
470                pthread_attr_destroy(&status.timerthreadattr);
471               
472                // free timerthread struct and stop all timer sub threads
473                freetimer(0);
474
475                status.skinerr = NULL;
476                free(status.gateway);
477                free(status.dnsserver1);
478                free(status.dnsserver2);
479                free(status.boxtype);
480                free(status.httpauth);
481                free(status.bgpic);
482
483                freeservice();
484                freecaservice();
485
486                freescreen();
487                freepic();
488                freefont();
489                deinitfont();
490
491                freerectimer();
492                freemostzap(0);
493                freechannelhistory();
494                freesat();
495                freeallplaylist();
496                freemainplaylist();
497                freeallbouquet();
498                freemainbouquet(0);
499                freechannel(0);
500                freetransponder();
501                freeprovider();
502                freeownconfig();
503                freeepgscanlist();
504                freercconfig();
505                freeskinconfig();
506                freequeue();
507                freehdd(0);
508
509                free(status.configfile);
510                freeconfig();
511
512                freedvbdev(0);
513
514                closefb(fb);
515                freefb();
516
517                closerc();
518                freerc();
519                freercmap();
520                free_shutdowntimervar();
521                freeinetwork();
522                freeoldentry();
523                freeextepgconfig();
524                freelastsubtitle();
525                freebgdownload();
526                freechannelslot();
527        }
528        else
529                freetimer(1);
530
531        if(exitcode == 1)
532                setcecstandby(1);
533
534        starthttpd(0);
535        startrguid(0);
536        initmutex(0);
537
538        if(faststop != 0)
539        {
540                //wait for write thread
541                if(writethread != '\0')
542                        pthread_join(writethread, &threadstatus);
543                pthread_attr_destroy(&writethreadattr);
544        }
545
546        exit(exitcode);
547}
548
549int main(int argc, char *argv[])
550{
551        int ret = 0, serviceret = 0, skincheck = 0;
552        char* tmpstr = NULL;
553        unsigned char *mmapfb = NULL;
554        struct sigaction sa;
555        struct stimerthread *tmpthread = NULL;
556        //struct sched_param schedparam;
557
558#ifdef SIMULATE
559        // for mem leak debug
560        setenv("MALLOC_TRACE", "/home/nit/titan/m.txt", 1);
561        mtrace();
562        status.security = 1;
563#endif
564
565        printf("[%s] copyright by %s - version %s\n", PROGNAME, COPYRIGHT, OVERSION);
566        printf("[%s] crontribut: %s\n", PROGNAME, CRONTRIBUT);
567
568        sa.sa_handler = (void *)sighandler;
569        sigemptyset(&sa.sa_mask);
570        sa.sa_flags = SA_RESTART;
571       
572        initsignal(&sa);
573
574        status.rguidfd = -1;
575        status.sec = time(NULL);
576        status.mainthread = pthread_self();
577
578        if(argc > 1)
579                status.configfile = ostrcat(argv[1], NULL, 0, 0);
580        else
581                status.configfile = ostrcat(CONFIGFILE, NULL, 0, 0);
582
583        printf("[%s] using config: %s\n", PROGNAME, status.configfile);
584        ret = readconfig(status.configfile, config);
585        if(ret != 0)
586                return 100;
587       
588        //Workaround da ansonsten DVR4 nicht funktioniert (Treiberproblem)
589        status.setdvr0 = 0;
590       
591        //start timer thread
592        status.timerthreadaktion = START;
593        pthread_attr_init(&status.timerthreadattr);
594        pthread_attr_setstacksize(&status.timerthreadattr, 50000);
595        pthread_attr_setdetachstate(&status.timerthreadattr, PTHREAD_CREATE_JOINABLE);
596        ret = pthread_create(&status.timerthread, &status.timerthreadattr, timerthreadfunc, NULL);
597        if(ret)
598        {
599                err("create timer thread");
600                return 100;
601        }
602
603        //change working dir to /tmp
604        //chdir("/tmp");
605
606        //set main scheduler priority
607        //schedparam.sched_priority = 10;
608        //pthread_setschedparam(pthread_self(), SCHED_RR, &schedparam);
609
610        readconfig(getconfig("ownconfig", NULL), ownconfig);
611        readconfig(getconfig("rcconfig", NULL), rcconfig);
612
613        skincheck = checkskin();
614        readconfig(getconfig("skinconfig", NULL), skinconfig);
615
616        setprogress(100);
617        setdefaults();
618        setdebuglevel();
619        initmutex(1);
620        m_lock(&status.waitrcmutex, 24);
621        initvfd();
622
623        if(checkbox("UFS922") == 1)
624                setfanspeed(-1, 0);
625        if(checkbox("ATEMIO-NEMESIS") == 1)
626        {
627                if(getconfigint("fanmode", NULL) == 0)
628                        addconfig("fanmode", "3");
629                writesys("/proc/stb/fp/fan", getconfig("fanmode", NULL), 1);
630        }
631        if(getconfigint("wol", NULL) == 1)
632                system("echo enable > /proc/stb/fp/wol");
633        else
634                system("echo disable > /proc/stb/fp/wol");
635
636#ifdef MIPSEL
637        cecinit();
638#endif 
639        system(getconfig("skriptbeforetv", NULL));
640//      ret = setcecstandby(0); --- > jetzt in checkboxstart
641        ret = setvideomode(getconfig("av_videomode", NULL), 0);
642#ifndef MIPSEL
643        ret = setaspect(getconfig("av_aspect", NULL));
644#endif
645        ret = setpolicy(getconfig("av_policy", NULL));
646        ret = setcolorformat(getconfig("av_colorformat", NULL), 0);
647        ret = setcolorformat(getconfig("av_colorformatscart", NULL), 1);
648        ret = setaudiosource(getconfig("av_audiosource", NULL));
649        ret = setac3(getconfig("av_ac3mode", NULL));
650#ifdef MIPSEL
651        ret = setaac(getconfig("av_aacmode", NULL));
652        ret = setwss(getconfig("av_wssmode", NULL));
653#endif
654        ret = setpolicy(getconfig("av_policy", NULL));
655        ret = setmode3d(getconfig("av_mode3d", NULL));
656        ret = setvfdbrightness(getconfigint("vfdbrightness", NULL));
657        ret = setaudiodelaybitstream(getconfig("audiodelaybitstream", NULL));
658        ret = addinetworkall(NULL);
659 
660#ifndef SIMULATE
661        if(getconfigint("sos", NULL) == 0)
662        {
663                if(ostrcmp(string_newline(gettimeinfo()), TIMECODE) == 1)
664                {
665                        printf("error: 1\n");
666                        destroy();
667                        exit(100);
668                }
669                if(ostrcmp(string_newline(gettimeinfovar()), TIMECODE) == 1)
670                {
671                        printf("error: 2\n");           
672                        destroy();
673                        exit(100);
674                }
675                if(checkreseller() != 0)
676                {
677                        printf("error: 3\n");           
678                        destroy();
679                        exit(100);
680                }
681                if(getsysinfo() != SYSCODE)
682                {
683                        printf("error: 4\n");           
684                        destroy();
685                        exit(100);
686                }
687                if(file_exist("/mnt/swapextensions/etc/.vnumber") == 1)
688                {
689                        printf("error: 5\n");           
690                        destroy();
691                        exit(100);
692                }
693                if(checkflash() != 0)
694                {
695                        printf("error: 6\n");           
696                        destroy();
697                        exit(100);
698                }
699                if((checkbox("ATEMIO-NEMESIS") == 1 || checkbox("ATEMIO5200") == 1 || checkbox("UFS913") == 1 || checkbox("ATEMIO6200") == 1 || checkbox("ATEMIO6100") == 1 || checkbox("ATEMIO6200") == 1 || checkbox("SPARK") == 1 || checkbox("SPARK7162") == 1 || checkbox("IPBOX91") == 1 || checkbox("IPBOX900") == 1 || checkbox("IPBOX910") == 1 || checkbox("IPBOX9000") == 1) && checkhighflash() != 0)
700                {
701                        printf("error: 7\n");           
702                        destroy();
703                        exit(100);
704                }
705                if(checkbox("UFS910") == 1 && checklowflash() != 0)
706                {
707                        printf("error: 8\n");           
708                        destroy();
709                        exit(100);
710                }
711       
712                char* cpuid = getcpuid();
713                checkserial(cpuid);
714                free(cpuid); cpuid = NULL;
715        }
716        else
717        {
718                status.security = 1;
719                startnet();
720                setskinnodeslocked(0);
721        }
722#endif
723
724        if(file_exist("/mnt/config/dualboot.enigma2"))
725        {
726                printf("error: found /mnt/config/dualboot.enigma2\n");
727                return 0;
728        }
729
730        ret = initfont();
731        if(ret != 0)
732                return 100;
733        ret = openfont(getconfig("fontfile1", NULL));
734        if(ret != 0)
735        {
736                err("open fontfile1 font");
737                return 100;
738        }
739        openfont(getconfig("fontfile2", NULL));
740        openfont(getconfig("fontfile3", NULL));
741        openfont(getconfig("fontfile4", NULL));
742        openfont(getconfig("fontfile5", NULL));
743
744        //skin defined fonts
745        openfont(getskinconfig("fontfile1", NULL));
746        openfont(getskinconfig("fontfile2", NULL));
747        openfont(getskinconfig("fontfile3", NULL));
748        openfont(getskinconfig("fontfile4", NULL));
749        openfont(getskinconfig("fontfile5", NULL));
750
751
752        setvol(getconfigint("vol", NULL));
753
754       
755        setlang(getconfig("lang", NULL));
756        initlocale(getconfig("localepath", NULL));
757
758#ifdef MIPSEL
759        bcm_accel_init();
760#endif
761
762        fb = openfb(getconfig("fbdev", NULL), 0);
763        if(fb == NULL)
764                return 100;
765        clearfball();
766        enablemanualblit();
767       
768        tmpstr = getconfig("fb1dev", NULL);
769        if(tmpstr != NULL)
770                fb1 = openfb(tmpstr, 1);
771        tmpstr = NULL;
772
773#ifdef MIPSEL
774        waitvsync();
775        setfbosd();
776        status.usedirectfb = 1;
777#endif
778
779        if(status.usedirectfb != 1)
780        {
781                skinfb = addfb(SKINFB, 0, getconfigint("skinfbwidth", NULL), getconfigint("skinfbheight", NULL), 4, fb->fd, fb->fb + fb->varfbsize, fb->fixfbsize);
782                if(skinfb != NULL)
783                {
784                        ret = getfbsize(0);
785                        if(ret > 0)
786                                accelfb = addfb(ACCELFB, 0, ret / 4, 1, 4, fb->fd, skinfb->fb + skinfb->varfbsize, fb->fixfbsize);
787                }
788                else
789                {
790                        debug(100, "use directfb");
791                        status.usedirectfb = 1;
792                }
793        }
794        if(status.usedirectfb == 1)
795        {
796                skinfb = fb;
797#ifndef MIPSEL
798                ret = getfbsize(0);
799                if(ret > 0)
800                        accelfb = addfb(ACCELFB, 0, ret / 4, 1, 4, fb->fd, skinfb->fb + skinfb->varfbsize, fb->fixfbsize);
801#endif
802        }
803
804        //if(lcdskinfb == NULL) {
805                //mmapfb = malloc(4 * 320 * 240);
806                //mmapfb = malloc(4 * 1024 * 768);
807                //mmapfb = NULL;
808                /* dev=999 ist LCD Buffer */
809                //lcdskinfb = addfb("lcdskinfb", 999, 320, 240, 4, -1, mmapfb, 4 * 320 * 240);
810                //lcdskinfb = addfb("lcdskinfb", 999, 1024, 768, 4, -1, mmapfb, 4 * 1024 * 768);
811                // mmapfb = NULL;
812        //}
813
814        ret = createstartscreen();
815        if(ret != 0) return 100;
816
817        //from here we can use starterror screen
818        ret = openrc();
819        if(ret != 0)
820        {
821                tmpstr = ostrcat(tmpstr, _("Error: open rc device !!"), 1, 0);
822                goto starterror;
823        }
824
825        if(fegetdev() < 1)
826        {
827                tmpstr = ostrcat(tmpstr, _("Error: no frontend device found !!"), 1, 0);
828                err("no frontend device found");
829                goto starterror;
830        }
831        if(dmxgetdev() < 1)
832        {
833                tmpstr = ostrcat(tmpstr, _("Error: no demux device found !!"), 1, 0);
834                err("no demux device found");
835                goto starterror;
836        }
837        if(videogetdev() < 1)
838        {
839                tmpstr = ostrcat(tmpstr, _("Error: no video device found !!"), 1, 0);
840                err("no video device found");
841                goto starterror;
842        }
843        if(audiogetdev() < 1)
844        {
845                tmpstr = ostrcat(tmpstr, _("Error: no audio device found !!"), 1, 0);
846                err("no audio device found");
847                goto starterror;
848        }
849        ret = fecreatedummy();
850        ret = cagetdev();
851        ret = cigetdev();
852        ret = dvrgetdev();
853        ret = scgetdev();
854#ifdef MIPSEL
855        if(checkbox("ATEMIO-NEMESIS") == 1)
856                ret = encodergetdev();
857#endif
858
859        settunerstatus();
860
861        //start ca slot watching threads
862        castart();
863
864        //check skin
865        if(skincheck > 0)
866        {
867
868                tmpstr = ostrcat(tmpstr, _("Error: skin not found !!"), 1, 0);
869                err("skin not found");
870                goto starterror;
871        }
872
873        ret = readsat(getconfig("satfile", NULL));
874        ret = readtransponder(getconfig("transponderfile", NULL));
875        ret = readprovider(getconfig("providerfile", NULL));
876        ret = readchannel(getconfig("channelfile", NULL));
877        ret = readtransponderencoding(getconfig("transponderencodingfile", NULL));
878        ret = readmostzap(getconfig("mostzapfile", NULL));
879        ret = readlastsubtitle(getconfig("lastsubtitle", NULL));
880        ret = readchannelslot(getconfig("channelslotfile", NULL));
881
882        status.aktservice = addservice(NULL);
883        status.lastservice = addservice(NULL);
884        status.pipservice = addservice(NULL);
885
886        //check if startchannel defined
887        char* startchannellist = getconfig("startchannellist", NULL);
888        int startserviceid = getconfigint("startserviceid", NULL);
889        uint64_t starttransponderid = getconfigllu("starttransponderid", NULL);
890        int startservicetype = getconfigint("startservicetype", NULL);
891        if(startchannellist != NULL && startserviceid != 0)
892        {
893                if(startservicetype == 0)
894                {
895                        addconfig("channellist", startchannellist);
896                        addconfigint("serviceid", startserviceid);
897                        addconfigllu("transponderid", starttransponderid);
898                }
899                else
900                {
901                        addconfig("rchannellist", startchannellist);
902                        addconfigint("rserviceid", startserviceid);
903                        addconfigllu("rtransponderid", starttransponderid);
904                }
905                addconfigint("servicetype", startservicetype);
906        }
907        setvol(getconfigint("vol", NULL));
908        //tune to channel
909        if(status.servicetype == 0)
910                serviceret = servicestart(getchannel(getconfigint("serviceid", NULL), getconfigllu("transponderid", NULL)), getconfig("channellist", NULL), NULL, 0);
911        else
912                serviceret = servicestart(getchannel(getconfigint("rserviceid", NULL), getconfigllu("rtransponderid", NULL)), getconfig("rchannellist", NULL),  NULL, 0);
913
914        if(checkbox("IPBOX9000") == 1 && !file_exist("/tmp/.opticum9600.workaround"))
915        {
916                printf("opticum.workaround start\n");
917                system("touch /tmp/.opticum9600.workaround");
918                oshutdown(3, 1);
919                printf("opticum.workaround end\n");
920        }
921
922        ret = readscreen(getconfig("skinfile", NULL), 0, 0);
923        ret = readmainbouquet(getconfig("bouquetfile", NULL));
924        ret = readallbouquet();
925        ret = readmainplaylist(getconfig("playlistfile", NULL));
926        ret = readallplaylist();
927        ret = readrcmap(getconfig("rcmapfile", NULL));
928        ret = readepgscanlist(getconfig("epgchannelfile", NULL));
929        ret = settimezone(getconfig("timezone", NULL));
930        ret = readextepgconfig(getconfig("extepgfile", NULL));
931       
932        if(checkbox("VUSOLO2") == 1)
933                system("fbset 1280x720-1");
934
935
936        //check to remove preinstalled tpk packages
937        ret = tpkupdatepre();
938
939        addtimer(&checkdate, START, 2000, -1, NULL, NULL, NULL);
940        if(checkbox("ATEMIO510") == 0)
941                addtimer(&updatevfd, START, 1000, -1, NULL, NULL, NULL);
942
943        if(getconfigint("firststart", NULL) == 1)
944        {
945                if(file_exist("/var/etc/.scart"))
946                {
947                        setvideomode("pal", 0);
948                        changefbresolution("pal", 0);
949                        autoresolution();
950                }
951                addconfig("firststart", "0");
952        }
953
954        if(getconfig("remotecontrol", NULL) == NULL)
955        {
956                if(checkbox("ATEMIO520") == 1 || checkbox("ATEMIO530") == 1)
957                {
958                        //autopo work
959                        char* tmptxt = NULL;
960                        tmptxt = ostrcat(tmptxt, _("RemoteControl Old Version"), 0, 0);
961                        tmptxt = ostrcat(tmptxt, _("RemoteControl Long Version"), 0, 0);
962                        free(tmptxt), tmptxt = NULL;
963
964                        struct menulist* mlist = NULL, *mbox = NULL;
965                        addmenulist(&mlist, "RemoteControl Old Version", "0", NULL, 0, 0);
966                        addmenulist(&mlist, "RemoteControl Long Version", "1", NULL, 0, 0);
967                        // remotecontrol try menulist
968                        mbox = menulistbox(mlist, "menulist", _("Select Your Remote Control"), _("Choose your Remotecontrol Model from the following list"), NULL, NULL, 3, 0);
969                        if(mbox != NULL)
970                        {
971                                debug(10, "mbox->name %s", mbox->name);
972                                debug(10, "mbox->text %s", mbox->text);
973                                addconfig("remotecontrol", mbox->text);
974                                writeallconfig(1);                             
975                        }
976                }
977        }
978                       
979        //first wizzard
980        if(getconfigint("nofirstwizzard", NULL) < 2)
981        {
982                if(file_exist("/var/etc/.scart"))
983                {
984                        setvideomode("pal", 0);
985                        changefbresolution("pal", 0);
986                }
987
988                autoresolution();
989                       
990                if(getconfigint("nofirstwizzard", NULL) == 0)
991                {
992firstwizzardstep1:
993
994                        status.updatevfd = PAUSE;
995//                      screenavsettings(1);
996//                      resettvpic();
997                        //this screen can reload the skin (on language change)
998                        //all skin changes before here than are deleted
999//                      if(screenlanguage(2) == 2) return 100;
1000//                      resettvpic();
1001
1002                        screentunerconfig();
1003                        resettvpic();
1004                        screenscanconfig(1);
1005                        resettvpic();
1006//                      screennetwork_adapter();
1007//                      resettvpic();
1008                        writevfd("Setting OK ?");
1009                        if(textbox(_("First Wizzard"), _("Settings OK ?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 2)
1010                        {
1011                                goto firstwizzardstep1;
1012                        }
1013                }
1014                resettvpic();
1015
1016                char* msg = NULL;
1017                msg = readfiletomem("/etc/imageinfo", 0);
1018                textbox(_("Info"), _(msg), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 1100, 680, 30, 0);
1019                free(msg); msg = NULL;
1020               
1021                writevfd("");
1022                status.updatevfd = START;
1023                drawscreen(skin, 0, 0);
1024                addconfig("nofirstwizzard", "2");
1025        }
1026        else
1027        {
1028                // workaround, remove bootlogo on startup
1029                drawscreen(skin, 0, 0);
1030
1031                //check servicestart
1032                if(serviceret != 21) // no message if startchannel empty
1033                        servicecheckret(serviceret, 0);
1034        }
1035
1036// fixt manual start
1037        resettvpic();
1038
1039        //start auto shutdown thread
1040        addtimer(&checkshutdowntimer, START, 10000, -1, NULL, NULL, NULL);
1041        //start demo mode
1042        if(checkbox("WHITEBOX") == 1)
1043                addtimer(&demomodethread, START, 600000, -1, NULL, NULL, NULL);
1044
1045        status.lastrcaction = time(NULL);
1046        ret = loadplugin();
1047        setosdtransparent(getskinconfigint("osdtransparent", NULL));
1048        ret = setsaturation(getconfigint("vs_saturation", NULL));
1049        ret = setbrightness(getconfigint("vs_brightness", NULL));
1050        ret = setcontrast(getconfigint("vs_contrast", NULL));
1051        ret = settint(getconfigint("vs_tint", NULL));
1052       
1053#ifndef SIMULATE
1054        //set skinentrys locked
1055        if(status.security == 0)
1056                setskinnodeslocked(1);
1057        else
1058                setskinnodeslocked(0);
1059#endif
1060
1061        //start epg thread
1062        status.epgthread = addtimer(&epgthreadfunc, START, 1000, -1, NULL, NULL, NULL);
1063        //start record timer thread (on delay change you must change rectimer.h also)
1064        status.rectimerthread = addtimer(&checkrectimer, START, 1000, -1, NULL, NULL, NULL);
1065        //check if cam socket connected
1066        addtimer(&checkcam, START, 3000, -1, NULL, NULL, NULL);
1067        //start stream server
1068        tmpthread = addtimer(&streamthreadfunc, START, 10000, -1, NULL, NULL, NULL);
1069        if(tmpthread != NULL)
1070        {
1071                tmpthread->flag = setbit(tmpthread->flag, 0);
1072                tmpthread = NULL;
1073        }
1074        //start epg scanlist
1075        status.epgscanlistthread = addtimer(&epgscanlistthread, START, 1000, 1, NULL, NULL, NULL);
1076        //get pmt
1077        if(getconfigint("checkpmtalways", NULL) == 1)
1078                addtimer(&dvbgetpmtthread, START, 2000, -1, NULL, NULL, NULL);
1079        //check hdd
1080        status.addhddall = addtimer(&addhddall, START, 6000, -1, NULL, NULL, NULL);
1081        //check net
1082        addtimer(&addinetworkall, START, 15000, -1, NULL, NULL, NULL);
1083        //check kill net (security)
1084        addtimer(&ckeckkillnetthread, START, 1000, 1, NULL, NULL, NULL);
1085        //check old entrys and remove from mem
1086        addtimer(&oldentrythreadfunc, START, 60000 * 60, -1, NULL, NULL, NULL);
1087
1088        //start newsletter
1089        startnewsletter(1);
1090
1091        //thumb create thread
1092        startthumb(1);
1093
1094        //start webserver
1095        starthttpd(1);
1096       
1097        //start rguid
1098        startrguid(1);
1099
1100        //init the player
1101        playerinit(argc, argv);
1102       
1103        //start spinner thread
1104        addtimer(&checkspinner, START, 2000, -1, NULL, NULL, NULL);
1105
1106        system(getconfig("skriptaftertv", NULL));
1107
1108        // work
1109        resettvpic();
1110       
1111        char* cmd = NULL;
1112#ifdef SH4
1113        cmd = ostrcat("/media/hdd/movie/titankey.sh4", NULL, 0, 0);
1114#endif
1115
1116#ifdef MIPSEL
1117        cmd = ostrcat("/media/hdd/movie/titankey.mipsel", NULL, 0, 0);
1118#endif
1119
1120        //for atemio to unlock box with stick
1121        if(file_exist(cmd))
1122        {
1123                char* cpuid = getcpuid();
1124                cmd = ostrcat(cmd, " ", 1, 0);
1125                cmd = ostrcat(cmd, cpuid, 1, 0);
1126
1127                system(cmd);
1128                checkserial(cpuid);
1129                free(cmd); cmd = NULL;
1130
1131                if(status.security == 1)
1132                {
1133                        char* mac = getmacfromcmdline();
1134                        if(mac != NULL)
1135                        {
1136                                cmd = ostrcat(cmd, cpuid, 1, 0);
1137                                cmd = ostrcat(cmd, ",", 1, 0);
1138                                cmd = ostrcat(cmd, mac, 1, 0);
1139                               
1140                                free(mac); mac = NULL;
1141                        }
1142                        else
1143                                cmd = ostrcat(cmd, cpuid, 1, 0);
1144
1145                        writesys("/media/hdd/movie/codelist.txt", cmd, 3);
1146                        textbox(_("Message"), _("Receiver successful unlocked"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
1147                }
1148
1149                free(cpuid); cpuid = NULL;
1150        }
1151        free(cmd); cmd = NULL;
1152
1153        //must called direct befor screeninfobar
1154        if(getconfigint("saverun", NULL) == 1)
1155        {
1156                ret = sigsetjmp(status.longjumpbuf, 1);
1157                if(ret != 0 && ret != 999)
1158                {
1159                        err("set sigsegjump");
1160                }
1161        }
1162       
1163        if(checkbox("UFS910") == 0 && checkbox("UFS922") == 0)
1164        {
1165                //check free space in /var
1166                if(getfreespace("/var") / 1024 < 50) //200kb
1167                        textbox(_("Message"), _("Free space in /var to little!\nThis can make problems!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 7, 0);
1168                else
1169                {
1170                        //check writeable in /var
1171                        if(mkdir("/var/writetest", 0777) != 0 && errno != EEXIST)
1172                        {
1173                                if(textbox(_("Message"), _("/var not writeable!\nRepair it?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) == 1)
1174                                {
1175                                        system("repairjffs2.sh var &"); //this script kills titan an reboot
1176                                        sleep(10);
1177                                }
1178                        }
1179                        rmdir("/var/writetest");
1180                }
1181       
1182                //check free space in /mnt
1183                if(getfreespace("/mnt") / 1024 < 50) //200kb
1184                        textbox(_("Message"), _("Free space in /mnt to little!\nThis can make problems!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 7, 0);
1185                else
1186                {
1187                        //check writeable in /mnt
1188                        if(mkdir("/mnt/writetest", 0777) != 0 && errno != EEXIST)
1189                        {
1190                                if(textbox(_("Message"), _("/mnt not writeable!\nRepair it?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 15, 0) == 1)
1191                                {
1192                                        system("repairjffs2.sh mnt &"); //this script kills titan an reboot
1193                                        sleep(10);
1194                                }
1195                        }
1196                        rmdir("/mnt/writetest");
1197                }
1198        }
1199
1200        addtimer(&guestthread, START, 1000, 1, NULL, NULL, NULL);
1201        startinternreader(1);
1202       
1203        screeninfobar();
1204
1205        //for testign screens
1206        //screenmanualscan();
1207        //screeninputhelp();
1208        //screendownload("test", "www.orf.at", NULL, 80, "test.html", 0);
1209        //screenrectimer();
1210        //screenepgsettings();
1211        //screenlnb("1");
1212        //screendiseqc("1");
1213        //screenlanguage();
1214        //screenvideosettings();
1215        //screenskinselect();
1216        //screenrectimer();
1217        //screennetwork_adapter(2);
1218        //screenpin();
1219        //screenchannellist();
1220        //recordstart(channel, RECDIRECT);
1221        //mc_main();
1222        //screenmc_videoplayer();
1223        //screenserviceinfo();
1224        //screentunerconfig();
1225        //screenvfdisplay();
1226        //screenavsettings(1);
1227        //screenadjust();
1228        //subtitlestart();
1229
1230        if(mmapfb != NULL) {
1231                free(mmapfb); mmapfb=NULL;
1232        }
1233        oshutdown(1, 1);
1234        return 0;
1235
1236starterror:
1237        addscreen("<screen hspace=5 vspace=5 type=textbox name=starterror posx=center posy=center bordersize=2 bordercol=#ffffff fontsize=30 fontcol=#ffffff width=600 height=150/>", 0, 0);
1238        struct skin *starterror = getscreen("starterror");
1239        if(tmpstr == NULL)
1240                tmpstr = ostrcat(tmpstr, _("Unknown Error."), 1, 0);
1241        tmpstr = ostrcat(tmpstr, "\n", 1, 0);
1242        tmpstr = ostrcat(tmpstr, _("Automatic stop in 10 seconds."), 1, 0);
1243        changetext(starterror, _(tmpstr));
1244        drawscreen(starterror, 0, 0);
1245        sleep(10);
1246        free(tmpstr);
1247        return 100;
1248}
Note: See TracBrowser for help on using the repository browser.