Commit b128be17 authored by Mark Thompson's avatar 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.
parent 6d86cef0
...@@ -53,8 +53,6 @@ typedef struct DeintVAAPIContext { ...@@ -53,8 +53,6 @@ typedef struct DeintVAAPIContext {
AVBufferRef *input_frames_ref; AVBufferRef *input_frames_ref;
AVHWFramesContext *input_frames; AVHWFramesContext *input_frames;
AVBufferRef *output_frames_ref;
AVHWFramesContext *output_frames;
int output_height; int output_height;
int output_width; int output_width;
...@@ -236,6 +234,7 @@ static int deint_vaapi_config_output(AVFilterLink *outlink) ...@@ -236,6 +234,7 @@ static int deint_vaapi_config_output(AVFilterLink *outlink)
DeintVAAPIContext *ctx = avctx->priv; DeintVAAPIContext *ctx = avctx->priv;
AVVAAPIHWConfig *hwconfig = NULL; AVVAAPIHWConfig *hwconfig = NULL;
AVHWFramesConstraints *constraints = NULL; AVHWFramesConstraints *constraints = NULL;
AVHWFramesContext *output_frames;
AVVAAPIFramesContext *va_frames; AVVAAPIFramesContext *va_frames;
VAStatus vas; VAStatus vas;
int err; int err;
...@@ -287,34 +286,35 @@ static int deint_vaapi_config_output(AVFilterLink *outlink) ...@@ -287,34 +286,35 @@ static int deint_vaapi_config_output(AVFilterLink *outlink)
goto fail; goto fail;
} }
ctx->output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref); outlink->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->device_ref);
if (!ctx->output_frames_ref) { if (!outlink->hw_frames_ctx) {
av_log(avctx, AV_LOG_ERROR, "Failed to create HW frame context " av_log(avctx, AV_LOG_ERROR, "Failed to create HW frame context "
"for output.\n"); "for output.\n");
err = AVERROR(ENOMEM); err = AVERROR(ENOMEM);
goto fail; 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; output_frames->format = AV_PIX_FMT_VAAPI;
ctx->output_frames->sw_format = ctx->input_frames->sw_format; output_frames->sw_format = ctx->input_frames->sw_format;
ctx->output_frames->width = ctx->output_width; output_frames->width = ctx->output_width;
ctx->output_frames->height = ctx->output_height; output_frames->height = ctx->output_height;
// The number of output frames we need is determined by what follows output_frames->initial_pool_size = 4;
// the filter. If it's an encoder with complex frame reference
// structures then this could be very high. err = ff_filter_init_hw_frames(avctx, outlink, 10);
ctx->output_frames->initial_pool_size = 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) { if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame " av_log(avctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame "
"context for output: %d\n", err); "context for output: %d\n", err);
goto fail; goto fail;
} }
va_frames = ctx->output_frames->hwctx; va_frames = output_frames->hwctx;
av_assert0(ctx->va_context == VA_INVALID_ID); av_assert0(ctx->va_context == VA_INVALID_ID);
vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
...@@ -340,18 +340,12 @@ static int deint_vaapi_config_output(AVFilterLink *outlink) ...@@ -340,18 +340,12 @@ static int deint_vaapi_config_output(AVFilterLink *outlink)
outlink->frame_rate = av_mul_q(inlink->frame_rate, outlink->frame_rate = av_mul_q(inlink->frame_rate,
(AVRational) { ctx->field_rate, 1 }); (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_freep(&hwconfig);
av_hwframe_constraints_free(&constraints); av_hwframe_constraints_free(&constraints);
return 0; return 0;
fail: fail:
av_buffer_unref(&ctx->output_frames_ref); av_buffer_unref(&outlink->hw_frames_ctx);
av_freep(&hwconfig); av_freep(&hwconfig);
av_hwframe_constraints_free(&constraints); av_hwframe_constraints_free(&constraints);
return err; return err;
...@@ -601,7 +595,6 @@ static av_cold void deint_vaapi_uninit(AVFilterContext *avctx) ...@@ -601,7 +595,6 @@ static av_cold void deint_vaapi_uninit(AVFilterContext *avctx)
deint_vaapi_pipeline_uninit(avctx); deint_vaapi_pipeline_uninit(avctx);
av_buffer_unref(&ctx->input_frames_ref); av_buffer_unref(&ctx->input_frames_ref);
av_buffer_unref(&ctx->output_frames_ref);
av_buffer_unref(&ctx->device_ref); av_buffer_unref(&ctx->device_ref);
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <va/va_vpp.h> #include <va/va_vpp.h>
#include "libavutil/avassert.h" #include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/hwcontext.h" #include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_vaapi.h" #include "libavutil/hwcontext_vaapi.h"
#include "libavutil/mem.h" #include "libavutil/mem.h"
...@@ -46,9 +47,6 @@ typedef struct ScaleVAAPIContext { ...@@ -46,9 +47,6 @@ typedef struct ScaleVAAPIContext {
AVBufferRef *input_frames_ref; AVBufferRef *input_frames_ref;
AVHWFramesContext *input_frames; AVHWFramesContext *input_frames;
AVBufferRef *output_frames_ref;
AVHWFramesContext *output_frames;
char *output_format_string; char *output_format_string;
enum AVPixelFormat output_format; enum AVPixelFormat output_format;
int output_width; int output_width;
...@@ -83,7 +81,6 @@ static int scale_vaapi_pipeline_uninit(ScaleVAAPIContext *ctx) ...@@ -83,7 +81,6 @@ static int scale_vaapi_pipeline_uninit(ScaleVAAPIContext *ctx)
ctx->va_config = VA_INVALID_ID; ctx->va_config = VA_INVALID_ID;
} }
av_buffer_unref(&ctx->output_frames_ref);
av_buffer_unref(&ctx->device_ref); av_buffer_unref(&ctx->device_ref);
ctx->hwctx = 0; ctx->hwctx = 0;
...@@ -115,6 +112,7 @@ static int scale_vaapi_config_output(AVFilterLink *outlink) ...@@ -115,6 +112,7 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
ScaleVAAPIContext *ctx = avctx->priv; ScaleVAAPIContext *ctx = avctx->priv;
AVVAAPIHWConfig *hwconfig = NULL; AVVAAPIHWConfig *hwconfig = NULL;
AVHWFramesConstraints *constraints = NULL; AVHWFramesConstraints *constraints = NULL;
AVHWFramesContext *output_frames;
AVVAAPIFramesContext *va_frames; AVVAAPIFramesContext *va_frames;
VAStatus vas; VAStatus vas;
int err, i; int err, i;
...@@ -176,34 +174,35 @@ static int scale_vaapi_config_output(AVFilterLink *outlink) ...@@ -176,34 +174,35 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
goto fail; goto fail;
} }
ctx->output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref); outlink->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->device_ref);
if (!ctx->output_frames_ref) { if (!outlink->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "Failed to create HW frame context " av_log(ctx, AV_LOG_ERROR, "Failed to create HW frame context "
"for output.\n"); "for output.\n");
err = AVERROR(ENOMEM); err = AVERROR(ENOMEM);
goto fail; 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; output_frames->initial_pool_size = 4;
ctx->output_frames->sw_format = ctx->output_format;
ctx->output_frames->width = ctx->output_width;
ctx->output_frames->height = ctx->output_height;
// The number of output frames we need is determined by what follows err = ff_filter_init_hw_frames(avctx, outlink, 10);
// the filter. If it's an encoder with complex frame reference if (err < 0)
// structures then this could be very high. goto fail;
ctx->output_frames->initial_pool_size = 10;
err = av_hwframe_ctx_init(ctx->output_frames_ref); err = av_hwframe_ctx_init(outlink->hw_frames_ctx);
if (err < 0) { if (err < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame " av_log(ctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame "
"context for output: %d\n", err); "context for output: %d\n", err);
goto fail; goto fail;
} }
va_frames = ctx->output_frames->hwctx; va_frames = output_frames->hwctx;
av_assert0(ctx->va_context == VA_INVALID_ID); av_assert0(ctx->va_context == VA_INVALID_ID);
vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
...@@ -220,18 +219,12 @@ static int scale_vaapi_config_output(AVFilterLink *outlink) ...@@ -220,18 +219,12 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
outlink->w = ctx->output_width; outlink->w = ctx->output_width;
outlink->h = ctx->output_height; 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_freep(&hwconfig);
av_hwframe_constraints_free(&constraints); av_hwframe_constraints_free(&constraints);
return 0; return 0;
fail: fail:
av_buffer_unref(&ctx->output_frames_ref); av_buffer_unref(&outlink->hw_frames_ctx);
av_freep(&hwconfig); av_freep(&hwconfig);
av_hwframe_constraints_free(&constraints); av_hwframe_constraints_free(&constraints);
return err; return err;
...@@ -410,7 +403,6 @@ static av_cold void scale_vaapi_uninit(AVFilterContext *avctx) ...@@ -410,7 +403,6 @@ static av_cold void scale_vaapi_uninit(AVFilterContext *avctx)
scale_vaapi_pipeline_uninit(ctx); scale_vaapi_pipeline_uninit(ctx);
av_buffer_unref(&ctx->input_frames_ref); av_buffer_unref(&ctx->input_frames_ref);
av_buffer_unref(&ctx->output_frames_ref);
av_buffer_unref(&ctx->device_ref); av_buffer_unref(&ctx->device_ref);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment