source: titan/titan/mipselport.h @ 39231

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

fix minitv disable mipselport.h

File size: 40.8 KB
Line 
1#ifndef MIPSELPORT_H
2#define MIPSELPORT_H
3
4#ifndef FBIO_BLIT
5//#define FBIO_SET_MANUAL_BLIT _IOW('F', 0x20, __u32)
6#define FBIO_SET_MANUAL_BLIT _IOW('F', 0x21, __u8)
7#define FBIO_BLIT 0x22
8#endif
9
10#ifndef FBIO_WAITFORVSYNC
11#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
12#endif
13
14//fuer Funktion memcpy_word
15volatile char *memcpy_word_src;
16volatile char *memcpy_word_dest;
17volatile long  memcpy_word_anzw = 0;
18
19//fuer Funktion memcpy_byte
20volatile char *memcpy_byte_src;
21volatile char *memcpy_byte_dest;
22volatile long  memcpy_byte_anzb = 0;
23
24unsigned char *lfb = NULL;
25int g_manual_blit = 0;
26struct fb_fix_screeninfo fix_screeninfo;
27struct fb_var_screeninfo var_screeninfo;
28
29void memcpy_area(unsigned char* targetADDR, unsigned char* startADDR, long pxAbs, long hight, long widthAbs, long FBwidthAbs);
30
31int setmixer(struct dvbdev* node, int left, int right)
32{
33        return audiosetmixer(node, left, right);
34}
35
36int setencoding(struct channel* chnode, struct dvbdev* videonode)
37{
38        int ret = 1;
39        if(chnode == NULL) return ret;
40       
41        switch(chnode->videocodec)
42        {
43                case MPEGV:
44                        ret = videosetstreamtype(videonode, 0);
45                        break;
46                case MPEG4V:
47                        ret = videosetstreamtype(videonode, 4);
48                        break;
49                case H264:
50                        ret = videosetstreamtype(videonode, 1);
51                        break;
52                case VC1:
53                        ret = videosetstreamtype(videonode, 3);
54                        break;
55                default:
56                        ret = videosetstreamtype(videonode, 0);
57        }
58        return ret;
59}
60
61int videodiscontinuityskip(struct dvbdev* node, int flag)
62{
63        return 0;
64}
65
66void fbsave()
67{
68}
69
70void fbrestore()
71{
72}
73
74void setfbvarsize(struct fb* newnode)
75{
76        if(newnode != NULL)
77                newnode->varfbsize = 1920 * 1080 * newnode->colbytes;
78//              newnode->varfbsize = 1920 * 1080 * (newnode->colbytes * 8);
79
80}
81
82void enablemanualblit()
83{
84        unsigned char tmp = 1;
85        if (ioctl(fb->fd, FBIO_SET_MANUAL_BLIT, &tmp)<0)
86                perror("FBIO_SET_MANUAL_BLIT");
87        else
88                g_manual_blit = 1;
89}
90
91void disablemanualblit()
92{
93        unsigned char tmp = 0;
94        if (ioctl(fb->fd, FBIO_SET_MANUAL_BLIT, &tmp)<0)
95                perror("FBIO_SET_MANUAL_BLIT");
96        else
97                g_manual_blit = 0;
98}
99
100void blit()
101{
102        if (g_manual_blit == 1) {
103                if (ioctl(fb->fd, FBIO_BLIT) < 0)
104                        perror("FBIO_BLIT");
105        }
106}
107
108int waitvsync()
109{
110        int c = 0;
111        return ioctl(fb->fd, FBIO_WAITFORVSYNC, &c);
112}
113
114void fbsetoffset(int x, int y)
115{
116        struct fb_var_screeninfo var_screeninfo;
117
118        var_screeninfo.xoffset = x;
119        var_screeninfo.yoffset = y;
120
121        if(ioctl(fb->fd, FBIOPAN_DISPLAY, &var_screeninfo) < 0)
122        {
123                perr("FBIOPAN_DISPLAY");
124        }
125}
126
127//flag 0 = no animation
128//flag 1 = animation
129void blitfb2(struct fb* fbnode, int flag)
130{
131        int doblit = 1;
132        struct fb_var_screeninfo var_screeninfo;
133
134        var_screeninfo.xres_virtual = fb->width;
135        var_screeninfo.xres = fb->width;
136//      if(checkbox("VUSOLO2") == 0)
137                var_screeninfo.yres_virtual = fb->height * 2;
138//      else
139//              var_screeninfo.yres_virtual = fb->height;
140        var_screeninfo.yres = fb->height;
141        var_screeninfo.height = 0;
142        var_screeninfo.width = 0;
143        var_screeninfo.xoffset = 0;
144        var_screeninfo.yoffset = 0;
145//      if(checkbox("VUSOLO2") == 0)
146                var_screeninfo.bits_per_pixel = fb->colbytes * 8;
147//      else
148//              var_screeninfo.bits_per_pixel = fb->colbytes;
149       
150        switch(fb->colbytes)
151        {
152                case 2:
153                        var_screeninfo.transp.offset = 15;
154                        var_screeninfo.transp.length = 1;
155                        var_screeninfo.red.offset = 10;
156                        var_screeninfo.red.length = 5;
157                        var_screeninfo.green.offset = 5;
158                        var_screeninfo.green.length = 5;
159                        var_screeninfo.blue.offset = 0;
160                        var_screeninfo.blue.length = 5;
161                        break;
162                case 4:
163                        var_screeninfo.transp.offset = 24;
164                        var_screeninfo.transp.length = 8;
165                        var_screeninfo.red.offset = 16;
166                        var_screeninfo.red.length = 8;
167                        var_screeninfo.green.offset = 8;
168                        var_screeninfo.green.length = 8;
169                        var_screeninfo.blue.offset = 0;
170                        var_screeninfo.blue.length = 8;
171                        break;
172        }
173       
174        debug(444, "FB: line_length %d", fix_screeninfo.line_length);
175        debug(444, "FB: var_screeninfo.xres %d", var_screeninfo.xres);
176        debug(444, "FB: var_screeninfo.yres %d", var_screeninfo.yres);
177        debug(444, "FB: var_screeninfo.xres_virt %d", var_screeninfo.xres_virtual);
178        debug(444, "FB: var_screeninfo.yres_virt %d", var_screeninfo.yres_virtual);
179        debug(444, "FB: var_screeninfo.xoffset %d", var_screeninfo.xoffset);
180        debug(444, "FB: var_screeninfo.yoffset %d", var_screeninfo.yoffset);
181        debug(444, "FB: var_screeninfo.bits_per_pixel %d", var_screeninfo.bits_per_pixel);
182        debug(444, "FB: var_screeninfo.grayscale %d", var_screeninfo.grayscale);
183
184        if(ioctl(fb->fd, FBIOPUT_VSCREENINFO, &var_screeninfo) < 0)
185        {
186                var_screeninfo.yres_virtual = fb->height;
187                if(ioctl(fb->fd, FBIOPUT_VSCREENINFO, &var_screeninfo) < 0)
188                {
189                        perr("FBIOPUT_VSCREENINFO");
190                }
191                debug(444, "FB: double buffering not available");
192        }
193        else
194        {
195                debug(444, "FB: double buffering available!");
196        }
197
198        ioctl(fb->fd, FBIOGET_VSCREENINFO, &var_screeninfo);
199        if ((var_screeninfo.xres!=fb->width) && (var_screeninfo.yres!=fb->height) && (var_screeninfo.bits_per_pixel!=fb->colbytes))
200        {
201                debug(444, "SetMode failed: wanted: %dx%dx%d, got %dx%dx%d",
202                        fb->width, fb->height, fb->colbytes,
203                        var_screeninfo.xres, var_screeninfo.yres, var_screeninfo.bits_per_pixel);
204        }
205       
206        int posx = 0;
207        int posy = 0;
208        int width = 0;
209        int height = 0;
210       
211        if(status.bcm == 1 && status.usedirectfb == 0)
212        {
213                posx = getconfigint("fbleftoffset", NULL) * 5;
214                posy = getconfigint("fbtopoffset", NULL) * 5;
215                width = (fb->width - posx) - (getconfigint("fbrightoffset", NULL) * 5);
216                height = (fb->height - posy) - (getconfigint("fbbottomoffset", NULL) * 5);
217        }
218        else
219        {
220                posx = getconfigint("fbleftoffset", NULL);
221                posy = getconfigint("fbtopoffset", NULL);
222                width = (720 - posx) - (getconfigint("fbrightoffset", NULL));
223                height = (576 - posy) - (getconfigint("fbbottomoffset", NULL));
224        }
225        //printf("posx:%i posy:%i width:%i height:%i\n", posx, posy, width, height);
226
227        if(flag == 0 || checkbox("ATEMIO5200") == 1 || status.screenanim == 0)
228        {
229                if(status.bcm == 1 && status.usedirectfb == 0)
230                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0);
231                blit();
232                return;
233        }
234       
235
236        int i = 0, max = 1, wstep = 0, hstep = 0;
237        int dst_left = 0, dst_width = 0, dst_top = 0, dst_height = 0;
238        int mode3d = 0;
239
240        if(flag == 1 && status.screenanim > 0 && mode3d == 0)
241        {
242                doblit = 0;
243                //max = 25;
244                max = 8;
245                dst_left = posx;
246                dst_width = width;
247                dst_top = posy;
248                dst_height = height;
249               
250                char* fbleftdev = "/proc/stb/fb/dst_left";
251                char* fbwidthdev = "/proc/stb/fb/dst_width";
252                char* fbtopdev = "/proc/stb/fb/dst_top";
253                char* fbheightdev = "/proc/stb/fb/dst_height";
254               
255                int screenanimspeed = 0;       
256               
257                if(status.bcm == 1 && status.usedirectfb == 0)
258                {
259                        if(status.screenanimspeed == 1 || status.screenanimspeed == 0)
260                                max = 4;
261                        else if(status.screenanimspeed == 5)
262                                max = 8;
263                        else
264                                screenanimspeed = status.screenanimspeed;
265                }
266                else
267                        screenanimspeed = status.screenanimspeed;
268                       
269                if(status.screenanim == 1 || status.screenanim == 3)
270                {
271                        dst_left = (width / 2) - 1;
272                        dst_width = 2;
273                }
274                if(status.screenanim == 2 || status.screenanim == 3)
275                {
276                        dst_top = (height / 2) - 1;
277                        dst_height = 2;
278                }
279                if(status.screenanim == 4 || status.screenanim == 11)
280                {
281                        dst_top = posy;
282                        dst_height = height;
283                        dst_left = posx;
284                        dst_width = 2;
285                }
286                if(status.screenanim == 5 || status.screenanim == 12)
287                {
288                        dst_top = posy;
289                        dst_height = 2;
290                        dst_left = posx;
291                        dst_width = width;
292                }
293               
294                wstep = width / max;
295                hstep = height / max;
296                       
297                for(i = 0; i <= max; i++)
298                {
299                        if(status.screenanim == 1 || status.screenanim == 3)
300                        {
301                                int tmpleft = dst_left - (wstep/2);
302                                int tmpwidth = dst_width + wstep;
303                                if(tmpleft < posx)
304                                        tmpleft = posx;
305                                if(tmpwidth > width)
306                                        tmpwidth = width;
307                                dst_left = tmpleft;
308                                dst_width = tmpwidth;
309                        }
310                        if(status.screenanim == 2 || status.screenanim == 3)
311                        {
312                                int tmptop = dst_top - (hstep/2);
313                                int tmpheight = dst_height + hstep;
314                                if(tmptop < posy)
315                                        tmptop = posy;
316                                if(tmpheight > height)
317                                        tmpheight = height;
318                                dst_top = tmptop;
319                                dst_height = tmpheight;
320                        }
321                        if(status.screenanim == 4 || status.screenanim == 11)
322                        {
323                                int tmpwidth = dst_width + wstep;
324                                if(tmpwidth > width)
325                                        tmpwidth = width;
326                                dst_width = tmpwidth;
327                        }
328                        if(status.screenanim == 5 || status.screenanim == 12)
329                        {
330                                int tmpheight = dst_height + hstep;
331                                if(tmpheight > height)
332                                        tmpheight = height;
333                                dst_height = tmpheight;
334                        }
335                       
336                        if((dst_width + dst_left) > width)
337                                dst_width = dst_width - dst_left;
338                                                       
339                        if((dst_height + dst_top) > height)
340                                dst_height = dst_height - dst_top;
341                                                               
342                        //printf("left:%i width:%i top:%i height:%i\n", dst_left, dst_width, dst_top, dst_height);
343                        //waitvsync();
344                        if(status.bcm == 1 && status.usedirectfb == 0)
345                        {
346                                if(status.screenanim < 10)
347                                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, dst_left, dst_top, dst_width, dst_height, 0, 0);
348                                else
349                                {
350                                        int dswidth = (dst_width + posx*2) * skinfb->width / (width + posx*2);
351                                        int dsheight = (dst_height + posy*2) * skinfb->height / (height + posy*2);
352                                        int dsleft = skinfb->width - dswidth;
353                                        int dstop = skinfb->height - dsheight;
354                                        if(status.screenanim == 11)
355                                                dstop = 0;
356                                        if(status.screenanim == 12)
357                                                dsleft = 0;
358                                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, dsleft, dstop, dswidth, dsheight, dst_left, dst_top, dst_width, dst_height, 0, 0);
359                                }       
360                        }       
361                        else
362                        {
363                                setfbosddev(fbleftdev, dst_left);
364                                setfbosddev(fbwidthdev, dst_width);
365                                setfbosddev(fbtopdev, dst_top);
366                                setfbosddev(fbheightdev, dst_height);
367                                usleep(1000);
368                        }
369                        if(status.screenanim > 0) usleep(status.screenanimspeed * 1000);
370                        blit();
371                }
372                if(status.bcm == 1 && status.usedirectfb == 0)
373                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0);
374                else
375                {
376                        setfbosddev(fbleftdev, posx);
377                        setfbosddev(fbwidthdev, width);
378                        setfbosddev(fbtopdev, posy);
379                        setfbosddev(fbheightdev, height);
380                }
381                blit();
382        }
383        else
384        {
385                if(status.bcm == 1 && status.usedirectfb == 0)
386                        bcm_accel_blit(skinfb->data_phys, skinfb->width, skinfb->height, skinfb->pitch, 0, fb->data_phys, fb->width, fb->height, fb->pitch, 0, 0, skinfb->width, skinfb->height, posx, posy, width, height, 0, 0);
387        }
388        if(doblit == 1)
389                blit();
390       
391/*     
392        int xRes, yRes, stride, bpp;
393       
394        xRes=var_screeninfo.xres;
395        yRes=var_screeninfo.yres;
396        bpp=var_screeninfo.bits_per_pixel;
397//      fb_fix_screeninfo fix;
398//      struct fb_fix_screeninfo fix_screeninfo;
399        if (ioctl(fb->fd, FBIOGET_FSCREENINFO, &fix_screeninfo)<0)
400        {
401                perror("FBIOGET_FSCREENINFO");
402                printf("fb failed\n");
403        }
404        stride=fix_screeninfo.line_length;
405        memset(lfb, 0, stride*yRes);
406*/
407//      blit();
408       
409/*
410        int i = 0, max = 1, wstep = 0, hstep = 0, ret = 0;
411        unsigned char buf[10];
412
413        if(fbnode == NULL) return;
414#ifndef NOHWBLIT
415        if(fbnode == fb) return;
416
417        if(status.rguidfd > -1)
418        {
419                m_lock(&status.accelfbmutex, 16);
420               
421                int zlen = 0;
422                char* zbuf = NULL;
423                blitscale(0, 0, fbnode->width, fbnode->height, 440, 330, 1);
424                ret = ozip((char*)accelfb->fb, 440 * 330 * 4, &zbuf, &zlen, 1);
425
426                if(ret == 0)
427                {
428                        memset(buf, 0, 10);
429                        char* tmpnr = oitoa(zlen);
430                        memcpy(buf, tmpnr, strlen(tmpnr));
431                        free(tmpnr); tmpnr = NULL;
432                        socksend(&status.rguidfd, buf, 10, 5000 * 1000);
433                        socksend(&status.rguidfd, (unsigned char*)zbuf, zlen, 5000 * 1000);
434                }
435                free(zbuf); zbuf = NULL;
436                zlen = 0;
437
438                m_unlock(&status.accelfbmutex, 16);
439        }
440
441        if(status.write_png == 1 && status.infobaraktiv == 0)
442        {
443                m_lock(&status.accelfbmutex, 16);
444                blitscale(0, 0, fbnode->width, fbnode->height, 320, 240, 1);
445                if(writeFBfile.ActBuf == NULL)
446                {
447                        writeFBfile.buf1 = malloc(4 * 320 * 240);
448                        writeFBfile.ActBuf = writeFBfile.buf1;
449                        memcpy(writeFBfile.buf1, accelfb->fb, 4 * 320 * 240);
450                        addtimer(&fb2png_thread, START, 10000, 1, NULL, NULL, NULL);
451                }
452                else if(writeFBfile.buf1 == writeFBfile.ActBuf)
453                {
454                        if(writeFBfile.buf2 == NULL)
455                                writeFBfile.buf2 = malloc(4 * 320 * 240);
456                        memcpy(writeFBfile.buf2, accelfb->fb, 4 * 320 * 240);
457                }
458                else if(writeFBfile.buf2 == writeFBfile.ActBuf)
459                {
460                        if(writeFBfile.buf1 == NULL)
461                                writeFBfile.buf1 = malloc(4 * 320 * 240);
462                        memcpy(writeFBfile.buf1, accelfb->fb, 4 * 320 * 240);
463                }
464                m_unlock(&status.accelfbmutex, 16);
465        }
466
467        int mode3d = 0, leftoffset = 0, rightoffset = 0, topoffset = 0, bottomoffset = 0;
468        char* mode3dstr = NULL;
469
470        if(status.leftoffset != 0) blitrect(0, 0, status.leftoffset, fb->height, 0, 255, 2);
471        if(status.rightoffset != 0) blitrect(fb->width - status.rightoffset, 0, status.rightoffset, fb->height, 0, 255, 2);
472        if(status.topoffset != 0) blitrect(0, 0, fb->width, status.topoffset, 0, 255, 2);
473        if(status.bottomoffset != 0) blitrect(0, fb->height - status.bottomoffset, fb->width, status.bottomoffset, 0, 255, 2);
474
475        mode3dstr = getconfig("av_mode3d", NULL);
476        if(ostrcmp(mode3dstr, "sbs") == 0)
477                mode3d = 1;
478        else if(ostrcmp(mode3dstr, "tab") == 0)
479                mode3d = 2;
480
481        STMFBIO_BLT_DATA  bltData;
482        memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA));
483
484        bltData.operation  = BLT_OP_COPY;
485        bltData.srcOffset  = fbnode->fb - fb->fb;
486        bltData.srcPitch   = fbnode->pitch;
487        bltData.src_top    = 0;
488        bltData.src_left   = 0;
489        bltData.src_right  = fbnode->width;
490        bltData.src_bottom = fbnode->height;
491        bltData.srcFormat  = SURF_BGRA8888;
492        bltData.srcMemBase = STMFBGP_FRAMEBUFFER;
493
494        bltData.dstOffset  = 0;
495        bltData.dstPitch   = fb->pitch;
496        bltData.dst_left   = status.leftoffset;
497        bltData.dst_top    = status.topoffset;
498        if(mode3d == 1)
499                bltData.dst_right = (fb->width - status.rightoffset) / 2;
500        else
501                bltData.dst_right = fb->width - status.rightoffset;
502        if(mode3d == 2)
503                bltData.dst_bottom = (fb->height - status.bottomoffset) / 2;
504        else
505                bltData.dst_bottom = fb->height - status.bottomoffset;
506        bltData.dstFormat  = SURF_BGRA8888;
507        bltData.dstMemBase = STMFBGP_FRAMEBUFFER;
508
509        if(flag == 1 && status.screenanim > 0 && mode3d == 0)
510        {
511                int width = (fb->width - status.rightoffset) - status.leftoffset;
512                int height = (fb->height - status.topoffset) - status.bottomoffset;
513                max = 25;
514                if(status.screenanim == 1 || status.screenanim == 3)
515                {
516                        bltData.dst_left = (width / 2) - 1;
517                        bltData.dst_right = (width / 2) + 1;
518                }
519                if(status.screenanim == 2 || status.screenanim == 3)
520                {
521                        bltData.dst_top = (height / 2) - 1;
522                        bltData.dst_bottom = (height / 2) + 1;
523                }
524                wstep = width / max;
525                hstep = height / max;
526        }
527
528        for(i = 0; i < max; i++)
529        {
530
531                if(status.screenanim == 1 || status.screenanim == 3)
532                {
533                        int tmpleft = bltData.dst_left - wstep;
534                        int tmpright = bltData.dst_right + wstep;
535                        if(tmpleft < status.leftoffset)
536                                tmpleft = status.leftoffset;
537                        if(tmpright > fb->width - status.rightoffset)
538                                tmpright = fb->width - status.rightoffset;
539                        bltData.dst_left = tmpleft;
540                        bltData.dst_right = tmpright;
541                }
542
543                if(status.screenanim == 2 || status.screenanim == 3)
544                {
545                        int tmptop = bltData.dst_top - hstep;
546                        int tmpbottom = bltData.dst_bottom + hstep;
547                        if(tmptop < status.topoffset)
548                                tmptop = status.topoffset;
549                        if(tmpbottom > fb->height - status.bottomoffset)
550                                tmpbottom = fb->height - status.bottomoffset;
551                        bltData.dst_top = tmptop;
552                        bltData.dst_bottom = tmpbottom;
553                }
554
555                if(status.screenanim > 0) usleep(status.screenanimspeed * 1000);
556
557                if (ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
558                {
559                        perr("ioctl STMFBIO_BLT");
560                }
561                if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
562                {
563                        perr("ioctl STMFBIO_SYNC_BLITTER");
564                }
565
566                if(mode3d != 0)
567                {
568                        if(mode3d == 1)
569                                bltData.dst_left = 0 + status.leftoffset + ((fb->width - status.rightoffset) / 2);
570                        if(mode3d == 2)
571                                bltData.dst_top = 0 + status.topoffset + ((fb->height - status.bottomoffset) / 2);
572                        bltData.dst_right  = fb->width - status.rightoffset;
573                        bltData.dst_bottom = fb->height - status.bottomoffset;
574
575                        if (ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
576                        {
577                                perr("ioctl STMFBIO_BLT");
578                        }
579                        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
580                        {
581                                perr("ioctl STMFBIO_SYNC_BLITTER");
582                        }
583                }
584        }
585#else
586#ifdef NOFB
587        if(status.rguidfd > -1)
588        {
589                char* buf = NULL;
590                buf = scale(fbnode->fb, fbnode->width, fbnode->height, 4, 320, 240, 0);
591                if(buf != NULL)
592                {
593                        socksend(&status.rguidfd, (unsigned char*)buf, 320 * 240 * 4, 5000 * 1000);
594                        free(buf); buf = NULL;
595                }
596        }
597        if(status.write_png == 1 && status.infobaraktiv == 0)
598        {
599                char* buf = NULL;
600                buf = scale(fbnode->fb, fbnode->width, fbnode->height, 4, 320, 240, 0);
601                if(buf != NULL)
602                {
603                        if(writeFBfile.ActBuf == NULL)
604                        {
605                                writeFBfile.buf1 = malloc(4 * 320 * 240);
606                                writeFBfile.ActBuf = writeFBfile.buf1;
607                                memcpy(writeFBfile.buf1, (unsigned char*)buf, 4 * 320 * 240);
608                                addtimer(&fb2png_thread, START, 10000, 1, NULL, NULL, NULL);
609                        }
610                        else if(writeFBfile.buf1 == writeFBfile.ActBuf)
611                        {
612                                if(writeFBfile.buf2 == NULL)
613                                        writeFBfile.buf2 = malloc(4 * 320 * 240);
614                                memcpy(writeFBfile.buf2, (unsigned char*)buf, 4 * 320 * 240);
615                        }
616                        else if(writeFBfile.buf2 == writeFBfile.ActBuf)
617                        {
618                                if(writeFBfile.buf1 == NULL)
619                                        writeFBfile.buf1 = malloc(4 * 320 * 240);
620                                memcpy(writeFBfile.buf1, (unsigned char*)buf, 4 * 320 * 240);
621                        }
622                        //fb2png((unsigned char*)buf, 320, 240, "/tmp/titanlcd.png");
623                        free(buf); buf = NULL;
624                }
625        }
626
627        if(fbnode != fb)
628        {
629                for(i = 0; i < fbnode->height; i++)
630                {
631                        memcpy(fb->fb + (i * fb->pitch), fbnode->fb + (i * fbnode->pitch), fbnode->width * fbnode->colbytes);
632                }
633        }
634        system("killall -9 xloadimage");
635
636        FILE *fd;
637        fd=fopen("titan.png", "w");
638        fwrite(fb->fb, fb->varfbsize, 1, fd);
639        fclose(fd);
640
641        system("fbgrab -f titan.png -w 1280 -h 720 -b 32 titan1.png > /dev/null");
642        system("xloadimage titan1.png > /dev/null &");
643#endif
644#endif
645*/
646}
647
648void setfbtransparent(int value)
649{
650        char* transparentdev;
651
652        transparentdev = getconfig("transparentdev", NULL);
653
654        if(transparentdev != NULL /*&& checkdev(transparentdev)*/)
655        {
656                debug(100, "set %s to %d", transparentdev, value);
657                writesysint(transparentdev, value, 1);
658                return;
659        }
660/*
661#ifndef SIMULATE
662        struct stmfbio_var_screeninfo_ex varEx = {0};
663
664        varEx.layerid  = 0;
665        varEx.activate = STMFBIO_ACTIVATE_IMMEDIATE;
666        varEx.caps = STMFBIO_VAR_CAPS_OPACITY;
667        varEx.opacity = value;
668
669
670        if(ioctl(fb->fd, STMFBIO_SET_VAR_SCREENINFO_EX, &varEx) < 0)
671                perr("STMFBIO_SET_VAR_SCREENINFO_EX");
672#endif
673*/
674}
675
676int allocbpamem(size_t size, int *memfd, unsigned char **mem)
677{
678        return -1;
679}
680
681void freebpamem(int memfd, unsigned char* mem, size_t len)
682{
683}
684
685//mode 0: with fill (draw to skinfb)
686//mode 1: without fill (draw to skinfb)
687//mode 2: with fill (draw to fb)
688//mode 3: without fill (draw to fb)
689void blitrect(int posx, int posy, int width, int height, long color, int transparent, int mode)
690{
691        int y, x;
692        unsigned long tmpcol;
693        struct fb* tmpfb = NULL;
694       
695        if(posx < 0) posx = 0;
696        if(posy < 0) posy = 0;
697        if(mode < 2)
698                tmpfb = skinfb;
699        else
700                tmpfb = fb;
701               
702        if(posx > tmpfb->width) posx = tmpfb->width;
703        if(posy > tmpfb->height) posy = tmpfb->height;
704        if(posx + width > tmpfb->width) width = tmpfb->width - posx;
705        if(posy + height > tmpfb->height) height = tmpfb->height - posy;
706
707        if(width <= 0 || height <= 0) return;
708
709        transparent = (transparent - 255) * -1;
710        tmpcol = color | ((transparent & 0xff) << 24);
711
712        if(mode == 0 || mode == 2)
713        {
714               
715                if(status.bcm == 1 && tmpfb->data_phys != 0)
716                {
717                        bcm_accel_fill(tmpfb->data_phys, tmpfb->width, tmpfb->height, tmpfb->pitch, posx, posy, width, height, tmpcol);
718                }
719                else
720                {
721                        int yend = (posy + height) * tmpfb->width;
722                        posy *= tmpfb->width;
723                        int xend = posx + width;
724                        int xlen = (xend - posx) * tmpfb->colbytes;
725                        int r = 0;
726                        unsigned char* from = tmpfb->fb + (posy + posx) * tmpfb->colbytes;
727
728                        for(y = posy; y < yend; y += tmpfb->width)     
729                        {
730                                if(r == 0)
731                                {
732                                        r = 1;
733                                        for(x = posx; x < xend; x++)
734                                                drawpixelfastfb(tmpfb, x, y, tmpcol);
735                                }
736                                else
737                                {
738//                                      printf("befor memcpy_area\n");
739                                        memcpy(tmpfb->fb + (y + posx) * tmpfb->colbytes, from, xlen);
740                                        // return 100 error on branch 3.4
741//                                      memcpy_area(tmpfb->fb + (y + posx) * tmpfb->colbytes, from, posx * 4, height-1, width*4, tmpfb->width*4);
742                                        //y = yend;
743                                }
744                               
745                        }
746                }
747        }
748        else if(mode == 1 || mode == 3)
749        {
750                //topline
751                for(x = 0; x < width; x++)
752                        drawpixelfb(tmpfb, posx + x, posy, tmpcol);
753                //bottomline
754                for(x = 0; x < width; x++)
755                        drawpixelfb(tmpfb, posx + x, posy + height - 1, tmpcol);
756                //leftline
757                for(y = 0; y < height; y++)
758                        drawpixelfb(tmpfb, posx, posy + y, tmpcol);
759                //rightline
760                for(y = 0; y < height; y++)
761                        drawpixelfb(tmpfb, posx + width - 1, posy + y, tmpcol);
762        }
763
764/*
765        unsigned long tmpcol;
766
767        transparent = (transparent - 255) * -1;
768        tmpcol = color | ((transparent & 0xff) << 24);
769
770        STMFBIO_BLT_DATA  bltData;
771        memset(&bltData, 0, sizeof(STMFBIO_BLT_DATA));
772
773        if(posx < 0) posx = 0;
774        if(posy < 0) posy = 0;
775        if(mode < 2)
776        {
777                if(posx > skinfb->width) posx = skinfb->width;
778                if(posy > skinfb->height) posy = skinfb->height;
779                if(posx + width > skinfb->width) width = skinfb->width - posx;
780                if(posy + height > skinfb->height) height = skinfb->height - posy;
781        }
782        else
783        {
784                if(posx > fb->width) posx = fb->width;
785                if(posy > fb->height) posy = fb->height;
786                if(posx + width > fb->width) width = fb->width - posx;
787                if(posy + height > fb->height) height = fb->height - posy;
788        }
789
790        if(width <= 0 || height <= 0) return;
791
792        if(mode == 0 || mode == 2)
793                bltData.operation  = BLT_OP_FILL;
794        else if(mode == 1 || mode == 3)
795                bltData.operation  = BLT_OP_DRAW_RECTANGLE;
796        bltData.colour     = tmpcol;
797        bltData.srcFormat  = SURF_ARGB8888;
798        bltData.srcMemBase = STMFBGP_FRAMEBUFFER;
799
800        if(status.usedirectfb == 1)
801                bltData.dstOffset  = 0;
802        else
803        {
804                if(mode < 2)
805                        bltData.dstOffset  = fb->varfbsize;
806                else
807                        bltData.dstOffset  = 0;
808        }
809        if(mode < 2)
810                bltData.dstPitch   = skinfb->pitch;
811        else
812                bltData.dstPitch   = fb->pitch;
813        bltData.dst_top    = posy;
814        bltData.dst_left   = posx;
815        bltData.dst_bottom = posy + height;
816        bltData.dst_right  = posx + width;
817        bltData.dstFormat  = SURF_ARGB8888;
818        bltData.dstMemBase = STMFBGP_FRAMEBUFFER;
819
820        if(ioctl(fb->fd, STMFBIO_BLT, &bltData) < 0)
821        {
822                perr("ioctl STMFBIO_BLT");
823        }
824        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
825        {
826                perr("ioctl STMFBIO_SYNC_BLITTER");
827        }
828*/
829}
830
831int readjpg(const char* filename, unsigned long* width, unsigned long* height, unsigned long* rowbytes, int* channels, unsigned char **mem, int *memfd)
832{
833/*
834#ifndef SIMULATE
835        FILE *fp;
836        unsigned int temp1, temp2;
837
838        if(filename == NULL) return -1;
839
840        debug(200, "hardware decode picture (%s)...", filename);
841
842        if (!(fp = fopen(filename, "rb")))
843                return -1;
844         
845        if(get_jpeg_img_size(fp, &temp1, &temp2) != LIBMMEIMG_SUCCESS)
846                return -1;
847       
848        *width = temp1;
849        *height = temp2;
850        *channels = 3;
851        *rowbytes = *channels * temp1;
852       
853        if(allocbpamem(temp1 * temp2 * (*channels), memfd, mem) != 0)
854        {
855                fclose(fp);
856                return -1;
857        }
858               
859        if(decode_jpeg_noalloc(fp, temp1, temp2, temp1, temp2, (char *)*mem, 1) == LIBMMEIMG_SUCCESS)
860        {
861                fclose(fp);
862                return 0;
863        }
864       
865        fclose(fp);
866        freebpamem(*memfd, *mem, temp1 * temp2 * (*channels));
867        err("hardware decode error");
868#endif
869        return -1;
870*/
871return -1;
872}
873
874//flag 0: blit from accelfb to skinfb
875//flag 1: blit from skinfb to accelfb
876void blitscale(int posx, int posy, int width, int height, int scalewidth, int scaleheight, int flag)
877{
878#ifndef SIMULATE
879//#ifdef BLITHELP
880        unsigned char *source = NULL;
881        unsigned char *target = NULL;
882        int zpitch = 0;
883        int zheight = 0;
884        int zwidth = 0;
885        int qpitch = 0;
886        int qheight = 0;
887        int qwidth = 0;
888        unsigned long source_phys = 0;
889        unsigned long target_phys = 0;
890
891        if(scalewidth == 0) scalewidth = width;
892        if(scaleheight == 0) scaleheight = height;
893
894        if(posx < 0) posx = 0;
895        if(posx > skinfb->width) posx = skinfb->width;
896        if(posy < 0) posy = 0;
897        if(posy > skinfb->height) posy = skinfb->height;
898        if(posx + scalewidth > skinfb->width) scalewidth = skinfb->width - posx;
899        if(posy + scaleheight > skinfb->height) scaleheight = skinfb->height - posy;
900       
901        if(width <= 0 || height <= 0 || scalewidth <= 0 || scaleheight <= 0) return;
902       
903        if(flag == 1 && (scalewidth * scaleheight * 4) > accelfb->varfbsize)
904        {
905                err("accelfb to small %d -> %lu ", scalewidth * scaleheight * 4, accelfb->varfbsize);
906                return;
907        }
908        if(flag == 0)
909        {
910                source = accelfb->fb;
911                source_phys = accelfb->data_phys;
912                target_phys = skinfb->data_phys;
913
914                target = skinfb->fb + (posy * skinfb->pitch) + (posx*4);
915                zpitch = skinfb->pitch;
916                zheight = skinfb->height;
917                zwidth = skinfb->width;
918                qpitch = width*4;
919                qheight = height;
920                qwidth = width;
921        }
922        else
923        {
924                source = skinfb->fb;
925                source_phys = skinfb->data_phys;
926                target_phys = accelfb->data_phys;
927
928                target = accelfb->fb + (posy * accelfb->pitch) + (posx*4);
929                zpitch = accelfb->pitch;
930                zheight = accelfb->height;
931                zwidth = accelfb->width;
932                qpitch = width*4;
933                qheight = height;
934                qwidth = width;
935        }
936       
937        if(status.bcm == 1 && source_phys > 0 && target_phys >0)
938        {
939                bcm_accel_blit(source_phys, qwidth, qheight, qpitch, 0, target_phys, zwidth, zheight, zpitch, 0, 0, width, height, posx, posy, scalewidth, scaleheight, 0, 0);
940                flag = 1;
941        }
942        else
943        {
944                unsigned char *helpbuf = NULL;
945                helpbuf = scale(source, width, height, 4, scalewidth, scaleheight, 0);
946       
947                size_t helpb = 0;
948                size_t helpz = 0;
949                size_t help = 0;
950       
951                while(helpz < scaleheight && helpz < (zheight - posy)) {
952                        //memcpy(target[help], helpbuf[helpb], scalewidth*4);
953                        memcpy(target+help, helpbuf+helpb, scalewidth*4);
954                        help = help + zpitch;
955                        helpb = helpb + scalewidth*4;
956                        helpz = helpz + 1;
957                }
958                free(helpbuf);
959        }
960       
961       
962        if(flag == 0)
963                blit();
964
965//#endif
966
967/*
968        STMFBIO_BLT_DATA  blt_data;
969        memset(&blt_data, 0, sizeof(STMFBIO_BLT_DATA));
970
971        if(scalewidth == 0) scalewidth = width;
972        if(scaleheight == 0) scaleheight = height;
973
974        if(posx < 0) posx = 0;
975        if(posx > skinfb->width) posx = skinfb->width;
976        if(posy < 0) posy = 0;
977        if(posy > skinfb->height) posy = skinfb->height;
978        if(posx + scalewidth > skinfb->width) scalewidth = skinfb->width - posx;
979        if(posy + scaleheight > skinfb->height) scaleheight = skinfb->height - posy;
980       
981        if(width <= 0 || height <= 0 || scalewidth <= 0 || scaleheight <= 0) return;
982       
983        if(flag == 1 && (scalewidth * scaleheight * 4) > accelfb->varfbsize)
984        {
985                err("accelfb to small %d -> %lu ", scalewidth * scaleheight * 4, accelfb->varfbsize);
986                return;
987        }
988
989        blt_data.operation  = BLT_OP_COPY;
990       
991        if(flag == 0)
992        {
993                if(status.usedirectfb == 1)
994                        blt_data.srcOffset  = fb->varfbsize;
995                else
996                        blt_data.srcOffset  = fb->varfbsize + skinfb->varfbsize;
997        }
998        else
999        {
1000                if(status.usedirectfb == 1)
1001                        blt_data.srcOffset  = 0;
1002                else
1003                        blt_data.srcOffset  = fb->varfbsize;
1004        }
1005       
1006        blt_data.srcPitch   = width * 4;
1007        blt_data.src_top    = 0;
1008        blt_data.src_left   = 0;
1009        blt_data.src_right  = width;
1010        blt_data.src_bottom = height;
1011        blt_data.srcFormat  = SURF_ARGB8888;
1012        blt_data.srcMemBase = STMFBGP_FRAMEBUFFER;
1013       
1014        if(flag == 0)
1015        {
1016                if(status.usedirectfb == 1)
1017                {
1018                        blt_data.dstOffset  = 0;
1019                        blt_data.dstPitch   = fb->pitch;
1020                }
1021                else
1022                {
1023                        blt_data.dstOffset  = fb->varfbsize;
1024                        blt_data.dstPitch   = skinfb->pitch;
1025                }
1026        }
1027        else
1028        {
1029                if(status.usedirectfb == 1)
1030                {
1031                        blt_data.dstOffset  = fb->varfbsize;
1032                        blt_data.dstPitch   = skinfb->pitch;
1033                }
1034                else
1035                {
1036                        blt_data.dstOffset  = fb->varfbsize + skinfb->varfbsize;
1037                        blt_data.dstPitch   = scalewidth * 4;
1038                }
1039        }
1040       
1041        blt_data.dst_left   = posx;
1042        blt_data.dst_top    = posy;
1043        blt_data.dst_right  = posx + scalewidth;
1044        blt_data.dst_bottom = posy + scaleheight;
1045        blt_data.dstFormat  = SURF_ARGB8888;
1046        blt_data.dstMemBase = STMFBGP_FRAMEBUFFER;
1047       
1048        if (ioctl(fb->fd, STMFBIO_BLT, &blt_data) < 0)
1049        {
1050                perr("ioctl STMFBIO_BLT");
1051        }
1052        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
1053        {
1054                perr("ioctl STMFBIO_SYNC_BLITTER");
1055        }
1056*/
1057#endif
1058}
1059
1060void blitjpg(unsigned char* buf, int posx, int posy, int width, int height, int scalewidth, int scaleheight, int mwidth, int mheight, int halign, int valign)
1061//void blitjpg(unsigned char* buf, int posx, int posy, int width, int height, int scalewidth, int scaleheight)
1062{
1063#ifndef SIMULATE
1064#ifdef BLITHELP
1065        unsigned char *helpbuf = NULL;
1066        unsigned char *framebuf = NULL;
1067
1068        if(scalewidth != 0 || scaleheight != 0) {
1069                helpbuf = scale(buf, width, height, 3, scalewidth, scaleheight, 1);
1070                if(helpbuf == NULL)
1071                        return;
1072        }
1073        else {
1074                helpbuf = buf;
1075                scalewidth = width;
1076                scaleheight = height;
1077        }
1078        size_t helpb = 0;
1079        size_t helpz = 0;
1080        size_t help = 0;
1081       
1082        framebuf = skinfb->fb;
1083        framebuf = framebuf + (posy * skinfb->pitch) + (posx*4);
1084       
1085        while(helpz < scaleheight && helpz < (skinfb->height - posy)) {
1086                help = 0;
1087                while(help < (scalewidth*4) && help < (skinfb->pitch - (posx*4))) {
1088                        framebuf[help+0] = helpbuf[helpb+2];
1089                        framebuf[help+1] = helpbuf[helpb+1];
1090                        framebuf[help+2] = helpbuf[helpb+0];
1091                        framebuf[help+3] = 0xff;
1092                        help = help + 4;
1093                        helpb = helpb + 3;
1094                }
1095                if(help >= (skinfb->pitch - (posx*4)))
1096                        helpb = (helpz+1) * (scalewidth*3);
1097                framebuf = framebuf + skinfb->pitch;
1098                helpz = helpz + 1;
1099        }
1100        free(helpbuf);
1101        blit();
1102#endif
1103                 
1104/*
1105        STMFBIO_BLT_EXTERN_DATA blt_data;
1106        memset(&blt_data, 0, sizeof(STMFBIO_BLT_EXTERN_DATA));
1107
1108        blt_data.operation  = BLT_OP_COPY;
1109        blt_data.ulFlags    = 0;
1110        blt_data.srcOffset  = 0;
1111        blt_data.srcPitch   = width * 3;
1112        blt_data.dstOffset  = 0;
1113        blt_data.dstPitch   = skinfb->pitch;
1114        blt_data.src_top    = 0;
1115        blt_data.src_left   = 0;
1116        blt_data.src_right  = width;
1117        blt_data.src_bottom = height;
1118        blt_data.dst_left   = posx;
1119        blt_data.dst_top    = posy;
1120       
1121        if(scalewidth == 0)  scalewidth = width;
1122        if(scaleheight == 0) scaleheight = height;
1123       
1124        blt_data.dst_right  = posx + scalewidth;
1125        blt_data.dst_bottom = posy + scaleheight;
1126        blt_data.srcFormat  = SURF_BGR888;
1127        blt_data.dstFormat  = SURF_ARGB8888;
1128        blt_data.srcMemBase = (char *)buf;
1129        blt_data.dstMemBase = (char *)skinfb->fb;
1130        blt_data.srcMemSize = width * height * 3;
1131        blt_data.dstMemSize = skinfb->pitch * skinfb->height;
1132       
1133        if(ioctl(skinfb->fd, STMFBIO_BLT_EXTERN, &blt_data) < 0)
1134        {
1135                err("ioctl STMFBIO_BLT_EXTERN");
1136        }
1137        if(ioctl(fb->fd, STMFBIO_SYNC_BLITTER) < 0)
1138        {
1139                perr("ioctl STMFBIO_SYNC_BLITTER");
1140        }
1141*/
1142
1143#endif
1144}
1145
1146void initsignal(struct sigaction* sa)
1147{
1148        sigaction(SIGILL, sa, NULL);
1149        sigaction(SIGBUS, sa, NULL);
1150        sigaction(SIGFPE, sa, NULL);
1151        sigaction(SIGUSR1, sa, NULL);
1152        sigaction(SIGSEGV, sa, NULL);
1153        sigaction(SIGUSR2, sa, NULL);
1154        sigaction(SIGPIPE, sa, NULL);
1155        sigaction(SIGALRM, sa, NULL);
1156//      sigaction(SIGSTKFLT, sa, NULL);
1157        sigaction(SIGABRT, sa, NULL);
1158
1159        signal(SIGHUP, SIG_IGN);
1160        signal(SIGINT, SIG_IGN);
1161        signal(SIGTRAP, SIG_IGN);
1162        signal(SIGXCPU, SIG_IGN);
1163        signal(SIGXFSZ, SIG_IGN);
1164        signal(SIGVTALRM, SIG_IGN);
1165        signal(SIGPROF, SIG_IGN);
1166        signal(SIGPOLL, SIG_IGN);
1167        signal(SIGRTMAX, SIG_IGN);
1168        signal(SIGPWR, SIG_IGN);
1169        signal(SIGSYS, SIG_IGN);
1170}
1171
1172void sighandler(int sig, struct sigcontext ctx)
1173{
1174        switch(sig)
1175        {
1176                case SIGALRM:
1177                {
1178                        err("got signal sigalrm but ignore it");
1179                        break;
1180                }
1181                case SIGPIPE:
1182                {
1183                        err("got signal sigpipe but ignore it");
1184                        break;
1185                }
1186                case SIGUSR1:
1187                {
1188                        //todo all configs
1189                        reloadconfig(status.configfile);
1190                        reloadconfig(getconfig("ownconfig", NULL));
1191                        break;
1192                }
1193                case SIGUSR2: //called if hanging mainthread detect
1194                {
1195                        debugstack(sig, NULL, NULL);
1196                        break;
1197                }
1198                case SIGILL:
1199                case SIGBUS:
1200                case SIGFPE:
1201                case SIGSEGV:
1202//              case SIGSTKFLT:
1203                {
1204/*
1205#ifdef SIMULATE
1206                        //intel
1207                        debugstack((void *)ctx.eip, NULL);
1208                        err("got signal %d, fault address 0x%lx from 0x%lx", sig, ctx.cr2, ctx.eip);
1209#else
1210                        // sh4
1211                        //unsigned long sc_regs[16];
1212                        //unsigned long sc_pc; //programm counter register
1213                        //unsigned long sc_pr; //procedure register
1214                        //unsigned long sc_sr; //status register
1215                        //unsigned long sc_gbr;
1216                        //unsigned long sc_mach;
1217                        //unsigned long sc_macl;
1218
1219                        debugstack(sig, (void *)ctx.sc_pr, (void *)ctx.sc_pc);
1220                        err("got signal %d (%s), programm counter reg: 0x%lx,  procedure reg: 0x%lx", sig, strsignal(sig), ctx.sc_pc, ctx.sc_pr);
1221#endif
1222*/
1223                        if(getconfigint("saverun", NULL) == 1 && status.longjumpbuf != NULL)
1224                                siglongjmp(status.longjumpbuf, 999);
1225                        else
1226                                exit(100);
1227                        break;
1228                }
1229        }
1230}
1231
1232int setvmpeg(struct dvbdev* node, int value, int flag)
1233{
1234        debug(4440, "in");
1235        char* vmpegdev = NULL, *tmpstr = NULL, *buf = NULL;
1236        int ret = 0;
1237
1238        if(getskinconfigint("minitv", NULL) == 1)
1239                return 0;
1240
1241        if(node == NULL) return 1;
1242        if(flag == 0)  vmpegdev = getconfig("vmpegleftdev", NULL);
1243        if(flag == 1)  vmpegdev = getconfig("vmpegtopdev", NULL);
1244        if(flag == 2)  vmpegdev = getconfig("vmpegwidthdev", NULL);
1245        if(flag == 3)  vmpegdev = getconfig("vmpegheightdev", NULL);
1246        if(flag == 99) vmpegdev = getconfig("vmpegapplydev", NULL);
1247
1248        if(vmpegdev != NULL)
1249        {
1250                buf = malloc(MINMALLOC);
1251                if(buf == NULL)
1252                {
1253                        err("no mem");
1254                        return 1;
1255                }
1256               
1257                tmpstr = malloc(10);
1258                if(tmpstr == NULL)
1259                {
1260                        err("no mem");
1261                        free(buf);
1262                        return 1;
1263                }
1264               
1265                snprintf(buf, MINMALLOC, vmpegdev, node->devnr);
1266                snprintf(tmpstr, 10, "%x", value);
1267                debug(444, "set %s to %s", buf, tmpstr);
1268                status.tvpic = 1;
1269                ret = writesys(buf, tmpstr, 1);
1270               
1271                free(tmpstr);
1272                free(buf);
1273                return ret;
1274        }
1275
1276        debug(4440, "out");
1277        return 0;
1278}
1279
1280//flag 0: wh = width
1281//flag 1: wh = height
1282//int setvmpegrect(struct dvbdev* node, int left, int top, int wh, int flag)
1283int setvmpegrect(struct dvbdev* node, int posx, int posy, int wh, int flag)
1284{
1285        int ret = 0;
1286        int leftoffset = status.leftoffset;
1287        int rightoffset = status.rightoffset;
1288        int topoffset = status.topoffset;
1289        int bottomoffset = status.bottomoffset;
1290
1291        float rx = (float)720 / (float)(720 - leftoffset - rightoffset);
1292        float ry = (float)576 / (float)(576 - topoffset - bottomoffset);
1293
1294        posx = (float)posx / rx;
1295        posx += leftoffset;
1296
1297        posy = (float)posy / ry;
1298        posy += topoffset;
1299
1300        ret = setvmpeg(node, posx, 0);
1301        ret = setvmpeg(node, posy, 1);
1302       
1303        if(flag == 0)
1304        {
1305                wh = wh * (720 - leftoffset - rightoffset) / 720;
1306                ret = setvmpeg(node, wh, 2);
1307                ret = setvmpeg(node, (int)((float)wh / 1.2), 3);
1308        }
1309
1310        if(flag == 1)
1311        {
1312                wh = wh * (576 - topoffset - bottomoffset) / 576;
1313                ret = setvmpeg(node, wh, 3);
1314                ret = setvmpeg(node, (int)((float)wh * 1.2), 2);
1315        }
1316       
1317        setvmpeg(node, 0, 99);
1318       
1319        return ret;
1320}
1321       
1322int resetvmpeg(struct dvbdev* node)
1323{
1324        int ret = 0;
1325
1326        ret = setvmpeg(node, 0, 0);
1327        ret = setvmpeg(node, 0, 1);
1328        ret = setvmpeg(node, 0, 2);
1329        ret = setvmpeg(node, 0, 3);
1330       
1331        ret = setvmpeg(node, 0, 99);
1332
1333        status.tvpic = 0;
1334                       
1335        return ret;
1336}
1337
1338int resettvpic()
1339{
1340/*
1341        if(status.tvpic == 1 && status.aktservice != NULL)
1342        {
1343                status.tvpic = 0;
1344                resetvmpeg(status.aktservice->videodev);
1345        }
1346*/
1347        int ret = 0;
1348
1349        if(status.tvpic > 0 && status.aktservice != NULL)
1350                ret = resetvmpeg(status.aktservice->videodev);
1351
1352        return ret;
1353}
1354
1355int cagetslotinfo(struct dvbdev* node, ca_slot_info_t* info)
1356{
1357        int ret = 0;
1358       
1359        if(node == NULL || info == NULL)
1360        {
1361                err("NULL detect");
1362                return 1;
1363        }
1364       
1365        struct pollfd fds;
1366       
1367        fds.fd = node->fd;
1368        fds.events = POLLOUT | POLLPRI | POLLIN;
1369       
1370        info->flags = 0;
1371       
1372        ret = TEMP_FAILURE_RETRY(poll(&fds, 1, 1000));
1373       
1374        if(ret < 0)
1375        {
1376                err("poll data");
1377                return 1; //error
1378        }
1379        else if(ret == 0)
1380                return 0; //timeout
1381        else if(ret > 0)
1382        {
1383                if(fds.revents & POLLOUT)
1384                        info->flags = CA_CI_MODULE_READY;
1385                if(fds.revents & POLLIN)
1386                        info->flags = CA_CI_MODULE_READY;
1387                if(fds.revents & POLLPRI)
1388                        info->flags = 0;
1389        }
1390
1391        return 0;
1392}
1393
1394void memcpy_word(char* dest, char* src, long anzw)
1395{
1396        // Folgende Werte m�ssen volatile definiert sein
1397        // char* memcpy_word_src ---> pointer Quelle
1398        // char* memcpy_word_dest ---> pointer Ziehl
1399        // long  memcpy_word_anzw ---> Anzahl der W�rter (4 byte) die kopiert werden sollen.
1400       
1401        memcpy_word_src = src;
1402        memcpy_word_dest = dest;
1403        memcpy_word_anzw = anzw;
1404
1405#ifndef ARM     
1406        asm(   
1407                                "               lw        $8, memcpy_word_src           \n"
1408                                "               lw        $9, memcpy_word_dest  \n"                             
1409                                "               lw              $10, memcpy_word_anzw   \n"             
1410                                "               addi    $10, $10, -1                                    \n"
1411                                "loop1:                                                                                                 \n"
1412                                "               lw        $11, ($8)                                                     \n"
1413                                "               sw        $11, ($9)                                                     \n"
1414                                "               addi    $8, $8, 4                                                       \n"
1415                                "               addi    $9, $9, 4                                                       \n"
1416                                "               addi    $10, $10, -1                                    \n"
1417                                "               bgez    $10, loop1                                              \n"
1418                        );
1419#endif
1420
1421}
1422
1423void memcpy_byte(char* dest, char* src, long anzb)
1424{
1425        // Folgende Werte m�ssen volatile definiert sein
1426        // char* memcpy_byte_src ---> pointer Quelle
1427        // char* memcpy_byte_dest ---> pointer Ziehl
1428        // long  memcpy_byte_anzb ---> Anzahl bytes die kopiert werden sollen.
1429       
1430        memcpy_byte_src = src;
1431        memcpy_byte_dest = dest;
1432        memcpy_byte_anzb = anzb;
1433       
1434#ifndef ARM     
1435        asm (   
1436                                "               li    $12, 4                                                            \n"
1437                                "               lw        $8, memcpy_byte_src           \n"
1438                                "               lw        $9, memcpy_byte_dest  \n"                             
1439                                "               lw              $10, memcpy_byte_anzb   \n"             
1440                                "word:                                                                                                  \n"
1441                                "               bltu    $10, $12, byte                          \n"
1442                                "               lw        $11, ($8)                                                     \n"
1443                                "               sw        $11, ($9)                                                     \n"
1444                                "               addi    $8, $8, 4                                                       \n"
1445                                "               addi    $9, $9, 4                                                       \n"
1446                                "               addi    $10, $10, -4                                    \n"
1447                                "               b                       word                                                                    \n"
1448                                "byte:                                                                                                  \n"
1449                                "               beqz    $10, end                                                        \n"
1450                                "               lb        $11, ($8)                                                     \n"
1451                                "               sb        $11, ($9)                                                     \n"
1452                                "               addi    $8, $8, 1                                                       \n"
1453                                "               addi    $9, $9, 1                                                       \n"
1454                                "               addi    $10, $10, -1                                    \n"             
1455                                "               b     byte                                                                      \n"
1456                                "end:                                                                                                           \n"
1457                                "               nop                                                                                                     \n"       
1458                        );
1459#endif
1460}
1461
1462
1463void memcpy_area(unsigned char* targetADDR, unsigned char* startADDR, long pxAbs, long hight, long widthAbs, long FBwidthAbs)
1464{
1465
1466#ifndef ARM
1467        asm(   
1468
1469                                "               lw    $t3, %[targetADDR]                                                                                                        \n"
1470                                "               lw    $t4, %[startADDR]                                                                                                 \n"
1471                                "               lw              $t5, %[pxAbs]                                                                                                                   \n"
1472                                "               lw    $t6, %[widthAbs]                                                                                                  \n"
1473                                "               lw    $t7, %[FBwidthAbs]                                                                                                \n"
1474                                "               lw    $t8, %[hight]                                                                                                                     \n"
1475
1476                                "               move  $t0, $t4      # Temp-startADDR                                                    \n" 
1477                                "               move  $t1, $t6      # Temp-widthAbs                                                             \n"
1478                                "               add   $t2, $t5, $t6                                                                                                                             \n"
1479                                "               sub   $t7, $t7, $t2 # Diff withAbs und FBwidthAbs       \n"
1480
1481                                "p3NewLine2:                                                                                                                                                                    \n"             
1482                                "               beqz  $t8, p3End                                                                                                                                        \n"
1483                                "p3NextWord:                                                                                                                                                                    \n"
1484                                "   beqz  $t1, p3NewLine1                                                                                                                       \n"
1485                                "               lw    $t9, ($t0)                                                                                                                                        \n"
1486                                "               sw    $t9, ($t3)                                                                                                                                        \n"
1487                                "               addi  $t0, 4                                                                                                                                                    \n"
1488                                "               addi  $t3, 4                                                                                                                                                    \n"
1489                                "               addi  $t1, -4                                                                                                                                                   \n"
1490                                "               b     p3NextWord                                                                                                                                        \n"
1491
1492               
1493                                "p3NewLine1:                                                                                                                                                                    \n"
1494                                "               move  $t0, $t4                                                                                                                                          \n"
1495                                "               move  $t1, $t6                                                                                                                                          \n"
1496                                "               add   $t3, $t3, $t7                                                                                                                             \n"
1497                                "               add   $t3, $t3, $t5                                                                                                                             \n"
1498                                "               addi  $t8, -1                                                                                                                                                   \n"
1499                                "               b     p3NewLine2                                                                                                                                        \n"
1500
1501                                "p3End:                                                                                                                                                                                         \n"
1502                                "               nop                                                                                                                                                                                             \n"     
1503                                ::[targetADDR] "m" (targetADDR), [startADDR] "m" (startADDR), [pxAbs] "m" (pxAbs), [widthAbs] "m" (widthAbs), [FBwidthAbs] "m" (FBwidthAbs), [hight] "m" (hight)
1504                                );
1505#endif
1506                               
1507        return;
1508}
1509
1510int setfbosddev(char* dev, int value)
1511{
1512        char* tmpstr = NULL;
1513        int ret = 0;
1514
1515        tmpstr = malloc(10);
1516        if(tmpstr == NULL)
1517        {
1518                err("no mem");
1519                return 1;
1520        }
1521       
1522        sprintf(tmpstr, "%x", value);
1523        debug(101, "set %s to %s", dev, tmpstr);
1524
1525        if(dev != NULL)
1526        {
1527                ret = writesys(dev, tmpstr, 1);
1528                return ret;
1529        }
1530
1531        return 0;
1532}
1533
1534char* getfbosddev(char* dev)
1535{
1536        char *value = NULL;
1537
1538        if(dev == NULL)
1539        {
1540                err("NULL detect");
1541                return NULL;
1542        }
1543
1544        value = readsys(dev, 1);
1545        if(value == NULL)
1546        {
1547                err("NULL detect");
1548                return NULL;
1549        }
1550
1551        debug(101, "get %s to %s", dev, value);
1552               
1553        return value;
1554}
1555
1556
1557void setfbosd()
1558{
1559        debug(101, "################## set osd offset ####################");
1560        debug(101, "status.leftoffset: %d", status.leftoffset);
1561        debug(101, "status.rightoffset: %d", status.rightoffset);
1562        debug(101, "status.topoffset: %d", status.topoffset);
1563        debug(101, "status.bottomoffset: %d", status.bottomoffset);
1564       
1565        char* fbleftdev = "/proc/stb/fb/dst_left";
1566        char* fbwidthdev = "/proc/stb/fb/dst_width";
1567        char* fbtopdev = "/proc/stb/fb/dst_top";
1568        char* fbheightdev = "/proc/stb/fb/dst_height";
1569       
1570        int fbleft = strtol(getfbosddev(fbleftdev) , NULL, 16);
1571        int fbwidth = strtol(getfbosddev(fbwidthdev) , NULL, 16);
1572        int fbtop = strtol(getfbosddev(fbtopdev) , NULL, 16);
1573        int fbheight = strtol(getfbosddev(fbheightdev) , NULL, 16);
1574        debug(101, "Setting OSD position: %d %d %d %d", fbleft ,fbwidth ,fbtop ,fbheight);
1575       
1576        fbleft = status.leftoffset;
1577        fbwidth = 720 - status.leftoffset - status.rightoffset;
1578        fbtop = status.topoffset;
1579        fbheight = 576 - status.topoffset - status.bottomoffset;
1580        debug(101, "Setting OSD position changed: %d %d %d %d", fbleft ,fbwidth ,fbtop ,fbheight);
1581        debug(10, "Setting OSD position changed: %d %d %d %d", fbleft ,fbwidth ,fbtop ,fbheight);
1582       
1583        setfbosddev(fbleftdev, fbleft);
1584        setfbosddev(fbwidthdev, fbwidth);
1585        setfbosddev(fbtopdev, fbtop);
1586        setfbosddev(fbheightdev, fbheight);
1587        debug(101, "######################################################");
1588}
1589
1590int setrtctimemips()
1591{
1592        char *rtctimedev = NULL, *tmpstr = NULL;
1593        int ret = 0;
1594//      int value = 0;
1595       
1596        time_t t = time(NULL);
1597        struct tm *local = localtime(&t);
1598        time_t rawlocal = mktime(local);
1599       
1600        t = time(NULL);
1601        struct tm *gmt = gmtime(&t);
1602        time_t rawgmt = mktime(gmt);
1603 
1604        int offset = difftime(rawlocal, rawgmt);
1605
1606        tmpstr = oitoa(offset);
1607        rtctimedev = getconfig("rtctime_offsetdev", NULL);
1608        if(rtctimedev != NULL)
1609                ret = writesys(rtctimedev, tmpstr, 0);
1610        else
1611                ret = writesys("/proc/stb/fp/rtc_offset", tmpstr, 0);
1612        free(tmpstr); tmpstr = NULL;
1613        rtctimedev = NULL;
1614       
1615        if(ret == 0)
1616        {
1617                tmpstr = oitoa(rawlocal);
1618                rtctimedev = getconfig("rtctimedev", NULL);
1619                if(rtctimedev != NULL)
1620                        ret = writesys(rtctimedev, tmpstr, 0);
1621                else
1622                        ret = writesys("/proc/stb/fp/rtc", tmpstr, 0);
1623                free(tmpstr); tmpstr = NULL;
1624                rtctimedev = NULL;
1625        }
1626        return ret;
1627}
1628
1629#endif
Note: See TracBrowser for help on using the repository browser.