[MPlayer-dev-eng] [PATCH]Allow hardware accelerated codecs to use vdpau deinterlacing

Carl Eugen Hoyos cehoyos at rainbow.studorg.tuwien.ac.at
Tue Mar 17 23:47:44 CET 2009


Hi!

With a lot of help from Reimar.
(The bugs are all my idea, though.)

Please comment, Carl Eugen
-------------- next part --------------
Index: libmpcodecs/vd_ffmpeg.c
===================================================================
--- libmpcodecs/vd_ffmpeg.c	(revision 28986)
+++ libmpcodecs/vd_ffmpeg.c	(working copy)
@@ -719,7 +719,7 @@
         }
 #endif
         // release mpi (in case MPI_IMGTYPE_NUMBERED is used, e.g. for VDPAU)
-        mpi->flags &= ~MP_IMGFLAG_IN_USE;
+        mpi->usage_count--;
     }
 
     if(pic->type!=FF_BUFFER_TYPE_USER){
Index: libmpcodecs/mp_image.h
===================================================================
--- libmpcodecs/mp_image.h	(revision 28986)
+++ libmpcodecs/mp_image.h	(working copy)
@@ -54,8 +54,6 @@
 
 // buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!)
 #define MP_IMGFLAG_TYPE_DISPLAYED 0x8000
-// set if it can not be reused yet (for MP_IMGTYPE_NUMBERED)
-#define MP_IMGFLAG_IN_USE 0x10000
 
 // codec doesn't support any form of direct rendering - it has own buffer
 // allocation. so we just export its buffer pointers:
@@ -101,6 +99,7 @@
     int chroma_height;
     int chroma_x_shift; // horizontal
     int chroma_y_shift; // vertical
+    int usage_count;
     /* for private use by filter or vo driver (to store buffer id or dmpi) */
     void* priv;
 } mp_image_t;
Index: libmpcodecs/vf.c
===================================================================
--- libmpcodecs/vf.c	(revision 28986)
+++ libmpcodecs/vf.c	(working copy)
@@ -304,7 +304,7 @@
     if (number == -1) {
       int i;
       for (i = 0; i < NUM_NUMBERED_MPI; i++)
-        if (!vf->imgctx.numbered_images[i] || !(vf->imgctx.numbered_images[i]->flags & MP_IMGFLAG_IN_USE))
+        if (!vf->imgctx.numbered_images[i] || !vf->imgctx.numbered_images[i]->usage_count)
           break;
       number = i;
     }
@@ -431,7 +431,7 @@
 
   mpi->qscale = NULL;
   }
-  mpi->flags |= MP_IMGFLAG_IN_USE;
+  mpi->usage_count++;
 //    printf("\rVF_MPI: %p %p %p %d %d %d    \n",
 //	mpi->planes[0],mpi->planes[1],mpi->planes[2],
 //	mpi->stride[0],mpi->stride[1],mpi->stride[2]);
Index: libvo/vo_vdpau.c
===================================================================
--- libvo/vo_vdpau.c	(revision 28986)
+++ libvo/vo_vdpau.c	(working copy)
@@ -148,12 +148,14 @@
 #define osd_surface output_surfaces[NUM_OUTPUT_SURFACES]
 static VdpOutputSurface                   output_surfaces[NUM_OUTPUT_SURFACES + 1];
 static VdpVideoSurface                    deint_surfaces[3];
+static mp_image_t                        *deint_mpi[3];
 static int                                output_surface_width, output_surface_height;
 
 static VdpVideoMixer                      video_mixer;
 static int                                deint;
 static int                                deint_type;
 static int                                deint_counter;
+static int                                deint_prepare;
 static int                                pullup;
 static float                              denoise;
 static float                              sharpen;
@@ -456,6 +458,12 @@
     for (i = 0; i < 3; i++)
         deint_surfaces[i] = VDP_INVALID_HANDLE;
 
+    for (i = 0; i < 3; i++)
+        if (deint_mpi[i]) {
+            deint_mpi[i]->usage_count--;
+            deint_mpi[i] = NULL;
+        }
+
     for (i = 0; i < MAX_VIDEO_SURFACES; i++) {
         if (surface_render[i].surface != VDP_INVALID_HANDLE) {
           vdp_st = vdp_video_surface_destroy(surface_render[i].surface);
@@ -848,7 +856,14 @@
     if (IMGFMT_IS_VDPAU(image_format)) {
         struct vdpau_render_state *rndr = mpi->priv;
         vid_surface_num = rndr - surface_render;
-        deint = FFMIN(deint, 2);
+        if (deint_prepare) {
+            mpi->usage_count++;
+            if (deint_mpi[2])
+                deint_mpi[2]->usage_count--;
+            deint_mpi[2] = deint_mpi[1];
+            deint_mpi[1] = deint_mpi[0];
+            deint_mpi[0] = mpi;
+        }
     } else if (!(mpi->flags & MP_IMGFLAG_DRAW_CALLBACK)) {
         VdpStatus vdp_st;
         void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]};
@@ -1007,6 +1022,8 @@
     deint = 0;
     deint_type = 3;
     deint_counter = 0;
+    deint_prepare = 0;
+    deint_mpi[0] = deint_mpi[1] = deint_mpi[2] = NULL;
     chroma_deint = 1;
     pullup = 0;
     denoise = 0;
@@ -1017,6 +1034,8 @@
     }
     if (deint)
         deint_type = deint;
+    if (deint > 2)
+        deint_prepare = 1;
 
     vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY);
     if (!vdpau_lib_handle) {
@@ -1122,6 +1141,7 @@
                                                              features,
                                                              feature_enables);
                 CHECK_ST_WARNING("Error changing deinterlacing settings")
+                deint_prepare = 1;
             }
             return VO_TRUE;
         case VOCTRL_PAUSE:


More information about the MPlayer-dev-eng mailing list