[FFmpeg-cvslog] vf_*_vaapi: Support increasing hardware frame pool size

Mark Thompson git at videolan.org
Tue Feb 13 00:49:56 EET 2018


ffmpeg | branch: master | Mark Thompson <sw at jkqxz.net> | Mon Mar 27 21:10:10 2017 +0100| [b128be1748f3920a14a98307265df5f2d3433e1d] | committer: Mark Thompson

vf_*_vaapi: Support increasing hardware frame pool size

Defaults to 10 frames to preserve compatibility, but can allocate
fewer if extra_hw_frames is set explicitly.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b128be1748f3920a14a98307265df5f2d3433e1d
---

 libavfilter/vf_deinterlace_vaapi.c | 39 +++++++++++++++--------------------
 libavfilter/vf_scale_vaapi.c       | 42 +++++++++++++++-----------------------
 2 files changed, 33 insertions(+), 48 deletions(-)

diff --git a/libavfilter/vf_deinterlace_vaapi.c b/libavfilter/vf_deinterlace_vaapi.c
index 95a0f40419..082df89147 100644
--- a/libavfilter/vf_deinterlace_vaapi.c
+++ b/libavfilter/vf_deinterlace_vaapi.c
@@ -53,8 +53,6 @@ typedef struct DeintVAAPIContext {
     AVBufferRef       *input_frames_ref;
     AVHWFramesContext *input_frames;
 
-    AVBufferRef       *output_frames_ref;
-    AVHWFramesContext *output_frames;
     int                output_height;
     int                output_width;
 
@@ -236,6 +234,7 @@ static int deint_vaapi_config_output(AVFilterLink *outlink)
     DeintVAAPIContext    *ctx = avctx->priv;
     AVVAAPIHWConfig *hwconfig = NULL;
     AVHWFramesConstraints *constraints = NULL;
+    AVHWFramesContext *output_frames;
     AVVAAPIFramesContext *va_frames;
     VAStatus vas;
     int err;
@@ -287,34 +286,35 @@ static int deint_vaapi_config_output(AVFilterLink *outlink)
         goto fail;
     }
 
-    ctx->output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
-    if (!ctx->output_frames_ref) {
+    outlink->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->device_ref);
+    if (!outlink->hw_frames_ctx) {
         av_log(avctx, AV_LOG_ERROR, "Failed to create HW frame context "
                "for output.\n");
         err = AVERROR(ENOMEM);
         goto fail;
     }
 
-    ctx->output_frames = (AVHWFramesContext*)ctx->output_frames_ref->data;
+    output_frames = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
 
-    ctx->output_frames->format    = AV_PIX_FMT_VAAPI;
-    ctx->output_frames->sw_format = ctx->input_frames->sw_format;
-    ctx->output_frames->width     = ctx->output_width;
-    ctx->output_frames->height    = ctx->output_height;
+    output_frames->format    = AV_PIX_FMT_VAAPI;
+    output_frames->sw_format = ctx->input_frames->sw_format;
+    output_frames->width     = ctx->output_width;
+    output_frames->height    = ctx->output_height;
 
-    // The number of output frames we need is determined by what follows
-    // the filter.  If it's an encoder with complex frame reference
-    // structures then this could be very high.
-    ctx->output_frames->initial_pool_size = 10;
+    output_frames->initial_pool_size = 4;
+
+    err = ff_filter_init_hw_frames(avctx, outlink, 10);
+    if (err < 0)
+        goto fail;
 
-    err = av_hwframe_ctx_init(ctx->output_frames_ref);
+    err = av_hwframe_ctx_init(outlink->hw_frames_ctx);
     if (err < 0) {
         av_log(avctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame "
                "context for output: %d\n", err);
         goto fail;
     }
 
-    va_frames = ctx->output_frames->hwctx;
+    va_frames = output_frames->hwctx;
 
     av_assert0(ctx->va_context == VA_INVALID_ID);
     vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
@@ -340,18 +340,12 @@ static int deint_vaapi_config_output(AVFilterLink *outlink)
     outlink->frame_rate = av_mul_q(inlink->frame_rate,
                                    (AVRational) { ctx->field_rate, 1 });
 
-    outlink->hw_frames_ctx = av_buffer_ref(ctx->output_frames_ref);
-    if (!outlink->hw_frames_ctx) {
-        err = AVERROR(ENOMEM);
-        goto fail;
-    }
-
     av_freep(&hwconfig);
     av_hwframe_constraints_free(&constraints);
     return 0;
 
 fail:
-    av_buffer_unref(&ctx->output_frames_ref);
+    av_buffer_unref(&outlink->hw_frames_ctx);
     av_freep(&hwconfig);
     av_hwframe_constraints_free(&constraints);
     return err;
