Re: [FFmpeg-devel] [PATCH 2/9] libavcodec: add amfdec.

2024-02-14 Thread Mark Thompson

On 14/02/2024 01:55, Dmitrii Ovchinnikov wrote:

From: Evgeny Pavlov 

Added AMF based h264, hevc, av1 decoders.
Co-authored-by: Dmitrii Ovchinnikov 
---
  libavcodec/Makefile |   4 +-
  libavcodec/allcodecs.c  |   3 +
  libavcodec/amfdec.c | 667 
  libavcodec/amfdec.h |  75 +
  libavcodec/h264_slice.c |   3 +
  libavcodec/h264dec.c|   3 +
  libavcodec/hwconfig.h   |   2 +
  7 files changed, 755 insertions(+), 2 deletions(-)
  create mode 100644 libavcodec/amfdec.c
  create mode 100644 libavcodec/amfdec.h

...
+
+static int amf_decode_init(AVCodecContext *avctx)
+{
+AvAmfDecoderContext *ctx = avctx->priv_data;
+int ret;
+enum AVPixelFormat pix_fmts[3] = {
+AV_PIX_FMT_AMF,
+avctx->pix_fmt,
+AV_PIX_FMT_NONE };
+
+ret = ff_get_format(avctx, pix_fmts);
+if (ret < 0) {
+avctx->pix_fmt = AV_PIX_FMT_NONE;
+}


I think you've misunderstood how decoder setup works.  AVCodecContext.pix_fmt 
happens to be set to an initial value in some cases which use libavformat 
(including the ffmpeg utility), but there is no requirement on the user to do 
so (see the doxy).  Also all of the format information can change at any moment 
mid-stream (consider adaptive streaming scenarios).

It is therefore necessary for the decoder to parse the input and determine the 
intended format before calling the get_format callback, and to do that again 
whenever the format changes.  Calling it once at the beginning does not work at 
all.


...
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 8464a0b34c..d11821194f 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -864,6 +864,9 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, 
int force_callback)
  #if CONFIG_H264_NVDEC_HWACCEL
  *fmt++ = AV_PIX_FMT_CUDA;
  #endif
+#if CONFIG_H264_AMFDEC_HWACCEL
+*fmt++ = AV_PIX_FMT_AMF;
+#endif
  #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
  if (h->avctx->colorspace != AVCOL_SPC_RGB)
  *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 9f5893c512..7a2c9eecef 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -1137,6 +1137,9 @@ const FFCodec ff_h264_decoder = {
  #if CONFIG_H264_NVDEC_HWACCEL
 HWACCEL_NVDEC(h264),
  #endif
+#if CONFIG_H264_AMFDEC_HWACCEL
+   HWACCEL_AMFDEC(h264),
+#endif
  #if CONFIG_H264_VAAPI_HWACCEL
 HWACCEL_VAAPI(h264),
  #endif


I don't see any acceleration support here at all, this is entirely an offload 
decoder.

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-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/9] libavcodec: add amfdec.

2024-02-13 Thread Dmitrii Ovchinnikov
From: Evgeny Pavlov 

Added AMF based h264, hevc, av1 decoders.
Co-authored-by: Dmitrii Ovchinnikov 
---
 libavcodec/Makefile |   4 +-
 libavcodec/allcodecs.c  |   3 +
 libavcodec/amfdec.c | 667 
 libavcodec/amfdec.h |  75 +
 libavcodec/h264_slice.c |   3 +
 libavcodec/h264dec.c|   3 +
 libavcodec/hwconfig.h   |   2 +
 7 files changed, 755 insertions(+), 2 deletions(-)
 create mode 100644 libavcodec/amfdec.c
 create mode 100644 libavcodec/amfdec.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 470d7cb9b1..c2e4715f4b 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -69,7 +69,7 @@ include $(SRC_PATH)/libavcodec/x86/vvc/Makefile
 OBJS-$(CONFIG_AANDCTTABLES)+= aandcttab.o
 OBJS-$(CONFIG_AC3DSP)  += ac3dsp.o ac3.o ac3tab.o
 OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o 
