[dvbapp] increase PR.
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-vuplus / aio-grab / aio-grab / aio-grab_vuplus_6706273e6987e54e4dace15936a2cfd4e8c8c41c.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..c600103 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,BRCM_ARM};
45 +char *stb_name[]={"unknown","Pallas","Vulcan","Xilleon","Brcm7401","Brcm7400","Brcm7405","Brcm7335","Brcm7325","Brcm7346","Brcm7425\/7241","Brcm7362", "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,43 @@ 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),"7362"))
105 +                       stb_type=BRCM7362;
106 +               else if (strstr(upcase(line),"7366"))
107 +                       stb_type=BRCM_ARM;
108 +               else if (strstr(upcase(line),"7376"))
109 +                       stb_type=BRCM_ARM;
110 +               else if (strstr(upcase(line),"7444"))
111 +                       stb_type=BRCM_ARM;
112 +               else if (strstr(upcase(line),"7252"))
113 +                       stb_type=BRCM_ARM;
114 +               else if (strstr(upcase(line),"7260"))
115 +                       stb_type=BRCM_ARM;
116 +#else
117                 line = file_getline("/proc/stb/info/model");
118                 if (line == NULL)
119                         return 1;
120 @@ -221,6 +269,7 @@ int main(int argc, char **argv) {
121                          !strcmp(line, "dm800se") ||
122                          !strcmp(line, "dm7020hd"))
123                         stb_type = BRCM7405;
124 +#endif
125         } else if (strstr(line, "xilleonfb")) {
126                 stb_type = XILLEON;
127         } else if (strstr(line, "Pallas FB")) {
128 @@ -325,9 +374,18 @@ int main(int argc, char **argv) {
129         if (!video_only && !getosd(osd, &xres_o, &yres_o))
130                 return 1;
131  
132 -       // get video
133 -       if (!osd_only && !getvideo(video, &xres_v, &yres_v))
134 -               return 1;
135 +       if (stb_type == BRCM_ARM)
136 +       {
137 +               if (!osd_only && !getvideo2(video, &xres_v, &yres_v))
138 +                       return 1;
139 +       }
140 +       else
141 +       {
142 +               if (!osd_only && !getvideo(video, &xres_v, &yres_v))
143 +                       return 1;
144 +       }
145 +
146 +       
147  
148         // get aspect ratio
149         if (stb_type == VULCAN || stb_type == PALLAS)
150 @@ -549,6 +607,22 @@ int main(int argc, char **argv) {
151  }
152  
153  // grabing the video picture
154 +static bool getvideo2(unsigned char *video, unsigned int *xres, unsigned int *yres)
155 +{
156 +       int fd_video = open("/dev/dvb/adapter0/video0", O_RDONLY);
157 +       if (fd_video < 0) {
158 +               perror("/dev/dvb/adapter0/video0");
159 +               return false;
160 +       }
161 +       
162 +       ssize_t r = read(fd_video, video, 1920 * 1080 * 3);
163 +       close(fd_video);
164 +
165 +       *xres = 1920;
166 +       *yres = 1080;
167 +
168 +       return true;
169 +}
170  
171  static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yres)
172  {
173 @@ -563,16 +637,34 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
174                 perror("/dev/mem");
175                 return false;
176         }
177 -
178 +#if IS_VUPLUS
179 +       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)
180 +#else
181         if (stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405)
182 +#endif
183         {
184                 // grab brcm7401 pic from decoder memory
185 +#if IS_VUPLUS
186 +               off_t offset_addr = 0x10600000;
187 +               switch(stb_type) {
188 +               case BRCM7401:
189 +               case BRCM7400:
190 +               case BRCM7405:
191 +               case BRCM7335:
192 +               case BRCM7325: offset_addr = 0x10100000; break;
193 +               }
194 +               unsigned char *memory = mmap(0, 100, PROT_READ, MAP_SHARED, mem_fd, offset_addr);
195 +               if (memory == MAP_FAILED) {
196 +                       perror("mmap");
197 +                       return false;
198 +               }
199 +#else
200                 unsigned char *memory = mmap(0, 100, PROT_READ, MAP_SHARED, mem_fd, 0x10100000);
201                 if (memory == MAP_FAILED) {
202                         perror("mmap");
203                         return false;
204                 }
205 -
206 +#endif
207                 unsigned char data[100];
208  
209                 unsigned int adr,adr2,ofs,ofs2,offset/*,vert_start,vert_end*/;
210 @@ -582,12 +674,30 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
211                 memcpy(data,memory,100); 
212                 //vert_start=data[0x1B]<<8|data[0x1A];
213                 //vert_end=data[0x19]<<8|data[0x18];
214 +#if IS_VUPLUS
215 +               if(stb_type == BRCM7401 || stb_type == BRCM7400 || stb_type == BRCM7405 || stb_type == BRCM7335 || stb_type == BRCM7325) {
216 +                       stride=data[0x15]<<8|data[0x14];        
217 +                       ofs=(data[0x28]<<8|data[0x27])>>4;
218 +                       ofs2=(data[0x2c]<<8|data[0x2b])>>4;
219 +                       adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
220 +                       adr2=(data[0x23]<<24|data[0x22]<<16|data[0x21]<<8|data[0x20])&0xFFFFFF00;
221 +                       offset=adr2-adr;
222 +               } else {
223 +                       stride=data[0x15]<<8|data[0x14];
224 +                       ofs=(data[0x3c]<<8|data[0x3b])>>4;
225 +                       ofs2=(data[0x40]<<8|data[0x3f])>>4;
226 +                       adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
227 +                       adr2=(data[0x37]<<24|data[0x36]<<16|data[0x35]<<8|data[0x34])&0xFFFFFF00;
228 +                       offset=adr2-adr;
229 +               }
230 +#else
231                 stride=data[0x15]<<8|data[0x14];        
232                 ofs=(data[0x28]<<8|data[0x27])>>4;
233                 ofs2=(data[0x2c]<<8|data[0x2b])>>4;
234                 adr=(data[0x1f]<<24|data[0x1e]<<16|data[0x1d]<<8|data[0x1c])&0xFFFFFF00;
235                 adr2=(data[0x23]<<24|data[0x22]<<16|data[0x21]<<8|data[0x20])&0xFFFFFF00;
236                 offset=adr2-adr;
237 +#endif
238                 
239                 munmap(memory, 100);
240  
241 @@ -609,7 +719,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
242                 assert(chroma);
243  
244                 // grabbing luma & chroma plane from the decoder memory
245 +#if IS_VUPLUS
246 +               if (stb_type == BRCM7401 || stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425 || stb_type == BRCM7362 ) {
247 +#else
248                 if (stb_type == BRCM7401 || stb_type == BRCM7405) {
249 +#endif
250                         // on dm800/dm500hd we have direct access to the decoder memory
251                         memory = mmap(0, offset + stride*(ofs2+64), PROT_READ, MAP_SHARED, mem_fd, adr);
252                         if (memory == MAP_FAILED) {
253 @@ -620,7 +734,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
254                         usleep(50000);  // we try to get a full picture, its not possible to get a sync from the decoder so we use a delay
255                                         // and hope we get a good timing. dont ask me why, but every DM800 i tested so far produced a good
256                                         // result with a 50ms delay
257 +#if IS_VUPLUS
258 +               } else if (stb_type == BRCM7400 || stb_type == BRCM7335) {
259 +#else
260                 } else if (stb_type == BRCM7400) { 
261 +#endif
262                         // on dm8000 we have to use dma, so dont change anything here until you really know what you are doing !
263                         
264                         unsigned int i = 0;
265 @@ -639,7 +757,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
266                         }
267  
268                         volatile unsigned long *mem_dma;
269 +#if IS_VUPLUS
270 +                       mem_dma = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, (stb_type==BRCM7400)?0x10c02000:0x10c01000);
271 +#else
272                         mem_dma = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0x10c02000);
273 +#endif
274                         if (mem_dma == MAP_FAILED) {
275                                 perror("mmap");
276                                 return false;
277 @@ -675,8 +797,11 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
278                 unsigned int t = 0, t2 = 0, dat1 = 0;
279                 unsigned int chr_luma_stride = 0x40;
280                 unsigned int sw;
281 -
282 +#if IS_VUPLUS
283 +               if (stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425)
284 +#else
285                 if (stb_type == BRCM7405)
286 +#endif
287                         chr_luma_stride *= 2;
288  
289                 xsub=chr_luma_stride;
290 @@ -692,6 +817,7 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
291                         for (ytmp = 0; ytmp < ofs; ytmp++) 
292                         {
293                                 memcpy(luma + dat1, memory + t, xsub); // luma
294 +                               
295                                 t += chr_luma_stride;
296  
297                                 switch (ofs2-ytmp) // the two switch commands are much faster than one if statement
298 @@ -710,10 +836,17 @@ static bool getvideo(unsigned char *video, unsigned int *xres, unsigned int *yre
299                                 dat1+=stride;
300                         }
301                 }
302 -
303 +#if IS_VUPLUS
304 +               if (stb_type == BRCM7401 || stb_type == BRCM7405 || stb_type == BRCM7325 || stb_type == BRCM7346 || stb_type == BRCM7425 || stb_type == BRCM7362) {
305 +#else
306                 if (stb_type == BRCM7401 || stb_type == BRCM7405)
307 +#endif
308                         munmap(memory, offset + stride * (ofs2 + 64));
309 +#if IS_VUPLUS
310 +               } else if (stb_type == BRCM7400 || stb_type == BRCM7335) {
311 +#else
312                 else if (stb_type == BRCM7400) {
313 +#endif
314                         memory -= 0x1000;
315                         munmap(memory, DMA_BLOCKSIZE + 0x1000);
316                 }