[FFmpeg-cvslog] lavc/vc1dsp: R-V V inv_trans

2023-12-08 Thread sunyuechi
ffmpeg | branch: master | sunyuechi  | Fri Dec  1 
10:07:40 2023 +0800| [0b9d009b4a85be31ed8ba1a9cece3b2db3e4d2f3] | committer: 
Rémi Denis-Courmont

lavc/vc1dsp: R-V V inv_trans

C908:
vc1dsp.vc1_inv_trans_4x4_dc_c:  125.7
vc1dsp.vc1_inv_trans_4x4_dc_rvv_i32: 53.5
vc1dsp.vc1_inv_trans_4x8_dc_c:  230.7
vc1dsp.vc1_inv_trans_4x8_dc_rvv_i32: 65.5
vc1dsp.vc1_inv_trans_8x4_dc_c:  228.7
vc1dsp.vc1_inv_trans_8x4_dc_rvv_i64: 64.5
vc1dsp.vc1_inv_trans_8x8_dc_c:  476.5
vc1dsp.vc1_inv_trans_8x8_dc_rvv_i64: 80.2

Signed-off-by: Rémi Denis-Courmont 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0b9d009b4a85be31ed8ba1a9cece3b2db3e4d2f3
---

 libavcodec/riscv/Makefile  |   2 +
 libavcodec/riscv/vc1dsp_init.c |  49 ++
 libavcodec/riscv/vc1dsp_rvv.S  | 113 +
 libavcodec/vc1dsp.c|   2 +
 libavcodec/vc1dsp.h|   1 +
 5 files changed, 167 insertions(+)

diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index 29a7fec455..3c7fb63579 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -40,5 +40,7 @@ OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o \
 RVV-OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_rvv.o
 OBJS-$(CONFIG_UTVIDEO_DECODER) += riscv/utvideodsp_init.o
 RVV-OBJS-$(CONFIG_UTVIDEO_DECODER) += riscv/utvideodsp_rvv.o
+OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_init.o
+RVV-OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_rvv.o
 OBJS-$(CONFIG_VORBIS_DECODER) += riscv/vorbisdsp_init.o
 RVV-OBJS-$(CONFIG_VORBIS_DECODER) += riscv/vorbisdsp_rvv.o
diff --git a/libavcodec/riscv/vc1dsp_init.c b/libavcodec/riscv/vc1dsp_init.c
new file mode 100644
index 00..0d22d28f4d
--- /dev/null
+++ b/libavcodec/riscv/vc1dsp_init.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include 
+
+#include "libavutil/attributes.h"
+#include "libavutil/cpu.h"
+#include "libavutil/riscv/cpu.h"
+#include "libavcodec/vc1.h"
+
+void ff_vc1_inv_trans_8x8_dc_rvv(uint8_t *dest, ptrdiff_t stride, int16_t 
*block);
+void ff_vc1_inv_trans_4x8_dc_rvv(uint8_t *dest, ptrdiff_t stride, int16_t 
*block);
+void ff_vc1_inv_trans_8x4_dc_rvv(uint8_t *dest, ptrdiff_t stride, int16_t 
*block);
+void ff_vc1_inv_trans_4x4_dc_rvv(uint8_t *dest, ptrdiff_t stride, int16_t 
*block);
+
+av_cold void ff_vc1dsp_init_riscv(VC1DSPContext *dsp)
+{
+#if HAVE_RVV
+int flags = av_get_cpu_flags();
+
+if (ff_get_rv_vlenb() >= 16) {
+if (flags & AV_CPU_FLAG_RVV_I64) {
+dsp->vc1_inv_trans_8x8_dc = ff_vc1_inv_trans_8x8_dc_rvv;
+dsp->vc1_inv_trans_8x4_dc = ff_vc1_inv_trans_8x4_dc_rvv;
+}
+if (flags & AV_CPU_FLAG_RVV_I32) {
+dsp->vc1_inv_trans_4x8_dc = ff_vc1_inv_trans_4x8_dc_rvv;
+dsp->vc1_inv_trans_4x4_dc = ff_vc1_inv_trans_4x4_dc_rvv;
+}
+}
+#endif
+}
diff --git a/libavcodec/riscv/vc1dsp_rvv.S b/libavcodec/riscv/vc1dsp_rvv.S
new file mode 100644
index 00..1a503ecc87
--- /dev/null
+++ b/libavcodec/riscv/vc1dsp_rvv.S
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2023 Institue of Software Chinese Academy of Sciences (ISCAS).
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/riscv/asm.S"
+
+func ff_vc1_inv_trans_8x8_dc_rvv, zve64x
+lht2, (a2)
+vsetivli  zero, 8, e8, mf2, ta, ma
+vlse64.v  v0, (a0), a1
+sh1addt2, t2, t2
+addi

