changeset 10452:4eaf6fa120b1

sync to ffmpeg, updates, cleanups
author iive
date Mon, 21 Jul 2003 21:02:34 +0000
parents e97b59049b4c
children b411916cb86a
files libmpcodecs/vd_ffmpeg.c libvo/vo_xvmc.c xvmc_render.h
diffstat 3 files changed, 71 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vd_ffmpeg.c	Mon Jul 21 19:04:12 2003 +0000
+++ b/libmpcodecs/vd_ffmpeg.c	Mon Jul 21 21:02:34 2003 +0000
@@ -48,7 +48,7 @@
 #endif
 
 //!!TODO!! when ffmpeg is patched set correct version number
-#if LIBAVCODEC_BUILD < 4669
+#if LIBAVCODEC_BUILD < 4671
 #undef HAVE_XVMC
 #endif
 
@@ -88,8 +88,8 @@
 static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic);
 static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic);
 static void mc_render_slice(struct AVCodecContext *s,
-                	uint8_t **src, int linesize,
-                	int y, int width, int height);
+                	AVFrame *src, int offset[4],
+                	int y, int type, int height);
 #endif
 
 static int lavc_param_workaround_bugs= FF_BUG_AUTODETECT;
@@ -122,10 +122,6 @@
         {
             int format =(*((int*)arg));
 	    if( format == ctx->best_csp ) return CONTROL_TRUE;//supported
-#ifdef HAVE_XVMC
-	    if( (avctx->pix_fmt == PIX_FMT_XVMC) && IMGFMT_IS_XVMC(format) ) 
-                return CONTROL_TRUE;
-#endif
 	// possible conversions:
 	    switch( format ){
         case IMGFMT_YV12:
@@ -135,6 +131,11 @@
 	    if(avctx->pix_fmt==PIX_FMT_YUV420P) return CONTROL_TRUE;// u/v swap
 	    if(avctx->pix_fmt==PIX_FMT_YUV422P) return CONTROL_TRUE;// half stride
 	    break;
+#ifdef HAVE_XVMC
+        case IMGFMT_XVMC_IDCT_MPEG2:
+        case IMGFMT_XVMC_MOCO_MPEG2:
+            if(avctx->pix_fmt==PIX_FMT_XVMC_MPEG2) return CONTROL_TRUE;
+#endif
 	}
         return CONTROL_FALSE;
     }
@@ -405,9 +406,7 @@
 	case PIX_FMT_RGB24 :  ctx->best_csp=IMGFMT_BGR24;break; //huffyuv
 	case PIX_FMT_RGBA32:  ctx->best_csp=IMGFMT_BGR32;break; //huffyuv / mjpeg
 #ifdef HAVE_XVMC
-	case PIX_FMT_XVMC: //ctx->best_csp=IMGFMT_XVMC_MPEG2;
-	   ctx->best_csp=sh->codec->outfmt[sh->outfmtidx];//!!maybe!!??
-           break;
+	case PIX_FMT_XVMC_MPEG2:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break;
 #endif
 	default:
 	    ctx->best_csp=0;
@@ -580,7 +579,7 @@
 #ifdef HAVE_XVMC
 // in fact if(!dr1) should be the only condition, but this way we hide an 
 //ffmpeg interlace (mpeg2) bug. use -noslices to avoid it.
-    if( (avctx->pix_fmt != PIX_FMT_XVMC) )// && (!dr1) )
+    if( !avctx->xvmc_acceleration )// && (!dr1) )
 #endif
     avctx->draw_horiz_band=NULL;
     avctx->opaque=sh;
@@ -748,18 +747,21 @@
                MP_IMGFLAG_DRAW_CALLBACK;
     
 //  printf("vd_ffmpeg::mc_get_buffer (xvmc) %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count);
-    if(avctx->pix_fmt != PIX_FMT_XVMC){
-        printf("vd_ffmpeg::mc_get_buffer should work only with XVMC format!!!");
+    if(!avctx->xvmc_acceleration){
+        printf("vd_ffmpeg::mc_get_buffer should work only with XVMC acceleration !!");
         assert(0);
         exit(1);
+//        return -1;//!!fixme check error conditions
     }
     assert(avctx->draw_horiz_band == mc_render_slice);
     assert(avctx->release_buffer == mc_release_buffer);
     if(verbose > 4)
         printf("vd_ffmpeg::mc_get_buffer\n");
+
     if(init_vo(sh)<0){
         printf("vd_ffmpeg: Unexpected init_vo error\n");
         exit(1);
+//        return -1;//!!fixme check error conditions
     }
 
 
@@ -777,12 +779,14 @@
         printf("Unrecoverable error, render buffers not taken\n");
         assert(0);
         exit(1);
+//        return -1;//!!fixme check error conditions in ffmpeg
     };
     
     if( (mpi->flags & MP_IMGFLAG_DIRECT) == 0){
         printf("Only buffers allocated by vo_xvmc allowed\n");
         assert(0);
         exit(1);
+//        return -1;//!!fixme check error conditions in ffmpeg
     }
     
     pic->data[0]= mpi->planes[0];