@@ -601,7 +595,6 @@ static av_cold void deint_vaapi_uninit(AVFilterContext *avctx)
         deint_vaapi_pipeline_uninit(avctx);
 
     av_buffer_unref(&ctx->input_frames_ref);
-    av_buffer_unref(&ctx->output_frames_ref);
     av_buffer_unref(&ctx->device_ref);
 }
 
diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
index 4c8f2cf4ef..0ab5518b5f 100644
--- a/libavfilter/vf_scale_vaapi.c
+++ b/libavfilter/vf_scale_vaapi.c
@@ -22,6 +22,7 @@
 #include <va/va_vpp.h>
 
 #include "libavutil/avassert.h"
+#include "libavutil/common.h"
 #include "libavutil/hwcontext.h"
 #include "libavutil/hwcontext_vaapi.h"
 #include "libavutil/mem.h"
@@ -46,9 +47,6 @@ typedef struct ScaleVAAPIContext {
     AVBufferRef       *input_frames_ref;
     AVHWFramesContext *input_frames;
 
-    AVBufferRef       *output_frames_ref;
-    AVHWFramesContext *output_frames;
-
     char *output_format_string;
     enum AVPixelFormat output_format;
     int output_width;
@@ -83,7 +81,6 @@ static int scale_vaapi_pipeline_uninit(ScaleVAAPIContext *ctx)
         ctx->va_config = VA_INVALID_ID;
     }
 
-    av_buffer_unref(&ctx->output_frames_ref);
     av_buffer_unref(&ctx->device_ref);
     ctx->hwctx = 0;
 
@@ -115,6 +112,7 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
     ScaleVAAPIContext *ctx = avctx->priv;
     AVVAAPIHWConfig *hwconfig = NULL;
     AVHWFramesConstraints *constraints = NULL;
+    AVHWFramesContext *output_frames;
     AVVAAPIFramesContext *va_frames;
     VAStatus vas;
     int err, i;
@@ -176,34 +174,35 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
         goto fail;
     }
 
-    ctx->output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
-    if (!ctx->output_frames_ref) {
+    outlink->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->device_ref);
+    if (!outlink->hw_frames_ctx) {
         av_log(ctx, AV_LOG_ERROR, "Failed to create HW frame context "
                "for output.\n");
         err = AVERROR(ENOMEM);
         goto fail;
     }
 
-    ctx->output_frames = (AVHWFramesContext*)ctx->output_frames_ref->data;
+    output_frames = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
+
+    output_frames->format    = AV_PIX_FMT_VAAPI;
+    output_frames->sw_format = ctx->output_format;
+    output_frames->width     = ctx->output_width;
+    output_frames->height    = ctx->output_height;
 
-    ctx->output_frames->format    = AV_PIX_FMT_VAAPI;
-    ctx->output_frames->sw_format = ctx->output_format;
-    ctx->output_frames->width     = ctx->output_width;
-    ctx->output_frames->height    = ctx->output_height;
+    output_frames->initial_pool_size = 4;
 
-    // The number of output frames we need is determined by what follows
-    // the filter.  If it's an encoder with complex frame reference
-    // structures then this could be very high.
-    ctx->output_frames->initial_pool_size = 10;
+    err = ff_filter_init_hw_frames(avctx, outlink, 10);
+    if (err < 0)
+        goto fail;
 
-    err = av_hwframe_ctx_init(ctx->output_frames_ref);
+    err = av_hwframe_ctx_init(outlink->hw_frames_ctx);
     if (err < 0) {
         av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame "
                "context for output: %d\n", err);
         goto fail;
     }
 
-    va_frames = ctx->output_frames->hwctx;
+    va_frames = output_frames->hwctx;
 
     av_assert0(ctx->va_context == VA_INVALID_ID);
     vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
@@ -220,18 +219,12 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
     outlink->w = ctx->output_width;
     outlink->h = ctx->output_height;
 
-    outlink->hw_frames_ctx = av_buffer_ref(ctx->output_frames_ref);
-    if (!outlink->hw_frames_ctx) {
-        err = AVERROR(ENOMEM);
-        goto fail;
-    }
-
     av_freep(&hwconfig);
     av_hwframe_constraints_free(&constraints);
     return 0;
 
 fail:
-    av_buffer_unref(&ctx->output_frames_ref);
+    av_buffer_unref(&outlink->hw_frames_ctx);
     av_freep(&hwconfig);
     av_hwframe_constraints_free(&constraints);
     return err;
@@ -410,7 +403,6 @@ static av_cold void scale_vaapi_uninit(AVFilterContext *avctx)
         scale_vaapi_pipeline_uninit(ctx);
 
     av_buffer_unref(&ctx->input_frames_ref);
-    av_buffer_unref(&ctx->output_frames_ref);
     av_buffer_unref(&ctx->device_ref);
 }
 



More information about the ffmpeg-cvslog mailing list