summaryrefslogtreecommitdiff
path: root/libavfilter/vf_scale_vaapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavfilter/vf_scale_vaapi.c')
-rw-r--r--libavfilter/vf_scale_vaapi.c42
1 files changed, 17 insertions, 25 deletions
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);
}