@@ -814,9 +818,9 @@
         ctx->ip_age[1]++;
         ctx->b_age=1;
     }
-#if LIBAVCODEC_BUILD >= 4644
+
     pic->type= FF_BUFFER_TYPE_USER;
-#endif
+
     render=(xvmc_render_state_t*)mpi->priv;//same as data[2]
     assert(render != 0);
     assert(render->magic == MP_XVMC_RENDER_MAGIC);
@@ -854,16 +858,16 @@
 }
 
 static void mc_render_slice(struct AVCodecContext *s,
-                	uint8_t **src, int linesize,
-                	int y, int width, int height){
-
-    sh_video_t * sh = s->opaque;
-    int stride[3];
+                	AVFrame *src, int offset[4],
+                	int y, int type, int height){
+int width= s->width;
+sh_video_t * sh = s->opaque;
+uint8_t *source[3]= {src->data[0], src->data[1], src->data[2]};
     
-    assert(linesize==0);
-
-    stride[0]=stride[1]=stride[2]=linesize;
-    mpcodecs_draw_slice (sh,src, stride, width, height, 0, y);
+    assert(src->linesize[0]==0 && src->linesize[1]==0 && src->linesize[2]==0);
+    assert(offset[0]==0 && offset[1]==0 && offset[2]==0);
+    
+    mpcodecs_draw_slice (sh, source, src->linesize, width, height, 0, y);
 
 }
 
--- a/libvo/vo_xvmc.c	Mon Jul 21 19:04:12 2003 +0000
+++ b/libvo/vo_xvmc.c	Mon Jul 21 21:02:34 2003 +0000
@@ -57,7 +57,7 @@
 #define MAX_SURFACES 8
 static int number_of_surfaces=0;
 static XvMCSurface surface_array[MAX_SURFACES];
-static xvmc_render_state_t surface_render[MAX_SURFACES];//these one are used in mpi->priv
+static xvmc_render_state_t * surface_render;
 
 static xvmc_render_state_t * p_render_surface_to_show=NULL;
 static xvmc_render_state_t * p_render_surface_visible=NULL;
@@ -113,13 +113,13 @@
 //from vo_xmga
 static void mDrawColorKey(uint32_t x,uint32_t  y, uint32_t w, uint32_t h)
 {
-   if( (keycolor_handling != 2) || (keycolor_handling != 3) ) 
+   if( (keycolor_handling != 2) && (keycolor_handling != 3) ) 
       return ;//unknow method
 
    XSetBackground( mDisplay,vo_gc,0 );
    XClearWindow( mDisplay,vo_window );
  
-   if(keycolor_handling == 2){
+   if(keycolor_handling == 3){
       XSetForeground( mDisplay,vo_gc,keycolor );
       XFillRectangle( mDisplay,vo_window,vo_gc,x,y,w,h);
    }
@@ -255,8 +255,9 @@
    }
    xv_port = 0;
    number_of_surfaces = 0;
-   keycolor_handling = 1;
-
+   keycolor_handling = 1;//!!fixme
+   surface_render=NULL;
+   
    return 0;
 }
 
@@ -326,6 +327,9 @@
    }
    printf("vo_xvmc: mv_blocks allocated\n");
 
+   if(surface_render==NULL)
+      surface_render=malloc(MAX_SURFACES*sizeof(xvmc_render_state_t));//easy mem debug
+   
    for(i=0; i<MAX_SURFACES; i++){
       rez=XvMCCreateSurface(mDisplay,&ctx,&surface_array[i]);
       if( rez != Success )
@@ -336,6 +340,7 @@
       surface_render[i].mv_blocks = mv_blocks.macro_blocks;
       surface_render[i].total_number_of_mv_blocks = numblocks;
       surface_render[i].total_number_of_data_blocks = numblocks*blocks_per_macroblock;;
+      surface_render[i].mc_type = surface_info.mc_type & (~XVMC_IDCT);
       surface_render[i].idct = (surface_info.mc_type & XVMC_IDCT) == XVMC_IDCT;
       surface_render[i].chroma_format = surface_info.chroma_format;
       surface_render[i].unsigned_intra = (surface_info.flags & XVMC_INTRA_UNSIGNED) == XVMC_INTRA_UNSIGNED;
@@ -476,7 +481,7 @@
 //    vo_x11_sizehint( hint.x, hint.y, hint.width, hint.height,0 );   
     
       if ( vo_gc != None ) XFreeGC( mDisplay,vo_gc );
-      vo_gc = XCreateGC(mDisplay, vo_window, 0L, &xgcv);
+      vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &xgcv);
       XFlush(mDisplay);
       XSync(mDisplay, False);
 #ifdef HAVE_XF86VM
@@ -525,6 +530,24 @@
 static void draw_osd(void){
 }
 
