Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_vpp_qsv: apply 3D LUT from file.

2023-10-22 Thread Chen Yufei
Thanks for your comments.

I'll use MFX_RESOURCE_SYSTEM_SURFACE and send another patch.

While implementing this feature, I noticed that
vpp_set_frame_ext_params is called multiple times.
If using system memory for storing 3D LUT, is it possible the LUT
table copying to gfx memory will occur multiple times?

On Mon, Oct 16, 2023 at 4:05 PM Xiang, Haihao  wrote:
>
> On Sa, 2023-09-23 at 23:36 +0800, Chen Yufei wrote:
> > Usage: "vpp_qsv=lut3d_file="
> >
> > Only enabled with VAAPI because using VASurface to store 3D LUT.
> >
> > Signed-off-by: Chen Yufei 
> > ---
> >  libavfilter/vf_vpp_qsv.c | 241 ++-
> >  1 file changed, 236 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
> > index c07b45fedb..cd913d3c40 100644
> > --- a/libavfilter/vf_vpp_qsv.c
> > +++ b/libavfilter/vf_vpp_qsv.c
> > @@ -23,6 +23,7 @@
> >
> >  #include 
> >
> > +#include "config.h"
> >  #include "config_components.h"
> >
> >  #include "libavutil/opt.h"
> > @@ -37,10 +38,15 @@
> >  #include "internal.h"
> >  #include "avfilter.h"
> >  #include "filters.h"
> > +#include "lut3d.h"
> >
> >  #include "qsvvpp.h"
> >  #include "transpose.h"
> >
> > +#if QSV_ONEVPL && CONFIG_VAAPI
> > +#include 
> > +#endif
>
> VA-API is available on Windows now, however oneVPL can't work with VA-API on
> Windows.
>
> I'd prefer to support MFX_RESOURCE_SYSTEM_SURFACE instead of
> MFX_RESOURCE_VA_SURFACE in FFmpeg because we neend't consider VA-API too much
> for MFX_RESOURCE_SYSTEM_SURFACE. oneVPL should be able to copy data from 
> system
> memory to gfx memory internally.
>
> Thanks
> Haihao
>
>
> > +
> >  #define OFFSET(x) offsetof(VPPContext, x)
> >  #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM)
> >
> > @@ -67,6 +73,10 @@ typedef struct VPPContext{
> >  /** HDR parameters attached on the input frame */
> >  mfxExtMasteringDisplayColourVolume mdcv_conf;
> >  mfxExtContentLightLevelInfo clli_conf;
> > +
> > +/** LUT parameters attached on the input frame */
> > +mfxExtVPP3DLut lut3d_conf;
> > +LUT3DContext lut3d;
> >  #endif
> >
> >  /**
> > @@ -260,6 +270,7 @@ static av_cold int vpp_preinit(AVFilterContext *ctx)
> >
> >  static av_cold int vpp_init(AVFilterContext *ctx)
> >  {
> > +int ret = 0;
> >  VPPContext  *vpp  = ctx->priv;
> >
> >  if (!vpp->output_format_str || !strcmp(vpp->output_format_str, 
> > "same")) {
> > @@ -288,9 +299,9 @@ static av_cold int vpp_init(AVFilterContext *ctx)
> >  STRING_OPTION(color_primaries, color_primaries, AVCOL_PRI_UNSPECIFIED);
> >  STRING_OPTION(color_transfer,  color_transfer,  AVCOL_TRC_UNSPECIFIED);
> >  STRING_OPTION(color_matrix,color_space, AVCOL_SPC_UNSPECIFIED);
> > -
> >  #undef STRING_OPTION
> > -return 0;
> > +
> > +return ret;
> >  }
> >
> >  static int config_input(AVFilterLink *inlink)
> > @@ -388,6 +399,194 @@ static mfxStatus get_mfx_version(const AVFilterContext
> > *ctx, mfxVersion *mfx_ver
> >  return MFXQueryVersion(device_hwctx->session, mfx_version);
> >  }
> >
> > +#if QSV_ONEVPL && CONFIG_VAAPI
> > +static mfxStatus get_va_display(AVFilterContext *ctx, VADisplay 
> > *va_display)
> > +{
> > +VPPContext *vpp = ctx->priv;
> > +QSVVPPContext *qsvvpp = >qsv;
> > +mfxHDL handle;
> > +mfxStatus ret;
> > +
> > +ret = MFXVideoCORE_GetHandle(qsvvpp->session, MFX_HANDLE_VA_DISPLAY,
> > );
> > +if (ret != MFX_ERR_NONE) {
> > +av_log(ctx, AV_LOG_ERROR, "MFXVideoCORE_GetHandle failed, status:
> > %d\n", ret);
> > +*va_display = NULL;
> > +return ret;
> > +}
> > +
> > +*va_display = (VADisplay)handle;
> > +return MFX_ERR_NONE;
> > +}
> > +
> > +// Allocate memory on device and copy 3D LUT table.
> > +// Reference
> > https://spec.oneapi.io/onevpl/2.9.0/programming_guide/VPL_prg_vpp.html#video-processing-3dlut
> > +static int init_3dlut_surface(AVFilterContext *ctx)
> > +{
> > +VPPContext *vpp = ctx->priv;
> > +LUT3DContext *lut3d = >lut3d;
> > +mfxExtVPP3DLut *lut3d_conf = >lut3d_conf;
> > +
> > +VAStatus ret = 0;
> > +VADisplay va_dpy = 0;
> > +VASurfaceID surface_id = 0;
> > +VASurfaceAttrib surface_attrib;
> > +VAImage surface_image;
> > +mfxU16 *surface_u16 = NULL;
> > +mfx3DLutMemoryLayout mem_layout;
> > +mfxMemId mem_id = 0;
> > +
> > +int lut_size = lut3d->lutsize;
> > +int mul_size = 0;
> > +
> > +int r, g, b, lut_idx, sf_idx;
> > +struct rgbvec *s = NULL;
> > +
> > +av_log(ctx, AV_LOG_VERBOSE, "create 3D LUT surface, size: %u.\n",
> > lut_size);
> > +
> > +switch (lut_size) {
> > +case 17:
> > +mul_size = 32;
> > +mem_layout = MFX_3DLUT_MEMORY_LAYOUT_INTEL_17LUT;
> > +break;
> > +case 33:
> > +mul_size = 64;
> > +mem_layout = MFX_3DLUT_MEMORY_LAYOUT_INTEL_33LUT;
> > +break;
> > +case 65:
> > +mul_size = 128;
> > +

Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_lut3d: expose 3D LUT file parse function.

2023-10-22 Thread Chen Yufei
Thanks for reviewing this patch.

Do you mean this should be merged with the change to vf_vpp_qsv file
and send only one patch file?

On Mon, Oct 16, 2023 at 3:51 PM Xiang, Haihao  wrote:
>
> On Sa, 2023-09-23 at 23:36 +0800, Chen Yufei wrote:
> > Signed-off-by: Chen Yufei 
> > ---
> >  libavfilter/Makefile   |   8 +-
> >  libavfilter/lut3d.c| 669 +
> >  libavfilter/lut3d.h|  13 +
> >  libavfilter/vf_lut3d.c | 590 +---
> >  4 files changed, 689 insertions(+), 591 deletions(-)
> >  create mode 100644 libavfilter/lut3d.c
> >
> > diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> > index 2fe0033b21..c1cd797e5c 100644
> > --- a/libavfilter/Makefile
> > +++ b/libavfilter/Makefile
> > @@ -330,7 +330,7 @@ OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   +=
> > f_graphmonitor.o
> >  OBJS-$(CONFIG_GRAYWORLD_FILTER)  += vf_grayworld.o
> >  OBJS-$(CONFIG_GREYEDGE_FILTER)   += vf_colorconstancy.o
> >  OBJS-$(CONFIG_GUIDED_FILTER) += vf_guided.o
> > -OBJS-$(CONFIG_HALDCLUT_FILTER)   += vf_lut3d.o framesync.o
> > +OBJS-$(CONFIG_HALDCLUT_FILTER)   += vf_lut3d.o lut3d.o
> > framesync.o
> >  OBJS-$(CONFIG_HFLIP_FILTER)  += vf_hflip.o
> >  OBJS-$(CONFIG_HFLIP_VULKAN_FILTER)   += vf_flip_vulkan.o vulkan.o
> >  OBJS-$(CONFIG_HISTEQ_FILTER) += vf_histeq.o
> > @@ -367,10 +367,10 @@ OBJS-$(CONFIG_LIMITDIFF_FILTER)  +=
> > vf_limitdiff.o framesync.o
> >  OBJS-$(CONFIG_LIMITER_FILTER)+= vf_limiter.o
> >  OBJS-$(CONFIG_LOOP_FILTER)   += f_loop.o
> >  OBJS-$(CONFIG_LUMAKEY_FILTER)+= vf_lumakey.o
> > -OBJS-$(CONFIG_LUT1D_FILTER)  += vf_lut3d.o
> > +OBJS-$(CONFIG_LUT1D_FILTER)  += vf_lut3d.o lut3d.o
> >  OBJS-$(CONFIG_LUT_FILTER)+= vf_lut.o
> >  OBJS-$(CONFIG_LUT2_FILTER)   += vf_lut2.o framesync.o
> > -OBJS-$(CONFIG_LUT3D_FILTER)  += vf_lut3d.o framesync.o
> > +OBJS-$(CONFIG_LUT3D_FILTER)  += vf_lut3d.o lut3d.o
> > framesync.o
> >  OBJS-$(CONFIG_LUTRGB_FILTER) += vf_lut.o
> >  OBJS-$(CONFIG_LUTYUV_FILTER) += vf_lut.o
> >  OBJS-$(CONFIG_MASKEDCLAMP_FILTER)+= vf_maskedclamp.o 
> > framesync.o
> > @@ -549,7 +549,7 @@ OBJS-$(CONFIG_VIDSTABTRANSFORM_FILTER)   +=
> > vidstabutils.o vf_vidstabtransfo
> >  OBJS-$(CONFIG_VIF_FILTER)+= vf_vif.o framesync.o
> >  OBJS-$(CONFIG_VIGNETTE_FILTER)   += vf_vignette.o
> >  OBJS-$(CONFIG_VMAFMOTION_FILTER) += vf_vmafmotion.o framesync.o
> > -OBJS-$(CONFIG_VPP_QSV_FILTER)+= vf_vpp_qsv.o
> > +OBJS-$(CONFIG_VPP_QSV_FILTER)+= vf_vpp_qsv.o lut3d.o
>
> This should be moved to patch 2/2.
>
> Thanks
> Haihao
>
>
> >  OBJS-$(CONFIG_VSTACK_FILTER) += vf_stack.o framesync.o
> >  OBJS-$(CONFIG_W3FDIF_FILTER) += vf_w3fdif.o
> >  OBJS-$(CONFIG_WAVEFORM_FILTER)   += vf_waveform.o
> > diff --git a/libavfilter/lut3d.c b/libavfilter/lut3d.c
> > new file mode 100644
> > index 00..173979adcc
> > --- /dev/null
> > +++ b/libavfilter/lut3d.c
> > @@ -0,0 +1,669 @@
> > +/*
> > + * Copyright (c) 2013 Clément Bœsch
> > + * Copyright (c) 2018 Paul B Mahol
> > + *
> > + * 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 "lut3d.h"
> > +
> > +#include 
> > +
> > +#include "libavutil/avstring.h"
> > +#include "libavutil/file_open.h"
> > +
> > +#define EXPONENT_MASK 0x7F80
> > +#define MANTISSA_MASK 0x007F
> > +#define SIGN_MASK 0x8000
> > +
> > +static inline float sanitizef(float f)
> > +{
> > +union av_intfloat32 t;
> > +t.f = f;
> > +
> > +if ((t.i & EXPONENT_MASK) == EXPONENT_MASK) {
> > +if ((t.i & MANTISSA_MASK) != 0) {
> > +// NAN
> > +return 0.0f;
> > +} else if (t.i & SIGN_MASK) {
> > +// -INF
> > +return -FLT_MAX;
> > +} else {
> > +// +INF
> > +return FLT_MAX;
> > +}
> > +}
> > +

Re: [FFmpeg-devel] [PATCH 1/9] avcodec/vlc: merge lost 16bit end of array check

2023-10-22 Thread Paul B Mahol
I have no time to review these hacks.

Make sure you do not break >8 bit support in utvideo and magicyuv decoders.
___
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: remove special casing CACHED_BITSTREAM_READER

2023-10-22 Thread Michael Niedermayer
after the vlc multi cleanup patchset today i see no fate failure but i do not 
know
why exactly these special cases where there

Signed-off-by: Michael Niedermayer 
---
 libavcodec/magicyuv.c   | 2 +-
 libavcodec/utvideodec.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 3f6348b531e..4a143cdbbf7 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -122,7 +122,7 @@ static void magicyuv_median_pred16(uint16_t *dst, const 
uint16_t *src1,
 #define READ_PLANE(dst, plane, b, c) \
 { \
 x = 0; \
-for (; CACHED_BITSTREAM_READER && x < width-c && get_bits_left() > 0;) 
{\
+for (; x < width-c && get_bits_left() > 0;) {\
 ret = get_vlc_multi(, (uint8_t *)dst + x * b, multi, \
 vlc, vlc_bits, 3); \
 if (ret <= 0) \
diff --git a/libavcodec/utvideodec.c b/libavcodec/utvideodec.c
index ce5d00f7af7..5697210276f 100644
--- a/libavcodec/utvideodec.c
+++ b/libavcodec/utvideodec.c
@@ -118,7 +118,7 @@ static int build_huff(UtvideoContext *c, const uint8_t 
*src, VLC *vlc,
 { \
 buf = !use_pred ? dest : c->buffer; \
 i = 0; \
-for (; CACHED_BITSTREAM_READER && i < width-end && get_bits_left() > 
0;) {\
+for (; i < width-end && get_bits_left() > 0;) {\
 ret = get_vlc_multi(, (uint8_t *)buf + i * b, multi.table, \
 vlc.table, VLC_BITS, 3); \
 if (ret > 0) \
-- 
2.17.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 9/9] avcodec/vlc: simplify min/maxbits in multi VLC

2023-10-22 Thread Michael Niedermayer
nothing uses maxbits, so its removed
minbits is just the last entry (verified with assert on fate)

This basically reverts 58d9b5caf3d332c6495f9af437158bf45531a05e for the minbits 
computation

Signed-off-by: Michael Niedermayer 
---
 libavcodec/vlc.c | 13 -
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index ceabeba5408..de16424c93d 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -395,7 +395,7 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
  const int is16bit, const int nb_codes, const int 
numbits,
  VLCcode *buf, void *logctx)
 {
-int minbits, maxbits, max;
+int minbits, max;
 unsigned count[VLC_MULTI_MAX_SYMBOLS-1] = { 0, };
 VLC_MULTI_ELEM info = { { 0, }, 0, 0, };
 int count0 = 0;
@@ -407,14 +407,9 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
 }
 }
 
-minbits = 32;
-maxbits = 0;
-
-for (int n = nb_codes - count0; n < nb_codes; n++) {
-minbits = FFMIN(minbits, buf[n].bits);
-maxbits = FFMAX(maxbits, buf[n].bits);
-}
-av_assert0(maxbits <= numbits);
+//This is only correct if count0 > 0 and the table is sorted
+//minbits is not used if count0 == 0 and other parts assume the table is 
sorted too
+minbits = buf[nb_codes - 1].bits;
 
 for (max = nb_codes; max > nb_codes - count0; max--) {
 // We can only add a code that fits with the shortest other code into 
the table
-- 
2.17.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] Revert "avcodec/vlc: fix off by one in limit check for multi"

2023-10-22 Thread Michael Niedermayer
This with the last revert results in a table with additional entries

This reverts commit b23eaf968e375f2d38865d90a788221caead3324.
---
 libavcodec/vlc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 79544006677..ceabeba5408 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -365,7 +365,7 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
is16bit,
 uint32_t code;
 
 sym = buf[i].symbol;
-if (l >= curlimit)
+if (l > curlimit)
 return;
 code = curcode + (buf[i].code >> curlen);
 newlimit = curlimit - l;
-- 
2.17.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 7/9] Revert "avcodec/vlc: add correct upper limit for recursive function"

2023-10-22 Thread Michael Niedermayer
This reverts commit fa20f5cd9e131f22da06ef57bf5aedd87ff51a90.
---
 libavcodec/vlc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 4c96fcddc9b..79544006677 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -432,7 +432,7 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
 }
 
 add_level(table, is16bit, nb_codes, numbits, buf,
-  0, 0, FFMIN(maxbits, numbits), 0, minbits, max, count, info);
+  0, 0, numbits, 0, minbits, max, count, info);
 
 av_log(logctx, AV_LOG_DEBUG, "Joint: %d/%d/%d/%d/%d codes min=%ubits 
max=%u\n",
count[0], count[1], count[2], count[3], count[4], minbits, max);
-- 
2.17.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/9] avcodec/vlc: Remove mysterious jitter loop in multi VLC

2023-10-22 Thread Michael Niedermayer
No difference in my testcase in the tables content

Signed-off-by: Michael Niedermayer 
---
 libavcodec/vlc.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 4adec2da705..4c96fcddc9b 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -360,16 +360,14 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
is16bit,
 {
 int max_symbols = VLC_MULTI_MAX_SYMBOLS >> is16bit;
 for (int i = num-1; i >= max; i--) {
-for (int j = 0; j < 2; j++) {
 int newlimit, sym;
-int t = j ? i-1 : i;
-int l = buf[t].bits;
+int l = buf[i].bits;
 uint32_t code;
 
-sym = buf[t].symbol;
+sym = buf[i].symbol;
 if (l >= curlimit)
 return;
-code = curcode + (buf[t].code >> curlen);
+code = curcode + (buf[i].code >> curlen);
 newlimit = curlimit - l;
 l  += curlen;
 if (is16bit) AV_WN16(info.val+2*curlevel, sym);
@@ -390,7 +388,6 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
is16bit,
   code, l, newlimit, curlevel+1,
   minlen, max, levelcnt, info);
 }
-}
 }
 }
 
-- 
2.17.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 5/9] avcodec/vlc: Pass VLC_MULTI_ELEM directly not by pointer

2023-10-22 Thread Michael Niedermayer
This makes the code more testable as uninitialized fields are 0
and not random values from the last call

Signed-off-by: Michael Niedermayer 
---
 libavcodec/vlc.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 9b7a42f79a3..4adec2da705 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -356,7 +356,7 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
is16bit,
   uint32_t curcode, int curlen,
   int curlimit, int curlevel,
   const int minlen, const int max,
-  unsigned* levelcnt, VLC_MULTI_ELEM *info)
+  unsigned* levelcnt, VLC_MULTI_ELEM info)
 {
 int max_symbols = VLC_MULTI_MAX_SYMBOLS >> is16bit;
 for (int i = num-1; i >= max; i--) {
@@ -372,16 +372,16 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
is16bit,
 code = curcode + (buf[t].code >> curlen);
 newlimit = curlimit - l;
 l  += curlen;
-if (is16bit) AV_WN16(info->val+2*curlevel, sym);
-else info->val[curlevel] = sym&0xFF;
+if (is16bit) AV_WN16(info.val+2*curlevel, sym);
+else info.val[curlevel] = sym&0xFF;
 
 if (curlevel) { // let's not add single entries
 uint32_t val = code >> (32 - numbits);
 uint32_t  nb = val + (1U << (numbits - l));
-info->len = l;
-info->num = curlevel+1;
+info.len = l;
+info.num = curlevel+1;
 for (; val < nb; val++)
-AV_COPY64(table+val, info);
+AV_COPY64(table+val, );
 levelcnt[curlevel-1]++;
 }
 
@@ -435,7 +435,7 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
 }
 
 add_level(table, is16bit, nb_codes, numbits, buf,
-  0, 0, FFMIN(maxbits, numbits), 0, minbits, max, count, );
+  0, 0, FFMIN(maxbits, numbits), 0, minbits, max, count, info);
 
 av_log(logctx, AV_LOG_DEBUG, "Joint: %d/%d/%d/%d/%d codes min=%ubits 
max=%u\n",
count[0], count[1], count[2], count[3], count[4], minbits, max);
-- 
2.17.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/vlc: Replace mysterious max computation code in multi vlc

2023-10-22 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/vlc.c | 13 -
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 65883a506ff..9b7a42f79a3 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -359,7 +359,7 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
is16bit,
   unsigned* levelcnt, VLC_MULTI_ELEM *info)
 {
 int max_symbols = VLC_MULTI_MAX_SYMBOLS >> is16bit;
-for (int i = num-1; i > max; i--) {
+for (int i = num-1; i >= max; i--) {
 for (int j = 0; j < 2; j++) {
 int newlimit, sym;
 int t = j ? i-1 : i;
@@ -398,7 +398,7 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
  const int is16bit, const int nb_codes, const int 
numbits,
  VLCcode *buf, void *logctx)
 {
-int minbits, maxbits, max = nb_codes-1;
+int minbits, maxbits, max;
 unsigned count[VLC_MULTI_MAX_SYMBOLS-1] = { 0, };
 VLC_MULTI_ELEM info = { { 0, }, 0, 0, };
 int count0 = 0;
@@ -419,10 +419,13 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
 }
 av_assert0(maxbits <= numbits);
 
-while (max >= nb_codes/2) {
-if (buf[max].bits+minbits > maxbits)
+for (max = nb_codes; max > nb_codes - count0; max--) {
+// We can only add a code that fits with the shortest other code into 
the table
+// We assume the table is sorted by bits and we skip subtables which 
from our
+// point of view are basically random corrupted entries
+// If we have not a single useable vlc we end with max = nb_codes
+if (buf[max - 1].bits+minbits > numbits)
 break;
-max--;
 }
 
 for (int j = 0; j < 1

[FFmpeg-devel] [PATCH 3/9] avcodec/vlc: Skip subtable entries in multi VLC

2023-10-22 Thread Michael Niedermayer
These entries do not correspond to VLC symbols that can be used
they do corrupt various variables like min/max bits

This also no longer assumes that there is a single non subtable
entry
Probably fixes some infinite loops too

Signed-off-by: Michael Niedermayer 
---
 libavcodec/vlc.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 77860430861..65883a506ff 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -401,15 +401,23 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
 int minbits, maxbits, max = nb_codes-1;
 unsigned count[VLC_MULTI_MAX_SYMBOLS-1] = { 0, };
 VLC_MULTI_ELEM info = { { 0, }, 0, 0, };
+int count0 = 0;
 
-minbits = buf[0].bits;
-maxbits = buf[0].bits;
+for (int j = 0; j < 1 0) {
+count0 ++;
+j += (1 << (numbits - single->table[j].len)) - 1;
+}
+}
+
+minbits = 32;
+maxbits = 0;
 
-for (int n = 1; n < nb_codes; n++) {
+for (int n = nb_codes - count0; n < nb_codes; n++) {
 minbits = FFMIN(minbits, buf[n].bits);
 maxbits = FFMAX(maxbits, buf[n].bits);
 }
-maxbits = FFMIN(maxbits, numbits);
+av_assert0(maxbits <= numbits);
 
 while (max >= nb_codes/2) {
 if (buf[max].bits+minbits > maxbits)
-- 
2.17.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 2/9] avcodec/vlc: dont pass nb_elems into multi vlc code

2023-10-22 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/vlc.c | 11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index 4f62eddf0fb..77860430861 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -350,7 +350,7 @@ fail:
 return AVERROR_INVALIDDATA;
 }
 
-static void add_level(VLC_MULTI_ELEM *table, const int nb_elems,
+static void add_level(VLC_MULTI_ELEM *table, const int is16bit,
   const int num, const int numbits,
   const VLCcode *buf,
   uint32_t curcode, int curlen,
@@ -358,7 +358,6 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
nb_elems,
   const int minlen, const int max,
   unsigned* levelcnt, VLC_MULTI_ELEM *info)
 {
-int is16bit = nb_elems>256;
 int max_symbols = VLC_MULTI_MAX_SYMBOLS >> is16bit;
 for (int i = num-1; i > max; i--) {
 for (int j = 0; j < 2; j++) {
@@ -387,7 +386,7 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
nb_elems,
 }
 
 if (curlevel+1 < max_symbols && newlimit >= minlen) {
-add_level(table, nb_elems, num, numbits, buf,
+add_level(table, is16bit, num, numbits, buf,
   code, l, newlimit, curlevel+1,
   minlen, max, levelcnt, info);
 }
@@ -396,7 +395,7 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
nb_elems,
 }
 
 static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC *single,
- const int nb_elems, const int nb_codes, const int 
numbits,
+ const int is16bit, const int nb_codes, const int 
numbits,
  VLCcode *buf, void *logctx)
 {
 int minbits, maxbits, max = nb_codes-1;
@@ -424,7 +423,7 @@ static int vlc_multi_gen(VLC_MULTI_ELEM *table, const VLC 
*single,
 AV_WN16(table[j].val, single->table[j].sym);
 }
 
-add_level(table, nb_elems, nb_codes, numbits, buf,
+add_level(table, is16bit, nb_codes, numbits, buf,
   0, 0, FFMIN(maxbits, numbits), 0, minbits, max, count, );
 
 av_log(logctx, AV_LOG_DEBUG, "Joint: %d/%d/%d/%d/%d codes min=%ubits 
max=%u\n",
@@ -480,7 +479,7 @@ int ff_vlc_init_multi_from_lengths(VLC *vlc, VLC_MULTI 
*multi, int nb_bits, int
 ret = vlc_common_end(vlc, nb_bits, j, buf, flags, buf);
 if (ret < 0)
 goto fail;
-ret = vlc_multi_gen(multi->table, vlc, nb_elems, j, nb_bits, buf, logctx);
+ret = vlc_multi_gen(multi->table, vlc, nb_elems > 256, j, nb_bits, buf, 
logctx);
 if (buf != localbuf)
 av_free(buf);
 return ret;
-- 
2.17.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/9] avcodec/vlc: merge lost 16bit end of array check

2023-10-22 Thread Michael Niedermayer
Also cleanup related code

Signed-off-by: Michael Niedermayer 
---
 libavcodec/vlc.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
index e4bbf2945e1..4f62eddf0fb 100644
--- a/libavcodec/vlc.c
+++ b/libavcodec/vlc.c
@@ -358,8 +358,8 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
nb_elems,
   const int minlen, const int max,
   unsigned* levelcnt, VLC_MULTI_ELEM *info)
 {
-if (nb_elems > 256 && curlevel > 2)
-return; // No room
+int is16bit = nb_elems>256;
+int max_symbols = VLC_MULTI_MAX_SYMBOLS >> is16bit;
 for (int i = num-1; i > max; i--) {
 for (int j = 0; j < 2; j++) {
 int newlimit, sym;
@@ -373,7 +373,7 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
nb_elems,
 code = curcode + (buf[t].code >> curlen);
 newlimit = curlimit - l;
 l  += curlen;
-if (nb_elems>256) AV_WN16(info->val+2*curlevel, sym);
+if (is16bit) AV_WN16(info->val+2*curlevel, sym);
 else info->val[curlevel] = sym&0xFF;
 
 if (curlevel) { // let's not add single entries
@@ -386,7 +386,7 @@ static void add_level(VLC_MULTI_ELEM *table, const int 
nb_elems,
 levelcnt[curlevel-1]++;
 }
 
-if (curlevel+1 < VLC_MULTI_MAX_SYMBOLS && newlimit >= minlen) {
+if (curlevel+1 < max_symbols && newlimit >= minlen) {
 add_level(table, nb_elems, num, numbits, buf,
   code, l, newlimit, curlevel+1,
   minlen, max, levelcnt, info);
-- 
2.17.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] avcodec/librsvgdec: fix memory leaks and deprecated functions

2023-10-22 Thread Leo Izen

On 10/15/23 08:06, Leo Izen wrote:

On 10/7/23 21:36, Leo Izen wrote:

At various points through the function librsvg_decode_frame, errors are
returned from immediately without deallocating any allocated structs.
This patch both fixes those leaks, and also fixes the use of functions
that are deprecated since librsvg version 2.52.0. The older calls are
still used, guarded by #ifdefs while the newer replacements are used if
librsvg >= 2.52.0. One of the deprecated functions is used as a check
for the configure shell script, so it was replaced with a different
function.

Signed-off-by: Leo Izen 
---


Bumping, thanks.

- Leo Izen (Traneptora)


Pushed as 86ed68420d3b.

- Leo Izen (Traneptora)
___
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] cbs_av1: Reject thirty-two zero bits in uvlc code

2023-10-22 Thread Mark Thompson

The spec allows at least thirty-two zero bits followed by a one to mean
2^32-1, with no constraint on the number of zeroes.  The libaom
reference decoder does not match this, instead reading thirty-two zeroes
but not the following one to mean 2^32-1.  These two interpretations are
incompatible and other implementations may follow one or the other.
Therefore reject thirty-two zeroes because the intended behaviour is not
clear.
---
libaom, dav1d and SVT-AV1 all have the same nonstandard behaviour of stopping 
at thirty-two zeroes and not reading the one.  gav1 just rejects thirty-two 
zeroes.

This is also a source of arbitrarily large single syntax elements to hit 
.

 libavcodec/cbs_av1.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 1d9ac5ab44..13c749a25b 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -36,7 +36,7 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, 
GetBitContext *gbc,
 CBS_TRACE_READ_START();

 zeroes = 0;
-while (1) {
+while (zeroes < 32) {
 if (get_bits_left(gbc) < 1) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid uvlc code at "
"%s: bitstream ended.\n", name);
@@ -49,10 +49,18 @@ static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, 
GetBitContext *gbc,
 }

 if (zeroes >= 32) {
-// Note that the spec allows an arbitrarily large number of
-// zero bits followed by a one bit in this case, but the
-// libaom implementation does not support it.
-value = MAX_UINT_BITS(32);
+// The spec allows at least thirty-two zero bits followed by a
+// one to mean 2^32-1, with no constraint on the number of
+// zeroes.  The libaom reference decoder does not match this,
+// instead reading thirty-two zeroes but not the following one
+// to mean 2^32-1.  These two interpretations are incompatible
+// and other implementations may follow one or the other.
+// Therefore we reject thirty-two zeroes because the intended
+// behaviour is not clear.
+av_log(ctx->log_ctx, AV_LOG_ERROR, "Thirty-two zero bits in "
+   "%s uvlc code: considered invalid due to conflicting "
+   "standard and reference decoder behaviour.\n", name);
+return AVERROR_INVALIDDATA;
 } else {
 if (get_bits_left(gbc) < zeroes) {
 av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid uvlc code at "
--
2.39.2
___
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] MULTI VLC decoding boost

2023-10-22 Thread Michael Niedermayer
On Mon, Aug 28, 2023 at 07:36:17PM +0200, Paul B Mahol wrote:
> Patches attached.
> 
> Thanks for kurosu for pointing unmerged branches.
> 


[...]

> +static void add_level(VLC_MULTI_ELEM *table, const int nb_elems,
> +   const int num, const int numbits,
> +  const VLCcode *buf,
> +  uint32_t curcode, int curlen,
> +  int curlimit, int curlevel,
> +  const int minlen, const int max,
> +  unsigned* levelcnt, VLC_MULTI_ELEM *info)
> +{

> +if (nb_elems > 256 && curlevel > 2)
> +return; // No room

this and


> +for (int i = num-1; i > max; i--) {
> +for (int j = 0; j < 2; j++) {
> +int newlimit, sym;
> +int t = j ? i-1 : i;
> +int l = buf[t].bits;
> +uint32_t code;
> +
> +sym = buf[t].symbol;
> +if (l > curlimit)
> +return;
> +code = curcode + (buf[t].code >> curlen);
> +newlimit = curlimit - l;
> +l  += curlen;
> +if (nb_elems>256) AV_WN16(info->val+2*curlevel, sym);
> +else info->val[curlevel] = sym&0xFF;
> +
> +if (curlevel) { // let's not add single entries
> +uint32_t val = code >> (32 - numbits);
> +uint32_t  nb = val + (1U << (numbits - l));
> +info->len = l;
> +info->num = curlevel+1;
> +for (; val < nb; val++)
> +AV_COPY64(table+val, info);
> +levelcnt[curlevel-1]++;
> +}
> +

> +if (curlevel+1 < VLC_MULTI_MAX_SYMBOLS && newlimit >= minlen) {

this are 2 checks doing the same thing for 8 and 16 bit
what mess is this ?
for 8bit we have VLC_MULTI_MAX_SYMBOLS space (6) in the array so we skip beyond 
that
for 16bit we have VLC_MULTI_MAX_SYMBOLS/2 space which is 3 and the skip instead
is inside add_level() above with hardcoded litteral number
(nb_elems > 256 is a check for if its 8 or 16bit)

why is such totally hacked up code pushed with standing objections and no
review ?

yes, ill fix this one but i have the feeling this code has more surprises


> +add_level(table, nb_elems, num, numbits, buf,
> +  code, l, newlimit, curlevel+1,
> +  minlen, max, levelcnt, info);
> +}
> +}
> +}
> +}

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship: All citizens are under surveillance, all their steps and
actions recorded, for the politicians to enforce control.
Democracy: All politicians are under surveillance, all their steps and
actions recorded, for the citizens to enforce control.


signature.asc
Description: PGP signature
___
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] lavc/aarch64: new optimization for 8-bit hevc_epel_v

2023-10-22 Thread Martin Storsjö

On Sun, 22 Oct 2023, Logan.Lyu wrote:


Hi, Martin,

Could you please review these patches and let me know if there are any 
changes needed.


Did you see the message from Michael on Oct 14th? Your patches have 
corrupted whitespace and can't be applied. Earlier you've submitted some 
patches as attached files, and those have been possible to apply.


Secondly; I just pushed some indentation cleanup for aarch64 assembly 
yesterday. In case there are conflicts with your patches, please rebase 
your patches before attempting to resubmit them, so they apply cleanly.


// 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 3/3] avcodec/magicyuv: remove redundant check in inner loop

2023-10-22 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/magicyuv.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index d813f209203..3f6348b531e 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -125,10 +125,9 @@ static void magicyuv_median_pred16(uint16_t *dst, const 
uint16_t *src1,
 for (; CACHED_BITSTREAM_READER && x < width-c && get_bits_left() > 0;) 
{\
 ret = get_vlc_multi(, (uint8_t *)dst + x * b, multi, \
 vlc, vlc_bits, 3); \
-if (ret > 0) \
-x += ret; \
 if (ret <= 0) \
 return AVERROR_INVALIDDATA; \
+x += ret; \
 } \
 for (; x < width && get_bits_left() > 0; x++) \
 dst[x] = get_vlc2(, vlc, vlc_bits, 3); \
-- 
2.17.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 2/3] avcodec/magicyuv: correct end of array check in multi VLC parsing

2023-10-22 Thread Michael Niedermayer
Fixes: out of array write
Fixes: 
63390/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MAGICYUV_fuzzer-5144552979431424.fuzz

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
 libavcodec/magicyuv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
index 3573db0f0ad..d813f209203 100644
--- a/libavcodec/magicyuv.c
+++ b/libavcodec/magicyuv.c
@@ -299,7 +299,7 @@ static int magy_decode_slice(AVCodecContext *avctx, void 
*tdata,
 return ret;
 
 for (k = 0; k < height; k++)
-READ_PLANE(dst, i, 1, 5)
+READ_PLANE(dst, i, 1, 7)
 }
 
 switch (pred) {
-- 
2.17.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/3] avcodec/bitstream_template: Basic documentation for read_vlc_multi()

2023-10-22 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavcodec/bitstream_template.h | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavcodec/bitstream_template.h b/libavcodec/bitstream_template.h
index cf4aeff4feb..4f3d07275fb 100644
--- a/libavcodec/bitstream_template.h
+++ b/libavcodec/bitstream_template.h
@@ -520,7 +520,20 @@ static inline int BS_FUNC(read_vlc)(BSCTX *bc, const 
VLCElem *table,
 return code;
 }
 
-static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t *dst,
+/**
+ * Parse a vlc / vlc_multi code.
+ * @param bits is the number of bits which will be read at once, must be
+ * identical to nb_bits in vlc_init()
+ * @param max_depth is the number of times bits bits must be read to completely
+ *  read the longest vlc code
+ *  = (max_vlc_length + bits - 1) / bits
+ * @param dst the parsed symbol(s) will be stored here. Up to 8 bytes are 
written
+ * @returns number of symbols parsed
+ * If the vlc code is invalid and max_depth=1, then no bits will be removed.
+ * If the vlc code is invalid and max_depth>1, then the number of bits removed
+ * is undefined.
+ */
+static inline int BS_FUNC(read_vlc_multi)(BSCTX *bc, uint8_t dst[8],
   const VLC_MULTI_ELEM *const Jtable,
   const VLCElem *const table,
   const int bits, const int max_depth)
-- 
2.17.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] avcodec/magicyuv: add vlc multi support