[FFmpeg-cvslog] riscv: test for assembler support

2023-12-08 Thread Rémi Denis-Courmont
ffmpeg | branch: master | Rémi Denis-Courmont  | Tue Dec  5 
17:54:26 2023 +0200| [b3825bbe452c8e4f129fa90bba1fed0ee7b87d71] | committer: 
Rémi Denis-Courmont

riscv: test for assembler support

This should fix the build on LLVM 16 and earlier, at the cost of turning
all non-RVV optimisations off.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b3825bbe452c8e4f129fa90bba1fed0ee7b87d71
---

 Makefile|  6 +++---
 configure   |  5 -
 ffbuild/arch.mak|  1 +
 libavcodec/riscv/Makefile   | 16 
 libavcodec/riscv/ac3dsp_init.c  |  2 ++
 libavcodec/riscv/audiodsp_init.c|  2 ++
 libavcodec/riscv/bswapdsp_init.c|  2 ++
 libavcodec/riscv/pixblockdsp_init.c |  2 ++
 libswscale/riscv/Makefile   |  2 +-
 libswscale/riscv/rgb2rgb.c  |  2 ++
 tests/checkasm/Makefile |  2 +-
 tests/checkasm/checkasm.c   |  2 +-
 tests/checkasm/checkasm.h   |  5 -
 13 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile
index 78652c47bd..2fc3e538c1 100644
--- a/Makefile
+++ b/Makefile
@@ -93,10 +93,10 @@ ffbuild/.config: $(CONFIGURABLE_COMPONENTS)
 SUBDIR_VARS := CLEANFILES FFLIBS HOSTPROGS TESTPROGS TOOLS   \
HEADERS ARCH_HEADERS BUILT_HEADERS SKIPHEADERS\
ARMV5TE-OBJS ARMV6-OBJS ARMV8-OBJS VFP-OBJS NEON-OBJS \
-   ALTIVEC-OBJS VSX-OBJS RVV-OBJS MMX-OBJS X86ASM-OBJS   \
+   ALTIVEC-OBJS VSX-OBJS MMX-OBJS X86ASM-OBJS\
MIPSFPU-OBJS MIPSDSPR2-OBJS MIPSDSP-OBJS MSA-OBJS \
-   MMI-OBJS LSX-OBJS LASX-OBJS OBJS SLIBOBJS SHLIBOBJS   \
-   STLIBOBJS HOSTOBJS TESTOBJS
+   MMI-OBJS LSX-OBJS LASX-OBJS RV-OBJS RVV-OBJS  \
+   OBJS SLIBOBJS SHLIBOBJS STLIBOBJS HOSTOBJS TESTOBJS
 
 define RESET
 $(1) :=
diff --git a/configure b/configure
index d77c053226..7d2ee66000 100755
--- a/configure
+++ b/configure
@@ -2154,6 +2154,7 @@ ARCH_EXT_LIST_PPC="
 "
 
 ARCH_EXT_LIST_RISCV="
+rv
 rvv
 "
 
@@ -2679,7 +2680,8 @@ ppc4xx_deps="ppc"
 vsx_deps="altivec"
 power8_deps="vsx"
 
-rvv_deps="riscv"
+rv_deps="riscv"
+rvv_deps="rv"
 
 loongson2_deps="mips"
 loongson3_deps="mips"
@@ -6243,6 +6245,7 @@ elif enabled ppc; then
 
 elif enabled riscv; then
 
