[vlc-devel] [PATCH 2/2] vaapi: prefer vaGetImage over vaDeriveImage under most circumstances.
Jean-Yves Avenard
jyavenard at gmail.com
Sun Jun 15 12:04:38 CEST 2014
From: Jean-Yves Avenard <jyavenard at mythtv.org>
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
---
modules/codec/avcodec/vaapi.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index 1d8f7fa..204e8da 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -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;
--
1.9.1
More information about the vlc-devel
mailing list