2023-10-22 Thread Michael Niedermayer
On Sun, Oct 22, 2023 at 11:21:28AM +0200, Paul B Mahol wrote:
> On Sun, Oct 22, 2023 at 9:06 AM Michael Niedermayer 
> wrote:
> 
> > On Sun, Oct 22, 2023 at 12:56:40AM +0200, Michael Niedermayer wrote:
> > > On Sat, Oct 21, 2023 at 11:00:19AM +0200, Paul B Mahol wrote:
> > > > On Sat, Oct 21, 2023 at 2:13 AM Michael Niedermayer <
> > mich...@niedermayer.cc>
> > > > wrote:
> > > >
> 
> 
> You have enough skills to fix this,

Of course and i care about the projects security and our users.

will post a fix for this shortly

thx

[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"Nothing to hide" only works if the folks in power share the values of
you and everyone you know entirely and always will -- Tom Scott



signature.asc
Description: PGP signature
___
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] libavcodec/amfenc: Add more pixel formats support

2023-10-22 Thread Mark Thompson

On 20/10/2023 09:13, Evgeny Pavlov wrote:

On Tue, Jul 18, 2023 at 10:32 AM Evgeny Pavlov  wrote:


This commit adds BGRA, RGBA and ARGB pixel formats for AMF encoders

