]> git.sesse.net Git - vlc/commitdiff
vaapi: prefer vaGetImage over vaDeriveImage under most circumstances.
authorJean-Yves Avenard <jyavenard@mythtv.org>
Sun, 15 Jun 2014 09:04:38 +0000 (09:04 +0000)
committerJean-Baptiste Kempf <jb@videolan.org>
Mon, 16 Jun 2014 07:50:24 +0000 (09:50 +0200)
While vaDeriveImage is slightly faster than vaGetImage, there's an added cost of having to convert NV12 into YV12 later, which in practice negates any benefits.
Prefer YV12 and YUV420 formats over NV12.
This decrease time to process a VAAPI frame by over 50%: from 2.1ms/frame to 0.9ms/frame on an i7-4650U

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/codec/avcodec/vaapi.c

index 1d8f7fa97b4d85b35601ed9caaaa0ff441aa7d4b..204e8dab1e3e0e218d4ccbb4803a9d202d7e36f9 100644 (file)
@@ -345,13 +345,16 @@ static int CreateSurfaces( vlc_va_sys_t *sys, void **pp_hw_ctx, vlc_fourcc_t *pi
     }
 
     VAImage test_image;
+    vlc_fourcc_t  deriveImageFormat = 0;
     if(vaDeriveImage(sys->p_display, pi_surface_id[0], &test_image) == VA_STATUS_SUCCESS)
     {
         sys->b_supports_derive = true;
+        deriveImageFormat = test_image.format.fourcc;
         vaDestroyImage(sys->p_display, test_image.image_id);
     }
 
     vlc_fourcc_t  i_chroma = 0;
+    int nv12support = -1;
     for( int i = 0; i < i_fmt_count; i++ )
     {
         if( p_fmt[i].fourcc == VA_FOURCC_YV12 ||
@@ -373,10 +376,34 @@ static int CreateSurfaces( vlc_va_sys_t *sys, void **pp_hw_ctx, vlc_fourcc_t *pi
                 continue;
             }
 
+            if( p_fmt[i].fourcc == VA_FOURCC_NV12 )
+            {
+                /* Mark NV12 as supported, but favor other formats first */
+                nv12support = i;
+                vaDestroyImage( sys->p_display, sys->image.image_id );
+                sys->image.image_id = VA_INVALID_ID;
+                continue;
+            }
             i_chroma = VLC_CODEC_YV12;
             break;
         }
     }
+
+    if( !i_chroma && nv12support >= 0 )
+    {
+        /* only nv12 is supported, so use that format */
+        if( vaCreateImage(  sys->p_display, &p_fmt[nv12support], i_width, i_height, &sys->image ) )
+        {
+            sys->image.image_id = VA_INVALID_ID;
+        }
+        i_chroma = VLC_CODEC_YV12;
+    }
+    else if( sys->b_supports_derive && deriveImageFormat != sys->image.format.fourcc )
+    {
+        /* only use vaDerive if it's giving us a format we handle natively */
+        sys->b_supports_derive = false;
+    }
+
     free( p_fmt );
     if( !i_chroma )
         goto error;