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