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