comparison libvo/vo_tdfx_vid.c @ 9546:8feb4bb5b334

vo tdfx vid, even faster than tdfxfb and that's just the beginning ;)
author albeu
date Fri, 07 Mar 2003 18:45:02 +0000
parents
children 9883afd390dc
comparison
equal deleted inserted replaced
9545:d1bbeae9f46a 9546:8feb4bb5b334
1 /*
2 * video_out_null.c
3 *
4 * Copyright (C) Aaron Holtzman - June 2000
5 *
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
7 *
8 * mpeg2dec is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * mpeg2dec is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Make; see the file COPYING. If not, write to
20 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <sys/ioctl.h>
33 #include <sys/mman.h>
34 #include "config.h"
35 #include "video_out.h"
36 #include "video_out_internal.h"
37 #include "aspect.h"
38
39 #include "fastmemcpy.h"
40 #include "drivers/tdfx_vid.h"
41
42
43 static vo_info_t info =
44 {
45 "tdfx_vid video output",
46 "tdfx_vid",
47 "Albeu",
48 ""
49 };
50
51 LIBVO_EXTERN(tdfx_vid)
52
53 static tdfx_vid_config_t tdfx_cfg;
54
55 static unsigned char* agp_mem = NULL;
56 static int tdfx_fd = -1;
57
58 static uint32_t img_fmt; // The real input format
59 static uint32_t src_width, src_height, src_fmt, src_bpp, src_stride;
60 static uint32_t dst_width, dst_height, dst_fmt, dst_bpp, dst_stride;
61
62 static uint32_t tdfx_page;
63 static uint32_t front_buffer;
64 static uint32_t back_buffer;
65
66
67 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
68 {
69 tdfx_vid_agp_move_t mov;
70 tdfx_vid_yuv_t yuv;
71 int p;
72 uint8_t* ptr[3];
73
74 switch(img_fmt) {
75 case IMGFMT_YUY2:
76 case IMGFMT_UYVY:
77 case IMGFMT_BGR8:
78 case IMGFMT_BGR16:
79 case IMGFMT_BGR24:
80 case IMGFMT_BGR32:
81 // copy :( to agp_mem
82 // still faster than tdfxfb wich directly copy to the video mem :)
83 memcpy_pic(agp_mem,image[0],src_bpp*w,h,stride[0],stride[0]);
84
85 mov.move2 = TDFX_VID_MOVE_2_PACKED;
86 mov.width = w*src_bpp;
87 mov.height = h;
88 mov.src = 0;
89 mov.src_stride = stride[0];
90
91 mov.dst = back_buffer + y*src_stride + x * src_bpp;
92 mov.dst_stride = src_stride;
93
94 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov)) {
95 printf("tdfx_vid: AGP move failed\n");
96 return 1;
97 }
98 break;
99 case IMGFMT_YV12:
100 case IMGFMT_I420:
101 // Copy to agp mem
102 ptr[0] = agp_mem;
103 memcpy_pic(ptr[0],image[0],w,h,stride[0],stride[0]);
104 ptr[1] = ptr[0] + (h*stride[0]);
105 memcpy_pic(ptr[1],image[1],w/2,h/2,stride[1],stride[1]);
106 ptr[2] = ptr[1] + (h/2*stride[1]);
107 memcpy_pic(ptr[2],image[2],w/2,h/2,stride[2],stride[2]);
108
109 // Setup the yuv thing
110 yuv.base = back_buffer + y*src_stride + x * src_bpp;
111 yuv.stride = src_stride;
112 if(ioctl(tdfx_fd,TDFX_VID_SET_YUV,&yuv)) {
113 printf("tdfx_vid: Set yuv failed\n");
114 return 1;
115 }
116
117 // Now agp move that
118 // Y
119 mov.move2 = TDFX_VID_MOVE_2_YUV;
120 mov.width = w;
121 mov.height = h;
122 mov.src = ptr[0] - agp_mem;
123 mov.src_stride = stride[0];
124 mov.dst = 0x0;
125 mov.dst_stride = TDFX_VID_YUV_STRIDE;
126 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov)) {
127 printf("tdfx_vid: AGP move failed on Y plane\n");
128 return 1;
129 }
130 //return 0;
131 // U
132 p = img_fmt == IMGFMT_YV12 ? 1 : 2;
133 mov.width = w/2;
134 mov.height = h/2;
135 mov.src = ptr[p] - agp_mem;
136 mov.src_stride = stride[p];
137 mov.dst += TDFX_VID_YUV_PLANE_SIZE;
138 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov)) {
139 printf("tdfx_vid: AGP move failed on U plane\n");
140 return 1;
141 }
142 // V
143 p = img_fmt == IMGFMT_YV12 ? 2 : 1;
144 mov.src = ptr[p] - agp_mem;
145 mov.src_stride = stride[p];
146 mov.dst += TDFX_VID_YUV_PLANE_SIZE;
147 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov)) {
148 printf("tdfx_vid: AGP move failed on U plane\n");
149 return 1;
150 }
151 }
152
153 return 0;
154 }
155
156 static void draw_osd(void)
157 {
158 }
159
160 static void
161 flip_page(void)
162 {
163 tdfx_vid_blit_t blit;
164 //return;
165 // Scale convert
166 blit.src = back_buffer;
167 blit.src_stride = src_stride;
168 blit.src_x = 0;
169 blit.src_y = 0;
170 blit.src_w = src_width;
171 blit.src_h = src_height;
172 blit.src_format = src_fmt;
173
174 blit.dst = front_buffer;
175 blit.dst_stride = dst_stride;
176 blit.dst_x = 0;
177 blit.dst_y = 0;
178 blit.dst_w = dst_width;
179 blit.dst_h = dst_height;
180 blit.dst_format = dst_fmt;
181
182 if(ioctl(tdfx_fd,TDFX_VID_BLIT,&blit))
183 printf("tdfx_vid: Blit failed\n");
184 }
185
186 static uint32_t
187 draw_frame(uint8_t *src[])
188 {
189 int stride[] = { src_stride, 0, 0};
190 return draw_slice(src,stride,src_width, src_height,0,0);
191 }
192
193 static uint32_t
194 query_format(uint32_t format)
195 {
196 switch(format) {
197 case IMGFMT_YUY2:
198 case IMGFMT_UYVY:
199 case IMGFMT_BGR8:
200 case IMGFMT_BGR16:
201 case IMGFMT_BGR24:
202 case IMGFMT_BGR32:
203 case IMGFMT_YV12:
204 case IMGFMT_I420:
205 return 3 | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
206 }
207 return 0;
208 }
209
210 static uint32_t
211 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
212 {
213
214 if(tdfx_fd < 0)
215 return 1;
216
217 if(!vo_screenwidth)
218 vo_screenwidth = tdfx_cfg.screen_width;
219 if(!vo_screenheight)
220 vo_screenheight = tdfx_cfg.screen_height;
221
222 aspect_save_orig(width,height);
223 aspect_save_prescale(d_width,d_height);
224 aspect_save_screenres(vo_screenwidth,vo_screenheight);
225
226 if(fullscreen&0x01) { /* -fs */
227 aspect(&d_width,&d_height,A_ZOOM);
228 vo_fs = VO_TRUE;
229 } else {
230 aspect(&d_width,&d_height,A_NOZOOM);
231 vo_fs = VO_FALSE;
232 }
233
234 src_width = width;
235 src_height = height;
236 switch(format) {
237 case IMGFMT_BGR8:
238 case IMGFMT_BGR16:
239 case IMGFMT_BGR24:
240 case IMGFMT_BGR32:
241 src_fmt = format;
242 src_bpp = ((format & 0x3F)+7)/8;
243 break;
244 case IMGFMT_YUY2:
245 case IMGFMT_YV12:
246 case IMGFMT_I420:
247 src_fmt = TDFX_VID_FORMAT_YUY2;
248 src_bpp = 2;
249 break;
250 default:
251 printf("Unsupported input format 0x%x\n",format);
252 return 1;
253 }
254
255 img_fmt = format;
256 src_stride = src_width*src_bpp;
257
258 dst_fmt = tdfx_cfg.screen_format;
259 dst_bpp = ((dst_fmt & 0x3F)+7)/8;
260 dst_width = d_width;
261 dst_height = d_height;
262 dst_stride = tdfx_cfg.screen_stride;
263
264 tdfx_page = tdfx_cfg.screen_stride*tdfx_cfg.screen_height;
265 front_buffer = tdfx_cfg.screen_start;
266 back_buffer = front_buffer + tdfx_page;
267
268 printf("tdfxvid setup : %d(%d) x %d @ %d => %d(%d) x %d @ %d\n",
269 src_width,src_stride,src_height,src_bpp,
270 dst_width,dst_stride,dst_height,dst_bpp);
271
272 return 0;
273 }
274
275 static void
276 uninit(void)
277 {
278 close(tdfx_fd);
279 tdfx_fd = -1;
280 }
281
282
283 static void check_events(void)
284 {
285 }
286
287 static uint32_t preinit(const char *arg)
288 {
289
290 tdfx_fd = open(arg ? arg : "/dev/tdfx_vid", O_RDWR);
291 if(tdfx_fd < 0) {
292 printf("tdfx_vid: Can't open %s: %s\n",arg ? arg : "/dev/tdfx_vid",
293 strerror(errno));
294 return 1;
295 }
296
297 if(ioctl(tdfx_fd,TDFX_VID_GET_CONFIG,&tdfx_cfg)) {
298 printf("tdfx_vid: Can't get current cfg: %s\n",strerror(errno));
299 return 1;
300 }
301
302 printf("tdfx_vid version %d\n"
303 " Ram: %d\n"
304 " Screen: %d x %d\n"
305 " Format: %c%c%c%d\n",
306 tdfx_cfg.version,
307 tdfx_cfg.ram_size,
308 tdfx_cfg.screen_width, tdfx_cfg.screen_height,
309 tdfx_cfg.screen_format>>24,(tdfx_cfg.screen_format>>16)&0xFF,
310 (tdfx_cfg.screen_format>>8)&0xFF,tdfx_cfg.screen_format&0xFF);
311
312 // For now just allocate more than i ever need
313 agp_mem = mmap( NULL, 1024*768*4, PROT_READ | PROT_WRITE, MAP_SHARED,
314 tdfx_fd, 0);
315
316 if(agp_mem == MAP_FAILED) {
317 printf("tdfx_vid: Memmap failed !!!!!\n");
318 return 1;
319 }
320
321 memset(agp_mem,0,1024*768*4);
322
323 return 0;
324 }
325
326 static uint32_t get_image(mp_image_t *mpi) {
327
328 if(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
329 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
330
331 if(mpi->type > MP_IMGTYPE_TEMP)
332 return VO_FALSE; // TODO ??
333
334 switch(mpi->imgfmt) {
335 case IMGFMT_YUY2:
336 case IMGFMT_UYVY:
337 // case IMGFMT_BGR8:
338 case IMGFMT_BGR16:
339 case IMGFMT_BGR24:
340 case IMGFMT_BGR32:
341 mpi->planes[0] = agp_mem;
342 mpi->stride[0] = src_stride;
343 break;
344 case IMGFMT_YV12:
345 mpi->planes[0] = agp_mem;
346 mpi->stride[0] = mpi->width;
347 mpi->planes[1] = mpi->planes[0] + mpi->stride[0]*mpi->height;
348 mpi->stride[1] = mpi->chroma_width;
349 mpi->planes[2] = mpi->planes[1] + mpi->stride[1]*mpi->chroma_height;
350 mpi->stride[2] = mpi->chroma_width;
351 break;
352 default:
353 printf("Get image todo\n");
354 return VO_FALSE;
355 }
356 mpi->flags |= MP_IMGFLAG_DIRECT;
357
358 return VO_TRUE;
359 }
360
361 static uint32_t draw_image(mp_image_t *mpi){
362 tdfx_vid_agp_move_t mov;
363 tdfx_vid_yuv_t yuv;
364 int p;
365 uint8_t* planes[3];
366 int stride[3];
367
368 //printf("Draw image !!!!\n");
369 if(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)
370 return VO_TRUE;
371
372 switch(mpi->imgfmt) {
373 case IMGFMT_YUY2:
374 case IMGFMT_UYVY:
375 case IMGFMT_BGR8:
376 case IMGFMT_BGR16:
377 case IMGFMT_BGR24:
378 case IMGFMT_BGR32:
379 if(!(mpi->flags&MP_IMGFLAG_DIRECT)) {
380 // copy :( to agp_mem
381 // still faster than tdfxfb wich directly copy to the video mem :)
382 planes[0] = agp_mem;
383 memcpy_pic(agp_mem,mpi->planes[0],src_bpp*mpi->width,mpi->height,
384 mpi->stride[0],mpi->stride[0]);
385 } else
386 planes[0] = mpi->planes[0];
387
388 mov.move2 = TDFX_VID_MOVE_2_PACKED;
389 mov.width = mpi->width*((mpi->bpp+7)/8);
390 mov.height = mpi->height;
391 mov.src = planes[0] - agp_mem;
392 mov.src_stride = mpi->stride[0];
393
394 mov.dst = back_buffer;
395 mov.dst_stride = src_stride;
396
397 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov))
398 printf("tdfx_vid: AGP move failed\n");
399 break;
400
401 case IMGFMT_YV12:
402 case IMGFMT_I420:
403 if(!(mpi->flags&MP_IMGFLAG_DIRECT)) {
404 // Copy to agp mem
405 planes[0] = agp_mem;
406 memcpy_pic(planes[0],mpi->planes[0],mpi->width,mpi->height,
407 mpi->stride[0],mpi->stride[0]);
408 planes[1] = planes[0] + (mpi->height*mpi->stride[0]);
409 memcpy_pic(planes[1],mpi->planes[1],mpi->chroma_width,mpi->chroma_height,
410 mpi->stride[1],mpi->stride[1]);
411 planes[2] = planes[1] + (mpi->chroma_height*mpi->stride[1]);
412 memcpy_pic(planes[2],mpi->planes[2],mpi->chroma_width,mpi->chroma_height,
413 mpi->stride[2],mpi->stride[2]);
414 } else
415 memcpy(planes,mpi->planes,3*sizeof(uint8_t*));
416
417 // Setup the yuv thing
418 yuv.base = back_buffer;
419 yuv.stride = src_stride;
420 if(ioctl(tdfx_fd,TDFX_VID_SET_YUV,&yuv)) {
421 printf("tdfx_vid: Set yuv failed\n");
422 break;
423 }
424 //return VO_FALSE;
425 // Now agp move that
426 // Y
427 mov.move2 = TDFX_VID_MOVE_2_YUV;
428 mov.width = mpi->width;
429 mov.height = mpi->height;
430 mov.src = planes[0] - agp_mem;
431 mov.src_stride = mpi->stride[0];
432 mov.dst = 0x0;
433 mov.dst_stride = TDFX_VID_YUV_STRIDE;
434
435 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov)) {
436 printf("tdfx_vid: AGP move failed on Y plane\n");
437 break;
438 }
439 //return 0;
440 // U
441 p = mpi->imgfmt == IMGFMT_YV12 ? 1 : 2;
442 mov.width = mpi->chroma_width;
443 mov.height = mpi->chroma_height;
444 mov.src = planes[p] - agp_mem;
445 mov.src_stride = mpi->stride[p];
446 mov.dst += TDFX_VID_YUV_PLANE_SIZE;
447 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov)) {
448 printf("tdfx_vid: AGP move failed on U plane\n");
449 break;
450 }
451 // V
452 p = mpi->imgfmt == IMGFMT_YV12 ? 2 : 1;
453 mov.src = planes[p] - agp_mem;
454 mov.src_stride = mpi->stride[p];
455 mov.dst += TDFX_VID_YUV_PLANE_SIZE;
456 if(ioctl(tdfx_fd,TDFX_VID_AGP_MOVE,&mov)) {
457 printf("tdfx_vid: AGP move failed on U plane\n");
458 break;
459 }
460 break;
461 default:
462 printf("What's that for a format 0x%x\n",mpi->imgfmt);
463 return VO_TRUE;
464 }
465 printf("Draw image true !!!!!\n");
466 return VO_TRUE;
467 }
468
469
470 static uint32_t control(uint32_t request, void *data, ...)
471 {
472 switch (request) {
473 case VOCTRL_QUERY_FORMAT:
474 return query_format(*((uint32_t*)data));
475 case VOCTRL_GET_IMAGE:
476 return get_image(data);
477 case VOCTRL_DRAW_IMAGE:
478 return draw_image(data);
479 }
480 return VO_NOTIMPL;
481 }
482