source: titan/titan/mipselport.h @ 39656

Last change on this file since 39656 was 39584, checked in by gost, 7 years ago

DM900 workaround Pixel drop outs

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