Re: [FFmpeg-devel] [PATCH] avcodec/vvcdec: frame_context_setup, set fc->ref to NULL

2024-02-13 Thread Nuo Mi
On Tue, Feb 13, 2024 at 6:39 PM Frank Plowman  wrote:

> On 13/02/2024 02:30, Nuo Mi wrote:
> > fc->ref points to an old VVCFrame, which cannot be used after
> frame_context_setup.
> > This prevents crashes in decode_nal_units-->ff_vvc_report_frame_finished.
> >
> > Signed-off-by: Frank Plowman 
> > ---
> >  libavcodec/vvc/vvcdec.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
> > index 8163b5ecb6..e88e746de4 100644
> > --- a/libavcodec/vvc/vvcdec.c
> > +++ b/libavcodec/vvc/vvcdec.c
> > @@ -594,6 +594,8 @@ static int frame_context_setup(VVCFrameContext *fc,
> VVCContext *s)
> >  {
> >  int ret;
> >
> > +fc->ref = NULL;
> > +
> >  // copy refs from the last frame
> >  if (s->nb_frames && s->nb_fcs > 1) {
> >  VVCFrameContext *prev = get_frame_context(s, fc, -1);
>
> LGTM.  Fixes the crash on all the fuzz data I have which produce it.
> FATE runners are failing at the time of writing, but I manually ran this
> against the VVC tests as well as the suite from the FFVVC GitHub and all
> tests passed.
>
> Btw, I don't think you should add Signed-off-by tags for other people.
> Their exact meaning varies by project and I am not sure of their meaning
> in FFmpeg (if there is one), but generally they indicate that person
> claims some sort of responsibility for the patch in the case of e.g. a
> license violation.  That being said, I am happy to sign this off.
>
Hi Frank,
Thank you for the review.
Sorry for the misuse. I will pay attention to it next time.
Patch applied.

>
> --
> Frank
> ___
> 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 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".


Re: [FFmpeg-devel] [PATCH v5] lavc/libvpxenc: add screen-content-mode option

2024-02-13 Thread James Zern via ffmpeg-devel
On Mon, Feb 12, 2024 at 10:34 PM Dariusz Marcinkiewicz via
ffmpeg-devel  wrote:
>
> This exposes VP8E_SET_SCREEN_CONTENT_MODE option from libvpx.
>
> Co-authored-by: Erik Språng 
> Signed-off-by: Dariusz Marcinkiewicz 
> ---
>  doc/encoders.texi  |  6 ++
>  libavcodec/libvpxenc.c | 13 +
>  libavcodec/version.h   |  2 +-
>  3 files changed, 20 insertions(+), 1 deletion(-)
>

lgtm. I'll submit this soon if there are no other comments.

> diff --git a/doc/encoders.texi b/doc/encoders.texi
> index c9fe6d6143..13a7084512 100644
> --- a/doc/encoders.texi
> +++ b/doc/encoders.texi
> @@ -2237,6 +2237,12 @@ the two temporal layer 2 frames within the temporal 
> period.
>  @end table
>  @end table
>
> +@item VP8-specific options
> +@table @option
> +@item screen-content-mode
> +Screen content mode, one of: (0) off, (1) screen, (2) screen with more 
> aggressive rate control.

I swapped the ()s: 0 (off) ...
___
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".


Re: [FFmpeg-devel] [PATCH] vvcdec: Mark as experimental

2024-02-13 Thread Nuo Mi
>
>
>>>
>>> If there are no objections, I'll push it tomorrow.
> thank you, Kieran and Paul.
>
Hi Kieran,
Patchwork didn't get your patch.
I've checked the fate status locally, and it indicates that "make fate-vvc"
will fail.
Could you please send a new one to the patchwork?

Thank you.
___
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".


Re: [FFmpeg-devel] [PATCH 1/9] libavutil: add hwcontext_amf.

2024-02-13 Thread James Almer

On 2/13/2024 10:55 PM, Dmitrii Ovchinnikov wrote:

+const FormatMap format_map[] =
+{
+{ AV_PIX_FMT_NONE,  AMF_SURFACE_UNKNOWN },
+{ AV_PIX_FMT_NV12,  AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_BGR0,  AMF_SURFACE_BGRA },
+{ AV_PIX_FMT_RGB0,  AMF_SURFACE_RGBA },
+{ AV_PIX_FMT_BGRA,  AMF_SURFACE_BGRA },
+{ AV_PIX_FMT_ARGB,  AMF_SURFACE_ARGB },
+{ AV_PIX_FMT_RGBA,  AMF_SURFACE_RGBA },
+{ AV_PIX_FMT_GRAY8, AMF_SURFACE_GRAY8 },
+{ AV_PIX_FMT_YUV420P,   AMF_SURFACE_YUV420P },
+{ AV_PIX_FMT_YUYV422,   AMF_SURFACE_YUY2 },
+{ AV_PIX_FMT_P010,  AMF_SURFACE_P010 },
+{ AV_PIX_FMT_YUV420P10, AMF_SURFACE_P010 },


yuv420p10 is not equal to p010.


+{ AV_PIX_FMT_YUV420P12, AMF_SURFACE_P012 },
+{ AV_PIX_FMT_YUV420P12, AMF_SURFACE_P012 },


Why the duplication? And there's AV_PIX_FMT_P012.


+{ AV_PIX_FMT_YUV420P16, AMF_SURFACE_P016 },


AV_PIX_FMT_P016?


+{ AV_PIX_FMT_YUV422P10LE,   AMF_SURFACE_Y210 },


AV_PIX_FMT_Y210?


+{ AV_PIX_FMT_YUV444P10LE,   AMF_SURFACE_Y416 },
+};


[...]


diff --git a/libavutil/hwcontext_amf.h b/libavutil/hwcontext_amf.h
new file mode 100644
index 00..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 
+#include 
+#include 
+#include "pixfmt.h"
+
+#include "libavformat/avformat.h"


lavu can't depend on lavf.


+#include "libavutil/hwcontext.h"
+
+#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"


Bad namespace. And this doesn't need to be public.


+
+typedef struct AmfTraceWriter {


Ditto namespace. Does this need to be public?


+AMFTraceWriterVtbl  *vtbl;
+void*avctx;
+void*avcl;
+} AmfTraceWriter;
+
+typedef struct AVAMFDeviceContextInternal {


If this is internal, then define it in an internal header and put only 
the typedef here.



+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;


AVAMFDeviceContextInternal *internal. Can't say if this is needed here 
at all or not.



+} AVAMFDeviceContext;
+
+typedef struct AMFFramesContext {


Again namespace.


+AMFSurface * surfaces;
+intnb_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}


These should probably be internal.


+
+typedef struct FormatMap {
+enum AVPixelFormat   av_format;
+enum AMF_SURFACE_FORMAT  amf_format;
+} FormatMap;
+
+extern const FormatMap format_map[];


This doesn't need to be in a public header.


+enum AMF_SURFACE_FORMAT av_amf_av_to_amf_format(enum AVPixelFormat fmt);


Namespace.


+enum AVPixelFormat av_amf_to_av_format(enum AMF_SURFACE_FORMAT fmt);
+extern AmfTraceWriter av_amf_trace_writer;


Same as AmfTraceWriter, this probably doesn't need to be public.


+
+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 

Re: [FFmpeg-devel] [PATCH v4] lavc/libvpxenc: add screen-content-mode option

2024-02-13 Thread Dariusz Marcinkiewicz via ffmpeg-devel
Hello.

On Tue, Feb 13, 2024 at 12:12 AM James Zern  wrote:
>
[...]
> > +@item screen-content-mode
> > +Screen content mode, one of: off (0), screen (1), screen with more 
> > aggressive rate control (2).
> > +
>
> Move this above 'VP9-specific options' and add a section for VP8. Also
> reword this to '...one of: 0 (off), 1 (screen), ...'. The parameter is
> an integer so should list that first, similar to aq-mode.
>

This and below are addressed in v5.

Thank you.
___
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 9/9] doc/filters: Add documentation for AMF filters

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

Signed-off-by: Evgeny Pavlov 
---
 doc/filters.texi | 238 +++
 1 file changed, 238 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index e0436a5755..4c5b9c1f63 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -21330,6 +21330,244 @@ If the specified expression is not valid, it is kept 
at its current
 value.
 @end table
 
+@anchor{scale_amf}
+@section scale_amf
+
+Scale (resize) and convert colorspace, transfer characteristics or color 
primaries for the input video, using AMD Advanced Media Framework library for 
hardware acceleration.
+Setting the output width and height works in the same way as for the 
@ref{scale} filter.
+
+The filter accepts the following options:
+@table @option
+@item w
+@item h
+Set the output video dimension expression. Default value is the input 
dimension.
+
+Allows for the same expressions as the @ref{scale} filter.
+
+@item scale_type
+Sets the algorithm used for scaling:
+
+@table @var
+@item bilinear
+Bilinear
+
+This is the default.
+
+@item bicubic
+Bicubic
+
+@end table
+
+@item format
+Controls the output pixel format. By default, or if none is specified, the 
input
+pixel format is used.
+
+
+@item force_original_aspect_ratio
+@item force_divisible_by
+Work the same as the identical @ref{scale} filter options.
+
+@anchor{color_profile}
+@item color_profile
+Specify all color properties at once.
+
+The accepted values are:
+@table @samp
+@item bt601
+BT.601
+
+@item bt709
+BT.709
+
+@item bt2020
+BT.2020
+
+@end table
+
+@anchor{trc}
+@item trc
+Specify output transfer characteristics.
+
+The accepted values are:
+@table @samp
+@item bt709
+BT.709
+
+@item gamma22
+Constant gamma of 2.2
+
+@item gamma28
+Constant gamma of 2.8
+
+@item smpte170m
+SMPTE-170M
+
+@item smpte240m
+SMPTE-240M
+
+@item linear
+Linear
+
+@item log
+LOG
+
+@item log-sqrt
+LOG_SQRT
+
+@item iec61966-2-4
+iec61966-2-4
+
+@item bt1361-ecg
+BT1361_ECG
+
+@item iec61966-2-1
+iec61966-2-1
+
+@item bt2020-10
+BT.2020 for 10-bits content
+
+@item bt2020-12
+BT.2020 for 12-bits content
+
+@item smpte2084
+SMPTE2084
+
+@item smpte428
+SMPTE428
+
+@item arib-std-b67
+ARIB_STD_B67
+
+@end table
+
+@anchor{primaries}
+@item primaries
+Specify output color primaries.
+
+The accepted values are:
+@table @samp
+@item bt709
+BT.709
+
+@item bt470m
+BT.470M
+
+@item bt470bg
+BT.470BG or BT.601-6 625
+
+@item smpte170m
+SMPTE-170M or BT.601-6 525
+
+@item smpte240m
+SMPTE-240M
+
+@item film
+film
+
+@item bt2020
+BT.2020
+
+@item smpte428
+SMPTE-428
+
+@item smpte431
+SMPTE-431
+
+@item smpte432
+SMPTE-432
+
+@item jedec-p22
+JEDEC P22 phosphors
+
+@end table
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Scale input to 720p, keeping aspect ratio and ensuring the output is yuv420p.
+@example
+scale_amf=-2:720:format=yuv420p
+@end example
+
+@item
+Upscale to 4K and change color profile to bt2020.
+@example
+scale_amf=4096:2160:color_profile=bt2020
+@end example
+@end itemize
+
+@anchor{scale_amf_hq}
+@section scale_amf_hq
+
+Upscale (size increasing) for the input video using AMD Advanced Media 
Framework library for hardware acceleration.
+Use advanced algorithms for upscaling with higher output quality.
+Setting the output width and height works in the same way as for the 
@ref{scale} filter.
+
+The filter accepts the following options:
+@table @option
+@item w
+@item h
+Set the output video dimension expression. Default value is the input 
dimension.
+
+Allows for the same expressions as the @ref{scale} filter.
+
+@item algorithm
+Sets the algorithm used for scaling:
+
+@table @var
+@item bilinear
+Bilinear
+
+@item bicubic
+Bicubic
+
+@item sr1-0
+Video SR1.0
+This is a default value
+
+@item point
+Point
+
+@item sr1-1
+Video SR1.1
+
+@end table
+
+@item sharpness
+Control hq scaler sharpening. The value is a float in the range of [0.0, 2.0]
+
+@item format
+Controls the output pixel format. By default, or if none is specified, the 
input
+pixel format is used.
+
+@item keep-ratio
+Force the scaler to keep the aspect ratio of the input image when the output 
size has a different aspect ratio.
+Default value is false.
+
+@item fill
+Specifies whether the output image outside the region of interest,
+which does not fill the entire output surface should be filled with a solid 
color.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Scale input to 720p, keeping aspect ratio and ensuring the output is yuv420p.
+@example
+scale_amf_hq=-2:720:format=yuv420p
+@end example
+
+@item
+Upscale to 4K with algorithm video SR1.1.
+@example
+scale_amf_hq=4096:2160:algorithm=sr1-1
+@end example
+@end itemize
+
 @anchor{scale_cuda}
 @section scale_cuda
 
-- 
2.38.1.windows.1

___
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 8/9] avfilter/scale_amf: Add AMF HW scaler & color converter

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

This commit adds two AMF filters: scale_amf & scale_amf_hq.
Both filters are using AMF hardware acceleration.
scale_amf supports simple scaling algorithms & color conversion.
scale_amf_hq supports advanced scaling algorithms & might be used
for upscaling only.

Signed-off-by: Evgeny Pavlov 
---
 configure |   1 +
 libavfilter/Makefile  |   2 +
 libavfilter/allfilters.c  |   2 +
 libavfilter/vf_scale_amf.c| 266 +++
 libavfilter/vf_scale_amf_common.c | 515 ++
 libavfilter/vf_scale_amf_common.h |  71 
 libavfilter/vf_scale_amf_hq.c | 191 +++
 7 files changed, 1048 insertions(+)
 create mode 100644 libavfilter/vf_scale_amf.c
 create mode 100644 libavfilter/vf_scale_amf_common.c
 create mode 100644 libavfilter/vf_scale_amf_common.h
 create mode 100644 libavfilter/vf_scale_amf_hq.c

diff --git a/configure b/configure
index f72533b7d2..3d1c44d7ae 100755
--- a/configure
+++ b/configure
@@ -3826,6 +3826,7 @@ rubberband_filter_deps="librubberband"
 sab_filter_deps="gpl swscale"
 scale2ref_filter_deps="swscale"
 scale_filter_deps="swscale"
+scale_amf_filter_deps="amf"
 scale_qsv_filter_deps="libmfx"
 scale_qsv_filter_select="qsvvpp"
 scdet_filter_select="scene_sad"
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f6c1d641d6..a87e519b85 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -456,6 +456,8 @@ OBJS-$(CONFIG_ROBERTS_OPENCL_FILTER) += 
vf_convolution_opencl.o opencl.o
 OBJS-$(CONFIG_ROTATE_FILTER) += vf_rotate.o
 OBJS-$(CONFIG_SAB_FILTER)+= vf_sab.o
 OBJS-$(CONFIG_SCALE_FILTER)  += vf_scale.o scale_eval.o
+OBJS-$(CONFIG_SCALE_AMF_FILTER)  += vf_scale_amf.o scale_eval.o 
vf_scale_amf_common.o
+OBJS-$(CONFIG_SCALE_AMF_FILTER)  += vf_scale_amf_hq.o scale_eval.o 
vf_scale_amf_common.o
 OBJS-$(CONFIG_SCALE_CUDA_FILTER) += vf_scale_cuda.o scale_eval.o \
 vf_scale_cuda.ptx.o 
cuda/load_helper.o
 OBJS-$(CONFIG_SCALE_NPP_FILTER)  += vf_scale_npp.o scale_eval.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 149bf50997..299cfb148b 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -430,6 +430,8 @@ extern const AVFilter ff_vf_roberts_opencl;
 extern const AVFilter ff_vf_rotate;
 extern const AVFilter ff_vf_sab;
 extern const AVFilter ff_vf_scale;
+extern const AVFilter ff_vf_scale_amf;
+extern const AVFilter ff_vf_scale_amf_hq;
 extern const AVFilter ff_vf_scale_cuda;
 extern const AVFilter ff_vf_scale_npp;
 extern const AVFilter ff_vf_scale_qsv;
diff --git a/libavfilter/vf_scale_amf.c b/libavfilter/vf_scale_amf.c
new file mode 100644
index 00..6d2c211d83
--- /dev/null
+++ b/libavfilter/vf_scale_amf.c
@@ -0,0 +1,266 @@
+/*
+ * 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
+ */
+
+/**
+ * @file
+ * scale video filter - AMF
+ */
+
+#include 
+#include 
+
+#include "libavutil/avassert.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/time.h"
+
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_amf.h"
+
+#include "AMF/components/VideoConverter.h"
+#include "vf_scale_amf_common.h"
+
+#include "avfilter.h"
+#include "formats.h"
+#include "video.h"
+#include "scale_eval.h"
+#include "internal.h"
+
+#if CONFIG_DXVA2
+#include 
+#endif
+
+#if CONFIG_D3D11VA
+#include 
+#endif
+
+static int amf_scale_query_formats(AVFilterContext *avctx)
+{
+const enum AVPixelFormat *output_pix_fmts;
+static const enum AVPixelFormat input_pix_fmts[] = {
+AV_PIX_FMT_NV12,
+AV_PIX_FMT_P010,
+AV_PIX_FMT_0RGB,
+AV_PIX_FMT_BGR0,
+AV_PIX_FMT_BGRA,
+AV_PIX_FMT_RGB0,
+AV_PIX_FMT_RGBA,
+AV_PIX_FMT_GRAY8,
+AV_PIX_FMT_YUV420P,
+AV_PIX_FMT_YUV420P10,
+AV_PIX_FMT_YUYV422,
+AV_PIX_FMT_AMF,
+AV_PIX_FMT_NONE,
+};
+static const enum AVPixelFormat output_pix_fmts_default[] = {
+AV_PIX_FMT_AMF,
+AV_PIX_FMT_D3D11,
+AV_PIX_FMT_DXVA2_VLD,
+AV_PIX_FMT_NV12,
+

[FFmpeg-devel] [PATCH 7/9] libavcodec/amfenc: redesign to use hwcontext_amf.

2024-02-13 Thread Dmitrii Ovchinnikov
Co-authored-by: Evgeny Pavlov 
---
 libavcodec/amfenc.c | 560 
 libavcodec/amfenc.h |  23 +-
 2 files changed, 158 insertions(+), 425 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index f1b76bd6aa..e6e5302cca 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -29,6 +29,7 @@
 #define COBJMACROS
 #include "libavutil/hwcontext_dxva2.h"
 #endif
+#include "libavutil/hwcontext_amf.h"
 #include "libavutil/mem.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/time.h"
@@ -38,6 +39,18 @@
 #include "internal.h"
 #include "libavutil/mastering_display_metadata.h"
 
+#if CONFIG_D3D11VA
+#include 
+#endif
+
+#ifdef _WIN32
+#include "compat/w32dlfcn.h"
+#else
+#include 
+#endif
+
+#define PTS_PROP L"PtsProp"
+
 static int amf_save_hdr_metadata(AVCodecContext *avctx, const AVFrame *frame, 
AMFHDRMetadata *hdrmeta)
 {
 AVFrameSideData*sd_display;
@@ -88,20 +101,6 @@ static int amf_save_hdr_metadata(AVCodecContext *avctx, 
const AVFrame *frame, AM
 return 1;
 }
 
-#if CONFIG_D3D11VA
-#include 
-#endif
-
-#ifdef _WIN32
-#include "compat/w32dlfcn.h"
-#else
-#include 
-#endif
-
-#define FFMPEG_AMF_WRITER_ID L"ffmpeg_amf"
-
-#define PTS_PROP L"PtsProp"
-
 const enum AVPixelFormat ff_amf_pix_fmts[] = {
 AV_PIX_FMT_NV12,
 AV_PIX_FMT_YUV420P,
@@ -111,289 +110,18 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 #if CONFIG_DXVA2
 AV_PIX_FMT_DXVA2_VLD,
 #endif
+AV_PIX_FMT_AMF,
 AV_PIX_FMT_P010,
 AV_PIX_FMT_NONE
 };
 
-typedef struct FormatMap {
-enum AVPixelFormat   av_format;
-enum AMF_SURFACE_FORMAT  amf_format;
-} FormatMap;
-
-static const FormatMap format_map[] =
-{
-{ AV_PIX_FMT_NONE,   AMF_SURFACE_UNKNOWN },
-{ AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
-{ AV_PIX_FMT_P010,   AMF_SURFACE_P010 },
-{ AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
-{ AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
-{ AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
-{ AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
-{ AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
-};
-
-static enum AMF_SURFACE_FORMAT amf_av_to_amf_format(enum AVPixelFormat fmt)
-{
-int i;
-for (i = 0; i < amf_countof(format_map); i++) {
-if (format_map[i].av_format == fmt) {
-return format_map[i].amf_format;
-}
-}
-return AMF_SURFACE_UNKNOWN;
-}
-
-static void AMF_CDECL_CALL AMFTraceWriter_Write(AMFTraceWriter *pThis,
-const wchar_t *scope, const wchar_t *message)
-{
-AmfTraceWriter *tracer = (AmfTraceWriter*)pThis;
-av_log(tracer->avctx, AV_LOG_DEBUG, "%ls: %ls", scope, message); // \n is 
provided from AMF
-}
-
-static void AMF_CDECL_CALL AMFTraceWriter_Flush(AMFTraceWriter *pThis)
-{
-}
-
-static AMFTraceWriterVtbl tracer_vtbl =
-{
-.Write = AMFTraceWriter_Write,
-.Flush = AMFTraceWriter_Flush,
-};
-
-static int amf_load_library(AVCodecContext *avctx)
-{
-AmfContext*ctx = avctx->priv_data;
-AMFInit_Fn init_fun;
-AMFQueryVersion_Fn version_fun;
-AMF_RESULT res;
-
-ctx->delayed_frame = av_frame_alloc();
-if (!ctx->delayed_frame) {
-return AVERROR(ENOMEM);
-}
-// hardcoded to current HW queue size - will auto-realloc if too small
-ctx->timestamp_list = av_fifo_alloc2(avctx->max_b_frames + 16, 
sizeof(int64_t),
- AV_FIFO_FLAG_AUTO_GROW);
-if (!ctx->timestamp_list) {
-return AVERROR(ENOMEM);
-}
-ctx->dts_delay = 0;
-
-
-ctx->library = dlopen(AMF_DLL_NAMEA, RTLD_NOW | RTLD_LOCAL);
-AMF_RETURN_IF_FALSE(ctx, ctx->library != NULL,
-AVERROR_UNKNOWN, "DLL %s failed to open\n", AMF_DLL_NAMEA);
-
-init_fun = (AMFInit_Fn)dlsym(ctx->library, AMF_INIT_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, init_fun != NULL, AVERROR_UNKNOWN, "DLL %s failed 
to find function %s\n", AMF_DLL_NAMEA, AMF_INIT_FUNCTION_NAME);
-
-version_fun = (AMFQueryVersion_Fn)dlsym(ctx->library, 
AMF_QUERY_VERSION_FUNCTION_NAME);
-AMF_RETURN_IF_FALSE(ctx, version_fun != NULL, AVERROR_UNKNOWN, "DLL %s 
failed to find function %s\n", AMF_DLL_NAMEA, AMF_QUERY_VERSION_FUNCTION_NAME);
-
-res = version_fun(>version);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_QUERY_VERSION_FUNCTION_NAME, res);
-res = init_fun(AMF_FULL_VERSION, >factory);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "%s failed with 
error %d\n", AMF_INIT_FUNCTION_NAME, res);
-res = ctx->factory->pVtbl->GetTrace(ctx->factory, >trace);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetTrace() 
failed with error %d\n", res);
-res = ctx->factory->pVtbl->GetDebug(ctx->factory, >debug);
-AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "GetDebug() 
failed with error %d\n", res);
-return 0;
-}
-
-#if CONFIG_D3D11VA
-static int amf_init_from_d3d11_device(AVCodecContext *avctx, 

[FFmpeg-devel] [PATCH 6/9] avcodec/amfenc: add smart access video option

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

This commit adds option for enabling SmartAccess Video (SAV)
in AMF encoders. SAV is an AMD hardware-specific feature which
enables the parallelization of encode and decode streams across
multiple Video Codec Engine (VCN) hardware instances.

Signed-off-by: Evgeny Pavlov 
---
 libavcodec/amfenc.h  |  1 +
 libavcodec/amfenc_av1.c  | 18 ++
 libavcodec/amfenc_h264.c | 18 ++
 libavcodec/amfenc_hevc.c | 18 ++
 4 files changed, 55 insertions(+)

diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 62736ef579..1bda0136bd 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -90,6 +90,7 @@ typedef struct AmfContext {
 int quality;
 int b_frame_delta_qp;
 int ref_b_frame_delta_qp;
+int smart_access_video;
 
 // Dynamic options, can be set after Init() call
 
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 9b32616aa8..109533fb2d 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -104,6 +104,8 @@ static const AVOption options[] = {
 
 { "log_to_dbg", "Enable AMF logging to debug output",   
OFFSET(log_to_dbg), AV_OPT_TYPE_BOOL,{.i64 = 0 }, 0, 1, VE },
 
+{ "smart_access_video", "Enable Smart Access Video",
OFFSET(smart_access_video), AV_OPT_TYPE_BOOL, {.i64 = -1  }, -1, 1, 
VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -265,6 +267,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 }
 
+if (ctx->smart_access_video != -1) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
+if (res != AMF_OK) {
+av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not 
supported by AMF.\n");
+if (ctx->smart_access_video != 0)
+return AVERROR(ENOSYS);
+} else {
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is 
set.\n", ctx->smart_access_video);
+// Set low latency mode if Smart Access Video is enabled
+if (ctx->smart_access_video != 0) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_ENCODING_LATENCY_MODE, 
AMF_VIDEO_ENCODER_AV1_ENCODING_LATENCY_MODE_LOWEST_LATENCY);
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low 
latency mode.\n");
+}
+}
+}
+
 // Pre-Pass, Pre-Analysis, Two-Pass
 if (ctx->rate_control_mode == 
AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_METHOD_CONSTANT_QP) {
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_RATE_CONTROL_PREENCODE, 0);
diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c
index f785e091c9..f83a9fcaa7 100644
--- a/libavcodec/amfenc_h264.c
+++ b/libavcodec/amfenc_h264.c
@@ -136,6 +136,8 @@ static const AVOption options[] = {
 
 { "log_to_dbg", "Enable AMF logging to debug output",   
OFFSET(log_to_dbg), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
 
+{ "smart_access_video", "Enable Smart Access Video",
OFFSET(smart_access_video), AV_OPT_TYPE_BOOL, {.i64 = -1  }, -1, 1, VE},
+
 //Pre Analysis options
 { "preanalysis","Enable preanalysis",  
 OFFSET(preanalysis),   
 AV_OPT_TYPE_BOOL,   {.i64 = -1 }, -1, 1, VE },
 
@@ -369,6 +371,22 @@ FF_ENABLE_DEPRECATION_WARNINGS
 av_log(ctx, AV_LOG_WARNING, "rate control mode is PEAK_CONSTRAINED_VBR 
but rc_max_rate is not set\n");
 }
 
+if (ctx->smart_access_video != -1) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_ENABLE_SMART_ACCESS_VIDEO, ctx->smart_access_video != 0);
+if (res != AMF_OK) {
+av_log(avctx, AV_LOG_ERROR, "The Smart Access Video is not 
supported by AMF.\n");
+if (ctx->smart_access_video != 0)
+return AVERROR(ENOSYS);
+} else {
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video (%d) is 
set.\n", ctx->smart_access_video);
+// Set low latency mode if Smart Access Video is enabled
+if (ctx->smart_access_video != 0) {
+AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_LOWLATENCY_MODE, true);
+av_log(avctx, AV_LOG_INFO, "The Smart Access Video set low 
latency mode.\n");
+}
+}
+}
+
 if (ctx->preanalysis != -1) {
 AMF_ASSIGN_PROPERTY_BOOL(res, ctx->encoder, 
AMF_VIDEO_ENCODER_PRE_ANALYSIS_ENABLE, !!((ctx->preanalysis == 0) ? false : 
true));
 }
diff --git a/libavcodec/amfenc_hevc.c b/libavcodec/amfenc_hevc.c
index 8c6401c646..f3caa7cb29 100644
--- 

[FFmpeg-devel] [PATCH 5/9] avcodec/amfenc: add 10 bit encoding in av1_amf

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

v2: refactored after review

Signed-off-by: Evgeny Pavlov 
Co-authored-by: Dmitrii Ovchinnikov 
---
 libavcodec/amfenc.c |  2 ++
 libavcodec/amfenc_av1.c | 22 ++
 2 files changed, 24 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 068bb53002..f1b76bd6aa 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -826,6 +826,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
 case AV_CODEC_ID_HEVC:
 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+case AV_CODEC_ID_AV1:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_INPUT_HDR_METADATA, hdrmeta_buffer); break;
 }
 hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
 }
diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c
index 3f164ccc59..9b32616aa8 100644
--- a/libavcodec/amfenc_av1.c
+++ b/libavcodec/amfenc_av1.c
@@ -165,6 +165,9 @@ static av_cold int amf_encode_init_av1(AVCodecContext* 
avctx)
 AMFGuid guid;
 AMFRate framerate;
 AMFSize framesize = AMFConstructSize(avctx->width, 
avctx->height);
+amf_int64   color_depth;
+amf_int64   color_profile;
+enumAVPixelFormat pix_fmt;
 
 
 
@@ -203,6 +206,25 @@ FF_ENABLE_DEPRECATION_WARNINGS
 }
 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_PROFILE, profile);
 
+/// Color profile
+color_profile = ff_amf_get_color_profile(avctx);
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
+
+/// Color Depth
+pix_fmt = avctx->hw_frames_ctx ? 
((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format
+: avctx->pix_fmt;
+color_depth = AMF_COLOR_BIT_DEPTH_8;
+if (pix_fmt == AV_PIX_FMT_P010) {
+color_depth = AMF_COLOR_BIT_DEPTH_10;
+}
+
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_COLOR_BIT_DEPTH, color_depth);
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
+/// Color Transfer Characteristics (AMF matches ISO/IEC)
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_TRANSFER_CHARACTERISTIC, 
(amf_int64)avctx->color_trc);
+/// Color Primaries (AMF matches ISO/IEC)
+AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, 
AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PRIMARIES, 
(amf_int64)avctx->color_primaries);
+
 profile_level = avctx->level;
 if (profile_level == AV_LEVEL_UNKNOWN) {
 profile_level = ctx->level;
-- 
2.38.1.windows.1

___
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 4/9] avcodec/amfenc: HDR metadata.

2024-02-13 Thread Dmitrii Ovchinnikov
From: nyanmisaka 

v2: fixes for indentation
---
 libavcodec/amfenc.c | 83 +
 1 file changed, 83 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 0bd15dd812..068bb53002 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -36,6 +36,57 @@
 #include "amfenc.h"
 #include "encode.h"
 #include "internal.h"
+#include "libavutil/mastering_display_metadata.h"
+
+static int amf_save_hdr_metadata(AVCodecContext *avctx, const AVFrame *frame, 
AMFHDRMetadata *hdrmeta)
+{
+AVFrameSideData*sd_display;
+AVFrameSideData*sd_light;
+AVMasteringDisplayMetadata *display_meta;
+AVContentLightMetadata *light_meta;
+
+sd_display = av_frame_get_side_data(frame, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
+if (sd_display) {
+display_meta = (AVMasteringDisplayMetadata *)sd_display->data;
+if (display_meta->has_luminance) {
+const unsigned int luma_den = 1;
+hdrmeta->maxMasteringLuminance =
+(amf_uint32)(luma_den * av_q2d(display_meta->max_luminance));
+hdrmeta->minMasteringLuminance =
+FFMIN((amf_uint32)(luma_den * 
av_q2d(display_meta->min_luminance)), hdrmeta->maxMasteringLuminance);
+}
+if (display_meta->has_primaries) {
+const unsigned int chroma_den = 5;
+hdrmeta->redPrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[0][0])), chroma_den);
+hdrmeta->redPrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[0][1])), chroma_den);
+hdrmeta->greenPrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[1][0])), chroma_den);
+hdrmeta->greenPrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[1][1])), chroma_den);
+hdrmeta->bluePrimary[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[2][0])), chroma_den);
+hdrmeta->bluePrimary[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->display_primaries[2][1])), chroma_den);
+hdrmeta->whitePoint[0] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->white_point[0])), chroma_den);
+hdrmeta->whitePoint[1] =
+FFMIN((amf_uint16)(chroma_den * 
av_q2d(display_meta->white_point[1])), chroma_den);
+}
+
+sd_light = av_frame_get_side_data(frame, 
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
+if (sd_light) {
+light_meta = (AVContentLightMetadata *)sd_light->data;
+if (light_meta) {
+hdrmeta->maxContentLightLevel = (amf_uint16)light_meta->MaxCLL;
+hdrmeta->maxFrameAverageLightLevel = 
(amf_uint16)light_meta->MaxFALL;
+}
+}
+return 0;
+}
+return 1;
+}
 
 #if CONFIG_D3D11VA
 #include 
@@ -683,6 +734,26 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
 }
 
+// HDR10 metadata
+if (frame->color_trc == AVCOL_TRC_SMPTE2084) {
+AMFBuffer * hdrmeta_buffer = NULL;
+res = ctx->context->pVtbl->AllocBuffer(ctx->context, 
AMF_MEMORY_HOST, sizeof(AMFHDRMetadata), _buffer);
+if (res == AMF_OK) {
+AMFHDRMetadata * hdrmeta = 
(AMFHDRMetadata*)hdrmeta_buffer->pVtbl->GetNative(hdrmeta_buffer);
+if (amf_save_hdr_metadata(avctx, frame, hdrmeta) == 0) {
+switch (avctx->codec->id) {
+case AV_CODEC_ID_H264:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+case AV_CODEC_ID_HEVC:
+AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, 
AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
+}
+res = amf_set_property_buffer(surface, 
L"av_frame_hdrmeta", hdrmeta_buffer);
+AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, 
"SetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res);
+}
+hdrmeta_buffer->pVtbl->Release(hdrmeta_buffer);
+}
+}
+
 surface->pVtbl->SetPts(surface, frame->pts);
 AMF_ASSIGN_PROPERTY_INT64(res, surface, PTS_PROP, frame->pts);
 