Signed-off-by: Evgeny Pavlov 
---
  libavcodec/amfenc.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c
index cb48f8c273..234cd012ef 100644
--- a/libavcodec/amfenc.c
+++ b/libavcodec/amfenc.c
@@ -74,6 +74,9 @@ static const FormatMap format_map[] =
  { 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_RGBA,   AMF_SURFACE_RGBA },
+{ AV_PIX_FMT_ARGB,   AMF_SURFACE_ARGB },
  { AV_PIX_FMT_GRAY8,  AMF_SURFACE_GRAY8 },
  { AV_PIX_FMT_YUV420P,AMF_SURFACE_YUV420P },
  { AV_PIX_FMT_YUYV422,AMF_SURFACE_YUY2 },
--
2.37.3.windows.1

The purpose of this patch is to fix an issue with feeding ddagrab output

to AMF directly. The output of ddagrab might be BGRA, AMF supports this
input, but failed to encode due to missing mapping from AV_PIX_BGRA to
AMF_SURFACE_BGRA in amfenc.c
DXGI isn't firm to distinguish between RGBA & RGBX, so it is safer to
support both to avoid failures like with ddagrab.


See patch just sent to fix the bug in ddagrab that it incorrectly advertises an 
alpha channel.

Do you have ddagrab->amfenc working with just something to fix the alpha 
channel?  To make it work I also need to mess with the bind flags because amfenc 
wants to use the textures as shader resources.

This has been noted as a problem before, where a proper fix would require large changes 
in the format negotiation setup and so it hasn't been done.  I'm wondering whether adding 
"-bind_flags shader_resource" option to ddagrab would be a plausible hack for 
these cases, or whether that's a bit too obscure for an actual user?

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 2/2] lavfi/ddagrab: Fix 8-bit BGR output to not advertise an alpha component

2023-10-22 Thread Mark Thompson

There is never an alpha component here, so the actual format is BGR0
rather than BGRA.  This fixes cases which maintain the alpha component
and therefore generate unexpected results.
---
E.g. fixes download and encode with PNG to make an RGB PNG as expected, rather 
than an RGBA PNG with nothing in the alpha channel.  (Previously this was 
relying on the user to realise that the alpha channel contained nothing and 
ignore it.)

 doc/filters.texi   | 2 +-
 libavfilter/vsrc_ddagrab.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f5032ddf74..550f9a6ecc 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -28183,7 +28183,7 @@ It accepts the following values:
 @item auto
 Passes all supported output formats to DDA and returns what DDA decides to use.
 @item 8bit
-@item bgra
+@item bgrx
 8 Bit formats always work, and DDA will convert to them if neccesary.
 @item 10bit
 @item x2bgr10
diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
index 9c59faf53e..8ff3c97959 100644
--- a/libavfilter/vsrc_ddagrab.c
+++ b/libavfilter/vsrc_ddagrab.c
@@ -115,14 +115,14 @@ static const AVOption ddagrab_options[] = {
 { "output_fmt", "desired output format",   OFFSET(out_fmt),AV_OPT_TYPE_INT,  
  { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM },0, INT_MAX, FLAGS, "output_fmt" },
 { "auto",   "let dda pick its preferred format", 0,
AV_OPT_TYPE_CONST,  { .i64 = 0 }, 0, INT_MAX, FLAGS, "output_fmt" },
 { "8bit",   "only output default 8 Bit format",  0,
AV_OPT_TYPE_CONST,  { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM },0, INT_MAX, FLAGS, "output_fmt" },
-{ "bgra",   "only output 8 Bit BGRA",0,
AV_OPT_TYPE_CONST,  { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM },0, INT_MAX, FLAGS, "output_fmt" },
+{ "bgrx",   "only output 8 Bit BGRX",0,
AV_OPT_TYPE_CONST,  { .i64 = DXGI_FORMAT_B8G8R8A8_UNORM },0, INT_MAX, FLAGS, "output_fmt" },
 { "10bit",  "only output default 10 Bit format", 0,
AV_OPT_TYPE_CONST,  { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
 { "x2bgr10","only output 10 Bit X2BGR10",0,
AV_OPT_TYPE_CONST,  { .i64 = DXGI_FORMAT_R10G10B10A2_UNORM }, 0, INT_MAX, FLAGS, "output_fmt" },
 { "16bit",  "only output default 16 Bit format", 0,
AV_OPT_TYPE_CONST,  { .i64 = DXGI_FORMAT_R16G16B16A16_FLOAT },0, INT_MAX, FLAGS, "output_fmt" },
 { "rgbaf16","only output 16 Bit RGBAF16",0,
AV_OPT_TYPE_CONST,  { .i64 = DXGI_FORMAT_R16G16B16A16_FLOAT },0, INT_MAX, FLAGS, "output_fmt" },
 { "allow_fallback", "don't error on fallback to default 8 Bit format",
OFFSET(allow_fallback), 
AV_OPT_TYPE_BOOL,   { .i64 = 0},   0,   1, FLAGS },
-{ "force_fmt",  "exclude BGRA from format list (experimental, discouraged by 
Microsoft)",
+{ "force_fmt",  "exclude BGRX from format list (experimental, discouraged by 
Microsoft)",
OFFSET(force_fmt),  
AV_OPT_TYPE_BOOL,   { .i64 = 0},   0,   1, FLAGS },
 { NULL }
 };
@@ -775,7 +775,7 @@ static av_cold int init_hwframes_ctx(AVFilterContext *avctx)
 switch (dda->raw_format) {
 case DXGI_FORMAT_B8G8R8A8_UNORM:
 av_log(avctx, AV_LOG_VERBOSE, "Probed 8 bit RGB frame format\n");
-dda->frames_ctx->sw_format = AV_PIX_FMT_BGRA;
+dda->frames_ctx->sw_format = AV_PIX_FMT_BGR0;
 break;
 case DXGI_FORMAT_R10G10B10A2_UNORM:
 av_log(avctx, AV_LOG_VERBOSE, "Probed 10 bit RGB frame format\n");
--
2.39.2
___
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/2] hwcontext_d3d11: Add BGR0 support

2023-10-22 Thread Mark Thompson

The 8-bit four-component DXGI container is also used for three-component
RGB without alpha.
---
This list is only used for AV->DXGI mapping, so it doesn't matter that there 
are duplicate DXGI formats in the list.

 libavutil/hwcontext_d3d11va.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index cc8c97d2b6..1d249f2088 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -86,6 +86,7 @@ static const struct {
 } supported_formats[] = {
 { DXGI_FORMAT_NV12, AV_PIX_FMT_NV12 },
 { DXGI_FORMAT_P010, AV_PIX_FMT_P010 },
+{ DXGI_FORMAT_B8G8R8A8_UNORM,AV_PIX_FMT_BGR0 },
 { DXGI_FORMAT_B8G8R8A8_UNORM,AV_PIX_FMT_BGRA },
 { DXGI_FORMAT_R10G10B10A2_UNORM, AV_PIX_FMT_X2BGR10 },
 { DXGI_FORMAT_R16G16B16A16_FLOAT, AV_PIX_FMT_RGBAF16 },
--
2.39.2
___
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/6] avcodec/cbs: Do not assert on traces beyond 255 bits

2023-10-22 Thread Mark Thompson

On 22/10/2023 01:35, Michael Niedermayer wrote:

Fixes: Assertion length < 256 failed at libavcodec/cbs.c:517
Fixes: 
62673/clusterfuzz-testcase-minimized-ffmpeg_BSF_TRACE_HEADERS_fuzzer-6490971837431808

Found-by: continuous fuzzing process 
https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer 
---
  libavcodec/cbs.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index cdd7adebebd..2f5d0334a2a 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -514,6 +514,11 @@ void ff_cbs_trace_read_log(void *trace_context,
  
  position = get_bits_count(gbc);
  
+if (length >= 256) {

+av_log(ctx->log_ctx, ctx->trace_level, "trace of %d bits truncated at 
255\n", length);
+length = 255;
+}
+
  av_assert0(length < 256);
  for (i = 0; i < length; i++)
  bits[i] = get_bits1(gbc) ? '1' : '0';


IMO the assert is sensible (no syntax element is that large) and so this must 
be catching a bug somewhere else.  Please don't nullify the assert to hide the 
bug.

Can you share the input stream which hit this case?

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] amfenc: Use a blocking call instead of sleeping and polling

2023-10-22 Thread Mark Thompson

On 19/10/2023 17:13, Evgeny Pavlov wrote:

On Wed, Oct 18, 2023 at 10:36 PM Mark Thompson  wrote:


---
On 17/10/2023 18:11, Evgeny Pavlov wrote:

The reason for using av_usleep() here is that AMF API doesn’t provide an
API for explicit wait. There are two modes to get output from encoder:

1. Polling with some sleep to avoid CPU thrashing – currently used in

FFmpeg


2. Set timeout parameter on AMF encoder and QueryOutput call will block
till output is available or the timeout happens.

#2 is the preferable way but it is designed more to be used with a

separate

polling thread. With a single-thread approach in FFmpeg, the use of

timeout

can block input submission making things slower.  This is even more
pronounced when B-frames are enabled and several inputs are needed to

produce

the first output.


This approach seems like it should work here?  Run non-blocking until the
queue is full, then switch to blocking when you need to wait for some
output.

I tried the patch enclosing (H.264 only, different proprties needed for
other codecs), but it doesn't seem to work - the test assert always hits
immediately and timing shows that QueryOutput didn't block even though the
timeout should be set?  I'm probably doing something incorrect, maybe you
would know how to fix it.


The condition of this sleep is in special events (primarily when amf

input

queue is full), not the core loop part. During the experiments the cpu
increasing is about 2-4% or so, not a burst.


What cases are you experimenting with?

The most problematic case I can think of is multiple encodes running
simultaneously sharing the same instance so that each one has to wait for
others to complete and therefore all queues fill up.

The busy wait will end up being the only place where it can block (since
everything else runs asynchronously), so you will peg one CPU at close to
100% per encode running.

Thanks,

- Mark

   libavcodec/amfenc.c | 22 +++---
   libavcodec/amfenc.h |  1 +
   2 files changed, 20 insertions(+), 3 deletions(-)

...


Dynamic switching between non-blocking & blocking approaches isn’t
supported in AMF at this time.

We might request to implement this feature for AMF team, but it might took
some time to implement this.


That is unfortunate, but it sounds like something like this is required.


I would suggest using av_usleep(500) until this feature is implemented.


What cases are you experimenting with?


This issue is very easy to reproduce when:

1) low resolution transcoding

2) hardware accelerated decoding

The command line sample:  ffmpeg -hwaccel d3d11va -hwaccel_output_format
d3d11 -i input_480x360_h264.mp4 -c:v hevc_amf  output_480x360_hevc.mp4


To clarify, I meant: what cases are you experimenting with to verify that this 
doesn't cause problems elsewhere?

I agree (and can reproduce) that the specific case with one low-resolution 
stream slightly improves throughput at the cost of increased CPU use.

>> The most problematic case I can think of is multiple encodes running
>> simultaneously sharing the same instance so that each one has to wait for
>> others to complete and therefore all queues fill up.
>>
>> The busy wait will end up being the only place where it can block (since
>> everything else runs asynchronously), so you will peg one CPU at close to
>> 100% per encode running.

I tried this case with two 4K streams and indeed it is a huge regression.  CPU 
use goes from 1-2% of one core for both streams to spinning on two cores, 
around a 100x increase.

Total throughput also decreased by about 10% in my testing, though since I'm 
running on a low-power device that might be an artefact of the CPU spinning 
wasting so much power that other clocks are reduced.

(My test was two instances of

$ ./ffmpeg_g.exe -extra_hw_frames 100 -hwaccel d3d11va -hwaccel_output_format 
d3d11 -i input-4k.mp4 -an -vf loop=loop=20:size=100:start=0 -c:v h264_amf -f 
null -

running simulataneously, looking at the steady state in the loop after the 
first hundred frames with the decoder are complete.)

Please consider this patch rejected in its current form.  IMO this is a hole in 
the AMF API and it needs to be improved to be able to wait for operations to 
complete rather than polling in the user code.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


Re: [FFmpeg-devel] [PATCH] lavc/webp: Remove frame threading

2023-10-22 Thread Andreas Rheinhardt
Thilo Borgmann via ffmpeg-devel:
> Revealed by the patch to support animated webp, the current
> frame threading implementation contains a data race.

No, it doesn't: The current implementation does not call
ff_thread_finish_setup() in vp8.c for webp:

if (ffcodec(avctx->codec)->update_thread_context)
ff_thread_finish_setup(avctx);

It seems that "the patch to support animated webp" (what patch are we
talking about?) adds an update_thread_context to the webp decoder,
thereby changing things and adding the data race.

> vp8_lossy_decode_frame() calls ff_vp8_decode_frame() wich
> calls ff_thread_finish_setup() to sync its internal slice threading.

Nonsense: ff_thread_finish_setup() is only for frame-threading.

> The race is happens because vp8_lossy_decode_frame() has to touch
> the AVCodecContext after it was passed to ff_vp8_decode_frame() and
> ff_thread_finish_setup() had been called.
> 
> Therefore remove frame threading in webp and rely on slice threading
> in VP8 only.

Also nonsense: The webp decoder does not support slice threading, so the
internal VP8 decoder won't ever use it (even though it supports it).

I am a bit confused here: On the one hand,
https://developers.google.com/speed/webp/docs/riff_container says that
it only uses VP8 key frame encoding; on the other hand, it has this
animation feature. Does this also only use VP8-intra coding (i.e. is the
non-intra part of animation just the blending of earlier frames?)? If it
does, then the webp decoder should be separated from the VP8 decoder
(i.e. it should use it according to the public API) and the sub-decoder
should only be used in single-threaded mode.

IMO removing frame-threading for ordinary WebP due to animated WebP is
unacceptable.

> ---
>  libavcodec/webp.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/libavcodec/webp.c b/libavcodec/webp.c
> index 54b3fde6dc..cde91aa7bb 100644
> --- a/libavcodec/webp.c
> +++ b/libavcodec/webp.c
> @@ -49,7 +49,6 @@
>  #include "decode.h"
>  #include "exif.h"
>  #include "get_bits.h"
> -#include "thread.h"
>  #include "tiff_common.h"
>  #include "vp8.h"
>  
> @@ -570,7 +569,7 @@ static int decode_entropy_coded_image(WebPContext *s, 
> enum ImageRole role,
>  img->frame->height = h;
>  
>  if (role == IMAGE_ROLE_ARGB && !img->is_alpha_primary) {
> -ret = ff_thread_get_buffer(s->avctx, img->frame, 0);
> +ret = ff_get_buffer(s->avctx, img->frame, 0);
>  } else
>  ret = av_frame_get_buffer(img->frame, 1);
>  if (ret < 0)
> @@ -1564,6 +1563,6 @@ const FFCodec ff_webp_decoder = {
>  .init   = webp_decode_init,
>  FF_CODEC_DECODE_CB(webp_decode_frame),
>  .close  = webp_decode_close,
> -.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
> +.p.capabilities = AV_CODEC_CAP_DR1,
>  .caps_internal  = FF_CODEC_CAP_ICC_PROFILES,
>  };


___
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/3] avcodec/rv60: RealVideo 6.0 decoder

2023-10-22 Thread Andreas Rheinhardt
Peter Ross:
> ---
> diff --git a/libavformat/matroska.c b/libavformat/matroska.c
> index 5878594e68..1674806f29 100644
> --- a/libavformat/matroska.c
> +++ b/libavformat/matroska.c
> @@ -95,6 +95,7 @@ const CodecTags ff_mkv_codec_tags[]={
>  {"V_REAL/RV20"  , AV_CODEC_ID_RV20},
>  {"V_REAL/RV30"  , AV_CODEC_ID_RV30},
>  {"V_REAL/RV40"  , AV_CODEC_ID_RV40},
> +{"V_REAL/RV60"  , AV_CODEC_ID_RV60},

I don't see the Matroska codec mapping for this.

>  {"V_SNOW"   , AV_CODEC_ID_SNOW},
>  {"V_THEORA" , AV_CODEC_ID_THEORA},
>  {"V_UNCOMPRESSED"   , AV_CODEC_ID_RAWVIDEO},

- 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 1/4] lavc/aarch64: new optimization for 8-bit hevc_epel_v

2023-10-22 Thread Logan.Lyu

Hi, Martin,

Could you please review these patches and let me know if there are any 
changes needed.


Thanks.


Logan Lyu

在 2023/10/14 16:45, Logan.Lyu 写道:

