source: titan/titan/mipselport.h @ 37142

Last change on this file since 37142 was 37142, checked in by gost, 8 years ago

[titan] mipsel fix animation

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