@@ -746,6 +817,18 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 }
 res_resubmit = AMF_OK;
 if (ctx->delayed_surface != NULL) { // try to resubmit frame
+if (ctx->delayed_surface->pVtbl->HasProperty(ctx->delayed_surface, 
L"av_frame_hdrmeta")) {
+AMFBuffer * 

[FFmpeg-devel] [PATCH 3/9] avcodec/amfenc: Fixes the color information in the output.

2024-02-13 Thread Dmitrii Ovchinnikov
From: Michael Fabian 'Xaymar' Dirks 

added 10 bit support for amf hevc.

before:

command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file.mkv -an -c:v h264_amf res.dx11_hw_h264.mkv
output -  Format of input frames context (p010le) is not supported by AMF.
command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv
output -  Format of input frames context (p010le) is not supported by AMF.

after:

command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v h264_amf res.dx11_hw_h264.mkv
output -  10-bit input video is not supported by AMF H264 encoder
command - ffmpeg.exe -hide_banner -y -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i test_10bit_file -an -c:v hevc_amf res.dx11_hw_hevc.mkv
output -  10bit file

v2 - lost line returned in ff_amf_pix_fmts
v3 - fixes after review
v4 - extract duplicated code, fix incorrect processing of 10-bit input for h264
v5 - non-functional changes after review

Co-authored-by: Evgeny Pavlov 
---
 libavcodec/amfenc.c  | 37 +
 libavcodec/amfenc.h  |  3 +++
 libavcodec/amfenc_h264.c | 24 
 libavcodec/amfenc_hevc.c | 26 +-
 4 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index 061859f85c..0bd15dd812 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -60,6 +60,7 @@ const enum AVPixelFormat ff_amf_pix_fmts[] = {
 #if CONFIG_DXVA2
 AV_PIX_FMT_DXVA2_VLD,
 #endif
+AV_PIX_FMT_P010,
 AV_PIX_FMT_NONE
 };
 
@@ -72,6 +73,7 @@ static const FormatMap format_map[] =
 {
 { AV_PIX_FMT_NONE,   AMF_SURFACE_UNKNOWN },
 { AV_PIX_FMT_NV12,   AMF_SURFACE_NV12 },
+{ AV_PIX_FMT_P010,   AMF_SURFACE_P010 },
 { AV_PIX_FMT_BGR0,   AMF_SURFACE_BGRA },
 { AV_PIX_FMT_RGB0,   AMF_SURFACE_RGBA },
 { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
@@ -785,6 +787,41 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt)
 return ret;
 }
 
+int ff_amf_get_color_profile(AVCodecContext *avctx)
+{
+amf_int64 color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_UNKNOWN;
+if (avctx->color_range == AVCOL_RANGE_JPEG) {
+/// Color Space for Full (JPEG) Range
+switch (avctx->colorspace) {
+case AVCOL_SPC_SMPTE170M:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_601;
+break;
+case AVCOL_SPC_BT709:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_709;
+break;
+case AVCOL_SPC_BT2020_NCL:
+case AVCOL_SPC_BT2020_CL:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_FULL_2020;
+break;
+}
+} else {
+/// Color Space for Limited (MPEG) range
+switch (avctx->colorspace) {
+case AVCOL_SPC_SMPTE170M:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_601;
+break;
+case AVCOL_SPC_BT709:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_709;
+break;
+case AVCOL_SPC_BT2020_NCL:
+case AVCOL_SPC_BT2020_CL:
+color_profile = AMF_VIDEO_CONVERTER_COLOR_PROFILE_2020;
+break;
+}
+}
+return color_profile;
+}
+
 const AVCodecHWConfigInternal *const ff_amfenc_hw_configs[] = {
 #if CONFIG_D3D11VA
 HW_CONFIG_ENCODER_FRAMES(D3D11, D3D11VA),
diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h
index 2dbd378ef8..62736ef579 100644
--- a/libavcodec/amfenc.h
+++ b/libavcodec/amfenc.h
@@ -21,6 +21,7 @@
 
 #include 
 
+#include 
 #include 
 #include 
 #include 
@@ -170,6 +171,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket 
*avpkt);
 */
 extern const enum AVPixelFormat ff_amf_pix_fmts[];
 
+int ff_amf_get_color_profile(AVCodecContext *avctx);
+
 /**
 * Error handling helper
 */
diff --git a/libavcodec/amfenc_h264.c b/libavcodec/amfenc_h264.c
index bd544d12df..f785e091c9 100644
--- a/libavcodec/amfenc_h264.c
+++ b/libavcodec/amfenc_h264.c
@@ -199,6 +199,8 @@ static av_cold int amf_encode_init_h264(AVCodecContext 
*avctx)
 AMFRate  framerate;
 AMFSize  framesize = 
AMFConstructSize(avctx->width, avctx->height);
 int  deblocking_filter = (avctx->flags & 
AV_CODEC_FLAG_LOOP_FILTER) ? 1 : 0;
+amf_int64color_profile;
+enum AVPixelFormat pix_fmt;
 
 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
 framerate = AMFConstructRate(avctx->framerate.num, 
avctx->framerate.den);
@@ -262,10 +264,24 @@ FF_ENABLE_DEPRECATION_WARNINGS
 AMF_ASSIGN_PROPERTY_RATIO(res, ctx->encoder, 
AMF_VIDEO_ENCODER_ASPECT_RATIO, ratio);
 }
 
-/// Color Range (Partial/TV/MPEG or Full/PC/JPEG)
- 

[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 

[FFmpeg-devel] [PATCH 1/9] libavutil: add hwcontext_amf.

2024-02-13 Thread Dmitrii Ovchinnikov
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/Makefile b/libavutil/Makefile
index e7709b97d0..785af8e926 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -45,6 +45,7 @@ HEADERS = adler32.h   
  \
   hwcontext_d3d12va.h   \
   hwcontext_drm.h   \
   hwcontext_dxva2.h \
+  hwcontext_amf.h   \
   hwcontext_qsv.h   \
   hwcontext_mediacodec.h\
   hwcontext_opencl.h\
@@ -195,6 +196,7 @@ OBJS-$(CONFIG_CUDA) += hwcontext_cuda.o
 OBJS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.o
 OBJS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.o
 OBJS-$(CONFIG_DXVA2)+= hwcontext_dxva2.o
+OBJS-$(CONFIG_AMF)  += hwcontext_amf.o
 OBJS-$(CONFIG_LIBDRM)   += hwcontext_drm.o
 OBJS-$(CONFIG_MACOS_KPERF)  += macos_kperf.o
 OBJS-$(CONFIG_MEDIACODEC)   += hwcontext_mediacodec.o
@@ -219,6 +221,7 @@ SKIPHEADERS-$(CONFIG_CUDA) += 
hwcontext_cuda_internal.h \
 SKIPHEADERS-$(CONFIG_D3D11VA)  += hwcontext_d3d11va.h
 SKIPHEADERS-$(CONFIG_D3D12VA)  += hwcontext_d3d12va.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= hwcontext_dxva2.h
+SKIPHEADERS-$(CONFIG_AMF)  += hwcontext_amf.h
 SKIPHEADERS-$(CONFIG_QSV)  += hwcontext_qsv.h
 SKIPHEADERS-$(CONFIG_OPENCL)   += hwcontext_opencl.h
 SKIPHEADERS-$(CONFIG_VAAPI)+= hwcontext_vaapi.h
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index e23bad230f..8c53fc1862 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -65,6 +65,9 @@ static const HWContextType * const hw_table[] = {
 #endif
 #if CONFIG_VULKAN
 _hwcontext_type_vulkan,
+#endif
+#if CONFIG_AMF
+_hwcontext_type_amf,
 #endif
 NULL,
 };
@@ -82,6 +85,7 @@ static const char *const hw_type_names[] = {
 [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
 [AV_HWDEVICE_TYPE_MEDIACODEC] = "mediacodec",
 [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
+[AV_HWDEVICE_TYPE_AMF] = "amf",
 };
 
 enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 2b33721a97..53292ea67f 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -38,6 +38,7 @@ enum AVHWDeviceType {
 AV_HWDEVICE_TYPE_MEDIACODEC,
 AV_HWDEVICE_TYPE_VULKAN,
 AV_HWDEVICE_TYPE_D3D12VA,
+AV_HWDEVICE_TYPE_AMF,
 };
 
 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
diff --git a/libavutil/hwcontext_amf.c b/libavutil/hwcontext_amf.c
new file mode 100644
index 00..6f43780dc5
--- /dev/null
+++ b/libavutil/hwcontext_amf.c
@@ -0,0 +1,580 @@
+/*
+ * 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 "buffer.h"
+#include "common.h"
+#include "hwcontext.h"
+#include "hwcontext_amf.h"
+#include "hwcontext_internal.h"
+#if CONFIG_VULKAN
+#include "hwcontext_vulkan.h"
+#endif

Re: [FFmpeg-devel] [PATCH] avcodec/hevcdsp: Offset ff_hevc_.pel_filters to simplify addressing

2024-02-13 Thread James Almer

On 2/12/2024 11:54 PM, Nuo Mi wrote:

On Sun, Feb 11, 2024 at 4:21 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:


Besides simplifying address computations (it saves 432B of .text
in hevcdsp.o alone here) it also fixes undefined behaviour that
occurs if mx or my are 0 (happens when the filters are unused)
because they lead to an array index of -1 in the old code.
This happens in the checkasm-hevc_pel FATE-test.

Signed-off-by: Andreas Rheinhardt 

Thank you, Andreas,


Hi all,
If there are no objections, I'll merge it tomorrow.


Just pushed it. Thanks Andreas for fixing this.
___
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 7/7] avcodec/mediacodec_wrapper: remove unnecessary NULL checks before calling Delete{Global, Local}Ref()

2024-02-13 Thread Matthieu Bouron
Delete{Global,Local}Ref already handle NULL.
---
 libavcodec/mediacodec_wrapper.c | 189 
 1 file changed, 47 insertions(+), 142 deletions(-)

diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index 536b5b8e81..19d63e2ba0 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -549,10 +549,8 @@ char *ff_AMediaCodecList_getCodecNameByType(const char 
*mime, int profile, int e
 goto done;
 }
 
-if (codec_name) {
-(*env)->DeleteLocalRef(env, codec_name);
-codec_name = NULL;
-}
+(*env)->DeleteLocalRef(env, codec_name);
+codec_name = NULL;
 
 /* Skip software decoders */
 if (
@@ -616,10 +614,8 @@ char *ff_AMediaCodecList_getCodecNameByType(const char 
*mime, int profile, int e
 
 found_codec = profile == supported_profile;
 
-if (profile_level) {
-(*env)->DeleteLocalRef(env, profile_level);
-profile_level = NULL;
-}
+(*env)->DeleteLocalRef(env, profile_level);
+profile_level = NULL;
 
 if (found_codec) {
 break;
@@ -627,20 +623,14 @@ char *ff_AMediaCodecList_getCodecNameByType(const char 
*mime, int profile, int e
 }
 
 done_with_type:
-if (profile_levels) {
-(*env)->DeleteLocalRef(env, profile_levels);
-profile_levels = NULL;
-}
+(*env)->DeleteLocalRef(env, profile_levels);
+profile_levels = NULL;
 
-if (capabilities) {
-(*env)->DeleteLocalRef(env, capabilities);
-capabilities = NULL;
-}
+(*env)->DeleteLocalRef(env, capabilities);
+capabilities = NULL;
 
-if (type) {
-(*env)->DeleteLocalRef(env, type);
-type = NULL;
-}
+(*env)->DeleteLocalRef(env, type);
+type = NULL;
 
 av_freep(_type);
 
@@ -650,15 +640,11 @@ done_with_type:
 }
 
 done_with_info:
-if (info) {
-(*env)->DeleteLocalRef(env, info);
-info = NULL;
-}
+(*env)->DeleteLocalRef(env, info);
+info = NULL;
 
-if (types) {
-(*env)->DeleteLocalRef(env, types);
-types = NULL;
-}
+(*env)->DeleteLocalRef(env, types);
+types = NULL;
 
 if (found_codec) {
 break;
@@ -668,33 +654,13 @@ done_with_info:
 }
 
 done:
-if (codec_name) {
-(*env)->DeleteLocalRef(env, codec_name);
-}
-
-if (info) {
-(*env)->DeleteLocalRef(env, info);
-}
-
-if (type) {
-(*env)->DeleteLocalRef(env, type);
-}
-
-if (types) {
-(*env)->DeleteLocalRef(env, types);
-}
-
-if (capabilities) {
-(*env)->DeleteLocalRef(env, capabilities);
-}
-
-if (profile_level) {
-(*env)->DeleteLocalRef(env, profile_level);
-}
-
-if (profile_levels) {
-(*env)->DeleteLocalRef(env, profile_levels);
-}
+(*env)->DeleteLocalRef(env, codec_name);
+(*env)->DeleteLocalRef(env, info);
+(*env)->DeleteLocalRef(env, type);
+(*env)->DeleteLocalRef(env, types);
+(*env)->DeleteLocalRef(env, capabilities);
+(*env)->DeleteLocalRef(env, profile_level);
+(*env)->DeleteLocalRef(env, profile_levels);
 
 av_freep(_type);
 
@@ -741,9 +707,7 @@ static FFAMediaFormat *mediaformat_jni_new(void)
 }
 
 fail:
-if (object) {
-(*env)->DeleteLocalRef(env, object);
-}
+(*env)->DeleteLocalRef(env, object);
 
 if (!format->object) {
 avpriv_jni_reset_jfields(env, >jfields, 
jni_amediaformat_mapping, 1, format);
@@ -828,9 +792,7 @@ static char* mediaformat_jni_toString(FFAMediaFormat* ctx)
 
 ret = avpriv_jni_jstring_to_utf_chars(env, description, format);
 fail:
-if (description) {
-(*env)->DeleteLocalRef(env, description);
-}
+(*env)->DeleteLocalRef(env, description);
 
 return ret;
 }
@@ -867,9 +829,7 @@ static int mediaformat_jni_getInt32(FFAMediaFormat* ctx, 
const char *name, int32
 
 ret = 1;
 fail:
-if (key) {
-(*env)->DeleteLocalRef(env, key);
-}
+(*env)->DeleteLocalRef(env, key);
 
 return ret;
 }
@@ -906,9 +866,7 @@ static int mediaformat_jni_getInt64(FFAMediaFormat* ctx, 
const char *name, int64
 
 ret = 1;
 fail:
-if (key) {
-(*env)->DeleteLocalRef(env, key);
-}
+(*env)->DeleteLocalRef(env, key);
 
 return ret;
 }
@@ -945,9 +903,7 @@ static int mediaformat_jni_getFloat(FFAMediaFormat* ctx, 
const char *name, float
 
 ret = 1;
 fail:
-if (key) {
-(*env)->DeleteLocalRef(env, key);
-}
+(*env)->DeleteLocalRef(env, key);
 
 return ret;
 }
@@ -999,13 +955,8 @@ static int mediaformat_jni_getBuffer(FFAMediaFormat* ctx, 

[FFmpeg-devel] [PATCH 5/7] avutil/jni: remove unnecessary NULL checks before calling DeleteLocalRef()

2024-02-13 Thread Matthieu Bouron
Delete{Global,Local}Ref() already handle NULL.
---
 libavutil/jniutils.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/libavutil/jniutils.c b/libavutil/jniutils.c
index 89623af3f8..beedf24c0d 100644
--- a/libavutil/jniutils.c
+++ b/libavutil/jniutils.c
@@ -236,17 +236,9 @@ done:
 av_free(name);
 av_free(message);
 
-if (class_class) {
-(*env)->DeleteLocalRef(env, class_class);
-}
-
-if (exception_class) {
-(*env)->DeleteLocalRef(env, exception_class);
-}
-
-if (string) {
-(*env)->DeleteLocalRef(env, string);
-}
+(*env)->DeleteLocalRef(env, class_class);
+(*env)->DeleteLocalRef(env, exception_class);
+(*env)->DeleteLocalRef(env, string);
 
 return ret;
 }
-- 
2.43.1

___
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 6/7] avcodec/mediacodec_wrapper: use an OFFSET() macro where relevant

2024-02-13 Thread Matthieu Bouron
Reduces a bit the horizontal spacing.
---
 libavcodec/mediacodec_wrapper.c | 138 +---
 1 file changed, 72 insertions(+), 66 deletions(-)

diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c
index bc3eb0a80d..536b5b8e81 100644
--- a/libavcodec/mediacodec_wrapper.c
+++ b/libavcodec/mediacodec_wrapper.c
@@ -60,31 +60,33 @@ struct JNIAMediaCodecListFields {
 jfieldID level_id;
 };
 
+#define OFFSET(x) offsetof(struct JNIAMediaCodecListFields, x)
 static const struct FFJniField jni_amediacodeclist_mapping[] = {
-{ "android/media/MediaCodecList", NULL, NULL, FF_JNI_CLASS, 
offsetof(struct JNIAMediaCodecListFields, mediacodec_list_class), 1 },
-{ "android/media/MediaCodecList", "", "(I)V", FF_JNI_METHOD, 
offsetof(struct JNIAMediaCodecListFields, init_id), 0 },
-{ "android/media/MediaCodecList", "findDecoderForFormat", 
"(Landroid/media/MediaFormat;)Ljava/lang/String;", FF_JNI_METHOD, 
offsetof(struct JNIAMediaCodecListFields, find_decoder_for_format_id), 0 },
+{ "android/media/MediaCodecList", NULL, NULL, FF_JNI_CLASS, 
OFFSET(mediacodec_list_class), 1 },
+{ "android/media/MediaCodecList", "", "(I)V", FF_JNI_METHOD, 
OFFSET(init_id), 0 },
+{ "android/media/MediaCodecList", "findDecoderForFormat", 
"(Landroid/media/MediaFormat;)Ljava/lang/String;", FF_JNI_METHOD, 
OFFSET(find_decoder_for_format_id), 0 },
 
-{ "android/media/MediaCodecList", "getCodecCount", "()I", 
FF_JNI_STATIC_METHOD, offsetof(struct JNIAMediaCodecListFields, 
get_codec_count_id), 1 },
-{ "android/media/MediaCodecList", "getCodecInfoAt", 
"(I)Landroid/media/MediaCodecInfo;", FF_JNI_STATIC_METHOD, offsetof(struct 
JNIAMediaCodecListFields, get_codec_info_at_id), 1 },
+{ "android/media/MediaCodecList", "getCodecCount", "()I", 
FF_JNI_STATIC_METHOD, OFFSET(get_codec_count_id), 1 },
+{ "android/media/MediaCodecList", "getCodecInfoAt", 
"(I)Landroid/media/MediaCodecInfo;", FF_JNI_STATIC_METHOD, 
OFFSET(get_codec_info_at_id), 1 },
 
-{ "android/media/MediaCodecInfo", NULL, NULL, FF_JNI_CLASS, 
offsetof(struct JNIAMediaCodecListFields, mediacodec_info_class), 1 },
-{ "android/media/MediaCodecInfo", "getName", "()Ljava/lang/String;", 
FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, get_name_id), 1 },
-{ "android/media/MediaCodecInfo", "getCapabilitiesForType", 
"(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;", 
FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, 
get_codec_capabilities_id), 1 },
-{ "android/media/MediaCodecInfo", "getSupportedTypes", 
"()[Ljava/lang/String;", FF_JNI_METHOD, offsetof(struct 
JNIAMediaCodecListFields, get_supported_types_id), 1 },
-{ "android/media/MediaCodecInfo", "isEncoder", "()Z", FF_JNI_METHOD, 
offsetof(struct JNIAMediaCodecListFields, is_encoder_id), 1 },
-{ "android/media/MediaCodecInfo", "isSoftwareOnly", "()Z", 
FF_JNI_METHOD, offsetof(struct JNIAMediaCodecListFields, is_software_only_id), 
0 },
+{ "android/media/MediaCodecInfo", NULL, NULL, FF_JNI_CLASS, 
OFFSET(mediacodec_info_class), 1 },
+{ "android/media/MediaCodecInfo", "getName", "()Ljava/lang/String;", 
FF_JNI_METHOD, OFFSET(get_name_id), 1 },
+{ "android/media/MediaCodecInfo", "getCapabilitiesForType", 
"(Ljava/lang/String;)Landroid/media/MediaCodecInfo$CodecCapabilities;", 
FF_JNI_METHOD, OFFSET(get_codec_capabilities_id), 1 },
+{ "android/media/MediaCodecInfo", "getSupportedTypes", 
"()[Ljava/lang/String;", FF_JNI_METHOD, OFFSET(get_supported_types_id), 1 },
+{ "android/media/MediaCodecInfo", "isEncoder", "()Z", FF_JNI_METHOD, 
OFFSET(is_encoder_id), 1 },
+{ "android/media/MediaCodecInfo", "isSoftwareOnly", "()Z", 
FF_JNI_METHOD, OFFSET(is_software_only_id), 0 },
 
-{ "android/media/MediaCodecInfo$CodecCapabilities", NULL, NULL, 
FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, 
codec_capabilities_class), 1 },
-{ "android/media/MediaCodecInfo$CodecCapabilities", "colorFormats", 
"[I", FF_JNI_FIELD, offsetof(struct JNIAMediaCodecListFields, 
color_formats_id), 1 },
-{ "android/media/MediaCodecInfo$CodecCapabilities", "profileLevels", 
"[Landroid/media/MediaCodecInfo$CodecProfileLevel;", FF_JNI_FIELD, 
offsetof(struct JNIAMediaCodecListFields, profile_levels_id), 1 },
+{ "android/media/MediaCodecInfo$CodecCapabilities", NULL, NULL, 
FF_JNI_CLASS, OFFSET(codec_capabilities_class), 1 },
+{ "android/media/MediaCodecInfo$CodecCapabilities", "colorFormats", 
"[I", FF_JNI_FIELD, OFFSET(color_formats_id), 1 },
+{ "android/media/MediaCodecInfo$CodecCapabilities", "profileLevels", 
"[Landroid/media/MediaCodecInfo$CodecProfileLevel;", FF_JNI_FIELD, 
OFFSET(profile_levels_id), 1 },
 
-{ "android/media/MediaCodecInfo$CodecProfileLevel", NULL, NULL, 
FF_JNI_CLASS, offsetof(struct JNIAMediaCodecListFields, 
codec_profile_level_class), 1 },
-{ 

[FFmpeg-devel] [PATCH 4/7] avutil/jni: use size_t to store structure offsets

2024-02-13 Thread Matthieu Bouron
---
 libavutil/jniutils.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/jniutils.h b/libavutil/jniutils.h
index 2be401c974..01f3acb88d 100644
--- a/libavutil/jniutils.h
+++ b/libavutil/jniutils.h
@@ -24,6 +24,7 @@
 #define AVUTIL_JNIUTILS_H
 
 #include 
+#include 
 
 /*
  * Attach permanently a JNI environment to the current thread and retrieve it.
@@ -102,7 +103,7 @@ struct FFJniField {
 const char *method;
 const char *signature;
 enum FFJniFieldType type;
-int offset;
+size_t offset;
 int mandatory;
 };
 
-- 
2.43.1

___
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 3/7] avformat: add Android content resolver protocol support

2024-02-13 Thread Matthieu Bouron
Handles Android content-uri starting with content://.
---
 configure   |   2 +
 doc/APIchanges  |   3 +
 libavformat/Makefile|   1 +
 libavformat/file.c  | 157 
 libavformat/protocols.c |   1 +
 5 files changed, 164 insertions(+)

diff --git a/configure b/configure
index f72533b7d2..a3593dc200 100755
--- a/configure
+++ b/configure
@@ -3651,6 +3651,8 @@ xcbgrab_indev_suggest="libxcb_shm libxcb_shape 
libxcb_xfixes"
 xv_outdev_deps="xlib_xv xlib_x11 xlib_xext"
 
 # protocols
+android_content_protocol_deps="jni"
+android_content_protocol_select="file_protocol"
 async_protocol_deps="threads"
 bluray_protocol_deps="libbluray"
 ffrtmpcrypt_protocol_conflict="librtmp_protocol"
diff --git a/doc/APIchanges b/doc/APIchanges
index 45611ea7ea..7f6631b3d3 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2024-02-xx - xx - lavu 58.40.100 - jni.h
+  Add av_jni_set_android_app_ctx() and av_jni_get_android_app_ctx().
+
 2024-02-xx - xx - lavu 58.39.100 - jni.h
   Add av_jni_set_jvm() and av_jni_get_jvm().
 
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 05b9b8a115..788d4e4135 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -655,6 +655,7 @@ OBJS-$(CONFIG_LIBOPENMPT_DEMUXER)+= libopenmpt.o
 OBJS-$(CONFIG_VAPOURSYNTH_DEMUXER)   += vapoursynth.o
 
 # protocols I/O
+OBJS-$(CONFIG_ANDROID_CONTENT_PROTOCOL)  += file.o
 OBJS-$(CONFIG_ASYNC_PROTOCOL)+= async.o
 OBJS-$(CONFIG_APPLEHTTP_PROTOCOL)+= hlsproto.o
 OBJS-$(CONFIG_BLURAY_PROTOCOL)   += bluray.o
diff --git a/libavformat/file.c b/libavformat/file.c
index 64df7ff6fb..c7c7a5073f 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -40,6 +40,12 @@
 #include 
 #include "os_support.h"
 #include "url.h"
+#if CONFIG_ANDROID_CONTENT_PROTOCOL
+#include 
+#include "libavutil/jni.h"
+#include "libavutil/jniutils.h"
+#endif
+
 
 /* Some systems may not have S_ISFIFO */
 #ifndef S_ISFIFO
@@ -101,6 +107,21 @@ typedef struct FileContext {
 int64_t initial_pos;
 } FileContext;
 
+
+#if CONFIG_ANDROID_CONTENT_PROTOCOL
+static const AVOption android_content_options[] = {
+{ "blocksize", "set I/O operation maximum block size", 
offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+{ NULL }
+};
+
+static const AVClass android_content_class = {
+.class_name = "android_content",
+.item_name  = av_default_item_name,
+.option = android_content_options,
+.version= LIBAVUTIL_VERSION_INT,
+};
+#endif
+
 static const AVOption file_options[] = {
 { "truncate", "truncate existing files on write", offsetof(FileContext, 
trunc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
 { "blocksize", "set I/O operation maximum block size", 
offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, 
INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
@@ -524,3 +545,139 @@ const URLProtocol ff_fd_protocol = {
 };
 
 #endif /* CONFIG_FD_PROTOCOL */
+
+#if CONFIG_ANDROID_CONTENT_PROTOCOL
+
+struct JFields {
+jclass uri_class;
+jmethodID parse_id;
+
+jclass context_class;
+jmethodID get_content_resolver_id;
+
+jclass content_resolver_class;
+jmethodID open_file_descriptor_id;
+
+jclass parcel_file_descriptor_class;
+jmethodID detach_fd_id;
+};
+
+#define OFFSET(x) offsetof(struct JFields, x)
+static const struct FFJniField jfields_mapping[] = {
+{ "android/net/Uri", NULL, NULL, FF_JNI_CLASS, OFFSET(uri_class), 1 },
+{ "android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;", 
FF_JNI_STATIC_METHOD, OFFSET(parse_id), 1 },
+
+{ "android/content/Context", NULL, NULL, FF_JNI_CLASS, 
OFFSET(context_class), 1 },
+{ "android/content/Context", "getContentResolver", 
"()Landroid/content/ContentResolver;", FF_JNI_METHOD, 
OFFSET(get_content_resolver_id), 1 },
+
+{ "android/content/ContentResolver", NULL, NULL, FF_JNI_CLASS, 
OFFSET(content_resolver_class), 1 },
+{ "android/content/ContentResolver", "openFileDescriptor", 
"(Landroid/net/Uri;Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;", 
FF_JNI_METHOD, OFFSET(open_file_descriptor_id), 1 },
+
+{ "android/os/ParcelFileDescriptor", NULL, NULL, FF_JNI_CLASS, 
OFFSET(parcel_file_descriptor_class), 1 },
+{ "android/os/ParcelFileDescriptor", "detachFd", "()I", FF_JNI_METHOD, 
OFFSET(detach_fd_id), 1 },
+
+{ NULL }
+};
+#undef OFFSET
+
+static int android_content_open(URLContext *h, const char *filename, int flags)
+{
+FileContext *c = h->priv_data;
+int fd, ret;
+const char *mode_str = "r";
+
+JNIEnv *env;
+struct JFields jfields = { 0 };
+jobject application_context = NULL;
+jobject url = NULL;
+jobject mode = NULL;
+jobject uri = NULL;
+jobject 

[FFmpeg-devel] [PATCH 2/7] avutil: add av_jni_{get, set}_android_app_ctx helper

2024-02-13 Thread Matthieu Bouron
This will allow users to pass the Android ApplicationContext which is mandatory
to retrieve the ContentResolver responsible to resolve/open Android content-uri.
---
 libavutil/jni.c | 28 
 libavutil/jni.h | 17 +
 2 files changed, 45 insertions(+)

diff --git a/libavutil/jni.c b/libavutil/jni.c
index 541747cb20..d6f96717b0 100644
--- a/libavutil/jni.c
+++ b/libavutil/jni.c
@@ -34,6 +34,7 @@
 #include "libavutil/jni.h"
 
 static void *java_vm;
+static void *android_app_ctx;
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
 int av_jni_set_jvm(void *vm, void *log_ctx)
@@ -63,6 +64,24 @@ void *av_jni_get_jvm(void *log_ctx)
 return vm;
 }
 
+void av_jni_set_android_app_ctx(void *app_ctx)
+{
+pthread_mutex_lock();
+android_app_ctx = app_ctx;
+pthread_mutex_unlock();
+}
+
+void *av_jni_get_android_app_ctx(void)
+{
+void *ctx;
+
+pthread_mutex_lock();
+ctx = android_app_ctx;
+pthread_mutex_unlock();
+
+return ctx;
+}
+
 #else
 
 int av_jni_set_java_vm(void *vm, void *log_ctx)
@@ -75,4 +94,13 @@ void *av_jni_get_java_vm(void *log_ctx)
 return NULL;
 }
 
+void av_jni_set_android_app_ctx(void *app_ctx)
+{
+}
+
+void *av_jni_get_android_app_ctx(void)
+{
+return NULL;
+}
+
 #endif
diff --git a/libavutil/jni.h b/libavutil/jni.h
index 700960dbb8..630f4074a1 100644
--- a/libavutil/jni.h
+++ b/libavutil/jni.h
@@ -43,4 +43,21 @@ int av_jni_set_jvm(void *vm, void *log_ctx);
  */
 void *av_jni_get_jvm(void *log_ctx);
 
+/*
+ * Set the Android application context which will be used to retrieve the 
Android
+ * content resolver to resolve content uris.
+ *
+ * @param app_ctx global JNI reference to the Android application context
+ */
+void av_jni_set_android_app_ctx(void *app_ctx);
+
+/*
+ * Get the Android application context that has been set with
+ * av_jni_set_android_app_ctx.
+ *
+ * @return a pointer the the Android application context
+ */
+void *av_jni_get_android_app_ctx(void);
+
+
 #endif /* AVUTIL_JNI_H */
-- 
2.43.1

___
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 1/7] avcodec: move ffjni to avutil/jniutils

2024-02-13 Thread Matthieu Bouron
This will allow to use the jni utils in libavformat. This will be mostly useful
to add Android content-uri support.

This deprecates avcodec/jni.h functions in favor of the ones from avutil/jni.h.
---
 doc/APIchanges |   6 +
 libavcodec/Makefile|   3 +-
 libavcodec/jni.c   |  48 +
 libavcodec/jni.h   |   8 +
 libavcodec/mediacodec.c|   6 +-
 libavcodec/mediacodec_surface.c|   6 +-
 libavcodec/mediacodec_wrapper.c| 200 ++---
 libavcodec/mediacodecdec.c |   3 +-
 libavutil/Makefile |   4 +
 libavutil/jni.c|  78 
 libavutil/jni.h|  46 +
 libavcodec/ffjni.c => libavutil/jniutils.c |  36 ++--
 libavcodec/ffjni.h => libavutil/jniutils.h |  26 ++-
 13 files changed, 283 insertions(+), 187 deletions(-)
 create mode 100644 libavutil/jni.c
 create mode 100644 libavutil/jni.h
 rename libavcodec/ffjni.c => libavutil/jniutils.c (88%)
 rename libavcodec/ffjni.h => libavutil/jniutils.h (84%)

diff --git a/doc/APIchanges b/doc/APIchanges
index 221fea30c2..45611ea7ea 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,12 @@ The last version increases of all libraries were on 2023-02-09
 
 API changes, most recent first:
 
+2024-02-xx - xx - lavu 58.39.100 - jni.h
+  Add av_jni_set_jvm() and av_jni_get_jvm().
+
+2024-02-xx - xx - lavc 60.40.100 - jni.h
+  Deprecate av_jni_set_java_vm() and av_jni_get_java_vm().
+
 2024-02-xx - xx - lavu 58.38.100 - channel_layout.h
   Add av_channel_layout_retype().
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 470d7cb9b1..f8584d8dfd 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -117,7 +117,7 @@ OBJS-$(CONFIG_IIRFILTER)   += iirfilter.o
 OBJS-$(CONFIG_INFLATE_WRAPPER) += zlib_wrapper.o
 OBJS-$(CONFIG_INTRAX8) += intrax8.o intrax8dsp.o msmpeg4data.o
 OBJS-$(CONFIG_IVIDSP)  += ivi_dsp.o
-OBJS-$(CONFIG_JNI) += ffjni.o jni.o
+OBJS-$(CONFIG_JNI) += jni.o
 OBJS-$(CONFIG_JPEGTABLES)  += jpegtables.o
 OBJS-$(CONFIG_LCMS2)   += fflcms2.o
 OBJS-$(CONFIG_LLAUDDSP)+= lossless_audiodsp.o
@@ -1269,7 +1269,6 @@ SKIPHEADERS-$(CONFIG_AMF)  += amfenc.h
 SKIPHEADERS-$(CONFIG_D3D11VA)  += d3d11va.h dxva2_internal.h
 SKIPHEADERS-$(CONFIG_D3D12VA)  += d3d12va_decode.h
 SKIPHEADERS-$(CONFIG_DXVA2)+= dxva2.h dxva2_internal.h
-SKIPHEADERS-$(CONFIG_JNI)  += ffjni.h
 SKIPHEADERS-$(CONFIG_LCMS2)+= fflcms2.h
 SKIPHEADERS-$(CONFIG_LIBAOM)   += libaom.h
 SKIPHEADERS-$(CONFIG_LIBJXL)   += libjxl.h
diff --git a/libavcodec/jni.c b/libavcodec/jni.c
index ae6490de9d..a98c27d73a 100644
--- a/libavcodec/jni.c
+++ b/libavcodec/jni.c
@@ -20,60 +20,18 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "config.h"
-
 #include 
 
 #include "libavutil/error.h"
+#include "libavutil/jni.h"
 #include "jni.h"
 
-#if CONFIG_JNI
-#include 
-#include 
-
-#include "libavutil/log.h"
-#include "ffjni.h"
-
-static void *java_vm;
-static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
-
-int av_jni_set_java_vm(void *vm, void *log_ctx)
-{
-int ret = 0;
-
-pthread_mutex_lock();
-if (java_vm == NULL) {
-java_vm = vm;
-} else if (java_vm != vm) {
-ret = AVERROR(EINVAL);
-av_log(log_ctx, AV_LOG_ERROR, "A Java virtual machine has already been 
set");
-}
-pthread_mutex_unlock();
-
-return ret;
-}
-
-void *av_jni_get_java_vm(void *log_ctx)
-{
-void *vm;
-
-pthread_mutex_lock();
-vm = java_vm;
-pthread_mutex_unlock();
-
-return vm;
-}
-
-#else
-
 int av_jni_set_java_vm(void *vm, void *log_ctx)
 {
-return AVERROR(ENOSYS);
+return av_jni_set_jvm(vm, log_ctx);
 }
 
 void *av_jni_get_java_vm(void *log_ctx)
 {
-return NULL;
+return av_jni_get_jvm(log_ctx);
 }
-
-#endif
diff --git a/libavcodec/jni.h b/libavcodec/jni.h
index dd99e92611..49ddab4120 100644
--- a/libavcodec/jni.h
+++ b/libavcodec/jni.h
@@ -23,6 +23,8 @@
 #ifndef AVCODEC_JNI_H
 #define AVCODEC_JNI_H
 
+#include 
+
 /*
  * Manually set a Java virtual machine which will be used to retrieve the JNI
  * environment. Once a Java VM is set it cannot be changed afterwards, meaning
@@ -32,7 +34,10 @@
  * @param vm Java virtual machine
  * @param log_ctx context used for logging, can be NULL
  * @return 0 on success, < 0 otherwise
+ *
+ * @deprecated use av_jni_set_jvm from libavutil/jni.h
  */
+attribute_deprecated
 int av_jni_set_java_vm(void *vm, void *log_ctx);
 
 /*
@@ -40,7 +45,10 @@ int av_jni_set_java_vm(void *vm, void *log_ctx);
  *
  * @param vm Java virtual machine
  * @return a pointer to the Java virtual machine
+ 

[FFmpeg-devel] Add protocol for Android content providers

2024-02-13 Thread Matthieu Bouron
Hi,

On Android, content providers are used for accessing files through shared
mechanisms. One typical case would be an app willing to open a video from
Google Photos, gallery apps, TikTok, Instagram or some other providers.
A content URI looks something like "content://authority/path/id", see:
https://developer.android.com/reference/android/content/ContentUris
https://developer.android.com/guide/topics/providers/content-provider-basics

It can currently be somehow managed through clumsy means such as using a "fd:"
filename and crafting a special AVOption, which also has the drawback of
requiring the third party to carry around opened file descriptors (with the
multiple opened file limitations implied). Custom AVIOContexts are also an
option. Both options will have to deal with the JNI though and end users will
have to re-implement the same exact thing.

This patchset addresses this by adding a content provider protocol, which has
an API fairly similar to fopen. Android 11 appears to provide something
transparent within fopen(), but FFmpeg doesn't use it in the file protocol, and
Android < 11 are still widely used.

The first part move the JNI infrastructure from avcodec to avutil (it remains
internally shared, there is little user implication), and then the URLProtocol
is added, along with a few cleanups.

Regards,

-- 
Matthieu

___
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".


Re: [FFmpeg-devel] [PATCH v2] libavfi/dnn: add LibTorch as one of DNN backend

2024-02-13 Thread Jean-Baptiste Kempf
Hello,

On Fri, 2 Feb 2024, at 08:26, wenbin.chen-at-intel@ffmpeg.org wrote:
> +static void infer_completion_callback(void *args) {
> +THRequestItem *request = (THRequestItem*)args;
> +LastLevelTaskItem *lltask = request->lltask;
> +TaskItem *task = lltask->task;
> +DNNData outputs = { 0 };
> +THInferRequest *infer_request = request->infer_request;
> +THModel *th_model = (THModel *)task->model;
> +torch::Tensor *output = infer_request->output;
> +
> +c10::IntArrayRef sizes = output->sizes();
> +assert(sizes.size == 5);

Why 5?

> +outputs.order = DCO_RGB;
> +outputs.layout = DL_NCHW;
> +outputs.dims[2] = sizes.at(3);
> +outputs.dims[3] = sizes.at(4);
> +outputs.dt = DNN_FLOAT;
> +outputs.dims[1] = 3;

Why 3?


-- 
Jean-Baptiste Kempf -  President
+33 672 704 734
___
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 3/3] avcodec/pngenc: write eXIf chunks

2024-02-13 Thread Leo Izen
Write EXIF metadata exposed AV_FRAME_DATA_EXIF as an eXIf chunk
to PNG files, if present.

Signed-off-by: Leo Izen 
---
 libavcodec/pngenc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 50689cb50c..a302c879da 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -413,6 +413,10 @@ static int encode_headers(AVCodecContext *avctx, const 
AVFrame *pict)
 }
 }
 
+side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_EXIF);
+if (side_data)
+png_write_chunk(>bytestream, MKTAG('e', 'X', 'I', 'f'), 
side_data->data, FFMIN(side_data->size, INT_MAX));
+
 side_data = av_frame_get_side_data(pict, AV_FRAME_DATA_ICC_PROFILE);
 if ((ret = png_write_iccp(s, side_data)))
 return ret;
-- 
2.43.0

___
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/3] avcodec/pngdec: parse eXIf chunk

2024-02-13 Thread Leo Izen
Add support to parse eXIf chunks using the new EXIF framework.

Signed-off-by: Leo Izen 
---
 libavcodec/pngdec.c | 35 +++
 1 file changed, 35 insertions(+)

diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c
index 026da30c25..e7951d1802 100644
--- a/libavcodec/pngdec.c
+++ b/libavcodec/pngdec.c
@@ -38,6 +38,7 @@
 #include "bytestream.h"
 #include "codec_internal.h"
 #include "decode.h"
+#include "exif_internal.h"
 #include "apng.h"
 #include "png.h"
 #include "pngdsp.h"
@@ -123,6 +124,7 @@ typedef struct PNGDecContext {
 int pass_row_size; /* decompress row size of the current pass */
 int y;
 FFZStream zstream;
+AVBufferRef *exif_data;
 } PNGDecContext;
 
 /* Mask to determine which pixels are valid in a pass */
@@ -652,6 +654,26 @@ static int decode_phys_chunk(AVCodecContext *avctx, 
PNGDecContext *s,
 return 0;
 }
 
+static int decode_exif_chunk(AVCodecContext *avctx, PNGDecContext *s,
+ GetByteContext *gb)
+{
+if (!(s->hdr_state & PNG_IHDR)) {
+av_log(avctx, AV_LOG_ERROR, "eXIf before IHDR\n");
+return AVERROR_INVALIDDATA;
+}
+if (s->pic_state & PNG_IDAT) {
+av_log(avctx, AV_LOG_ERROR, "eXIf after IDAT\n");
+return AVERROR_INVALIDDATA;
+}
+av_buffer_unref(>exif_data);
+s->exif_data = av_buffer_alloc(bytestream2_get_bytes_left(gb));
+if (!s->exif_data)
+return AVERROR(ENOMEM);
+bytestream2_get_buffer(gb, s->exif_data->data, s->exif_data->size);
+
+return 0;
+}
+
 /*
  * This populates AVCodecContext fields so it must be called before
  * ff_thread_finish_setup() to avoid a race condition with respect to the
@@ -890,6 +912,12 @@ static int decode_idat_chunk(AVCodecContext *avctx, 
PNGDecContext *s,
 p->flags   |= AV_FRAME_FLAG_KEY;
 p->flags |= AV_FRAME_FLAG_INTERLACED * !!s->interlace_type;
 
+if (s->exif_data) {
+ret = ff_exif_attach(avctx, p, >exif_data);
+if (ret < 0)
+return ret;
+}
+
 if ((ret = populate_avctx_color_fields(avctx, p)) < 0)
 return ret;
 ff_thread_finish_setup(avctx);
@@ -1571,6 +1599,12 @@ static int decode_frame_common(AVCodecContext *avctx, 
PNGDecContext *s,
 s->mdvc_max_lum = bytestream2_get_be32u(_chunk);
 s->mdvc_min_lum = bytestream2_get_be32u(_chunk);
 break;
+case MKTAG('e', 'X', 'I', 'f'): {
+ret = decode_exif_chunk(avctx, s, _chunk);
+if (ret < 0)
+goto fail;
+break;
+}
 case MKTAG('I', 'E', 'N', 'D'):
 if (!(s->pic_state & PNG_ALLIMAGE))
 av_log(avctx, AV_LOG_ERROR, "IEND without all image\n");
@@ -1907,6 +1941,7 @@ static av_cold int png_dec_end(AVCodecContext *avctx)
 s->tmp_row_size = 0;
 
 av_freep(>iccp_data);
+av_buffer_unref(>exif_data);
 av_dict_free(>frame_metadata);
 ff_inflate_end(>zstream);
 
-- 
2.43.0

___
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 1/3] various: change EXIF metadata into AVFrameSideData

2024-02-13 Thread Leo Izen
This patch centralizes much of the EXIF parsing and handling code for
libavcodec, and delegates its own AVFrameSideData type to containing
the buffer that holds EXIF metadata. This patch also adds exposes the
exif parsing routing so it can be called by ffprobe, and updates the
corresponding FATE tests to read the keys from the side data instead of
from the main frame metadata.

This commit also removes an avpriv_ function in exif.h, exposing the
parsing functionality as a public API in the exported libavcodec/exif.h
header file. As such, this commit requires an ABI break and can only be
applied during a major version bump.

Signed-off-by: Leo Izen 
---
 fftools/ffprobe.c  |  27 ++-
 libavcodec/Makefile|   1 +
 libavcodec/exif.c  | 267 +++--
 libavcodec/exif.h  |  21 ++-
 libavcodec/exif_internal.h |  41 +
 libavcodec/mjpegdec.c  |  96 ++-
 libavcodec/mjpegdec.h  |   2 +-
 libavcodec/tiff.c  |  19 +-
 libavcodec/tiff.h  |   1 +
 libavcodec/webp.c  |  38 ++--
 libavformat/avidec.c   |   4 +-
 libavutil/frame.c  |   1 +
 libavutil/frame.h  |   6 +
 tests/ref/fate/exif-image-embedded |   5 +-
 tests/ref/fate/exif-image-jpg  |  91 +-
 tests/ref/fate/exif-image-webp |  91 +-
 16 files changed, 482 insertions(+), 229 deletions(-)
 create mode 100644 libavcodec/exif_internal.h

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index aa1153e709..7c3cd4a0ee 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -32,6 +32,7 @@
 #include "libavformat/avformat.h"
 #include "libavformat/version.h"
 #include "libavcodec/avcodec.h"
+#include "libavcodec/exif.h"
 #include "libavcodec/version.h"
 #include "libavutil/ambient_viewing_environment.h"
 #include "libavutil/avassert.h"
@@ -1982,19 +1983,30 @@ static void writer_register_all(void)
 memset( (ptr) + (cur_n), 0, ((new_n) - (cur_n)) * sizeof(*(ptr)) ); \
 }
 
-static inline int show_tags(WriterContext *w, AVDictionary *tags, int 
section_id)
+static inline int show_dict(WriterContext *w, const AVDictionary *tags)
 {
 const AVDictionaryEntry *tag = NULL;
 int ret = 0;
-
 if (!tags)
 return 0;
-writer_print_section_header(w, NULL, section_id);
-
 while ((tag = av_dict_iterate(tags, tag))) {
-if ((ret = print_str_validate(tag->key, tag->value)) < 0)
+ret = print_str_validate(tag->key, tag->value);
+if (ret < 0)
 break;
 }
+return ret;
+}
+
+static inline int show_tags(WriterContext *w, const AVDictionary *tags, int 
section_id)
+{
+int ret;
+
+if (!tags)
+return 0;
+writer_print_section_header(w, NULL, section_id);
+
+ret = show_dict(w, tags);
+
 writer_print_section_footer(w);
 
 return ret;
@@ -2700,6 +2712,11 @@ static void print_frame_side_data(WriterContext *w,
 print_dynamic_hdr_vivid(w, metadata);
 } else if (sd->type == AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT) {
 print_ambient_viewing_environment(w, (const 
AVAmbientViewingEnvironment *)sd->data);
+} else if (sd->type == AV_FRAME_DATA_EXIF) {
+AVDictionary *dict = NULL;
+int ret = av_exif_parse_buffer(NULL, sd->data, sd->size, , 
AV_EXIF_PARSE_TIFF_HEADER);
+if (ret >= 0)
+show_dict(w, dict);
 }
 writer_print_section_footer(w);
 }
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 470d7cb9b1..fea2f9b8b3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -16,6 +16,7 @@ HEADERS = ac3_parser.h
  \
   dirac.h   \
   dv_profile.h  \
   dxva2.h   \
+  exif.h\
   jni.h \
   mediacodec.h  \
   packet.h  \
diff --git a/libavcodec/exif.c b/libavcodec/exif.c
index 959d114d09..0b7ad1c07c 100644
--- a/libavcodec/exif.c
+++ b/libavcodec/exif.c
@@ -1,6 +1,7 @@
 /*
  * EXIF metadata parser
  * Copyright (c) 2013 Thilo Borgmann 
+ * Copyright (c) 2024 Leo Izen 
  *
  * This file is part of FFmpeg.
  *
@@ -23,9 +24,12 @@
  * @file
  * EXIF metadata parser
  * @author Thilo Borgmann 
+ * @author Leo Izen 
  */
 
-#include "exif.h"
+#include "libavutil/display.h"
+
+#include "exif_internal.h"
 #include "tiff_common.h"
 
 #define EXIF_TAG_NAME_LENGTH   32
@@ -197,6 +201,8 @@ static int exif_add_metadata(void *logctx, int count, int 
type,
 };
 }
 
+static int exif_parse_ifd_list(void 

[FFmpeg-devel] [PATCH 0/3] [RFC] EXIF overhaul

2024-02-13 Thread Leo Izen
A few notes:
- This includes an avpriv_ removal, so it won't be able to be merged
  until the ABI is bumped. Alternatively, I could add that avipriv_
  back in as a wrapper around the actual API so it's not a blocker,
  and then we can remove it when the time comes to bump the ABI.
- MakerNote inside TIFF files are not handled by this patch. I don't
  have any samples that lets me reliably special-case them based on
  manufacturer. MakerNote is, by spec, a binary blob, but in practice
  it's often a TIFF IFD, with arbitrary data before the IFD starts
  and arbitrary semantics on whether its IFD-offsets are relative to
  the start of the TIFF header or the start of the MakerNote. The lack
  of samples makes this hard to work around. See [1] for more details.
  Note that [1] links [2] but [2] is a deadlink.
- We attach the EXIF buffer as-is from mjpeg, webp, or other files that
  treat it as a blob, but we still need to parse it in order to determine
  the display matrix orientation side data. If there's a better way to
  handle this, please suggest one.
- AVFrameSideData must be flat, so we can't parse it and store an
  AVDictionary * pointer in its place, as convenient as that would be.


[1] https://exiv2.org/makernote.html
[2] http://www.exif.org/samples.html

Leo Izen (3):
  various: change EXIF metadata into AVFrameSideData
  avcodec/pngdec: parse eXIf chunk
  avcodec/pngenc: write eXIf chunks

 fftools/ffprobe.c  |  27 ++-
 libavcodec/Makefile|   1 +
 libavcodec/exif.c  | 267 +++--
 libavcodec/exif.h  |  21 ++-
 libavcodec/exif_internal.h |  41 +
 libavcodec/mjpegdec.c  |  96 ++-
 libavcodec/mjpegdec.h  |   2 +-
 libavcodec/pngdec.c|  35 
 libavcodec/pngenc.c|   4 +
 libavcodec/tiff.c  |  19 +-
 libavcodec/tiff.h  |   1 +
 libavcodec/webp.c  |  38 ++--
 libavformat/avidec.c   |   4 +-
 libavutil/frame.c  |   1 +
 libavutil/frame.h  |   6 +
 tests/ref/fate/exif-image-embedded |   5 +-
 tests/ref/fate/exif-image-jpg  |  91 +-
 tests/ref/fate/exif-image-webp |  91 +-
 18 files changed, 521 insertions(+), 229 deletions(-)
 create mode 100644 libavcodec/exif_internal.h

-- 
2.43.0

___
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".


Re: [FFmpeg-devel] [PATCH 2/5] avutil/channel_layout: add AV_CHANNEL_ORDER_NB

2024-02-13 Thread Marton Balint




On Tue, 13 Feb 2024, James Almer wrote:


On 2/12/2024 6:15 PM, Marton Balint wrote:

 Signed-off-by: Marton Balint 
 ---
   libavutil/channel_layout.h | 4 
   1 file changed, 4 insertions(+)

 diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
 index b8bff6f365..db0c005e87 100644
 --- a/libavutil/channel_layout.h
 +++ b/libavutil/channel_layout.h
 @@ -146,6 +146,10 @@ enum AVChannelOrder {
* as defined in AmbiX format $ 2.1.
*/
   AV_CHANNEL_ORDER_AMBISONIC,
 +/**
 + * Number of channel orders, not part of ABI/API
 + */
 +AV_CHANNEL_ORDER_NB
   };


Is it worth adding this to a public header just to limit a loop in a test? A 
loop that fwiw still depends on an array that needs to be updated with more 
names if you add new orders.


Several other enums also have this. So API consistency can be considered 
a more important factor.




IMO, just do FF_ARRAY_ELEMS(channel_order_names) in the test.


Then adding a new channel order would not show up as breakage in the 
test. I have no strong preference though, and can change it if you 
still want me to.


Regards,
Marton
___
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".


Re: [FFmpeg-devel] [TC] Decision on FF_INTERNAL_FIELDS in libavfilter

2024-02-13 Thread Nicolas George
Rémi Denis-Courmont (12024-02-13):
> Speaking as an elected member of another OSS project's TC, I believe
> that the experienced adult developers on the FFmpeg TC are perfectly
> capable of reading mailing archives and Trac comments as necessary. In
> fact, I think it is preferable that they stick to arguments made in
> public, rather than go out of their way to dig up private information.

So you are thinking that Anton did not summarize and polish his
arguments while submitting the question to the TC. Sure, let us believe
that.

> Or to follow your metaphor, in a trial, the arguments are made before
> the jury in public sessions. The deliberations of the jury are kept
> private to shield members from external pressure.

As a matter of principle, the defense has the last word.

> I don't expect that antagonising the TC members will do you, and any
> potential future arguments of yours, much good.

I have lost all confidence in both committees and consider the only hope
to save this project is if Fabrice reboots it.

-- 
  Nicolas George
___
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".


Re: [FFmpeg-devel] [TC] Decision on FF_INTERNAL_FIELDS in libavfilter

2024-02-13 Thread Rémi Denis-Courmont
Hi,



Le 13 février 2024 18:22:46 GMT+02:00, Nicolas George  a écrit 
:
>Martin Storsjo (12024-02-13):
>> The main arguments raised were about API consistency, prevention of
>> accidental inclusions, as well as explicitness in marking a field as
>> public or private.
>
>Too bad the committee neglected to ask for the arguments of the people
>who opposed this. Like having a trial and not listening to the defense.

Speaking as an elected member of another OSS project's TC, I believe that the 
experienced adult developers on the FFmpeg TC are perfectly capable of reading 
mailing archives and Trac comments as necessary. In fact, I think it is 
preferable that they stick to arguments made in public, rather than go out of 
their way to dig up private information.

Or to follow your metaphor, in a trial, the arguments are made before the jury 
in public sessions. The deliberations of the jury are kept private to shield 
members from external pressure.

I don't expect that antagonising the TC members will do you, and any potential 
future arguments of yours, much good.
___
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] avutil/channel_layout: print known layout names in custom layout

2024-02-13 Thread James Almer
If a custom layout is equivalent to a native one, check if it matches one of the
known layout names and print that instead.

Signed-off-by: James Almer 
---
Should be applied after the patch this one is a reply to.

 libavutil/channel_layout.c| 68 +--
 tests/ref/fate/channel_layout |  4 +--
 2 files changed, 44 insertions(+), 28 deletions(-)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index 7f51c076dc..8b3bf2f4af 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -679,6 +679,29 @@ int av_channel_layout_copy(AVChannelLayout *dst, const 
AVChannelLayout *src)
 return 0;
 }
 
+static int64_t masked_description(const AVChannelLayout *channel_layout, int 
start_channel)
+{
+uint64_t mask = 0;
+for (int i = start_channel; i < channel_layout->nb_channels; i++) {
+enum AVChannel ch = channel_layout->u.map[i].id;
+if (ch >= 0 && ch < 63 && mask < (1ULL << ch))
+mask |= (1ULL << ch);
+else
+return AVERROR(EINVAL);
+}
+return mask;
+}
+
+static int has_channel_names(const AVChannelLayout *channel_layout)
+{
+if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM)
+return 0;
+for (int i = 0; i < channel_layout->nb_channels; i++)
+if (channel_layout->u.map[i].name[0])
+return 1;
+return 0;
+}
+
 /**
  * If the layout is n-th order standard-order ambisonic, with optional
  * extra non-diegetic channels at the end, return the order.
@@ -746,9 +769,17 @@ static int try_describe_ambisonic(AVBPrint *bp, const 
AVChannelLayout *channel_l
 extra.nb_channels = av_popcount64(channel_layout->u.mask);
 extra.u.mask  = channel_layout->u.mask;
 } else {
-extra.order   = AV_CHANNEL_ORDER_CUSTOM;
-extra.nb_channels = channel_layout->nb_channels - nb_ambi_channels;
-extra.u.map   = channel_layout->u.map + nb_ambi_channels;
+int64_t mask;
+if (!has_channel_names(channel_layout) &&
+(mask = masked_description(channel_layout, nb_ambi_channels)) 
> 0) {
+extra.order   = AV_CHANNEL_ORDER_NATIVE;
+extra.nb_channels = av_popcount64(mask);
+extra.u.mask  = mask;
+} else {
+extra.order   = AV_CHANNEL_ORDER_CUSTOM;
+extra.nb_channels = channel_layout->nb_channels - 
nb_ambi_channels;
+extra.u.map   = channel_layout->u.map + nb_ambi_channels;
+}
 }
 
 av_bprint_chars(bp, '+', 1);
@@ -774,9 +805,17 @@ int av_channel_layout_describe_bprint(const 
AVChannelLayout *channel_layout,
 // fall-through
 case AV_CHANNEL_ORDER_CUSTOM:
 if (channel_layout->order == AV_CHANNEL_ORDER_CUSTOM) {
+int64_t mask;
 int res = try_describe_ambisonic(bp, channel_layout);
 if (res >= 0)
 return 0;
+if (!has_channel_names(channel_layout) &&
+(mask = masked_description(channel_layout, 0)) > 0) {
+AVChannelLayout native = { .order   = 
AV_CHANNEL_ORDER_NATIVE,
+   .nb_channels = av_popcount64(mask),
+   .u.mask  = mask };
+return av_channel_layout_describe_bprint(, bp);
+}
 }
 if (channel_layout->nb_channels)
 av_bprintf(bp, "%d channels (", channel_layout->nb_channels);
@@ -1037,29 +1076,6 @@ uint64_t av_channel_layout_subset(const AVChannelLayout 
*channel_layout,
 return ret;
 }
 
-static int64_t masked_description(AVChannelLayout *channel_layout, int 
start_channel)
-{
-uint64_t mask = 0;
-for (int i = start_channel; i < channel_layout->nb_channels; i++) {
-enum AVChannel ch = channel_layout->u.map[i].id;
-if (ch >= 0 && ch < 63 && mask < (1ULL << ch))
-mask |= (1ULL << ch);
-else
-return AVERROR(EINVAL);
-}
-return mask;
-}
-
-static int has_channel_names(AVChannelLayout *channel_layout)
-{
-if (channel_layout->order != AV_CHANNEL_ORDER_CUSTOM)
-return 0;
-for (int i = 0; i < channel_layout->nb_channels; i++)
-if (channel_layout->u.map[i].name[0])
-return 1;
-return 0;
-}
-
 int av_channel_layout_retype(AVChannelLayout *channel_layout, enum 
AVChannelOrder order, int flags)
 {
 int allow_lossy = !(flags & AV_CHANNEL_LAYOUT_RETYPE_FLAG_LOSSLESS);
diff --git a/tests/ref/fate/channel_layout b/tests/ref/fate/channel_layout
index 1d1f1cb082..466fa78d9e 100644
--- a/tests/ref/fate/channel_layout
+++ b/tests/ref/fate/channel_layout
@@ -195,7 +195,7 @@ With "FL@Boo": CUSTOM (1 channels (FL@Boo))
 With "stereo": NATIVE (stereo)
   ~~ UNSPEC (2 channels)
   == NATIVE (stereo)
-  == CUSTOM (2 channels (FL+FR))
+  == CUSTOM (stereo)
   != AMBI
 With 

Re: [FFmpeg-devel] [PATCH 32/35] avfilter/af_hdcd: Drop a redundant log

2024-02-13 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> avfilter_insert_filter() already reports (also with AV_LOG_VERBOSE)
> when a filter is auto-inserted.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
> Can be applied at any time.
> 
>  libavfilter/af_hdcd.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c
> index a03c9aadf7..9cd483cfc4 100644
> --- a/libavfilter/af_hdcd.c
> +++ b/libavfilter/af_hdcd.c
> @@ -1714,9 +1714,6 @@ static int config_input(AVFilterLink *inlink) {
>  HDCDContext *s = ctx->priv;
>  int c;
>  
> -av_log(ctx, AV_LOG_VERBOSE, "Auto-convert: %s\n",
> -(ctx->graph->disable_auto_convert) ? "disabled" : "enabled");
> -
>  if ((inlink->format == AV_SAMPLE_FMT_S16 ||
>   inlink->format == AV_SAMPLE_FMT_S16P) &&
>   s->bits_per_sample != 16) {

Will apply tomorrow unless there are objections.

- Andreas

___
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".


Re: [FFmpeg-devel] [PATCH 2/5] avutil/channel_layout: add AV_CHANNEL_ORDER_NB

2024-02-13 Thread James Almer

On 2/12/2024 6:15 PM, Marton Balint wrote:

Signed-off-by: Marton Balint 
---
  libavutil/channel_layout.h | 4 
  1 file changed, 4 insertions(+)

diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h
index b8bff6f365..db0c005e87 100644
--- a/libavutil/channel_layout.h
+++ b/libavutil/channel_layout.h
@@ -146,6 +146,10 @@ enum AVChannelOrder {
   * as defined in AmbiX format $ 2.1.
   */
  AV_CHANNEL_ORDER_AMBISONIC,
+/**
+ * Number of channel orders, not part of ABI/API
+ */
+AV_CHANNEL_ORDER_NB
  };


Is it worth adding this to a public header just to limit a loop in a 
test? A loop that fwiw still depends on an array that needs to be 
updated with more names if you add new orders.


IMO, just do FF_ARRAY_ELEMS(channel_order_names) in the test.
___
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".


Re: [FFmpeg-devel] [PATCH v2 1/2] avcodec/s302m: enable non-PCM decoding

2024-02-13 Thread Gyan Doshi




On 2024-01-27 04:08 pm, Gyan Doshi wrote:

Set up framework for non-PCM decoding in-place and
add support for Dolby-E decoding.

Useful for direct transcoding of non-PCM audio in live inputs.


Plan to push in 3 days, barring objections.

Regards,
Gyan



---
  configure  |   1 +
  doc/decoders.texi  |  40 +++
  libavcodec/s302m.c | 596 +
  3 files changed, 530 insertions(+), 107 deletions(-)

v2:
switch to pointer for non-pcm sync search
use intreadwrite macro for writing frame data
remove unneeded free of non-pcm dec opts

diff --git a/configure b/configure
index 21663000f8..4d7cd83247 100755
--- a/configure
+++ b/configure
@@ -2980,6 +2980,7 @@ rv20_decoder_select="h263_decoder"
  rv20_encoder_select="h263_encoder"
  rv30_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
  rv40_decoder_select="golomb h264pred h264qpel mpegvideodec rv34dsp"
+s302m_decoder_select="dolby_e_decoder"
  screenpresso_decoder_deps="zlib"
  shorten_decoder_select="bswapdsp"
  sipr_decoder_select="lsp"
diff --git a/doc/decoders.texi b/doc/decoders.texi
index 293c82c2ba..9f85c876bf 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -347,6 +347,46 @@ configuration. You need to explicitly configure the build 
with
  An FFmpeg native decoder for Opus exists, so users can decode Opus
  without this library.
  
+@section s302m

+
+SMPTE ST 302 decoder.
+
+SMPTE ST 302 is a method for storing AES3 data format within an MPEG Transport
+Stream. AES3 streams can contain LPCM streams of 2, 4, 6 or 8 channels with a
+bit depth of 16, 20 or 24-bits at a sample rate of 48 kHz.
+They can also contain non-PCM codec streams such as AC-3 or Dolby-E.
+
+Decoding non-PCM streams directly requires that the necessary stream decoder be
+present in the build. At present, only Dolby-E decoding is supported.
+
+@subsection Options
+
+The following options are supported by the s302m decoder.
+
+@table @option
+@item non_pcm_mode @var{mode}
+Specify how to process non-PCM streams
+
+@table @samp
+@item copy
+Treat data as if it were LPCM.
+@item drop
+Discard the stream.
+@item decode_copy
+Decode if possible eise treat the same as @code{copy}.
+@item decode_drop
+Decode if possible eise treat the same as @code{drop}.
+@end table
+
+The default value is @code{decode_drop}. This option does not affect the 
processing of
+LPCM streams.
+
+@item non_pcm_options @var{options}
+Set options for non-PCM decoder using a list of key=value pairs separated by 
":".
+Consult the docs for the non-PCM decoder for its options.
+
+@end table
+
  @c man end AUDIO DECODERS
  
  @chapter Subtitles Decoders

diff --git a/libavcodec/s302m.c b/libavcodec/s302m.c
index f1b41608f3..d890b6f117 100644
--- a/libavcodec/s302m.c
+++ b/libavcodec/s302m.c
@@ -24,21 +24,264 @@
  #include "libavutil/intreadwrite.h"
  #include "libavutil/opt.h"
  #include "libavutil/log.h"
+#include "libavutil/dict.h"
  #include "libavutil/reverse.h"
  #include "avcodec.h"
  #include "codec_internal.h"
+#include "get_bits.h"
  #include "decode.h"
  
  #define AES3_HEADER_LEN 4
  
+#define NONPCMSYNC_16MARKER  0x4E1F0F8720

+#define NONPCMSYNC_20MARKER  0x4E1F60F872A0
+#define NONPCMSYNC_24MARKER  0x7E1F690F872A50
+
+#define NONPCMSYNC_16_IN_20MARKER  0x04E1F00F8720
+#define NONPCMSYNC_20_IN_24MARKER  0x04E1F600F872A0
+
+#define IS_NONPCMSYNC_16(state)   ((state & 0x00) == 
NONPCMSYNC_16MARKER)
+#define IS_NONPCMSYNC_20(state)   ((state & 0xF0F0)   == 
NONPCMSYNC_20MARKER)
+#define IS_NONPCMSYNC_24(state)   ((state & 0xFF0FF0) == 
NONPCMSYNC_24MARKER)
+
+#define IS_NONPCMSYNC_16_IN_20(state)   ((state & 0x0000)   == 
NONPCMSYNC_16_IN_20MARKER)
+#define IS_NONPCMSYNC_20_IN_24(state)   ((state & 0x0F00F0) == 
NONPCMSYNC_20_IN_24MARKER)
+
+#define IS_NONPCMSYNC(bit,state)  ( ((bit == 16) &&  IS_NONPCMSYNC_16(state)) 
|| \
+((bit == 20) && (IS_NONPCMSYNC_20(state) 
|| IS_NONPCMSYNC_16_IN_20(state))) || \
+((bit == 24) && (IS_NONPCMSYNC_24(state) 
|| IS_NONPCMSYNC_20_IN_24(state))) \
+  )
+
+enum non_pcm_modes {
+NON_PCM_COPY,
+NON_PCM_DROP,
+NON_PCM_DEC_ELSE_COPY,
+NON_PCM_DEC_ELSE_DROP,
+};
+
  typedef struct S302Context {
  AVClass *class;
+
+int avctx_props_set;
+
+int channels;
+int bits;
+
  int non_pcm_mode;
+int non_pcm_data_type;
+int non_pcm_bits;
+int non_pcm_dec;
+
+AVCodecContext *non_pcm_ctx;
+AVDictionary   *non_pcm_opts;
+AVPacket *packet;
+AVFrame  *frame;
  } S302Context;
  
