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