1
|
1
|
|
2 // How many MegaBytes of RAM is on your G200/G400 card?
|
|
3 #define RAM_SIZE 16
|
|
4
|
|
5 /*
|
|
6 * video_out_syncfb.c
|
|
7 *
|
|
8 * Copyright (C) Aaron Holtzman - Aug 1999
|
|
9 *
|
|
10 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
11 *
|
|
12 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
13 * it under the terms of the GNU General Public License as published by
|
|
14 * the Free Software Foundation; either version 2, or (at your option)
|
|
15 * any later version.
|
|
16 *
|
|
17 * mpeg2dec is distributed in the hope that it will be useful,
|
|
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 * GNU General Public License for more details.
|
|
21 *
|
|
22 * You should have received a copy of the GNU General Public License
|
|
23 * along with GNU Make; see the file COPYING. If not, write to
|
|
24 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
25 *
|
|
26 */
|
|
27
|
|
28 #include <stdio.h>
|
|
29 #include <stdlib.h>
|
|
30 #include <string.h>
|
|
31
|
|
32 #include "config.h"
|
|
33 #include "video_out.h"
|
|
34 #include "video_out_internal.h"
|
|
35
|
|
36 LIBVO_EXTERN(syncfb)
|
|
37
|
|
38 #include <sys/ioctl.h>
|
|
39 #include <unistd.h>
|
|
40 #include <fcntl.h>
|
|
41 #include <sys/mman.h>
|
|
42 #include <linux/videodev.h>
|
|
43
|
|
44 #include "drivers/syncfb/syncfb.h"
|
|
45
|
|
46 static vo_info_t vo_info =
|
|
47 {
|
|
48 "Matrox G200/G400 Synchronous framebuffer (/dev/syncfb)",
|
|
49 "syncfb",
|
|
50 "Matthias Oelmann <mao@well.com>",
|
|
51 ""
|
|
52 };
|
|
53
|
|
54 /* deinterlacing on? looks only good in 50 Hz(PAL) or 60 Hz(NTSC) modes */
|
|
55 static int vo_conf_deinterlace = 0;
|
|
56
|
|
57 /* 72/75 Hz Monitor frequency for progressive output */
|
|
58 static int vo_conf_cinemode = 0;
|
|
59
|
|
60
|
|
61 static syncfb_config_t config;
|
|
62 static syncfb_capability_t sfb_caps;
|
|
63
|
|
64 static syncfb_buffer_info_t bufinfo;
|
|
65
|
|
66 static uint_8 *vid_data;
|
|
67 static uint_8 *frame_mem;
|
|
68
|
|
69 static int debug_skip_first = 250;
|
|
70 static int dbg_singleframe = 0;
|
|
71
|
|
72 static int conf_palette;
|
|
73
|
|
74 static int f;
|
|
75
|
|
76
|
|
77
|
|
78 /*
|
|
79 it seems that mpeg2dec never calls
|
|
80 draw_frame, so i could not test it....
|
|
81 */
|
|
82
|
|
83 static void
|
|
84 write_frame_YUV422(uint_8 *y,uint_8 *cr, uint_8 *cb)
|
|
85 {
|
|
86 uint_8 *crp, *cbp;
|
|
87 uint_32 *dest32;
|
|
88 uint_32 bespitch,h,w;
|
|
89
|
|
90
|
|
91 bespitch = config.src_pitch;
|
|
92 dest32 = (uint_32 *)vid_data;
|
|
93
|
|
94 for(h=0; h < config.src_height/2; h++)
|
|
95 {
|
|
96 cbp = cb;
|
|
97 crp = cr;
|
|
98 for(w=0; w < config.src_width/2; w++)
|
|
99 {
|
|
100 *dest32++ = (*y) + ((*cr)<<8) + ((*(y+1))<<16) + ((*cb)<<24);
|
|
101 y++; y++; cb++; cr++;
|
|
102 }
|
|
103 dest32 += (bespitch - config.src_width) / 2;
|
|
104
|
|
105 for(w=0; w < config.src_width/2; w++)
|
|
106 {
|
|
107 *dest32++ = (*y) + ((*crp)<<8) + ((*(y+1))<<16) + ((*cbp)<<24);
|
|
108 y++; y++; cbp++; crp++;
|
|
109 }
|
|
110 dest32 += (bespitch - config.src_width) / 2;
|
|
111 }
|
|
112 }
|
|
113
|
|
114
|
|
115 static void
|
|
116 write_frame_YUV420P2(uint_8 *y,uint_8 *cr, uint_8 *cb)
|
|
117 {
|
|
118 uint_8 *dest, *tmp;
|
|
119 uint_32 bespitch,h,w;
|
|
120
|
|
121 bespitch = config.src_pitch;
|
|
122 dest = frame_mem + bufinfo.offset;
|
|
123
|
|
124 for(h=0; h < config.src_height; h++)
|
|
125 {
|
|
126 memcpy(dest, y, config.src_width);
|
|
127 y += config.src_width;
|
|
128 dest += bespitch;
|
|
129 }
|
|
130
|
|
131 dest = frame_mem + bufinfo.offset_p2;
|
|
132 for(h=0; h < config.src_height/2; h++)
|
|
133 {
|
|
134 tmp = dest;
|
|
135 for(w=0; w < config.src_width/2; w++)
|
|
136 {
|
|
137 *tmp++ = *cr++;
|
|
138 *tmp++ = *cb++;
|
|
139 }
|
|
140 dest += bespitch;
|
|
141 }
|
|
142 }
|
|
143
|
|
144 static void
|
|
145 write_frame_YUV420P3(uint_8 *y,uint_8 *cr, uint_8 *cb)
|
|
146 {
|
|
147 }
|
|
148
|
|
149 static void
|
|
150 write_slice_YUV420P2(uint_8 *y,uint_8 *cr, uint_8 *cb,uint_32 slice_num)
|
|
151 {
|
|
152 uint_8 *dest, *tmp;
|
|
153 uint_32 bespitch,h,w;
|
|
154
|
|
155 bespitch = config.src_pitch;
|
|
156 dest = frame_mem + bufinfo.offset + (bespitch * 16 * slice_num);
|
|
157
|
|
158 for(h=0; h < 16; h++)
|
|
159 {
|
|
160 memcpy(dest, y, config.src_width);
|
|
161 y += config.src_width;
|
|
162 dest += bespitch;
|
|
163 }
|
|
164
|
|
165 dest = frame_mem + bufinfo.offset_p2 + (bespitch * 16 * slice_num) /2;
|
|
166 for(h=0; h < 8; h++)
|
|
167 {
|
|
168 tmp = dest;
|
|
169 for(w=0; w < config.src_width/2; w++)
|
|
170 {
|
|
171 *tmp++ = *cr++;
|
|
172 *tmp++ = *cb++;
|
|
173 }
|
|
174 dest += bespitch;
|
|
175 }
|
|
176 }
|
|
177
|
|
178 static void
|
|
179 write_slice_YUV420P3(uint_8 *y,uint_8 *cr, uint_8 *cb,int stride[],uint_32 ypos,uint_32 xsize,uint_32 ysize)
|
|
180 {
|
|
181 uint_8 *dest;
|
|
182 uint_32 bespitch,h;
|
|
183
|
|
184 bespitch = config.src_pitch;
|
|
185
|
|
186 dest = frame_mem + bufinfo.offset + (bespitch * ypos);
|
|
187 for(h=0; h < ysize; h++)
|
|
188 {
|
|
189 memcpy(dest, y, xsize);
|
|
190 y += stride[0];
|
|
191 dest += bespitch;
|
|
192 }
|
|
193
|
|
194 xsize/=2;
|
|
195 ysize/=2;
|
|
196
|
|
197 dest = frame_mem + bufinfo.offset_p2 + (bespitch * ypos)/4;
|
|
198 for(h=0; h < ysize; h++)
|
|
199 {
|
|
200 memcpy(dest, cr, xsize);
|
|
201 cr += stride[1];
|
|
202 dest += bespitch/2;
|
|
203 }
|
|
204
|
|
205 dest = frame_mem + bufinfo.offset_p3 + (bespitch * ypos)/4;
|
|
206 for(h=0; h < ysize; h++)
|
|
207 {
|
|
208 memcpy(dest, cb, xsize);
|
|
209 cb += stride[2];
|
|
210 dest += bespitch/2;
|
|
211 }
|
|
212
|
|
213
|
|
214 }
|
|
215
|
|
216
|
|
217 static void
|
|
218 write_slice_YUV422(uint_8 *y,uint_8 *cr, uint_8 *cb,uint_32 slice_num)
|
|
219 {
|
|
220 uint_8 *crp, *cbp;
|
|
221 uint_32 *dest32;
|
|
222 uint_32 bespitch,h,w;
|
|
223
|
|
224
|
|
225 bespitch = config.src_pitch;
|
|
226 dest32 = (uint_32 *)(vid_data + (bespitch * 16 * slice_num) * 2);
|
|
227
|
|
228 for(h=0; h < 8; h++)
|
|
229 {
|
|
230 cbp = cb;
|
|
231 crp = cr;
|
|
232 for(w=0; w < config.src_width/2; w++)
|
|
233 {
|
|
234 *dest32++ = (*y) + ((*cr)<<8) + ((*(y+1))<<16) + ((*cb)<<24);
|
|
235 y++; y++; cb++; cr++;
|
|
236 }
|
|
237 dest32 += (bespitch - config.src_width) / 2;
|
|
238
|
|
239 for(w=0; w < config.src_width/2; w++)
|
|
240 {
|
|
241 *dest32++ = (*y) + ((*crp)<<8) + ((*(y+1))<<16) + ((*cbp)<<24);
|
|
242 y++; y++; cbp++; crp++;
|
|
243 }
|
|
244 dest32 += (bespitch - config.src_width) / 2;
|
|
245 }
|
|
246 }
|
|
247
|
|
248 //static uint32_t draw_slice(uint8_t *src[], uint32_t slice_num)
|
|
249 static uint32_t
|
|
250 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
|
|
251 {
|
|
252
|
|
253 if ( vid_data == NULL ) return 0;
|
|
254
|
|
255 write_slice_YUV420P3(src[0],src[1], src[2],stride,y,w,h);
|
|
256
|
|
257 //printf("sorry, not syncfb/draw_slice() implemented yet...\n");
|
|
258
|
|
259 #if 0
|
|
260
|
|
261 if ( conf_palette == VIDEO_PALETTE_YUV422 ) {
|
|
262 write_slice_YUV422(src[0],src[1], src[2],slice_num);
|
|
263 } else if ( conf_palette == VIDEO_PALETTE_YUV420P2 ) {
|
|
264 write_slice_YUV420P2(src[0],src[1], src[2],slice_num);
|
|
265 } else if ( conf_palette == VIDEO_PALETTE_YUV420P3 ) {
|
|
266 write_slice_YUV420P3(src[0],src[1], src[2],slice_num);
|
|
267 }
|
|
268 #endif
|
|
269
|
|
270 return 0;
|
|
271 }
|
|
272
|
|
273
|
|
274
|
|
275
|
|
276 static void
|
|
277 flip_page(void)
|
|
278 {
|
|
279
|
|
280 // memset(frame_mem + bufinfo.offset_p2, 0x80, config.src_width*config.src_height);
|
|
281 ioctl(f,SYNCFB_COMMIT_BUFFER,&bufinfo);
|
|
282
|
|
283 if ( dbg_singleframe ) {
|
|
284 if ( debug_skip_first == 0 ) {
|
|
285 printf( "Press 'anykey' for field 1\n" );
|
|
286 getchar();
|
|
287 ioctl(f,SYNCFB_VBI,0);
|
|
288 }
|
|
289
|
|
290 if ( debug_skip_first > 0 ) {
|
|
291 debug_skip_first--;
|
|
292 // debug_skip_first = 0;
|
|
293 if ( debug_skip_first == 0 ) {
|
|
294 ioctl(f,SYNCFB_VBI,0);
|
|
295 ioctl(f,SYNCFB_VBI,0);
|
|
296 ioctl(f,SYNCFB_VBI,0);
|
|
297 }
|
|
298 }
|
|
299
|
|
300 if ( debug_skip_first == 0 ) {
|
|
301 printf( "Press 'anykey' for field 2\n" );
|
|
302 getchar();
|
|
303 ioctl(f,SYNCFB_VBI,0);
|
|
304 }
|
|
305 }
|
|
306
|
|
307 ioctl(f,SYNCFB_REQUEST_BUFFER,&bufinfo);
|
|
308 if ( bufinfo.id == -1 ) printf( "Got buffer #%d\n", bufinfo.id );
|
|
309
|
|
310 vid_data = (uint_8 *)(frame_mem + bufinfo.offset);
|
|
311 if ( bufinfo.id == -1 ) {
|
|
312 //vid_data = frame_mem;
|
|
313 vid_data = NULL;
|
|
314 }
|
|
315 // printf("Flip %d\n", bufinfo.offset);
|
|
316
|
|
317 }
|
|
318
|
|
319 static uint32_t draw_frame(uint8_t *src[])
|
|
320 {
|
|
321 printf("DRAW FRAME!!!\n");
|
|
322 if ( conf_palette == VIDEO_PALETTE_YUV422 ) {
|
|
323 write_frame_YUV422(src[0],src[1], src[2]);
|
|
324 } else if ( conf_palette == VIDEO_PALETTE_YUV420P2 ) {
|
|
325 write_frame_YUV420P2(src[0],src[1], src[2]);
|
|
326 } else if ( conf_palette == VIDEO_PALETTE_YUV420P3 ) {
|
|
327 write_frame_YUV420P3(src[0],src[1], src[2]);
|
|
328 }
|
|
329
|
|
330 flip_page();
|
|
331 return 0;
|
|
332 }
|
|
333
|
|
334 static uint32_t
|
|
335 query_format(uint32_t format)
|
|
336 {
|
|
337 switch(format){
|
|
338 case IMGFMT_YV12:
|
|
339 // case IMGFMT_RGB|24:
|
|
340 // case IMGFMT_BGR|24:
|
|
341 return 1;
|
|
342 }
|
|
343 return 0;
|
|
344 }
|
|
345
|
|
346 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
|
|
347 {
|
|
348 uint_32 frame_size;
|
|
349
|
|
350 f = open("/dev/syncfb",O_RDWR);
|
|
351
|
|
352 if(f == -1)
|
|
353 {
|
|
354 f = open("/dev/mga_vid",O_RDWR);
|
|
355 if(f == -1)
|
|
356 {
|
|
357 fprintf(stderr,"Couldn't open /dev/syncfb or /dev/mga_vid\n");
|
|
358 return(-1);
|
|
359 }
|
|
360 }
|
|
361
|
|
362 if (ioctl(f,SYNCFB_GET_CAPS,&sfb_caps)) perror("Error in mga_vid_config ioctl");
|
|
363 if (ioctl(f,SYNCFB_GET_CONFIG,&config)) perror("Error in mga_vid_config ioctl");
|
|
364
|
|
365 if (sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV420P3) ) {
|
|
366 config.src_palette= VIDEO_PALETTE_YUV420P3;
|
|
367 printf("using palette yuv420p3\n");
|
|
368 }else if ( sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV420P2) ) {
|
|
369 config.src_palette= VIDEO_PALETTE_YUV420P2;
|
|
370 printf("using palette yuv420p2\n");
|
|
371 } else if ( sfb_caps.palettes & (1<<VIDEO_PALETTE_YUV422) ) {
|
|
372 config.src_palette= VIDEO_PALETTE_YUV422;
|
|
373 printf("using palette yuv422\n");
|
|
374 } else {
|
|
375 printf("no supported palette found\n");
|
|
376 exit(1);
|
|
377 }
|
|
378
|
|
379 // config.src_palette= VIDEO_PALETTE_YUV422;
|
|
380
|
|
381 if ( vo_conf_cinemode ) {
|
|
382 config.default_repeat = 3;
|
|
383 } else {
|
|
384 config.default_repeat = 2;
|
|
385 }
|
|
386
|
|
387 conf_palette = config.src_palette;
|
|
388 if ( vo_conf_deinterlace ) {
|
|
389 config.syncfb_mode = SYNCFB_FEATURE_SCALE | SYNCFB_FEATURE_BLOCK_REQUEST | SYNCFB_FEATURE_DEINTERLACE;
|
|
390 config.default_repeat = 1;
|
|
391 } else {
|
|
392 config.syncfb_mode = SYNCFB_FEATURE_SCALE | SYNCFB_FEATURE_BLOCK_REQUEST;
|
|
393 }
|
|
394
|
|
395 config.fb_screen_size = (RAM_SIZE-4)*0x100000; //(1280 * 1024 * 32) / 8;
|
|
396 config.src_width = width;
|
|
397 config.src_height= height;
|
|
398
|
|
399 config.image_width = d_width;
|
|
400 config.image_height= d_height;
|
|
401 //config.image_width = 1024;
|
|
402 //config.image_height= 576;
|
|
403
|
|
404 config.image_xorg= 0;
|
|
405 config.image_yorg= 0;
|
|
406
|
|
407
|
|
408 printf ("BES Sourcer size: %d x %d\n", width, height);
|
|
409
|
|
410 ioctl(f,SYNCFB_ON,0);
|
|
411 if (ioctl(f,SYNCFB_SET_CONFIG,&config)) perror("Error in mga_vid_config ioctl");
|
|
412
|
|
413 printf ("Framebuffer memory: %ld in %ld buffers\n", sfb_caps.memory_size, config.buffers);
|
|
414
|
|
415 frame_size = ((width + 31) & ~31) * height + (((width + 31) & ~31) * height) / 2;
|
|
416 frame_mem = (uint_8*)mmap(0,sfb_caps.memory_size,PROT_WRITE,MAP_SHARED,f,0);
|
|
417
|
|
418 printf( "Requesting first buffer #%d\n", bufinfo.id );
|
|
419 ioctl(f,SYNCFB_REQUEST_BUFFER,&bufinfo);
|
|
420 printf( "Got first buffer #%d\n", bufinfo.id );
|
|
421
|
|
422
|
|
423 vid_data = (uint_8 *)(frame_mem + bufinfo.offset);
|
|
424
|
|
425 //clear the buffer
|
|
426 // memset(frame_mem,0x80,frame_size*2);
|
|
427 return 0;
|
|
428 }
|
|
429
|
|
430 static const vo_info_t*
|
|
431 get_info(void)
|
|
432 {
|
|
433 return &vo_info;
|
|
434 }
|
|
435
|
|
436
|
|
437 static void
|
|
438 uninit(void)
|
|
439 {
|
|
440 if (ioctl(f,SYNCFB_OFF,0)) perror("Error in OFF ioctl");
|
|
441
|
|
442 }
|
|
443
|
31
|
444 static void check_events(void)
|
|
445 {
|
|
446 }
|
1
|
447
|