+static av_cold int s302m_init(AVCodecContext *avctx)

+{
+S302Context *s = avctx->priv_data;
+
+s->non_pcm_data_type = -1;
+
+return 0;
+}
+
+static int s302m_non_pcm_inspect(AVCodecContext *avctx, const uint8_t *buf, 
int buf_size,
+  int *offset, int *length)
+{
+

Re: [FFmpeg-devel] [TC] Decision on FF_INTERNAL_FIELDS in libavfilter

2024-02-13 Thread Nicolas George
Martin Storsjo (12024-02-13):
> The main arguments raised were about API consistency, prevention of
> accidental inclusions, as well as explicitness in marking a field as
> public or private.

Too bad the committee neglected to ask for the arguments of the people
who opposed this. Like having a trial and not listening to the defense.

-- 
  Nicolas George
___
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] [TC] Decision on FF_INTERNAL_FIELDS in libavfilter

2024-02-13 Thread FFmpeg Technical Committee
Hi,

Last year, Anton raised the conflict on his patch "lavfi: get rid of 
FF_INTERNAL_FIELDS", 
https://lists.ffmpeg.org//pipermail/ffmpeg-devel/2023-January/306102.html, to 
the TC to decide on.

At the time, the TC did not come to any conclusion on the matter. Recently, 
Anton raised the question again, and this time, the current TC managed to 
successfully discuss the matter and come to a conclusion.

