[FFmpeg-devel] [PATCH] libavcodec/cbs_av1: Add size check before parse obu

2022-03-23 Thread Wenbin Chen
cbs_av1_write_unit() check pbc size after parsing obu frame, and return
AVERROR(ENOSPC) if pbc is small. pbc will be reallocated and this obu
frame will be parsed again, but this may cause error because
CodedBitstreamAV1Context has already been updated, for example
ref_order_hint is updated and will not match the same obu frame. Now size
check is added before parsing obu frame to avoid this error.

Signed-off-by: Wenbin Chen 
---
 libavcodec/cbs_av1.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c
index 1229480567..571d3c15c3 100644
--- a/libavcodec/cbs_av1.c
+++ b/libavcodec/cbs_av1.c
@@ -1075,6 +1075,9 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
 put_bits32(pbc, 0);
 }
 
+if (8 * unit->data_size > put_bits_left(pbc))
+return AVERROR(ENOSPC);
+
 td = NULL;
 start_pos = put_bits_count(pbc);
 
@@ -1196,9 +1199,6 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx,
 flush_put_bits(pbc);
 av_assert0(data_pos <= start_pos);
 
-if (8 * obu->obu_size > put_bits_left(pbc))
-return AVERROR(ENOSPC);
-
 if (obu->obu_size > 0) {
 memmove(pbc->buf + data_pos,
 pbc->buf + start_pos, header_size);
-- 
2.32.0

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

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


Re: [FFmpeg-devel] [PATCH] libavcodec/hevc_mp4toannexb_bsf: insert extradata before non-AUD unit

2022-03-23 Thread Xiang, Haihao
On Tue, 2022-03-22 at 10:29 +0100, Andreas Rheinhardt wrote:
> Xiang, Haihao:
> > From: Haihao Xiang 
> > 
> > It is possible that an IRAP frame in input AVPacket contains VPS, SPS
> > and PPS, and these headers should take effect. However the prepended
> > extradata might override these headers. This patch inserts extradata
> > before non-AUD unit, hence VPS, SPS and PPS from the input AVPacket will
> > take effect if they are present.
> > 
> > This should fix #7799
> > 
> > Signed-off-by: Haihao Xiang 
> > ---
> >  libavcodec/hevc_mp4toannexb_bsf.c | 12 ++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/libavcodec/hevc_mp4toannexb_bsf.c
> > b/libavcodec/hevc_mp4toannexb_bsf.c
> > index 790dfb0394..77551ba221 100644
> > --- a/libavcodec/hevc_mp4toannexb_bsf.c
> > +++ b/libavcodec/hevc_mp4toannexb_bsf.c
> > @@ -124,6 +124,7 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx,
> > AVPacket *out)
> >  
> >  int got_irap = 0;
> >  int i, ret = 0;
> > +int prev_nalu_is_aud = 0, extradata_offset = 0;
> >  
> >  ret = ff_bsf_get_packet(ctx, &in);
> >  if (ret < 0)
> > @@ -169,14 +170,21 @@ static int hevc_mp4toannexb_filter(AVBSFContext *ctx,
> > AVPacket *out)
> >  
> >  prev_size = out->size;
> >  
> > +if (prev_nalu_is_aud)
> > +extradata_offset = prev_size;
> > +
> >  ret = av_grow_packet(out, 4 + nalu_size + extra_size);
> >  if (ret < 0)
> >  goto fail;
> >  
> > -if (extra_size)
> > -memcpy(out->data + prev_size, ctx->par_out->extradata,
> > extra_size);
> > +if (extra_size) {
> > +memmove(out->data + extradata_offset + extra_size, out->data +
> > extradata_offset, prev_size - extradata_offset);
> > +memcpy(out->data + extradata_offset, ctx->par_out->extradata,
> > extra_size);
> > +}
> > +
> >  AV_WB32(out->data + prev_size + extra_size, 1);
> >  bytestream2_get_buffer(&gb, out->data + prev_size + 4 + extra_size,
> > nalu_size);
> > +prev_nalu_is_aud = nalu_type == HEVC_NAL_AUD;
> >  }
> >  
> >  ret = av_packet_copy_props(out, in);
> 
> 1. prev_nalu_is_aud is unnecessary: You can just use "if (nalu_type ==
> HEVC_NAL_AUD) extradata_offset = out->size;" at the end of the loop.

Thanks for reviewing the patch.

> 2. This only mitigates a certain case of wrongly inserted extradata; it
> does not fix the underlying issue which is that this BSF does not track
> the current state of extradata and therefore inserts parameter sets that
> have already been superseded by new in-band extradata. Your patch
> ensures that the extradata parameter sets will be prepended to the
> in-band extradata. Yet the already deactivated parameter sets will still
> be inserted. The output can still be invalid, because 7.4.2.4.2 of the
> HEVC spec requires the following: "Any SPS NAL unit with nuh_layer_id
> equal to 0 containing the value of sps_seq_parameter_set_id for the
> active SPS
> RBSP for the base layer for a CVS shall have the same content as that of
> the active SPS RBSP for the base layer for the CVS, unless it follows
> the last access unit of the CVS and precedes the first VCL NAL unit and
> the first SEI NAL unit containing an active parameter sets SEI message
> (when present) of another CVS." Furthermore in case a preceding packet
> contained updated parameter sets that (perhaps partially) overwrite
> parameter sets from extradata and the current packet does not
> contain/repeat these parameter sets, then the above code will still
> insert the outdated and incorrect parameter set and these parameter sets
> will not be overwritten before being used.

I agree this patch doesn't resolve the underlying issue and user might still
experience issues in some cases, but in practice lots of issues disappear after
applying this patch, including the issues in #7799 and some issues I experienced
when using hevc_qsv encoder. May we merge such patch for these issues ? If yes,
I'll update the patch. 

> 3. Andriy Gelman once proposed a patchset that tracked the parameter
> sets and inserted only the needed ones. See
> 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20191016025040.31273-2-andriy.gel...@gmail.com/
> The problem with this patchset was the complexity emanating from HEVC's
> layers.

So this patch won't be merged, right ?

> 4. Lacking proper tracking of parameter sets we should probably err on
> the side of caution and stop inserting parameter sets if the input
> contained in-band parameter sets (similar to h264_mp4toannexb). I can
> write a patch for this.

I'm looking forward to test your patch. 

Thanks
Haihao

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

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


Re: [FFmpeg-devel] [PATCH v4 1/2] lavc/vaapi_encode: add support for maxframesize

2022-03-23 Thread Wang, Fei W
> -Original Message-
> From: Wang, Fei W 
> Sent: Tuesday, March 22, 2022 10:11 PM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Linjie Fu ; Wang, Fei W 
> Subject: [PATCH v4 1/2] lavc/vaapi_encode: add support for maxframesize
> 
> From: Linjie Fu 
> 
> Add support for max frame size:
> - max_frame_size (bytes) to indicate the max allowed size for frame.
> 
> If the frame size exceeds the limitation, encoder will to control the frame 
> size by
> adjusting QP value.
> - MFS_NUM_PASSES to indicate number of passes for QP adjust.
> - MFS_DELTA_QP to indicate adjust qp value per pass.
> 
> To simplify the usage, default QP adjust is set to delta_qp[4] = {1, 1, 1, 1}.
> Use new_qp for encoder if frame size exceeds the limitation:
> new_qp = base_qp + delta_qp[0] + delta_qp[1] + ...
> 
> ffmpeg -hwaccel vaapi -vaapi_device /dev/dri/renderD128 -f rawvideo \
> -v verbose -s:v 352x288 -i ./input.yuv -vf format=nv12,hwupload \
> -c:v h264_vaapi -profile:v main -g 30 -bf 3 -max_frame_size 4 \
> -vframes 100 -y ./max_frame_size.h264
> 
> Max frame size was enabled since VA-API version (1, 3, 0), but query is 
> available
> since (1, 5, 0). It will be passed as a parameter in picParam and should be 
> set for
> each frame.
> 
> Signed-off-by: Linjie Fu 
> Signed-off-by: Fei Wang 
> ---
> 1. re-send the 2 legacy patch:
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/20190715105936.4860-1-
> linjie...@intel.com/
> https://patchwork.ffmpeg.org/project/ffmpeg/patch/2019071511.5069-1-
> linjie...@intel.com/
> 
>  libavcodec/vaapi_encode.c | 67
> +++
>  libavcodec/vaapi_encode.h | 19 +--
>  2 files changed, 84 insertions(+), 2 deletions(-)

Hi Andriy,

Is there any way to know the details of failure for this patch? Like OS, 
configuration,
gcc version, etc. It looks good on my local Ubuntu with gcc 9.3, but show fails 
in patchwork checks:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220322141119.595627-1-fei.w.w...@intel.com/

Fei
Thanks
___
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] avformat/aaxdec: Check for overlaping segments

2022-03-23 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
45875/clusterfuzz-testcase-minimized-ffmpeg_dem_AAX_fuzzer-6121689903136768

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

diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index 0ae4057a53..baa405bb17 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -251,6 +251,10 @@ static int aax_read_header(AVFormatContext *s)
 size  = avio_rb32(pb);
 a->segments[r].start = start + a->data_offset;
 a->segments[r].end   = a->segments[r].start + size;
+if (r &&
+a->segments[r].start < a->segments[r-1].end &&
+a->segments[r].end   > a->segments[r-1].start)
+return AVERROR_INVALIDDATA;
 } else
 return AVERROR_INVALIDDATA;
 }
-- 
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 v8 1/5] avcodec/jpegxl: add Jpeg XL image codec and parser

2022-03-23 Thread Leo Izen
This commit adds support to libavcodec to read and parse
encoded Jpeg XL images. Jpeg XL is intended to be an
extended-life replacement to legacy mjpeg.
---
 MAINTAINERS|   2 +
 libavcodec/Makefile|   1 +
 libavcodec/codec_desc.c|   9 +
 libavcodec/codec_id.h  |   1 +
 libavcodec/jpegxl.h|  43 ++
 libavcodec/jpegxl_parser.c | 941 +
 libavcodec/parsers.c   |   1 +
 libavcodec/version.h   |   2 +-
 8 files changed, 999 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/jpegxl.h
 create mode 100644 libavcodec/jpegxl_parser.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 931cf4bd2c..2e0de9e224 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -188,6 +188,7 @@ Codecs:
   interplayvideo.c  Mike Melanson
   jni*, ffjni*  Matthieu Bouron
   jpeg2000* Nicolas Bertrand
+  jpegxl.h, jpegxl_parser.c Leo Izen
   jvdec.c   Peter Ross
   lcl*.cRoberto Togni, Reimar Doeffinger
   libcelt_dec.c Nicolas George
@@ -616,6 +617,7 @@ Haihao Xiang (haihao) 1F0C 31E8 B4FE F7A4 4DC1 DC99 
E0F5 76D4 76FC 437F
 Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 D368
 James Almer   7751 2E8C FD94 A169 57E6 9A7A 1463 01AD 7376 59E0
 Jean Delvare  7CA6 9F44 60F1 BDC4 1FD2 C858 A552 6B9B B3CD 4E6A
+Leo Izen (thebombzen) B6FD 3CFC 7ACF 83FC 9137 6945 5A71 C331 FD2F A19A
 Loren Merritt ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 56DE
 Lynne FE50 139C 6805 72CA FD52 1F8D A2FE A5F0 3F03 4464
 Michael Niedermayer   9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb8b0e824b..3723601b3d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -44,6 +44,7 @@ OBJS = ac3_parser.o   
  \
