update packages.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-vuplus / aio-grab / aio-grab / aio-grab_vuplus_8394e1ba98c73d7c56d3235ef16cce253dc597cd.patch
1 diff --git a/.gitignore b/.gitignore
2 index ccfb515..a6f8d11 100644
3 --- a/.gitignore
4 +++ b/.gitignore
5 @@ -16,3 +16,4 @@ install-sh
6  *.o
7  missing
8  stamp-h1
9 +aio-grab_vuplus_*
10 diff --git a/main.c b/main.c
11 index 190ff5f..c611913 100644
12 --- a/main.c
13 +++ b/main.c
14 @@ -38,6 +38,7 @@ Feel free to use the code for your own projects. See LICENSE file for details.
15  #include <sys/stat.h>
16  #include <sys/types.h>
17  #include <unistd.h>
18 +#include <ctype.h>
19  
20  #include <linux/fb.h>
21  
22 @@ -101,10 +102,24 @@ static void combine(unsigned char *output,
23                     const unsigned char *video, const unsigned char *osd,
24                     unsigned int xres, unsigned int yres);
25  
26 +#define IS_VUPLUS 1
27 +#if IS_VUPLUS
28 +enum {UNKNOWN,PALLAS,VULCAN,XILLEON,BRCM7401,BRCM7400,BRCM7405,BRCM7335,BRCM7325,BRCM7346,BRCM7425};
29 +char *stb_name[]={"unknown","Pallas","Vulcan","Xilleon","Brcm7401","Brcm7400","Brcm7405","Brcm7335","Brcm7325","Brcm7346","Brcm7425"};
30 +#else
31  enum {UNKNOWN,PALLAS,VULCAN,XILLEON,BRCM7401,BRCM7400,BRCM7405};
32  static const char *stb_name[]={"unknown","Pallas","Vulcan","Xilleon","Brcm7401","Brcm7400","Brcm7405"};
33 +#endif
34  static int stb_type=UNKNOWN;
35  
36 +char* upcase(char* mixedstr)
37 +{
38 +       size_t j;
39 +       for (j=0; j< strlen(mixedstr); ++j)
40 +               mixedstr[j]=toupper(mixedstr[j]);
41 +       return mixedstr;
42 +}
43 +
44  static const char *file_getline(const char *filename)
45  {
46         static char *line = NULL;
47 @@ -184,7 +199,6 @@ static int file_scanf_lines(const char *filename, const char *fmt, ...)
48  }
49  
50  // main program
51 -
52  int main(int argc, char **argv) {
53  
54         printf("AiO Dreambox Screengrabber " PACKAGE_VERSION "\n\n");
55 @@ -205,11 +219,29 @@ int main(int argc, char **argv) {
56         char filename[256] = { "/tmp/screenshot.bmp" };
57  
58         // detect STB
59 -       const char *line = file_getline("/proc/fb");
60 +       char *line = (char*)file_getline("/proc/fb");
61         if (line == NULL)
62                 return 1;
63  
64         if (strstr(line, "bcmfb")) {
65 +#if IS_VUPLUS
66 +               if((line=(char*)file_getline("/proc/stb/info/chipset")) == NULL)
67 +                       return 1;
68 +               if (strstr(upcase(line),"7335"))
69 +                       stb_type=BRCM7335;
70 +               else if (strstr(upcase(line),"7325"))
71 +                       stb_type=BRCM7325;
72 +               else if (strstr(upcase(line),"7405"))
73 +                       stb_type=BRCM7405;
74 +               else if (strstr(upcase(line),"7356"))
75 +                       stb_type=BRCM7346;
76 +               else if (strstr(upcase(line),"7346"))
77 +                       stb_type=BRCM7346;
78 +               else if (strstr(upcase(line),"7424"))
79 +                       stb_type=BRCM7425;
80 +               else if (strstr(upcase(line),"7425"))
81 +                       stb_type=BRCM7425;
82 +#else
83                 line = file_getline("/proc/stb/info/model");
84                 if (line == NULL)
85                         return 1;
86 @@ -221,6 +253,7 @@ int main(int argc, char **argv) {
87                          !strcmp(line, "dm800se") ||
88                          !strcmp(line, "dm7020hd"))
89                         stb_type = BRCM7405;
90 +#endif
91         } else if (strstr(line, "xilleonfb")) {
92                 stb_type = XILLEON;
93         } else if (strstr(line, "Pallas FB")) {
94 @@ -563,16 +596,34 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
95                 perror("/dev/mem");
96                 return false;
97         }
98 -
99 +#if IS_VUPLUS
100 +       if (stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405 || stb_type == BRCM7335 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425)
101 +#else
102         if (stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405)
103 +#endif
104         {
105                 // grab brcm7401 pic from decoder memory
106 +#if IS_VUPLUS
107 +               off_t offset_addr = 0x10600000;
108 +               switch(stb_type) {
109 +               case BRCM7401:
110 +               case BRCM7400:
111 +               case BRCM7405:
112 +               case BRCM7335:
113 +               case BRCM7325: offset_addr = 0x10100000; break;
114 +               }
115 +               unsigned char *memory = mmap(0, 100, PROT_READ, MAP_SHARED, mem_fd, offset_addr);
116 +               if (memory == MAP_FAILED) {
117 +                       perror("mmap");
118 +                       return false;
119 +               }
120 +#else
121                 unsigned char *memory = mmap(0, 100, PROT_READ, MAP_SHARED, mem_fd, 0x10100000);
122                 if (memory == MAP_FAILED) {
123                         perror("mmap");
124                         return false;
125                 }
126 -
127 +#endif
128                 unsigned char data[100];
129  
130                 unsigned int adr,adr2,ofs,ofs2,offset/*,vert_start,vert_end*/;
131 @@ -582,12 +633,30 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
132                 memcpy(data,memory,100); 
133                 //vert_start=data[0x1B]<<8|data[0x1A];
134                 //vert_end=data[0x19]<<8|data[0x18];
135 +#if IS_VUPLUS
136 +               if(stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405 || stb_type == BRCM7335 || stb_type == BRCM7325) {
137 +                       stride=data[0x15]<<8|data[0x14];        
138 +                       ofs=(data[0x28]<<8|data[0x27])>>4;
139 +                       ofs2=(data[0x2c]<<8|data[0x2b])>>4;
140 +                       adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
141 +                       adr2=(data[0x23]<<24|data[0x22]<<16|data[0x21]<<8|data[0x20])&0xFFFFFF00;
142 +                       offset=adr2-adr;
143 +               } else {
144 +                       stride=data[0x15]<<8|data[0x14];
145 +                       ofs=(data[0x3c]<<8|data[0x3b])>>4;
146 +                       ofs2=(data[0x40]<<8|data[0x3f])>>4;
147 +                       adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
148 +                       adr2=(data[0x37]<<24|data[0x36]<<16|data[0x35]<<8|data[0x34])&0xFFFFFF00;
149 +                       offset=adr2-adr;
150 +               }
151 +#else
152                 stride=data[0x15]<<8|data[0x14];        
153                 ofs=(data[0x28]<<8|data[0x27])>>4;
154                 ofs2=(data[0x2c]<<8|data[0x2b])>>4;
155                 adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
156                 adr2=(data[0x23]<<24|data[0x22]<<16|data[0x21]<<8|data[0x20])&0xFFFFFF00;
157                 offset=adr2-adr;
158 +#endif
159                 
160                 munmap(memory, 100);
161  
162 @@ -609,7 +678,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
163                 assert(chroma);
164  
165                 // grabbing luma & chroma plane from the decoder memory
166 +#if IS_VUPLUS
167 +               if (stb_type == BRCM7401 || stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425) {
168 +#else
169                 if (stb_type == BRCM7401 || stb_type == BRCM7405) {
170 +#endif
171                         // on dm800/dm500hd we have direct access to the decoder memory
172                         memory = mmap(0, offset + stride*(ofs2+64), PROT_READ, MAP_SHARED, mem_fd, adr);
173                         if (memory == MAP_FAILED) {
174 @@ -620,7 +693,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
175                         usleep(50000);  // we try to get a full picture, its not possible to get a sync from the decoder so we use a delay
176                                         // and hope we get a good timing. dont ask me why, but every DM800 i tested so far produced a good
177                                         // result with a 50ms delay
178 +#if IS_VUPLUS
179 +               } else if (stb_type == BRCM7400 || stb_type == BRCM7335) {
180 +#else
181                 } else if (stb_type == BRCM7400) { 
182 +#endif
183                         // on dm8000 we have to use dma, so dont change anything here until you really know what you are doing !
184                         
185                         unsigned int i = 0;
186 @@ -639,7 +716,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
187                         }
188  
189                         volatile unsigned long *mem_dma;
190 +#if IS_VUPLUS
191 +                       mem_dma = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, (stb_type==BRCM7400)?0x10c02000:0x10c01000);
192 +#else
193                         mem_dma = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0x10c02000);
194 +#endif
195                         if (mem_dma == MAP_FAILED) {
196                                 perror("mmap");
197                                 return false;
198 @@ -675,8 +756,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
199                 unsigned int t = 0, t2 = 0, dat1 = 0;
200                 unsigned int chr_luma_stride = 0x40;
201                 unsigned int sw;
202 -
203 +#if IS_VUPLUS
204 +               if (stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425)
205 +#else
206                 if (stb_type == BRCM7405)
207 +#endif
208                         chr_luma_stride *= 2;
209  
210                 xsub=chr_luma_stride;
211 @@ -710,10 +794,17 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
212                                 dat1+=stride;
213                         }
214                 }
215 -
216 +#if IS_VUPLUS
217 +               if (stb_type == BRCM7401 || stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425) {
218 +#else
219                 if (stb_type == BRCM7401 || stb_type == BRCM7405)
220 +#endif
221                         munmap(memory, offset + stride * (ofs2 + 64));
222 +#if IS_VUPLUS
223 +               } else if (stb_type == BRCM7400 || stb_type == BRCM7335) {
224 +#else
225                 else if (stb_type == BRCM7400) {
226 +#endif
227                         memory -= 0x1000;
228                         munmap(memory, DMA_BLOCKSIZE + 0x1000);
229                 }