The main arguments raised were about API consistency, prevention of accidental 
inclusions, as well as explicitness in marking a field as public or private. 
These advantages were deemed to be worth the trade-off of making access to 
private fields slightly less convenient.

The TC has voted on the matter, with 4 votes in favour of the patch, 1 vote 
preferring to look for other solutions, and Anton himself abstaining from the 
vote.

Therefore, the matter has been decided, approving the patch at hand.

Regards,
The FFmpeg Technical Committee
- Jan Ekström
- Mark Thompson
- Martin Storsjö
- Michael Niedermayer
- Niklas Haas
- Anton Khirnov

___
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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] lavf/assenc: normalize line endings to \n

2024-02-13 Thread Martin Storsjö

On Tue, 13 Feb 2024, Ridley Combs wrote:


It looks like checkout has different behavior from reset, and fate uses a
hard reset.
To test, I committed the change adding tests/ref/** -text,
unix2dos'd tests/ref/fate/sub-scc, then ran git -c core.autocrlf=true reset
--quiet --hard; this dos2unix'd the file as expected when run with a working
tree containing the .gitattributes change (but not otherwise).


Git doesn't have any "memory" of the CRLFiness of a file beyond the content
of the file itself (whether in the working tree or in committed blobs). It
just doesn't necessarily replace every file in checkout invocations when
they differ only in line endings. Windows was a mistake.


To rephrase; reset vs checkout doesn't make any difference here.

It seems to simply be the case, that as long as there are no changes to 
the file contents themselves between the relevant git commits, and the 
file isn't flagged as dirty in the stat cache of the local workdir, git 
never revisits the .gitattributes for this particular file.


// Martin
___
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".


Re: [FFmpeg-devel] [PATCH] fate/subtitles: Ignore line endings for sub-scc test

2024-02-13 Thread Martin Storsjö via ffmpeg-devel

On Tue, 13 Feb 2024, Andreas Rheinhardt wrote:


Since 7bf1b9b35769b37684dd2f18a54f01d852a540c8,
the test produces ordinary \n, yet this is not what the reference
file used for the most time, leading to test failures.

Signed-off-by: Andreas Rheinhardt 
---
tests/fate/subtitles.mak | 1 +
1 file changed, 1 insertion(+)

diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
index cea4c810dd..90412e9ac1 100644
--- a/tests/fate/subtitles.mak
+++ b/tests/fate/subtitles.mak
@@ -114,6 +114,7 @@ fate-sub-charenc: CMD = fmtstdout ass -sub_charenc cp1251 
-i $(TARGET_SAMPLES)/s

FATE_SUBTITLES-$(call DEMDEC, SCC, CCAPTION) += fate-sub-scc
fate-sub-scc: CMD = fmtstdout ass -ss 57 -i $(TARGET_SAMPLES)/sub/witch.scc
+fate-sub-scc: CMP = diff

FATE_SUBTITLES-$(call DEMMUX, SCC, SCC) += fate-sub-scc-remux
fate-sub-scc-remux: CMD = fmtstdout scc -i $(TARGET_SAMPLES)/sub/witch.scc -ss 
4:00 -map 0 -c copy
--
2.34.1


Looks ok to me, as a temporary measure until we figure out the best way to 
upgrade everybody's workdirs without needing interaction. (As an added 
note to the other thread; even if we could easily patch fate.sh, every 
current user's workdir is also prone to this issue, and the way of fixing 
it is kinda non-obvious.)


// Martin

___
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".


Re: [FFmpeg-devel] [PATCH] avformat/matroska: Add support for A_ATRAC/AT1

2024-02-13 Thread Andreas Rheinhardt
asivery via ffmpeg-devel:
> I've attached the updated patch. Both new entries are now placed in an 
> alphabetically correct way in their appropriate lists.
> 

Applied.

- Andreas

___
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".


Re: [FFmpeg-devel] [PATCH] avcodec/avcodec: don't print coded dimensions if not set

2024-02-13 Thread James Almer

On 2/10/2024 2:39 PM, James Almer wrote:

The avctx passed to avcodec_string() may have unset coded dimensions, as is
the case when called by av_dump_format() where the streams had all the needed
information at the container level, and as such no frames were decoded 
internally.

Signed-off-by: James Almer 
---
  libavcodec/avcodec.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index b6d27ada21..a13b781996 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -625,6 +625,7 @@ void avcodec_string(char *buf, int buf_size, AVCodecContext 
*enc, int encode)
 enc->width, enc->height);
  
  if (av_log_get_level() >= AV_LOG_VERBOSE &&

+enc->coded_width && enc->coded_height &&
  (enc->width != enc->coded_width ||
   enc->height != enc->coded_height))
  av_bprintf(, " (%dx%d)",


Will apply.
___
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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] lavf/assenc: normalize line endings to \n

2024-02-13 Thread Martin Storsjö

On Tue, 13 Feb 2024, Ridley Combs wrote:


It looks like checkout has different behavior from reset, and fate uses a
hard reset.
To test, I committed the change adding tests/ref/** -text,
unix2dos'd tests/ref/fate/sub-scc, then ran git -c core.autocrlf=true reset
--quiet --hard; this dos2unix'd the file as expected when run with a working
tree containing the .gitattributes change (but not otherwise).


The difference here seems to be that you actively modify 
tests/ref/fate/sub-scc, which causes git to consider the file as needing 
to be restored when you run git reset.


When fate updates from one version to another, the files won't be locally 
modified, i.e. git's stat cache or similar has this file flagged as "not 
dirty".


So I suggest you retry your procedure by not manually modifying the file, 
but just letting git handle it, simulating exactly what happens on fate 
instances when updating from one version to another.


I.e., first check out 7bf1b9b3576~, nuke the file and check it out again, 
make sure that it contains CRLF. Then check out current master, which 
lacks attributes, but the local file in your workdir still contains CRLF. 
Then do any series of "git reset --hard", with/without "-c core.autocrlf", 
to commits on your experimental branch, and it won't change the line 
endings of the ref file, unless there actually are content changes to that 
particular file, between the git commits that you do check out.


// Martin
___
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] fate/subtitles: Ignore line endings for sub-scc test

2024-02-13 Thread Andreas Rheinhardt
Since 7bf1b9b35769b37684dd2f18a54f01d852a540c8,
the test produces ordinary \n, yet this is not what the reference
file used for the most time, leading to test failures.

Signed-off-by: Andreas Rheinhardt 
---
 tests/fate/subtitles.mak | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/fate/subtitles.mak b/tests/fate/subtitles.mak
index cea4c810dd..90412e9ac1 100644
--- a/tests/fate/subtitles.mak
+++ b/tests/fate/subtitles.mak
@@ -114,6 +114,7 @@ fate-sub-charenc: CMD = fmtstdout ass -sub_charenc cp1251 
-i $(TARGET_SAMPLES)/s
 
 FATE_SUBTITLES-$(call DEMDEC, SCC, CCAPTION) += fate-sub-scc
 fate-sub-scc: CMD = fmtstdout ass -ss 57 -i $(TARGET_SAMPLES)/sub/witch.scc
+fate-sub-scc: CMP = diff
 
 FATE_SUBTITLES-$(call DEMMUX, SCC, SCC) += fate-sub-scc-remux
 fate-sub-scc-remux: CMD = fmtstdout scc -i $(TARGET_SAMPLES)/sub/witch.scc -ss 
4:00 -map 0 -c copy
-- 
2.34.1

___
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] avformat/dump: Fix use of undeclared variables

2024-02-13 Thread Andreas Rheinhardt
Broken in ec2036454bcdc6c12382961d4ab539c2f9b70ec8.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/dump.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/dump.c b/libavformat/dump.c
index 9bf1695d96..42b1909bd7 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -685,7 +685,7 @@ static void dump_stream_group(const AVFormatContext *ic, 
uint8_t *printed,
 case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: {
 const AVIAMFAudioElement *audio_element = 
stg->params.iamf_audio_element;
 av_log(NULL, AV_LOG_INFO, " IAMF Audio Element:");
-dump_disposition(st->disposition, log_level);
+dump_disposition(stg->disposition, AV_LOG_INFO);
 av_log(NULL, AV_LOG_INFO, "\n");
 dump_metadata(NULL, stg->metadata, "", AV_LOG_INFO);
 for (int j = 0; j < audio_element->nb_layers; j++) {
@@ -708,7 +708,7 @@ static void dump_stream_group(const AVFormatContext *ic, 
uint8_t *printed,
 case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: {
 const AVIAMFMixPresentation *mix_presentation = 
stg->params.iamf_mix_presentation;
 av_log(NULL, AV_LOG_INFO, " IAMF Mix Presentation:");
-dump_disposition(st->disposition, log_level);
+dump_disposition(stg->disposition, AV_LOG_INFO);
 av_log(NULL, AV_LOG_INFO, "\n");
 dump_metadata(NULL, stg->metadata, "", AV_LOG_INFO);
 dump_dictionary(NULL, mix_presentation->annotations, "Annotations", "  
  ", AV_LOG_INFO);
-- 
2.34.1

___
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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] lavf/assenc: normalize line endings to \n

2024-02-13 Thread Ridley Combs via ffmpeg-devel


> On Feb 13, 2024, at 04:33, Martin Storsjö  wrote:
> 
> On Tue, 13 Feb 2024, Ridley Combs via ffmpeg-devel wrote:
> 
>>> On Feb 13, 2024, at 01:28, Anton Khirnov  wrote:
>>> Quoting Martin Storsjö (2024-02-12 12:31:29)
 On Mon, 12 Feb 2024, Hendrik Leppkes wrote:
> On Mon, Feb 12, 2024 at 11:22 AM Martin Storsjö  wrote:
>>> diff --git a/.gitattributes b/.gitattributes
>>> index 5a19b963b6..a900528e47 100644
>>> --- a/.gitattributes
>>> +++ b/.gitattributes
>>> @@ -1,2 +1 @@
>>> *.pnm -diff -text
>>> -tests/ref/fate/sub-scc eol=crlf
>> This change seems to have had a tricky effect on the
>> tests/ref/fate/sub-scc file. Previously, when checked out, users got the
>> file with CRLF newlines. When updating to this git commit, or past it,
>> that file remains untouched, with CRLF still present, and the
>> fate-sub-scc test fails. If one does "rm tests/ref/fate/sub-scc; git
>> checkout tests/ref/fate/sub-scc", then the file does get restored with LR
>> newlines, and the test passes.
>> It's easy to do this change manually in the source checkout of a fate
>> runner, but I'm not sure how easily we get all fate instances fixed that
>> way - currently this test is failing in most of them.
> Can this be fixed by restoring the .gitattribute entry but with eol=lf?
> Not sure if Git would reset the file then.
 No, that doesn't seem to make any difference. Not sure if there are any 
 other straightforward/elegant fixes, short of renaming the file, which I 
 guess would require renaming the test itself.
>>> I'm fine with renaming the test, unless anyone has a better fix.
>> 
>> We could probably tweak the fate runner script to make sure this gets fixed 
>> up; can anyone try this patch on one of the affected machines? 
>> https://gist.github.com/rcombs/c2ad470bf36c5cbd3fc33e699330eb15
> 
> That doesn't seem to make any difference.
> 
> Also, updating fate.sh doesn't necessarily propagate automatically to runners 
> - in order to run fate, one needs to run fate.sh before it even clones/checks 
> out the directory where it fetches the latest source. So unless one later has 
> changed one's setup, to invoke a fate.sh from the checkout, most fate runners 
> just use whatever copy of fate.sh they had when it was set up.
> 
>> Alternately, we could set -text on all fate ref files, or explicitly set 
>> eol=of for them, to ensure their line endings never get rewritten like this 
>> regardless of git config. I think either of these solutions would fix this 
>> in fate, but only after the fix commit gets checked out *followed by* at 
>> least one other commit.
> 
> Neither of those seem to make any difference either.
> 
> It's quite easy to test for one self:
> 
> $ git checkout -b experiment
> $ 
> $ 
> 
> $ git checkout 7bf1b9b3576~ # Reset original state, for testing
> $ rm tests/ref/fate/sub-scc; git checkout tests/ref/fate/sub-scc
> $ vi tests/ref/fate/sub-scc # inspect that the file originally has CRLF
> $ git checkout experiment~ # check out the commit setting attributes
> $ git checkout experiment # check out the next commit, with the new 
> attributes set
> $ vi tests/ref/fate/sub-scc # observe that the file still has CRLF
> 
> $ git checkout --detach
> $ git -c core.autocrlf=false reset --hard 7bf1b9b3576
> $ vi tests/ref/fate/sub-scc # observe that the file still has CRLF

It looks like checkout has different behavior from reset, and fate uses a hard 
reset.
To test, I committed the change adding tests/ref/** -text, unix2dos'd 
tests/ref/fate/sub-scc, then ran git -c core.autocrlf=true reset --quiet 
--hard; this dos2unix'd the file as expected when run with a working tree 
containing the .gitattributes change (but not otherwise).

> 
> 
> It seems to me (I haven't trid to dig into manuals) that the attribute gets 
> stuck in whatever form it was when the file was first created in the workdir. 
> E.g. doing a "git checkout d1df72a702~" (the commit before the file was 
> originally added) followed by "git checkout 7bf1b9b3576" does fix it. This is 
> at least observed with git 2.25.1. Not sure if this is intended behaviour or 
> a bug from git's side.

Git doesn't have any "memory" of the CRLFiness of a file beyond the content of 
the file itself (whether in the working tree or in committed blobs). It just 
doesn't necessarily replace every file in checkout invocations when they differ 
only in line endings. Windows was a mistake.

> 
> // Martin

___
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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] lavf/assenc: normalize line endings to \n

2024-02-13 Thread Martin Storsjö

On Tue, 13 Feb 2024, Ridley Combs via ffmpeg-devel wrote:


On Feb 13, 2024, at 01:28, Anton Khirnov  wrote:

Quoting Martin Storsjö (2024-02-12 12:31:29)

On Mon, 12 Feb 2024, Hendrik Leppkes wrote:


On Mon, Feb 12, 2024 at 11:22 AM Martin Storsjö  wrote:


diff --git a/.gitattributes b/.gitattributes
index 5a19b963b6..a900528e47 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,2 +1 @@
*.pnm -diff -text
-tests/ref/fate/sub-scc eol=crlf


This change seems to have had a tricky effect on the
tests/ref/fate/sub-scc file. Previously, when checked out, users got the
file with CRLF newlines. When updating to this git commit, or past it,
that file remains untouched, with CRLF still present, and the
fate-sub-scc test fails. If one does "rm tests/ref/fate/sub-scc; git
checkout tests/ref/fate/sub-scc", then the file does get restored with LR
newlines, and the test passes.

It's easy to do this change manually in the source checkout of a fate
runner, but I'm not sure how easily we get all fate instances fixed that
way - currently this test is failing in most of them.



Can this be fixed by restoring the .gitattribute entry but with eol=lf?
Not sure if Git would reset the file then.


No, that doesn't seem to make any difference. Not sure if there are any 
other straightforward/elegant fixes, short of renaming the file, which I 
guess would require renaming the test itself.


I'm fine with renaming the test, unless anyone has a better fix.


We could probably tweak the fate runner script to make sure this gets 
fixed up; can anyone try this patch on one of the affected machines? 
https://gist.github.com/rcombs/c2ad470bf36c5cbd3fc33e699330eb15


That doesn't seem to make any difference.

Also, updating fate.sh doesn't necessarily propagate automatically to 
runners - in order to run fate, one needs to run fate.sh before it even 
clones/checks out the directory where it fetches the latest source. So 
unless one later has changed one's setup, to invoke a fate.sh from the 
checkout, most fate runners just use whatever copy of fate.sh they had 
when it was set up.


Alternately, we could set -text on all fate ref files, or explicitly set 
eol=of for them, to ensure their line endings never get rewritten like 
this regardless of git config. I think either of these solutions would 
fix this in fate, but only after the fix commit gets checked out 
*followed by* at least one other commit.


Neither of those seem to make any difference either.

It's quite easy to test for one self:

$ git checkout -b experiment
$ 
$ 

$ git checkout 7bf1b9b3576~ # Reset original state, for testing
$ rm tests/ref/fate/sub-scc; git checkout tests/ref/fate/sub-scc
$ vi tests/ref/fate/sub-scc # inspect that the file originally has CRLF
$ git checkout experiment~ # check out the commit setting attributes
$ git checkout experiment # check out the next commit, with the new attributes 
set
$ vi tests/ref/fate/sub-scc # observe that the file still has CRLF

$ git checkout --detach
$ git -c core.autocrlf=false reset --hard 7bf1b9b3576
$ vi tests/ref/fate/sub-scc # observe that the file still has CRLF


It seems to me (I haven't trid to dig into manuals) that the attribute 
gets stuck in whatever form it was when the file was first created in the 
workdir. E.g. doing a "git checkout d1df72a702~" (the commit before the 
file was originally added) followed by "git checkout 7bf1b9b3576" does fix 
it. This is at least observed with git 2.25.1. Not sure if this is 
intended behaviour or a bug from git's side.


// Martin
___
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] avcodec/x86/simple_idct: Empty MMX state in ff_simple_idct_mmx

2024-02-13 Thread Andreas Rheinhardt
We currently mostly do not empty the MMX state in our MMX
DSP functions; instead we only do so before code that might
be using x87 code. This is a violation of the System V i386 ABI
(and maybe of other ABIs, too):
"The CPU shall be in x87 mode upon entry to a function. Therefore,
every function that uses the MMX registers is required to issue an
emms or femms instruction after using MMX registers, before returning
or calling another function." (See 2.2.1 in [1])
This patch does not intend to change all these functions to abide
by the ABI; it only does so for ff_simple_idct_mmx, as this
function can by called by external users, because it is exported
via the avdct API. Without this, the following fragment will
assert (on x86_32, as ff_simple_idct_mmx is not used on x64):
int16_t __attribute__ ((aligned (16))) block[64];
AVDCT *dct = avcodec_dct_alloc();
dct->idct_algo = FF_IDCT_AUTO;
avcodec_dct_init(dct);
dct->idct(block);
av_assert0_fpu();

[1]: 
https://raw.githubusercontent.com/wiki/hjl-tools/x86-psABI/intel386-psABI-1.1.pdf

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/x86/simple_idct.asm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavcodec/x86/simple_idct.asm b/libavcodec/x86/simple_idct.asm
index 982b2f0bbb..4139b6dab5 100644
--- a/libavcodec/x86/simple_idct.asm
+++ b/libavcodec/x86/simple_idct.asm
@@ -845,6 +845,7 @@ INIT_MMX mmx
 
 cglobal simple_idct, 1, 2, 8, 128, block, t0
 IDCT
+emms
 RET
 
 INIT_XMM sse2
-- 
2.34.1

___
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".


Re: [FFmpeg-devel] [PATCH] avformat/avformat: Remove reference to removed setter

2024-02-13 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Removed in 704017d91ec8fbade0de072d222018c1a6013b70.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/avformat.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 5d0fe82250..1e98970b89 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -1688,7 +1688,7 @@ typedef struct AVFormatContext {
>  /**
>   * Number of bytes to be written as padding in a metadata header.
>   * Demuxing: Unused.
> - * Muxing: Set by user via av_format_set_metadata_header_padding.
> + * Muxing: Set by user.
>   */
>  int metadata_header_padding;
>  

