From patchwork Thu Jan 18 05:18:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jun Zhao X-Patchwork-Id: 7322 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.78.2 with SMTP id r2csp6460214jaa; Wed, 17 Jan 2018 21:18:27 -0800 (PST) X-Google-Smtp-Source: ACJfBotTtv7o/NATl8pmhEXdq3OUEpl2uRoJCeVyYU4q5YkLohEDEl55dHUQ0iVsosI5dS+pjiUM X-Received: by 10.223.186.194 with SMTP id w2mr3283387wrg.154.1516252707742; Wed, 17 Jan 2018 21:18:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516252707; cv=none; d=google.com; s=arc-20160816; b=hizrNU+uIfbeyBS++RtIxjY/9EnCn0LWiLESibJxg1f8snal9ukpsxfGtqLtijsY0s cYzopfT1tLq0oWMEMvad7+B91RsDzQ3YGGinIVjME2J2Wt5gvU+Kra6aaGa9fLkmcch/ 67tfx0nd4R9sMd8H9KFlHVldRSOQzFGOKA5AnASlwJrGVkEzoebu5+s2zMIPuUbwUnH5 6M3bpTmPjSD9+xhYPz7BnTWImSebHvdtceni+C7C7u/19h/lpx8qlz5GCF20e1nA1I5N 9V+FlTG5IGmwUFCtoGz/j6JIi7Bm9tVDg5iGnUvI8yYnXSxeFJEVa7xZSRMGbwsrHA7q i7CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:mime-version:user-agent:date:message-id:from:to :dkim-signature:delivered-to:arc-authentication-results; bh=cVIdVEa8LX05SSl2OphsNfmvGhM9iEtvbhuk1K5gXJg=; b=G53oXaTUHjYg1pss0INYHYDTWtDRYkm6ofZTsDDLNkdC2hl4o4Bfet1oWPe+AwS44I y6F6nFknk6/ZWh2N2zm8KZ8yq+GCLOz6Fp0ykG/RmRVp/00MG/k9le8PHKCr0xheLRUx q34+npT0ayRUTOlZJmf8WeGJHPAhwSVu6woqxmAGeX50E4l5TbCnIt2i2+pT4t6D4rBg Dt2Tupaq9m6Qwr6AD1l6elUORp6SQoKwZ03rRbgl9NJk/0yW3W1BvxbByqWU5FExXO82 Ve9WX7SjMNmKaZ2Rp40rNRb7XsICNcTEFTdeowzVYP3rkGDt4lTVgh8Hktn+/acE4DN9 a0dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=QgjkVBg7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h6si4736484wmf.236.2018.01.17.21.18.26; Wed, 17 Jan 2018 21:18:27 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=QgjkVBg7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 74A276883E3; Thu, 18 Jan 2018 07:18:25 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f52.google.com (mail-pg0-f52.google.com [74.125.83.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9890E68798D for ; Thu, 18 Jan 2018 07:18:18 +0200 (EET) Received: by mail-pg0-f52.google.com with SMTP id g16so6492003pgn.7 for ; Wed, 17 Jan 2018 21:18:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=hJGSSx8D4ZZBiuvrrzUnK1tTRuN4CPPTrpstGrNkJ7M=; b=QgjkVBg7oq8Wb5J5FSf5NJosdUkvSqcQQt5B4c9EiUB66I/D7KXu9tuFgMUixnmE+i nb2jMPeYH4RCtQQ2hV1Mfk7x8V2xh86GaFyCeVVdeouN2T1XzjroUimMIyWLhGW0+jQi sBQJmMKFGyT8qwi64tB9ydpXmJ0et6pe/0fnTvNXLJYWz7Kf9vFeBjsARVtlW87cbwZv 5JDK94UXtRJQUMRTNZz5ReYs9CAbdnSq6TkpZiGuyT0IloiIu3wCq7u1wgemayBYmNgn W1+nlwrKyIrVGJOURDhG0O5VrKkkbriuB33xL4SQ7pXJAF1NmET2MBE02MIqYtnddV8a cVUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=hJGSSx8D4ZZBiuvrrzUnK1tTRuN4CPPTrpstGrNkJ7M=; b=rLRCRLnULEJ+6zxzrMvLWBPQGQh2tV0N5hXFQynrrEpabljZHPXgzXnx1dk5rQyZOV TWtFz0eiEHQatSp4kjZev2o0xTr2cpHDVTFe5QEpv8VH3GO1UWhOt9wpIHBuulpd5+QZ lv5ay38doZGbP+YqZg49KMb6YdRwZT5a1Ll9FJcEmdq+WAGiOA3BQtbiutw4gGjpM3By 1X8WlI7fUM6tREsrMaCxmmp4nChVxLhPR/V+LHnGStROrreofxh7VbeD72o+2jEzUVqq +4BF0Yn/uEMMCpHQYzmku4Am+7ln9TxXvnpwQvu6a5hS0cjqsPoxOqVAwKoR+k9iU2oO cBkA== X-Gm-Message-State: AKGB3mKkLIwuoeDVAVghyJ4GXZJNBIJ3Ck5kRK2GbzXaKOGBLbjL2QRy Pj1XbSf/5YwctmwIfcd3vYs= X-Received: by 10.124.22.129 with SMTP id v1mr38453724ply.170.1516252696824; Wed, 17 Jan 2018 21:18:16 -0800 (PST) Received: from [10.67.68.27] ([192.55.54.44]) by smtp.gmail.com with ESMTPSA id y14sm9900789pfl.77.2018.01.17.21.18.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jan 2018 21:18:16 -0800 (PST) To: FFmpeg development discussions and patches , Mark Thompson , Michael Niedermayer From: Jun Zhao Message-ID: Date: Thu, 18 Jan 2018 13:18:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Language: en-US Subject: [FFmpeg-devel] [PATCH V3 1/6] lavfi: VAAPI VPP common infrastructure. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" V3: - Fix the error handle in vaapi_vpp.     - Fix the build issue and remove the duplicated header file - Add a entry to Changelog for procamp_vaapi filter.   V2: - Fix the resource leak in procamp/misc VPP filter.     - Re-work the common VAAPIVPPContext and specific VPP context part like VAAPIVPPContext+ScaleVAAPIContext, borrowing the idea from vaapi_encode.     - misc vpp part need to refactoring, and I don't have good idea about the file name for vf_misc_vaapi.c, sadly. From 826e2c10bbe107fd494912ce72aa166db49ac9db Mon Sep 17 00:00:00 2001 From: Jun Zhao Date: Mon, 8 Jan 2018 15:56:43 +0800 Subject: [PATCH V3 1/6] lavfi: VAAPI VPP common infrastructure. Re-work the VA-API common infrastructure. Signed-off-by: Jun Zhao --- libavfilter/vaapi_vpp.c | 377 ++++++++++++++++++++++++++++++++++++++++++++++++ libavfilter/vaapi_vpp.h | 88 +++++++++++ 2 files changed, 465 insertions(+) create mode 100644 libavfilter/vaapi_vpp.c create mode 100644 libavfilter/vaapi_vpp.h diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c new file mode 100644 index 0000000000..95ee38ca10 --- /dev/null +++ b/libavfilter/vaapi_vpp.c @@ -0,0 +1,377 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +#include "libavutil/avassert.h" +#include "libavutil/pixdesc.h" +#include "formats.h" + +#include "vaapi_vpp.h" + +int vaapi_vpp_query_formats(AVFilterContext *avctx) +{ + enum AVPixelFormat pix_fmts[] = { + AV_PIX_FMT_VAAPI, AV_PIX_FMT_NONE, + }; + int err; + + if ((err = ff_formats_ref(ff_make_format_list(pix_fmts), + &avctx->inputs[0]->out_formats)) < 0) + return err; + if ((err = ff_formats_ref(ff_make_format_list(pix_fmts), + &avctx->outputs[0]->in_formats)) < 0) + return err; + + return 0; +} + +void vaapi_vpp_pipeline_uninit(AVFilterContext *avctx) +{ + VAAPIVPPContext *ctx = avctx->priv; + int i; + for (i = 0; i < ctx->nb_filter_buffers; i++) { + if (ctx->filter_buffers[i] != VA_INVALID_ID) { + vaDestroyBuffer(ctx->hwctx->display, ctx->filter_buffers[i]); + ctx->filter_buffers[i] = VA_INVALID_ID; + } + } + ctx->nb_filter_buffers = 0; + + if (ctx->va_context != VA_INVALID_ID) { + vaDestroyContext(ctx->hwctx->display, ctx->va_context); + ctx->va_context = VA_INVALID_ID; + } + + if (ctx->va_config != VA_INVALID_ID) { + vaDestroyConfig(ctx->hwctx->display, ctx->va_config); + ctx->va_config = VA_INVALID_ID; + } + + av_buffer_unref(&ctx->output_frames_ref); + av_buffer_unref(&ctx->device_ref); + ctx->hwctx = NULL; +} + +int vaapi_vpp_config_input(AVFilterLink *inlink) +{ + AVFilterContext *avctx = inlink->dst; + VAAPIVPPContext *ctx = avctx->priv; + + if (ctx->pipeline_uninit) + ctx->pipeline_uninit(avctx); + + if (!inlink->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); + if (!ctx->input_frames_ref) { + av_log(avctx, AV_LOG_ERROR, "A input frames reference create " + "failed.\n"); + return AVERROR(ENOMEM); + } + ctx->input_frames = (AVHWFramesContext*)ctx->input_frames_ref->data; + + return 0; +} + +int vaapi_vpp_config_output(AVFilterLink *outlink) +{ + AVFilterContext *avctx = outlink->src; + VAAPIVPPContext *ctx = avctx->priv; + AVVAAPIHWConfig *hwconfig = NULL; + AVHWFramesConstraints *constraints = NULL; + AVVAAPIFramesContext *va_frames; + VAStatus vas; + int err, i; + + if (ctx->pipeline_uninit) + ctx->pipeline_uninit(avctx); + + if (!ctx->output_width) + ctx->output_width = avctx->inputs[0]->w; + if (!ctx->output_height) + ctx->output_height = avctx->inputs[0]->h; + + av_assert0(ctx->input_frames); + ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref); + if (!ctx->device_ref) { + av_log(avctx, AV_LOG_ERROR, "A device reference create " + "failed.\n"); + return AVERROR(ENOMEM); + } + ctx->hwctx = ((AVHWDeviceContext*)ctx->device_ref->data)->hwctx; + + av_assert0(ctx->va_config == VA_INVALID_ID); + vas = vaCreateConfig(ctx->hwctx->display, VAProfileNone, + VAEntrypointVideoProc, NULL, 0, &ctx->va_config); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to create processing pipeline " + "config: %d (%s).\n", vas, vaErrorStr(vas)); + err = AVERROR(EIO); + goto fail; + } + + hwconfig = av_hwdevice_hwconfig_alloc(ctx->device_ref); + if (!hwconfig) { + err = AVERROR(ENOMEM); + goto fail; + } + hwconfig->config_id = ctx->va_config; + + constraints = av_hwdevice_get_hwframe_constraints(ctx->device_ref, + hwconfig); + if (!constraints) { + err = AVERROR(ENOMEM); + goto fail; + } + + if (ctx->output_format == AV_PIX_FMT_NONE) + ctx->output_format = ctx->input_frames->sw_format; + if (constraints->valid_sw_formats) { + for (i = 0; constraints->valid_sw_formats[i] != AV_PIX_FMT_NONE; i++) { + if (ctx->output_format == constraints->valid_sw_formats[i]) + break; + } + if (constraints->valid_sw_formats[i] == AV_PIX_FMT_NONE) { + av_log(avctx, AV_LOG_ERROR, "Hardware does not support output " + "format %s.\n", av_get_pix_fmt_name(ctx->output_format)); + err = AVERROR(EINVAL); + goto fail; + } + } + + if (ctx->output_width < constraints->min_width || + ctx->output_height < constraints->min_height || + ctx->output_width > constraints->max_width || + ctx->output_height > constraints->max_height) { + av_log(avctx, AV_LOG_ERROR, "Hardware does not support scaling to " + "size %dx%d (constraints: width %d-%d height %d-%d).\n", + ctx->output_width, ctx->output_height, + constraints->min_width, constraints->max_width, + constraints->min_height, constraints->max_height); + err = AVERROR(EINVAL); + goto fail; + } + + ctx->output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref); + if (!ctx->output_frames_ref) { + 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; + + 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; + + // 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 = av_hwframe_ctx_init(ctx->output_frames_ref); + 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; + + av_assert0(ctx->va_context == VA_INVALID_ID); + vas = vaCreateContext(ctx->hwctx->display, ctx->va_config, + ctx->output_width, ctx->output_height, + VA_PROGRESSIVE, + va_frames->surface_ids, va_frames->nb_surfaces, + &ctx->va_context); + if (vas != VA_STATUS_SUCCESS) { + av_log(avctx, AV_LOG_ERROR, "Failed to create processing pipeline " + "context: %d (%s).\n", vas, vaErrorStr(vas)); + return AVERROR(EIO); + } + + outlink->w = ctx->output_width; + outlink->h = ctx->output_height; + + if (ctx->build_filter_params) { + err = ctx->build_filter_params(avctx); + if (err < 0) + goto fail; + } + + 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_freep(&hwconfig); + av_hwframe_constraints_free(&constraints); + return err; +} + +int vaapi_vpp_colour_standard(enum AVColorSpace av_cs) +{ + switch(av_cs) { +#define CS(av, va) case AVCOL_SPC_ ## av: return VAProcColorStandard ## va; + CS(BT709, BT709); + CS(BT470BG, BT601); + CS(SMPTE170M, SMPTE170M); + CS(SMPTE240M, SMPTE240M); +#undef CS + default: + return VAProcColorStandardNone; + } +} + +int vaapi_vpp_make_param_buffers(VAAPIVPPContext *ctx, + int type, + const void *data, + size_t size, + int count) +{ + VAStatus vas; + VABufferID buffer; + + av_assert0(ctx->nb_filter_buffers + 1 <= VAProcFilterCount); + + vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, + type, size, count, (void*)data, &buffer); + if (vas != VA_STATUS_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "Failed to create parameter " + "buffer (type %d): %d (%s).\n", + type, vas, vaErrorStr(vas)); + return AVERROR(EIO); + } + + ctx->filter_buffers[ctx->nb_filter_buffers++] = buffer; + + av_log(ctx, AV_LOG_DEBUG, "Param buffer (type %d, %zu bytes, count %d) " + "is %#x.\n", type, size, count, buffer); + return 0; +} + + +int vaapi_vpp_render_picture(VAAPIVPPContext *ctx, + VAProcPipelineParameterBuffer *params, + VASurfaceID output_surface) +{ + VABufferID params_id; + VAStatus vas; + int err = 0; + + vas = vaBeginPicture(ctx->hwctx->display, + ctx->va_context, output_surface); + if (vas != VA_STATUS_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "Failed to attach new picture: " + "%d (%s).\n", vas, vaErrorStr(vas)); + err = AVERROR(EIO); + goto fail; + } + + vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, + VAProcPipelineParameterBufferType, + sizeof(*params), 1, params, ¶ms_id); + if (vas != VA_STATUS_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "Failed to create parameter buffer: " + "%d (%s).\n", vas, vaErrorStr(vas)); + err = AVERROR(EIO); + goto fail_after_begin; + } + av_log(ctx, AV_LOG_DEBUG, "Pipeline parameter buffer is %#x.\n", + params_id); + + vas = vaRenderPicture(ctx->hwctx->display, ctx->va_context, + ¶ms_id, 1); + if (vas != VA_STATUS_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "Failed to render parameter buffer: " + "%d (%s).\n", vas, vaErrorStr(vas)); + err = AVERROR(EIO); + goto fail_after_begin; + } + + vas = vaEndPicture(ctx->hwctx->display, ctx->va_context); + if (vas != VA_STATUS_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "Failed to start picture processing: " + "%d (%s).\n", vas, vaErrorStr(vas)); + err = AVERROR(EIO); + goto fail_after_render; + } + + if (CONFIG_VAAPI_1 || ctx->hwctx->driver_quirks & + AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS) { + vas = vaDestroyBuffer(ctx->hwctx->display, params_id); + if (vas != VA_STATUS_SUCCESS) { + av_log(ctx, AV_LOG_ERROR, "Failed to free parameter buffer: " + "%d (%s).\n", vas, vaErrorStr(vas)); + // And ignore. + } + } + + return 0; + + // We want to make sure that if vaBeginPicture has been called, we also + // call vaRenderPicture and vaEndPicture. These calls may well fail or + // do something else nasty, but once we're in this failure case there + // isn't much else we can do. +fail_after_begin: + vaRenderPicture(ctx->hwctx->display, ctx->va_context, ¶ms_id, 1); +fail_after_render: + vaEndPicture(ctx->hwctx->display, ctx->va_context); +fail: + return err; +} + +void vaapi_vpp_ctx_init(VAAPIVPPContext *ctx) +{ + int i; + ctx->va_config = VA_INVALID_ID; + ctx->va_context = VA_INVALID_ID; + ctx->valid_ids = 1; + + ctx->priv = ctx->priv_data; + + for (i = 0; i < VAProcFilterCount; i++) + ctx->filter_buffers[i] = VA_INVALID_ID; + ctx->nb_filter_buffers = 0; +} + +void vaapi_vpp_ctx_uninit(AVFilterContext *avctx) +{ + VAAPIVPPContext *ctx = avctx->priv; + if (ctx->valid_ids && ctx->pipeline_uninit) + ctx->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/vaapi_vpp.h b/libavfilter/vaapi_vpp.h new file mode 100644 index 0000000000..dad4e84d13 --- /dev/null +++ b/libavfilter/vaapi_vpp.h @@ -0,0 +1,88 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVFILTER_VAAPI_VPP_H +#define AVFILTER_VAAPI_VPP_H + +#include +#include + +#include "libavutil/hwcontext.h" +#include "libavutil/hwcontext_vaapi.h" + +#include "avfilter.h" + +typedef struct VAAPIVPPContext { + const AVClass *class; + + AVVAAPIDeviceContext *hwctx; + AVBufferRef *device_ref; + + int valid_ids; + VAConfigID va_config; + VAContextID va_context; + + AVBufferRef *input_frames_ref; + AVHWFramesContext *input_frames; + + AVBufferRef *output_frames_ref; + AVHWFramesContext *output_frames; + + enum AVPixelFormat output_format; + int output_width; // computed width + int output_height; // computed height + + VABufferID filter_buffers[VAProcFilterCount]; + int nb_filter_buffers; + + int (*build_filter_params)(AVFilterContext *avctx); + + void (*pipeline_uninit)(AVFilterContext *avctx); + + // VPP-local context are allocated to follow this structure in + // memory (in the AVFilter definition, set priv_size to + // sizeof(VAAPIVPPContext) + sizeof(FooVAAPIOptions)). + void *priv; + char priv_data[0]; +} VAAPIVPPContext; + +void vaapi_vpp_ctx_init(VAAPIVPPContext *ctx); + +void vaapi_vpp_ctx_uninit(AVFilterContext *avctx); + +int vaapi_vpp_query_formats(AVFilterContext *avctx); + +void vaapi_vpp_pipeline_uninit(AVFilterContext *avctx); + +int vaapi_vpp_config_input(AVFilterLink *inlink); + +int vaapi_vpp_config_output(AVFilterLink *outlink); + +int vaapi_vpp_colour_standard(enum AVColorSpace av_cs); + +int vaapi_vpp_make_param_buffers(VAAPIVPPContext *ctx, + int type, + const void *data, + size_t size, + int count); + +int vaapi_vpp_render_picture(VAAPIVPPContext *ctx, + VAProcPipelineParameterBuffer *params, + VASurfaceID output_surface); + +#endif /* AVFILTER_VAAPI_VPP_H */