source: titan/titan/mipselport.h @ 37119

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

[titan] mipsel.. new animations

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