comparison libvo/vo_xv.c @ 676:428755f858f7

multi buffering added (modify NUM_BUFFERS in the source)
author arpi_esp
date Tue, 01 May 2001 01:32:59 +0000
parents 41d6eec69b60
children c3e0bdb64027
comparison
equal deleted inserted replaced
675:3ec7d432d972 676:428755f858f7
1
2 #define NUM_BUFFERS 1
1 3
2 /* 4 /*
3 * vo_xv.c, X11 Xv interface 5 * vo_xv.c, X11 Xv interface
4 * 6 *
5 * Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. 7 * Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved.
59 static void allocate_xvimage(int); 61 static void allocate_xvimage(int);
60 static unsigned int ver,rel,req,ev,err; 62 static unsigned int ver,rel,req,ev,err;
61 static unsigned int formats, adaptors,i,xv_port,xv_format; 63 static unsigned int formats, adaptors,i,xv_port,xv_format;
62 static XvAdaptorInfo *ai; 64 static XvAdaptorInfo *ai;
63 static XvImageFormatValues *fo; 65 static XvImageFormatValues *fo;
64 static XvImage *xvimage[1]; 66
67 static int current_buf=0;
68 static XvImage* xvimage[NUM_BUFFERS];
65 69
66 #include <sys/ipc.h> 70 #include <sys/ipc.h>
67 #include <sys/shm.h> 71 #include <sys/shm.h>
68 #include <X11/extensions/XShm.h> 72 #include <X11/extensions/XShm.h>
69 73
70 static int Shmem_Flag; 74 static int Shmem_Flag;
71 static int Quiet_Flag; 75 static int Quiet_Flag;
72 static XShmSegmentInfo Shminfo[1]; 76 static XShmSegmentInfo Shminfo[NUM_BUFFERS];
73 static int gXErrorFlag; 77 static int gXErrorFlag;
74 static int CompletionType = -1; 78 static int CompletionType = -1;
75 79
76 static uint32_t image_width; 80 static uint32_t image_width;
77 static uint32_t image_height; 81 static uint32_t image_height;
183 187
184 if (xv_port != 0) 188 if (xv_port != 0)
185 { 189 {
186 printf( "using Xvideo port %d for hw scaling\n",xv_port ); 190 printf( "using Xvideo port %d for hw scaling\n",xv_port );
187 191
188 allocate_xvimage(0); 192 for(current_buf=0;current_buf<NUM_BUFFERS;++current_buf)
193 allocate_xvimage(current_buf);
194
195 current_buf=0;
189 196
190 XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); 197 XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
191 drwX=0; drwY=0; 198 drwX=0; drwY=0;
192 XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot ); 199 XTranslateCoordinates( mydisplay,mywindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
193 printf( "[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); 200 printf( "[xv] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
265 272
266 switch (xv_format) { 273 switch (xv_format) {
267 case IMGFMT_YV12: 274 case IMGFMT_YV12:
268 case IMGFMT_I420: 275 case IMGFMT_I420:
269 case IMGFMT_IYUV: 276 case IMGFMT_IYUV:
270 vo_draw_alpha_yv12(w,h,src,srca,stride,xvimage[0]->data+image_width*y0+x0,image_width); 277 vo_draw_alpha_yv12(w,h,src,srca,stride,xvimage[current_buf]->data+image_width*y0+x0,image_width);
271 break; 278 break;
272 case IMGFMT_YUY2: 279 case IMGFMT_YUY2:
273 case IMGFMT_YVYU: 280 case IMGFMT_YVYU:
274 vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[0]->data+2*(image_width*y0+x0),2*image_width); 281 vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[current_buf]->data+2*(image_width*y0+x0),2*image_width);
275 break; 282 break;
276 case IMGFMT_UYVY: 283 case IMGFMT_UYVY:
277 vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[0]->data+2*(image_width*y0+x0)+1,2*image_width); 284 vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[current_buf]->data+2*(image_width*y0+x0)+1,2*image_width);
278 break; 285 break;
279 } 286 }
280 287
281 } 288 }
282 289
283 static void flip_page(void) 290 static void flip_page(void)
284 { 291 {
285 vo_draw_text(image_width,image_height,draw_alpha); 292 vo_draw_text(image_width,image_height,draw_alpha);
286 check_events(); 293 check_events();
287 XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[0], 294 XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[current_buf],
288 0, 0, image_width, image_height, 295 0, 0, image_width, image_height,
289 drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight), 296 drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight),
290 False); 297 False);
291 XFlush(mydisplay); 298 XFlush(mydisplay);
299 current_buf=(current_buf+1)%NUM_BUFFERS;
292 return; 300 return;
293 } 301 }
294 302
295 303
296 304
298 { 306 {
299 uint8_t *src; 307 uint8_t *src;
300 uint8_t *dst; 308 uint8_t *dst;
301 int i; 309 int i;
302 310
303 dst = xvimage[0]->data + image_width * y + x; 311 dst = xvimage[current_buf]->data + image_width * y + x;
304 src = image[0]; 312 src = image[0];
305 if(w==stride[0] && w==image_width) memcpy(dst,src,w*h); 313 if(w==stride[0] && w==image_width) memcpy(dst,src,w*h);
306 else 314 else
307 for(i=0;i<h;i++) 315 for(i=0;i<h;i++)
308 { 316 {
311 dst+=image_width; 319 dst+=image_width;
312 } 320 }
313 321
314 x/=2;y/=2;w/=2;h/=2; 322 x/=2;y/=2;w/=2;h/=2;
315 323
316 dst = xvimage[0]->data + image_width * image_height + image_width/2 * y + x; 324 dst = xvimage[current_buf]->data + image_width * image_height + image_width/2 * y + x;
317 src = image[2]; 325 src = image[2];
318 if(w==stride[2] && w==image_width/2) memcpy(dst,src,w*h); 326 if(w==stride[2] && w==image_width/2) memcpy(dst,src,w*h);
319 else 327 else
320 for(i=0;i<h;i++) 328 for(i=0;i<h;i++)
321 { 329 {
322 memcpy(dst,src,w); 330 memcpy(dst,src,w);
323 src+=stride[2]; 331 src+=stride[2];
324 dst+=image_width/2; 332 dst+=image_width/2;
325 } 333 }
326 dst = xvimage[0]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x; 334 dst = xvimage[current_buf]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x;
327 src = image[1]; 335 src = image[1];
328 if(w==stride[1] && w==image_width/2) memcpy(dst,src,w*h); 336 if(w==stride[1] && w==image_width/2) memcpy(dst,src,w*h);
329 else 337 else
330 for(i=0;i<h;i++) 338 for(i=0;i<h;i++)
331 { 339 {
347 355
348 // YUY2 packed, flipped 356 // YUY2 packed, flipped
349 #if 0 357 #if 0
350 int i; 358 int i;
351 unsigned short *s=(unsigned short *)src[0]; 359 unsigned short *s=(unsigned short *)src[0];
352 unsigned short *d=(unsigned short *)xvimage[0]->data; 360 unsigned short *d=(unsigned short *)xvimage[current_buf]->data;
353 s+=image_width*image_height; 361 s+=image_width*image_height;
354 for(i=0;i<image_height;i++) { 362 for(i=0;i<image_height;i++) {
355 s-=image_width; 363 s-=image_width;
356 memcpy(d,s,image_width*2); 364 memcpy(d,s,image_width*2);
357 d+=image_width; 365 d+=image_width;
358 } 366 }
359 #else 367 #else
360 memcpy(xvimage[0]->data,src[0],image_width*image_height*2); 368 memcpy(xvimage[current_buf]->data,src[0],image_width*image_height*2);
361 #endif 369 #endif
362 break; 370 break;
363 371
364 case IMGFMT_YV12: 372 case IMGFMT_YV12:
365 case IMGFMT_I420: 373 case IMGFMT_I420:
366 case IMGFMT_IYUV: 374 case IMGFMT_IYUV:
367 375
368 // YV12 planar 376 // YV12 planar
369 memcpy(xvimage[0]->data,src[0],image_width*image_height); 377 memcpy(xvimage[current_buf]->data,src[0],image_width*image_height);
370 memcpy(xvimage[0]->data+image_width*image_height,src[2],image_width*image_height/4); 378 memcpy(xvimage[current_buf]->data+image_width*image_height,src[2],image_width*image_height/4);
371 memcpy(xvimage[0]->data+image_width*image_height*5/4,src[1],image_width*image_height/4); 379 memcpy(xvimage[current_buf]->data+image_width*image_height*5/4,src[1],image_width*image_height/4);
372 break; 380 break;
373 } 381 }
374 382
375 return 0; 383 return 0;
376 } 384 }