[1/2] vaapi_encode: Destroy output buffer pool before VA context

Message ID f7f4a721-397c-199e-2507-211681794d85@jkqxz.net
State Committed
Commit 216c44dfc17252ec0681dcb0bbeeb45a9d14eca7
Headers show

Commit Message

Mark Thompson Dec. 17, 2017, 8 p.m.
The buffers are created associated with the context, so they should be
destroyed before the context is.  This is enforced by the iHD driver.
---
(Causes a crash on close.)


 libavcodec/vaapi_encode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jun Zhao Dec. 18, 2017, 1:51 a.m. | #1
On 2017/12/18 4:00, Mark Thompson wrote:
> The buffers are created associated with the context, so they should be
> destroyed before the context is.  This is enforced by the iHD driver.
> ---
> (Causes a crash on close.)
>
>
>  libavcodec/vaapi_encode.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 47795ba73..fdc3d2a95 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -1536,6 +1536,8 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
>          vaapi_encode_free(avctx, pic);
>      }
>  
> +    av_buffer_pool_uninit(&ctx->output_buffer_pool);
> +
>      if (ctx->va_context != VA_INVALID_ID) {
>          vaDestroyContext(ctx->hwctx->display, ctx->va_context);
>          ctx->va_context = VA_INVALID_ID;
> @@ -1546,8 +1548,6 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
>          ctx->va_config = VA_INVALID_ID;
>      }
>  
> -    av_buffer_pool_uninit(&ctx->output_buffer_pool);
> -
>      av_freep(&ctx->codec_sequence_params);
>      av_freep(&ctx->codec_picture_params);
>  
I think is make sense, but Libva(VA-API) maybe need to update the
comments, and I think iHD will decouple the context and vabuffer when
need to destory.

Patch

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 47795ba73..fdc3d2a95 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -1536,6 +1536,8 @@  av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
         vaapi_encode_free(avctx, pic);
     }
 
+    av_buffer_pool_uninit(&ctx->output_buffer_pool);
+
     if (ctx->va_context != VA_INVALID_ID) {
         vaDestroyContext(ctx->hwctx->display, ctx->va_context);
         ctx->va_context = VA_INVALID_ID;
@@ -1546,8 +1548,6 @@  av_cold int ff_vaapi_encode_close(AVCodecContext *avctx)
         ctx->va_config = VA_INVALID_ID;
     }
 
-    av_buffer_pool_uninit(&ctx->output_buffer_pool);
-
     av_freep(&ctx->codec_sequence_params);
     av_freep(&ctx->codec_picture_params);