lavfi: move AVFilterLink.hw_frames_ctx to FilterLink

This commit is contained in:
Anton Khirnov 2024-08-05 18:00:30 +02:00
parent ce24b5ba8f
commit 7f17e0e6dd
42 changed files with 326 additions and 193 deletions

View File

@ -206,6 +206,8 @@ static void link_free(AVFilterLink **link)
ff_frame_pool_uninit(&li->frame_pool);
av_channel_layout_uninit(&(*link)->ch_layout);
av_buffer_unref(&li->l.hw_frames_ctx);
av_freep(link);
}
@ -411,13 +413,18 @@ int ff_filter_config_links(AVFilterContext *filter)
link->time_base = (AVRational) {1, link->sample_rate};
}
if (link->src->nb_inputs && link->src->inputs[0]->hw_frames_ctx &&
if (link->src->nb_inputs &&
!(link->src->filter->flags_internal & FF_FILTER_FLAG_HWFRAME_AWARE)) {
av_assert0(!link->hw_frames_ctx &&
FilterLink *l0 = ff_filter_link(link->src->inputs[0]);
av_assert0(!li->l.hw_frames_ctx &&
"should not be set by non-hwframe-aware filter");
link->hw_frames_ctx = av_buffer_ref(link->src->inputs[0]->hw_frames_ctx);
if (!link->hw_frames_ctx)
return AVERROR(ENOMEM);
if (l0->hw_frames_ctx) {
li->l.hw_frames_ctx = av_buffer_ref(l0->hw_frames_ctx);
if (!li->l.hw_frames_ctx)
return AVERROR(ENOMEM);
}
}
if ((config_link = link->dstpad->config_props))
@ -765,8 +772,6 @@ static void free_link(AVFilterLink *link)
if (link->dst)
link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
av_buffer_unref(&link->hw_frames_ctx);
ff_formats_unref(&link->incfg.formats);
ff_formats_unref(&link->outcfg.formats);
ff_formats_unref(&link->incfg.color_spaces);
@ -1615,12 +1620,13 @@ const AVClass *avfilter_get_class(void)
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
int default_pool_size)
{
FilterLink *l = ff_filter_link(link);
AVHWFramesContext *frames;
// Must already be set by caller.
av_assert0(link->hw_frames_ctx);
av_assert0(l->hw_frames_ctx);
frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
frames = (AVHWFramesContext*)l->hw_frames_ctx->data;
if (frames->initial_pool_size == 0) {
// Dynamic allocation is necessarily supported.

View File

@ -641,12 +641,6 @@ struct AVFilterLink {
* cleared when a frame is filtered.
*/
int frame_wanted_out;
/**
* For hwaccel pixel formats, this should be a reference to the
* AVHWFramesContext describing the frames.
*/
AVBufferRef *hw_frames_ctx;
};
/**

View File

@ -188,7 +188,12 @@ MAKE_AVFILTERLINK_ACCESSOR(enum AVColorRange, color_range)
MAKE_AVFILTERLINK_ACCESSOR(int , sample_rate )
MAKE_AVFILTERLINK_ACCESSOR(AVBufferRef * , hw_frames_ctx )
AVBufferRef* av_buffersink_get_hw_frames_ctx(const AVFilterContext *ctx)
{
FilterLink *l = ff_filter_link(ctx->inputs[0]);
av_assert0(ctx->filter->activate == activate);
return l->hw_frames_ctx;
}
int av_buffersink_get_channels(const AVFilterContext *ctx)
{

View File

@ -493,6 +493,7 @@ static int query_formats(AVFilterContext *ctx)
static int config_props(AVFilterLink *link)
{
FilterLink *l = ff_filter_link(link);
BufferSourceContext *c = link->src->priv;
switch (link->type) {
@ -502,8 +503,8 @@ static int config_props(AVFilterLink *link)
link->sample_aspect_ratio = c->pixel_aspect;
if (c->hw_frames_ctx) {
link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx);
if (!link->hw_frames_ctx)
l->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx);
if (!l->hw_frames_ctx)
return AVERROR(ENOMEM);
}
break;

View File

@ -57,6 +57,14 @@ typedef struct FilterLink {
* May be set by the link destination filter in its config_props().
*/
int max_samples;
/**
* For hwaccel pixel formats, this should be a reference to the
* AVHWFramesContext describing the frames.
*
* May be set by the link source filter in its config_props().
*/
AVBufferRef *hw_frames_ctx;
} FilterLink;
static inline FilterLink* ff_filter_link(AVFilterLink *link)

View File

@ -23,6 +23,7 @@
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "filters.h"
#include "opencl.h"
static int opencl_filter_set_device(AVFilterContext *avctx,
@ -44,12 +45,13 @@ static int opencl_filter_set_device(AVFilterContext *avctx,
int ff_opencl_filter_config_input(AVFilterLink *inlink)
{
FilterLink *l = ff_filter_link(inlink);
AVFilterContext *avctx = inlink->dst;
OpenCLFilterContext *ctx = avctx->priv;
AVHWFramesContext *input_frames;
int err;
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(avctx, AV_LOG_ERROR, "OpenCL filtering requires a "
"hardware frames context on the input.\n");
return AVERROR(EINVAL);
@ -59,7 +61,7 @@ int ff_opencl_filter_config_input(AVFilterLink *inlink)
if (avctx->inputs[0] != inlink)
return 0;
input_frames = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
input_frames = (AVHWFramesContext*)l->hw_frames_ctx->data;
if (input_frames->format != AV_PIX_FMT_OPENCL)
return AVERROR(EINVAL);
@ -80,13 +82,14 @@ int ff_opencl_filter_config_input(AVFilterLink *inlink)
int ff_opencl_filter_config_output(AVFilterLink *outlink)
{
FilterLink *l = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
OpenCLFilterContext *ctx = avctx->priv;
AVBufferRef *output_frames_ref = NULL;
AVHWFramesContext *output_frames;
int err;
av_buffer_unref(&outlink->hw_frames_ctx);
av_buffer_unref(&l->hw_frames_ctx);
if (!ctx->device_ref) {
if (!avctx->hw_device_ctx) {
@ -119,7 +122,7 @@ int ff_opencl_filter_config_output(AVFilterLink *outlink)
goto fail;
}
outlink->hw_frames_ctx = output_frames_ref;
l->hw_frames_ctx = output_frames_ref;
outlink->w = ctx->output_width;
outlink->h = ctx->output_height;

View File

@ -28,6 +28,7 @@
#include "libavutil/pixdesc.h"
#include "internal.h"
#include "filters.h"
#include "qsvvpp.h"
#include "video.h"
@ -303,10 +304,11 @@ static int fill_frameinfo_by_link(mfxFrameInfo *frameinfo, AVFilterLink *link)
const AVPixFmtDescriptor *desc;
if (link->format == AV_PIX_FMT_QSV) {
if (!link->hw_frames_ctx)
FilterLink *l = ff_filter_link(link);
if (!l->hw_frames_ctx)
return AVERROR(EINVAL);
frames_ctx = (AVHWFramesContext *)link->hw_frames_ctx->data;
frames_ctx = (AVHWFramesContext *)l->hw_frames_ctx->data;
frames_hwctx = frames_ctx->hwctx;
*frameinfo = frames_hwctx->nb_surfaces ? frames_hwctx->surfaces[0].Info : *frames_hwctx->info;
} else {
@ -472,6 +474,7 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p
/* get the output surface */
static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink, const AVFrame *in)
{
FilterLink *l = ff_filter_link(outlink);
AVFilterContext *ctx = outlink->src;
QSVFrame *out_frame;
int ret;
@ -489,7 +492,7 @@ static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink, const AVFr
if (!out_frame->frame)
return NULL;
ret = av_hwframe_get_buffer(outlink->hw_frames_ctx, out_frame->frame, 0);
ret = av_hwframe_get_buffer(l->hw_frames_ctx, out_frame->frame, 0);
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Can't allocate a surface.\n");
return NULL;
@ -546,7 +549,9 @@ FF_ENABLE_DEPRECATION_WARNINGS
static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
{
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
AVFilterLink *outlink = avctx->outputs[0];
FilterLink *outl = ff_filter_link(outlink);
AVQSVFramesContext *in_frames_hwctx = NULL;
AVQSVFramesContext *out_frames_hwctx = NULL;
@ -559,8 +564,8 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
mfxIMPL impl;
int ret, i;
if (inlink->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
if (inl->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
device_ref = frames_ctx->device_ref;
in_frames_hwctx = frames_ctx->hwctx;
@ -657,8 +662,8 @@ static int init_vpp_session(AVFilterContext *avctx, QSVVPPContext *s)
s->surface_ptrs_out[i] = out_frames_hwctx->surfaces + i;
s->nb_surface_ptrs_out = out_frames_hwctx->nb_surfaces;
av_buffer_unref(&outlink->hw_frames_ctx);
outlink->hw_frames_ctx = out_frames_ref;
av_buffer_unref(&outl->hw_frames_ctx);
outl->hw_frames_ctx = out_frames_ref;
} else
s->out_mem_mode = MFX_MEMTYPE_SYSTEM_MEMORY;

View File

@ -21,6 +21,8 @@
#include "libavutil/avassert.h"
#include "libavutil/mem.h"
#include "libavutil/pixdesc.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "vaapi_vpp.h"
@ -74,19 +76,20 @@ void ff_vaapi_vpp_pipeline_uninit(AVFilterContext *avctx)
int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
{
FilterLink *l = ff_filter_link(inlink);
AVFilterContext *avctx = inlink->dst;
VAAPIVPPContext *ctx = avctx->priv;
if (ctx->pipeline_uninit)
ctx->pipeline_uninit(avctx);
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is "
"required to associate the processing device.\n");
return AVERROR(EINVAL);
}
ctx->input_frames_ref = av_buffer_ref(inlink->hw_frames_ctx);
ctx->input_frames_ref = av_buffer_ref(l->hw_frames_ctx);
if (!ctx->input_frames_ref) {
av_log(avctx, AV_LOG_ERROR, "A input frames reference create "
"failed.\n");
@ -99,8 +102,10 @@ int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
VAAPIVPPContext *ctx = avctx->priv;
AVVAAPIHWConfig *hwconfig = NULL;
AVHWFramesConstraints *constraints = NULL;
@ -121,8 +126,8 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
outlink->h = ctx->output_height;
if (ctx->passthrough) {
if (inlink->hw_frames_ctx)
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
if (inl->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
av_log(ctx, AV_LOG_VERBOSE, "Using VAAPI filter passthrough mode.\n");
return 0;
@ -189,15 +194,15 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
goto fail;
}
outlink->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->device_ref);
if (!outlink->hw_frames_ctx) {
outl->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->device_ref);
if (!outl->hw_frames_ctx) {
av_log(avctx, AV_LOG_ERROR, "Failed to create HW frame context "
"for output.\n");
err = AVERROR(ENOMEM);
goto fail;
}
output_frames = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
output_frames = (AVHWFramesContext*)outl->hw_frames_ctx->data;
output_frames->format = AV_PIX_FMT_VAAPI;
output_frames->sw_format = ctx->output_format;
@ -213,7 +218,7 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
if (err < 0)
goto fail;
err = av_hwframe_ctx_init(outlink->hw_frames_ctx);
err = av_hwframe_ctx_init(outl->hw_frames_ctx);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame "
"context for output: %d\n", err);
@ -247,7 +252,7 @@ int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
return 0;
fail:
av_buffer_unref(&outlink->hw_frames_ctx);
av_buffer_unref(&outl->hw_frames_ctx);
av_freep(&hwconfig);
av_hwframe_constraints_free(&constraints);
return err;

View File

@ -30,6 +30,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "cuda/load_helper.h"
@ -178,16 +179,18 @@ static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int height)
{
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
CUDABilateralContext *s = ctx->priv;
AVHWFramesContext *in_frames_ctx;
int ret;
/* check that we have a hw context */
if (!ctx->inputs[0]->hw_frames_ctx) {
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
return AVERROR(EINVAL);
}
in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
in_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
if (!format_is_supported(in_frames_ctx->sw_format)) {
av_log(ctx, AV_LOG_ERROR, "Unsupported format: %s\n", av_get_pix_fmt_name(in_frames_ctx->sw_format));
@ -200,8 +203,8 @@ static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int he
if (ret < 0)
return ret;
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!ctx->outputs[0]->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;
@ -248,6 +251,7 @@ static av_cold int cuda_bilateral_config_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = outlink->src->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
CUDABilateralContext *s = ctx->priv;
AVHWFramesContext *frames_ctx;
AVCUDADeviceContext *device_hwctx;
@ -257,7 +261,7 @@ static av_cold int cuda_bilateral_config_props(AVFilterLink *outlink)
if (ret < 0)
return ret;
frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
device_hwctx = frames_ctx->device_ctx->hwctx;
s->hwctx = device_hwctx;

View File

@ -22,6 +22,8 @@
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_cuda_internal.h"
#include "libavutil/cuda_check.h"
#include "filters.h"
#include "internal.h"
#include "yadif.h"
@ -217,16 +219,17 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
{
FilterLink *l = ff_filter_link(inlink);
AVFilterContext *ctx = inlink->dst;
DeintCUDAContext *s = ctx->priv;
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "A hardware frames reference is "
"required to associate the processing device.\n");
return AVERROR(EINVAL);
}
s->input_frames_ref = av_buffer_ref(inlink->hw_frames_ctx);
s->input_frames_ref = av_buffer_ref(l->hw_frames_ctx);
if (!s->input_frames_ref) {
av_log(ctx, AV_LOG_ERROR, "A input frames reference create "
"failed.\n");
@ -239,6 +242,7 @@ static int config_input(AVFilterLink *inlink)
static int config_output(AVFilterLink *link)
{
FilterLink *l = ff_filter_link(link);
AVHWFramesContext *output_frames;
AVFilterContext *ctx = link->src;
DeintCUDAContext *s = ctx->priv;
@ -257,15 +261,15 @@ static int config_output(AVFilterLink *link)
s->hwctx = ((AVHWDeviceContext*)s->device_ref->data)->hwctx;
cu = s->hwctx->internal->cuda_dl;
link->hw_frames_ctx = av_hwframe_ctx_alloc(s->device_ref);
if (!link->hw_frames_ctx) {
l->hw_frames_ctx = av_hwframe_ctx_alloc(s->device_ref);
if (!l->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "Failed to create HW frame context "
"for output.\n");
ret = AVERROR(ENOMEM);
goto exit;
}
output_frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
output_frames = (AVHWFramesContext*)l->hw_frames_ctx->data;
output_frames->format = AV_PIX_FMT_CUDA;
output_frames->sw_format = s->input_frames->sw_format;
@ -278,7 +282,7 @@ static int config_output(AVFilterLink *link)
if (ret < 0)
goto exit;
ret = av_hwframe_ctx_init(link->hw_frames_ctx);
ret = av_hwframe_ctx_init(l->hw_frames_ctx);
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to initialise CUDA frame "
"context for output: %d\n", ret);

View File

@ -26,6 +26,7 @@
#include "vulkan_spirv.h"
#include "yadif.h"
#include "internal.h"
#include "filters.h"
typedef struct BWDIFVulkanContext {
YADIFContext yadif;
@ -303,18 +304,19 @@ static void bwdif_vulkan_uninit(AVFilterContext *avctx)
static int bwdif_vulkan_config_input(AVFilterLink *inlink)
{
FilterLink *l = ff_filter_link(inlink);
AVHWFramesContext *input_frames;
AVFilterContext *avctx = inlink->dst;
BWDIFVulkanContext *s = avctx->priv;
FFVulkanContext *vkctx = &s->vkctx;
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(inlink->dst, AV_LOG_ERROR, "Vulkan filtering requires a "
"hardware frames context on the input.\n");
return AVERROR(EINVAL);
}
input_frames = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
input_frames = (AVHWFramesContext *)l->hw_frames_ctx->data;
if (input_frames->format != AV_PIX_FMT_VULKAN)
return AVERROR(EINVAL);
@ -323,7 +325,7 @@ static int bwdif_vulkan_config_input(AVFilterLink *inlink)
return 0;
/* Save the ref, without reffing it */
vkctx->input_frames_ref = inlink->hw_frames_ctx;
vkctx->input_frames_ref = l->hw_frames_ctx;
/* Defaults */
vkctx->output_format = input_frames->sw_format;
@ -335,13 +337,14 @@ static int bwdif_vulkan_config_input(AVFilterLink *inlink)
static int bwdif_vulkan_config_output(AVFilterLink *outlink)
{
FilterLink *l = ff_filter_link(outlink);
int err;
AVFilterContext *avctx = outlink->src;
BWDIFVulkanContext *s = avctx->priv;
YADIFContext *y = &s->yadif;
FFVulkanContext *vkctx = &s->vkctx;
av_buffer_unref(&outlink->hw_frames_ctx);
av_buffer_unref(&l->hw_frames_ctx);
err = ff_vk_filter_init_context(avctx, vkctx, vkctx->input_frames_ref,
vkctx->output_width, vkctx->output_height,
@ -352,8 +355,8 @@ static int bwdif_vulkan_config_output(AVFilterLink *outlink)
/* For logging */
vkctx->class = y->class;
outlink->hw_frames_ctx = av_buffer_ref(vkctx->frames_ref);
if (!outlink->hw_frames_ctx)
l->hw_frames_ctx = av_buffer_ref(vkctx->frames_ref);
if (!l->hw_frames_ctx)
return AVERROR(ENOMEM);
err = ff_yadif_config_output_common(outlink);

View File

@ -30,6 +30,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "cuda/load_helper.h"
@ -180,17 +181,18 @@ static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_
static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int height)
{
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
ChromakeyCUDAContext *s = ctx->priv;
AVHWFramesContext *in_frames_ctx;
int ret;
/* check that we have a hw context */
if (!ctx->inputs[0]->hw_frames_ctx)
{
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
return AVERROR(EINVAL);
}
in_frames_ctx = (AVHWFramesContext *)ctx->inputs[0]->hw_frames_ctx->data;
in_frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
if (!format_is_supported(in_frames_ctx->sw_format))
{
@ -204,8 +206,8 @@ static av_cold int init_processing_chain(AVFilterContext *ctx, int width, int he
if (ret < 0)
return ret;
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!ctx->outputs[0]->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;
@ -258,6 +260,7 @@ static av_cold int cudachromakey_config_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = outlink->src->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
ChromakeyCUDAContext *s = ctx->priv;
AVHWFramesContext *frames_ctx;
AVCUDADeviceContext *device_hwctx;
@ -275,7 +278,7 @@ static av_cold int cudachromakey_config_props(AVFilterLink *outlink)
if (ret < 0)
return ret;
frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
frames_ctx = (AVHWFramesContext *)inl->hw_frames_ctx->data;
device_hwctx = frames_ctx->device_ctx->hwctx;
s->hwctx = device_hwctx;

View File

@ -31,6 +31,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "cuda/load_helper.h"
@ -151,17 +152,19 @@ static int format_is_supported(enum AVPixelFormat fmt)
static av_cold int init_processing_chain(AVFilterContext* ctx, int width,
int height)
{
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
CUDAColorspaceContext* s = ctx->priv;
AVHWFramesContext* in_frames_ctx;
int ret;
if (!ctx->inputs[0]->hw_frames_ctx) {
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
return AVERROR(EINVAL);
}
in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
in_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
s->pix_fmt = in_frames_ctx->sw_format;
if (!format_is_supported(s->pix_fmt)) {
@ -181,8 +184,8 @@ static av_cold int init_processing_chain(AVFilterContext* ctx, int width,
if (ret < 0)
return ret;
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!ctx->outputs[0]->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;
@ -225,6 +228,7 @@ static av_cold int cudacolorspace_config_props(AVFilterLink* outlink)
{
AVFilterContext* ctx = outlink->src;
AVFilterLink* inlink = outlink->src->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
CUDAColorspaceContext* s = ctx->priv;
AVHWFramesContext* frames_ctx;
AVCUDADeviceContext* device_hwctx;
@ -237,7 +241,7 @@ static av_cold int cudacolorspace_config_props(AVFilterLink* outlink)
if (ret < 0)
return ret;
frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
device_hwctx = frames_ctx->device_ctx->hwctx;
s->hwctx = device_hwctx;

View File

@ -1112,6 +1112,7 @@ static int deshake_opencl_init(AVFilterContext *avctx)
DeshakeOpenCLContext *ctx = avctx->priv;
AVFilterLink *outlink = avctx->outputs[0];
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
// Pointer to the host-side pattern buffer to be initialized and then copied
// to the GPU
PointPair *pattern_host = NULL;
@ -1146,7 +1147,7 @@ static int deshake_opencl_init(AVFilterContext *avctx)
const int descriptor_buf_size = image_grid_32 * (BREIFN / 8);
const int features_buf_size = image_grid_32 * sizeof(cl_float2);
const AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
const AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hw_frames_ctx->sw_format);
av_assert0(hw_frames_ctx);

View File

@ -24,6 +24,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
@ -50,18 +51,19 @@ static int hwdownload_query_formats(AVFilterContext *avctx)
static int hwdownload_config_input(AVFilterLink *inlink)
{
FilterLink *l = ff_filter_link(inlink);
AVFilterContext *avctx = inlink->dst;
HWDownloadContext *ctx = avctx->priv;
av_buffer_unref(&ctx->hwframes_ref);
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "The input must have a hardware frame "
"reference.\n");
return AVERROR(EINVAL);
}
ctx->hwframes_ref = av_buffer_ref(inlink->hw_frames_ctx);
ctx->hwframes_ref = av_buffer_ref(l->hw_frames_ctx);
if (!ctx->hwframes_ref)
return AVERROR(ENOMEM);

View File

@ -23,6 +23,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
@ -52,9 +53,11 @@ static int hwmap_query_formats(AVFilterContext *avctx)
static int hwmap_config_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
HWMapContext *ctx = avctx->priv;
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
AVHWFramesContext *hwfc;
AVBufferRef *device;
const AVPixFmtDescriptor *desc;
@ -69,8 +72,8 @@ static int hwmap_config_output(AVFilterLink *outlink)
device = avctx->hw_device_ctx;
device_is_derived = 0;
if (inlink->hw_frames_ctx) {
hwfc = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
if (inl->hw_frames_ctx) {
hwfc = (AVHWFramesContext*)inl->hw_frames_ctx->data;
if (ctx->derive_device_type) {
enum AVHWDeviceType type;
@ -114,7 +117,7 @@ static int hwmap_config_output(AVFilterLink *outlink)
err = av_hwframe_ctx_create_derived(&ctx->hwframes_ref,
outlink->format,
device,
inlink->hw_frames_ctx,
inl->hw_frames_ctx,
ctx->mode);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to create derived "
@ -171,8 +174,8 @@ static int hwmap_config_output(AVFilterLink *outlink)
// the format it expects. If there were any additional
// constraints on the output frames there then this may
// break nastily.
av_buffer_unref(&inlink->hw_frames_ctx);
inlink->hw_frames_ctx = source;
av_buffer_unref(&inl->hw_frames_ctx);
inl->hw_frames_ctx = source;
} else if ((outlink->format == hwfc->format &&
inlink->format == hwfc->sw_format) ||
@ -180,7 +183,7 @@ static int hwmap_config_output(AVFilterLink *outlink)
// Map from a hardware format to a software format, or
// undo an existing such mapping.
ctx->hwframes_ref = av_buffer_ref(inlink->hw_frames_ctx);
ctx->hwframes_ref = av_buffer_ref(inl->hw_frames_ctx);
if (!ctx->hwframes_ref) {
err = AVERROR(ENOMEM);
goto fail;
@ -241,8 +244,8 @@ static int hwmap_config_output(AVFilterLink *outlink)
return AVERROR(EINVAL);
}
outlink->hw_frames_ctx = av_buffer_ref(ctx->hwframes_ref);
if (!outlink->hw_frames_ctx) {
outl->hw_frames_ctx = av_buffer_ref(ctx->hwframes_ref);
if (!outl->hw_frames_ctx) {
err = AVERROR(ENOMEM);
goto fail;
}
@ -263,11 +266,12 @@ fail:
static AVFrame *hwmap_get_buffer(AVFilterLink *inlink, int w, int h)
{
FilterLink *l = ff_filter_link(inlink);
AVFilterContext *avctx = inlink->dst;
AVFilterLink *outlink = avctx->outputs[0];
HWMapContext *ctx = avctx->priv;
if (ctx->reverse && !inlink->hw_frames_ctx) {
if (ctx->reverse && !l->hw_frames_ctx) {
AVFrame *src, *dst;
int err;

View File

@ -24,6 +24,7 @@
#include "libavutil/opt.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
@ -106,8 +107,10 @@ fail:
static int hwupload_config_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
HWUploadContext *ctx = avctx->priv;
int err;
@ -116,13 +119,13 @@ static int hwupload_config_output(AVFilterLink *outlink)
if (inlink->format == outlink->format) {
// The input is already a hardware format, so we just want to
// pass through the input frames in their own hardware context.
if (!inlink->hw_frames_ctx) {
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No input hwframe context.\n");
return AVERROR(EINVAL);
}
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
if (!outlink->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;
@ -138,9 +141,9 @@ static int hwupload_config_output(AVFilterLink *outlink)
av_get_pix_fmt_name(inlink->format));
ctx->hwframes->format = outlink->format;
if (inlink->hw_frames_ctx) {
if (inl->hw_frames_ctx) {
AVHWFramesContext *in_hwframe_ctx =
(AVHWFramesContext*)inlink->hw_frames_ctx->data;
(AVHWFramesContext*)inl->hw_frames_ctx->data;
ctx->hwframes->sw_format = in_hwframe_ctx->sw_format;
} else {
ctx->hwframes->sw_format = inlink->format;
@ -155,8 +158,8 @@ static int hwupload_config_output(AVFilterLink *outlink)
if (err < 0)
goto fail;
outlink->hw_frames_ctx = av_buffer_ref(ctx->hwframes_ref);
if (!outlink->hw_frames_ctx) {
outl->hw_frames_ctx = av_buffer_ref(ctx->hwframes_ref);
if (!outl->hw_frames_ctx) {
err = AVERROR(ENOMEM);
goto fail;
}

View File

@ -22,6 +22,7 @@
#include "libavutil/opt.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
@ -86,8 +87,10 @@ static int cudaupload_query_formats(AVFilterContext *ctx)
static int cudaupload_config_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = ctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
CudaUploadContext *s = ctx->priv;
AVHWFramesContext *hwframe_ctx;
@ -100,8 +103,8 @@ static int cudaupload_config_output(AVFilterLink *outlink)
hwframe_ctx = (AVHWFramesContext*)s->hwframe->data;
hwframe_ctx->format = AV_PIX_FMT_CUDA;
if (inlink->hw_frames_ctx) {
AVHWFramesContext *in_hwframe_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
if (inl->hw_frames_ctx) {
AVHWFramesContext *in_hwframe_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
hwframe_ctx->sw_format = in_hwframe_ctx->sw_format;
} else {
hwframe_ctx->sw_format = inlink->format;
@ -113,8 +116,8 @@ static int cudaupload_config_output(AVFilterLink *outlink)
if (ret < 0)
return ret;
outlink->hw_frames_ctx = av_buffer_ref(s->hwframe);
if (!outlink->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(s->hwframe);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;

View File

@ -1188,6 +1188,7 @@ static inline AVRational max_q(AVRational a, AVRational b)
static int libplacebo_config_output(AVFilterLink *outlink)
{
int err;
FilterLink *l = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
LibplaceboContext *s = avctx->priv;
AVFilterLink *inlink = outlink->src->inputs[0];
@ -1253,7 +1254,7 @@ static int libplacebo_config_output(AVFilterLink *outlink)
s->vkctx.output_format = s->out_format;
}
RET(ff_vk_filter_config_output(outlink));
hwfc = (AVHWFramesContext *) outlink->hw_frames_ctx->data;
hwfc = (AVHWFramesContext *)l->hw_frames_ctx->data;
vkfc = hwfc->hwctx;
vkfc->usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

View File

@ -34,6 +34,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "drawutils.h"
#include "filters.h"
#include "formats.h"
#include "framesync.h"
#include "internal.h"
@ -651,7 +652,8 @@ static int config_props_cuda(AVFilterLink *outlink)
AVFilterContext *ctx = outlink->src;
LIBVMAFContext *s = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
AVHWFramesContext *frames_ctx = (AVHWFramesContext*) inlink->hw_frames_ctx->data;
FilterLink *inl = ff_filter_link(inlink);
AVHWFramesContext *frames_ctx = (AVHWFramesContext*) inl->hw_frames_ctx->data;
AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
CUcontext cu_ctx = device_hwctx->cuda_ctx;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frames_ctx->sw_format);
@ -756,7 +758,8 @@ static int do_vmaf_cuda(FFFrameSync* fs)
AVFilterContext* ctx = fs->parent;
LIBVMAFContext* s = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
AVHWFramesContext *frames_ctx = (AVHWFramesContext*) inlink->hw_frames_ctx->data;
FilterLink *inl = ff_filter_link(inlink);
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
VmafPicture pic_ref, pic_dist;
AVFrame *ref, *dist;

View File

@ -436,14 +436,17 @@ static int overlay_cuda_config_output(AVFilterLink *outlink)
extern const unsigned int ff_vf_overlay_cuda_ptx_len;
int err;
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext* avctx = outlink->src;
OverlayCUDAContext* ctx = avctx->priv;
AVFilterLink *inlink = avctx->inputs[0];
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
FilterLink *inl = ff_filter_link(inlink);
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
AVFilterLink *inlink_overlay = avctx->inputs[1];
AVHWFramesContext *frames_ctx_overlay = (AVHWFramesContext*)inlink_overlay->hw_frames_ctx->data;
FilterLink *inl_overlay = ff_filter_link(inlink_overlay);
AVHWFramesContext *frames_ctx_overlay = (AVHWFramesContext*)inl_overlay->hw_frames_ctx->data;
CUcontext dummy, cuda_ctx;
CudaFunctions *cu;
@ -496,8 +499,8 @@ static int overlay_cuda_config_output(AVFilterLink *outlink)
ctx->cu_stream = ctx->hwctx->stream;
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
if (!outlink->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
// load functions

View File

@ -29,6 +29,7 @@
#include "libavutil/hwcontext.h"
#include "libavutil/mathematics.h"
#include "filters.h"
#include "internal.h"
#include "avfilter.h"
#include "formats.h"
@ -156,12 +157,13 @@ release:
static int have_alpha_planar(AVFilterLink *link)
{
FilterLink *l = ff_filter_link(link);
enum AVPixelFormat pix_fmt = link->format;
const AVPixFmtDescriptor *desc;
AVHWFramesContext *fctx;
if (link->format == AV_PIX_FMT_QSV) {
fctx = (AVHWFramesContext *)link->hw_frames_ctx->data;
fctx = (AVHWFramesContext *)l->hw_frames_ctx->data;
pix_fmt = fctx->sw_format;
}
@ -273,6 +275,8 @@ static int config_output(AVFilterLink *outlink)
QSVOverlayContext *vpp = ctx->priv;
AVFilterLink *in0 = ctx->inputs[0];
AVFilterLink *in1 = ctx->inputs[1];
FilterLink *l0 = ff_filter_link(in0);
FilterLink *l1 = ff_filter_link(in1);
int ret;
av_log(ctx, AV_LOG_DEBUG, "Output is of %s.\n", av_get_pix_fmt_name(outlink->format));
@ -282,8 +286,8 @@ static int config_output(AVFilterLink *outlink)
av_log(ctx, AV_LOG_ERROR, "Mixing hardware and software pixel formats is not supported.\n");
return AVERROR(EINVAL);
} else if (in0->format == AV_PIX_FMT_QSV) {
AVHWFramesContext *hw_frame0 = (AVHWFramesContext *)in0->hw_frames_ctx->data;
AVHWFramesContext *hw_frame1 = (AVHWFramesContext *)in1->hw_frames_ctx->data;
AVHWFramesContext *hw_frame0 = (AVHWFramesContext *)l0->hw_frames_ctx->data;
AVHWFramesContext *hw_frame1 = (AVHWFramesContext *)l1->hw_frames_ctx->data;
if (hw_frame0->device_ctx != hw_frame1->device_ctx) {
av_log(ctx, AV_LOG_ERROR, "Inputs with different underlying QSV devices are forbidden.\n");

View File

@ -21,6 +21,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "framesync.h"
#include "internal.h"
#include "vaapi_vpp.h"
@ -256,12 +257,13 @@ fail:
static int have_alpha_planar(AVFilterLink *link)
{
FilterLink *l = ff_filter_link(link);
enum AVPixelFormat pix_fmt = link->format;
const AVPixFmtDescriptor *desc;
AVHWFramesContext *fctx;
if (link->format == AV_PIX_FMT_VAAPI) {
fctx = (AVHWFramesContext *)link->hw_frames_ctx->data;
fctx = (AVHWFramesContext *)l->hw_frames_ctx->data;
pix_fmt = fctx->sw_format;
}

View File

@ -32,6 +32,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "scale_eval.h"
#include "video.h"
@ -221,6 +222,8 @@ static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int
int out_width, int out_height)
{
CUDAScaleContext *s = ctx->priv;
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
AVHWFramesContext *in_frames_ctx;
@ -229,11 +232,11 @@ static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int
int ret;
/* check that we have a hw context */
if (!ctx->inputs[0]->hw_frames_ctx) {
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
return AVERROR(EINVAL);
}
in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
in_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
in_format = in_frames_ctx->sw_format;
out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
@ -251,7 +254,7 @@ static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int
set_format_info(ctx, in_format, out_format);
if (s->passthrough && in_width == out_width && in_height == out_height && in_format == out_format) {
s->frames_ctx = av_buffer_ref(ctx->inputs[0]->hw_frames_ctx);
s->frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if (!s->frames_ctx)
return AVERROR(ENOMEM);
} else {
@ -266,8 +269,8 @@ static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int
s->interp_algo = INTERP_ALGO_NEAREST;
}
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!ctx->outputs[0]->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;
@ -348,6 +351,7 @@ static av_cold int cudascale_config_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = outlink->src->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
CUDAScaleContext *s = ctx->priv;
AVHWFramesContext *frames_ctx;
AVCUDADeviceContext *device_hwctx;
@ -374,7 +378,7 @@ static av_cold int cudascale_config_props(AVFilterLink *outlink)
if (ret < 0)
return ret;
frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
device_hwctx = frames_ctx->device_ctx->hwctx;
s->hwctx = device_hwctx;

View File

@ -36,6 +36,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "scale_eval.h"
@ -536,6 +537,8 @@ static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_heig
int out_width, int out_height)
{
NPPScaleContext *s = ctx->priv;
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
AVHWFramesContext *in_frames_ctx;
@ -547,11 +550,11 @@ static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_heig
int i, ret, last_stage = -1;
/* check that we have a hw context */
if (!ctx->inputs[0]->hw_frames_ctx) {
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
return AVERROR(EINVAL);
}
in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
in_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
in_format = in_frames_ctx->sw_format;
out_format = (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
@ -629,11 +632,11 @@ static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_heig
}
if (last_stage >= 0)
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
outl->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
else
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(ctx->inputs[0]->hw_frames_ctx);
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if (!ctx->outputs[0]->hw_frames_ctx)
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;
@ -686,8 +689,9 @@ fail:
static int config_props_ref(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterLink *inlink = outlink->src->inputs[1];
AVFilterContext *ctx = outlink->src;
FilterLink *inl = ff_filter_link(inlink);
outlink->w = inlink->w;
outlink->h = inlink->h;
@ -695,7 +699,7 @@ static int config_props_ref(AVFilterLink *outlink)
outlink->time_base = inlink->time_base;
outlink->frame_rate = inlink->frame_rate;
ctx->outputs[1]->hw_frames_ctx = av_buffer_ref(ctx->inputs[1]->hw_frames_ctx);
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
return 0;
}
@ -900,7 +904,8 @@ static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
AVFilterContext *ctx = link->dst;
NPPScaleContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
FilterLink *l = ff_filter_link(outlink);
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)l->hw_frames_ctx->data;
AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
AVFrame *out = NULL;

View File

@ -24,6 +24,8 @@
#include "libavutil/hwcontext_videotoolbox.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "filters.h"
#include "internal.h"
#include "scale_eval.h"
#include "video.h"
@ -174,9 +176,11 @@ fail:
static int scale_vt_config_output(AVFilterLink *outlink)
{
int err;
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
ScaleVtContext *s = avctx->priv;
AVFilterLink *inlink = outlink->src->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
AVHWFramesContext *hw_frame_ctx_in;
AVHWFramesContext *hw_frame_ctx_out;
@ -196,11 +200,11 @@ static int scale_vt_config_output(AVFilterLink *outlink)
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
}
hw_frame_ctx_in = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
hw_frame_ctx_in = (AVHWFramesContext *)inl->hw_frames_ctx->data;
av_buffer_unref(&outlink->hw_frames_ctx);
outlink->hw_frames_ctx = av_hwframe_ctx_alloc(hw_frame_ctx_in->device_ref);
hw_frame_ctx_out = (AVHWFramesContext *)outlink->hw_frames_ctx->data;
av_buffer_unref(&outl->hw_frames_ctx);
outl->hw_frames_ctx = av_hwframe_ctx_alloc(hw_frame_ctx_in->device_ref);
hw_frame_ctx_out = (AVHWFramesContext *)outl->hw_frames_ctx->data;
hw_frame_ctx_out->format = AV_PIX_FMT_VIDEOTOOLBOX;
hw_frame_ctx_out->sw_format = hw_frame_ctx_in->sw_format;
hw_frame_ctx_out->width = outlink->w;
@ -210,7 +214,7 @@ static int scale_vt_config_output(AVFilterLink *outlink)
if (err < 0)
return err;
err = av_hwframe_ctx_init(outlink->hw_frames_ctx);
err = av_hwframe_ctx_init(outl->hw_frames_ctx);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR,
"Failed to init videotoolbox frame context, %s\n",

View File

@ -24,6 +24,7 @@
#include <nppi.h>
#include <nppi_filtering_functions.h>
#include "filters.h"
#include "internal.h"
#include "libavutil/pixdesc.h"
#include "libavutil/cuda_check.h"
@ -31,6 +32,7 @@
#include "libavutil/hwcontext_cuda_internal.h"
#include "libavutil/opt.h"
#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
static const enum AVPixelFormat supported_formats[] = {
@ -70,16 +72,18 @@ fail:
static int nppsharpen_config(AVFilterContext* ctx, int width, int height)
{
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
NPPSharpenContext* s = ctx->priv;
AVHWFramesContext *out_ctx, *in_ctx;
int i, ret, supported_format = 0;
if (!ctx->inputs[0]->hw_frames_ctx) {
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
goto fail;
}
in_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
in_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
s->frames_ctx = av_hwframe_ctx_alloc(in_ctx->device_ref);
if (!s->frames_ctx)
@ -111,8 +115,8 @@ static int nppsharpen_config(AVFilterContext* ctx, int width, int height)
if (ret < 0)
goto fail;
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!ctx->outputs[0]->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(s->frames_ctx);
if (!outl->hw_frames_ctx)
goto fail;
return 0;
@ -152,8 +156,8 @@ static int nppsharpen_config_props(AVFilterLink* outlink)
static int nppsharpen_sharpen(AVFilterContext* ctx, AVFrame* out, AVFrame* in)
{
AVHWFramesContext* in_ctx =
(AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
AVHWFramesContext* in_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
NPPSharpenContext* s = ctx->priv;
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(in_ctx->sw_format);
@ -179,8 +183,9 @@ static int nppsharpen_filter_frame(AVFilterLink* link, AVFrame* in)
AVFilterContext* ctx = link->dst;
NPPSharpenContext* s = ctx->priv;
AVFilterLink* outlink = ctx->outputs[0];
FilterLink *outl = ff_filter_link(outlink);
AVHWFramesContext* frames_ctx =
(AVHWFramesContext*)outlink->hw_frames_ctx->data;
(AVHWFramesContext*)outl->hw_frames_ctx->data;
AVCUDADeviceContext* device_hwctx = frames_ctx->device_ctx->hwctx;
AVFrame* out = NULL;

View File

@ -100,15 +100,16 @@ static int config_output(AVFilterLink *outlink)
AVFilterContext *ctx = outlink->src;
StackQSVContext *sctx = ctx->priv;
AVFilterLink *inlink0 = ctx->inputs[0];
FilterLink *inl0 = ff_filter_link(inlink0);
enum AVPixelFormat in_format;
int depth = 8, ret;
mfxVPPCompInputStream *is = sctx->comp_conf.InputStream;
if (inlink0->format == AV_PIX_FMT_QSV) {
if (!inlink0->hw_frames_ctx || !inlink0->hw_frames_ctx->data)
if (!inl0->hw_frames_ctx || !inl0->hw_frames_ctx->data)
return AVERROR(EINVAL);
in_format = ((AVHWFramesContext*)inlink0->hw_frames_ctx->data)->sw_format;
in_format = ((AVHWFramesContext*)inl0->hw_frames_ctx->data)->sw_format;
} else
in_format = inlink0->format;
@ -116,10 +117,11 @@ static int config_output(AVFilterLink *outlink)
for (int i = 1; i < sctx->base.nb_inputs; i++) {
AVFilterLink *inlink = ctx->inputs[i];
FilterLink *inl = ff_filter_link(inlink);
if (inlink0->format == AV_PIX_FMT_QSV) {
AVHWFramesContext *hwfc0 = (AVHWFramesContext *)inlink0->hw_frames_ctx->data;
AVHWFramesContext *hwfc = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
AVHWFramesContext *hwfc0 = (AVHWFramesContext *)inl0->hw_frames_ctx->data;
AVHWFramesContext *hwfc = (AVHWFramesContext *)inl->hw_frames_ctx->data;
if (inlink0->format != inlink->format) {
av_log(ctx, AV_LOG_ERROR, "Mixing hardware and software pixel formats is not supported.\n");

View File

@ -137,26 +137,28 @@ static int config_output(AVFilterLink *outlink)
StackVAAPIContext *sctx = avctx->priv;
VAAPIVPPContext *vppctx = avctx->priv;
AVFilterLink *inlink0 = avctx->inputs[0];
FilterLink *inl0 = ff_filter_link(inlink0);
AVHWFramesContext *hwfc0 = NULL;
int ret;
if (inlink0->format != AV_PIX_FMT_VAAPI || !inlink0->hw_frames_ctx || !inlink0->hw_frames_ctx->data) {
if (inlink0->format != AV_PIX_FMT_VAAPI || !inl0->hw_frames_ctx || !inl0->hw_frames_ctx->data) {
av_log(avctx, AV_LOG_ERROR, "Software pixel format is not supported.\n");
return AVERROR(EINVAL);
}
hwfc0 = (AVHWFramesContext *)inlink0->hw_frames_ctx->data;
hwfc0 = (AVHWFramesContext *)inl0->hw_frames_ctx->data;
for (int i = 1; i < sctx->base.nb_inputs; i++) {
AVFilterLink *inlink = avctx->inputs[i];
FilterLink *inl = ff_filter_link(inlink);
AVHWFramesContext *hwfc = NULL;
if (inlink->format != AV_PIX_FMT_VAAPI || !inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data) {
if (inlink->format != AV_PIX_FMT_VAAPI || !inl->hw_frames_ctx || !inl->hw_frames_ctx->data) {
av_log(avctx, AV_LOG_ERROR, "Software pixel format is not supported.\n");
return AVERROR(EINVAL);
}
hwfc = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
hwfc = (AVHWFramesContext *)inl->hw_frames_ctx->data;
if (hwfc0->sw_format != hwfc->sw_format) {
av_log(avctx, AV_LOG_ERROR, "All inputs should have the same underlying software pixel format.\n");

View File

@ -28,6 +28,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "cuda/load_helper.h"
@ -358,8 +359,10 @@ static int format_is_supported(enum AVPixelFormat fmt)
static int config_props(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
FilterLink *inl = ff_filter_link(inlink);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
ThumbnailCudaContext *s = ctx->priv;
AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)inlink->hw_frames_ctx->data;
AVHWFramesContext *hw_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
AVCUDADeviceContext *device_hwctx = hw_frames_ctx->device_ctx->hwctx;
CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
CudaFunctions *cu = device_hwctx->internal->cuda_dl;
@ -401,10 +404,10 @@ static int config_props(AVFilterLink *inlink)
CHECK_CU(cu->cuCtxPopCurrent(&dummy));
s->hw_frames_ctx = ctx->inputs[0]->hw_frames_ctx;
s->hw_frames_ctx = inl->hw_frames_ctx;
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->hw_frames_ctx);
if (!ctx->outputs[0]->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(s->hw_frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
s->tb = inlink->time_base;

View File

@ -29,6 +29,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
@ -178,6 +179,8 @@ static int format_is_supported(enum AVPixelFormat fmt)
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height,
int out_width, int out_height)
{
FilterLink *inl = ff_filter_link(ctx->inputs[0]);
FilterLink *outl = ff_filter_link(ctx->outputs[0]);
NPPTransposeContext *s = ctx->priv;
AVHWFramesContext *in_frames_ctx;
enum AVPixelFormat format;
@ -185,12 +188,12 @@ static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_heig
int rot_width = out_width, rot_height = out_height;
/* check that we have a hw context */
if (!ctx->inputs[0]->hw_frames_ctx) {
if (!inl->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
return AVERROR(EINVAL);
}
in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
in_frames_ctx = (AVHWFramesContext*)inl->hw_frames_ctx->data;
format = in_frames_ctx->sw_format;
if (!format_is_supported(format)) {
@ -235,13 +238,13 @@ static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_heig
}
if (last_stage >= 0) {
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
outl->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
} else {
ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(ctx->inputs[0]->hw_frames_ctx);
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
s->passthrough = 1;
}
if (!ctx->outputs[0]->hw_frames_ctx)
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
return 0;
@ -249,17 +252,19 @@ static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_heig
static int npptranspose_config_props(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = ctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
NPPTransposeContext *s = ctx->priv;
int ret;
if ((inlink->w >= inlink->h && s->passthrough == NPP_TRANSPOSE_PT_TYPE_LANDSCAPE) ||
(inlink->w <= inlink->h && s->passthrough == NPP_TRANSPOSE_PT_TYPE_PORTRAIT))
{
if (inlink->hw_frames_ctx) {
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
if (!outlink->hw_frames_ctx)
if (inl->hw_frames_ctx) {
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
}
@ -387,7 +392,8 @@ static int npptranspose_filter_frame(AVFilterLink *link, AVFrame *in)
AVFilterContext *ctx = link->dst;
NPPTransposeContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
FilterLink *outl = ff_filter_link(outlink);
AVHWFramesContext *frames_ctx = (AVHWFramesContext*)outl->hw_frames_ctx->data;
AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
AVFrame *out = NULL;
CUcontext dummy;

View File

@ -23,6 +23,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "opencl.h"
#include "opencl_source.h"
@ -71,9 +72,11 @@ fail:
static int transpose_opencl_config_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
TransposeOpenCLContext *s = avctx->priv;
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
const AVPixFmtDescriptor *desc_in = av_pix_fmt_desc_get(inlink->format);
int ret;
@ -81,9 +84,9 @@ static int transpose_opencl_config_output(AVFilterLink *outlink)
s->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) ||
(inlink->w <= inlink->h &&
s->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) {
if (inlink->hw_frames_ctx) {
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
if (!outlink->hw_frames_ctx)
if (inl->hw_frames_ctx) {
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
}
av_log(avctx, AV_LOG_VERBOSE,

View File

@ -21,6 +21,7 @@
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "transpose.h"
#include "vaapi_vpp.h"
@ -185,15 +186,17 @@ static av_cold int transpose_vaapi_init(AVFilterContext *avctx)
static int transpose_vaapi_vpp_config_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
VAAPIVPPContext *vpp_ctx = avctx->priv;
TransposeVAAPIContext *ctx = avctx->priv;
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
if ((inlink->w >= inlink->h && ctx->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) ||
(inlink->w <= inlink->h && ctx->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) {
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
if (!outlink->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if (!outl->hw_frames_ctx)
return AVERROR(ENOMEM);
av_log(avctx, AV_LOG_VERBOSE,
"w:%d h:%d -> w:%d h:%d (passthrough mode)\n",

View File

@ -24,6 +24,8 @@
#include "libavutil/hwcontext_videotoolbox.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "filters.h"
#include "internal.h"
#include "transpose.h"
#include "video.h"
@ -105,17 +107,19 @@ fail:
static int transpose_vt_recreate_hw_ctx(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
AVFilterLink *inlink = outlink->src->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
AVHWFramesContext *hw_frame_ctx_in;
AVHWFramesContext *hw_frame_ctx_out;
int err;
av_buffer_unref(&outlink->hw_frames_ctx);
av_buffer_unref(&outl->hw_frames_ctx);
hw_frame_ctx_in = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
outlink->hw_frames_ctx = av_hwframe_ctx_alloc(hw_frame_ctx_in->device_ref);
hw_frame_ctx_out = (AVHWFramesContext *)outlink->hw_frames_ctx->data;
hw_frame_ctx_in = (AVHWFramesContext *)inl->hw_frames_ctx->data;
outl->hw_frames_ctx = av_hwframe_ctx_alloc(hw_frame_ctx_in->device_ref);
hw_frame_ctx_out = (AVHWFramesContext *)outl->hw_frames_ctx->data;
hw_frame_ctx_out->format = AV_PIX_FMT_VIDEOTOOLBOX;
hw_frame_ctx_out->sw_format = hw_frame_ctx_in->sw_format;
hw_frame_ctx_out->width = outlink->w;
@ -125,7 +129,7 @@ static int transpose_vt_recreate_hw_ctx(AVFilterLink *outlink)
if (err < 0)
return err;
err = av_hwframe_ctx_init(outlink->hw_frames_ctx);
err = av_hwframe_ctx_init(outl->hw_frames_ctx);
if (err < 0) {
av_log(avctx, AV_LOG_ERROR,
"Failed to init videotoolbox frame context, %s\n",
@ -139,16 +143,18 @@ static int transpose_vt_recreate_hw_ctx(AVFilterLink *outlink)
static int transpose_vt_config_output(AVFilterLink *outlink)
{
int err;
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
TransposeVtContext *s = avctx->priv;
AVFilterLink *inlink = outlink->src->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
CFStringRef rotation = kVTRotation_0;
CFBooleanRef vflip = kCFBooleanFalse;
CFBooleanRef hflip = kCFBooleanFalse;
int swap_w_h = 0;
av_buffer_unref(&outlink->hw_frames_ctx);
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
av_buffer_unref(&outl->hw_frames_ctx);
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
if ((inlink->w >= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) ||
(inlink->w <= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) {

View File

@ -23,6 +23,8 @@
#include "libavutil/opt.h"
#include "vulkan_filter.h"
#include "vulkan_spirv.h"
#include "filters.h"
#include "internal.h"
#include "transpose.h"
#include "video.h"
@ -193,18 +195,20 @@ static av_cold void transpose_vulkan_uninit(AVFilterContext *avctx)
static int config_props_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
TransposeVulkanContext *s = avctx->priv;
FFVulkanContext *vkctx = &s->vkctx;
AVFilterLink *inlink = avctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
if ((inlink->w >= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) ||
(inlink->w <= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) {
av_log(avctx, AV_LOG_VERBOSE,
"w:%d h:%d -> w:%d h:%d (passthrough mode)\n",
inlink->w, inlink->h, inlink->w, inlink->h);
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
return outlink->hw_frames_ctx ? 0 : AVERROR(ENOMEM);
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
return outl->hw_frames_ctx ? 0 : AVERROR(ENOMEM);
} else {
s->passthrough = TRANSPOSE_PT_TYPE_NONE;
}

View File

@ -364,13 +364,13 @@ static int config_input(AVFilterLink *inlink)
static mfxStatus get_mfx_version(const AVFilterContext *ctx, mfxVersion *mfx_version)
{
const AVFilterLink *inlink = ctx->inputs[0];
const FilterLink *l = ff_filter_link(ctx->inputs[0]);
AVBufferRef *device_ref;
AVHWDeviceContext *device_ctx;
AVQSVDeviceContext *device_hwctx;
if (inlink->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
if (l->hw_frames_ctx) {
AVHWFramesContext *frames_ctx = (AVHWFramesContext *)l->hw_frames_ctx->data;
device_ref = frames_ctx->device_ref;
} else if (ctx->hw_device_ctx) {
device_ref = ctx->hw_device_ctx;
@ -524,6 +524,7 @@ static int vpp_set_frame_ext_params(AVFilterContext *ctx, const AVFrame *in, AVF
static int config_output(AVFilterLink *outlink)
{
FilterLink *outl = ff_filter_link(outlink);
AVFilterContext *ctx = outlink->src;
VPPContext *vpp = ctx->priv;
QSVVPPParam param = { NULL };
@ -531,6 +532,7 @@ static int config_output(AVFilterLink *outlink)
mfxExtBuffer *ext_buf[ENH_FILTERS_COUNT];
mfxVersion mfx_version;
AVFilterLink *inlink = ctx->inputs[0];
FilterLink *inl = ff_filter_link(inlink);
enum AVPixelFormat in_format;
outlink->w = vpp->out_width;
@ -552,10 +554,10 @@ static int config_output(AVFilterLink *outlink)
}
if (inlink->format == AV_PIX_FMT_QSV) {
if (!inlink->hw_frames_ctx || !inlink->hw_frames_ctx->data)
if (!inl->hw_frames_ctx || !inl->hw_frames_ctx->data)
return AVERROR(EINVAL);
else
in_format = ((AVHWFramesContext*)inlink->hw_frames_ctx->data)->sw_format;
in_format = ((AVHWFramesContext*)inl->hw_frames_ctx->data)->sw_format;
} else
in_format = inlink->format;
@ -716,8 +718,8 @@ static int config_output(AVFilterLink *outlink)
else {
/* No MFX session is created in this case */
av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
if (inlink->hw_frames_ctx)
outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
if (inl->hw_frames_ctx)
outl->hw_frames_ctx = av_buffer_ref(inl->hw_frames_ctx);
}
return 0;

View File

@ -22,6 +22,8 @@
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_cuda_internal.h"
#include "libavutil/cuda_check.h"
#include "filters.h"
#include "internal.h"
#include "yadif.h"
@ -209,16 +211,17 @@ static av_cold void deint_cuda_uninit(AVFilterContext *ctx)
static int config_input(AVFilterLink *inlink)
{
FilterLink *l = ff_filter_link(inlink);
AVFilterContext *ctx = inlink->dst;
DeintCUDAContext *s = ctx->priv;
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "A hardware frames reference is "
"required to associate the processing device.\n");
return AVERROR(EINVAL);
}
s->input_frames_ref = av_buffer_ref(inlink->hw_frames_ctx);
s->input_frames_ref = av_buffer_ref(l->hw_frames_ctx);
if (!s->input_frames_ref) {
av_log(ctx, AV_LOG_ERROR, "A input frames reference create "
"failed.\n");
@ -231,6 +234,7 @@ static int config_input(AVFilterLink *inlink)
static int config_output(AVFilterLink *link)
{
FilterLink *l = ff_filter_link(link);
AVHWFramesContext *output_frames;
AVFilterContext *ctx = link->src;
DeintCUDAContext *s = ctx->priv;
@ -249,15 +253,15 @@ static int config_output(AVFilterLink *link)
s->hwctx = ((AVHWDeviceContext*)s->device_ref->data)->hwctx;
cu = s->hwctx->internal->cuda_dl;
link->hw_frames_ctx = av_hwframe_ctx_alloc(s->device_ref);
if (!link->hw_frames_ctx) {
l->hw_frames_ctx = av_hwframe_ctx_alloc(s->device_ref);
if (!l->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "Failed to create HW frame context "
"for output.\n");
ret = AVERROR(ENOMEM);
goto exit;
}
output_frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
output_frames = (AVHWFramesContext*)l->hw_frames_ctx->data;
output_frames->format = AV_PIX_FMT_CUDA;
output_frames->sw_format = s->input_frames->sw_format;
@ -270,7 +274,7 @@ static int config_output(AVFilterLink *link)
if (ret < 0)
goto exit;
ret = av_hwframe_ctx_init(link->hw_frames_ctx);
ret = av_hwframe_ctx_init(l->hw_frames_ctx);
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to initialise CUDA frame "
"context for output: %d\n", ret);

View File

@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "filters.h"
#include "internal.h"
#include "metal/utils.h"
#include "yadif.h"
@ -288,16 +289,17 @@ static av_cold int yadif_videotoolbox_init(AVFilterContext *ctx)
static int do_config_input(AVFilterLink *inlink) API_AVAILABLE(macos(10.11), ios(8.0))
{
FilterLink *l = ff_filter_link(inlink);
AVFilterContext *ctx = inlink->dst;
YADIFVTContext *s = ctx->priv;
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "A hardware frames reference is "
"required to associate the processing device.\n");
return AVERROR(EINVAL);
}
s->input_frames_ref = av_buffer_ref(inlink->hw_frames_ctx);
s->input_frames_ref = av_buffer_ref(l->hw_frames_ctx);
if (!s->input_frames_ref) {
av_log(ctx, AV_LOG_ERROR, "A input frames reference create "
"failed.\n");
@ -321,6 +323,7 @@ static int config_input(AVFilterLink *inlink)
static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(8.0))
{
FilterLink *l = ff_filter_link(link);
AVHWFramesContext *output_frames;
AVFilterContext *ctx = link->src;
YADIFVTContext *s = ctx->priv;
@ -335,15 +338,15 @@ static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(
return AVERROR(ENOMEM);
}
link->hw_frames_ctx = av_hwframe_ctx_alloc(s->device_ref);
if (!link->hw_frames_ctx) {
l->hw_frames_ctx = av_hwframe_ctx_alloc(s->device_ref);
if (!l->hw_frames_ctx) {
av_log(ctx, AV_LOG_ERROR, "Failed to create HW frame context "
"for output.\n");
ret = AVERROR(ENOMEM);
goto exit;
}
output_frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
output_frames = (AVHWFramesContext*)l->hw_frames_ctx->data;
output_frames->format = AV_PIX_FMT_VIDEOTOOLBOX;
output_frames->sw_format = s->input_frames->sw_format;
@ -354,7 +357,7 @@ static int do_config_output(AVFilterLink *link) API_AVAILABLE(macos(10.11), ios(
if (ret < 0)
goto exit;
ret = av_hwframe_ctx_init(link->hw_frames_ctx);
ret = av_hwframe_ctx_init(l->hw_frames_ctx);
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Failed to initialise VideoToolbox frame "
"context for output: %d\n", ret);

View File

@ -55,15 +55,15 @@ AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int alig
int pool_align = 0;
enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
if (link->hw_frames_ctx &&
((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
if (li->l.hw_frames_ctx &&
((AVHWFramesContext*)li->l.hw_frames_ctx->data)->format == link->format) {
int ret;
frame = av_frame_alloc();
if (!frame)
return NULL;
ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0);
ret = av_hwframe_get_buffer(li->l.hw_frames_ctx, frame, 0);
if (ret < 0)
av_frame_free(&frame);

View File

@ -43,6 +43,7 @@
#include "libavutil/hwcontext_d3d11va.h"
#include "compat/w32dlfcn.h"
#include "avfilter.h"
#include "filters.h"
#include "internal.h"
#include "video.h"
@ -854,6 +855,7 @@ fail:
static int ddagrab_config_props(AVFilterLink *outlink)
{
FilterLink *l = ff_filter_link(outlink);
AVFilterContext *avctx = outlink->src;
DdagrabContext *dda = avctx->priv;
int ret;
@ -915,8 +917,8 @@ static int ddagrab_config_props(AVFilterLink *outlink)
if (ret < 0)
return ret;
outlink->hw_frames_ctx = av_buffer_ref(dda->frames_ref);
if (!outlink->hw_frames_ctx)
l->hw_frames_ctx = av_buffer_ref(dda->frames_ref);
if (!l->hw_frames_ctx)
return AVERROR(ENOMEM);
outlink->w = dda->width;

View File

@ -266,6 +266,7 @@ static int testsrc_vulkan_activate(AVFilterContext *ctx)
static int testsrc_vulkan_config_props(AVFilterLink *outlink)
{
int err;
FilterLink *l = ff_filter_link(outlink);
TestSrcVulkanContext *s = outlink->src->priv;
FFVulkanContext *vkctx = &s->vkctx;
@ -284,8 +285,8 @@ static int testsrc_vulkan_config_props(AVFilterLink *outlink)
if (err < 0)
return err;
outlink->hw_frames_ctx = av_buffer_ref(vkctx->frames_ref);
if (!outlink->hw_frames_ctx)
l->hw_frames_ctx = av_buffer_ref(vkctx->frames_ref);
if (!l->hw_frames_ctx)
return AVERROR(ENOMEM);
s->time_base = av_inv_q(s->frame_rate);

View File

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "filters.h"
#include "vulkan_filter.h"
#include "libavutil/vulkan_loader.h"
@ -165,17 +166,18 @@ skip:
int ff_vk_filter_config_input(AVFilterLink *inlink)
{
FilterLink *l = ff_filter_link(inlink);
AVHWFramesContext *input_frames;
AVFilterContext *avctx = inlink->dst;
FFVulkanContext *s = inlink->dst->priv;
if (!inlink->hw_frames_ctx) {
if (!l->hw_frames_ctx) {
av_log(inlink->dst, AV_LOG_ERROR, "Vulkan filtering requires a "
"hardware frames context on the input.\n");
return AVERROR(EINVAL);
}
input_frames = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
input_frames = (AVHWFramesContext *)l->hw_frames_ctx->data;
if (input_frames->format != AV_PIX_FMT_VULKAN)
return AVERROR(EINVAL);
@ -184,7 +186,7 @@ int ff_vk_filter_config_input(AVFilterLink *inlink)
return 0;
/* Save the ref, without reffing it */
s->input_frames_ref = inlink->hw_frames_ctx;
s->input_frames_ref = l->hw_frames_ctx;
/* Defaults */
s->input_format = input_frames->sw_format;
@ -198,9 +200,10 @@ int ff_vk_filter_config_input(AVFilterLink *inlink)
int ff_vk_filter_config_output(AVFilterLink *outlink)
{
int err;
FilterLink *l = ff_filter_link(outlink);
FFVulkanContext *s = outlink->src->priv;
av_buffer_unref(&outlink->hw_frames_ctx);
av_buffer_unref(&l->hw_frames_ctx);
err = ff_vk_filter_init_context(outlink->src, s, s->input_frames_ref,
s->output_width, s->output_height,
@ -208,8 +211,8 @@ int ff_vk_filter_config_output(AVFilterLink *outlink)
if (err < 0)
return err;
outlink->hw_frames_ctx = av_buffer_ref(s->frames_ref);
if (!outlink->hw_frames_ctx)
l->hw_frames_ctx = av_buffer_ref(s->frames_ref);
if (!l->hw_frames_ctx)
return AVERROR(ENOMEM);
outlink->w = s->output_width;