Will apply tomorrow unless there are objections.

- Andreas

___
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".


Re: [FFmpeg-devel] [PATCH] avcodec/cri, tdsc, tiff: Don't forward AVCodecContext.dct_algo

2024-02-13 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> It is unused for decoders.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/cri.c  | 1 -
>  libavcodec/tdsc.c | 1 -
>  libavcodec/tiff.c | 1 -
>  3 files changed, 3 deletions(-)
> 
> diff --git a/libavcodec/cri.c b/libavcodec/cri.c
> index 0380a0c665..c4eb468610 100644
> --- a/libavcodec/cri.c
> +++ b/libavcodec/cri.c
> @@ -70,7 +70,6 @@ static av_cold int cri_decode_init(AVCodecContext *avctx)
>  return AVERROR(ENOMEM);
>  s->jpeg_avctx->flags = avctx->flags;
>  s->jpeg_avctx->flags2 = avctx->flags2;
> -s->jpeg_avctx->dct_algo = avctx->dct_algo;
>  s->jpeg_avctx->idct_algo = avctx->idct_algo;
>  ret = avcodec_open2(s->jpeg_avctx, codec, NULL);
>  if (ret < 0)
> diff --git a/libavcodec/tdsc.c b/libavcodec/tdsc.c
> index 739738d9b1..624e219cb4 100644
> --- a/libavcodec/tdsc.c
> +++ b/libavcodec/tdsc.c
> @@ -127,7 +127,6 @@ static av_cold int tdsc_init(AVCodecContext *avctx)
>  return AVERROR(ENOMEM);
>  ctx->jpeg_avctx->flags = avctx->flags;
>  ctx->jpeg_avctx->flags2 = avctx->flags2;
> -ctx->jpeg_avctx->dct_algo = avctx->dct_algo;
>  ctx->jpeg_avctx->idct_algo = avctx->idct_algo;
>  ret = avcodec_open2(ctx->jpeg_avctx, codec, NULL);
>  if (ret < 0)
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index adb49e4525..7687dfd0d6 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -2416,7 +2416,6 @@ static av_cold int tiff_init(AVCodecContext *avctx)
>  return AVERROR(ENOMEM);
>  s->avctx_mjpeg->flags = avctx->flags;
>  s->avctx_mjpeg->flags2 = avctx->flags2;
> -s->avctx_mjpeg->dct_algo = avctx->dct_algo;
>  s->avctx_mjpeg->idct_algo = avctx->idct_algo;
>  s->avctx_mjpeg->max_pixels = avctx->max_pixels;
>  ret = avcodec_open2(s->avctx_mjpeg, codec, NULL);

