From: Mark Thompson <sw@jkqxz.net>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 1/9] libavutil: add hwcontext_amf.
Date: Wed, 14 Feb 2024 20:56:28 +0000
Message-ID: <3fd27a93-d2bd-41f8-8572-ef4ddfddc871@jkqxz.net> (raw)
In-Reply-To: <20240214015515.1027-1-ovchinnikov.dmitrii@gmail.com>
On 14/02/2024 01:55, Dmitrii Ovchinnikov wrote:
> Adds hwcontext_amf, which allows to use shared AMF
> context for the encoder, decoder and AMF-based filters,
> without copy to the host memory.
> It will also allow you to use some optimizations in
> the interaction of components (for example, SAV) and make a more
> manageable and optimal setup for using GPU devices with AMF
> in the case of a fully AMF pipeline.
> It will be a significant performance uplift when full AMF pipeline
> with filters is used.
>
> We also plan to add Compression artefact removal filter in near feature.
> ---
> libavutil/Makefile | 3 +
> libavutil/hwcontext.c | 4 +
> libavutil/hwcontext.h | 1 +
> libavutil/hwcontext_amf.c | 580 +++++++++++++++++++++++++++++++++
> libavutil/hwcontext_amf.h | 105 ++++++
> libavutil/hwcontext_internal.h | 1 +
> libavutil/pixdesc.c | 4 +
> libavutil/pixfmt.h | 4 +
> 8 files changed, 702 insertions(+)
> create mode 100644 libavutil/hwcontext_amf.c
> create mode 100644 libavutil/hwcontext_amf.h
>
> ...
> diff --git a/libavutil/hwcontext_amf.h b/libavutil/hwcontext_amf.h
> new file mode 100644
> index 0000000000..0161b9a29c
> --- /dev/null
> +++ b/libavutil/hwcontext_amf.h
> @@ -0,0 +1,105 @@
> +/*
> + * 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 AVUTIL_HWCONTEXT_AMF_H
> +#define AVUTIL_HWCONTEXT_AMF_H
> +#include <AMF/core/Factory.h>
> +#include <AMF/core/Context.h>
> +#include <AMF/core/Trace.h>
> +#include "pixfmt.h"
> +
> +#include "libavformat/avformat.h"
> +#include "libavutil/hwcontext.h"
> +
> +#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
> +
> +typedef struct AmfTraceWriter {
> + AMFTraceWriterVtbl *vtbl;
> + void *avctx;
> + void *avcl;
> +} AmfTraceWriter;
> +
> +typedef struct AVAMFDeviceContextInternal {
> + amf_handle library; ///< handle to DLL library
> + AMFFactory *factory; ///< pointer to AMF factory
> + AMFDebug *debug; ///< pointer to AMF debug interface
> + AMFTrace *trace; ///< pointer to AMF trace interface
> +
> + amf_uint64 version; ///< version of AMF runtime
> + AMFContext *context; ///< AMF context
> + AMF_MEMORY_TYPE mem_type;
> +} AVAMFDeviceContextInternal;
> +
> +/**
> + * This struct is allocated as AVHWDeviceContext.hwctx
> + */
> +
> +typedef struct AVAMFDeviceContext {
> + AVBufferRef *internal;
> +} AVAMFDeviceContext;
> +
> +typedef struct AMFFramesContext {
> + AMFSurface * surfaces;
> + int nb_surfaces;
> +} AMFFramesContext;
> +
> +/**
> +* Error handling helper
> +*/
> +#define AMF_RETURN_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
> + if (!(exp)) { \
> + av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
> + return ret_value; \
> + }
> +
> +#define AMF_GOTO_FAIL_IF_FALSE(avctx, exp, ret_value, /*message,*/ ...) \
> + if (!(exp)) { \
> + av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \
> + ret = ret_value; \
> + goto fail; \
> + }
> +
> +#define AMF_TIME_BASE_Q (AVRational){1, AMF_SECOND}
> +
> +typedef struct FormatMap {
> + enum AVPixelFormat av_format;
> + enum AMF_SURFACE_FORMAT amf_format;
> +} FormatMap;
> +
> +extern const FormatMap format_map[];
> +enum AMF_SURFACE_FORMAT av_amf_av_to_amf_format(enum AVPixelFormat fmt);
> +enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt);
> +extern AmfTraceWriter av_amf_trace_writer;
> +
> +int av_amf_context_init(AVAMFDeviceContextInternal* internal, void* avcl);
> +int av_amf_load_library(AVAMFDeviceContextInternal* internal, void* avcl);
> +int av_amf_create_context( AVAMFDeviceContextInternal * internal,
> + void* avcl,
> + const char *device,
> + AVDictionary *opts, int flags);
> +int av_amf_context_internal_create(AVAMFDeviceContextInternal * internal,
> + void* avcl,
> + const char *device,
> + AVDictionary *opts, int flags);
> +void av_amf_context_internal_free(void *opaque, uint8_t *data);
> +int av_amf_context_derive(AVAMFDeviceContextInternal * internal,
> + AVHWDeviceContext *child_device_ctx, AVDictionary *opts,
> + int flags);
> +
> +#endif /* AVUTIL_HWCONTEXT_AMF_H */
We need to sort out the content of the public header file before doing anything else. It needs to contain exactly what a user has to see to set up an AMF hwcontext instance:
* A device hwctx structure, with notes on how to set the fields to put an existing device into the device context before calling av_hwdevice_ctx_init().
* Notes on what the buffer pool in a frames context contains, which might involve another structure to act as the buffer entry.
* Optionally a frame hwctx structure, with notes on how to set the fields when putting a pool of existing frames into the frame context before calling av_hwframe_ctx_init() (omit if it would contain nothing).
* Optionally a hwconfig structure, with notes on how to set the fields when requesting the capabilities of some particular operation (omit if all operations have identical capabilities).
* If the pixfmt needs to define additional structures, they go here as well.
It shouldn't contain anything else unless there are hard ABI requirements (e.g. to allocate some sort of non-fixed structure).
> diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
> index 4df516ee6a..48d2dc012c 100644
> --- a/libavutil/hwcontext_internal.h
> +++ b/libavutil/hwcontext_internal.h
> @@ -175,5 +175,6 @@ extern const HWContextType ff_hwcontext_type_vdpau;
> extern const HWContextType ff_hwcontext_type_videotoolbox;
> extern const HWContextType ff_hwcontext_type_mediacodec;
> extern const HWContextType ff_hwcontext_type_vulkan;
> +extern const HWContextType ff_hwcontext_type_amf;
>
> #endif /* AVUTIL_HWCONTEXT_INTERNAL_H */
> diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
> index f6d4d01460..ebc79b0c74 100644
> --- a/libavutil/pixdesc.c
> +++ b/libavutil/pixdesc.c
> @@ -2125,6 +2125,10 @@ static const AVPixFmtDescriptor av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
> .name = "cuda",
> .flags = AV_PIX_FMT_FLAG_HWACCEL,
> },
> + [AV_PIX_FMT_AMF] = {
> + .name = "amf",
> + .flags = AV_PIX_FMT_FLAG_HWACCEL,
> + },
> [AV_PIX_FMT_AYUV64LE] = {
> .name = "ayuv64le",
> .nb_components = 4,
> diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
> index 9c87571f49..06459be62c 100644
> --- a/libavutil/pixfmt.h
> +++ b/libavutil/pixfmt.h
> @@ -251,6 +251,10 @@ enum AVPixelFormat {
> * exactly as for system memory frames.
> */
> AV_PIX_FMT_CUDA,
> + /**
> + * HW acceleration through AMF. data[3] contain AMFSurface pointer
> + */
> + AV_PIX_FMT_AMF,
IMO naming pixel formats to be identical to the API hosting them was a mistake. It's an AMFSurface, call the format AV_PIX_FMT_AMF_SURFACE.
Also no reason to copy old formats by putting your pointer in data[3], put it in data[0].
Thanks,
- Mark
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
prev parent reply other threads:[~2024-02-14 20:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 1:55 Dmitrii Ovchinnikov
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 2/9] libavcodec: add amfdec Dmitrii Ovchinnikov
2024-02-14 23:41 ` Mark Thompson
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 3/9] avcodec/amfenc: Fixes the color information in the output Dmitrii Ovchinnikov
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 4/9] avcodec/amfenc: HDR metadata Dmitrii Ovchinnikov
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 5/9] avcodec/amfenc: add 10 bit encoding in av1_amf Dmitrii Ovchinnikov
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 6/9] avcodec/amfenc: add smart access video option Dmitrii Ovchinnikov
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 7/9] libavcodec/amfenc: redesign to use hwcontext_amf Dmitrii Ovchinnikov
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 8/9] avfilter/scale_amf: Add AMF HW scaler & color converter Dmitrii Ovchinnikov
2024-02-14 15:08 ` Timo Rothenpieler
2024-02-14 15:27 ` Evgeny Pavlov
2024-02-14 16:26 ` Dennis Mungai
2024-02-19 11:18 ` Evgeny Pavlov
2024-02-19 14:43 ` Dennis Mungai
2024-02-14 1:55 ` [FFmpeg-devel] [PATCH 9/9] doc/filters: Add documentation for AMF filters Dmitrii Ovchinnikov
2024-02-14 2:56 ` [FFmpeg-devel] [PATCH 1/9] libavutil: add hwcontext_amf James Almer
2024-02-14 16:48 ` Dmitrii Ovchinnikov
2024-02-14 20:56 ` Mark Thompson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3fd27a93-d2bd-41f8-8572-ef4ddfddc871@jkqxz.net \
--to=sw@jkqxz.net \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git