mpeg4audio_sample_rates.o
-OBJS-$(CONFIG_AMF) += amfenc.o
+OBJS-$(CONFIG_AMF) += amfenc.o amfdec.o
 OBJS-$(CONFIG_AUDIO_FRAME_QUEUE)   += audio_frame_queue.o
 OBJS-$(CONFIG_ATSC_A53)+= atsc_a53.o
 OBJS-$(CONFIG_AUDIODSP)+= audiodsp.o
@@ -1265,7 +1265,7 @@ SKIPHEADERS+= %_tablegen.h
  \
   vulkan_video_codec_av1std.h   \
   $(ARCH)/vpx_arith.h  \
 
-SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
+SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h amfdec.h
 SKIPHEADERS-$(CONFIG_D3D11VA)  += d3d11va.h dxva2_internal.h
 SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va_decode.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index ef8c3a6d7d..c344c70e00 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -851,10 +851,12 @@ extern const FFCodec ff_av1_nvenc_encoder;
 extern const FFCodec ff_av1_qsv_decoder;
 extern const FFCodec ff_av1_qsv_encoder;
 extern const FFCodec ff_av1_amf_encoder;
+extern const FFCodec ff_av1_amf_decoder;
 extern const FFCodec ff_av1_vaapi_encoder;
 extern const FFCodec ff_libopenh264_encoder;
 extern const FFCodec ff_libopenh264_decoder;
 extern const FFCodec ff_h264_amf_encoder;
+extern const FFCodec ff_h264_amf_decoder;
 extern const FFCodec ff_h264_cuvid_decoder;
 extern const FFCodec ff_h264_mf_encoder;
 extern const FFCodec ff_h264_nvenc_encoder;
@@ -864,6 +866,7 @@ extern const FFCodec ff_h264_v4l2m2m_encoder;
 extern const FFCodec ff_h264_vaapi_encoder;
 extern const FFCodec ff_h264_videotoolbox_encoder;
 extern const FFCodec ff_hevc_amf_encoder;
+extern const FFCodec ff_hevc_amf_decoder;
 extern const FFCodec ff_hevc_cuvid_decoder;
 extern const FFCodec ff_hevc_mediacodec_decoder;
 extern const FFCodec ff_hevc_mediacodec_encoder;
diff --git a/libavcodec/amfdec.c b/libavcodec/amfdec.c
new file mode 100644
index 00..9d618ff442
--- /dev/null
+++ b/libavcodec/amfdec.c
@@ -0,0 +1,667 @@
+/*
+ * 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 
+#include 
+#include "libavutil/hwcontext_amf.h"
+#include "amfdec.h"
+#include "codec_internal.h"
+#include "hwconfig.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/time.h"
+#include "decode.h"
+#include "libavutil/mastering_display_metadata.h"
+
+#if CONFIG_D3D11VA
+#include "libavutil/hwcontext_d3d11va.h"
+#endif
+#if CONFIG_DXVA2
+#define COBJMACROS
+#include "libavutil/hwcontext_dxva2.h"
+#endif
+
+#ifdef _WIN32
+#include "compat/w32dlfcn.h"
+#else
+#include 
+#endif
+
+#define propNotFound 0
+
+const enum AVPixelFormat amf_dec_pix_fmts[] = {
+AV_PIX_FMT_YUV420P,
+AV_PIX_FMT_NV12,
+AV_PIX_FMT_BGRA,
+AV_PIX_FMT_ARGB,
+AV_PIX_FMT_RGBA,
+AV_PIX_FMT_GRAY8,
+AV_PIX_FMT_BGR0,
+AV_PIX_FMT_YUYV422,
+AV_PIX_FMT_P010,
+AV_PIX_FMT_P012,
+AV_PIX_FMT_YUV420P10,
+AV_PIX_FMT_YUV420P12,
+AV_PIX_FMT_YUV420P16,
+#if CONFIG_D3D11VA
+AV_PIX_FMT_D3D11,
+#endif
+#if CONFIG_DXVA2
+AV_PIX_FMT_DXVA2_VLD,
+#endif
+AV_PIX_FMT_AMF,
+AV_PIX_FMT_NONE
+};
+
+static const AVCodecHWConfigInternal *const amf_hw_configs[] = {
+&(const