Index: vd_realvid.c
===================================================================
--- vd_realvid.c	（修订版 19631）
+++ vd_realvid.c	（工作拷贝）
@@ -58,7 +58,7 @@
 static unsigned long WINAPI (*wrvyuv_init)(void*, void*); // initdata,context
 static unsigned long WINAPI (*wrvyuv_transform)(char*, char*,transform_in_t*,unsigned int*,void*);
 #endif
-
+static unsigned char * buffer = NULL;
 static void *rv_handle=NULL;
 static int inited=0;
 #ifdef USE_WIN32DLL
@@ -290,6 +290,9 @@
 #endif
 	rv_handle=NULL;
 	inited = 0;
+	if (buffer != NULL)
+	    free(buffer);
+	buffer = NULL;
 }
 
 // copypaste from demux_real.c - it should match to get it working!
@@ -307,7 +310,7 @@
 	dp_hdr_t* dp_hdr=(dp_hdr_t*)data;
 	unsigned char* dp_data=((unsigned char*)data)+sizeof(dp_hdr_t);
 	uint32_t* extra=(uint32_t*)(((char*)data)+dp_hdr->chunktab);
-	unsigned char* buffer;
+//	unsigned char* buffer;
 
 	unsigned int transform_out[5];
 	transform_in_t transform_in={
@@ -321,14 +324,11 @@
 
 	if(len<=0 || flags&2) return NULL; // skipped frame || hardframedrop
 
-	if(inited){  // rv30 width/height not yet known
-	mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/,
-		sh->disp_w, sh->disp_h);
-	if(!mpi) return NULL;
-	    buffer=mpi->planes[0];
-	} else {
+	if(!inited) {
 	    buffer=malloc(sh->disp_w*sh->disp_h*3/2);
 	    if (!buffer) return 0;
+            //if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;
+            //inited = 1;
 	}
 	
 #ifdef USE_WIN32DLL
@@ -340,18 +340,19 @@
 	result=(*rvyuv_transform)(dp_data, buffer, &transform_in,
 		transform_out, sh->context);
 
-	if(!inited){  // rv30 width/height now known
-	    sh->aspect=(float)sh->disp_w/(float)sh->disp_h;
+	if((!inited || sh->disp_w!=transform_out[3] || sh->disp_h!=transform_out[4])&& transform_out[0] == 1){  // rv30 width/height now known
 	    sh->disp_w=transform_out[3];
 	    sh->disp_h=transform_out[4];
+	    sh->aspect=(float)sh->disp_w/(float)sh->disp_h;
 	    if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_I420)) return 0;
-	    mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0 /*MP_IMGFLAG_ACCEPT_STRIDE*/,
-		    sh->disp_w, sh->disp_h);
-	    if(!mpi) return NULL;
-	    memcpy(mpi->planes[0],buffer,sh->disp_w*sh->disp_h*3/2);
-	    free(buffer);
-	    inited=1;
-	} 
+	    inited = 1;
+	}
 
+	mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, sh->disp_w, sh->disp_h);
+	if(!mpi) return NULL;
+	memcpy(mpi->planes[0], buffer, sh->disp_w*sh->disp_h);
+	memcpy(mpi->planes[1], buffer+sh->disp_w*sh->disp_h-1, sh->disp_w*sh->disp_h*1/4);
+	memcpy(mpi->planes[2], buffer+sh->disp_w*sh->disp_h*5/4-1, sh->disp_w*sh->disp_h*1/4);
+	//free(buffer);
 	return (result?NULL:mpi);
 }