+enabled rv && check_inline_asm rv '".option arch, +zbb\nrev8 t0, t1"'
 enabled rvv && check_inline_asm rvv '".option arch, +v\nvsetivli zero, 0, 
e8, m1, ta, ma"'
 
 elif enabled x86; then
diff --git a/ffbuild/arch.mak b/ffbuild/arch.mak
index 39d76ee152..23a3feb090 100644
--- a/ffbuild/arch.mak
+++ b/ffbuild/arch.mak
@@ -15,6 +15,7 @@ OBJS-$(HAVE_LASX)  += $(LASX-OBJS)   $(LASX-OBJS-yes)
 OBJS-$(HAVE_ALTIVEC) += $(ALTIVEC-OBJS) $(ALTIVEC-OBJS-yes)
 OBJS-$(HAVE_VSX) += $(VSX-OBJS) $(VSX-OBJS-yes)
 
+OBJS-$(HAVE_RV)  += $(RV-OBJS)  $(RV-OBJS-yes)
 OBJS-$(HAVE_RVV) += $(RVV-OBJS) $(RVV-OBJS-yes)
 
 OBJS-$(HAVE_MMX) += $(MMX-OBJS) $(MMX-OBJS-yes)
diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index 3c7fb63579..e9825c0856 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -1,15 +1,15 @@
 OBJS-$(CONFIG_AAC_DECODER) += riscv/aacpsdsp_init.o riscv/sbrdsp_init.o
 RVV-OBJS-$(CONFIG_AAC_DECODER) += riscv/aacpsdsp_rvv.o riscv/sbrdsp_rvv.o
-OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_init.o \
- riscv/ac3dsp_rvb.o
+OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_init.o
+RV-OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_rvb.o
 RVV-OBJS-$(CONFIG_AC3DSP) += riscv/ac3dsp_rvv.o
 OBJS-$(CONFIG_ALAC_DECODER) += riscv/alacdsp_init.o
 RVV-OBJS-$(CONFIG_ALAC_DECODER) += riscv/alacdsp_rvv.o
-OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_init.o \
-   riscv/audiodsp_rvf.o
+OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_init.o
+RV-OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_rvf.o
 RVV-OBJS-$(CONFIG_AUDIODSP) += riscv/audiodsp_rvv.o
-OBJS-$(CONFIG_BSWAPDSP) += riscv/bswapdsp_init.o \
-   riscv/bswapdsp_rvb.o
+OBJS-$(CONFIG_BSWAPDSP) += riscv/bswapdsp_init.o
+RV-OBJS-$(CONFIG_BSWAPDSP) += riscv/bswapdsp_rvb.o
 RVV-OBJS-$(CONFIG_BSWAPDSP) += riscv/bswapdsp_rvv.o
 OBJS-$(CONFIG_EXR_DECODER) += riscv/exrdsp_init.o
 RVV-OBJS-$(CONFIG_EXR_DECODER) += riscv/exrdsp_rvv.o
@@ -35,8 +35,8 @@ OBJS-$(CONFIG_LLVIDENCDSP) += riscv/llvidencdsp_init.o
 RVV-OBJS-$(CONFIG_LLVIDENCDSP) += riscv/llvidencdsp_rvv.o
 OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_init.o
 RVV-OBJS-$(CONFIG_OPUS_DECODER) += riscv/opusdsp_rvv.o
-OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o \
-  riscv/pixblockdsp_rvi.o
+OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_init.o
+RV-OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_rvi.o
 RVV-OBJS-$(CONFIG_PIXBLOCKDSP) += riscv/pixblockdsp_rvv.o
 OBJS-$(CONFIG_UTVIDEO_DECODER) += riscv/utvideodsp_ini

[FFmpeg-cvslog] avfilter/vf_libvmaf: fix string comparison bug

2023-12-08 Thread nilfm
ffmpeg | branch: master | nilfm  | Fri Dec  1 19:08:23 2023 
+| [5f4b7bf2b5b675a4a1dfc3b64c1c5dd03d80f278] | committer: Kyle Swanson

avfilter/vf_libvmaf: fix string comparison bug