Will apply tomorrow unless there are objections.

- Andreas

___
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".


Re: [FFmpeg-devel] [PATCH] avfilter/vf_(bwdif|yadif)_cuda: Remove unused variables

2024-02-13 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Forgotten in 268062fa15e1c05310f9c3977e0b95ac07eca274.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavfilter/vf_bwdif_cuda.c | 1 -
>  libavfilter/vf_yadif_cuda.c | 1 -
>  2 files changed, 2 deletions(-)
> 
> diff --git a/libavfilter/vf_bwdif_cuda.c b/libavfilter/vf_bwdif_cuda.c
> index 7585d1fe25..8c37dc8800 100644
> --- a/libavfilter/vf_bwdif_cuda.c
> +++ b/libavfilter/vf_bwdif_cuda.c
> @@ -199,7 +199,6 @@ static av_cold void deint_cuda_uninit(AVFilterContext 
> *ctx)
>  {
>  CUcontext dummy;
>  DeintCUDAContext *s = ctx->priv;
> -YADIFContext *y = >yadif;
>  
>  if (s->hwctx && s->cu_module) {
>  CudaFunctions *cu = s->hwctx->internal->cuda_dl;
> diff --git a/libavfilter/vf_yadif_cuda.c b/libavfilter/vf_yadif_cuda.c
> index 17389f092f..79080e71c2 100644
> --- a/libavfilter/vf_yadif_cuda.c
> +++ b/libavfilter/vf_yadif_cuda.c
> @@ -191,7 +191,6 @@ static av_cold void deint_cuda_uninit(AVFilterContext 
> *ctx)
>  {
>  CUcontext dummy;
>  DeintCUDAContext *s = ctx->priv;
> -YADIFContext *y = >yadif;
>  
>  if (s->hwctx && s->cu_module) {
>  CudaFunctions *cu = s->hwctx->internal->cuda_dl;

Will apply tomorrow unless there are objections.

- Andreas

___
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 24/24] avutil/hwcontext_cuda: Allocate public and internal device ctx jointly

2024-02-13 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavutil/hwcontext_cuda.c | 43 +++---
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index b430b42f62..3de3847399 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -35,6 +35,11 @@ typedef struct CUDAFramesContext {
 int tex_alignment;
 } CUDAFramesContext;
 
+typedef struct CUDADeviceContext {
+AVCUDADeviceContext p;
+AVCUDADeviceContextInternal internal;
+} CUDADeviceContext;
+
 static const enum AVPixelFormat supported_formats[] = {
 AV_PIX_FMT_NV12,
 AV_PIX_FMT_YUV420P,
@@ -283,39 +288,35 @@ exit:
 
 static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
 {
-AVCUDADeviceContext *hwctx = device_ctx->hwctx;
+CUDADeviceContext *hwctx = device_ctx->hwctx;
 
-if (hwctx->internal) {
-CudaFunctions *cu = hwctx->internal->cuda_dl;
+if (hwctx->p.internal) {
+CudaFunctions *cu = hwctx->internal.cuda_dl;
 
-if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
-if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
-
CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
-else if (!(hwctx->internal->flags & AV_CUDA_USE_CURRENT_CONTEXT))
-CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
+if (hwctx->internal.is_allocated && hwctx->p.cuda_ctx) {
+if (hwctx->internal.flags & AV_CUDA_USE_PRIMARY_CONTEXT)
+
CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal.cuda_device));
+else if (!(hwctx->internal.flags & AV_CUDA_USE_CURRENT_CONTEXT))
+CHECK_CU(cu->cuCtxDestroy(hwctx->p.cuda_ctx));
 
-hwctx->cuda_ctx = NULL;
+hwctx->p.cuda_ctx = NULL;
 }
 
-cuda_free_functions(>internal->cuda_dl);
+cuda_free_functions(>internal.cuda_dl);
+memset(>internal, 0, sizeof(hwctx->internal));
+hwctx->p.internal = NULL;
 }
-
-av_freep(>internal);
 }
 
 static int cuda_device_init(AVHWDeviceContext *ctx)
 {
-AVCUDADeviceContext *hwctx = ctx->hwctx;
+CUDADeviceContext *hwctx = ctx->hwctx;
 int ret;
 
-if (!hwctx->internal) {
-hwctx->internal = av_mallocz(sizeof(*hwctx->internal));
-if (!hwctx->internal)
-return AVERROR(ENOMEM);
-}
+hwctx->p.internal = >internal;
 
-if (!hwctx->internal->cuda_dl) {
-ret = cuda_load_functions(>internal->cuda_dl, ctx);
+if (!hwctx->internal.cuda_dl) {
+ret = cuda_load_functions(>internal.cuda_dl, ctx);
 if (ret < 0) {
 av_log(ctx, AV_LOG_ERROR, "Could not dynamically load CUDA\n");
 goto error;
@@ -563,7 +564,7 @@ const HWContextType ff_hwcontext_type_cuda = {
 .type = AV_HWDEVICE_TYPE_CUDA,
 .name = "CUDA",
 
-.device_hwctx_size= sizeof(AVCUDADeviceContext),
+.device_hwctx_size= sizeof(CUDADeviceContext),
 .frames_hwctx_size= sizeof(CUDAFramesContext),
 
 .device_create= cuda_device_create,
-- 
2.34.1

___
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".


Re: [FFmpeg-devel] [PATCH v4 2/2] lavc/vulkan_av1: port to the new stable API

2024-02-13 Thread James Almer

On 2/13/2024 9:10 AM, Lynne wrote:

Feb 13, 2024, 01:59 by ffmpeg-devel@ffmpeg.org:


On Sun Feb 11, 2024 at 10:15 AM EST, Lynne wrote:


From: Lynne 
Date: Fri, 19 Jan 2024 10:49:02 +1000
Subject: [PATCH v4 2/2] lavc/vulkan_av1: port to the new stable API

Most of this patch was written by Dave Airlie ,
with some additions by me.
---

  
-ap->av1_pic_info = (VkVideoDecodeAV1PictureInfoMESA) {

-.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_MESA,
-.frame_header = >av1_frame_header,
-.tile_list = >tile_list,
+ap->av1_pic_info = (VkVideoDecodeAV1PictureInfoKHR) {
+.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_KHR,
+.pStdPictureInfo = >std_pic_info,
+.tileCount = ap->tile_count,
+.pTileOffsets = ap->tile_offsets,



Mentioned this on IRC earlier, but this means the driver always get
pTileOffsets = NULL, since ap->tile_offsets only gets filled out during
vk_av1_decode_slice().



Thanks, already fixed it, I did report back on IRC.



+
+ap->loop_restoration = (StdVideoAV1LoopRestoration) {
+.FrameRestorationType[0] = remap_lr_type[frame_header->lr_type[0]],
+.FrameRestorationType[1] = remap_lr_type[frame_header->lr_type[1]],
+.FrameRestorationType[2] = remap_lr_type[frame_header->lr_type[2]],
+.LoopRestorationSize[0] = AV1_RESTORATION_TILESIZE_MAX >> (2 - 
frame_header->lr_unit_shift),
+.LoopRestorationSize[1] = ap->loop_restoration.LoopRestorationSize[0] >> 
frame_header->lr_uv_shift,
+.LoopRestorationSize[2] = ap->loop_restoration.LoopRestorationSize[0] >> 
frame_header->lr_uv_shift,
+};



Not sure what the C spec says, but at least on GCC 13.2.1 it seems like
the assignment for LoopRestorationSize[1] and [2] happens before the
initalization of LoopRestorationSize[0].



Nothing here on gcc-12, gcc-14 and clang-19.


If some compilers break with it, then it needs to be changed. So make it:


ap->loop_restoration = (StdVideoAV1LoopRestoration) {
.FrameRestorationType[0] = remap_lr_type[frame_header->lr_type[0]],
.FrameRestorationType[1] = remap_lr_type[frame_header->lr_type[1]],
.FrameRestorationType[2] = remap_lr_type[frame_header->lr_type[2]],
.LoopRestorationSize[0] = AV1_RESTORATION_TILESIZE_MAX >> (2 - 
frame_header->lr_unit_shift),
};
ap->loop_restoration.LoopRestorationSize[1] =
ap->loop_restoration.LoopRestorationSize[2] = 
ap->loop_restoration.LoopRestorationSize[0] >> frame_header->lr_uv_shift,

___
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".


Re: [FFmpeg-devel] [PATCH v4 2/2] lavc/vulkan_av1: port to the new stable API

2024-02-13 Thread Lynne
Feb 13, 2024, 01:59 by ffmpeg-devel@ffmpeg.org:

> On Sun Feb 11, 2024 at 10:15 AM EST, Lynne wrote:
>
>> From: Lynne 
>> Date: Fri, 19 Jan 2024 10:49:02 +1000
>> Subject: [PATCH v4 2/2] lavc/vulkan_av1: port to the new stable API
>>
>> Most of this patch was written by Dave Airlie ,
>> with some additions by me.
>> ---
>>
>>  
>> -ap->av1_pic_info = (VkVideoDecodeAV1PictureInfoMESA) {
>> -.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_MESA,
>> -.frame_header = >av1_frame_header,
>> -.tile_list = >tile_list,
>> +ap->av1_pic_info = (VkVideoDecodeAV1PictureInfoKHR) {
>> +.sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PICTURE_INFO_KHR,
>> +.pStdPictureInfo = >std_pic_info,
>> +.tileCount = ap->tile_count,
>> +.pTileOffsets = ap->tile_offsets,
>>
>
> Mentioned this on IRC earlier, but this means the driver always get
> pTileOffsets = NULL, since ap->tile_offsets only gets filled out during
> vk_av1_decode_slice().
>

Thanks, already fixed it, I did report back on IRC.


>> +
>> +ap->loop_restoration = (StdVideoAV1LoopRestoration) {
>> +.FrameRestorationType[0] = remap_lr_type[frame_header->lr_type[0]],
>> +.FrameRestorationType[1] = remap_lr_type[frame_header->lr_type[1]],
>> +.FrameRestorationType[2] = remap_lr_type[frame_header->lr_type[2]],
>> +.LoopRestorationSize[0] = AV1_RESTORATION_TILESIZE_MAX >> (2 - 
>> frame_header->lr_unit_shift),
>> +.LoopRestorationSize[1] = 
>> ap->loop_restoration.LoopRestorationSize[0] >> frame_header->lr_uv_shift,
>> +.LoopRestorationSize[2] = 
>> ap->loop_restoration.LoopRestorationSize[0] >> frame_header->lr_uv_shift,
>> +};
>>
>
> Not sure what the C spec says, but at least on GCC 13.2.1 it seems like
> the assignment for LoopRestorationSize[1] and [2] happens before the
> initalization of LoopRestorationSize[0].
>

Nothing here on gcc-12, gcc-14 and clang-19.
___
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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] lavf/assenc: normalize line endings to \n

2024-02-13 Thread Ridley Combs via ffmpeg-devel


> On Feb 13, 2024, at 01:28, Anton Khirnov  wrote:
> 
> Quoting Martin Storsjö (2024-02-12 12:31:29)
>> On Mon, 12 Feb 2024, Hendrik Leppkes wrote:
>> 
>>> On Mon, Feb 12, 2024 at 11:22 AM Martin Storsjö  wrote:
> 
> diff --git a/.gitattributes b/.gitattributes
> index 5a19b963b6..a900528e47 100644
> --- a/.gitattributes
> +++ b/.gitattributes
> @@ -1,2 +1 @@
> *.pnm -diff -text
> -tests/ref/fate/sub-scc eol=crlf
 
 This change seems to have had a tricky effect on the
 tests/ref/fate/sub-scc file. Previously, when checked out, users got the
 file with CRLF newlines. When updating to this git commit, or past it,
 that file remains untouched, with CRLF still present, and the
 fate-sub-scc test fails. If one does "rm tests/ref/fate/sub-scc; git
 checkout tests/ref/fate/sub-scc", then the file does get restored with LR
 newlines, and the test passes.
 
 It's easy to do this change manually in the source checkout of a fate
 runner, but I'm not sure how easily we get all fate instances fixed that
 way - currently this test is failing in most of them.
 
>>> 
>>> Can this be fixed by restoring the .gitattribute entry but with eol=lf?
>>> Not sure if Git would reset the file then.
>> 
>> No, that doesn't seem to make any difference. Not sure if there are any 
>> other straightforward/elegant fixes, short of renaming the file, which I 
>> guess would require renaming the test itself.
> 
> I'm fine with renaming the test, unless anyone has a better fix.

We could probably tweak the fate runner script to make sure this gets fixed up; 
can anyone try this patch on one of the affected machines? 
https://gist.github.com/rcombs/c2ad470bf36c5cbd3fc33e699330eb15

Alternately, we could set -text on all fate ref files, or explicitly set eol=of 
for them, to ensure their line endings never get rewritten like this regardless 
of git config. I think either of these solutions would fix this in fate, but 
only after the fix commit gets checked out *followed by* at least one other 
commit.

> 
> -- 
> Anton Khirnov
> ___
> 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 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".


Re: [FFmpeg-devel] [PATCH] avcodec/vvcdec: frame_context_setup, set fc->ref to NULL

2024-02-13 Thread Frank Plowman
On 13/02/2024 02:30, Nuo Mi wrote:
> fc->ref points to an old VVCFrame, which cannot be used after 
> frame_context_setup.
> This prevents crashes in decode_nal_units-->ff_vvc_report_frame_finished.
> 
> Signed-off-by: Frank Plowman 
> ---
>  libavcodec/vvc/vvcdec.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c
> index 8163b5ecb6..e88e746de4 100644
> --- a/libavcodec/vvc/vvcdec.c
> +++ b/libavcodec/vvc/vvcdec.c
> @@ -594,6 +594,8 @@ static int frame_context_setup(VVCFrameContext *fc, 
> VVCContext *s)
>  {
>  int ret;
>  
> +fc->ref = NULL;
> +
>  // copy refs from the last frame
>  if (s->nb_frames && s->nb_fcs > 1) {
>  VVCFrameContext *prev = get_frame_context(s, fc, -1);

LGTM.  Fixes the crash on all the fuzz data I have which produce it.
FATE runners are failing at the time of writing, but I manually ran this
against the VVC tests as well as the suite from the FFVVC GitHub and all
tests passed.

Btw, I don't think you should add Signed-off-by tags for other people.
Their exact meaning varies by project and I am not sure of their meaning
in FFmpeg (if there is one), but generally they indicate that person
claims some sort of responsibility for the patch in the case of e.g. a
license violation.  That being said, I am happy to sign this off.

-- 
Frank
___
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 v2] avcodec/h2645_parse: Don't treat 0x000002 as a start code and truncate

2024-02-13 Thread Mattias Wadman
According to ITU-T H.265 7.4.2.1 this byte sequence should not appear in a
NAL unit but in practice in rare cases it seems it does, possibly due to buggy
encoders. Other players like VLC and Quicktime seem to be fine with it.

Currently when this sequence is found it is treated as if the next start code
has been found and the NAL unit gets truncated.

This change limits the code to only look for first start code 0x001 or
first escape 0x03.

Sadly i can't share the original source file with the issue but the first
80 bytes of the NAL unit looks like this:

   │00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f│0123456789abcdef│
0x0│00 00 00 01 02 01 d0 bc 57 a1 b8 44 70 01 00 0b│W..Dp...│
0x00010│80 2e 00 c2 6c ec 3e b9 e3 03 fb 91 2e d2 43 cb│l.>...C.│
0x00020│1d 2c 00 00 02 00 02 00 5c 93 72 6f 31 76 18 00│.,..\.ro1v..│
0x00030│08 38 aa b1 4c 33 3f fd 08 cb 77 9b d4 3c db 02│.8..L3?...w..<..│
0x00040│a2 04 73 15 75 de 3b c4 67 c0 8f ca ad 31 f1 99│..s.u.;.g1..│
---
 libavcodec/h2645_parse.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 28db465059..9f66f079c2 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -40,8 +40,9 @@ int ff_h2645_extract_rbsp(const uint8_t *src, int length,
 
 nal->skipped_bytes = 0;
 #define STARTCODE_TEST  \
-if (i + 2 < length && src[i + 1] == 0 && src[i + 2] <= 3) { \
-if (src[i + 2] != 3 && src[i + 2] != 0) {   \
+if (i + 2 < length && src[i + 1] == 0 &&\
+   (src[i + 2] == 3 || src[i + 2] == 1)) {  \
+if (src[i + 2] == 1) {  \
 /* startcode, so we must be past the end */ \
 length = i; \
 }   \
-- 
2.43.0

___
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".


Re: [FFmpeg-devel] [PATCH 1/2] avdevice: deprecate opengl outdev

2024-02-13 Thread Marton Balint




On Tue, 13 Feb 2024, J. Dekker wrote:


Signed-off-by: J. Dekker 
---

These devices are fundamentally broken and usecases should be switched
away from output devices in general. Discussion in the thread tended towards
deprecation rather than immediate removal to give time for users to figure out
the best alternatives for their usecase.

libavdevice/opengl_enc.c | 10 ++
1 file changed, 10 insertions(+)

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index b2ac6eb16a..0c81ccc1c4 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -224,6 +224,8 @@ typedef struct OpenGLContext {
int picture_height;///< Rendered height
int window_width;
int window_height;
+
+int warned;
} OpenGLContext;

static const struct OpenGLFormatDesc {
@@ -1060,6 +1062,14 @@ static av_cold int opengl_write_header(AVFormatContext 
*h)
AVStream *st;
int ret;

+if (!opengl->warned) {
+av_log(opengl, AV_LOG_WARNING,
+"The opengl output device is deprecated. For monitoring purposes in 
ffmpeg you can output to a file or use pipes and a video player.\n"
+"Example: ffmpeg -i input.mkv -f nut - | ffplay \n"


The example seems wrong. Let's try to provide one which is working and is 
more similar to the old use (does not reencode the video):


-f nut -c:v rawvideo - | ffplay -

Regards,
Marton
___
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".


Re: [FFmpeg-devel] [PATCH 1/4] checkasm/rv34dsp: add rv34_inv_transform_dc test

2024-02-13 Thread flow gg
 it was due to a testing , not MMX. fixed it in this reply.

flow gg  于2024年2月13日周二 10:37写道:

> I sended  "[FFmpeg-devel] [PATCH] x86: Remove MMX assembly
> rv34_inv_transform_dc in rv34dsp"
>
> Rémi Denis-Courmont  于2024年2月13日周二 03:37写道:
>
>> Le perjantaina 2. helmikuuta 2024, 2.47.16 EET flow gg a écrit :
>> > It seems to be caused by movd m0, r1d in libavcodec/x86/rv34dsp.asm? I'm
>> > not quite sure.
>>
>> If it affects only MMX and neither SSE nor AVX, add a patch to remove the
>> offending code altogether.
>>
>> It's ridiculous to hold checkasm tests off because of broken legacy code.
>>
>> --
>> Rémi Denis-Courmont
>> http://www.remlab.net/
>>
>>
>>
>> ___
>> 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".
>>
>
From 0afcf0e6a177b3f0cd90dc4f0eab6f3c35a9d428 Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Wed, 31 Jan 2024 19:00:23 +0800
Subject: [PATCH 1/4] checkasm/rv34dsp: add rv34_inv_transform_dc test

---
 tests/checkasm/Makefile   |  1 +
 tests/checkasm/checkasm.c |  3 ++
 tests/checkasm/checkasm.h |  1 +
 tests/checkasm/rv34dsp.c  | 65 +++
 tests/fate/checkasm.mak   |  1 +
 5 files changed, 71 insertions(+)
 create mode 100644 tests/checkasm/rv34dsp.c

diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile
index 56aba601d3..3947b9ea79 100644
--- a/tests/checkasm/Makefile
+++ b/tests/checkasm/Makefile
@@ -34,6 +34,7 @@ AVCODECOBJS-$(CONFIG_JPEG2000_DECODER)  += jpeg2000dsp.o
 AVCODECOBJS-$(CONFIG_OPUS_DECODER)  += opusdsp.o
 AVCODECOBJS-$(CONFIG_PIXBLOCKDSP)   += pixblockdsp.o
 AVCODECOBJS-$(CONFIG_HEVC_DECODER)  += hevc_add_res.o hevc_deblock.o hevc_idct.o hevc_sao.o hevc_pel.o
+AVCODECOBJS-$(CONFIG_RV34DSP)   += rv34dsp.o
 AVCODECOBJS-$(CONFIG_SVQ1_ENCODER)  += svq1enc.o
 AVCODECOBJS-$(CONFIG_TAK_DECODER)   += takdsp.o
 AVCODECOBJS-$(CONFIG_UTVIDEO_DECODER)   += utvideodsp.o
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index b2f24b051b..ffc04f0623 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -167,6 +167,9 @@ static const struct {
 #if CONFIG_PIXBLOCKDSP
 { "pixblockdsp", checkasm_check_pixblockdsp },
 #endif
+#if CONFIG_RV34DSP
+{ "rv34dsp", checkasm_check_rv34dsp },
+#endif
 #if CONFIG_SVQ1_ENCODER
 { "svq1enc", checkasm_check_svq1enc },
 #endif
diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h
index 92f64a3014..1f31591ac0 100644
--- a/tests/checkasm/checkasm.h
+++ b/tests/checkasm/checkasm.h
@@ -112,6 +112,7 @@ void checkasm_check_nlmeans(void);
 void checkasm_check_opusdsp(void);
 void checkasm_check_pixblockdsp(void);
 void checkasm_check_sbrdsp(void);
+void checkasm_check_rv34dsp(void);
 void checkasm_check_svq1enc(void);
 void checkasm_check_synth_filter(void);
 void checkasm_check_sw_gbrp(void);
diff --git a/tests/checkasm/rv34dsp.c b/tests/checkasm/rv34dsp.c
new file mode 100644
index 00..9f46a54877
--- /dev/null
+++ b/tests/checkasm/rv34dsp.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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 "libavutil/mem.h"
+#include "libavutil/mem_internal.h"
+
+#include "libavcodec/rv34dsp.h"
+
+#include "checkasm.h"
+
+#define BUF_SIZE 1024
+
+#define randomize(buf, len) \
+do { \
+for (int i = 0; i < len; i++) \
+buf[i] = rnd(); \
+} while (0)
+
+static void test_rv34_inv_transform_dc(RV34DSPContext *s) {
+declare_func_emms(AV_CPU_FLAG_MMX, void, int16_t *block);
+
+if (check_func(s->rv34_inv_transform_dc, "rv34_inv_transform_dc")) {
+LOCAL_ALIGNED_16(int16_t, p1, [BUF_SIZE]);
+LOCAL_ALIGNED_16(int16_t, p2, [BUF_SIZE]);
+
+randomize(p1, BUF_SIZE);
+memcpy(p2, p1, BUF_SIZE * sizeof(*p1));
+
+call_ref(p1);
+call_new(p2);
+
+if (memcmp(p1,  p2,  BUF_SIZE * sizeof (*p1)) != 0) {
+fail();
+}
+
+bench_new(p1);
+}
+
+report("rv34_inv_transform_dc");
+}
+
+void 

Re: [FFmpeg-devel] [PATCH] x86: Remove MMX assembly rv34_inv_transform_dc in rv34dsp

2024-02-13 Thread flow gg
I made a mistake. It can be fixed your way. Please ignore this reply.

flow gg  于2024年2月13日周二 17:47写道:

> Thank you for your guidance. Do you mean that it should be modified test
> like this?
>
> - declare_func(void, uint8_t *dst, ptrdiff_t stride, int dc);
> + declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t, int);
>
> I tried to do it this way, but the test still failed. not sure why ...
>
___
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".


Re: [FFmpeg-devel] [PATCH] x86: Remove MMX assembly rv34_inv_transform_dc in rv34dsp

2024-02-13 Thread flow gg
Thank you for your guidance. Do you mean that it should be modified test
like this?

- declare_func(void, uint8_t *dst, ptrdiff_t stride, int dc);
+ declare_func_emms(AV_CPU_FLAG_MMX, void, uint8_t *, ptrdiff_t, int);

I tried to do it this way, but the test still failed. not sure why ...
___
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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] lavf/assenc: normalize line endings to \n

2024-02-13 Thread Anton Khirnov
Quoting Martin Storsjö (2024-02-12 12:31:29)
> On Mon, 12 Feb 2024, Hendrik Leppkes wrote:
> 
> > On Mon, Feb 12, 2024 at 11:22 AM Martin Storsjö  wrote:
> >> >
> >> > diff --git a/.gitattributes b/.gitattributes
> >> > index 5a19b963b6..a900528e47 100644
> >> > --- a/.gitattributes
> >> > +++ b/.gitattributes
> >> > @@ -1,2 +1 @@
> >> > *.pnm -diff -text
> >> > -tests/ref/fate/sub-scc eol=crlf
> >>
> >> This change seems to have had a tricky effect on the
> >> tests/ref/fate/sub-scc file. Previously, when checked out, users got the
> >> file with CRLF newlines. When updating to this git commit, or past it,
> >> that file remains untouched, with CRLF still present, and the
> >> fate-sub-scc test fails. If one does "rm tests/ref/fate/sub-scc; git
> >> checkout tests/ref/fate/sub-scc", then the file does get restored with LR
> >> newlines, and the test passes.
> >>
> >> It's easy to do this change manually in the source checkout of a fate
> >> runner, but I'm not sure how easily we get all fate instances fixed that
> >> way - currently this test is failing in most of them.
> >>
> >
> > Can this be fixed by restoring the .gitattribute entry but with eol=lf?
> > Not sure if Git would reset the file then.
> 
> No, that doesn't seem to make any difference. Not sure if there are any 
> other straightforward/elegant fixes, short of renaming the file, which I 
> guess would require renaming the test itself.

I'm fine with renaming the test, unless anyone has a better fix.

-- 
Anton Khirnov
___
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".


Re: [FFmpeg-devel] [PATCH] x86: Remove MMX assembly rv34_inv_transform_dc in rv34dsp

2024-02-13 Thread Andreas Rheinhardt
flow gg:
> Subject: [PATCH] x86: Remove MMX assembly rv34_inv_transform_dc in rv34dsp
> 
> This asm will cause checkasm to fail.
> ---
>  libavcodec/x86/rv34dsp.asm| 12 
>  libavcodec/x86/rv34dsp_init.c |  2 --

Of course your checkasm test will fail: You used declare_func and not
declare_func_emms for this. Using the latter means "the tested function
is expected to clobber the mmx state"; otherwise clobbering MMX is
considered an error.

- Andreas

___
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".