+static void xvmc_sync_surface(XvMCSurface * srf){
+int status,rez;
+   rez = XvMCGetSurfaceStatus(mDisplay,srf,&status);
+   assert(rez==Success);
+   if( status & XVMC_RENDERING )
+      XvMCSyncSurface(mDisplay, srf);
+/*
+   rez = XvMCFlushSurface(mDisplay, srf);
+   assert(rez==Success);
+
+   do {
+   usleep(1);
+   printf("waiting...\n");
+   XvMCGetSurfaceStatus(mDisplay,srf,&status);
+   } while (status & XVMC_RENDERING);       
+*/
+}
+
 static void flip_page(void){
 int rez;
 int clipX,clipY,clipW,clipH;
@@ -539,14 +562,16 @@
 
    if(p_render_surface_to_show == NULL) return;
    assert( p_render_surface_to_show->magic == MP_XVMC_RENDER_MAGIC );
-  
+//fixme   assert( p_render_surface_to_show != p_render_surface_visible);
+   
 // make sure the rendering is done
-   XvMCSyncSurface(mDisplay,p_render_surface_to_show->p_surface);//!!
+   xvmc_sync_surface(p_render_surface_to_show->p_surface);
+
 //the visible surface won't be displayed anymore, mark it as free
    if( p_render_surface_visible!=NULL ) 
       p_render_surface_visible->state &= ~MP_XVMC_STATE_DISPLAY_PENDING;
 
-   assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING);
+//!!fixme   assert(p_render_surface_to_show->state & MP_XVMC_STATE_DISPLAY_PENDING);
 
 // show it
 // if(benchmark)
@@ -617,6 +642,8 @@
             printf("vo_xvmc::uninit surface_render[%d].status=%d\n",i,
                     surface_render[i].state); 
       }
+      
+      free(surface_render);surface_render=NULL;
 
       XvMCDestroyContext(mDisplay,&ctx);
       if( verbose > 3) printf("vo_xvmc: Context sucessfuly freed\n");
@@ -660,19 +687,6 @@
    return flags;
 }
 
-static void xvmc_sync_surface(XvMCSurface * srf){
-int status,rez;
-   rez = XvMCGetSurfaceStatus(mDisplay,srf,&status);
-   assert(rez==Success);
-   if( status & XVMC_RENDERING )
-      XvMCSyncSurface(mDisplay, srf);
-/*
-   do {
-   unsleep(10);
-   XvMCGetSurfaceStatus(mDisplay,&surface_array[srf],&status);
-   } while (status & XVMC_RENDERING)       
-*/
-}
 
 static uint32_t draw_slice(uint8_t *image[], int stride[],
 			   int w, int h, int x, int y){
@@ -685,11 +699,6 @@
    rndr = (xvmc_render_state_t*)image[2];//this is copy of priv-ate
    assert( rndr != NULL );
    assert( rndr->magic == MP_XVMC_RENDER_MAGIC );
-   //!!todo make check for beggining of frame/field
-   if(rndr->p_past_surface!=NULL)
-      xvmc_sync_surface(rndr->p_past_surface);
-   if(rndr->p_future_surface!=NULL)
-      xvmc_sync_surface(rndr->p_future_surface);   
 
    rez = XvMCRenderSurface(mDisplay,&ctx,rndr->picture_structure,
              		   rndr->p_surface,
@@ -728,6 +737,7 @@
    }
 #endif
    assert(rez==Success);
+   if(verbose > 3 ) printf("vo_xvmc: flush surface\n");
    rez = XvMCFlushSurface(mDisplay, rndr->p_surface);
    assert(rez==Success);
 
@@ -782,6 +792,10 @@
       return VO_FALSE;
    }
 
+assert(surface_render[getsrf].start_mv_blocks_num == 0);
+assert(surface_render[getsrf].filled_mv_blocks_num == 0);
+assert(surface_render[getsrf].next_free_data_block_num == 0);
+
    mpi->flags |= MP_IMGFLAG_DIRECT;
 //keep strides 0 to avoid field manipulations
    mpi->stride[0] = 0;
--- a/xvmc_render.h	Mon Jul 21 19:04:12 2003 +0000
+++ b/xvmc_render.h	Mon Jul 21 21:02:34 2003 +0000
@@ -21,10 +21,11 @@
   XvMCMacroBlock * mv_blocks;
   int total_number_of_mv_blocks;
   int total_number_of_data_blocks;
+  int mc_type;//XVMC_MPEG1/2/4,XVMC_H263 without XVMC_IDCT
   int idct;//does we use IDCT acceleration?
   int chroma_format;//420,422,444
   int unsigned_intra;//+-128 for intra pictures after clip
-  int reserved1[14];//future extenstions (e.g. gmc,qpel)
+  int reserved1[13];//future extenstions (e.g. gmc,qpel)
   XvMCSurface* p_surface;//pointer to rendered surface, never changed
 
 //these are changed by decoder