source: titan/titan/mipselport.h @ 39959

Last change on this file since 39959 was 39789, checked in by gost, 7 years ago

[titan] dm900.. fix Cursor very slowly... I hope... please test

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