dv_profile.o \
encode.o \
imgconvert.o \
+   jpegxl_parser.o  \
jni.o\
mathtables.o \
mediacodec.o \
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 81f3b3c640..1b82870aaa 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1863,6 +1863,15 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("GEM Raster image"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_JPEGXL,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "jpegxl",
+.long_name = NULL_IF_CONFIG_SMALL("JPEG XL"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
+ AV_CODEC_PROP_LOSSLESS,
+.mime_types= MT("image/jxl"),
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 3ffb9bd22e..dbc4f3a208 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -308,6 +308,7 @@ enum AVCodecID {
 AV_CODEC_ID_SIMBIOSIS_IMX,
 AV_CODEC_ID_SGA_VIDEO,
 AV_CODEC_ID_GEM,
+AV_CODEC_ID_JPEGXL,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/jpegxl.h b/libavcodec/jpegxl.h
new file mode 100644
index 00..4f93c99687
--- /dev/null
+++ b/libavcodec/jpegxl.h
@@ -0,0 +1,43 @@
+/*
+ * JPEG XL header
+ * Copyright (c) 2021 Leo Izen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * JPEG XL header
+ */
+
+#ifndef AVCODEC_JPEGXL_H
+#define AVCODEC_JPEGXL_H
+
+#include 
+
+/* these are also used in avformat/img2dec.c */
+#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff
+#define FF_JPEGXL_CODESTREAM_SIGNATU

[FFmpeg-devel] [PATCH v8 2/5] avcodec/libjxl: add Jpeg XL decoding via libjxl

2022-03-23 Thread Leo Izen
This commit adds decoding support to libavcodec
for Jpeg XL images via the external library libjxl.
---
 MAINTAINERS   |   1 +
 configure |   5 +
 doc/general_contents.texi |   7 +
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libjxl.c   |  70 +
 libavcodec/libjxl.h   |  48 ++
 libavcodec/libjxldec.c| 302 ++
 8 files changed, 435 insertions(+)
 create mode 100644 libavcodec/libjxl.c
 create mode 100644 libavcodec/libjxl.h
 create mode 100644 libavcodec/libjxldec.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 2e0de9e224..875d25ca89 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -195,6 +195,7 @@ Codecs:
   libcodec2.c   Tomas Härdin
   libdirac* David Conrad
   libdavs2.cHuiwen Ren
+  libjxl*.c, libjxl.h   Leo Izen
   libgsm.c  Michel Bardiaux
   libkvazaar.c  Arttu Ylä-Outinen
   libopenh264enc.c  Martin Storsjo, Linjie Fu
diff --git a/configure b/configure
index a7953ffc16..4e28114d9c 100755
--- a/configure
+++ b/configure
@@ -240,6 +240,7 @@ External library support:
   --enable-libiec61883 enable iec61883 via libiec61883 [no]
   --enable-libilbc enable iLBC de/encoding via libilbc [no]
   --enable-libjack enable JACK audio sound server [no]
+  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
   --enable-liblensfun  enable lensfun lens correction [no]
@@ -1833,6 +1834,7 @@ EXTERNAL_LIBRARY_LIST="
 libiec61883
 libilbc
 libjack
+libjxl
 libklvanc
 libkvazaar
 libmodplug
@@ -3329,6 +3331,7 @@ libgsm_ms_decoder_deps="libgsm"
 libgsm_ms_encoder_deps="libgsm"
 libilbc_decoder_deps="libilbc"
 libilbc_encoder_deps="libilbc"
+libjxl_decoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
@@ -6541,6 +6544,8 @@ enabled libgsm&& { for gsm_hdr in "gsm.h" 
"gsm/gsm.h"; do
check_lib libgsm "${gsm_hdr}" gsm_create 
-lgsm && break;
done || die "ERROR: libgsm not found"; }
 enabled libilbc   && require libilbc ilbc.h WebRtcIlbcfix_InitDecode 
-lilbc $pthreads_extralibs
+enabled libjxl&& require_pkg_config libjxl "libjxl >= 0.7.0" 
jxl/decode.h JxlDecoderVersion &&
+ require_pkg_config libjxl_threads "libjxl_threads 
>= 0.7.0" jxl/thread_parallel_runner.h JxlThreadParallelRunner
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index fcd9da1b34..a893347fbe 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -171,6 +171,13 @@ Go to @url{https://github.com/TimothyGu/libilbc} and 
follow the instructions for
 installing the library. Then pass @code{--enable-libilbc} to configure to
 enable it.
 
+@section libjxl
+
+JPEG XL is an image format intended to fully replace legacy JPEG for an 
extended
+period of life. See @url{https://jpegxl.info/} for more information, and see
+@url{https://github.com/libjxl/libjxl} for the library source. You can pass
+@code{--enable-libjxl} to configure in order enable the libjxl wrapper.
+
 @section libvpx
 
 FFmpeg can make use of the libvpx library for VP8/VP9 decoding and encoding.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3723601b3d..c00b0d3246 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1060,6 +1060,7 @@ OBJS-$(CONFIG_LIBGSM_MS_DECODER)  += libgsmdec.o
 OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
 OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
 OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
+OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 22d56760ec..a9cd69dfce 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -749,6 +749,7 @@ extern const FFCodec ff_libgsm_ms_encoder;
 extern const FFCodec ff_libgsm_ms_decoder;
 extern const FFCodec ff_libilbc_encoder;
 extern const FFCodec ff_libilbc_decoder;
+extern const FFCodec ff_libjxl_decoder;
 extern const FFCodec ff_libmp3lame_encoder;
 extern const FFCodec ff_libope

[FFmpeg-devel] [PATCH v8 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-03-23 Thread Leo Izen
This commit adds encoding support to libavcodec
for Jpeg XL images via the external library libjxl.
---
 configure  |   3 +-
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libjxlenc.c | 385 +
 4 files changed, 389 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libjxlenc.c

diff --git a/configure b/configure
index 4e28114d9c..59095a5866 100755
--- a/configure
+++ b/configure
@@ -240,7 +240,7 @@ External library support:
   --enable-libiec61883 enable iec61883 via libiec61883 [no]
   --enable-libilbc enable iLBC de/encoding via libilbc [no]
   --enable-libjack enable JACK audio sound server [no]
-  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
+  --enable-libjxl  enable JPEG XL de/encoding via libjxl [no]
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
   --enable-liblensfun  enable lensfun lens correction [no]
@@ -3332,6 +3332,7 @@ libgsm_ms_encoder_deps="libgsm"
 libilbc_decoder_deps="libilbc"
 libilbc_encoder_deps="libilbc"
 libjxl_decoder_deps="libjxl libjxl_threads"
+libjxl_encoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c00b0d3246..b208cc0097 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1061,6 +1061,7 @@ OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
 OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
 OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
 OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
+OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a9cd69dfce..db92fb7af5 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -750,6 +750,7 @@ extern const FFCodec ff_libgsm_ms_decoder;
 extern const FFCodec ff_libilbc_encoder;
 extern const FFCodec ff_libilbc_decoder;
 extern const FFCodec ff_libjxl_decoder;
+extern const FFCodec ff_libjxl_encoder;
 extern const FFCodec ff_libmp3lame_encoder;
 extern const FFCodec ff_libopencore_amrnb_encoder;
 extern const FFCodec ff_libopencore_amrnb_decoder;
diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
new file mode 100644
index 00..802a543383
--- /dev/null
+++ b/libavcodec/libjxlenc.c
@@ -0,0 +1,385 @@
+/*
+ * JPEG XL encoding support via libjxl
+ * Copyright (c) 2021 Leo Izen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * JPEG XL encoder using libjxl
+ */
+
+#include "libavutil/avutil.h"
+#include "libavutil/error.h"
+#include "libavutil/frame.h"
+#include "libavutil/libm.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/pixfmt.h"
+#include "libavutil/version.h"
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include "internal.h"
+
+#include 
+#include 
+#include "libjxl.h"
+
+typedef struct LibJxlEncodeContext {
+AVClass *class;
+void *runner;
+JxlEncoder *encoder;
+JxlEncoderFrameSettings *options;
+int effort;
+float distance;
+int modular;
+uint8_t *buffer;
+size_t buffer_size;
+} LibJxlEncodeContext;
+
+/**
+ * Map a quality setting for -qscale roughly from libjpeg
+ * quality numbers to libjxl's butteraugli distance for
+ * photographic content.
+ *
+ * Setting distance explicitly is preferred, but this will
+ * allow qscale to be used as a fallback.
+ *
+ * This function is continuous and injective on [0, 100] which
+ * makes it monotonic.
+ *
+ * @param  quality 0.0 to 100.0 quality setting, libjpeg quality
+ * @return Butteraugli distance between 0.0 and 15.0
+ */
+static float quality_to_distance(float quality)
+{
+if (quality >= 100.0)
+return 0.0;
+else if (quality >= 90.0)
+return (100.0 - quality) * 0.10;
+else if (quality >= 30.0)
+return 0.1 + (100.0

[FFmpeg-devel] [PATCH v8 4/5] avformat/image2: add Jpeg XL as image2 format

2022-03-23 Thread Leo Izen
This commit adds support to libavformat for muxing
and demuxing Jpeg XL images as image2 streams.
---
 libavformat/allformats.c |  1 +
 libavformat/img2.c   |  1 +
 libavformat/img2dec.c| 21 +
 libavformat/img2enc.c|  6 +++---
 libavformat/mov.c|  1 +
 libavformat/version.h|  4 ++--
 6 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 587ad59b3c..941f3643f8 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -510,6 +510,7 @@ extern const AVInputFormat  ff_image_gif_pipe_demuxer;
 extern const AVInputFormat  ff_image_j2k_pipe_demuxer;
 extern const AVInputFormat  ff_image_jpeg_pipe_demuxer;
 extern const AVInputFormat  ff_image_jpegls_pipe_demuxer;
+extern const AVInputFormat  ff_image_jpegxl_pipe_demuxer;
 extern const AVInputFormat  ff_image_pam_pipe_demuxer;
 extern const AVInputFormat  ff_image_pbm_pipe_demuxer;
 extern const AVInputFormat  ff_image_pcx_pipe_demuxer;
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 4153102c92..13b1b997b8 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -87,6 +87,7 @@ const IdStrMap ff_img_tags[] = {
 { AV_CODEC_ID_GEM,"img"  },
 { AV_CODEC_ID_GEM,"ximg" },
 { AV_CODEC_ID_GEM,"timg" },
+{ AV_CODEC_ID_JPEGXL, "jxl"  },
 { AV_CODEC_ID_NONE,   NULL   }
 };
 
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index b9c06c5b54..32cadacb9d 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -32,6 +32,7 @@
 #include "libavutil/parseutils.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/gif.h"
+#include "libavcodec/jpegxl.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
@@ -836,6 +837,25 @@ static int jpegls_probe(const AVProbeData *p)
 return 0;
 }
 
+static int jpegxl_probe(const AVProbeData *p)
+{
+const uint8_t *b = p->buf;
+
+/* ISOBMFF-based container */
+/* 0x4a584c20 == "JXL " */
+if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE)
+return AVPROBE_SCORE_EXTENSION + 1;
+#if CONFIG_JPEGXL_PARSER
+/* Raw codestreams all start with 0xff0a */
+if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
+return 0;
+if (avpriv_jpegxl_verify_codestream_header(NULL, p->buf, p->buf_size) == 0)
+return AVPROBE_SCORE_MAX - 2;
+#endif
+return 0;
+}
+
+
 static int pcx_probe(const AVProbeData *p)
 {
 const uint8_t *b = p->buf;
@@ -1165,6 +1185,7 @@ IMAGEAUTO_DEMUXER(gif,   GIF)
 IMAGEAUTO_DEMUXER_EXT(j2k,   JPEG2000, J2K)
 IMAGEAUTO_DEMUXER_EXT(jpeg,  MJPEG, JPEG)
 IMAGEAUTO_DEMUXER(jpegls,JPEGLS)
+IMAGEAUTO_DEMUXER(jpegxl,JPEGXL)
 IMAGEAUTO_DEMUXER(pam,   PAM)
 IMAGEAUTO_DEMUXER(pbm,   PBM)
 IMAGEAUTO_DEMUXER(pcx,   PCX)
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 9b3b8741c8..e6ec6a50aa 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -263,9 +263,9 @@ static const AVClass img2mux_class = {
 const AVOutputFormat ff_image2_muxer = {
 .name   = "image2",
 .long_name  = NULL_IF_CONFIG_SMALL("image2 sequence"),
-.extensions = 
"bmp,dpx,exr,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,png,"
-  
"ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,im24,"
-  "sunras,xbm,xface,pix,y",
+.extensions = 
"bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,"
+  
"png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,"
+  "im24,sunras,xbm,xface,pix,y",
 .priv_data_size = sizeof(VideoMuxData),
 .video_codec= AV_CODEC_ID_MJPEG,
 .write_header   = write_header,
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6c847de164..c4b8873b0a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7697,6 +7697,7 @@ static int mov_probe(const AVProbeData *p)
 if (tag == MKTAG('f','t','y','p') &&
(   AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' 
')
 || AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' 
')
+|| AV_RL32(p->buf + offset + 8) == MKTAG('j','x','l',' 
')
 )) {
 score = FFMAX(score, 5);
 } else {
diff --git a/libavformat/version.h b/libavformat/version.h
index f4a26c2870..683184d5da 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,8 +31,8 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSION_MINOR  20
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR  21
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.35.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.or

[FFmpeg-devel] [PATCH v8 5/5] fate/jpegxl: add Jpeg XL demux and parse FATE test

2022-03-23 Thread Leo Izen
Add a fate test for the Jpeg XL parser in libavcodec and
its image2 wrapper inside libavformat.
---
 tests/fate/image.mak| 10 ++
 tests/ref/fate/jxl-parse-codestream |  6 ++
 tests/ref/fate/jxl-parse-container  |  6 ++
 3 files changed, 22 insertions(+)
 create mode 100644 tests/ref/fate/jxl-parse-codestream
 create mode 100644 tests/ref/fate/jxl-parse-container

diff --git a/tests/fate/image.mak b/tests/fate/image.mak
index 573d398915..15b6145c58 100644
--- a/tests/fate/image.mak
+++ b/tests/fate/image.mak
@@ -357,6 +357,16 @@ FATE_JPEGLS-$(call DEMDEC, IMAGE2, JPEGLS) += 
$(FATE_JPEGLS)
 FATE_IMAGE += $(FATE_JPEGLS-yes)
 fate-jpegls: $(FATE_JPEGLS-yes)
 
+FATE_JPEGXL += fate-jxl-parse-codestream
+fate-jxl-parse-codestream: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/belgium.jxl 
-c:v copy
+
+FATE_JPEGXL += fate-jxl-parse-container
+fate-jxl-parse-container: CMD = framecrc -i 
$(TARGET_SAMPLES)/jxl/lenna-256.jxl -c:v copy
+
+FATE_JPEGXL-$(call DEMDEC, IMAGE2) += $(FATE_JPEGXL)
+FATE_IMAGE += $(FATE_JPEGXL-yes)
+fate-jxl: $(FATE_JPEGXL-yes)
+
 FATE_IMAGE-$(call DEMDEC, IMAGE2, QDRAW) += fate-pict
 fate-pict: CMD = framecrc -i $(TARGET_SAMPLES)/quickdraw/TRU256.PCT -pix_fmt 
rgb24
 
diff --git a/tests/ref/fate/jxl-parse-codestream 
b/tests/ref/fate/jxl-parse-codestream
new file mode 100644
index 00..b2fe5035ac
--- /dev/null
+++ b/tests/ref/fate/jxl-parse-codestream
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 768x512
+#sar 0: 0/1
+0,  0,  0,1,   32, 0xa2930a20
diff --git a/tests/ref/fate/jxl-parse-container 
b/tests/ref/fate/jxl-parse-container
new file mode 100644
index 00..99233d612a
--- /dev/null
+++ b/tests/ref/fate/jxl-parse-container
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 256x256
+#sar 0: 0/1
+0,  0,  0,1, 8088, 0xbbfea9bd
-- 
2.35.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/2] avformat/aiffdec: check allocated size for overflow

2022-03-23 Thread Michael Niedermayer
Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in type 
'int'
Fixes: 
45891/clusterfuzz-testcase-minimized-ffmpeg_dem_AIFF_fuzzer-6159183893889024

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

diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 3634bb4960..c2b8e0dede 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -72,7 +72,12 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
 /* Metadata string read */
 static void get_meta(AVFormatContext *s, const char *key, int size)
 {
-uint8_t *str = av_malloc(size+1);
+uint8_t *str;
+
+if (size == INT_MAX)
+return;
+
+str = av_malloc(size+1);
 
 if (str) {
 int res = avio_read(s->pb, str, size);
-- 
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] avformat/codec2: remove surplus include 'memory.h' statement

2022-03-23 Thread Andreas Rheinhardt
Peter Ross:
> on glibc memory.h drags in string.h, but codec2 does not use any
> str* or mem* functions. additionally, memory.h is not part of the
> C99 or POSIX standards.
> ---
>  libavformat/codec2.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavformat/codec2.c b/libavformat/codec2.c
> index cd0521299c..400c5acbdb 100644
> --- a/libavformat/codec2.c
> +++ b/libavformat/codec2.c
> @@ -21,7 +21,6 @@
>  
>  #include "config_components.h"
>  
> -#include 
>  #include "libavcodec/codec2utils.h"
>  #include "libavutil/channel_layout.h"
>  #include "libavutil/intreadwrite.h"
> 

LGTM.

- 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 v9 1/5] avcodec/jpegxl: add Jpeg XL image codec and parser

2022-03-23 Thread Leo Izen
This commit adds support to libavcodec to read and parse
encoded Jpeg XL images. Jpeg XL is intended to be an
extended-life replacement to legacy mjpeg.
---
 MAINTAINERS|   2 +
 libavcodec/Makefile|   1 +
 libavcodec/codec_desc.c|   9 +
 libavcodec/codec_id.h  |   1 +
 libavcodec/jpegxl.h|  43 ++
 libavcodec/jpegxl_parser.c | 941 +
 libavcodec/parsers.c   |   1 +
 libavcodec/version.h   |   2 +-
 8 files changed, 999 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/jpegxl.h
 create mode 100644 libavcodec/jpegxl_parser.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 931cf4bd2c..2e0de9e224 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -188,6 +188,7 @@ Codecs:
   interplayvideo.c  Mike Melanson
   jni*, ffjni*  Matthieu Bouron
   jpeg2000* Nicolas Bertrand
+  jpegxl.h, jpegxl_parser.c Leo Izen
   jvdec.c   Peter Ross
   lcl*.cRoberto Togni, Reimar Doeffinger
   libcelt_dec.c Nicolas George
@@ -616,6 +617,7 @@ Haihao Xiang (haihao) 1F0C 31E8 B4FE F7A4 4DC1 DC99 
E0F5 76D4 76FC 437F
 Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 D368
 James Almer   7751 2E8C FD94 A169 57E6 9A7A 1463 01AD 7376 59E0
 Jean Delvare  7CA6 9F44 60F1 BDC4 1FD2 C858 A552 6B9B B3CD 4E6A
+Leo Izen (thebombzen) B6FD 3CFC 7ACF 83FC 9137 6945 5A71 C331 FD2F A19A
 Loren Merritt ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 56DE
 Lynne FE50 139C 6805 72CA FD52 1F8D A2FE A5F0 3F03 4464
 Michael Niedermayer   9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb8b0e824b..3723601b3d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -44,6 +44,7 @@ OBJS = ac3_parser.o   
  \
dv_profile.o \
encode.o \
imgconvert.o \
+   jpegxl_parser.o  \
jni.o\
mathtables.o \
mediacodec.o \
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 81f3b3c640..1b82870aaa 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1863,6 +1863,15 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("GEM Raster image"),
 .props = AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_JPEGXL,
+.type  = AVMEDIA_TYPE_VIDEO,
+.name  = "jpegxl",
+.long_name = NULL_IF_CONFIG_SMALL("JPEG XL"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
+ AV_CODEC_PROP_LOSSLESS,
+.mime_types= MT("image/jxl"),
+},
 
 /* various PCM "codecs" */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index 3ffb9bd22e..dbc4f3a208 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -308,6 +308,7 @@ enum AVCodecID {
 AV_CODEC_ID_SIMBIOSIS_IMX,
 AV_CODEC_ID_SGA_VIDEO,
 AV_CODEC_ID_GEM,
+AV_CODEC_ID_JPEGXL,
 
 /* various PCM "codecs" */
 AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
start of audio codecs
diff --git a/libavcodec/jpegxl.h b/libavcodec/jpegxl.h
new file mode 100644
index 00..4f93c99687
--- /dev/null
+++ b/libavcodec/jpegxl.h
@@ -0,0 +1,43 @@
+/*
+ * JPEG XL header
+ * Copyright (c) 2021 Leo Izen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * JPEG XL header
+ */
+
+#ifndef AVCODEC_JPEGXL_H
+#define AVCODEC_JPEGXL_H
+
+#include 
+
+/* these are also used in avformat/img2dec.c */
+#define FF_JPEGXL_CODESTREAM_SIGNATURE_LE 0x0aff
+#define FF_JPEGXL_CODESTREAM_SIGNATU

[FFmpeg-devel] [PATCH v9 2/5] avcodec/libjxl: add Jpeg XL decoding via libjxl

2022-03-23 Thread Leo Izen
This commit adds decoding support to libavcodec
for Jpeg XL images via the external library libjxl.
---
 MAINTAINERS   |   1 +
 configure |   5 +
 doc/general_contents.texi |   7 +
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libjxl.c   |  70 +
 libavcodec/libjxl.h   |  48 ++
 libavcodec/libjxldec.c| 302 ++
 8 files changed, 435 insertions(+)
 create mode 100644 libavcodec/libjxl.c
 create mode 100644 libavcodec/libjxl.h
 create mode 100644 libavcodec/libjxldec.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 2e0de9e224..875d25ca89 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -195,6 +195,7 @@ Codecs:
   libcodec2.c   Tomas Härdin
   libdirac* David Conrad
   libdavs2.cHuiwen Ren
+  libjxl*.c, libjxl.h   Leo Izen
   libgsm.c  Michel Bardiaux
   libkvazaar.c  Arttu Ylä-Outinen
   libopenh264enc.c  Martin Storsjo, Linjie Fu
diff --git a/configure b/configure
index a7953ffc16..4e28114d9c 100755
--- a/configure
+++ b/configure
@@ -240,6 +240,7 @@ External library support:
   --enable-libiec61883 enable iec61883 via libiec61883 [no]
   --enable-libilbc enable iLBC de/encoding via libilbc [no]
   --enable-libjack enable JACK audio sound server [no]
+  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
   --enable-liblensfun  enable lensfun lens correction [no]
@@ -1833,6 +1834,7 @@ EXTERNAL_LIBRARY_LIST="
 libiec61883
 libilbc
 libjack
+libjxl
 libklvanc
 libkvazaar
 libmodplug
@@ -3329,6 +3331,7 @@ libgsm_ms_decoder_deps="libgsm"
 libgsm_ms_encoder_deps="libgsm"
 libilbc_decoder_deps="libilbc"
 libilbc_encoder_deps="libilbc"
+libjxl_decoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
@@ -6541,6 +6544,8 @@ enabled libgsm&& { for gsm_hdr in "gsm.h" 
"gsm/gsm.h"; do
check_lib libgsm "${gsm_hdr}" gsm_create 
-lgsm && break;
done || die "ERROR: libgsm not found"; }
 enabled libilbc   && require libilbc ilbc.h WebRtcIlbcfix_InitDecode 
-lilbc $pthreads_extralibs
+enabled libjxl&& require_pkg_config libjxl "libjxl >= 0.7.0" 
jxl/decode.h JxlDecoderVersion &&
+ require_pkg_config libjxl_threads "libjxl_threads 
>= 0.7.0" jxl/thread_parallel_runner.h JxlThreadParallelRunner
 enabled libklvanc && require libklvanc libklvanc/vanc.h 
klvanc_context_create -lklvanc
 enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 0.8.1" 
kvazaar.h kvz_api_get
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_new
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index fcd9da1b34..a893347fbe 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -171,6 +171,13 @@ Go to @url{https://github.com/TimothyGu/libilbc} and 
follow the instructions for
 installing the library. Then pass @code{--enable-libilbc} to configure to
 enable it.
 
+@section libjxl
+
+JPEG XL is an image format intended to fully replace legacy JPEG for an 
extended
+period of life. See @url{https://jpegxl.info/} for more information, and see
+@url{https://github.com/libjxl/libjxl} for the library source. You can pass
+@code{--enable-libjxl} to configure in order enable the libjxl wrapper.
+
 @section libvpx
 
 FFmpeg can make use of the libvpx library for VP8/VP9 decoding and encoding.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3723601b3d..c00b0d3246 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1060,6 +1060,7 @@ OBJS-$(CONFIG_LIBGSM_MS_DECODER)  += libgsmdec.o
 OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
 OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
 OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
+OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 22d56760ec..a9cd69dfce 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -749,6 +749,7 @@ extern const FFCodec ff_libgsm_ms_encoder;
 extern const FFCodec ff_libgsm_ms_decoder;
 extern const FFCodec ff_libilbc_encoder;
 extern const FFCodec ff_libilbc_decoder;
+extern const FFCodec ff_libjxl_decoder;
 extern const FFCodec ff_libmp3lame_encoder;
 extern const FFCodec ff_libope

[FFmpeg-devel] [PATCH v9 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-03-23 Thread Leo Izen
This commit adds encoding support to libavcodec
for Jpeg XL images via the external library libjxl.
---
 configure  |   3 +-
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libjxlenc.c | 385 +
 4 files changed, 389 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libjxlenc.c

diff --git a/configure b/configure
index 4e28114d9c..59095a5866 100755
--- a/configure
+++ b/configure
@@ -240,7 +240,7 @@ External library support:
   --enable-libiec61883 enable iec61883 via libiec61883 [no]
   --enable-libilbc enable iLBC de/encoding via libilbc [no]
   --enable-libjack enable JACK audio sound server [no]
-  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
+  --enable-libjxl  enable JPEG XL de/encoding via libjxl [no]
   --enable-libklvanc   enable Kernel Labs VANC processing [no]
   --enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
   --enable-liblensfun  enable lensfun lens correction [no]
@@ -3332,6 +3332,7 @@ libgsm_ms_encoder_deps="libgsm"
 libilbc_decoder_deps="libilbc"
 libilbc_encoder_deps="libilbc"
 libjxl_decoder_deps="libjxl libjxl_threads"
+libjxl_encoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index c00b0d3246..b208cc0097 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1061,6 +1061,7 @@ OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
 OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
 OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
 OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
+OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o
 OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index a9cd69dfce..db92fb7af5 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -750,6 +750,7 @@ extern const FFCodec ff_libgsm_ms_decoder;
 extern const FFCodec ff_libilbc_encoder;
 extern const FFCodec ff_libilbc_decoder;
 extern const FFCodec ff_libjxl_decoder;
+extern const FFCodec ff_libjxl_encoder;
 extern const FFCodec ff_libmp3lame_encoder;
 extern const FFCodec ff_libopencore_amrnb_encoder;
 extern const FFCodec ff_libopencore_amrnb_decoder;
diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
new file mode 100644
index 00..802a543383
--- /dev/null
+++ b/libavcodec/libjxlenc.c
@@ -0,0 +1,385 @@
+/*
+ * JPEG XL encoding support via libjxl
+ * Copyright (c) 2021 Leo Izen 
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * JPEG XL encoder using libjxl
+ */
+
+#include "libavutil/avutil.h"
+#include "libavutil/error.h"
+#include "libavutil/frame.h"
+#include "libavutil/libm.h"
+#include "libavutil/opt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/pixfmt.h"
+#include "libavutil/version.h"
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include "internal.h"
+
+#include 
+#include 
+#include "libjxl.h"
+
+typedef struct LibJxlEncodeContext {
+AVClass *class;
+void *runner;
+JxlEncoder *encoder;
+JxlEncoderFrameSettings *options;
+int effort;
+float distance;
+int modular;
+uint8_t *buffer;
+size_t buffer_size;
+} LibJxlEncodeContext;
+
+/**
+ * Map a quality setting for -qscale roughly from libjpeg
+ * quality numbers to libjxl's butteraugli distance for
+ * photographic content.
+ *
+ * Setting distance explicitly is preferred, but this will
+ * allow qscale to be used as a fallback.
+ *
+ * This function is continuous and injective on [0, 100] which
+ * makes it monotonic.
+ *
+ * @param  quality 0.0 to 100.0 quality setting, libjpeg quality
+ * @return Butteraugli distance between 0.0 and 15.0
+ */
+static float quality_to_distance(float quality)
+{
+if (quality >= 100.0)
+return 0.0;
+else if (quality >= 90.0)
+return (100.0 - quality) * 0.10;
+else if (quality >= 30.0)
+return 0.1 + (100.0

[FFmpeg-devel] [PATCH v9 4/5] avformat/image2: add Jpeg XL as image2 format

2022-03-23 Thread Leo Izen
This commit adds support to libavformat for muxing
and demuxing Jpeg XL images as image2 streams.
---
 libavformat/allformats.c |  1 +
 libavformat/img2.c   |  1 +
 libavformat/img2dec.c| 21 +
 libavformat/img2enc.c|  6 +++---
 libavformat/mov.c|  1 +
 libavformat/version.h|  4 ++--
 6 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 587ad59b3c..941f3643f8 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -510,6 +510,7 @@ extern const AVInputFormat  ff_image_gif_pipe_demuxer;
 extern const AVInputFormat  ff_image_j2k_pipe_demuxer;
 extern const AVInputFormat  ff_image_jpeg_pipe_demuxer;
 extern const AVInputFormat  ff_image_jpegls_pipe_demuxer;
+extern const AVInputFormat  ff_image_jpegxl_pipe_demuxer;
 extern const AVInputFormat  ff_image_pam_pipe_demuxer;
 extern const AVInputFormat  ff_image_pbm_pipe_demuxer;
 extern const AVInputFormat  ff_image_pcx_pipe_demuxer;
diff --git a/libavformat/img2.c b/libavformat/img2.c
index 4153102c92..13b1b997b8 100644
--- a/libavformat/img2.c
+++ b/libavformat/img2.c
@@ -87,6 +87,7 @@ const IdStrMap ff_img_tags[] = {
 { AV_CODEC_ID_GEM,"img"  },
 { AV_CODEC_ID_GEM,"ximg" },
 { AV_CODEC_ID_GEM,"timg" },
+{ AV_CODEC_ID_JPEGXL, "jxl"  },
 { AV_CODEC_ID_NONE,   NULL   }
 };
 
diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
index b9c06c5b54..32cadacb9d 100644
--- a/libavformat/img2dec.c
+++ b/libavformat/img2dec.c
@@ -32,6 +32,7 @@
 #include "libavutil/parseutils.h"
 #include "libavutil/intreadwrite.h"
 #include "libavcodec/gif.h"
+#include "libavcodec/jpegxl.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
@@ -836,6 +837,25 @@ static int jpegls_probe(const AVProbeData *p)
 return 0;
 }
 
+static int jpegxl_probe(const AVProbeData *p)
+{
+const uint8_t *b = p->buf;
+
+/* ISOBMFF-based container */
+/* 0x4a584c20 == "JXL " */
+if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE)
+return AVPROBE_SCORE_EXTENSION + 1;
+#if CONFIG_JPEGXL_PARSER
+/* Raw codestreams all start with 0xff0a */
+if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
+return 0;
+if (avpriv_jpegxl_verify_codestream_header(NULL, p->buf, p->buf_size) == 0)
+return AVPROBE_SCORE_MAX - 2;
+#endif
+return 0;
+}
+
+
 static int pcx_probe(const AVProbeData *p)
 {
 const uint8_t *b = p->buf;
@@ -1165,6 +1185,7 @@ IMAGEAUTO_DEMUXER(gif,   GIF)
 IMAGEAUTO_DEMUXER_EXT(j2k,   JPEG2000, J2K)
 IMAGEAUTO_DEMUXER_EXT(jpeg,  MJPEG, JPEG)
 IMAGEAUTO_DEMUXER(jpegls,JPEGLS)
+IMAGEAUTO_DEMUXER(jpegxl,JPEGXL)
 IMAGEAUTO_DEMUXER(pam,   PAM)
 IMAGEAUTO_DEMUXER(pbm,   PBM)
 IMAGEAUTO_DEMUXER(pcx,   PCX)
diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c
index 9b3b8741c8..e6ec6a50aa 100644
--- a/libavformat/img2enc.c
+++ b/libavformat/img2enc.c
@@ -263,9 +263,9 @@ static const AVClass img2mux_class = {
 const AVOutputFormat ff_image2_muxer = {
 .name   = "image2",
 .long_name  = NULL_IF_CONFIG_SMALL("image2 sequence"),
-.extensions = 
"bmp,dpx,exr,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,png,"
-  
"ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,im24,"
-  "sunras,xbm,xface,pix,y",
+.extensions = 
"bmp,dpx,exr,jls,jpeg,jpg,jxl,ljpg,pam,pbm,pcx,pfm,pgm,pgmyuv,"
+  
"png,ppm,sgi,tga,tif,tiff,jp2,j2c,j2k,xwd,sun,ras,rs,im1,im8,"
+  "im24,sunras,xbm,xface,pix,y",
 .priv_data_size = sizeof(VideoMuxData),
 .video_codec= AV_CODEC_ID_MJPEG,
 .write_header   = write_header,
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6c847de164..c4b8873b0a 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -7697,6 +7697,7 @@ static int mov_probe(const AVProbeData *p)
 if (tag == MKTAG('f','t','y','p') &&
(   AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' 
')
 || AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' 
')
+|| AV_RL32(p->buf + offset + 8) == MKTAG('j','x','l',' 
')
 )) {
 score = FFMAX(score, 5);
 } else {
diff --git a/libavformat/version.h b/libavformat/version.h
index f4a26c2870..683184d5da 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -31,8 +31,8 @@
 
 #include "version_major.h"
 
-#define LIBAVFORMAT_VERSION_MINOR  20
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MINOR  21
+#define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.35.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.or

[FFmpeg-devel] [PATCH v9 5/5] fate/jpegxl: add Jpeg XL demux and parse FATE test

2022-03-23 Thread Leo Izen
Add a fate test for the Jpeg XL parser in libavcodec and
its image2 wrapper inside libavformat.
---
 tests/fate/image.mak| 10 ++
 tests/ref/fate/jxl-parse-codestream |  6 ++
 tests/ref/fate/jxl-parse-container  |  6 ++
 3 files changed, 22 insertions(+)
 create mode 100644 tests/ref/fate/jxl-parse-codestream
 create mode 100644 tests/ref/fate/jxl-parse-container

diff --git a/tests/fate/image.mak b/tests/fate/image.mak
index 573d398915..15b6145c58 100644
--- a/tests/fate/image.mak
+++ b/tests/fate/image.mak
@@ -357,6 +357,16 @@ FATE_JPEGLS-$(call DEMDEC, IMAGE2, JPEGLS) += 
$(FATE_JPEGLS)
 FATE_IMAGE += $(FATE_JPEGLS-yes)
 fate-jpegls: $(FATE_JPEGLS-yes)
 
+FATE_JPEGXL += fate-jxl-parse-codestream
+fate-jxl-parse-codestream: CMD = framecrc -i $(TARGET_SAMPLES)/jxl/belgium.jxl 
-c:v copy
+
+FATE_JPEGXL += fate-jxl-parse-container
+fate-jxl-parse-container: CMD = framecrc -i 
$(TARGET_SAMPLES)/jxl/lenna-256.jxl -c:v copy
+
+FATE_JPEGXL-$(call DEMDEC, IMAGE2) += $(FATE_JPEGXL)
+FATE_IMAGE += $(FATE_JPEGXL-yes)
+fate-jxl: $(FATE_JPEGXL-yes)
+
 FATE_IMAGE-$(call DEMDEC, IMAGE2, QDRAW) += fate-pict
 fate-pict: CMD = framecrc -i $(TARGET_SAMPLES)/quickdraw/TRU256.PCT -pix_fmt 
rgb24
 
diff --git a/tests/ref/fate/jxl-parse-codestream 
b/tests/ref/fate/jxl-parse-codestream
new file mode 100644
index 00..b2fe5035ac
--- /dev/null
+++ b/tests/ref/fate/jxl-parse-codestream
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 768x512
+#sar 0: 0/1
+0,  0,  0,1,   32, 0xa2930a20
diff --git a/tests/ref/fate/jxl-parse-container 
b/tests/ref/fate/jxl-parse-container
new file mode 100644
index 00..99233d612a
--- /dev/null
+++ b/tests/ref/fate/jxl-parse-container
@@ -0,0 +1,6 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: jpegxl
+#dimensions 0: 256x256
+#sar 0: 0/1
+0,  0,  0,1, 8088, 0xbbfea9bd
-- 
2.35.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 2/2] avformat/aiffdec: check allocated size for overflow

2022-03-23 Thread Andreas Rheinhardt
Michael Niedermayer:
> Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in type 
> 'int'
> Fixes: 
> 45891/clusterfuzz-testcase-minimized-ffmpeg_dem_AIFF_fuzzer-6159183893889024
> 
> Found-by: continuous fuzzing process 
> https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer 
> ---
>  libavformat/aiffdec.c | 7 ++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
> index 3634bb4960..c2b8e0dede 100644
> --- a/libavformat/aiffdec.c
> +++ b/libavformat/aiffdec.c
> @@ -72,7 +72,12 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
>  /* Metadata string read */
>  static void get_meta(AVFormatContext *s, const char *key, int size)
>  {
> -uint8_t *str = av_malloc(size+1);
> +uint8_t *str;
> +
> +if (size == INT_MAX)
> +return;
> +
> +str = av_malloc(size+1);
>  
>  if (str) {
>  int res = avio_read(s->pb, str, size);

If a size of INT_MAX is legal, then you can just use "size + 1U" to
avoid the wraparound. (The allocation will then fail with the default
value of max_alloc_size and in this case the avio_skip() will be
executed, so that we don't lose sync (your patch does that).)
Looking at get_tag() shows that the size actually comes from a uint32_t
which gets truncated to INT_MAX if it is not representable in an int. I
don't know whether the specs mandate this behaviour (probably not, so
one loses sync). If one wanted to impose an arbitrary limit, I will use
something much smaller than INT_MAX.

- 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] avformat/mov: Initialize padding of buffer

2022-03-23 Thread Andreas Rheinhardt
Fixes ticket #9695.

Signed-off-by: Andreas Rheinhardt 
---
No value read from the padding is actually used at all;
Valgrind is smart enough to detect this and not warn about this.
MemorySanitizer is unfortunately not. Do we treat such issues
as real or just close them as false positives?

 libavformat/mov.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 6c847de164..ff2824abad 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -2923,6 +2923,7 @@ static int mov_read_stsz(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 av_log(c->fc, AV_LOG_WARNING, "STSZ atom truncated\n");
 return 0;
 }
+memset(buf + num_bytes, 0, AV_INPUT_BUFFER_PADDING_SIZE);
 
 init_get_bits(&gb, buf, 8*num_bytes);
 
-- 
2.32.0

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

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


Re: [FFmpeg-devel] [PATCH v9 1/1] avformat: Add IPFS protocol support.

2022-03-23 Thread Mark Gaiser
On Fri, Mar 18, 2022 at 3:59 PM Mark Gaiser  wrote:

> On Fri, Mar 18, 2022 at 3:50 PM Mark Gaiser  wrote:
>
>> This patch adds support for:
>> - ffplay ipfs://
>> - ffplay ipns://
>>
>> IPFS data can be played from so called "ipfs gateways".
>> A gateway is essentially a webserver that gives access to the
>> distributed IPFS network.
>>
>> This protocol support (ipfs and ipns) therefore translates
>> ipfs:// and ipns:// to a http:// url. This resulting url is
>> then handled by the http protocol. It could also be https
>> depending on the gateway provided.
>>
>> To use this protocol, a gateway must be provided.
>> If you do nothing it will try to find it in your
>> $HOME/.ipfs/gateway file. The ways to set it manually are:
>> 1. Define a -gateway  to the gateway.
>> 2. Define $IPFS_GATEWAY with the full http link to the gateway.
>> 3. Define $IPFS_PATH and point it to the IPFS data path.
>> 4. Have IPFS running in your local user folder (under $HOME/.ipfs).
>>
>> Signed-off-by: Mark Gaiser 
>> ---
>>  configure |   2 +
>>  doc/protocols.texi|  30 
>>  libavformat/Makefile  |   2 +
>>  libavformat/ipfsgateway.c | 310 ++
>>  libavformat/protocols.c   |   2 +
>>  5 files changed, 346 insertions(+)
>>  create mode 100644 libavformat/ipfsgateway.c
>>
>> diff --git a/configure b/configure
>> index 5b19a35f59..6ff09e7974 100755
>> --- a/configure
>> +++ b/configure
>> @@ -3585,6 +3585,8 @@ udp_protocol_select="network"
>>  udplite_protocol_select="network"
>>  unix_protocol_deps="sys_un_h"
>>  unix_protocol_select="network"
>> +ipfs_protocol_select="https_protocol"
>> +ipns_protocol_select="https_protocol"
>>
>>  # external library protocols
>>  libamqp_protocol_deps="librabbitmq"
>> diff --git a/doc/protocols.texi b/doc/protocols.texi
>> index d207df0b52..7c9c0a4808 100644
>> --- a/doc/protocols.texi
>> +++ b/doc/protocols.texi
>> @@ -2025,5 +2025,35 @@ decoding errors.
>>
>>  @end table
>>
>> +@section ipfs
>> +
>> +InterPlanetary File System (IPFS) protocol support. One can access files
>> stored
>> +on the IPFS network through so called gateways. Those are http(s)
>> endpoints.
>> +This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to
>> be send
>> +to such a gateway. Users can (and should) host their own node which
>> means this
>> +protocol will use your local machine gateway to access files on the IPFS
>> network.
>> +
>> +If a user doesn't have a node of their own then the public gateway
>> dweb.link is
>> +used by default.
>> +
>> +You can use this protocol in 2 ways. Using IPFS:
>> +@example
>> +ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
>> +@end example
>> +
>> +Or the IPNS protocol (IPNS is mutable IPFS):
>> +@example
>> +ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
>> +@end example
>> +
>> +You can also change the gateway to be used:
>> +
>> +@table @option
>> +
>> +@item gateway
>> +Defines the gateway to use. When nothing is provided the protocol will
>> first try
>> +your local gateway. If that fails dweb.link will be used.
>> +
>> +@end table
>>
>>  @c man end PROTOCOLS
>> diff --git a/libavformat/Makefile b/libavformat/Makefile
>> index 3dc6a479cc..4edce8420f 100644
>> --- a/libavformat/Makefile
>> +++ b/libavformat/Makefile
>> @@ -656,6 +656,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) +=
>> srtpproto.o srtp.o
>>  OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
>>  OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
>>  OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
>> +OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
>> +OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
>>  TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
>>  TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
>>  TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
>> diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
>> new file mode 100644
>> index 00..2b2905d2c2
>> --- /dev/null
>> +++ b/libavformat/ipfsgateway.c
>> @@ -0,0 +1,310 @@
>> +/*
>> + * IPFS and IPNS protocol support through IPFS Gateway.
>> + * Copyright (c) 2022 Mark Gaiser
>> + *
>> + * 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, Bos

Re: [FFmpeg-devel] [PATCH v7 1/5] avcodec/jpegxl: add Jpeg XL image codec and parser

2022-03-23 Thread Anton Khirnov
Quoting Leo Izen (2022-03-19 18:26:41)
> +
> +#define jxl_bits(n) jpegxl_get_bits(NULL, jxlr, (n))
   
IIUC this leads to av_log(NULL). Please no more of these, we are trying
to remove them.

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

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


Re: [FFmpeg-devel] [PATCH v7 4/5] avformat/image2: add Jpeg XL as image2 format

2022-03-23 Thread Anton Khirnov
Quoting Leo Izen (2022-03-19 18:26:44)
> This commit adds support to libavformat for muxing
> and demuxing Jpeg XL images as image2 streams.
> ---
>  libavformat/allformats.c |  1 +
>  libavformat/img2.c   |  1 +
>  libavformat/img2dec.c| 21 +
>  libavformat/img2enc.c|  6 +++---
>  libavformat/mov.c|  1 +
>  libavformat/version.h|  4 ++--
>  6 files changed, 29 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 587ad59b3c..941f3643f8 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -510,6 +510,7 @@ extern const AVInputFormat  ff_image_gif_pipe_demuxer;
>  extern const AVInputFormat  ff_image_j2k_pipe_demuxer;
>  extern const AVInputFormat  ff_image_jpeg_pipe_demuxer;
>  extern const AVInputFormat  ff_image_jpegls_pipe_demuxer;
> +extern const AVInputFormat  ff_image_jpegxl_pipe_demuxer;
>  extern const AVInputFormat  ff_image_pam_pipe_demuxer;
>  extern const AVInputFormat  ff_image_pbm_pipe_demuxer;
>  extern const AVInputFormat  ff_image_pcx_pipe_demuxer;
> diff --git a/libavformat/img2.c b/libavformat/img2.c
> index 4153102c92..13b1b997b8 100644
> --- a/libavformat/img2.c
> +++ b/libavformat/img2.c
> @@ -87,6 +87,7 @@ const IdStrMap ff_img_tags[] = {
>  { AV_CODEC_ID_GEM,"img"  },
>  { AV_CODEC_ID_GEM,"ximg" },
>  { AV_CODEC_ID_GEM,"timg" },
> +{ AV_CODEC_ID_JPEGXL, "jxl"  },
>  { AV_CODEC_ID_NONE,   NULL   }
>  };
>  
> diff --git a/libavformat/img2dec.c b/libavformat/img2dec.c
> index b9c06c5b54..32cadacb9d 100644
> --- a/libavformat/img2dec.c
> +++ b/libavformat/img2dec.c
> @@ -32,6 +32,7 @@
>  #include "libavutil/parseutils.h"
>  #include "libavutil/intreadwrite.h"
>  #include "libavcodec/gif.h"
> +#include "libavcodec/jpegxl.h"
>  #include "avformat.h"
>  #include "avio_internal.h"
>  #include "internal.h"
> @@ -836,6 +837,25 @@ static int jpegls_probe(const AVProbeData *p)
>  return 0;
>  }
>  
> +static int jpegxl_probe(const AVProbeData *p)
> +{
> +const uint8_t *b = p->buf;
> +
> +/* ISOBMFF-based container */
> +/* 0x4a584c20 == "JXL " */
> +if (AV_RL64(b) == FF_JPEGXL_CONTAINER_SIGNATURE_LE)
> +return AVPROBE_SCORE_EXTENSION + 1;
> +#if CONFIG_JPEGXL_PARSER
> +/* Raw codestreams all start with 0xff0a */
> +if (AV_RL16(b) != FF_JPEGXL_CODESTREAM_SIGNATURE_LE)
> +return 0;
> +if (avpriv_jpegxl_verify_codestream_header(NULL, p->buf, p->buf_size) == 
> 0)

This function is way too complicated for a probe function. Can you think
of something simpler?

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

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


Re: [FFmpeg-devel] [PATCH 1/6] avcodec/internal, avfilter/qp_table: Remove unused FF_QSCALE_TYPEs

2022-03-23 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/internal.h  | 2 --
>  libavfilter/qp_table.h | 4 
>  2 files changed, 6 deletions(-)
> 
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index badca4c9dd..f9809926b8 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -37,8 +37,6 @@
>  
>  #define FF_QSCALE_TYPE_MPEG1 0
>  #define FF_QSCALE_TYPE_MPEG2 1
> -#define FF_QSCALE_TYPE_H264  2
> -#define FF_QSCALE_TYPE_VP56  3
>  
>  #define FF_SANE_NB_CHANNELS 512U
>  
> diff --git a/libavfilter/qp_table.h b/libavfilter/qp_table.h
> index 4758ee8538..169a7a7fea 100644
> --- a/libavfilter/qp_table.h
> +++ b/libavfilter/qp_table.h
> @@ -33,16 +33,12 @@ int ff_qp_table_extract(AVFrame *frame, int8_t **table, 
> int *table_w, int *table
>  
>  /**
>   * Normalize the qscale factor
> - * FIXME the H264 qscale is a log based scale, mpeg1/2 is not, the code below
> - *   cannot be optimal
>   */
>  static inline int ff_norm_qscale(int qscale, int type)
>  {
>  switch (type) {
>  case FF_QSCALE_TYPE_MPEG1: return qscale;
>  case FF_QSCALE_TYPE_MPEG2: return qscale >> 1;
> -case FF_QSCALE_TYPE_H264:  return qscale >> 2;
> -case FF_QSCALE_TYPE_VP56:  return (63 - qscale + 2) >> 2;
>  }
>  return qscale;
>  }

Will apply this patchset tomorrow unless there are objections.

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/bsf: Add FFBitStreamFilter, hide internals of BSFs

2022-03-23 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> This patch is analogous to 20f972701806be20a77f808db332d9489343bb78:
> It hides the internal part of AVBitStreamFilter by adding a new
> internal structure FFBitStreamFilter (declared in bsf_internal.h)
> that has an AVBitStreamFilter as its first member; the internal
> part of AVBitStreamFilter is moved to this new structure.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  configure  |  4 +-
>  libavcodec/aac_adtstoasc_bsf.c |  6 +-
>  libavcodec/av1_frame_merge_bsf.c   |  6 +-
>  libavcodec/av1_frame_split_bsf.c   |  6 +-
>  libavcodec/av1_metadata_bsf.c  |  9 +--
>  libavcodec/bitstream_filters.c | 85 +-
>  libavcodec/bsf.c   | 38 ++--
>  libavcodec/bsf.h   | 14 -
>  libavcodec/bsf_internal.h  | 13 
>  libavcodec/cbs_bsf.h   |  6 +-
>  libavcodec/chomp_bsf.c |  4 +-
>  libavcodec/dca_core_bsf.c  |  8 +--
>  libavcodec/dump_extradata_bsf.c|  6 +-
>  libavcodec/dv_error_marker_bsf.c   |  8 +--
>  libavcodec/eac3_core_bsf.c |  8 +--
>  libavcodec/extract_extradata_bsf.c |  8 +--
>  libavcodec/filter_units_bsf.c  |  8 +--
>  libavcodec/h264_metadata_bsf.c |  9 +--
>  libavcodec/h264_mp4toannexb_bsf.c  |  6 +-
>  libavcodec/h264_redundant_pps_bsf.c|  7 ++-
>  libavcodec/h265_metadata_bsf.c |  9 +--
>  libavcodec/hapqa_extract_bsf.c | 10 +--
>  libavcodec/hevc_mp4toannexb_bsf.c  |  6 +-
>  libavcodec/imx_dump_header_bsf.c   |  8 +--
>  libavcodec/mjpeg2jpeg_bsf.c|  6 +-
>  libavcodec/mjpega_dump_header_bsf.c|  8 +--
>  libavcodec/movsub_bsf.c|  8 +--
>  libavcodec/mp3_header_decompress_bsf.c |  8 +--
>  libavcodec/mpeg2_metadata_bsf.c| 10 +--
>  libavcodec/mpeg4_unpack_bframes_bsf.c  |  6 +-
>  libavcodec/noise_bsf.c |  7 +--
>  libavcodec/null_bsf.c  |  5 +-
>  libavcodec/opus_metadata_bsf.c |  8 +--
>  libavcodec/pcm_rechunk_bsf.c   |  8 +--
>  libavcodec/prores_metadata_bsf.c   | 12 ++--
>  libavcodec/remove_extradata_bsf.c  |  6 +-
>  libavcodec/setts_bsf.c |  6 +-
>  libavcodec/trace_headers_bsf.c |  6 +-
>  libavcodec/truehd_core_bsf.c   |  6 +-
>  libavcodec/vp9_metadata_bsf.c  | 12 ++--
>  libavcodec/vp9_raw_reorder_bsf.c   |  6 +-
>  libavcodec/vp9_superframe_bsf.c|  6 +-
>  libavcodec/vp9_superframe_split_bsf.c  |  6 +-
>  43 files changed, 219 insertions(+), 213 deletions(-)
> 
> diff --git a/configure b/configure
> index a7953ffc16..e4d36aa639 100755
> --- a/configure
> +++ b/configure
> @@ -3992,7 +3992,7 @@ CODEC_LIST="
>  $DECODER_LIST
>  "
>  PARSER_LIST=$(find_things_extern parser AVCodecParser libavcodec/parsers.c)
> -BSF_LIST=$(find_things_extern bsf AVBitStreamFilter 
> libavcodec/bitstream_filters.c)
> +BSF_LIST=$(find_things_extern bsf FFBitStreamFilter 
> libavcodec/bitstream_filters.c)
>  HWACCEL_LIST=$(find_things_extern hwaccel AVHWAccel libavcodec/hwaccels.h)
>  PROTOCOL_LIST=$(find_things_extern protocol URLProtocol 
> libavformat/protocols.c)
>  
> @@ -7869,7 +7869,7 @@ print_enabled_components(){
>  print_enabled_components libavfilter/filter_list.c AVFilter filter_list 
> $FILTER_LIST
>  print_enabled_components libavcodec/codec_list.c FFCodec codec_list 
> $CODEC_LIST
>  print_enabled_components libavcodec/parser_list.c AVCodecParser parser_list 
> $PARSER_LIST
> -print_enabled_components libavcodec/bsf_list.c AVBitStreamFilter 
> bitstream_filters $BSF_LIST
> +print_enabled_components libavcodec/bsf_list.c FFBitStreamFilter 
> bitstream_filters $BSF_LIST
>  print_enabled_components libavformat/demuxer_list.c AVInputFormat 
> demuxer_list $DEMUXER_LIST
>  print_enabled_components libavformat/muxer_list.c AVOutputFormat muxer_list 
> $MUXER_LIST
>  print_enabled_components libavdevice/indev_list.c AVInputFormat indev_list 
> $INDEV_LIST
> diff --git a/libavcodec/aac_adtstoasc_bsf.c b/libavcodec/aac_adtstoasc_bsf.c
> index 267ef97572..d32fcc5f9d 100644
> --- a/libavcodec/aac_adtstoasc_bsf.c
> +++ b/libavcodec/aac_adtstoasc_bsf.c
> @@ -148,10 +148,10 @@ static const enum AVCodecID codec_ids[] = {
>  AV_CODEC_ID_AAC, AV_CODEC_ID_NONE,
>  };
>  
> -const AVBitStreamFilter ff_aac_adtstoasc_bsf = {
> -.name   = "aac_adtstoasc",
> +const FFBitStreamFilter ff_aac_adtstoasc_bsf = {
> +.p.name = "aac_adtstoasc",
> +.p.codec_ids= codec_ids,
>  .priv_data_size = sizeof(AACBSFContext),
>  .init   = aac_adtstoasc_init,
>  .filter = aac_adtstoasc_filter,
> -.codec_ids  = codec_ids,
>  };
> diff --git a/libavcodec/av1_frame_merge_bsf.c 
> b/libavcodec/av1_frame_merge_bsf.c
> index 19b9cd01a8..4c54f2167e 100644
> --- a/libavcodec/av1_frame_merge_bsf.c
> +++ b/libavcodec/av1_frame_merge_

[FFmpeg-devel] [PATCH] avcodec/dxva2: don't call GetDesc on a NULL ID3D11VideoDecoderOutputView

2022-03-23 Thread Steve Lhomme
We should return 0 and assert there's something wrong. This is how it's done
with the other DXVA variants.

It fixes bad reference usage in http://www.gbbsoft.pl/!download/!/Film1.mp4
It's using a frame that doesn't have any data[] fields set (yet?).

Signed-off-by: Steve Lhomme 
---
 libavcodec/dxva2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index 568d686f39..043497b74f 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -777,7 +777,7 @@ unsigned ff_dxva2_get_surface_index(const AVCodecContext 
*avctx,
 #if CONFIG_D3D11VA
 if (avctx->pix_fmt == AV_PIX_FMT_D3D11)
 return (intptr_t)frame->data[1];
-if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD) {
+if (avctx->pix_fmt == AV_PIX_FMT_D3D11VA_VLD && surface) {
 D3D11_VIDEO_DECODER_OUTPUT_VIEW_DESC viewDesc;
 ID3D11VideoDecoderOutputView_GetDesc((ID3D11VideoDecoderOutputView*) 
surface, &viewDesc);
 return viewDesc.Texture2D.ArraySlice;
-- 
2.29.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 1/2] avcodec/av1: only set the private context pix_fmt field if get_pixel_format() succeeds

2022-03-23 Thread Michael Niedermayer
On Tue, Mar 22, 2022 at 04:10:59PM -0300, James Almer wrote:
> Otherwise get_pixel_format() will not be called when parsing a subsequent 
> Sequence
> Header in non hwaccel enabled scenarios, allowing frame parsing when it 
> shouldn't.
> 
> This prevents the scenario seqhdr -> frame_hdr/redundant_frame_hdr -> seqhdr 
> ->
> redundant_frame_hdr from having the latter redundant frame header parsed as 
> if it
> was a frame header by the decoder because the former was discarded.
> Since CBS did not discard it, the latter redundant frame header is output 
> with a
> zeroed AV1RawFrameHeader struct, which can have undesired results, like 
> division
> by zero with fields normally guaranteed to be anything else.
> 
> Signed-off-by: James Almer 
> ---
>  libavcodec/av1dec.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)

This patchset fixes the 2 issues too

thx

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

Its not that you shouldnt use gotos but rather that you should write
readable code and code with gotos often but not always is less readable


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 v2] avcodec/libsvtav1: pass color description info

2022-03-23 Thread James Almer

On 3/22/2022 6:54 PM, Jan Ekström wrote:

From: Christopher Degawa 

Signed-off-by: Christopher Degawa 
---
  libavcodec/libsvtav1.c | 10 ++
  1 file changed, 10 insertions(+)

diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index f02e410f69..6cf280377e 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -228,6 +228,16 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
*param,
  return AVERROR(EINVAL);
  }
  
+param->color_primaries  = avctx->color_primaries;

+param->matrix_coefficients  = (desc->flags & AV_PIX_FMT_FLAG_RGB) ?
+  AVCOL_SPC_RGB : avctx->colorspace;
+param->transfer_characteristics = avctx->color_trc;
+
+if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
+param->color_range = avctx->color_range == AVCOL_RANGE_JPEG;
+else
+param->color_range = !!(desc->flags & AV_PIX_FMT_FLAG_RGB);
+
  if (avctx->profile != FF_PROFILE_UNKNOWN)
  param->profile = avctx->profile;
  


LGTM
___
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 v7 1/5] avcodec/jpegxl: add Jpeg XL image codec and parser

2022-03-23 Thread Leo Izen


On 3/23/22 07:36, Anton Khirnov wrote:

Quoting Leo Izen (2022-03-19 18:26:41)

+
+#define jxl_bits(n) jpegxl_get_bits(NULL, jxlr, (n))

    
IIUC this leads to av_log(NULL). Please no more of these, we are trying
to remove them.

The prober functions in the image2 demuxer don't pass an AVFormatContext 
to the prober. I'd be happy to change this if the probers could see the 
AVFormatContext in img2dec.c.


Leo Izen (thebombzen)
___
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 v7 4/5] avformat/image2: add Jpeg XL as image2 format

2022-03-23 Thread Leo Izen

On 3/23/22 07:38, Anton Khirnov wrote:

+    return 0;
+    if (avpriv_jpegxl_verify_codestream_header(NULL, p->buf, 
p->buf_size) == 0)

This function is way too complicated for a probe function. Can you think
of something simpler?
This is necessary to prevent the probetest from returning false 
positives. My original patch lacked something like this and it was 
rejected on those grounds.


Leo Izen (thebombzen)


___
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/2] avformat/aiffdec: check allocated size for overflow

2022-03-23 Thread Michael Niedermayer
On Wed, Mar 23, 2022 at 12:07:25PM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in 
> > type 'int'
> > Fixes: 
> > 45891/clusterfuzz-testcase-minimized-ffmpeg_dem_AIFF_fuzzer-6159183893889024
> > 
> > Found-by: continuous fuzzing process 
> > https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  libavformat/aiffdec.c | 7 ++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
> > index 3634bb4960..c2b8e0dede 100644
> > --- a/libavformat/aiffdec.c
> > +++ b/libavformat/aiffdec.c
> > @@ -72,7 +72,12 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
> >  /* Metadata string read */
> >  static void get_meta(AVFormatContext *s, const char *key, int size)
> >  {
> > -uint8_t *str = av_malloc(size+1);
> > +uint8_t *str;
> > +
> > +if (size == INT_MAX)
> > +return;
> > +
> > +str = av_malloc(size+1);
> >  
> >  if (str) {
> >  int res = avio_read(s->pb, str, size);
> 
> If a size of INT_MAX is legal, then you can just use "size + 1U" to
> avoid the wraparound. (The allocation will then fail with the default
> value of max_alloc_size and in this case the avio_skip() will be
> executed, so that we don't lose sync (your patch does that).)

> Looking at get_tag() shows that the size actually comes from a uint32_t
> which gets truncated to INT_MAX if it is not representable in an int. I
> don't know whether the specs mandate this behaviour (probably not, so
> one loses sync). If one wanted to impose an arbitrary limit, I will use
> something much smaller than INT_MAX.

The goal of my patch was to fix the undefined behavior.
You are very correct that aiffdec has other bugs.

ill send a more complete set of fixes 

thx

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

There will always be a question for which you do not know the correct answer.


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


[FFmpeg-devel] [PATCH] dxva2_hevc: don't use frames as reference if they are not marked as such

2022-03-23 Thread Steve Lhomme
Similar to how a frame is considered for referencing for the RefPicList array.
This will do the same for RefPicSetStCurrBefore, RefPicSetStCurrAfter and
RefPicSetLtCurr.

Fixes playback of http://www.gbbsoft.pl/!download/!/Film1.mp4
Ref. VLC issue https://code.videolan.org/videolan/vlc/-/issues/26738

Signed-off-by: Steve Lhomme 
---
 libavcodec/dxva2_hevc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index c91bcf3eeb..6b239d9917 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -184,7 +184,7 @@ static void fill_picture_parameters(const AVCodecContext 
*avctx, AVDXVAContext *
 const HEVCFrame *frame = NULL; \
 while (!frame && j < rpl->nb_refs) \
 frame = rpl->ref[j++]; \
-if (frame) \
+if (frame && frame->flags & (HEVC_FRAME_FLAG_LONG_REF | 
HEVC_FRAME_FLAG_SHORT_REF)) \
 pp->ref_list[i] = get_refpic_index(pp, 
ff_dxva2_get_surface_index(avctx, ctx, frame->frame)); \
 else \
 pp->ref_list[i] = 0xff; \
-- 
2.29.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] dxva2_hevc: don't use frames as reference if they are not marked as such

2022-03-23 Thread Steve Lhomme
This makes my previous path "avcodec/dxva2: don't call GetDesc on a NULL 
ID3D11VideoDecoderOutputView" unnecessary. While it avoids a crash in 
release builds, it should still assert because a bogus reference is used.


With this patch no bogus reference is used for that sample file, and 
playback seems correct.


On 2022-03-23 14:54, Steve Lhomme wrote:

Similar to how a frame is considered for referencing for the RefPicList array.
This will do the same for RefPicSetStCurrBefore, RefPicSetStCurrAfter and
RefPicSetLtCurr.

Fixes playback of http://www.gbbsoft.pl/!download/!/Film1.mp4
Ref. VLC issue https://code.videolan.org/videolan/vlc/-/issues/26738

Signed-off-by: Steve Lhomme 
---
  libavcodec/dxva2_hevc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index c91bcf3eeb..6b239d9917 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -184,7 +184,7 @@ static void fill_picture_parameters(const AVCodecContext 
*avctx, AVDXVAContext *
  const HEVCFrame *frame = NULL; \
  while (!frame && j < rpl->nb_refs) \
  frame = rpl->ref[j++]; \
-if (frame) \
+if (frame && frame->flags & (HEVC_FRAME_FLAG_LONG_REF | 
HEVC_FRAME_FLAG_SHORT_REF)) \
  pp->ref_list[i] = get_refpic_index(pp, 
ff_dxva2_get_surface_index(avctx, ctx, frame->frame)); \
  else \
  pp->ref_list[i] = 0xff; \
--
2.29.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 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] avformat/aiffdec: avoid integer overflow in get_meta()

2022-03-23 Thread Michael Niedermayer
Fixes: signed integer overflow: 2147483647 + 1 cannot be represented in type 
'int'
Fixes: 
45891/clusterfuzz-testcase-minimized-ffmpeg_dem_AIFF_fuzzer-6159183893889024

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

diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 3634bb4960..5236cc2807 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -72,7 +72,7 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
 /* Metadata string read */
 static void get_meta(AVFormatContext *s, const char *key, int size)
 {
-uint8_t *str = av_malloc(size+1);
+uint8_t *str = av_malloc(size+1U);
 
 if (str) {
 int res = avio_read(s->pb, str, size);
-- 
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] dxva2_hevc: don't use frames as reference if they are not marked as such

2022-03-23 Thread Hendrik Leppkes
On Wed, Mar 23, 2022 at 2:54 PM Steve Lhomme  wrote:
>
> Similar to how a frame is considered for referencing for the RefPicList array.
> This will do the same for RefPicSetStCurrBefore, RefPicSetStCurrAfter and
> RefPicSetLtCurr.
>
> Fixes playback of http://www.gbbsoft.pl/!download/!/Film1.mp4
> Ref. VLC issue https://code.videolan.org/videolan/vlc/-/issues/26738
>
> Signed-off-by: Steve Lhomme 
> ---
>  libavcodec/dxva2_hevc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
> index c91bcf3eeb..6b239d9917 100644
> --- a/libavcodec/dxva2_hevc.c
> +++ b/libavcodec/dxva2_hevc.c
> @@ -184,7 +184,7 @@ static void fill_picture_parameters(const AVCodecContext 
> *avctx, AVDXVAContext *
>  const HEVCFrame *frame = NULL; \
>  while (!frame && j < rpl->nb_refs) \
>  frame = rpl->ref[j++]; \
> -if (frame) \
> +if (frame && frame->flags & (HEVC_FRAME_FLAG_LONG_REF | 
> HEVC_FRAME_FLAG_SHORT_REF)) \
>  pp->ref_list[i] = get_refpic_index(pp, 
> ff_dxva2_get_surface_index(avctx, ctx, frame->frame)); \
>  else \
>  pp->ref_list[i] = 0xff; \
> --
> 2.29.2
>

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

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


Re: [FFmpeg-devel] [PATCH v2] avcodec/libsvtav1: pass color description info

2022-03-23 Thread Jan Ekström
On Wed, Mar 23, 2022 at 2:57 PM James Almer  wrote:
>
> On 3/22/2022 6:54 PM, Jan Ekström wrote:
> > From: Christopher Degawa 
> >
> > Signed-off-by: Christopher Degawa 
> > ---
> >   libavcodec/libsvtav1.c | 10 ++
> >   1 file changed, 10 insertions(+)
> >
> > diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
> > index f02e410f69..6cf280377e 100644
> > --- a/libavcodec/libsvtav1.c
> > +++ b/libavcodec/libsvtav1.c
> > @@ -228,6 +228,16 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
> > *param,
> >   return AVERROR(EINVAL);
> >   }
> >
> > +param->color_primaries  = avctx->color_primaries;
> > +param->matrix_coefficients  = (desc->flags & AV_PIX_FMT_FLAG_RGB) ?
> > +  AVCOL_SPC_RGB : avctx->colorspace;
> > +param->transfer_characteristics = avctx->color_trc;
> > +
> > +if (avctx->color_range != AVCOL_RANGE_UNSPECIFIED)
> > +param->color_range = avctx->color_range == AVCOL_RANGE_JPEG;
> > +else
> > +param->color_range = !!(desc->flags & AV_PIX_FMT_FLAG_RGB);
> > +
> >   if (avctx->profile != FF_PROFILE_UNKNOWN)
> >   param->profile = avctx->profile;
> >
>
> LGTM

Thanks, applied as 51c0b9e829be99093ae8d1e642a8cf99896529b8 .

Jan
___
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 v9 1/5] avcodec/jpegxl: add Jpeg XL image codec and parser

2022-03-23 Thread Andreas Rheinhardt
Leo Izen:
> This commit adds support to libavcodec to read and parse
> encoded Jpeg XL images. Jpeg XL is intended to be an
> extended-life replacement to legacy mjpeg.
> ---
>  MAINTAINERS|   2 +
>  libavcodec/Makefile|   1 +
>  libavcodec/codec_desc.c|   9 +
>  libavcodec/codec_id.h  |   1 +
>  libavcodec/jpegxl.h|  43 ++
>  libavcodec/jpegxl_parser.c | 941 +
>  libavcodec/parsers.c   |   1 +
>  libavcodec/version.h   |   2 +-
>  8 files changed, 999 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/jpegxl.h
>  create mode 100644 libavcodec/jpegxl_parser.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 931cf4bd2c..2e0de9e224 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -188,6 +188,7 @@ Codecs:
>interplayvideo.c  Mike Melanson
>jni*, ffjni*  Matthieu Bouron
>jpeg2000* Nicolas Bertrand
> +  jpegxl.h, jpegxl_parser.c Leo Izen
>jvdec.c   Peter Ross
>lcl*.cRoberto Togni, Reimar Doeffinger
>libcelt_dec.c Nicolas George
> @@ -616,6 +617,7 @@ Haihao Xiang (haihao) 1F0C 31E8 B4FE F7A4 4DC1 
> DC99 E0F5 76D4 76FC 437F
>  Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 
> D368
>  James Almer   7751 2E8C FD94 A169 57E6 9A7A 1463 01AD 7376 
> 59E0
>  Jean Delvare  7CA6 9F44 60F1 BDC4 1FD2 C858 A552 6B9B B3CD 
> 4E6A
> +Leo Izen (thebombzen) B6FD 3CFC 7ACF 83FC 9137 6945 5A71 C331 FD2F 
> A19A
>  Loren Merritt ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 
> 56DE
>  Lynne FE50 139C 6805 72CA FD52 1F8D A2FE A5F0 3F03 
> 4464
>  Michael Niedermayer   9FF2 128B 147E F673 0BAD F133 611E C787 040B 
> 0FAB
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index fb8b0e824b..3723601b3d 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -44,6 +44,7 @@ OBJS = ac3_parser.o 
> \
> dv_profile.o \
> encode.o \
> imgconvert.o \
> +   jpegxl_parser.o  \
> jni.o\
> mathtables.o \
> mediacodec.o \
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 81f3b3c640..1b82870aaa 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1863,6 +1863,15 @@ static const AVCodecDescriptor codec_descriptors[] = {
>  .long_name = NULL_IF_CONFIG_SMALL("GEM Raster image"),
>  .props = AV_CODEC_PROP_LOSSY,
>  },
> +{
> +.id= AV_CODEC_ID_JPEGXL,
> +.type  = AVMEDIA_TYPE_VIDEO,
> +.name  = "jpegxl",
> +.long_name = NULL_IF_CONFIG_SMALL("JPEG XL"),
> +.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY |
> + AV_CODEC_PROP_LOSSLESS,
> +.mime_types= MT("image/jxl"),
> +},
>  
>  /* various PCM "codecs" */
>  {
> diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
> index 3ffb9bd22e..dbc4f3a208 100644
> --- a/libavcodec/codec_id.h
> +++ b/libavcodec/codec_id.h
> @@ -308,6 +308,7 @@ enum AVCodecID {
>  AV_CODEC_ID_SIMBIOSIS_IMX,
>  AV_CODEC_ID_SGA_VIDEO,
>  AV_CODEC_ID_GEM,
> +AV_CODEC_ID_JPEGXL,
>  
>  /* various PCM "codecs" */
>  AV_CODEC_ID_FIRST_AUDIO = 0x1, ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/jpegxl.h b/libavcodec/jpegxl.h
> new file mode 100644
> index 00..4f93c99687
> --- /dev/null
> +++ b/libavcodec/jpegxl.h
> @@ -0,0 +1,43 @@
> +/*
> + * JPEG XL header
> + * Copyright (c) 2021 Leo Izen 
> + *
> + * 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
>

Re: [FFmpeg-devel] [PATCH v9 2/5] avcodec/libjxl: add Jpeg XL decoding via libjxl

2022-03-23 Thread Andreas Rheinhardt
Leo Izen:
> This commit adds decoding support to libavcodec
> for Jpeg XL images via the external library libjxl.
> ---
>  MAINTAINERS   |   1 +
>  configure |   5 +
>  doc/general_contents.texi |   7 +
>  libavcodec/Makefile   |   1 +
>  libavcodec/allcodecs.c|   1 +
>  libavcodec/libjxl.c   |  70 +
>  libavcodec/libjxl.h   |  48 ++
>  libavcodec/libjxldec.c| 302 ++
>  8 files changed, 435 insertions(+)
>  create mode 100644 libavcodec/libjxl.c
>  create mode 100644 libavcodec/libjxl.h
>  create mode 100644 libavcodec/libjxldec.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2e0de9e224..875d25ca89 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -195,6 +195,7 @@ Codecs:
>libcodec2.c   Tomas Härdin
>libdirac* David Conrad
>libdavs2.cHuiwen Ren
> +  libjxl*.c, libjxl.h   Leo Izen
>libgsm.c  Michel Bardiaux
>libkvazaar.c  Arttu Ylä-Outinen
>libopenh264enc.c  Martin Storsjo, Linjie Fu
> diff --git a/configure b/configure
> index a7953ffc16..4e28114d9c 100755
> --- a/configure
> +++ b/configure
> @@ -240,6 +240,7 @@ External library support:
>--enable-libiec61883 enable iec61883 via libiec61883 [no]
>--enable-libilbc enable iLBC de/encoding via libilbc [no]
>--enable-libjack enable JACK audio sound server [no]
> +  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
>--enable-libklvanc   enable Kernel Labs VANC processing [no]
>--enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
>--enable-liblensfun  enable lensfun lens correction [no]
> @@ -1833,6 +1834,7 @@ EXTERNAL_LIBRARY_LIST="
>  libiec61883
>  libilbc
>  libjack
> +libjxl
>  libklvanc
>  libkvazaar
>  libmodplug
> @@ -3329,6 +3331,7 @@ libgsm_ms_decoder_deps="libgsm"
>  libgsm_ms_encoder_deps="libgsm"
>  libilbc_decoder_deps="libilbc"
>  libilbc_encoder_deps="libilbc"
> +libjxl_decoder_deps="libjxl libjxl_threads"
>  libkvazaar_encoder_deps="libkvazaar"
>  libmodplug_demuxer_deps="libmodplug"
>  libmp3lame_encoder_deps="libmp3lame"
> @@ -6541,6 +6544,8 @@ enabled libgsm&& { for gsm_hdr in "gsm.h" 
> "gsm/gsm.h"; do
> check_lib libgsm "${gsm_hdr}" gsm_create 
> -lgsm && break;
> done || die "ERROR: libgsm not found"; }
>  enabled libilbc   && require libilbc ilbc.h WebRtcIlbcfix_InitDecode 
> -lilbc $pthreads_extralibs
> +enabled libjxl&& require_pkg_config libjxl "libjxl >= 0.7.0" 
> jxl/decode.h JxlDecoderVersion &&
> + require_pkg_config libjxl_threads 
> "libjxl_threads >= 0.7.0" jxl/thread_parallel_runner.h JxlThreadParallelRunner
>  enabled libklvanc && require libklvanc libklvanc/vanc.h 
> klvanc_context_create -lklvanc
>  enabled libkvazaar&& require_pkg_config libkvazaar "kvazaar >= 
> 0.8.1" kvazaar.h kvz_api_get
>  enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
> lf_db_new
> diff --git a/doc/general_contents.texi b/doc/general_contents.texi
> index fcd9da1b34..a893347fbe 100644
> --- a/doc/general_contents.texi
> +++ b/doc/general_contents.texi
> @@ -171,6 +171,13 @@ Go to @url{https://github.com/TimothyGu/libilbc} and 
> follow the instructions for
>  installing the library. Then pass @code{--enable-libilbc} to configure to
>  enable it.
>  
> +@section libjxl
> +
> +JPEG XL is an image format intended to fully replace legacy JPEG for an 
> extended
> +period of life. See @url{https://jpegxl.info/} for more information, and see
> +@url{https://github.com/libjxl/libjxl} for the library source. You can pass
> +@code{--enable-libjxl} to configure in order enable the libjxl wrapper.
> +
>  @section libvpx
>  
>  FFmpeg can make use of the libvpx library for VP8/VP9 decoding and encoding.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 3723601b3d..c00b0d3246 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1060,6 +1060,7 @@ OBJS-$(CONFIG_LIBGSM_MS_DECODER)  += libgsmdec.o
>  OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
>  OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
>  OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
> +OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
>  OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
>  OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
>  OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 22d56760ec..a9cd69dfce 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -749,6 +749,7 @@ extern const FFCodec ff_libgsm_ms_encoder;
>  extern const

Re: [FFmpeg-devel] [PATCH v9 3/5] avcodec/libjxl: add Jpeg XL encoding via libjxl

2022-03-23 Thread Andreas Rheinhardt
Leo Izen:
> This commit adds encoding support to libavcodec
> for Jpeg XL images via the external library libjxl.
> ---
>  configure  |   3 +-
>  libavcodec/Makefile|   1 +
>  libavcodec/allcodecs.c |   1 +
>  libavcodec/libjxlenc.c | 385 +
>  4 files changed, 389 insertions(+), 1 deletion(-)
>  create mode 100644 libavcodec/libjxlenc.c
> 
> diff --git a/configure b/configure
> index 4e28114d9c..59095a5866 100755
> --- a/configure
> +++ b/configure
> @@ -240,7 +240,7 @@ External library support:
>--enable-libiec61883 enable iec61883 via libiec61883 [no]
>--enable-libilbc enable iLBC de/encoding via libilbc [no]
>--enable-libjack enable JACK audio sound server [no]
> -  --enable-libjxl  enable JPEG XL decoding via libjxl [no]
> +  --enable-libjxl  enable JPEG XL de/encoding via libjxl [no]
>--enable-libklvanc   enable Kernel Labs VANC processing [no]
>--enable-libkvazaar  enable HEVC encoding via libkvazaar [no]
>--enable-liblensfun  enable lensfun lens correction [no]
> @@ -3332,6 +3332,7 @@ libgsm_ms_encoder_deps="libgsm"
>  libilbc_decoder_deps="libilbc"
>  libilbc_encoder_deps="libilbc"
>  libjxl_decoder_deps="libjxl libjxl_threads"
> +libjxl_encoder_deps="libjxl libjxl_threads"
>  libkvazaar_encoder_deps="libkvazaar"
>  libmodplug_demuxer_deps="libmodplug"
>  libmp3lame_encoder_deps="libmp3lame"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index c00b0d3246..b208cc0097 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1061,6 +1061,7 @@ OBJS-$(CONFIG_LIBGSM_MS_ENCODER)  += libgsmenc.o
>  OBJS-$(CONFIG_LIBILBC_DECODER)+= libilbc.o
>  OBJS-$(CONFIG_LIBILBC_ENCODER)+= libilbc.o
>  OBJS-$(CONFIG_LIBJXL_DECODER) += libjxldec.o libjxl.o
> +OBJS-$(CONFIG_LIBJXL_ENCODER) += libjxlenc.o libjxl.o
>  OBJS-$(CONFIG_LIBKVAZAAR_ENCODER) += libkvazaar.o
>  OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
>  OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index a9cd69dfce..db92fb7af5 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -750,6 +750,7 @@ extern const FFCodec ff_libgsm_ms_decoder;
>  extern const FFCodec ff_libilbc_encoder;
>  extern const FFCodec ff_libilbc_decoder;
>  extern const FFCodec ff_libjxl_decoder;
> +extern const FFCodec ff_libjxl_encoder;
>  extern const FFCodec ff_libmp3lame_encoder;
>  extern const FFCodec ff_libopencore_amrnb_encoder;
>  extern const FFCodec ff_libopencore_amrnb_decoder;
> diff --git a/libavcodec/libjxlenc.c b/libavcodec/libjxlenc.c
> new file mode 100644
> index 00..802a543383
> --- /dev/null
> +++ b/libavcodec/libjxlenc.c
> @@ -0,0 +1,385 @@
> +/*
> + * JPEG XL encoding support via libjxl
> + * Copyright (c) 2021 Leo Izen 
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +/**
> + * @file
> + * JPEG XL encoder using libjxl
> + */
> +
> +#include "libavutil/avutil.h"
> +#include "libavutil/error.h"
> +#include "libavutil/frame.h"
> +#include "libavutil/libm.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "libavutil/pixfmt.h"
> +#include "libavutil/version.h"
> +
> +#include "avcodec.h"
> +#include "codec_internal.h"
> +#include "internal.h"

I think this header is unnecessary.

> +
> +#include 
> +#include 
> +#include "libjxl.h"
> +
> +typedef struct LibJxlEncodeContext {
> +AVClass *class;
> +void *runner;
> +JxlEncoder *encoder;
> +JxlEncoderFrameSettings *options;
> +int effort;
> +float distance;
> +int modular;
> +uint8_t *buffer;
> +size_t buffer_size;
> +} LibJxlEncodeContext;
> +
> +/**
> + * Map a quality setting for -qscale roughly from libjpeg
> + * quality numbers to libjxl's butteraugli distance for
> + * photographic content.
> + *
> + * Setting distance explicitly is preferred, but this will
> + * allow qscale to be used as a fallback.
> + *
> + * This function is continuous and injective on [0, 100] which
> + * makes it monotonic.
> + *
> + * @param  quality 0.0 to 100.0 quality setting, libjpeg 

Re: [FFmpeg-devel] [PATCH] ffmpeg: add packet duration to AVPacket logging

2022-03-23 Thread Jan Ekström
On Mon, Mar 14, 2022 at 4:36 PM Paul B Mahol  wrote:
>
> LGTM, could also be refactored/deduplicated.

Thanks. Yea, I think I largely agree. Logging function for AVFrames
and AVPackets, Additionally debug_ts could use an option to only log
the things you are interested in (demux/decode/etc).

Applied as b1cbeabf5e4b3234e895a58bafa371bfb792baf0 .

Jan
___
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/8] lavc/avcodec: simplify codec id/type validity checking

2022-03-23 Thread Anton Khirnov
On entry to avcodec_open2(), the type and id either have to be
UNKNOWN/NONE or have to match the codec to be used.
---
 libavcodec/avcodec.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index fbe4a5e413..dbaa9f78a2 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -158,17 +158,15 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 codec = avctx->codec;
 codec2 = ffcodec(codec);
 
-if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == 
codec->type) &&
-avctx->codec_id == AV_CODEC_ID_NONE) {
-avctx->codec_type = codec->type;
-avctx->codec_id   = codec->id;
-}
-if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type &&
- avctx->codec_type != 
AVMEDIA_TYPE_ATTACHMENT)) {
+if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != 
codec->type) ||
+(avctx->codec_id   != AV_CODEC_ID_NONE && avctx->codec_id   != 
codec->id)) {
 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
 return AVERROR(EINVAL);
 }
-avctx->codec = codec;
+
+avctx->codec_type = codec->type;
+avctx->codec_id   = codec->id;
+avctx->codec  = codec;
 
 if (avctx->extradata_size < 0 || avctx->extradata_size >= 
FF_MAX_EXTRADATA_SIZE)
 return AVERROR(EINVAL);
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 5/8] lavc/encode: add an encoder-specific get_buffer() variant

2022-03-23 Thread Anton Khirnov
Several encoders (roqvideo, svq1, snow, and the mpegvideo family)
currently call ff_get_buffer(). However this function is written
assuming it is called by a decoder. Though nothing has been obviously
broken by this until now, this may change in the future.

To avoid potential future issues, introduce a simple encode-specific
wrapper around avcodec_default_get_buffer2() and enforce its use in
encoders.
---
 libavcodec/decode.c  |  2 ++
 libavcodec/encode.c  | 34 ++
 libavcodec/encode.h  |  5 +
 libavcodec/mpegpicture.c | 16 +---
 libavcodec/roqvideoenc.c |  4 ++--
 libavcodec/snow.c|  8 ++--
 libavcodec/svq1enc.c |  4 ++--
 7 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index fffad5f700..3733e6d4b8 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1405,6 +1405,8 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, 
int flags)
 int override_dimensions = 1;
 int ret;
 
+av_assert0(av_codec_is_decoder(avctx->codec));
+
 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
 if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
 (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), 
avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || 
avctx->pix_fmt<0) {
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 837ffaa40d..ec8d06d068 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -572,3 +572,37 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 return 0;
 }
+
+int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
+{
+int ret;
+
+switch (avctx->codec->type) {
+case AVMEDIA_TYPE_VIDEO:
+frame->format = avctx->pix_fmt;
+if (frame->width <= 0 || frame->height <= 0) {
+frame->width  = FFMAX(avctx->width,  avctx->coded_width);
+frame->height = FFMAX(avctx->height, avctx->coded_height);
+}
+
+break;
+case AVMEDIA_TYPE_AUDIO:
+frame->sample_rate = avctx->sample_rate;
+frame->format  = avctx->sample_fmt;
+if (!frame->ch_layout.nb_channels) {
+int ret = av_channel_layout_copy(&frame->ch_layout, 
&avctx->ch_layout);
+if (ret < 0)
+return ret;
+}
+break;
+}
+
+ret = avcodec_default_get_buffer2(avctx, frame, 0);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+av_frame_unref(frame);
+return ret;
+}
+
+return 0;
+}
diff --git a/libavcodec/encode.h b/libavcodec/encode.h
index 97b3acf9df..b2536bf0f3 100644
--- a/libavcodec/encode.h
+++ b/libavcodec/encode.h
@@ -44,6 +44,11 @@ int ff_encode_get_frame(AVCodecContext *avctx, AVFrame 
*frame);
  */
 int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, 
int flags);
 
+/**
+ * Allocate buffers for a frame. Encoder equivalent to ff_get_buffer().
+ */
+int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame);
+
 /**
  * Check AVPacket size and allocate data.
  *
diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index 681ccc2b82..aaa1df0bd8 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -26,6 +26,7 @@
 #include "libavutil/imgutils.h"
 
 #include "avcodec.h"
+#include "encode.h"
 #include "motion_est.h"
 #include "mpegpicture.h"
 #include "mpegutils.h"
@@ -123,14 +124,15 @@ static int alloc_frame_buffer(AVCodecContext *avctx,  
Picture *pic,
 int r, ret;
 
 pic->tf.f = pic->f;
-if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
-avctx->codec_id != AV_CODEC_ID_VC1IMAGE  &&
-avctx->codec_id != AV_CODEC_ID_MSS2) {
-if (edges_needed) {
-pic->f->width  = avctx->width  + 2 * EDGE_WIDTH;
-pic->f->height = avctx->height + 2 * EDGE_WIDTH;
-}
 
+if (edges_needed) {
+pic->f->width  = avctx->width  + 2 * EDGE_WIDTH;
+pic->f->height = avctx->height + 2 * EDGE_WIDTH;
+
+r = ff_encode_alloc_frame(avctx, pic->f);
+} else if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
+   avctx->codec_id != AV_CODEC_ID_VC1IMAGE  &&
+   avctx->codec_id != AV_CODEC_ID_MSS2) {
 r = ff_thread_get_ext_buffer(avctx, &pic->tf,
  pic->reference ? AV_GET_BUFFER_FLAG_REF : 
0);
 } else {
diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
index ef7861088d..95db514140 100644
--- a/libavcodec/roqvideoenc.c
+++ b/libavcodec/roqvideoenc.c
@@ -1081,8 +1081,8 @@ static int roq_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
 if (enc->first_frame) {
 /* Alloc memory for the reconstruction data (we must know the stride
  for that) */
-if ((ret = ff_get_buffer(avctx, roq->current_frame, 0)) < 0 ||
-(ret = ff_get_buffer(avctx, roq->last_frame,0)) < 0)
+if ((ret = ff_encode_alloc_frame

[FFmpeg-devel] [PATCH 4/8] lavc/snow: only allocate mconly_picture for decoding

2022-03-23 Thread Anton Khirnov
It is not used in the encoder.
---
 libavcodec/snow.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavcodec/snow.c b/libavcodec/snow.c
index 0a500695ce..1224b95491 100644
--- a/libavcodec/snow.c
+++ b/libavcodec/snow.c
@@ -513,20 +513,23 @@ int ff_snow_common_init_after_header(AVCodecContext 
*avctx) {
 int ret, emu_buf_size;
 
 if(!s->scratchbuf) {
-if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
- AV_GET_BUFFER_FLAG_REF)) < 0)
-return ret;
+if (av_codec_is_decoder(avctx->codec)) {
+if ((ret = ff_get_buffer(s->avctx, s->mconly_picture,
+ AV_GET_BUFFER_FLAG_REF)) < 0)
+return ret;
+
+if (s->mconly_picture->format != avctx->pix_fmt) {
+av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
+return AVERROR_INVALIDDATA;
+}
+}
+
 emu_buf_size = FFMAX(s->mconly_picture->linesize[0], 
2*avctx->width+256) * (2 * MB_SIZE + HTAPS_MAX - 1);
 if (!FF_ALLOCZ_TYPED_ARRAY(s->scratchbuf,  
FFMAX(s->mconly_picture->linesize[0], 2*avctx->width+256) * 7 * MB_SIZE) ||
 !FF_ALLOCZ_TYPED_ARRAY(s->emu_edge_buffer, emu_buf_size))
 return AVERROR(ENOMEM);
 }
 
-if(s->mconly_picture->format != avctx->pix_fmt) {
-av_log(avctx, AV_LOG_ERROR, "pixel format changed\n");
-return AVERROR_INVALIDDATA;
-}
-
 for(plane_index=0; plane_index < s->nb_planes; plane_index++){
 int w= s->avctx->width;
 int h= s->avctx->height;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 3/8] lavc: move default get_buffer2() to its own file

2022-03-23 Thread Anton Khirnov
It is also used by some encoders, so decode.c is not the right place for
it.
---
 libavcodec/Makefile |   1 +
 libavcodec/decode.c | 278 ---
 libavcodec/get_buffer.c | 312 
 3 files changed, 313 insertions(+), 278 deletions(-)
 create mode 100644 libavcodec/get_buffer.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index fb8b0e824b..a24d8a3873 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -43,6 +43,7 @@ OBJS = ac3_parser.o   
  \
dirac.o  \
dv_profile.o \
encode.o \
+   get_buffer.o \
imgconvert.o \
jni.o\
mathtables.o \
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index f9fdb935f6..fffad5f700 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -48,25 +48,6 @@
 #include "internal.h"
 #include "thread.h"
 
-typedef struct FramePool {
-/**
- * Pools for each data plane. For audio all the planes have the same size,
- * so only pools[0] is used.
- */
-AVBufferPool *pools[4];
-
-/*
- * Pool parameters
- */
-int format;
-int width, height;
-int stride_align[AV_NUM_DATA_POINTERS];
-int linesize[4];
-int planes;
-int channels;
-int samples;
-} FramePool;
-
 static int apply_param_change(AVCodecContext *avctx, const AVPacket *avpkt)
 {
 int ret;
@@ -1250,265 +1231,6 @@ int ff_get_format(AVCodecContext *avctx, const enum 
AVPixelFormat *fmt)
 return ret;
 }
 
-static void frame_pool_free(void *opaque, uint8_t *data)
-{
-FramePool *pool = (FramePool*)data;
-int i;
-
-for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
-av_buffer_pool_uninit(&pool->pools[i]);
-
-av_freep(&data);
-}
-
-static AVBufferRef *frame_pool_alloc(void)
-{
-FramePool *pool = av_mallocz(sizeof(*pool));
-AVBufferRef *buf;
-
-if (!pool)
-return NULL;
-
-buf = av_buffer_create((uint8_t*)pool, sizeof(*pool),
-   frame_pool_free, NULL, 0);
-if (!buf) {
-av_freep(&pool);
-return NULL;
-}
-
-return buf;
-}
-
-static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
-{
-FramePool *pool = avctx->internal->pool ?
-  (FramePool*)avctx->internal->pool->data : NULL;
-AVBufferRef *pool_buf;
-int i, ret, ch, planes;
-
-if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-int planar = av_sample_fmt_is_planar(frame->format);
-ch = frame->ch_layout.nb_channels;
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-if (!ch)
-ch = frame->channels;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-planes = planar ? ch : 1;
-}
-
-if (pool && pool->format == frame->format) {
-if (avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
-pool->width == frame->width && pool->height == frame->height)
-return 0;
-if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && pool->planes == planes 
&&
-pool->channels == ch && frame->nb_samples == pool->samples)
-return 0;
-}
-
-pool_buf = frame_pool_alloc();
-if (!pool_buf)
-return AVERROR(ENOMEM);
-pool = (FramePool*)pool_buf->data;
-
-switch (avctx->codec_type) {
-case AVMEDIA_TYPE_VIDEO: {
-int linesize[4];
-int w = frame->width;
-int h = frame->height;
-int unaligned;
-ptrdiff_t linesize1[4];
-size_t size[4];
-
-avcodec_align_dimensions2(avctx, &w, &h, pool->stride_align);
-
-do {
-// NOTE: do not align linesizes individually, this breaks e.g. 
assumptions
-// that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
-ret = av_image_fill_linesizes(linesize, avctx->pix_fmt, w);
-if (ret < 0)
-goto fail;
-// increase alignment of w for next try (rhs gives the lowest bit 
set in w)
-w += w & ~(w - 1);
-
-unaligned = 0;
-for (i = 0; i < 4; i++)
-unaligned |= linesize[i] % pool->stride_align[i];
-} while (unaligned);
-
-for (i = 0; i < 4; i++)
-linesize1[i] = linesize[i];
-ret = av_image_fill_plane_sizes(size, avctx->pix_fmt, h, linesize1);
-if (ret < 0)
-goto fail;
-
-for (i = 0; i < 4; i++) {
-pool->linesize[i] = linesize[i];
-if (size[i]) {
-if (size[i] > INT_MAX - (16 + STRIDE_ALIGN - 1)) {
-   

[FFmpeg-devel] [PATCH 6/8] lavc/avcodec: only allocate decoding packets for decoders

2022-03-23 Thread Anton Khirnov
---
 libavcodec/avcodec.c | 7 +--
 libavcodec/decode.c  | 8 
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index c7daa385e7..5fd988a41c 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -180,12 +180,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 
 avci->buffer_frame = av_frame_alloc();
 avci->buffer_pkt = av_packet_alloc();
-avci->in_pkt = av_packet_alloc();
-avci->last_pkt_props = av_packet_alloc();
-avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
- AV_FIFO_FLAG_AUTO_GROW);
-if (!avci->buffer_frame || !avci->buffer_pkt  ||
-!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) {
+if (!avci->buffer_frame || !avci->buffer_pkt) {
 ret = AVERROR(ENOMEM);
 goto free_and_end;
 }
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 3733e6d4b8..bb3857afd9 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1527,6 +1527,7 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame 
*frame, int flags)
 
 int ff_decode_preinit(AVCodecContext *avctx)
 {
+AVCodecInternal *avci = avctx->internal;
 int ret = 0;
 
 /* if the decoder init function was already called previously,
@@ -1605,6 +1606,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
 avctx->export_side_data |= AV_CODEC_EXPORT_DATA_MVS;
 }
 
+avci->in_pkt = av_packet_alloc();
+avci->last_pkt_props = av_packet_alloc();
+avci->pkt_props  = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
+  AV_FIFO_FLAG_AUTO_GROW);
+if (!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props)
+return AVERROR(ENOMEM);
+
 ret = decode_bsfs_init(avctx);
 if (ret < 0)
 return ret;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 2/8] lavc/avcodec: only allocate the encoding frame for encoders

2022-03-23 Thread Anton Khirnov
And only when needed, i.e. for encoders using the simple API.
---
 libavcodec/avcodec.c | 4 +---
 libavcodec/encode.c  | 7 +++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index dbaa9f78a2..c7daa385e7 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -180,14 +180,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
 
 avci->buffer_frame = av_frame_alloc();
 avci->buffer_pkt = av_packet_alloc();
-avci->es.in_frame = av_frame_alloc();
 avci->in_pkt = av_packet_alloc();
 avci->last_pkt_props = av_packet_alloc();
 avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
  AV_FIFO_FLAG_AUTO_GROW);
 if (!avci->buffer_frame || !avci->buffer_pkt  ||
-!avci->es.in_frame  || !avci->in_pkt ||
-!avci->last_pkt_props || !avci->pkt_props) {
+!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) {
 ret = AVERROR(ENOMEM);
 goto free_and_end;
 }
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 70bd8da81f..837ffaa40d 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -412,6 +412,7 @@ int attribute_align_arg 
avcodec_receive_packet(AVCodecContext *avctx, AVPacket *
 
 int ff_encode_preinit(AVCodecContext *avctx)
 {
+AVCodecInternal *avci = avctx->internal;
 int i;
 
 if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
@@ -563,5 +564,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
 if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY)
 avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY;
 
+if (ffcodec(avctx->codec)->encode2) {
+avci->es.in_frame = av_frame_alloc();
+if (!avci->es.in_frame)
+return AVERROR(ENOMEM);
+}
+
 return 0;
 }
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 7/8] lavc/pthread_frame: do not copy AVCodecInternal contents

2022-03-23 Thread Anton Khirnov
None of its fields have meaningful values at that point that would need
to be copied to frame thread workers.
---
 libavcodec/pthread_frame.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index aa971bd74d..4ae1c02f62 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -791,7 +791,7 @@ static av_cold int init_thread(PerThreadContext *p, int 
*threads_to_free,
 p->parent = fctx;
 p->avctx  = copy;
 
-copy->internal = av_memdup(avctx->internal, sizeof(*avctx->internal));
+copy->internal = av_mallocz(sizeof(*copy->internal));
 if (!copy->internal)
 return AVERROR(ENOMEM);
 copy->internal->thread_ctx = p;
-- 
2.34.1

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

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


[FFmpeg-devel] [PATCH 8/8] lavc: drop a confusing message about "thread emulation"

2022-03-23 Thread Anton Khirnov
There is no such thing.
---
 libavcodec/avcodec.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 5fd988a41c..dec09476cc 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -309,9 +309,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
 if (ret < 0)
 goto free_and_end;
 
-if (!HAVE_THREADS)
-av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread 
support, using thread emulation\n");
-
 if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) {
 ret = ff_frame_thread_encoder_init(avctx);
 if (ret < 0)
-- 
2.34.1

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

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


Re: [FFmpeg-devel] [PATCH 5/8] lavc/encode: add an encoder-specific get_buffer() variant

2022-03-23 Thread James Almer




On 3/23/2022 12:57 PM, Anton Khirnov wrote:

Several encoders (roqvideo, svq1, snow, and the mpegvideo family)
currently call ff_get_buffer(). However this function is written
assuming it is called by a decoder. Though nothing has been obviously
broken by this until now, this may change in the future.

To avoid potential future issues, introduce a simple encode-specific
wrapper around avcodec_default_get_buffer2() and enforce its use in
encoders.
---
  libavcodec/decode.c  |  2 ++
  libavcodec/encode.c  | 34 ++
  libavcodec/encode.h  |  5 +
  libavcodec/mpegpicture.c | 16 +---
  libavcodec/roqvideoenc.c |  4 ++--
  libavcodec/snow.c|  8 ++--
  libavcodec/svq1enc.c |  4 ++--
  7 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index fffad5f700..3733e6d4b8 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1405,6 +1405,8 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, 
int flags)
  int override_dimensions = 1;
  int ret;
  
+av_assert0(av_codec_is_decoder(avctx->codec));

+
  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
  if ((unsigned)avctx->width > INT_MAX - STRIDE_ALIGN ||
  (ret = av_image_check_size2(FFALIGN(avctx->width, STRIDE_ALIGN), 
avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx)) < 0 || 
avctx->pix_fmt<0) {
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 837ffaa40d..ec8d06d068 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -572,3 +572,37 @@ FF_ENABLE_DEPRECATION_WARNINGS
  
  return 0;

  }
+
+int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
+{
+int ret;
+
+switch (avctx->codec->type) {
+case AVMEDIA_TYPE_VIDEO:
+frame->format = avctx->pix_fmt;
+if (frame->width <= 0 || frame->height <= 0) {
+frame->width  = FFMAX(avctx->width,  avctx->coded_width);
+frame->height = FFMAX(avctx->height, avctx->coded_height);
+}
+
+break;
+case AVMEDIA_TYPE_AUDIO:
+frame->sample_rate = avctx->sample_rate;
+frame->format  = avctx->sample_fmt;
+if (!frame->ch_layout.nb_channels) {
+int ret = av_channel_layout_copy(&frame->ch_layout, 
&avctx->ch_layout);


Unnecessarily shadowing ret.


+if (ret < 0)
+return ret;
+}
+break;
+}
+
+ret = avcodec_default_get_buffer2(avctx, frame, 0);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+av_frame_unref(frame);
+return ret;
+}
+
+return 0;
+}
diff --git a/libavcodec/encode.h b/libavcodec/encode.h
index 97b3acf9df..b2536bf0f3 100644
--- a/libavcodec/encode.h
+++ b/libavcodec/encode.h
@@ -44,6 +44,11 @@ int ff_encode_get_frame(AVCodecContext *avctx, AVFrame 
*frame);
   */
  int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t 
size, int flags);
  
+/**

+ * Allocate buffers for a frame. Encoder equivalent to ff_get_buffer().
+ */
+int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame);
+
  /**
   * Check AVPacket size and allocate data.
   *
diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c
index 681ccc2b82..aaa1df0bd8 100644
--- a/libavcodec/mpegpicture.c
+++ b/libavcodec/mpegpicture.c
@@ -26,6 +26,7 @@
  #include "libavutil/imgutils.h"
  
  #include "avcodec.h"

+#include "encode.h"
  #include "motion_est.h"
  #include "mpegpicture.h"
  #include "mpegutils.h"
@@ -123,14 +124,15 @@ static int alloc_frame_buffer(AVCodecContext *avctx,  
Picture *pic,
  int r, ret;
  
  pic->tf.f = pic->f;

-if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
-avctx->codec_id != AV_CODEC_ID_VC1IMAGE  &&
-avctx->codec_id != AV_CODEC_ID_MSS2) {
-if (edges_needed) {
-pic->f->width  = avctx->width  + 2 * EDGE_WIDTH;
-pic->f->height = avctx->height + 2 * EDGE_WIDTH;
-}
  
+if (edges_needed) {

+pic->f->width  = avctx->width  + 2 * EDGE_WIDTH;
+pic->f->height = avctx->height + 2 * EDGE_WIDTH;
+
+r = ff_encode_alloc_frame(avctx, pic->f);
+} else if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
+   avctx->codec_id != AV_CODEC_ID_VC1IMAGE  &&
+   avctx->codec_id != AV_CODEC_ID_MSS2) {
  r = ff_thread_get_ext_buffer(avctx, &pic->tf,
   pic->reference ? AV_GET_BUFFER_FLAG_REF 
: 0);
  } else {
diff --git a/libavcodec/roqvideoenc.c b/libavcodec/roqvideoenc.c
index ef7861088d..95db514140 100644
--- a/libavcodec/roqvideoenc.c
+++ b/libavcodec/roqvideoenc.c
@@ -1081,8 +1081,8 @@ static int roq_encode_frame(AVCodecContext *avctx, 
AVPacket *pkt,
  if (enc->first_frame) {
  /* Alloc memory for the reconstruction data (we must know the stride
   for that) */
-if ((ret = ff_get_buffer(avctx, roq->current_fr

Re: [FFmpeg-devel] [PATCH 2/8] lavc/avcodec: only allocate the encoding frame for encoders

2022-03-23 Thread James Almer




On 3/23/2022 12:57 PM, Anton Khirnov wrote:

And only when needed, i.e. for encoders using the simple API.
---
  libavcodec/avcodec.c | 4 +---
  libavcodec/encode.c  | 7 +++
  2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index dbaa9f78a2..c7daa385e7 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -180,14 +180,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext 
*avctx, const AVCodec *code
  
  avci->buffer_frame = av_frame_alloc();

  avci->buffer_pkt = av_packet_alloc();
-avci->es.in_frame = av_frame_alloc();
  avci->in_pkt = av_packet_alloc();
  avci->last_pkt_props = av_packet_alloc();
  avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props),
   AV_FIFO_FLAG_AUTO_GROW);
  if (!avci->buffer_frame || !avci->buffer_pkt  ||
-!avci->es.in_frame  || !avci->in_pkt ||
-!avci->last_pkt_props || !avci->pkt_props) {
+!avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) {
  ret = AVERROR(ENOMEM);
  goto free_and_end;
  }
diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 70bd8da81f..837ffaa40d 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -412,6 +412,7 @@ int attribute_align_arg 
avcodec_receive_packet(AVCodecContext *avctx, AVPacket *
  
  int ff_encode_preinit(AVCodecContext *avctx)

  {
+AVCodecInternal *avci = avctx->internal;
  int i;
  
  if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {

@@ -563,5 +564,11 @@ FF_ENABLE_DEPRECATION_WARNINGS
  if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY)
  avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY;
  
+if (ffcodec(avctx->codec)->encode2) {

+avci->es.in_frame = av_frame_alloc();


Could use the chance to remove the EncodeSimpleContext struct and just 
have in_frame in AVCodecInternal.
DecodeSimpleContext was removed the same way some time ago when it 
became a struct for a single field.



+if (!avci->es.in_frame)
+return AVERROR(ENOMEM);
+}
+
  return 0;
  }

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

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


Re: [FFmpeg-devel] [PATCH] avfilter/vf_subtitles: pass storage size to libass

2022-03-23 Thread Oneric
On Tue, Mar 22, 2022 at 13:45:20 -0300, James Almer wrote:
> 
> Will apply it unless someone is against it.

Thanks for applying the patch!

In case this fix is eligible for backporting:
It applies nicely at is to the release/5.0 branch and 5.0 also already 
requires a new enough libass for ass_set_storage_size to be always 
available.
For the release/4.[0-4] branches, the attached patch can be used instead.
It applied without problems for me on all the 4.x branches and also built 
and passed FATE with the config I used.
>From 27b6deafe859eb9bddfb21498a11f2b2b613802b Mon Sep 17 00:00:00 2001
From: Oneric 
Date: Wed, 23 Mar 2022 20:43:54 +0100
Subject: [PATCH] avfilter/vf_subtitles: pass storage size to libass

Due to a quirk of the ASS format some tags depend on the exact storage
resolution of the video, so tell libass via ass_set_storage_size.
---
 libavfilter/vf_subtitles.c | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index de74afa2b7..b57dd80b13 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -145,9 +145,16 @@ static int config_input(AVFilterLink *inlink)
 ff_draw_init(&ass->draw, inlink->format, ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0);
 
 ass_set_frame_size  (ass->renderer, inlink->w, inlink->h);
-if (ass->original_w && ass->original_h)
+if (ass->original_w && ass->original_h) {
 ass_set_aspect_ratio(ass->renderer, (double)inlink->w / inlink->h,
  (double)ass->original_w / ass->original_h);
+#if LIBASS_VERSION > 0x0101
+ass_set_storage_size(ass->renderer, ass->original_w, ass->original_h);
+} else {
+ass_set_storage_size(ass->renderer, inlink->w, inlink->h);
+#endif
+}
+
 if (ass->shaping != -1)
 ass_set_shaper(ass->renderer, ass->shaping);
 
-- 
2.30.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 2/2] avformat/aiffdec: cleanup size handling for extreem cases

2022-03-23 Thread Michael Niedermayer
Signed-off-by: Michael Niedermayer 
---
 libavformat/aiffdec.c | 29 -
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 5236cc2807..2bdcd1362b 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -53,9 +53,9 @@ static enum AVCodecID aiff_codec_get_id(int bps)
 }
 
 /* returns the size of the found tag */
-static int get_tag(AVIOContext *pb, uint32_t * tag)
+static int64_t get_tag(AVIOContext *pb, uint32_t * tag)
 {
-int size;
+int64_t size;
 
 if (avio_feof(pb))
 return AVERROR(EIO);
@@ -63,16 +63,16 @@ static int get_tag(AVIOContext *pb, uint32_t * tag)
 *tag = avio_rl32(pb);
 size = avio_rb32(pb);
 
-if (size < 0)
-size = 0x7fff;
-
 return size;
 }
 
 /* Metadata string read */
-static void get_meta(AVFormatContext *s, const char *key, int size)
+static void get_meta(AVFormatContext *s, const char *key, int64_t size)
 {
-uint8_t *str = av_malloc(size+1U);
+uint8_t *str = NULL;
+
+if (size < SIZE_MAX)
+str = av_malloc(size+1);
 
 if (str) {
 int res = avio_read(s->pb, str, size);
@@ -89,7 +89,7 @@ static void get_meta(AVFormatContext *s, const char *key, int 
size)
 }
 
 /* Returns the number of sound data frames or negative on error */
-static int get_aiff_header(AVFormatContext *s, int size,
+static int get_aiff_header(AVFormatContext *s, int64_t size,
 unsigned version)
 {
 AVIOContext *pb= s->pb;
@@ -101,9 +101,6 @@ static int get_aiff_header(AVFormatContext *s, int size,
 unsigned int num_frames;
 int channels;
 
-if (size == INT_MAX)
-return AVERROR_INVALIDDATA;
-
 if (size & 1)
 size++;
 par->codec_type = AVMEDIA_TYPE_AUDIO;
@@ -215,7 +212,8 @@ static int aiff_probe(const AVProbeData *p)
 /* aiff input */
 static int aiff_read_header(AVFormatContext *s)
 {
-int ret, size, filesize;
+int ret;
+int64_t filesize, size;
 int64_t offset = 0, position;
 uint32_t tag;
 unsigned version = AIFF_C_VERSION1;
@@ -226,7 +224,7 @@ static int aiff_read_header(AVFormatContext *s)
 
 /* check FORM header */
 filesize = get_tag(pb, &tag);
-if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))
+if (filesize < 4 || tag != MKTAG('F', 'O', 'R', 'M'))
 return AVERROR_INVALIDDATA;
 
 /* AIFF data type */
@@ -253,10 +251,7 @@ static int aiff_read_header(AVFormatContext *s)
 if (size < 0)
 return size;
 
-if (size >= 0x7fff - 8)
-filesize = 0;
-else
-filesize -= size + 8;
+filesize -= size + 8;
 
 switch (tag) {
 case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */
-- 
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 v2] avcodec/v4l2_m2m_dec: export v4l2 buffer dma-buf

2022-03-23 Thread Ming Qian
if the v4l2 buffer is supported to export dma-buf,
then we can report it to AV_PIX_FMT_DRM_PRIME,
so the caller can pass it to other hardware device,
such as display it directly without copy frame data.

Signed-off-by: Ming Qian 
---
 libavcodec/v4l2_buffers.c | 115 +-
 libavcodec/v4l2_buffers.h |   2 +
 libavcodec/v4l2_context.c |  53 ++
 libavcodec/v4l2_context.h |  17 ++
 libavcodec/v4l2_fmt.c |  96 ++-
 libavcodec/v4l2_fmt.h |   1 +
 libavcodec/v4l2_m2m_dec.c |  21 +++
 7 files changed, 264 insertions(+), 41 deletions(-)

diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c
index 3f5471067a1a..18f17d871b8c 100644
--- a/libavcodec/v4l2_buffers.c
+++ b/libavcodec/v4l2_buffers.c
@@ -21,17 +21,23 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include "libavutil/hwcontext.h"
+#include "libavutil/hwcontext_drm.h"
 #include "libavcodec/avcodec.h"
 #include "libavutil/pixdesc.h"
 #include "v4l2_context.h"
 #include "v4l2_buffers.h"
 #include "v4l2_m2m.h"
+#include "v4l2_fmt.h"
 
 #define USEC_PER_SEC 100
 static AVRational v4l2_timebase = { 1, USEC_PER_SEC };
@@ -209,7 +215,7 @@ static enum AVColorTransferCharacteristic 
v4l2_get_color_trc(V4L2Buffer *buf)
 return AVCOL_TRC_UNSPECIFIED;
 }
 
-static void v4l2_free_buffer(void *opaque, uint8_t *unused)
+static void v4l2_free_buffer(void *opaque, uint8_t *data)
 {
 V4L2Buffer* avbuf = opaque;
 V4L2m2mContext *s = buf_to_m2mctx(avbuf);
@@ -229,6 +235,12 @@ static void v4l2_free_buffer(void *opaque, uint8_t *unused)
 ff_v4l2_buffer_enqueue(avbuf);
 }
 
+if (avbuf->hwctx_ref) {
+AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)data;
+
+av_buffer_unref(&avbuf->hwctx_ref);
+av_free(desc);
+}
 av_buffer_unref(&avbuf->context_ref);
 }
 }
@@ -337,6 +349,90 @@ static int v4l2_buffer_buf_to_swframe(AVFrame *frame, 
V4L2Buffer *avbuf)
 return 0;
 }
 
+static int v4l2_buffer_buf_to_hwframe(AVFrame *frame, V4L2Buffer *avbuf)
+{
+V4L2Context *ctx = avbuf->context;
+AVDRMFrameDescriptor *desc = NULL;
+AVDRMLayerDescriptor *layer = NULL;
+int i;
+int ret;
+
+if (!ctx->hwframes)
+return AVERROR(EINVAL);
+
+for (i = 0; i < avbuf->num_planes; i++) {
+if (avbuf->plane_info[i].dmafd < 0)
+return AVERROR(EINVAL);
+}
+
+desc = av_mallocz(sizeof(AVDRMFrameDescriptor));
+if (!desc)
+return AVERROR(ENOMEM);
+
+for (i = 0; i < avbuf->num_planes; i++) {
+desc->objects[i].fd = avbuf->plane_info[i].dmafd;
+desc->objects[i].size = avbuf->plane_info[i].length;
+}
+desc->nb_objects = avbuf->num_planes;
+
+desc->nb_layers = 1;
+layer = &desc->layers[0];
+layer->format = ff_v4l2_format_avfmt_to_drm(avbuf->context->av_pix_fmt);
+layer->nb_planes = avbuf->num_planes;
+for (i = 0; i < avbuf->num_planes; i++) {
+layer->planes[i].object_index = i;
+layer->planes[i].offset = 0;
+layer->planes[i].pitch = avbuf->plane_info[i].bytesperline;
+}
+
+/* fixup special cases */
+switch (avbuf->context->av_pix_fmt) {
+case AV_PIX_FMT_NV12:
+case AV_PIX_FMT_NV21:
+if (avbuf->num_planes > 1)
+break;
+layer->nb_planes = 2;
+layer->planes[1].object_index = 0;
+layer->planes[1].offset = avbuf->plane_info[0].bytesperline * 
avbuf->context->format.fmt.pix_mp.height;
+layer->planes[1].pitch = avbuf->plane_info[0].bytesperline;
+break;
+
+case AV_PIX_FMT_YUV420P:
+if (avbuf->num_planes > 1)
+break;
+layer->nb_planes = 3;
+layer->planes[1].object_index = 0;
+layer->planes[2].object_index = 0;
+layer->planes[1].offset = avbuf->plane_info[0].bytesperline * 
avbuf->context->format.fmt.pix_mp.height;
+layer->planes[2].offset = layer->planes[1].offset + 
((avbuf->plane_info[0].bytesperline * avbuf->context->format.fmt.pix_mp.height) 
>> 2);
+layer->planes[1].pitch = avbuf->plane_info[0].bytesperline >> 1;
+layer->planes[2].pitch = avbuf->plane_info[0].bytesperline >> 1;
+break;
+
+default:
+break;
+}
+
+avbuf->hwctx_ref = av_buffer_ref(ctx->hwdevice);
+frame->buf[0] = av_buffer_create((uint8_t *)desc, sizeof(*desc), 
v4l2_free_buffer, avbuf, 0);
+if (!frame->buf[0]) {
+av_free(desc);
+av_buffer_unref(&avbuf->hwctx_ref);
+return AVERROR(ENOMEM);
+}
+frame->data[0] = (uint8_t *)desc;
+frame->format = AV_PIX_FMT_DRM_PRIME;
+frame->hw_frames_ctx = av_buffer_ref(ctx->hwframes);
+
+ret = v4l2_buf_increase_ref(avbuf);
+if (ret) {
+av_buffer_unref(&frame->buf[0]);
+

[FFmpeg-devel] [PATCH 1/2] avcodec/v4l2_m2m_dec: add a dequeue_timeout parameter

2022-03-23 Thread Ming Qian
the dequeue of capture queue will be blocked until
decoded frame available or an input buffer is ready to be dequeued.
but it may cause death waiting in some case.
For example, it has enqueued the first input frame,
and then blocks at ff_v4l2_context_dequeue_frame.
For some reason, the decoder can't decode the first frame,
also it can't return the input buffer. The decoder needs more input data
to decode, so the decoder is just waiting.
This creates some kind of deadlock.

And in linux/Documentation/userspace-api/media/v4l/dev-decoder.rst,
there are some descriptor like below:
The client must not assume any direct relationship between CAPTURE and
OUTPUT buffers and any specific timing of buffers becoming available to dequeue.
Specifically:
[snip]
- a buffer queued to OUTPUT may result in a buffer being produced on CAPTURE
  later into decode process, and/or after processing further OUTPUT buffers,
  or be returned out of order, e.g. if display reordering is used,

And I meet a similar case, there are 16 output buffers, but only one
buffer is queued to driver, then blocks at
ff_v4l2_context_dequeue_frame.
But the decoder need more frame data, otherwise it won't decode it.

So I think the client should keep processing OUTPUT buffers if there are
available buffers until the end.

To resolve it, I think we can set a reasonable timeout instead of -1.
So I add a parameter dequeue_timeout, and it works on my side.

Signed-off-by: Ming Qian 
---
 libavcodec/v4l2_m2m.h | 5 -
 libavcodec/v4l2_m2m_dec.c | 5 -
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/v4l2_m2m.h b/libavcodec/v4l2_m2m.h
index 16e0a6d6b90f..5c7e7c955383 100644
--- a/libavcodec/v4l2_m2m.h
+++ b/libavcodec/v4l2_m2m.h
@@ -38,7 +38,9 @@
 
 #define V4L_M2M_DEFAULT_OPTS \
 { "num_output_buffers", "Number of buffers in the output context",\
-OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, 
INT_MAX, FLAGS }
+OFFSET(num_output_buffers), AV_OPT_TYPE_INT, { .i64 = 16 }, 6, 
INT_MAX, FLAGS }, \
+{ "dequeue_timeout", "timeout of dequeue in the capture context",\
+OFFSET(dequeue_timeout), AV_OPT_TYPE_INT, { .i64 = 32 }, -1, INT_MAX, 
FLAGS }
 
 typedef struct V4L2m2mContext {
 char devname[PATH_MAX];
@@ -76,6 +78,7 @@ typedef struct V4L2m2mPriv {
 
 int num_output_buffers;
 int num_capture_buffers;
+int dequeue_timeout;
 } V4L2m2mPriv;
 
 /**
diff --git a/libavcodec/v4l2_m2m_dec.c b/libavcodec/v4l2_m2m_dec.c
index 4c521eba343c..e386e09e3e1e 100644
--- a/libavcodec/v4l2_m2m_dec.c
+++ b/libavcodec/v4l2_m2m_dec.c
@@ -138,6 +138,7 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 V4L2m2mContext *s = ((V4L2m2mPriv*)avctx->priv_data)->context;
 V4L2Context *const capture = &s->capture;
 V4L2Context *const output = &s->output;
+int timeout = ((V4L2m2mPriv*)avctx->priv_data)->dequeue_timeout;
 int ret;
 
 if (!s->buf_pkt.size) {
@@ -172,7 +173,9 @@ static int v4l2_receive_frame(AVCodecContext *avctx, 
AVFrame *frame)
 }
 
 dequeue:
-return ff_v4l2_context_dequeue_frame(capture, frame, -1);
+if (s->draining)
+timeout = -1;
+return ff_v4l2_context_dequeue_frame(capture, frame, timeout);
 fail:
 av_packet_unref(&s->buf_pkt);
 return ret;
-- 
2.33.0

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

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


[FFmpeg-devel] [PATCH 2/2] avcodec/v4l2_m2m_enc: add a dequeue_timeout parameter

2022-03-23 Thread Ming Qian
For the reason similar to decoder,
Set a reasonable timeout instead of -1
to avoid dead waiting in some case.

Signed-off-by: Ming Qian 
---
 libavcodec/v4l2_context.c | 4 ++--
 libavcodec/v4l2_context.h | 2 +-
 libavcodec/v4l2_m2m_enc.c | 5 -
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavcodec/v4l2_context.c b/libavcodec/v4l2_context.c
index 8910ae08d3a5..1122e68f9a97 100644
--- a/libavcodec/v4l2_context.c
+++ b/libavcodec/v4l2_context.c
@@ -644,7 +644,7 @@ int ff_v4l2_context_dequeue_frame(V4L2Context* ctx, 
AVFrame* frame, int timeout)
 return ff_v4l2_buffer_buf_to_avframe(frame, avbuf);
 }
 
-int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt)
+int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt, int 
timeout)
 {
 V4L2Buffer *avbuf;
 
@@ -653,7 +653,7 @@ int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, 
AVPacket* pkt)
  *  1. encoded packet available
  *  2. an input buffer ready to be dequeued
  */
-avbuf = v4l2_dequeue_v4l2buf(ctx, -1);
+avbuf = v4l2_dequeue_v4l2buf(ctx, timeout);
 if (!avbuf) {
 if (ctx->done)
 return AVERROR_EOF;
diff --git a/libavcodec/v4l2_context.h b/libavcodec/v4l2_context.h
index 6f7460c89a9d..b385bccc82a9 100644
--- a/libavcodec/v4l2_context.h
+++ b/libavcodec/v4l2_context.h
@@ -148,7 +148,7 @@ int ff_v4l2_context_set_status(V4L2Context* ctx, uint32_t 
cmd);
  * @param[inout] pkt The AVPacket to dequeue to.
  * @return 0 in case of success, AVERROR(EAGAIN) if no buffer was ready, 
another negative error in case of error.
  */
-int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt);
+int ff_v4l2_context_dequeue_packet(V4L2Context* ctx, AVPacket* pkt, int 
timeout);
 
 /**
  * Dequeues a buffer from a V4L2Context to an AVFrame.
diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 1d90de2b9d14..7eae121cf33f 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -290,6 +290,7 @@ static int v4l2_receive_packet(AVCodecContext *avctx, 
AVPacket *avpkt)
 V4L2Context *const capture = &s->capture;
 V4L2Context *const output = &s->output;
 AVFrame *frame = s->frame;
+int timeout = ((V4L2m2mPriv*)avctx->priv_data)->dequeue_timeout;
 int ret;
 
 if (s->draining)
@@ -328,7 +329,9 @@ static int v4l2_receive_packet(AVCodecContext *avctx, 
AVPacket *avpkt)
 }
 
 dequeue:
-return ff_v4l2_context_dequeue_packet(capture, avpkt);
+if (s->draining)
+timeout = -1;
+return ff_v4l2_context_dequeue_packet(capture, avpkt, timeout);
 }
 
 static av_cold int v4l2_encode_init(AVCodecContext *avctx)
-- 
2.33.0

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

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