checkasm bench:
put_hevc_epel_v4_8_c: 79.9
put_hevc_epel_v4_8_neon: 25.7
put_hevc_epel_v6_8_c: 151.4
put_hevc_epel_v6_8_neon: 46.4
put_hevc_epel_v8_8_c: 250.9
put_hevc_epel_v8_8_neon: 41.7
put_hevc_epel_v12_8_c: 542.7
put_hevc_epel_v12_8_neon: 108.7
put_hevc_epel_v16_8_c: 939.4
put_hevc_epel_v16_8_neon: 169.2
put_hevc_epel_v24_8_c: 2104.9
put_hevc_epel_v24_8_neon: 307.9
put_hevc_epel_v32_8_c: 3713.9
put_hevc_epel_v32_8_neon: 524.2
put_hevc_epel_v48_8_c: 8175.2
put_hevc_epel_v48_8_neon: 1197.2
put_hevc_epel_v64_8_c: 16049.4
put_hevc_epel_v64_8_neon: 2094.9

Co-Authored-By: J. Dekker 
Signed-off-by: Logan Lyu 
---
 libavcodec/aarch64/hevcdsp_epel_neon.S    | 223 ++
 libavcodec/aarch64/hevcdsp_init_aarch64.c |   5 +
 2 files changed, 228 insertions(+)

diff --git a/libavcodec/aarch64/hevcdsp_epel_neon.S 
b/libavcodec/aarch64/hevcdsp_epel_neon.S

index b4ca1e4c20..e541db5430 100644
--- a/libavcodec/aarch64/hevcdsp_epel_neon.S
+++ b/libavcodec/aarch64/hevcdsp_epel_neon.S
@@ -243,6 +243,229 @@ function ff_hevc_put_hevc_pel_pixels64_8_neon, 
export=1

 ret
 endfunc
 +
