[aio-grab] support new LNB chip.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-vuplus / aio-grab / aio-grab / aio-grab_vuplus_22f13d68e322e0609f457282ed5bf19376397f29.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..c6cb750 100644
12 --- a/main.c
13 +++ b/main.c
14 @@ -1,5 +1,5 @@
15  /*
16 -AiO Dreambox Screengrabber v0.83a
17 +AiO Screengrabber v0.83a
18  
19  written 2006 - 2009 by Seddi
20  Contact: seddi@ihad.tv / http://www.ihad.tv
21 @@ -38,6 +38,7 @@ Feel free to use the code for your own projects. See LICENSE file for details.
22  #include <sys/stat.h>
23  #include <sys/types.h>
24  #include <unistd.h>
25 +#include <ctype.h>
26  
27  #include <linux/fb.h>
28  
29 @@ -80,6 +81,8 @@ static const int yuv2rgbtable_bv[256] = {
30  };
31  
32  static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yres);
33 +static bool getvideo2(unsigned char *video, unsigned int *xres, unsigned int *yres);
34 +
35  static bool getosd(unsigned char *osd, unsigned int *xres, unsigned int *yres);
36  
37  static void smooth_resize(const unsigned char *source, unsigned char *dest,
38 @@ -101,10 +104,24 @@ static void combine(unsigned char *output,
39                     const unsigned char *video, const unsigned char *osd,
40                     unsigned int xres, unsigned int yres);
41  
42 +#define IS_VUPLUS 1
43 +#if IS_VUPLUS
44 +enum {UNKNOWN,PALLAS,VULCAN,XILLEON,BRCM7401,BRCM7400,BRCM7405,BRCM7335,BRCM7325,BRCM7346,BRCM7425,BRCM7362,BRCM73625,BRCM_ARM};
45 +char *stb_name[]={"unknown","Pallas","Vulcan","Xilleon","Brcm7401","Brcm7400","Brcm7405","Brcm7335","Brcm7325","Brcm7346","Brcm7425\/7241","Brcm7362", "Brcm73625", "Brcm_ARM"};
46 +#else
47  enum {UNKNOWN,PALLAS,VULCAN,XILLEON,BRCM7401,BRCM7400,BRCM7405};
48  static const char *stb_name[]={"unknown","Pallas","Vulcan","Xilleon","Brcm7401","Brcm7400","Brcm7405"};
49 +#endif
50  static int stb_type=UNKNOWN;
51  
52 +char* upcase(char* mixedstr)
53 +{
54 +       size_t j;
55 +       for (j=0; j< strlen(mixedstr); ++j)
56 +               mixedstr[j]=toupper(mixedstr[j]);
57 +       return mixedstr;
58 +}
59 +
60  static const char *file_getline(const char *filename)
61  {
62         static char *line = NULL;
63 @@ -184,10 +201,9 @@ static int file_scanf_lines(const char *filename, const char *fmt, ...)
64  }
65  
66  // main program
67 -
68  int main(int argc, char **argv) {
69  
70 -       printf("AiO Dreambox Screengrabber " PACKAGE_VERSION "\n\n");
71 +       printf("AiO Screengrabber " PACKAGE_VERSION "\n\n");
72  
73         unsigned int xres_v = 0,yres_v = 0,xres_o,yres_o,xres,yres,aspect,width;
74         int c,osd_only,video_only,use_osd_res,use_png,use_jpg,jpg_quality,no_aspect,use_letterbox;
75 @@ -205,11 +221,47 @@ int main(int argc, char **argv) {
76         char filename[256] = { "/tmp/screenshot.bmp" };
77  
78         // detect STB
79 -       const char *line = file_getline("/proc/fb");
80 +       char *line = (char*)file_getline("/proc/fb");
81         if (line == NULL)
82                 return 1;
83  
84         if (strstr(line, "bcmfb")) {
85 +#if IS_VUPLUS
86 +               if((line=(char*)file_getline("/proc/stb/info/chipset")) == NULL)
87 +                       return 1;
88 +               if (strstr(upcase(line),"7335"))
89 +                       stb_type=BRCM7335;
90 +               else if (strstr(upcase(line),"7325"))
91 +                       stb_type=BRCM7325;
92 +               else if (strstr(upcase(line),"7405"))
93 +                       stb_type=BRCM7405;
94 +               else if (strstr(upcase(line),"7356"))
95 +                       stb_type=BRCM7346;
96 +               else if (strstr(upcase(line),"7346"))
97 +                       stb_type=BRCM7346;
98 +               else if (strstr(upcase(line),"7424"))
99 +                       stb_type=BRCM7425;
100 +               else if (strstr(upcase(line),"7425"))
101 +                       stb_type=BRCM7425;
102 +               else if (strstr(upcase(line),"7241"))
103 +                       stb_type=BRCM7425;
104 +               else if (strstr(upcase(line),"73625"))
105 +                       stb_type=BRCM73625;
106 +               else if (strstr(upcase(line),"7362"))
107 +                       stb_type=BRCM7362;
108 +               else if (strstr(upcase(line),"7366"))
109 +                       stb_type=BRCM_ARM;
110 +               else if (strstr(upcase(line),"7376"))
111 +                       stb_type=BRCM_ARM;
112 +               else if (strstr(upcase(line),"7444"))
113 +                       stb_type=BRCM_ARM;
114 +               else if (strstr(upcase(line),"7252"))
115 +                       stb_type=BRCM_ARM;
116 +               else if (strstr(upcase(line),"7260"))
117 +                       stb_type=BRCM_ARM;
118 +               else if (strstr(upcase(line),"7278"))
119 +                       stb_type=BRCM_ARM;
120 +#else
121                 line = file_getline("/proc/stb/info/model");
122                 if (line == NULL)
123                         return 1;
124 @@ -221,6 +273,7 @@ int main(int argc, char **argv) {
125                          !strcmp(line, "dm800se") ||
126                          !strcmp(line, "dm7020hd"))
127                         stb_type = BRCM7405;
128 +#endif
129         } else if (strstr(line, "xilleonfb")) {
130                 stb_type = XILLEON;
131         } else if (strstr(line, "Pallas FB")) {
132 @@ -325,9 +378,18 @@ int main(int argc, char **argv) {
133         if (!video_only && !getosd(osd, &xres_o, &yres_o))
134                 return 1;
135  
136 -       // get video
137 -       if (!osd_only && !getvideo(video, &xres_v, &yres_v))
138 -               return 1;
139 +       if (stb_type == BRCM_ARM)
140 +       {
141 +               if (!osd_only && !getvideo2(video, &xres_v, &yres_v))
142 +                       return 1;
143 +       }
144 +       else
145 +       {
146 +               if (!osd_only && !getvideo(video, &xres_v, &yres_v))
147 +                       return 1;
148 +       }
149 +
150 +       
151  
152         // get aspect ratio
153         if (stb_type == VULCAN || stb_type == PALLAS)
154 @@ -549,6 +611,22 @@ int main(int argc, char **argv) {
155  }
156  
157  // grabing the video picture
158 +static bool getvideo2(unsigned char *video, unsigned int *xres, unsigned int *yres)
159 +{
160 +       int fd_video = open("/dev/dvb/adapter0/video0", O_RDONLY);
161 +       if (fd_video < 0) {
162 +               perror("/dev/dvb/adapter0/video0");
163 +               return false;
164 +       }
165 +       
166 +       ssize_t r = read(fd_video, video, 1920 * 1080 * 3);
167 +       close(fd_video);
168 +
169 +       *xres = 1920;
170 +       *yres = 1080;
171 +
172 +       return true;
173 +}
174  
175  static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yres)
176  {
177 @@ -563,16 +641,34 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
178                 perror("/dev/mem");
179                 return false;
180         }
181 -
182 +#if IS_VUPLUS
183 +       if (stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405 || stb_type == BRCM7335 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425 || stb_type == BRCM7362 || stb_type == BRCM73625)
184 +#else
185         if (stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405)
186 +#endif
187         {
188                 // grab brcm7401 pic from decoder memory
189 +#if IS_VUPLUS
190 +               off_t offset_addr = 0x10600000;
191 +               switch(stb_type) {
192 +               case BRCM7401:
193 +               case BRCM7400:
194 +               case BRCM7405:
195 +               case BRCM7335:
196 +               case BRCM7325: offset_addr = 0x10100000; break;
197 +               }
198 +               unsigned char *memory = mmap(0, 100, PROT_READ, MAP_SHARED, mem_fd, offset_addr);
199 +               if (memory == MAP_FAILED) {
200 +                       perror("mmap");
201 +                       return false;
202 +               }
203 +#else
204                 unsigned char *memory = mmap(0, 100, PROT_READ, MAP_SHARED, mem_fd, 0x10100000);
205                 if (memory == MAP_FAILED) {
206                         perror("mmap");
207                         return false;
208                 }
209 -
210 +#endif
211                 unsigned char data[100];
212  
213                 unsigned int adr,adr2,ofs,ofs2,offset/*,vert_start,vert_end*/;
214 @@ -582,12 +678,37 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
215                 memcpy(data,memory,100); 
216                 //vert_start=data[0x1B]<<8|data[0x1A];
217                 //vert_end=data[0x19]<<8|data[0x18];
218 +#if IS_VUPLUS
219 +               if(stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405 || stb_type == BRCM7335 || stb_type == BRCM7325) {
220 +                       stride=data[0x15]<<8|data[0x14];        
221 +                       ofs=(data[0x28]<<8|data[0x27])>>4;
222 +                       ofs2=(data[0x2c]<<8|data[0x2b])>>4;
223 +                       adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
224 +                       adr2=(data[0x23]<<24|data[0x22]<<16|data[0x21]<<8|data[0x20])&0xFFFFFF00;
225 +                       offset=adr2-adr;
226 +               } else if(stb_type == BRCM73625) {
227 +                       stride=data[0x19]<<8|data[0x18];        
228 +                       ofs=(data[0x54]<<8|data[0x53])>>4;
229 +                       ofs2=(data[0x58]<<8|data[0x57])>>4;
230 +                       adr=(data[0x37]<<24|data[0x36]<<16|data[0x35]<<8|data[0x34])&0xFFFFFF00;
231 +                       adr2=(data[0x3f]<<24|data[0x3e]<<16|data[0x3d]<<8|data[0x3c])&0xFFFFFF00;
232 +                       offset=adr2-adr;
233 +               } else {
234 +                       stride=data[0x15]<<8|data[0x14];
235 +                       ofs=(data[0x3c]<<8|data[0x3b])>>4;
236 +                       ofs2=(data[0x40]<<8|data[0x3f])>>4;
237 +                       adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
238 +                       adr2=(data[0x37]<<24|data[0x36]<<16|data[0x35]<<8|data[0x34])&0xFFFFFF00;
239 +                       offset=adr2-adr;
240 +               }
241 +#else
242                 stride=data[0x15]<<8|data[0x14];        
243                 ofs=(data[0x28]<<8|data[0x27])>>4;
244                 ofs2=(data[0x2c]<<8|data[0x2b])>>4;
245                 adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
246                 adr2=(data[0x23]<<24|data[0x22]<<16|data[0x21]<<8|data[0x20])&0xFFFFFF00;
247                 offset=adr2-adr;
248 +#endif
249                 
250                 munmap(memory, 100);
251  
252 @@ -609,7 +730,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
253                 assert(chroma);
254  
255                 // grabbing luma & chroma plane from the decoder memory
256 +#if IS_VUPLUS
257 +               if (stb_type == BRCM7401 || stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425 || stb_type == BRCM7362 || stb_type == BRCM73625) {
258 +#else
259                 if (stb_type == BRCM7401 || stb_type == BRCM7405) {
260 +#endif
261                         // on dm800/dm500hd we have direct access to the decoder memory
262                         memory = mmap(0, offset + stride*(ofs2+64), PROT_READ, MAP_SHARED, mem_fd, adr);
263                         if (memory == MAP_FAILED) {
264 @@ -620,7 +745,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
265                         usleep(50000);  // we try to get a full picture, its not possible to get a sync from the decoder so we use a delay
266                                         // and hope we get a good timing. dont ask me why, but every DM800 i tested so far produced a good
267                                         // result with a 50ms delay
268 +#if IS_VUPLUS
269 +               } else if (stb_type == BRCM7400 || stb_type == BRCM7335) {
270 +#else
271                 } else if (stb_type == BRCM7400) { 
272 +#endif
273                         // on dm8000 we have to use dma, so dont change anything here until you really know what you are doing !
274                         
275                         unsigned int i = 0;
276 @@ -639,7 +768,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
277                         }
278  
279                         volatile unsigned long *mem_dma;
280 +#if IS_VUPLUS
281 +                       mem_dma = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, (stb_type==BRCM7400)?0x10c02000:0x10c01000);
282 +#else
283                         mem_dma = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0x10c02000);
284 +#endif
285                         if (mem_dma == MAP_FAILED) {
286                                 perror("mmap");
287                                 return false;
288 @@ -675,8 +808,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
289                 unsigned int t = 0, t2 = 0, dat1 = 0;
290                 unsigned int chr_luma_stride = 0x40;
291                 unsigned int sw;
292 -
293 +#if IS_VUPLUS
294 +               if (stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425)
295 +#else
296                 if (stb_type == BRCM7405)
297 +#endif
298                         chr_luma_stride *= 2;
299  
300                 xsub=chr_luma_stride;
301 @@ -692,6 +828,7 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
302                         for (ytmp = 0; ytmp < ofs; ytmp++) 
303                         {
304                                 memcpy(luma + dat1, memory + t, xsub); // luma
305 +                               
306                                 t += chr_luma_stride;
307  
308                                 switch (ofs2-ytmp) // the two switch commands are much faster than one if statement
309 @@ -710,10 +847,17 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
310                                 dat1+=stride;
311                         }
312                 }
313 -
314 +#if IS_VUPLUS
315 +               if (stb_type == BRCM7401 || stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425 || stb_type == BRCM7362 || stb_type == BRCM73625) {
316 +#else
317                 if (stb_type == BRCM7401 || stb_type == BRCM7405)
318 +#endif
319                         munmap(memory, offset + stride * (ofs2 + 64));
320 +#if IS_VUPLUS
321 +               } else if (stb_type == BRCM7400 || stb_type == BRCM7335) {
322 +#else
323                 else if (stb_type == BRCM7400) {
324 +#endif
325                         memory -= 0x1000;
326                         munmap(memory, DMA_BLOCKSIZE + 0x1000);
327                 }