source: titan/titan/mipselport.h @ 37129

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

[titan] mipsel.. new animations for dm7020

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