The libvmaf filter was doing substring checks in place of string equality
comparisons. This led to a bug when the user specified the pooling method
"harmonic_mean", since "mean" was checked first and the substring comparison
returned true. This patch changes all substring comparisons for string equality
comparisons. This is both correct and more efficient than the existing method.

Signed-off-by: nilfm 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5f4b7bf2b5b675a4a1dfc3b64c1c5dd03d80f278
---

 libavfilter/vf_libvmaf.c | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c
index 9aec61de19..180ada040f 100644
--- a/libavfilter/vf_libvmaf.c
+++ b/libavfilter/vf_libvmaf.c
@@ -243,7 +243,7 @@ static int parse_features(AVFilterContext *ctx)
 const AVDictionaryEntry *e = NULL;
 
 while (e = av_dict_iterate(dict[i], e)) {
-if (av_stristr(e->key, "name")) {
+if (!strcmp(e->key, "name")) {
 feature_name = e->value;
 continue;
 }
@@ -304,29 +304,29 @@ static int parse_models(AVFilterContext *ctx)
 char  *path = NULL;
 
 while (e = av_dict_iterate(dict[i], e)) {
-if (av_stristr(e->key, "disable_clip")) {
-model_cfg.flags |= av_stristr(e->value, "true") ?
+if (!strcmp(e->key, "disable_clip")) {
+model_cfg.flags |= !strcmp(e->value, "true") ?
 VMAF_MODEL_FLAG_DISABLE_CLIP : 0;
 continue;
 }
 
-if (av_stristr(e->key, "enable_transform")) {
-model_cfg.flags |= av_stristr(e->value, "true") ?
+if (!strcmp(e->key, "enable_transform")) {
+model_cfg.flags |= !strcmp(e->value, "true") ?
 VMAF_MODEL_FLAG_ENABLE_TRANSFORM : 0;
 continue;
 }
 
-if (av_stristr(e->key, "name")) {
+if (!strcmp(e->key, "name")) {
 model_cfg.name = e->value;
 continue;
 }
 
-if (av_stristr(e->key, "version")) {
+if (!strcmp(e->key, "version")) {
 version = e->value;
 continue;
 }
 
-if (av_stristr(e->key, "path")) {
+if (!strcmp(e->key, "path")) {
 path = e->value;
 continue;
 }
@@ -521,13 +521,13 @@ static int activate(AVFilterContext *ctx)
 static enum VmafOutputFormat log_fmt_map(const char *log_fmt)
 {
 if (log_fmt) {
-if (av_stristr(log_fmt, "xml"))
+if (!strcmp(log_fmt, "xml"))
 return VMAF_OUTPUT_FORMAT_XML;
-if (av_stristr(log_fmt, "json"))
+if (!strcmp(log_fmt, "json"))
 return VMAF_OUTPUT_FORMAT_JSON;
-if (av_stristr(log_fmt, "csv"))
+if (!strcmp(log_fmt, "csv"))
 return VMAF_OUTPUT_FORMAT_CSV;
-if (av_stristr(log_fmt, "sub"))
+if (!strcmp(log_fmt, "sub"))
 return VMAF_OUTPUT_FORMAT_SUB;
 }
 
@@ -537,11 +537,11 @@ static enum VmafOutputFormat log_fmt_map(const char 
*log_fmt)
 static enum VmafPoolingMethod pool_method_map(const char *pool_method)
 {
 if (pool_method) {
-if (av_stristr(pool_method, "min"))
+if (!strcmp(pool_method, "min"))
 return VMAF_POOL_METHOD_MIN;
-if (av_stristr(pool_method, "mean"))
+if (!strcmp(pool_method, "mean"))
 return VMAF_POOL_METHOD_MEAN;
-if (av_stristr(pool_method, "harmonic_mean"))
+if (!strcmp(pool_method, "harmonic_mean"))
 return VMAF_POOL_METHOD_HARMONIC_MEAN;
 }
 

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

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


[FFmpeg-cvslog] avformat/webpenc: Reindent after the previous commit

2023-12-08 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Nov  3 16:27:22 2023 +0100| [8283db7fb0eaf422bb45192df3552ba74187ffe3] | 
committer: Andreas Rheinhardt

avformat/webpenc: Reindent after the previous commit

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8283db7fb0eaf422bb45192df3552ba74187ffe3
---

 libavformat/webpenc.c | 94 +--
 1 file changed, 47 insertions(+), 47 deletions(-)

diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
index 9ac353c967..d4acea7ba6 100644
--- a/libavformat/webpenc.c
+++ b/libavformat/webpenc.c
@@ -80,66 +80,66 @@ static int flush(AVFormatContext *s, int trailer, int64_t 
pts)
 {
 WebpContext *w = s->priv_data;
 AVStream *st = s->streams[0];
-int skip = 0;
-unsigned flags = 0;
-int vp8x = 0;
+int skip = 0;
+unsigned flags = 0;
+int vp8x = 0;
 
 if (!w->last_pkt->size)
 return 0;
 
-if (AV_RL32(w->last_pkt->data) == AV_RL32("RIFF"))
-skip = 12;
+if (AV_RL32(w->last_pkt->data) == AV_RL32("RIFF"))
+skip = 12;
 
-if (AV_RL32(w->last_pkt->data + skip) == AV_RL32("VP8X")) {
-flags |= w->last_pkt->data[skip + 4 + 4];
-vp8x = 1;
-skip += AV_RL32(w->last_pkt->data + skip + 4) + 8;
-}
+if (AV_RL32(w->last_pkt->data + skip) == AV_RL32("VP8X")) {
+flags |= w->last_pkt->data[skip + 4 + 4];
+vp8x = 1;
+skip += AV_RL32(w->last_pkt->data + skip + 4) + 8;
+}
 
-if (!w->wrote_webp_header) {
-avio_write(s->pb, "RIFF\0\0\0\0WEBP", 12);
-w->wrote_webp_header = 1;
-if (w->frame_count > 1)  // first non-empty packet
-w->frame_count = 1;  // so we don't count previous empty 
packets.
-}
+if (!w->wrote_webp_header) {
+avio_write(s->pb, "RIFF\0\0\0\0WEBP", 12);
+w->wrote_webp_header = 1;
+if (w->frame_count > 1)  // first non-empty packet
+w->frame_count = 1;  // so we don't count previous empty packets.
+}
 
-if (w->frame_count == 1) {
-if (!trailer) {
-vp8x = 1;
-flags |= 2 + 16;
-}
-
-if (vp8x) {
-avio_write(s->pb, "VP8X", 4);
-avio_wl32(s->pb, 10);
-avio_w8(s->pb, flags);
-avio_wl24(s->pb, 0);
-avio_wl24(s->pb, st->codecpar->width - 1);
-avio_wl24(s->pb, st->codecpar->height - 1);
-}
-if (!trailer) {
-avio_write(s->pb, "ANIM", 4);
-avio_wl32(s->pb, 6);
-avio_wl32(s->pb, 0x);
-avio_wl16(s->pb, w->loop);
-}
+if (w->frame_count == 1) {
+if (!trailer) {
+vp8x = 1;
+flags |= 2 + 16;
 }
 
-if (w->frame_count > trailer) {
-avio_write(s->pb, "ANMF", 4);
-avio_wl32(s->pb, 16 + w->last_pkt->size - skip);
-avio_wl24(s->pb, 0);
+if (vp8x) {
+avio_write(s->pb, "VP8X", 4);
+avio_wl32(s->pb, 10);
+avio_w8(s->pb, flags);
 avio_wl24(s->pb, 0);
 avio_wl24(s->pb, st->codecpar->width - 1);
 avio_wl24(s->pb, st->codecpar->height - 1);
-if (w->last_pkt->pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE) {
-avio_wl24(s->pb, pts - w->last_pkt->pts);
-} else
-avio_wl24(s->pb, w->last_pkt->duration);
-avio_w8(s->pb, 0);
 }
-avio_write(s->pb, w->last_pkt->data + skip, w->last_pkt->size - skip);
-av_packet_unref(w->last_pkt);
+if (!trailer) {
+avio_write(s->pb, "ANIM", 4);
+avio_wl32(s->pb, 6);
+avio_wl32(s->pb, 0x);
+avio_wl16(s->pb, w->loop);
+}
+}
+
+if (w->frame_count > trailer) {
+avio_write(s->pb, "ANMF", 4);
+avio_wl32(s->pb, 16 + w->last_pkt->size - skip);
+avio_wl24(s->pb, 0);
+avio_wl24(s->pb, 0);
+avio_wl24(s->pb, st->codecpar->width - 1);
+avio_wl24(s->pb, st->codecpar->height - 1);
+if (w->last_pkt->pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE) {
+avio_wl24(s->pb, pts - w->last_pkt->pts);
+} else
+avio_wl24(s->pb, w->last_pkt->duration);
+avio_w8(s->pb, 0);
+}
+avio_write(s->pb, w->last_pkt->data + skip, w->last_pkt->size - skip);
+av_packet_unref(w->last_pkt);
 
 return 0;
 }

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

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


[FFmpeg-cvslog] avformat/webpenc: Write correct size for single images when unseekable

2023-12-08 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Nov  3 16:54:24 2023 +0100| [b021bc4a474eb96a2080ee61d5a1a24baef40889] | 
committer: Andreas Rheinhardt

avformat/webpenc: Write correct size for single images when unseekable

The earlier code writes the file and then tries to patch up
the size later. This is avoidable for the common case of
a single image because one can know the complete size
in advance and write it.

Fixes ticket #4609.

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b021bc4a474eb96a2080ee61d5a1a24baef40889
---

 libavformat/webpenc.c | 68 +++
 1 file changed, 41 insertions(+), 27 deletions(-)

diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
index d4acea7ba6..ea7a321975 100644
--- a/libavformat/webpenc.c
+++ b/libavformat/webpenc.c
@@ -21,6 +21,7 @@
 
 #include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
+#include "libavcodec/bytestream.h"
 #include "avformat.h"
 #include "internal.h"
 #include "mux.h"
@@ -76,11 +77,16 @@ static int is_animated_webp_packet(AVPacket *pkt)
 return 0;
 }
 
+/**
+ * Returns 1 if it has written a RIFF header with a correct length field
+ */
 static int flush(AVFormatContext *s, int trailer, int64_t pts)
 {
 WebpContext *w = s->priv_data;
 AVStream *st = s->streams[0];
-int skip = 0;
+uint8_t buf[12 /* RIFF+WEBP */ + 18 /* VP8X */ +
+14 /* ANIM */ + 24 /* ANMF */], *bufp = buf;
+int writing_webp_header = 0, skip = 0;
 unsigned flags = 0;
 int vp8x = 0;
 
@@ -97,7 +103,10 @@ static int flush(AVFormatContext *s, int trailer, int64_t 
pts)
 }
 
 if (!w->wrote_webp_header) {
-avio_write(s->pb, "RIFF\0\0\0\0WEBP", 12);
+bytestream_put_le32(&bufp, MKTAG('R', 'I', 'F', 'F'));
+bytestream_put_le32(&bufp, 0); /* Size to be patched later */
+bytestream_put_le32(&bufp, MKTAG('W', 'E', 'B', 'P'));
+writing_webp_header  = 1;
 w->wrote_webp_header = 1;
 if (w->frame_count > 1)  // first non-empty packet
 w->frame_count = 1;  // so we don't count previous empty packets.
@@ -110,38 +119,41 @@ static int flush(AVFormatContext *s, int trailer, int64_t 
pts)
 }
 
 if (vp8x) {
-avio_write(s->pb, "VP8X", 4);
-avio_wl32(s->pb, 10);
-avio_w8(s->pb, flags);
-avio_wl24(s->pb, 0);
-avio_wl24(s->pb, st->codecpar->width - 1);
-avio_wl24(s->pb, st->codecpar->height - 1);
+bytestream_put_le32(&bufp, MKTAG('V', 'P', '8', 'X'));
+bytestream_put_le32(&bufp, 10);
+bytestream_put_byte(&bufp, flags);
+bytestream_put_le24(&bufp, 0);
+bytestream_put_le24(&bufp, st->codecpar->width  - 1);
+bytestream_put_le24(&bufp, st->codecpar->height - 1);
 }
 if (!trailer) {
-avio_write(s->pb, "ANIM", 4);
-avio_wl32(s->pb, 6);
-avio_wl32(s->pb, 0x);
-avio_wl16(s->pb, w->loop);
+bytestream_put_le32(&bufp, MKTAG('A', 'N', 'I', 'M'));
+bytestream_put_le32(&bufp, 6);
+bytestream_put_le32(&bufp, 0x);
+bytestream_put_le16(&bufp, w->loop);
 }
 }
 
 if (w->frame_count > trailer) {
-avio_write(s->pb, "ANMF", 4);
-avio_wl32(s->pb, 16 + w->last_pkt->size - skip);
-avio_wl24(s->pb, 0);
-avio_wl24(s->pb, 0);
-avio_wl24(s->pb, st->codecpar->width - 1);
-avio_wl24(s->pb, st->codecpar->height - 1);
+bytestream_put_le32(&bufp, MKTAG('A', 'N', 'M', 'F'));
+bytestream_put_le32(&bufp, 16 + w->last_pkt->size - skip);
+bytestream_put_le24(&bufp, 0);
+bytestream_put_le24(&bufp, 0);
+bytestream_put_le24(&bufp, st->codecpar->width  - 1);
+bytestream_put_le24(&bufp, st->codecpar->height - 1);
 if (w->last_pkt->pts != AV_NOPTS_VALUE && pts != AV_NOPTS_VALUE) {
-avio_wl24(s->pb, pts - w->last_pkt->pts);
+bytestream_put_le24(&bufp, pts - w->last_pkt->pts);
 } else
-avio_wl24(s->pb, w->last_pkt->duration);
-avio_w8(s->pb, 0);
+bytestream_put_le24(&bufp, w->last_pkt->duration);
+bytestream_put_byte(&bufp, 0);
 }
+if (trailer && writing_webp_header)
+AV_WL32(buf + 4, bufp - (buf + 8) + w->last_pkt->size - skip);
+avio_write(s->pb, buf, bufp - buf);
 avio_write(s->pb, w->last_pkt->data + skip, w->last_pkt->size - skip);
 av_packet_unref(w->last_pkt);
 
-return 0;
+return trailer && writing_webp_header;
 }
 
 static int webp_write_packet(AVFormatContext *s, AVPacket *pkt)
@@ -185,11 +197,13 @@ static int webp_write_trailer(AVFormatContext *s)
 if ((ret = flush(s, 1, AV_NOPTS_VALUE)) < 0)
 return ret;
 
-filesize = avio_tell(s->pb);
-if (avio_seek(s->pb, 4, SEEK

[FFmpeg-cvslog] avformat/webpenc: Return early to reduce indentation

2023-12-08 Thread Andreas Rheinhardt
ffmpeg | branch: master | Andreas Rheinhardt  | 
Fri Nov  3 16:08:22 2023 +0100| [18d7a97f9e061aff5d743aab62a5c26244e9629d] | 
committer: Andreas Rheinhardt

avformat/webpenc: Return early to reduce indentation

Signed-off-by: Andreas Rheinhardt 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=18d7a97f9e061aff5d743aab62a5c26244e9629d
---

 libavformat/webpenc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
index fb0cca3922..9ac353c967 100644
--- a/libavformat/webpenc.c
+++ b/libavformat/webpenc.c
@@ -80,12 +80,13 @@ static int flush(AVFormatContext *s, int trailer, int64_t 
pts)
 {
 WebpContext *w = s->priv_data;
 AVStream *st = s->streams[0];
-
-if (w->last_pkt->size) {
 int skip = 0;
 unsigned flags = 0;
 int vp8x = 0;
 
+if (!w->last_pkt->size)
+return 0;
+
 if (AV_RL32(w->last_pkt->data) == AV_RL32("RIFF"))
 skip = 12;
 
@@ -139,7 +140,6 @@ static int flush(AVFormatContext *s, int trailer, int64_t 
pts)
 }
 avio_write(s->pb, w->last_pkt->data + skip, w->last_pkt->size - skip);
 av_packet_unref(w->last_pkt);
-}
 
 return 0;
 }

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

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