changeset 676:428755f858f7

multi buffering added (modify NUM_BUFFERS in the source)
author arpi_esp
date Tue, 01 May 2001 01:32:59 +0000
parents 3ec7d432d972
children ee2dac2cc633
files libvo/vo_xv.c
diffstat 1 files changed, 23 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_xv.c	Mon Apr 30 22:58:22 2001 +0000
+++ b/libvo/vo_xv.c	Tue May 01 01:32:59 2001 +0000
@@ -1,3 +1,5 @@
+
+#define NUM_BUFFERS 1
 
 /*
  * vo_xv.c, X11 Xv interface
@@ -61,7 +63,9 @@
 static unsigned int formats, adaptors,i,xv_port,xv_format;
 static XvAdaptorInfo        *ai;
 static XvImageFormatValues  *fo;
-static XvImage *xvimage[1];
+
+static int current_buf=0;
+static XvImage* xvimage[NUM_BUFFERS];
 
 #include <sys/ipc.h>
 #include <sys/shm.h>
@@ -69,7 +73,7 @@
 
 static int Shmem_Flag;
 static int Quiet_Flag;
-static XShmSegmentInfo Shminfo[1];
+static XShmSegmentInfo Shminfo[NUM_BUFFERS];
 static int gXErrorFlag;
 static int CompletionType = -1;
 
@@ -185,7 +189,10 @@
     {
      printf( "using Xvideo port %d for hw scaling\n",xv_port );
 
-     allocate_xvimage(0);
+     for(current_buf=0;current_buf<NUM_BUFFERS;++current_buf)
+       allocate_xvimage(current_buf);
+
+     current_buf=0;
 
      XGetGeometry( mydisplay,mywindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
      drwX=0; drwY=0;
@@ -267,14 +274,14 @@
 	case IMGFMT_YV12:  
 	case IMGFMT_I420:
         case IMGFMT_IYUV:
-    		vo_draw_alpha_yv12(w,h,src,srca,stride,xvimage[0]->data+image_width*y0+x0,image_width);
+    		vo_draw_alpha_yv12(w,h,src,srca,stride,xvimage[current_buf]->data+image_width*y0+x0,image_width);
 	break;
 	case IMGFMT_YUY2:
         case IMGFMT_YVYU:	
-    		vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[0]->data+2*(image_width*y0+x0),2*image_width);
+    		vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[current_buf]->data+2*(image_width*y0+x0),2*image_width);
 	break;
         case IMGFMT_UYVY:
-    		vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[0]->data+2*(image_width*y0+x0)+1,2*image_width);
+    		vo_draw_alpha_yuy2(w,h,src,srca,stride,xvimage[current_buf]->data+2*(image_width*y0+x0)+1,2*image_width);
 	break;
   }		
 
@@ -284,11 +291,12 @@
 {
  vo_draw_text(image_width,image_height,draw_alpha);
  check_events();
- XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[0],
+ XvShmPutImage(mydisplay, xv_port, mywindow, mygc, xvimage[current_buf],
          0, 0,  image_width, image_height,
          drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight),
          False);
  XFlush(mydisplay);
+ current_buf=(current_buf+1)%NUM_BUFFERS;
  return;
 }
 
@@ -300,7 +308,7 @@
  uint8_t *dst;
  int i;
 
- dst = xvimage[0]->data + image_width * y + x;
+ dst = xvimage[current_buf]->data + image_width * y + x;
  src = image[0];
  if(w==stride[0] && w==image_width) memcpy(dst,src,w*h);
    else
@@ -313,7 +321,7 @@
 
  x/=2;y/=2;w/=2;h/=2;
 
- dst = xvimage[0]->data + image_width * image_height + image_width/2 * y + x;
+ dst = xvimage[current_buf]->data + image_width * image_height + image_width/2 * y + x;
  src = image[2];
  if(w==stride[2] && w==image_width/2) memcpy(dst,src,w*h);
   else
@@ -323,7 +331,7 @@
      src+=stride[2];
      dst+=image_width/2;
    }
- dst = xvimage[0]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x;
+ dst = xvimage[current_buf]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x;
  src = image[1];
  if(w==stride[1] && w==image_width/2) memcpy(dst,src,w*h);
   else
@@ -349,7 +357,7 @@
 #if 0
      int i;
      unsigned short *s=(unsigned short *)src[0];
-     unsigned short *d=(unsigned short *)xvimage[0]->data;
+     unsigned short *d=(unsigned short *)xvimage[current_buf]->data;
      s+=image_width*image_height;
      for(i=0;i<image_height;i++) {
 	 s-=image_width;
@@ -357,7 +365,7 @@
 	 d+=image_width;
      }
 #else
-     memcpy(xvimage[0]->data,src[0],image_width*image_height*2);
+     memcpy(xvimage[current_buf]->data,src[0],image_width*image_height*2);
 #endif
      break;
 
@@ -366,9 +374,9 @@
  case IMGFMT_IYUV:
 
      // YV12 planar
-     memcpy(xvimage[0]->data,src[0],image_width*image_height);
-     memcpy(xvimage[0]->data+image_width*image_height,src[2],image_width*image_height/4);
-     memcpy(xvimage[0]->data+image_width*image_height*5/4,src[1],image_width*image_height/4);
+     memcpy(xvimage[current_buf]->data,src[0],image_width*image_height);
+     memcpy(xvimage[current_buf]->data+image_width*image_height,src[2],image_width*image_height/4);
+     memcpy(xvimage[current_buf]->data+image_width*image_height*5/4,src[1],image_width*image_height/4);
      break;
  }