+function ff_hevc_put_hevc_epel_v4_8_neon, export=1
+    load_epel_filterb x5, x4
+    sub x1, x1, x2
+    mov x10, #(MAX_PB_SIZE * 2)
+    ldr s16, [x1]
+    ldr s17, [x1 ,x2]
+    add x1, x1, x2, lsl #1
+    ld1 {v18.s}[0], [x1], x2
+.macro calc src0, src1, src2, src3
+    ld1 {\src3\().s}[0], [x1], x2
+    movi    v4.8h, #0
+    calc_epelb  v4, \src0, \src1, \src2, \src3
+    subs    w3, w3, #1
+    st1 {v4.4h}, [x0], x10
+.endm
+1:  calc_all4
+.purgem calc
+2:  ret
+endfunc
+
+function ff_hevc_put_hevc_epel_v6_8_neon, export=1
+    load_epel_filterb x5, x4
+    sub x1, x1, x2
+    mov x10, #(MAX_PB_SIZE * 2 - 8)
+    ldr d16, [x1]
+    ldr d17, [x1, x2]
+    add x1, x1, x2, lsl #1
+    ld1 {v18.8b}, [x1], x2
+.macro calc src0, src1, src2, src3
+    ld1 {\src3\().8b}, [x1], x2
+    movi    v4.8h, #0
+    calc_epelb  v4, \src0, \src1, \src2, \src3
+    st1 {v4.d}[0], [x0], #8
+    subs    w3, w3, #1
+    st1 {v4.s}[2], [x0], x10
+.endm
+1:  calc_all4
+.purgem calc
+2:  ret
+endfunc
+
+function ff_hevc_put_hevc_epel_v8_8_neon, export=1
+    load_epel_filterb x5, x4
+    sub x1, x1, x2
+    mov x10, #(MAX_PB_SIZE * 2)
+    ldr d16, [x1]
+    ldr d17, [x1, x2]
+    add x1, x1, x2, lsl #1
+    ld1 {v18.8b}, [x1], x2
+.macro calc src0, src1, src2, src3
+    ld1 {\src3\().8b}, [x1], x2
+    movi    v4.8h, #0
+    calc_epelb  v4, \src0, \src1, \src2, \src3
+    subs    w3, w3, #1
+    st1 {v4.8h}, [x0], x10
+.endm
+1:  calc_all4
+.purgem calc
+2:  ret
+endfunc
+
+function ff_hevc_put_hevc_epel_v12_8_neon, export=1
+    load_epel_filterb x5, x4
+    sub x1, x1, x2
+    mov x10, #(MAX_PB_SIZE * 2)
+    ldr q16, [x1]
+    ldr q17, [x1, x2]
+    add x1, x1, x2, lsl #1
+    ld1 {v18.16b}, [x1], x2
+.macro calc src0, src1, src2, src3
+    ld1 {\src3\().16b}, [x1], x2
+    movi    v4.8h, #0
+    movi    v5.8h, #0
+    calc_epelb  v4, \src0, \src1, \src2, \src3
+    calc_epelb2 v5, \src0, \src1, \src2, \src3
+    str q4, [x0]
+    subs    w3, w3, #1
+    str d5, [x0, #16]
+    add x0, x0, x10
+.endm
+1:  calc_all4
+.purgem calc
+2:  ret
+endfunc
+
+function ff_hevc_put_hevc_epel_v16_8_neon, export=1
+    load_epel_filterb x5, x4
+    sub x1, x1, x2
+    mov x10, #(MAX_PB_SIZE * 2)
+    ldr q16, [x1]
+    ldr q17, [x1, x2]
+    add x1, x1, x2, lsl #1
+    ld1 {v18.16b}, [x1], x2
+.macro calc src0, src1, src2, src3
+    ld1    {\src3\().16b}, [x1], x2
+    movi    v4.8h, #0
+    movi    v5.8h, #0
+    calc_epelb  v4, \src0, \src1, \src2, \src3
+    calc_epelb2 v5, \src0, \src1, \src2, \src3
+    subs    w3, w3, #1
+    st1 {v4.8h, v5.8h}, [x0], x10
+.endm
+1:  calc_all4
+.purgem calc
+2:  ret
+endfunc
+
+function ff_hevc_put_hevc_epel_v24_8_neon, export=1
+    load_epel_filterb x5, x4
+    sub x1, x1, x2
+    mov x10, 

Re: [FFmpeg-devel] [PATCH] avcodec/cbs_h266: fix SPS VUI extension data leak

2023-10-22 Thread Andreas Rheinhardt
Nuo Mi:
> Fixes: VUI extension leak
> Fixes: 
> 63004/clusterfuzz-testcase-minimized-ffmpeg_BSF_VVC_METADATA_fuzzer-4928832253329408
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> ---
>  libavcodec/cbs_h2645.c | 10 +-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 470f60b95f..ef631a11fe 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1979,6 +1979,13 @@ static const CodedBitstreamUnitTypeDescriptor 
> cbs_h265_unit_types[] = {
>  CBS_UNIT_TYPE_END_OF_LIST
>  };
>  
> +static void cbs_h266_free_sps(FFRefStructOpaque unused, void *content)
> +{
> +H266RawSPS *sps = (H266RawSPS*)content;
> +av_buffer_unref(>extension_data.data_ref);
> +av_buffer_unref(>vui.extension_data.data_ref);
> +}
> +
>  static void cbs_h266_free_sei(FFRefStructOpaque unused, void *content)
>  {
>  H266RawSEI *sei = content;
> @@ -1989,7 +1996,6 @@ static const CodedBitstreamUnitTypeDescriptor 
> cbs_h266_unit_types[] = {
>  CBS_UNIT_TYPE_INTERNAL_REF(VVC_DCI_NUT, H266RawDCI, extension_data.data),
>  CBS_UNIT_TYPE_INTERNAL_REF(VVC_OPI_NUT, H266RawOPI, extension_data.data),
>  CBS_UNIT_TYPE_INTERNAL_REF(VVC_VPS_NUT, H266RawVPS, extension_data.data),
> -CBS_UNIT_TYPE_INTERNAL_REF(VVC_SPS_NUT, H266RawSPS, extension_data.data),
>  CBS_UNIT_TYPE_INTERNAL_REF(VVC_PPS_NUT, H266RawPPS, extension_data.data),
>  CBS_UNIT_TYPE_INTERNAL_REF(VVC_PREFIX_APS_NUT, H266RawAPS, 
> extension_data.data),
>  CBS_UNIT_TYPE_INTERNAL_REF(VVC_SUFFIX_APS_NUT, H266RawAPS, 
> extension_data.data),
> @@ -2003,6 +2009,8 @@ static const CodedBitstreamUnitTypeDescriptor 
> cbs_h266_unit_types[] = {
>  CBS_UNIT_RANGE_INTERNAL_REF(VVC_IDR_W_RADL, VVC_GDR_NUT,
>  H266RawSlice, data),
>  
> +CBS_UNIT_TYPE_COMPLEX(VVC_SPS_NUT, H266RawSPS, cbs_h266_free_sps),
> +
>  CBS_UNIT_TYPES_COMPLEX((VVC_PREFIX_SEI_NUT, VVC_SUFFIX_SEI_NUT),
> H266RawSEI, cbs_h266_free_sei),
>  

This should be a CBS_UNIT_TYPE_INTERNAL_REF().

- 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] lavc/webp: Remove frame threading

2023-10-22 Thread Thilo Borgmann via ffmpeg-devel
Revealed by the patch to support animated webp, the current
frame threading implementation contains a data race.
vp8_lossy_decode_frame() calls ff_vp8_decode_frame() wich
calls ff_thread_finish_setup() to sync its internal slice threading.
The race is happens because vp8_lossy_decode_frame() has to touch
the AVCodecContext after it was passed to ff_vp8_decode_frame() and
ff_thread_finish_setup() had been called.

Therefore remove frame threading in webp and rely on slice threading
in VP8 only.
---
 libavcodec/webp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index 54b3fde6dc..cde91aa7bb 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -49,7 +49,6 @@
 #include "decode.h"
 #include "exif.h"
 #include "get_bits.h"
-#include "thread.h"
 #include "tiff_common.h"
 #include "vp8.h"
 
@@ -570,7 +569,7 @@ static int decode_entropy_coded_image(WebPContext *s, enum 
ImageRole role,
 img->frame->height = h;
 
 if (role == IMAGE_ROLE_ARGB && !img->is_alpha_primary) {
-ret = ff_thread_get_buffer(s->avctx, img->frame, 0);
+ret = ff_get_buffer(s->avctx, img->frame, 0);
 } else
 ret = av_frame_get_buffer(img->frame, 1);
 if (ret < 0)
@@ -1564,6 +1563,6 @@ const FFCodec ff_webp_decoder = {
 .init   = webp_decode_init,
 FF_CODEC_DECODE_CB(webp_decode_frame),
 .close  = webp_decode_close,
-.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
+.p.capabilities = AV_CODEC_CAP_DR1,
 .caps_internal  = FF_CODEC_CAP_ICC_PROFILES,
 };
-- 
2.37.1 (Apple Git-137.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] avfilter/vidstab: add option for file format specification

2023-10-22 Thread Gyan Doshi



On 2023-10-22 05:36 pm, Timo Rothenpieler wrote:

On 22.10.2023 13:57, Gyan Doshi wrote:



On 2023-10-22 05:04 pm, Timo Rothenpieler wrote:

On 22.10.2023 13:24, Gyan Doshi wrote:

The vidstab library added support in Nov 2020 for writing/reading
the transforms data in binary in addition to ASCII. The library 
default

was changed to binary format but no changes were made to the AVfilters
resulting in data file for writing or reading being always opened 
as text.

This effectively broke the filters.

Options added to vidstab{detect,transform} to specify file format
and open files with the correct attributes.
---
  doc/filters.texi  | 26 ++
  libavfilter/vf_vidstabdetect.c    | 15 ++-
  libavfilter/vf_vidstabtransform.c | 15 ++-
  3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f5032ddf74..806448f063 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -24618,6 +24618,19 @@ If set to 0, it is disabled. The frames 
are counted starting from 1.

  Show fields and transforms in the resulting frames. It accepts an
  integer in the range 0-2. Default value is 0, which disables any
  visualization.
+
+@item fileformat
+Format for the transforms data file to be written.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format, roughly 40% smaller than @code{ascii}. 
(@emph{default})

+@end table
+
  @end table
    @subsection Examples
@@ -24772,6 +24785,19 @@ Use also @code{tripod} option of 
@ref{vidstabdetect}.

  Increase log verbosity if set to 1. Also the detected global motions
  are written to the temporary file @file{global_motions.trf}. Default
  value is 0.
+
+@item fileformat
+Format of the transforms data file to be read.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format (@emph{default})
+@end table
+
  @end table
    @subsection Examples
diff --git a/libavfilter/vf_vidstabdetect.c 
b/libavfilter/vf_vidstabdetect.c

index a2c6d89503..aa050afab9 100644
--- a/libavfilter/vf_vidstabdetect.c
+++ b/libavfilter/vf_vidstabdetect.c
@@ -40,6 +40,7 @@ typedef struct StabData {
  VSMotionDetectConfig conf;
    char *result;
+    int fileformat;
  FILE *f;
  } StabData;
  @@ -58,6 +59,11 @@ static const AVOption vidstabdetect_options[] = {
  {"show",    "0: draw nothing; 1,2: show fields and 
transforms",  OFFSETC(show), AV_OPT_TYPE_INT, {.i64 = 
0},  0,   2, FLAGS},
  {"tripod",  "virtual tripod mode (if >0): motion is 
compared to a reference"
  " reference frame (frame # is the 
value)",   OFFSETC(virtualTripod), 
AV_OPT_TYPE_INT,    {.i64 = 0}, 0, INT_MAX, FLAGS},

+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+    { "fileformat",   "transforms data file format", 
OFFSET(fileformat),  AV_OPT_TYPE_INT,  {.i64 = 
BINARY_SERIALIZATION_MODE},  ASCII_SERIALIZATION_MODE, 
BINARY_SERIALIZATION_MODE,  FLAGS,  "file_format"},
+    { "ascii",    "ASCII text",  0,  AV_OPT_TYPE_CONST, {.i64 
= ASCII_SERIALIZATION_MODE },  0,  0,  FLAGS, "file_format"},
+    { "binary",   "binary",  0,  AV_OPT_TYPE_CONST, {.i64 
= BINARY_SERIALIZATION_MODE},  0,  0,  FLAGS, "file_format"},

+#endif
  {NULL}
  };
  @@ -94,6 +100,13 @@ static int config_input(AVFilterLink *inlink)
  VSFrameInfo fi;
  const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(inlink->format);

  int is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
+    const char *file_mode = "w";
+
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+    md->serializationMode = s->fileformat;
+    if (s->fileformat == BINARY_SERIALIZATION_MODE)
+    file_mode = "wb";
+#endif
    vsFrameInfoInit(, inlink->w, inlink->h,
  ff_av2vs_pixfmt(ctx, inlink->format));
@@ -129,7 +142,7 @@ static int config_input(AVFilterLink *inlink)
  av_log(ctx, AV_LOG_INFO, "  show = %d\n", s->conf.show);
  av_log(ctx, AV_LOG_INFO, "    result = %s\n", s->result);
  -    s->f = avpriv_fopen_utf8(s->result, "w");
+    s->f = avpriv_fopen_utf8(s->result, file_mode);
  if (s->f == NULL) {
  av_log(ctx, AV_LOG_ERROR, "cannot open transform file 
%s\n", s->result);

  return AVERROR(EINVAL);
diff --git a/libavfilter/vf_vidstabtransform.c 
b/libavfilter/vf_vidstabtransform.c

index 8a66a463b4..780bf1064d 100644
--- a/libavfilter/vf_vidstabtransform.c
+++ b/libavfilter/vf_vidstabtransform.c
@@ -42,6 +42,7 @@ typedef struct TransformContext {
  char *input;    // name of transform file
  int tripod;
  int debug;
+    int fileformat;
  } TransformContext;
    #define OFFSET(x) offsetof(TransformContext, x)
@@ -101,6 +102,12 @@ static const AVOption 
vidstabtransform_options[] = {

 AV_OPT_TYPE_BOOL,   {.i64 = 0}, 0, 1, FLAGS},
  {"debug", "enable debug mode and 

Re: [FFmpeg-devel] [PATCH] avfilter/vidstab: add option for file format specification

2023-10-22 Thread Timo Rothenpieler

On 22.10.2023 13:57, Gyan Doshi wrote:



On 2023-10-22 05:04 pm, Timo Rothenpieler wrote:

On 22.10.2023 13:24, Gyan Doshi wrote:

The vidstab library added support in Nov 2020 for writing/reading
the transforms data in binary in addition to ASCII. The library default
was changed to binary format but no changes were made to the AVfilters
resulting in data file for writing or reading being always opened as 
text.

This effectively broke the filters.

Options added to vidstab{detect,transform} to specify file format
and open files with the correct attributes.
---
  doc/filters.texi  | 26 ++
  libavfilter/vf_vidstabdetect.c    | 15 ++-
  libavfilter/vf_vidstabtransform.c | 15 ++-
  3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f5032ddf74..806448f063 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -24618,6 +24618,19 @@ If set to 0, it is disabled. The frames are 
counted starting from 1.

  Show fields and transforms in the resulting frames. It accepts an
  integer in the range 0-2. Default value is 0, which disables any
  visualization.
+
+@item fileformat
+Format for the transforms data file to be written.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format, roughly 40% smaller than @code{ascii}. (@emph{default})
+@end table
+
  @end table
    @subsection Examples
@@ -24772,6 +24785,19 @@ Use also @code{tripod} option of 
@ref{vidstabdetect}.

  Increase log verbosity if set to 1. Also the detected global motions
  are written to the temporary file @file{global_motions.trf}. Default
  value is 0.
+
+@item fileformat
+Format of the transforms data file to be read.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format (@emph{default})
+@end table
+
  @end table
    @subsection Examples
diff --git a/libavfilter/vf_vidstabdetect.c 
b/libavfilter/vf_vidstabdetect.c

index a2c6d89503..aa050afab9 100644
--- a/libavfilter/vf_vidstabdetect.c
+++ b/libavfilter/vf_vidstabdetect.c
@@ -40,6 +40,7 @@ typedef struct StabData {
  VSMotionDetectConfig conf;
    char *result;
+    int fileformat;
  FILE *f;
  } StabData;
  @@ -58,6 +59,11 @@ static const AVOption vidstabdetect_options[] = {
  {"show",    "0: draw nothing; 1,2: show fields and 
transforms",  OFFSETC(show), AV_OPT_TYPE_INT,    {.i64 = 
0},  0,   2, FLAGS},
  {"tripod",  "virtual tripod mode (if >0): motion is 
compared to a reference"
  " reference frame (frame # is the 
value)",   OFFSETC(virtualTripod), 
AV_OPT_TYPE_INT,    {.i64 = 0}, 0, INT_MAX, FLAGS},

+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+    { "fileformat",   "transforms data file format", 
OFFSET(fileformat),  AV_OPT_TYPE_INT,  {.i64 = 
BINARY_SERIALIZATION_MODE},  ASCII_SERIALIZATION_MODE, 
BINARY_SERIALIZATION_MODE,  FLAGS,  "file_format"},
+    { "ascii",    "ASCII text",  0,  AV_OPT_TYPE_CONST, {.i64 = 
ASCII_SERIALIZATION_MODE },  0,  0,  FLAGS, "file_format"},
+    { "binary",   "binary",  0,  AV_OPT_TYPE_CONST, {.i64 = 
BINARY_SERIALIZATION_MODE},  0,  0,  FLAGS, "file_format"},

+#endif
  {NULL}
  };
  @@ -94,6 +100,13 @@ static int config_input(AVFilterLink *inlink)
  VSFrameInfo fi;
  const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(inlink->format);

  int is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
+    const char *file_mode = "w";
+
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+    md->serializationMode = s->fileformat;
+    if (s->fileformat == BINARY_SERIALIZATION_MODE)
+    file_mode = "wb";
+#endif
    vsFrameInfoInit(, inlink->w, inlink->h,
  ff_av2vs_pixfmt(ctx, inlink->format));
@@ -129,7 +142,7 @@ static int config_input(AVFilterLink *inlink)
  av_log(ctx, AV_LOG_INFO, "  show = %d\n", s->conf.show);
  av_log(ctx, AV_LOG_INFO, "    result = %s\n", s->result);
  -    s->f = avpriv_fopen_utf8(s->result, "w");
+    s->f = avpriv_fopen_utf8(s->result, file_mode);
  if (s->f == NULL) {
  av_log(ctx, AV_LOG_ERROR, "cannot open transform file 
%s\n", s->result);

  return AVERROR(EINVAL);
diff --git a/libavfilter/vf_vidstabtransform.c 
b/libavfilter/vf_vidstabtransform.c

index 8a66a463b4..780bf1064d 100644
--- a/libavfilter/vf_vidstabtransform.c
+++ b/libavfilter/vf_vidstabtransform.c
@@ -42,6 +42,7 @@ typedef struct TransformContext {
  char *input;    // name of transform file
  int tripod;
  int debug;
+    int fileformat;
  } TransformContext;
    #define OFFSET(x) offsetof(TransformContext, x)
@@ -101,6 +102,12 @@ static const AVOption vidstabtransform_options[] 
= {
 AV_OPT_TYPE_BOOL,   {.i64 = 0},    0, 1, 
FLAGS},
  {"debug", "enable debug mode and writer global motions 
information to file", 

Re: [FFmpeg-devel] [PATCH] avfilter/vidstab: add option for file format specification

2023-10-22 Thread Gyan Doshi



On 2023-10-22 05:04 pm, Timo Rothenpieler wrote:

On 22.10.2023 13:24, Gyan Doshi wrote:

The vidstab library added support in Nov 2020 for writing/reading
the transforms data in binary in addition to ASCII. The library default
was changed to binary format but no changes were made to the AVfilters
resulting in data file for writing or reading being always opened as 
text.

This effectively broke the filters.

Options added to vidstab{detect,transform} to specify file format
and open files with the correct attributes.
---
  doc/filters.texi  | 26 ++
  libavfilter/vf_vidstabdetect.c    | 15 ++-
  libavfilter/vf_vidstabtransform.c | 15 ++-
  3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f5032ddf74..806448f063 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -24618,6 +24618,19 @@ If set to 0, it is disabled. The frames are 
counted starting from 1.

  Show fields and transforms in the resulting frames. It accepts an
  integer in the range 0-2. Default value is 0, which disables any
  visualization.
+
+@item fileformat
+Format for the transforms data file to be written.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format, roughly 40% smaller than @code{ascii}. (@emph{default})
+@end table
+
  @end table
    @subsection Examples
@@ -24772,6 +24785,19 @@ Use also @code{tripod} option of 
@ref{vidstabdetect}.

  Increase log verbosity if set to 1. Also the detected global motions
  are written to the temporary file @file{global_motions.trf}. Default
  value is 0.
+
+@item fileformat
+Format of the transforms data file to be read.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format (@emph{default})
+@end table
+
  @end table
    @subsection Examples
diff --git a/libavfilter/vf_vidstabdetect.c 
b/libavfilter/vf_vidstabdetect.c

index a2c6d89503..aa050afab9 100644
--- a/libavfilter/vf_vidstabdetect.c
+++ b/libavfilter/vf_vidstabdetect.c
@@ -40,6 +40,7 @@ typedef struct StabData {
  VSMotionDetectConfig conf;
    char *result;
+    int fileformat;
  FILE *f;
  } StabData;
  @@ -58,6 +59,11 @@ static const AVOption vidstabdetect_options[] = {
  {"show",    "0: draw nothing; 1,2: show fields and 
transforms",  OFFSETC(show), AV_OPT_TYPE_INT,    {.i64 = 
0},  0,   2, FLAGS},
  {"tripod",  "virtual tripod mode (if >0): motion is 
compared to a reference"
  " reference frame (frame # is the 
value)",   OFFSETC(virtualTripod), 
AV_OPT_TYPE_INT,    {.i64 = 0}, 0, INT_MAX, FLAGS},

+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+    { "fileformat",   "transforms data file format", 
OFFSET(fileformat),  AV_OPT_TYPE_INT,  {.i64 = 
BINARY_SERIALIZATION_MODE},  ASCII_SERIALIZATION_MODE, 
BINARY_SERIALIZATION_MODE,  FLAGS,  "file_format"},
+    { "ascii",    "ASCII text",  0,  AV_OPT_TYPE_CONST, {.i64 = 
ASCII_SERIALIZATION_MODE },  0,  0,  FLAGS, "file_format"},
+    { "binary",   "binary",  0,  AV_OPT_TYPE_CONST, {.i64 = 
BINARY_SERIALIZATION_MODE},  0,  0,  FLAGS, "file_format"},

+#endif
  {NULL}
  };
  @@ -94,6 +100,13 @@ static int config_input(AVFilterLink *inlink)
  VSFrameInfo fi;
  const AVPixFmtDescriptor *desc = 
av_pix_fmt_desc_get(inlink->format);

  int is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
+    const char *file_mode = "w";
+
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+    md->serializationMode = s->fileformat;
+    if (s->fileformat == BINARY_SERIALIZATION_MODE)
+    file_mode = "wb";
+#endif
    vsFrameInfoInit(, inlink->w, inlink->h,
  ff_av2vs_pixfmt(ctx, inlink->format));
@@ -129,7 +142,7 @@ static int config_input(AVFilterLink *inlink)
  av_log(ctx, AV_LOG_INFO, "  show = %d\n", s->conf.show);
  av_log(ctx, AV_LOG_INFO, "    result = %s\n", s->result);
  -    s->f = avpriv_fopen_utf8(s->result, "w");
+    s->f = avpriv_fopen_utf8(s->result, file_mode);
  if (s->f == NULL) {
  av_log(ctx, AV_LOG_ERROR, "cannot open transform file 
%s\n", s->result);

  return AVERROR(EINVAL);
diff --git a/libavfilter/vf_vidstabtransform.c 
b/libavfilter/vf_vidstabtransform.c

index 8a66a463b4..780bf1064d 100644
--- a/libavfilter/vf_vidstabtransform.c
+++ b/libavfilter/vf_vidstabtransform.c
@@ -42,6 +42,7 @@ typedef struct TransformContext {
  char *input;    // name of transform file
  int tripod;
  int debug;
+    int fileformat;
  } TransformContext;
    #define OFFSET(x) offsetof(TransformContext, x)
@@ -101,6 +102,12 @@ static const AVOption vidstabtransform_options[] 
= {
 AV_OPT_TYPE_BOOL,   {.i64 = 0},    0, 1,    
FLAGS},
  {"debug", "enable debug mode and writer global motions 
information to file", OFFSET(debug),
 

[FFmpeg-devel] [PATCH v2] avfilter/vidstab: add option for file format specification

2023-10-22 Thread Gyan Doshi
The vidstab library added support in Nov 2020 for writing/reading
the transforms data in binary in addition to ASCII. The library default
was changed to binary format but no changes were made to the AVfilters
resulting in data file for writing or reading being always opened as text.
This effectively broke the filters.

Option added to vidstabdetect to specify file format and open files in
both filters with the correct attributes.
---
 doc/filters.texi  | 13 +
 libavfilter/vf_vidstabdetect.c| 15 ++-
 libavfilter/vf_vidstabtransform.c |  2 +-
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f5032ddf74..cc5d0d3f12 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -24618,6 +24618,19 @@ If set to 0, it is disabled. The frames are counted 
starting from 1.
 Show fields and transforms in the resulting frames. It accepts an
 integer in the range 0-2. Default value is 0, which disables any
 visualization.
+
+@item fileformat
+Format for the transforms data file to be written.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format, roughly 40% smaller than @code{ascii}. (@emph{default})
+@end table
+
 @end table
 
 @subsection Examples
diff --git a/libavfilter/vf_vidstabdetect.c b/libavfilter/vf_vidstabdetect.c
index a2c6d89503..aa050afab9 100644
--- a/libavfilter/vf_vidstabdetect.c
+++ b/libavfilter/vf_vidstabdetect.c
@@ -40,6 +40,7 @@ typedef struct StabData {
 VSMotionDetectConfig conf;
 
 char *result;
+int fileformat;
 FILE *f;
 } StabData;
 
@@ -58,6 +59,11 @@ static const AVOption vidstabdetect_options[] = {
 {"show","0: draw nothing; 1,2: show fields and transforms",
  OFFSETC(show),  AV_OPT_TYPE_INT,{.i64 = 0},  0,   2, 
FLAGS},
 {"tripod",  "virtual tripod mode (if >0): motion is compared to a 
reference"
 " reference frame (frame # is the value)", 
  OFFSETC(virtualTripod), AV_OPT_TYPE_INT,{.i64 = 0}, 0, INT_MAX, 
FLAGS},
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+{ "fileformat",   "transforms data file format",  OFFSET(fileformat),  
AV_OPT_TYPE_INT,  {.i64 = BINARY_SERIALIZATION_MODE},  
ASCII_SERIALIZATION_MODE,  BINARY_SERIALIZATION_MODE,  FLAGS,  "file_format"},
+{ "ascii","ASCII text",  0,  AV_OPT_TYPE_CONST,  {.i64 = 
ASCII_SERIALIZATION_MODE },  0,  0,  FLAGS,  "file_format"},
+{ "binary",   "binary",  0,  AV_OPT_TYPE_CONST,  {.i64 = 
BINARY_SERIALIZATION_MODE},  0,  0,  FLAGS,  "file_format"},
+#endif
 {NULL}
 };
 
@@ -94,6 +100,13 @@ static int config_input(AVFilterLink *inlink)
 VSFrameInfo fi;
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
 int is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
+const char *file_mode = "w";
+
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+md->serializationMode = s->fileformat;
+if (s->fileformat == BINARY_SERIALIZATION_MODE)
+file_mode = "wb";
+#endif
 
 vsFrameInfoInit(, inlink->w, inlink->h,
 ff_av2vs_pixfmt(ctx, inlink->format));
@@ -129,7 +142,7 @@ static int config_input(AVFilterLink *inlink)
 av_log(ctx, AV_LOG_INFO, "  show = %d\n", s->conf.show);
 av_log(ctx, AV_LOG_INFO, "result = %s\n", s->result);
 
-s->f = avpriv_fopen_utf8(s->result, "w");
+s->f = avpriv_fopen_utf8(s->result, file_mode);
 if (s->f == NULL) {
 av_log(ctx, AV_LOG_ERROR, "cannot open transform file %s\n", 
s->result);
 return AVERROR(EINVAL);
diff --git a/libavfilter/vf_vidstabtransform.c 
b/libavfilter/vf_vidstabtransform.c
index 8a66a463b4..f49d302b80 100644
--- a/libavfilter/vf_vidstabtransform.c
+++ b/libavfilter/vf_vidstabtransform.c
@@ -193,7 +193,7 @@ static int config_input(AVFilterLink *inlink)
 av_log(ctx, AV_LOG_INFO, "zoomspeed = %g\n", tc->conf.zoomSpeed);
 av_log(ctx, AV_LOG_INFO, "interpol  = %s\n", 
getInterpolationTypeName(tc->conf.interpolType));
 
-f = avpriv_fopen_utf8(tc->input, "r");
+f = avpriv_fopen_utf8(tc->input, "rb");
 if (!f) {
 int ret = AVERROR(errno);
 av_log(ctx, AV_LOG_ERROR, "cannot open input file %s\n", tc->input);
-- 
2.39.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] avfilter/vidstab: add option for file format specification

2023-10-22 Thread Timo Rothenpieler

On 22.10.2023 13:24, Gyan Doshi wrote:

The vidstab library added support in Nov 2020 for writing/reading
the transforms data in binary in addition to ASCII. The library default
was changed to binary format but no changes were made to the AVfilters
resulting in data file for writing or reading being always opened as text.
This effectively broke the filters.

Options added to vidstab{detect,transform} to specify file format
and open files with the correct attributes.
---
  doc/filters.texi  | 26 ++
  libavfilter/vf_vidstabdetect.c| 15 ++-
  libavfilter/vf_vidstabtransform.c | 15 ++-
  3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f5032ddf74..806448f063 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -24618,6 +24618,19 @@ If set to 0, it is disabled. The frames are counted 
starting from 1.
  Show fields and transforms in the resulting frames. It accepts an
  integer in the range 0-2. Default value is 0, which disables any
  visualization.
+
+@item fileformat
+Format for the transforms data file to be written.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format, roughly 40% smaller than @code{ascii}. (@emph{default})
+@end table
+
  @end table
  
  @subsection Examples

@@ -24772,6 +24785,19 @@ Use also @code{tripod} option of @ref{vidstabdetect}.
  Increase log verbosity if set to 1. Also the detected global motions
  are written to the temporary file @file{global_motions.trf}. Default
  value is 0.
+
+@item fileformat
+Format of the transforms data file to be read.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format (@emph{default})
+@end table
+
  @end table
  
  @subsection Examples

diff --git a/libavfilter/vf_vidstabdetect.c b/libavfilter/vf_vidstabdetect.c
index a2c6d89503..aa050afab9 100644
--- a/libavfilter/vf_vidstabdetect.c
+++ b/libavfilter/vf_vidstabdetect.c
@@ -40,6 +40,7 @@ typedef struct StabData {
  VSMotionDetectConfig conf;
  
  char *result;

+int fileformat;
  FILE *f;
  } StabData;
  
@@ -58,6 +59,11 @@ static const AVOption vidstabdetect_options[] = {

  {"show","0: draw nothing; 1,2: show fields and transforms",   
   OFFSETC(show),  AV_OPT_TYPE_INT,{.i64 = 0},  0,   2, FLAGS},
  {"tripod",  "virtual tripod mode (if >0): motion is compared to a 
reference"
  " reference frame (frame # is the value)",
   OFFSETC(virtualTripod), AV_OPT_TYPE_INT,{.i64 = 0}, 0, INT_MAX, FLAGS},
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+{ "fileformat",   "transforms data file format",  OFFSET(fileformat),  
AV_OPT_TYPE_INT,  {.i64 = BINARY_SERIALIZATION_MODE},  ASCII_SERIALIZATION_MODE,  BINARY_SERIALIZATION_MODE,  
FLAGS,  "file_format"},
+{ "ascii","ASCII text",  0,  AV_OPT_TYPE_CONST,  {.i64 = 
ASCII_SERIALIZATION_MODE },  0,  0,  FLAGS,  "file_format"},
+{ "binary",   "binary",  0,  AV_OPT_TYPE_CONST,  {.i64 = 
BINARY_SERIALIZATION_MODE},  0,  0,  FLAGS,  "file_format"},
+#endif
  {NULL}
  };
  
@@ -94,6 +100,13 @@ static int config_input(AVFilterLink *inlink)

  VSFrameInfo fi;
  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
  int is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
+const char *file_mode = "w";
+
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+md->serializationMode = s->fileformat;
+if (s->fileformat == BINARY_SERIALIZATION_MODE)
+file_mode = "wb";
+#endif
  
  vsFrameInfoInit(, inlink->w, inlink->h,

  ff_av2vs_pixfmt(ctx, inlink->format));
@@ -129,7 +142,7 @@ static int config_input(AVFilterLink *inlink)
  av_log(ctx, AV_LOG_INFO, "  show = %d\n", s->conf.show);
  av_log(ctx, AV_LOG_INFO, "result = %s\n", s->result);
  
-s->f = avpriv_fopen_utf8(s->result, "w");

+s->f = avpriv_fopen_utf8(s->result, file_mode);
  if (s->f == NULL) {
  av_log(ctx, AV_LOG_ERROR, "cannot open transform file %s\n", 
s->result);
  return AVERROR(EINVAL);
diff --git a/libavfilter/vf_vidstabtransform.c 
b/libavfilter/vf_vidstabtransform.c
index 8a66a463b4..780bf1064d 100644
--- a/libavfilter/vf_vidstabtransform.c
+++ b/libavfilter/vf_vidstabtransform.c
@@ -42,6 +42,7 @@ typedef struct TransformContext {
  char *input;// name of transform file
  int tripod;
  int debug;
+int fileformat;
  } TransformContext;
  
  #define OFFSET(x) offsetof(TransformContext, x)

@@ -101,6 +102,12 @@ static const AVOption vidstabtransform_options[] = {
 AV_OPT_TYPE_BOOL,   {.i64 = 0},0, 1,FLAGS},
  {"debug", "enable debug mode and writer global motions information to 
file", OFFSET(debug),
 AV_OPT_TYPE_BOOL,   {.i64 = 0},   

[FFmpeg-devel] [PATCH] avfilter/vidstab: add option for file format specification

2023-10-22 Thread Gyan Doshi
The vidstab library added support in Nov 2020 for writing/reading
the transforms data in binary in addition to ASCII. The library default
was changed to binary format but no changes were made to the AVfilters
resulting in data file for writing or reading being always opened as text.
This effectively broke the filters.

Options added to vidstab{detect,transform} to specify file format
and open files with the correct attributes.
---
 doc/filters.texi  | 26 ++
 libavfilter/vf_vidstabdetect.c| 15 ++-
 libavfilter/vf_vidstabtransform.c | 15 ++-
 3 files changed, 54 insertions(+), 2 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index f5032ddf74..806448f063 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -24618,6 +24618,19 @@ If set to 0, it is disabled. The frames are counted 
starting from 1.
 Show fields and transforms in the resulting frames. It accepts an
 integer in the range 0-2. Default value is 0, which disables any
 visualization.
+
+@item fileformat
+Format for the transforms data file to be written.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format, roughly 40% smaller than @code{ascii}. (@emph{default})
+@end table
+
 @end table
 
 @subsection Examples
@@ -24772,6 +24785,19 @@ Use also @code{tripod} option of @ref{vidstabdetect}.
 Increase log verbosity if set to 1. Also the detected global motions
 are written to the temporary file @file{global_motions.trf}. Default
 value is 0.
+
+@item fileformat
+Format of the transforms data file to be read.
+Acceptable values are
+
+@table @samp
+@item ascii
+Human-readable plain text
+
+@item binary
+Binary format (@emph{default})
+@end table
+
 @end table
 
 @subsection Examples
diff --git a/libavfilter/vf_vidstabdetect.c b/libavfilter/vf_vidstabdetect.c
index a2c6d89503..aa050afab9 100644
--- a/libavfilter/vf_vidstabdetect.c
+++ b/libavfilter/vf_vidstabdetect.c
@@ -40,6 +40,7 @@ typedef struct StabData {
 VSMotionDetectConfig conf;
 
 char *result;
+int fileformat;
 FILE *f;
 } StabData;
 
@@ -58,6 +59,11 @@ static const AVOption vidstabdetect_options[] = {
 {"show","0: draw nothing; 1,2: show fields and transforms",
  OFFSETC(show),  AV_OPT_TYPE_INT,{.i64 = 0},  0,   2, 
FLAGS},
 {"tripod",  "virtual tripod mode (if >0): motion is compared to a 
reference"
 " reference frame (frame # is the value)", 
  OFFSETC(virtualTripod), AV_OPT_TYPE_INT,{.i64 = 0}, 0, INT_MAX, 
FLAGS},
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+{ "fileformat",   "transforms data file format",  OFFSET(fileformat),  
AV_OPT_TYPE_INT,  {.i64 = BINARY_SERIALIZATION_MODE},  
ASCII_SERIALIZATION_MODE,  BINARY_SERIALIZATION_MODE,  FLAGS,  "file_format"},
+{ "ascii","ASCII text",  0,  AV_OPT_TYPE_CONST,  {.i64 = 
ASCII_SERIALIZATION_MODE },  0,  0,  FLAGS,  "file_format"},
+{ "binary",   "binary",  0,  AV_OPT_TYPE_CONST,  {.i64 = 
BINARY_SERIALIZATION_MODE},  0,  0,  FLAGS,  "file_format"},
+#endif
 {NULL}
 };
 
@@ -94,6 +100,13 @@ static int config_input(AVFilterLink *inlink)
 VSFrameInfo fi;
 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
 int is_planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR;
+const char *file_mode = "w";
+
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+md->serializationMode = s->fileformat;
+if (s->fileformat == BINARY_SERIALIZATION_MODE)
+file_mode = "wb";
+#endif
 
 vsFrameInfoInit(, inlink->w, inlink->h,
 ff_av2vs_pixfmt(ctx, inlink->format));
@@ -129,7 +142,7 @@ static int config_input(AVFilterLink *inlink)
 av_log(ctx, AV_LOG_INFO, "  show = %d\n", s->conf.show);
 av_log(ctx, AV_LOG_INFO, "result = %s\n", s->result);
 
-s->f = avpriv_fopen_utf8(s->result, "w");
+s->f = avpriv_fopen_utf8(s->result, file_mode);
 if (s->f == NULL) {
 av_log(ctx, AV_LOG_ERROR, "cannot open transform file %s\n", 
s->result);
 return AVERROR(EINVAL);
diff --git a/libavfilter/vf_vidstabtransform.c 
b/libavfilter/vf_vidstabtransform.c
index 8a66a463b4..780bf1064d 100644
--- a/libavfilter/vf_vidstabtransform.c
+++ b/libavfilter/vf_vidstabtransform.c
@@ -42,6 +42,7 @@ typedef struct TransformContext {
 char *input;// name of transform file
 int tripod;
 int debug;
+int fileformat;
 } TransformContext;
 
 #define OFFSET(x) offsetof(TransformContext, x)
@@ -101,6 +102,12 @@ static const AVOption vidstabtransform_options[] = {
AV_OPT_TYPE_BOOL,   {.i64 = 0},0, 1,FLAGS},
 {"debug", "enable debug mode and writer global motions information to 
file", OFFSET(debug),
AV_OPT_TYPE_BOOL,   {.i64 = 0},0, 1,FLAGS},
+#ifdef LIBVIDSTAB_FILE_FORMAT_VERSION
+{ "fileformat",   "transforms 

[FFmpeg-devel] [PATCH] fftools: Check HAVE_GETSTDHANDLE before using GetStdHandle

2023-10-22 Thread Martin Storsjö
GetStdHandle is unavailable outside of the desktop API subset.

This didn't use to be a problem with earlier WinSDKs, as kbhit also
used to be available only for desktop apps, and this whole section is
wrapped in #if HAVE_KBHIT. With newer WinSDKs, kbhit() is available also
for non-desktop apps, while GetStdHandle still isn't.
---
 fftools/ffmpeg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 7c33b56cd3..46a85b41a8 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -308,7 +308,7 @@ static int read_key(void)
 return n;
 }
 #elif HAVE_KBHIT
-#if HAVE_PEEKNAMEDPIPE
+#if HAVE_PEEKNAMEDPIPE && HAVE_GETSTDHANDLE
 static int is_pipe;
 static HANDLE input_handle;
 DWORD dw, nchars;
-- 
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] avcodec/magicyuv: add vlc multi support

2023-10-22 Thread Paul B Mahol
On Sun, Oct 22, 2023 at 9:06 AM Michael Niedermayer 
wrote:

> On Sun, Oct 22, 2023 at 12:56:40AM +0200, Michael Niedermayer wrote:
> > On Sat, Oct 21, 2023 at 11:00:19AM +0200, Paul B Mahol wrote:
> > > On Sat, Oct 21, 2023 at 2:13 AM Michael Niedermayer <
> mich...@niedermayer.cc>
> > > wrote:
> > >


You have enough skills to fix this,

Good luck!



>
> > > > On Wed, Sep 06, 2023 at 10:19:27PM +, Paul B Mahol wrote:
> > > > > ffmpeg | branch: master | Paul B Mahol  | Mon
> Aug 28
> > > > 12:20:15 2023 +0200| [8b7391cb5ff94ce94612fda69392a95d7ab1ffd0] |
> > > > committer: Paul B Mahol
> > > > >
> > > > > avcodec/magicyuv: add vlc multi support
> > > > >
> > > > > Gives nice speed boost, depending on encoded content it goes from
> > > > > 30% to 60% faster.
> > > > >
> > > > > >
> > > >
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8b7391cb5ff94ce94612fda69392a95d7ab1ffd0
> > > > > ---
> > > > >
> > > > >  libavcodec/magicyuv.c | 65
> > > > +++
> > > > >  1 file changed, 34 insertions(+), 31 deletions(-)
> > > > >
> > > > > diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
> > > > > index 7898cd5be4..bbaf14d0e0 100644
> > > > > --- a/libavcodec/magicyuv.c
> > > > > +++ b/libavcodec/magicyuv.c
> > > > > @@ -34,6 +34,8 @@
> > > > >  #include "lossless_videodsp.h"
> > > > >  #include "thread.h"
> > > > >
> > > > > +#define VLC_BITS 12
> > > > > +
> > > > >  typedef struct Slice {
> > > > >  uint32_t start;
> > > > >  uint32_t size;
> > > > > @@ -67,13 +69,14 @@ typedef struct MagicYUVContext {
> > > > >  Slice*slices[4];  // slice bitstream
> positions for
> > > > each plane
> > > > >  unsigned int  slices_size[4]; // slice sizes for each
> plane
> > > > >  VLC   vlc[4]; // VLC for each plane
> > > > > +VLC_MULTI multi[4];   // Buffer for joint VLC data
> > > > >  int (*magy_decode_slice)(AVCodecContext *avctx, void *tdata,
> > > > >   int j, int threadnr);
> > > > >  LLVidDSPContext   llviddsp;
> > > > >  } MagicYUVContext;
> > > > >
> > > > >  static int huff_build(const uint8_t len[], uint16_t codes_pos[33],
> > > > > -  VLC *vlc, int nb_elems, void *logctx)
> > > > > +  VLC *vlc, VLC_MULTI *multi, int nb_elems,
> void
> > > > *logctx)
> > > > >  {
> > > > >  HuffEntry he[4096];
> > > > >
> > > > > @@ -84,7 +87,8 @@ static int huff_build(const uint8_t len[],
> uint16_t
> > > > codes_pos[33],
> > > > >  he[--codes_pos[len[i]]] = (HuffEntry){ len[i], i };
> > > > >
> > > > >  ff_free_vlc(vlc);
> > > > > -return ff_init_vlc_from_lengths(vlc, FFMIN(he[0].len, 12),
> nb_elems,
> > > > > +ff_free_vlc_multi(multi);
> > > > > +return ff_init_vlc_multi_from_lengths(vlc, multi,
> FFMIN(he[0].len,
> > > > VLC_BITS), nb_elems, nb_elems,
> > > > >  [0].len, sizeof(he[0]),
> > > > >  [0].sym, sizeof(he[0]),
> > > > sizeof(he[0].sym),
> > > > >  0, 0, logctx);
> > > > > @@ -111,6 +115,22 @@ static void magicyuv_median_pred16(uint16_t
> *dst,
> > > > const uint16_t *src1,
> > > > >  *left_top = lt;
> > > > >  }
> > > > >
> > > > > +#define READ_PLANE(dst, plane, b, c) \
> > > > > +{ \
> > > > > +x = 0; \
> > > > > +for (; CACHED_BITSTREAM_READER && x < width-c &&
> get_bits_left()
> > > > > 0;) {\
> > > > > +ret = get_vlc_multi(, (uint8_t *)dst + x * b, multi, \
> > > > > +vlc, vlc_bits, 3); \
> > > > > +if (ret > 0) \
> > > > > +x += ret; \
> > > > > +if (ret <= 0) \
> > > > > +return AVERROR_INVALIDDATA; \
> > > > > +} \
> > > > > +for (; x < width && get_bits_left() > 0; x++) \
> > > > > +dst[x] = get_vlc2(, vlc, vlc_bits, 3); \
> > > > > +dst += stride; \
> > > > > +}
> > > > > +
> > > > >  static int magy_decode_slice10(AVCodecContext *avctx, void *tdata,
> > > > > int j, int threadnr)
> > > > >  {
> > > > > @@ -130,6 +150,9 @@ static int magy_decode_slice10(AVCodecContext
> > > > *avctx, void *tdata,
> > > > >  int sheight = AV_CEIL_RSHIFT(s->slice_height,
> s->vshift[i]);
> > > > >  ptrdiff_t fake_stride = (p->linesize[i] / 2) * (1 +
> interlaced);
> > > > >  ptrdiff_t stride = p->linesize[i] / 2;
> > > > > +const VLC_MULTI_ELEM *const multi = s->multi[i].table;
> > > > > +const VLCElem *const vlc = s->vlc[i].table;
> > > > > +const int vlc_bits = s->vlc[i].bits;
> > > > >  int flags, pred;
> > > > >  int ret = init_get_bits8(, s->buf +
> s->slices[i][j].start,
> > > > >   s->slices[i][j].size);
> > > > > @@ -151,20 +174,8 @@ static int magy_decode_slice10(AVCodecContext
> > > > *avctx, void *tdata,
> > > > > 

Re: [FFmpeg-devel] [FFmpeg-cvslog] avcodec/magicyuv: add vlc multi support

2023-10-22 Thread Michael Niedermayer
On Sun, Oct 22, 2023 at 12:56:40AM +0200, Michael Niedermayer wrote:
> On Sat, Oct 21, 2023 at 11:00:19AM +0200, Paul B Mahol wrote:
> > On Sat, Oct 21, 2023 at 2:13 AM Michael Niedermayer 
> > wrote:
> > 
> > > On Wed, Sep 06, 2023 at 10:19:27PM +, Paul B Mahol wrote:
> > > > ffmpeg | branch: master | Paul B Mahol  | Mon Aug 28
> > > 12:20:15 2023 +0200| [8b7391cb5ff94ce94612fda69392a95d7ab1ffd0] |
> > > committer: Paul B Mahol
> > > >
> > > > avcodec/magicyuv: add vlc multi support
> > > >
> > > > Gives nice speed boost, depending on encoded content it goes from
> > > > 30% to 60% faster.
> > > >
> > > > >
> > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8b7391cb5ff94ce94612fda69392a95d7ab1ffd0
> > > > ---
> > > >
> > > >  libavcodec/magicyuv.c | 65
> > > +++
> > > >  1 file changed, 34 insertions(+), 31 deletions(-)
> > > >
> > > > diff --git a/libavcodec/magicyuv.c b/libavcodec/magicyuv.c
> > > > index 7898cd5be4..bbaf14d0e0 100644
> > > > --- a/libavcodec/magicyuv.c
> > > > +++ b/libavcodec/magicyuv.c
> > > > @@ -34,6 +34,8 @@
> > > >  #include "lossless_videodsp.h"
> > > >  #include "thread.h"
> > > >
> > > > +#define VLC_BITS 12
> > > > +
> > > >  typedef struct Slice {
> > > >  uint32_t start;
> > > >  uint32_t size;
> > > > @@ -67,13 +69,14 @@ typedef struct MagicYUVContext {
> > > >  Slice*slices[4];  // slice bitstream positions for
> > > each plane
> > > >  unsigned int  slices_size[4]; // slice sizes for each plane
> > > >  VLC   vlc[4]; // VLC for each plane
> > > > +VLC_MULTI multi[4];   // Buffer for joint VLC data
> > > >  int (*magy_decode_slice)(AVCodecContext *avctx, void *tdata,
> > > >   int j, int threadnr);
> > > >  LLVidDSPContext   llviddsp;
> > > >  } MagicYUVContext;
> > > >
> > > >  static int huff_build(const uint8_t len[], uint16_t codes_pos[33],
> > > > -  VLC *vlc, int nb_elems, void *logctx)
> > > > +  VLC *vlc, VLC_MULTI *multi, int nb_elems, void
> > > *logctx)
> > > >  {
> > > >  HuffEntry he[4096];
> > > >
> > > > @@ -84,7 +87,8 @@ static int huff_build(const uint8_t len[], uint16_t
> > > codes_pos[33],
> > > >  he[--codes_pos[len[i]]] = (HuffEntry){ len[i], i };
> > > >
> > > >  ff_free_vlc(vlc);
> > > > -return ff_init_vlc_from_lengths(vlc, FFMIN(he[0].len, 12), 
> > > > nb_elems,
> > > > +ff_free_vlc_multi(multi);
> > > > +return ff_init_vlc_multi_from_lengths(vlc, multi, FFMIN(he[0].len,
> > > VLC_BITS), nb_elems, nb_elems,
> > > >  [0].len, sizeof(he[0]),
> > > >  [0].sym, sizeof(he[0]),
> > > sizeof(he[0].sym),
> > > >  0, 0, logctx);
> > > > @@ -111,6 +115,22 @@ static void magicyuv_median_pred16(uint16_t *dst,
> > > const uint16_t *src1,
> > > >  *left_top = lt;
> > > >  }
> > > >
> > > > +#define READ_PLANE(dst, plane, b, c) \
> > > > +{ \
> > > > +x = 0; \
> > > > +for (; CACHED_BITSTREAM_READER && x < width-c && get_bits_left()
> > > > 0;) {\
> > > > +ret = get_vlc_multi(, (uint8_t *)dst + x * b, multi, \
> > > > +vlc, vlc_bits, 3); \
> > > > +if (ret > 0) \
> > > > +x += ret; \
> > > > +if (ret <= 0) \
> > > > +return AVERROR_INVALIDDATA; \
> > > > +} \
> > > > +for (; x < width && get_bits_left() > 0; x++) \
> > > > +dst[x] = get_vlc2(, vlc, vlc_bits, 3); \
> > > > +dst += stride; \
> > > > +}
> > > > +
> > > >  static int magy_decode_slice10(AVCodecContext *avctx, void *tdata,
> > > > int j, int threadnr)
> > > >  {
> > > > @@ -130,6 +150,9 @@ static int magy_decode_slice10(AVCodecContext
> > > *avctx, void *tdata,
> > > >  int sheight = AV_CEIL_RSHIFT(s->slice_height, s->vshift[i]);
> > > >  ptrdiff_t fake_stride = (p->linesize[i] / 2) * (1 + 
> > > > interlaced);
> > > >  ptrdiff_t stride = p->linesize[i] / 2;
> > > > +const VLC_MULTI_ELEM *const multi = s->multi[i].table;
> > > > +const VLCElem *const vlc = s->vlc[i].table;
> > > > +const int vlc_bits = s->vlc[i].bits;
> > > >  int flags, pred;
> > > >  int ret = init_get_bits8(, s->buf + s->slices[i][j].start,
> > > >   s->slices[i][j].size);
> > > > @@ -151,20 +174,8 @@ static int magy_decode_slice10(AVCodecContext
> > > *avctx, void *tdata,
> > > >  dst += stride;
> > > >  }
> > > >  } else {
> > > > -for (k = 0; k < height; k++) {
> > > > -for (x = 0; x < width; x++) {
> > > > -int pix;
> > > > -if (get_bits_left() <= 0)
> > > > -return AVERROR_INVALIDDATA;
> > > > -
> > > > -