Re: [FFmpeg-devel] [PATCH 06/12] fftools/ffmpeg_dec: apply cropping manually

2024-03-22 Thread James Almer

On 3/22/2024 5:28 PM, Anton Khirnov wrote:

lavfi does not require aligned buffers, so we can safely apply top/left
cropping by any amount, without passing any special flags to lavc.
Longer term, an even better solution would probably be auto-inserting
the crop filter (or its hwaccel versions) as needed.


It's what i did in my container cropping set. One problem with it is 
that the cropping filter doesn't look at cropping values in input frames 
but at filter options instead, and will in fact *add* cropping values to 
the output frames if you pass it something it can't handle, like hwaccel 
formats.


And for that matter, cropping fields in frames should be handled by 
encoders, or by the generic encoding code in some form. Right now they 
are outright ignored.




Multiple FATE tests no longer need -flags unaligned.
---
  fftools/ffmpeg_dec.c | 14 ++
  tests/fate/h264.mak  |  2 +-
  tests/fate/hevc.mak  |  8 
  tests/fate/vvc.mak   |  2 +-
  4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index b8bfae469f..e3ed0b3978 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -51,6 +51,7 @@ typedef struct DecoderPriv {
  
  // a combination of DECODER_FLAG_*, provided to dec_open()

  int flags;
+int apply_cropping;
  
  enum AVPixelFormat  hwaccel_pix_fmt;

  enum HWAccelID  hwaccel_id;
@@ -404,6 +405,15 @@ static int video_frame_process(DecoderPriv *dp, AVFrame 
*frame)
  if (dp->sar_override.num)
  frame->sample_aspect_ratio = dp->sar_override;
  
+if (dp->apply_cropping) {

+// lavfi does not require aligned frame data
+int ret = av_frame_apply_cropping(frame, AV_FRAME_CROP_UNALIGNED);
+if (ret < 0) {
+av_log(dp, AV_LOG_ERROR, "Error applying decoder cropping\n");
+return ret;
+}
+}
+
  return 0;
  }
  
@@ -1214,6 +1224,10 @@ static int dec_open(DecoderPriv *dp, AVDictionary **dec_opts,

  if (o->flags & DECODER_FLAG_BITEXACT)
  dp->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
  
+// we apply cropping outselves

+dp->apply_cropping  = dp->dec_ctx->apply_cropping;
+dp->dec_ctx->apply_cropping = 0;
+
  if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
  av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
 av_err2str(ret));
diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
index 674054560b..88f06d7b15 100644
--- a/tests/fate/h264.mak
+++ b/tests/fate/h264.mak
@@ -312,7 +312,7 @@ fate-h264-conformance-ci1_ft_b:   CMD = 
framecrc -i $(TARGET_SAM
  fate-h264-conformance-ci_mw_d:CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CI_MW_D.264
  fate-h264-conformance-cvbs3_sony_c:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVBS3_Sony_C.jsv
  fate-h264-conformance-cvcanlma2_sony_c:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVCANLMA2_Sony_C.jsv
-fate-h264-conformance-cvfc1_sony_c:   CMD = framecrc -flags 
unaligned -i $(TARGET_SAMPLES)/h264-conformance/CVFC1_Sony_C.jsv
+fate-h264-conformance-cvfc1_sony_c:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFC1_Sony_C.jsv
  fate-h264-conformance-cvfi1_sony_d:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFI1_Sony_D.jsv
  fate-h264-conformance-cvfi1_sva_c:CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFI1_SVA_C.264
  fate-h264-conformance-cvfi2_sony_h:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFI2_Sony_H.jsv
diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak
index 4889ee8237..720603c112 100644
--- a/tests/fate/hevc.mak
+++ b/tests/fate/hevc.mak
@@ -200,8 +200,8 @@ $(HEVC_TESTS_444_8BIT): SCALE_OPTS := -pix_fmt yuv444p
  $(HEVC_TESTS_10BIT): SCALE_OPTS := -pix_fmt yuv420p10le -vf scale
  $(HEVC_TESTS_422_10BIT) $(HEVC_TESTS_422_10BIN): SCALE_OPTS := -pix_fmt 
yuv422p10le -vf scale
  $(HEVC_TESTS_444_12BIT): SCALE_OPTS := -pix_fmt yuv444p12le -vf scale
-fate-hevc-conformance-%: CMD = framecrc -flags unaligned -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bit 
$(SCALE_OPTS)
-$(HEVC_TESTS_422_10BIN): CMD = framecrc -flags unaligned -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bin 
$(SCALE_OPTS)
+fate-hevc-conformance-%: CMD = framecrc -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bit 
$(SCALE_OPTS)
+$(HEVC_TESTS_422_10BIN): CMD = framecrc -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bin 
$(SCALE_OPTS)
  
  FATE_HEVC-$(call FRAMECRC, HEVC, HEVC, HEVC_PARSER) += $(HEVC_TESTS_8BIT) $(HEVC_TESTS_444_8BIT)

  FATE_HEVC-$(call FRAMECRC, HEVC, HEVC, HEVC_PARSER SCALE_FILTER) += \
@@ -252,10 +252,10 @@ FATE_HEVC_FFPROBE-$(call DEMDEC, MOV, HEVC) += 

Re: [FFmpeg-devel] [PATCH 10/12] lavc/encode: map AVCodecContext.decoded_side_data to coded_side_data

2024-03-22 Thread James Almer

On 3/22/2024 5:28 PM, Anton Khirnov wrote:

This way it can be automagically propagated through the encoder to
muxing.
---
  libavcodec/encode.c  | 23 +++
  tests/ref/fate/libx265-hdr10 | 24 
  2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 7fc9737e93..46e46a055e 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -782,6 +782,29 @@ int ff_encode_preinit(AVCodecContext *avctx)
  return AVERROR(ENOMEM);
  }
  
+for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {

+const enum AVPacketSideDataType type_packet = 
ff_sd_global_map[i].packet;
+const enum AVFrameSideDataType  type_frame  = 
ff_sd_global_map[i].frame;
+const AVFrameSideData *sd_frame;
+AVPacketSideData  *sd_packet;
+
+sd_frame = av_frame_side_data_get(avctx->decoded_side_data,
+  avctx->nb_decoded_side_data,
+  type_frame);
+if (!sd_frame ||
+av_packet_side_data_get(avctx->coded_side_data, 
avctx->nb_coded_side_data,
+type_packet))
+
+continue;
+
+sd_packet = av_packet_side_data_new(>coded_side_data, 
>nb_coded_side_data,
+type_packet, sd_frame->size, 0);
+if (!sd_packet)
+return AVERROR(ENOMEM);
+
+memcpy(sd_packet->data, sd_frame->data, sd_frame->size);
+}
+
  if (CONFIG_FRAME_THREAD_ENCODER) {
  ret = ff_frame_thread_encoder_init(avctx);
  if (ret < 0)
diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10
index 571c837cac..68511202a5 100644
--- a/tests/ref/fate/libx265-hdr10
+++ b/tests/ref/fate/libx265-hdr10
@@ -1,16 +1,16 @@
  frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data 
Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data 
Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display 
metadata"
-frames.frame.0.side_data_list.side_data.2.red_x="13250/5"
-frames.frame.0.side_data_list.side_data.2.red_y="34500/5"
-frames.frame.0.side_data_list.side_data.2.green_x="7500/5"
-frames.frame.0.side_data_list.side_data.2.green_y="3000/5"
-frames.frame.0.side_data_list.side_data.2.blue_x="34000/5"
-frames.frame.0.side_data_list.side_data.2.blue_y="16000/5"
-frames.frame.0.side_data_list.side_data.2.white_point_x="15635/5"
-frames.frame.0.side_data_list.side_data.2.white_point_y="16450/5"
-frames.frame.0.side_data_list.side_data.2.min_luminance="50/1"
-frames.frame.0.side_data_list.side_data.2.max_luminance="1000/1"
+frames.frame.0.side_data_list.side_data.1.side_data_type="Mastering display 
metadata"
+frames.frame.0.side_data_list.side_data.1.red_x="13250/5"
+frames.frame.0.side_data_list.side_data.1.red_y="34500/5"
+frames.frame.0.side_data_list.side_data.1.green_x="7500/5"
+frames.frame.0.side_data_list.side_data.1.green_y="3000/5"
+frames.frame.0.side_data_list.side_data.1.blue_x="34000/5"
+frames.frame.0.side_data_list.side_data.1.blue_y="16000/5"
+frames.frame.0.side_data_list.side_data.1.white_point_x="15635/5"
+frames.frame.0.side_data_list.side_data.1.white_point_y="16450/5"
+frames.frame.0.side_data_list.side_data.1.min_luminance="50/1"
+frames.frame.0.side_data_list.side_data.1.max_luminance="1000/1"
+frames.frame.0.side_data_list.side_data.2.side_data_type="H.26[45] User Data 
Unregistered SEI message"
  frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level 
metadata"
  frames.frame.0.side_data_list.side_data.3.max_content=1000
  frames.frame.0.side_data_list.side_data.3.max_average=200


Why does this test change? And is it just the order or side data in the 
output frame?

___
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 15/15] avformat/internal: Move FF_FMT_INIT_CLEANUP to demux.h

2024-03-22 Thread Andreas Rheinhardt
and rename it to FF_INFMT_INIT_CLEANUP. This flag is demuxer-only,
so this is the more appropriate place for it.
This does not preclude adding internal flags common to both
demuxer and muxer in the future.

Signed-off-by: Andreas Rheinhardt 
---
 libavdevice/lavfi.c   | 2 +-
 libavformat/4xm.c | 2 +-
 libavformat/aadec.c   | 2 +-
 libavformat/aaxdec.c  | 2 +-
 libavformat/ape.c | 2 +-
 libavformat/aqtitledec.c  | 2 +-
 libavformat/assdec.c  | 2 +-
 libavformat/av1dec.c  | 4 ++--
 libavformat/avidec.c  | 2 +-
 libavformat/brstm.c   | 4 ++--
 libavformat/concatdec.c   | 2 +-
 libavformat/dashdec.c | 2 +-
 libavformat/demux.c   | 2 +-
 libavformat/demux.h   | 8 +++-
 libavformat/dvdvideodec.c | 2 +-
 libavformat/evcdec.c  | 2 +-
 libavformat/hls.c | 2 +-
 libavformat/iamfdec.c | 2 +-
 libavformat/icodec.c  | 2 +-
 libavformat/imfdec.c  | 2 +-
 libavformat/internal.h| 6 --
 libavformat/jacosubdec.c  | 2 +-
 libavformat/jpegxl_anim_dec.c | 2 +-
 libavformat/jvdec.c   | 2 +-
 libavformat/lafdec.c  | 2 +-
 libavformat/libgme.c  | 2 +-
 libavformat/libopenmpt.c  | 2 +-
 libavformat/lrcdec.c  | 2 +-
 libavformat/matroskadec.c | 4 ++--
 libavformat/mccdec.c  | 2 +-
 libavformat/microdvddec.c | 2 +-
 libavformat/mlvdec.c  | 2 +-
 libavformat/moflex.c  | 2 +-
 libavformat/mov.c | 2 +-
 libavformat/mpeg.c| 2 +-
 libavformat/mpl2dec.c | 2 +-
 libavformat/mpsubdec.c| 2 +-
 libavformat/mxfdec.c  | 2 +-
 libavformat/nsvdec.c  | 2 +-
 libavformat/nutdec.c  | 2 +-
 libavformat/oggdec.c  | 2 +-
 libavformat/omadec.c  | 2 +-
 libavformat/paf.c | 2 +-
 libavformat/pdvdec.c  | 2 +-
 libavformat/pjsdec.c  | 2 +-
 libavformat/pp_bnk.c  | 2 +-
 libavformat/realtextdec.c | 2 +-
 libavformat/rmdec.c   | 4 ++--
 libavformat/samidec.c | 2 +-
 libavformat/sccdec.c  | 2 +-
 libavformat/scd.c | 2 +-
 libavformat/segafilm.c| 2 +-
 libavformat/sierravmd.c   | 2 +-
 libavformat/srtdec.c  | 2 +-
 libavformat/stldec.c  | 2 +-
 libavformat/subviewer1dec.c   | 2 +-
 libavformat/subviewerdec.c| 2 +-
 libavformat/tedcaptionsdec.c  | 2 +-
 libavformat/tiertexseq.c  | 2 +-
 libavformat/vapoursynth.c | 2 +-
 libavformat/vividas.c | 2 +-
 libavformat/vplayerdec.c  | 2 +-
 libavformat/wc3movie.c| 2 +-
 libavformat/webvttdec.c   | 2 +-
 libavformat/xmv.c | 2 +-
 65 files changed, 74 insertions(+), 74 deletions(-)

diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index 58ad62bd97..ce10d61f8a 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -503,5 +503,5 @@ const FFInputFormat ff_lavfi_demuxer = {
 .read_header= lavfi_read_header,
 .read_packet= lavfi_read_packet,
 .read_close = lavfi_read_close,
-.flags_internal = FF_FMT_INIT_CLEANUP,
+.flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
 };
diff --git a/libavformat/4xm.c b/libavformat/4xm.c
index 3424791b81..516c7866bd 100644
--- a/libavformat/4xm.c
+++ b/libavformat/4xm.c
@@ -401,7 +401,7 @@ const FFInputFormat ff_fourxm_demuxer = {
 .p.name = "4xm",
 .p.long_name= NULL_IF_CONFIG_SMALL("4X Technologies"),
 .priv_data_size = sizeof(FourxmDemuxContext),
-.flags_internal = FF_FMT_INIT_CLEANUP,
+.flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
 .read_probe = fourxm_probe,
 .read_header= fourxm_read_header,
 .read_packet= fourxm_read_packet,
diff --git a/libavformat/aadec.c b/libavformat/aadec.c
index dd698d0d5d..c39fb51a8d 100644
--- a/libavformat/aadec.c
+++ b/libavformat/aadec.c
@@ -383,5 +383,5 @@ const FFInputFormat ff_aa_demuxer = {
 .read_packet= aa_read_packet,
 .read_seek  = aa_read_seek,
 .read_close = aa_read_close,
-.flags_internal = FF_FMT_INIT_CLEANUP,
+.flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
 };
diff --git a/libavformat/aaxdec.c b/libavformat/aaxdec.c
index 0ccd4944db..830ae5d89e 100644
--- a/libavformat/aaxdec.c
+++ b/libavformat/aaxdec.c
@@ -389,7 +389,7 @@ const FFInputFormat ff_aax_demuxer = {
 .p.extensions   = "aax",
 .p.flags= AVFMT_GENERIC_INDEX,
 .priv_data_size = sizeof(AAXContext),
-.flags_internal = FF_FMT_INIT_CLEANUP,
+.flags_internal = FF_INFMT_FLAG_INIT_CLEANUP,
 .read_probe = aax_probe,
 .read_header= aax_read_header,
 .read_packet= aax_read_packet,
diff --git a/libavformat/ape.c b/libavformat/ape.c
index b3994d12fd..231064be61 100644
--- a/libavformat/ape.c
+++ b/libavformat/ape.c
@@ -450,7 +450,7 @@ const FFInputFormat ff_ape_demuxer = {
 .p.long_name= NULL_IF_CONFIG_SMALL("Monkey's Audio"),
 .p.extensions  

[FFmpeg-devel] [PATCH 14/15] avformat/vqf: Return 0 on success in read_packet

2024-03-22 Thread Andreas Rheinhardt
Demuxers are not supposed to return the size of the packet read.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/vqf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/vqf.c b/libavformat/vqf.c
index 4c7f5aa22e..409c014a92 100644
--- a/libavformat/vqf.c
+++ b/libavformat/vqf.c
@@ -259,7 +259,7 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 c->last_frame_bits = pkt->data[size+1];
 c->remaining_bits  = (size << 3) - c->frame_bit_len + c->remaining_bits;
 
-return size+2;
+return 0;
 }
 
 static int vqf_read_seek(AVFormatContext *s,
-- 
2.40.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 07/15] avformat/avr: Combine skips

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/avr.c | 12 +++-
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/libavformat/avr.c b/libavformat/avr.c
index 12286c04d4..261edef4b5 100644
--- a/libavformat/avr.c
+++ b/libavformat/avr.c
@@ -49,8 +49,7 @@ static int avr_read_header(AVFormatContext *s)
 
 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
 
-avio_skip(s->pb, 4); // magic
-avio_skip(s->pb, 8); // sample_name
+avio_skip(s->pb, 4 /* magic */ + 8 /* sample_name */);
 
 chan = avio_rb16(s->pb);
 if (!chan) {
@@ -66,18 +65,13 @@ static int avr_read_header(AVFormatContext *s)
 
 sign = avio_rb16(s->pb);
 
-avio_skip(s->pb, 2); // loop
-avio_skip(s->pb, 2); // midi
-avio_skip(s->pb, 1); // replay speed
+avio_skip(s->pb, 2 /* loop */ + 2 /* midi */ + 1 /* replay speed */);
 
 st->codecpar->sample_rate = avio_rb24(s->pb);
 if (st->codecpar->sample_rate == 0)
 return AVERROR_INVALIDDATA;
 
-avio_skip(s->pb, 4 * 3);
-avio_skip(s->pb, 2 * 3);
-avio_skip(s->pb, 20);
-avio_skip(s->pb, 64);
+avio_skip(s->pb, 4 * 3 + 2 * 3 + 20 + 64);
 
 st->codecpar->codec_id = ff_get_pcm_codec_id(bps, 0, 1, sign);
 if (st->codecpar->codec_id == AV_CODEC_ID_NONE) {
-- 
2.40.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 13/15] avformat/pcmdec: Reindent after the previous commit

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/pcmdec.c | 52 ++--
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index 03feefb5bb..e95a08df4b 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -51,33 +51,33 @@ static int pcm_handle_mime_type(AVFormatContext *s, const 
char *prefix,
 if (!av_stristart(mime_type, prefix, )) /* audio/L16 */
 goto end;
 
-while (options = strchr(options, ';')) {
-options++;
-if (!rate)
-sscanf(options, " rate=%d", );
-if (!channels)
-sscanf(options, " channels=%d", );
-if (!little_endian) {
- char val[sizeof("little-endian")];
- if (sscanf(options, " endianness=%13s", val) == 1) {
- little_endian = strcmp(val, "little-endian") == 0;
- }
-}
+while (options = strchr(options, ';')) {
+options++;
+if (!rate)
+sscanf(options, " rate=%d", );
+if (!channels)
+sscanf(options, " channels=%d", );
+if (!little_endian) {
+char val[sizeof("little-endian")];
+if (sscanf(options, " endianness=%13s", val) == 1) {
+little_endian = strcmp(val, "little-endian") == 0;
 }
-if (rate <= 0) {
-av_log(s, AV_LOG_ERROR,
-   "Invalid sample_rate found in mime_type \"%s\"\n",
-   mime_type);
-av_freep(_type);
-return AVERROR_INVALIDDATA;
-}
-par->sample_rate = rate;
-if (channels > 0) {
-av_channel_layout_uninit(>ch_layout);
-par->ch_layout.nb_channels = channels;
-}
-if (little_endian)
-par->codec_id = AV_CODEC_ID_PCM_S16LE;
+}
+}
+if (rate <= 0) {
+av_log(s, AV_LOG_ERROR,
+   "Invalid sample_rate found in mime_type \"%s\"\n",
+   mime_type);
+av_freep(_type);
+return AVERROR_INVALIDDATA;
+}
+par->sample_rate = rate;
+if (channels > 0) {
+av_channel_layout_uninit(>ch_layout);
+par->ch_layout.nb_channels = channels;
+}
+if (little_endian)
+par->codec_id = AV_CODEC_ID_PCM_S16LE;
 
 end:
 av_freep(_type);
-- 
2.40.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 12/15] avformat/pcmdec: Avoid av_freep(&(void*){NULL})

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/pcmdec.c | 61 
 1 file changed, 39 insertions(+), 22 deletions(-)

diff --git a/libavformat/pcmdec.c b/libavformat/pcmdec.c
index e9c97f7959..03feefb5bb 100644
--- a/libavformat/pcmdec.c
+++ b/libavformat/pcmdec.c
@@ -37,31 +37,20 @@ typedef struct PCMAudioDemuxerContext {
 AVChannelLayout ch_layout;
 } PCMAudioDemuxerContext;
 
-static int pcm_read_header(AVFormatContext *s)
+static int pcm_handle_mime_type(AVFormatContext *s, const char *prefix,
+AVCodecParameters *par)
 {
-PCMAudioDemuxerContext *s1 = s->priv_data;
-AVCodecParameters *par;
-AVStream *st;
+int rate = 0, channels = 0, little_endian = 0;
 uint8_t *mime_type = NULL;
-int ret;
+const char *options;
 
-st = avformat_new_stream(s, NULL);
-if (!st)
-return AVERROR(ENOMEM);
-par = st->codecpar;
+av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, _type);
+if (!mime_type)
+return 0;
 
-par->codec_type  = AVMEDIA_TYPE_AUDIO;
-par->codec_id= ffifmt(s->iformat)->raw_codec_id;
-par->sample_rate = s1->sample_rate;
-ret = av_channel_layout_copy(>ch_layout, >ch_layout);
-if (ret < 0)
-return ret;
+if (!av_stristart(mime_type, prefix, )) /* audio/L16 */
+goto end;
 
-av_opt_get(s->pb, "mime_type", AV_OPT_SEARCH_CHILDREN, _type);
-if (mime_type && s->iformat->mime_type) {
-int rate = 0, channels = 0, little_endian = 0;
-const char *options;
-if (av_stristart(mime_type, s->iformat->mime_type, )) { /* 
audio/L16 */
 while (options = strchr(options, ';')) {
 options++;
 if (!rate)
@@ -89,10 +78,38 @@ static int pcm_read_header(AVFormatContext *s)
 }
 if (little_endian)
 par->codec_id = AV_CODEC_ID_PCM_S16LE;
-}
-}
+
+end:
 av_freep(_type);
 
+return 0;
+}
+
+static int pcm_read_header(AVFormatContext *s)
+{
+PCMAudioDemuxerContext *s1 = s->priv_data;
+AVCodecParameters *par;
+AVStream *st;
+int ret;
+
+st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+par = st->codecpar;
+
+par->codec_type  = AVMEDIA_TYPE_AUDIO;
+par->codec_id= ffifmt(s->iformat)->raw_codec_id;
+par->sample_rate = s1->sample_rate;
+ret = av_channel_layout_copy(>ch_layout, >ch_layout);
+if (ret < 0)
+return ret;
+
+if (s->iformat->mime_type) {
+ret = pcm_handle_mime_type(s, s->iformat->mime_type, par);
+if (ret < 0)
+return ret;
+}
+
 par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);
 
 av_assert0(par->bits_per_coded_sample > 0);
-- 
2.40.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 11/15] avformat/cdg: Don't store avio_size() return value in int

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/cdg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/cdg.c b/libavformat/cdg.c
index 2030cdff89..43d919e302 100644
--- a/libavformat/cdg.c
+++ b/libavformat/cdg.c
@@ -46,7 +46,7 @@ static int read_probe(const AVProbeData *p)
 static int read_header(AVFormatContext *s)
 {
 AVStream *vst;
-int ret;
+int64_t ret;
 
 vst = avformat_new_stream(s, NULL);
 if (!vst)
-- 
2.40.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 10/15] avformat/lafdec: Fix shadowing

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/lafdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/lafdec.c b/libavformat/lafdec.c
index 05f30691ba..77eab2ea6b 100644
--- a/libavformat/lafdec.c
+++ b/libavformat/lafdec.c
@@ -148,8 +148,8 @@ static int laf_read_header(AVFormatContext *ctx)
 if (!s->data)
 return AVERROR(ENOMEM);
 
-for (int st = 0; st < st_count; st++) {
-StreamParams *stp = >p[st];
+for (unsigned i = 0; i < st_count; i++) {
+StreamParams *stp = >p[i];
 AVCodecParameters *par;
 AVStream *st = avformat_new_stream(ctx, NULL);
 if (!st)
-- 
2.40.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 09/15] avformat/argo_cvg: Avoid relocations for ArgoCVGOverride

2024-03-22 Thread Andreas Rheinhardt
The average length of the strings used here does not differ much
from the length of the longest string; therefore it makes sense
to use an array big enough for the longest string and not
a pointer to a string. This also moves this array into .rodata
(from .data.rel.ro).

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/argo_cvg.c | 38 ++
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/libavformat/argo_cvg.c b/libavformat/argo_cvg.c
index 5db2a85dd8..03ae6fa59e 100644
--- a/libavformat/argo_cvg.c
+++ b/libavformat/argo_cvg.c
@@ -47,13 +47,6 @@ typedef struct ArgoCVGHeader {
 uint32_t reverb; /*< Reverb flag. */
 } ArgoCVGHeader;
 
-typedef struct ArgoCVGOverride {
-const char*name;
-ArgoCVGHeader header;
-uint32_t  checksum;
-int   sample_rate;
-} ArgoCVGOverride;
-
 typedef struct ArgoCVGDemuxContext {
 ArgoCVGHeader header;
 uint32_t  checksum;
@@ -72,12 +65,33 @@ typedef struct ArgoCVGMuxContext {
 
 #if CONFIG_ARGO_CVG_DEMUXER
 /* "Special" files that are played at a different rate. */
+//  FILE(NAME, SIZE, LOOP, REVERB, CHECKSUM, SAMPLE_RATE)
+#define OVERRIDE_FILES(FILE)   \
+FILE(CRYS, 23592, 0, 1, 2495499, 88200) /* Beta */ \
+FILE(REDCRY88, 38280, 0, 1, 4134848, 88200) /* Beta */ \
+FILE(DANLOOP1, 54744, 1, 0, 5684641, 37800) /* Beta */ \
+FILE(PICKUP88, 12904, 0, 1, 1348091, 48000) /* Beta */ \
+FILE(SELECT1,   5080, 0, 1,  549987, 44100) /* Beta */ \
+
+#define MAX_FILENAME_SIZE(NAME, SIZE, LOOP, REVERB, CHECKSUM, SAMPLE_RATE) \
+MAX_SIZE_BEFORE_ ## NAME,  \
+MAX_SIZE_UNTIL_ ## NAME ## _MINUS1 = FFMAX(sizeof(#NAME ".CVG"), 
MAX_SIZE_BEFORE_ ## NAME) - 1,
+enum {
+OVERRIDE_FILES(MAX_FILENAME_SIZE)
+MAX_OVERRIDE_FILENAME_SIZE
+};
+
+typedef struct ArgoCVGOverride {
+const charname[MAX_OVERRIDE_FILENAME_SIZE];
+ArgoCVGHeader header;
+uint32_t  checksum;
+int   sample_rate;
+} ArgoCVGOverride;
+
+#define FILE(NAME, SIZE, LOOP, REVERB, CHECKSUM, SAMPLE_RATE) \
+{ #NAME ".CVG", { SIZE, LOOP, REVERB }, CHECKSUM, SAMPLE_RATE },
 static const ArgoCVGOverride overrides[] = {
-{ "CRYS.CVG", { 23592, 0, 1 }, 2495499, 88200 }, /* Beta */
-{ "REDCRY88.CVG", { 38280, 0, 1 }, 4134848, 88200 }, /* Beta */
-{ "DANLOOP1.CVG", { 54744, 1, 0 }, 5684641, 37800 }, /* Beta */
-{ "PICKUP88.CVG", { 12904, 0, 1 }, 1348091, 48000 }, /* Beta */
-{ "SELECT1.CVG",  {  5080, 0, 1 },  549987, 44100 }, /* Beta */
+OVERRIDE_FILES(FILE)
 };
 
 static int argo_cvg_probe(const AVProbeData *p)
-- 
2.40.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 08/15] avformat/wady: Combine skips

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/wady.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libavformat/wady.c b/libavformat/wady.c
index 6dcc0018f3..17b7a88c19 100644
--- a/libavformat/wady.c
+++ b/libavformat/wady.c
@@ -45,13 +45,12 @@ static int wady_read_header(AVFormatContext *s)
 int channels, ret;
 AVStream *st;
 
-avio_skip(pb, 4);
+avio_skip(pb, 4 + 1);
 
 st = avformat_new_stream(s, NULL);
 if (!st)
 return AVERROR(ENOMEM);
 
-avio_skip(pb, 1);
 par  = st->codecpar;
 par->codec_type  = AVMEDIA_TYPE_AUDIO;
 par->codec_id= AV_CODEC_ID_WADY_DPCM;
-- 
2.40.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 06/15] avformat/fsb: Don't set data_offset manually

2024-03-22 Thread Andreas Rheinhardt
It is set generically to the value that it is to here.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/fsb.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavformat/fsb.c b/libavformat/fsb.c
index 4189822d8e..0febeffd56 100644
--- a/libavformat/fsb.c
+++ b/libavformat/fsb.c
@@ -157,7 +157,6 @@ static int fsb_read_header(AVFormatContext *s)
 }
 
 avio_skip(pb, offset - avio_tell(pb));
-ffformatcontext(s)->data_offset = avio_tell(pb);
 
 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
 
-- 
2.40.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 05/15] avformat/wvedec: Inline constant

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavformat/wvedec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/wvedec.c b/libavformat/wvedec.c
index 43e6359892..13934b78e4 100644
--- a/libavformat/wvedec.c
+++ b/libavformat/wvedec.c
@@ -45,7 +45,7 @@ static int wve_read_header(AVFormatContext *s)
 st->codecpar->codec_id= AV_CODEC_ID_PCM_ALAW;
 st->codecpar->sample_rate = 8000;
 st->codecpar->ch_layout.nb_channels = 1;
-st->codecpar->bits_per_coded_sample = 
av_get_bits_per_sample(st->codecpar->codec_id);
+st->codecpar->bits_per_coded_sample = 8;
 st->codecpar->block_align = st->codecpar->bits_per_coded_sample *
 st->codecpar->ch_layout.nb_channels / 8;
 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
-- 
2.40.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 04/15] avformat/g722: Inline constants

2024-03-22 Thread Andreas Rheinhardt
Forgotten in 5f0e161dd61552ad70760bad35b869eaec7368ff.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/g722.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/libavformat/g722.c b/libavformat/g722.c
index 15519d90b5..adb78e8db5 100644
--- a/libavformat/g722.c
+++ b/libavformat/g722.c
@@ -19,7 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "libavutil/avassert.h"
 #include "avformat.h"
 #include "demux.h"
 #include "internal.h"
@@ -38,10 +37,7 @@ static int g722_read_header(AVFormatContext *s)
 st->codecpar->sample_rate = 16000;
 st->codecpar->ch_layout   = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
 
-st->codecpar->bits_per_coded_sample =
-av_get_bits_per_sample(st->codecpar->codec_id);
-
-av_assert0(st->codecpar->bits_per_coded_sample > 0);
+st->codecpar->bits_per_coded_sample = 4;
 
 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
 return 0;
-- 
2.40.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 03/15] avformat/fitsdec: Don't use AVBPrint for temporary storage

2024-03-22 Thread Andreas Rheinhardt
Most of the data in the temporary storage ends up being
returned to the user as AVPacket.data, so it makes sense
to avoid using the AVBPrint for temporary storage altogether
(in particular in light of the fact that the blocks read here
are too big for the small-string optimization anyway) and
read the data directly into AVPacket.data. This also avoids
another memcpy() from a stack buffer to the AVBPrint in ts_image()
(that could always have been avoided with av_bprint_get_buffer()).

These changes also allow to use av_append_packet(), which
greatly simplifies the code; furthermore, one can avoid cleanup
code on error as the packet is already unreferenced generically
on error.

There are two user-visible changes from this patch:
1. Truncated packets are now marked as corrupt.
2. AVPacket.pos is set (it corresponds to the discarded header
line, 80 bytes before the position corresponding to the
actual packet data).

Furthermore, this patch also removes code that triggered
a -Wtautological-constant-out-of-range-compare warning
from Clang (namely a comparison of an unsigned and INT64_MAX
in an assert).

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/fitsdec.c | 80 ++-
 1 file changed, 25 insertions(+), 55 deletions(-)

diff --git a/libavformat/fitsdec.c b/libavformat/fitsdec.c
index fe2dd5ad5d..6771dda327 100644
--- a/libavformat/fitsdec.c
+++ b/libavformat/fitsdec.c
@@ -24,13 +24,10 @@
  * FITS demuxer.
  */
 
-#include "libavutil/avassert.h"
-#include "libavutil/intreadwrite.h"
 #include "demux.h"
 #include "internal.h"
 #include "libavutil/opt.h"
 #include "libavcodec/fits.h"
-#include "libavutil/bprint.h"
 
 #define FITS_BLOCK_SIZE 2880
 
@@ -71,31 +68,31 @@ static int fits_read_header(AVFormatContext *s)
  * @param s pointer to AVFormat Context
  * @param fits pointer to FITSContext
  * @param header pointer to FITSHeader
- * @param avbuf pointer to AVBPrint to store the header
+ * @param pkt pointer to AVPacket to store the header
  * @param data_size to store the size of data part
- * @return 1 if image found, 0 if any other extension and AVERROR_INVALIDDATA 
otherwise
+ * @return 1 if image found, 0 if any other extension and AVERROR code 
otherwise
  */
-static int64_t is_image(AVFormatContext *s, FITSContext *fits, FITSHeader 
*header,
- AVBPrint *avbuf, uint64_t *data_size)
+static int is_image(AVFormatContext *s, FITSContext *fits, FITSHeader *header,
+AVPacket *pkt, uint64_t *data_size)
 {
 int i, ret, image = 0;
-char buf[FITS_BLOCK_SIZE] = { 0 };
-int64_t buf_size = 0, size = 0, t;
+int64_t size = 0, t;
 
 do {
-ret = avio_read(s->pb, buf, FITS_BLOCK_SIZE);
+const uint8_t *buf, *buf_end;
+ret = av_append_packet(s->pb, pkt, FITS_BLOCK_SIZE);
 if (ret < 0) {
 return ret;
 } else if (ret < FITS_BLOCK_SIZE) {
 return AVERROR_INVALIDDATA;
 }
 
-av_bprint_append_data(avbuf, buf, FITS_BLOCK_SIZE);
 ret = 0;
-buf_size = 0;
-while(!ret && buf_size < FITS_BLOCK_SIZE) {
-ret = avpriv_fits_header_parse_line(s, header, buf + buf_size, 
NULL);
-buf_size += 80;
+buf_end = pkt->data + pkt->size;
+buf = buf_end - FITS_BLOCK_SIZE;
+while(!ret && buf < buf_end) {
+ret = avpriv_fits_header_parse_line(s, header, buf, NULL);
+buf += 80;
 }
 } while (!ret);
 if (ret < 0)
@@ -142,12 +139,10 @@ static int64_t is_image(AVFormatContext *s, FITSContext 
*fits, FITSHeader *heade
 
 static int fits_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
-int64_t pos, ret;
 uint64_t size;
 FITSContext *fits = s->priv_data;
 FITSHeader header;
-AVBPrint avbuf;
-char *buf;
+int ret;
 
 if (fits->first_image) {
 avpriv_fits_header_init(, STATE_SIMPLE);
@@ -155,57 +150,32 @@ static int fits_read_packet(AVFormatContext *s, AVPacket 
*pkt)
 avpriv_fits_header_init(, STATE_XTENSION);
 }
 
-av_bprint_init(, FITS_BLOCK_SIZE, AV_BPRINT_SIZE_UNLIMITED);
-while ((ret = is_image(s, fits, , , )) == 0) {
-av_bprint_finalize(, NULL);
-pos = avio_skip(s->pb, size);
+while ((ret = is_image(s, fits, , pkt, )) == 0) {
+int64_t pos = avio_skip(s->pb, size);
 if (pos < 0)
 return pos;
 
-av_bprint_init(, FITS_BLOCK_SIZE, AV_BPRINT_SIZE_UNLIMITED);
 avpriv_fits_header_init(, STATE_XTENSION);
+av_packet_unref(pkt);
 }
 if (ret < 0)
-goto fail;
-
-if (!av_bprint_is_complete()) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
-av_assert0(avbuf.len <= INT64_MAX && size <= INT64_MAX);
-if (avbuf.len + size > INT_MAX - 80)  {
-ret = AVERROR_INVALIDDATA;
-goto fail;
-}
-// Header is sent with the first line removed...
-ret = av_new_packet(pkt, avbuf.len - 80 + 

[FFmpeg-devel] [PATCH 02/15] avformat/hls: Don't access FFInputFormat.raw_codec_id

2024-03-22 Thread Andreas Rheinhardt
It is an implementation detail of other input formats whether
they use raw_codec_id or not. The HLS demuxer should not rely
on this.

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/hls.c   | 10 ++
 libavformat/hls_sample_encryption.c |  1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index f6b44c2e35..94defa9384 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -2100,10 +2100,12 @@ static int hls_read_header(AVFormatContext *s)
  */
 if (seg && seg->key_type == KEY_SAMPLE_AES && pls->is_id3_timestamped 
&&
 pls->audio_setup_info.codec_id != AV_CODEC_ID_NONE) {
-void *iter = NULL;
-while ((in_fmt = av_demuxer_iterate()))
-if (ffifmt(in_fmt)->raw_codec_id == 
pls->audio_setup_info.codec_id)
-break;
+av_assert1(pls->audio_setup_info.codec_id == AV_CODEC_ID_AAC ||
+   pls->audio_setup_info.codec_id == AV_CODEC_ID_AC3 ||
+   pls->audio_setup_info.codec_id == AV_CODEC_ID_EAC3);
+// Keep this list in sync with ff_hls_senc_read_audio_setup_info()
+in_fmt = av_find_input_format(pls->audio_setup_info.codec_id == 
AV_CODEC_ID_AAC ? "aac" :
+  pls->audio_setup_info.codec_id == 
AV_CODEC_ID_AC3 ? "ac3" : "eac3");
 } else {
 pls->ctx->probesize = s->probesize > 0 ? s->probesize : 1024 * 4;
 pls->ctx->max_analyze_duration = s->max_analyze_duration > 0 ? 
s->max_analyze_duration : 4 * AV_TIME_BASE;
diff --git a/libavformat/hls_sample_encryption.c 
b/libavformat/hls_sample_encryption.c
index d5b4c11b66..f412836d4f 100644
--- a/libavformat/hls_sample_encryption.c
+++ b/libavformat/hls_sample_encryption.c
@@ -64,6 +64,7 @@ void ff_hls_senc_read_audio_setup_info(HLSAudioSetupInfo 
*info, const uint8_t *b
 
 info->codec_tag = AV_RL32(buf);
 
+/* Always keep this list in sync with the one from hls_read_header() */
 if (info->codec_tag == MKTAG('z','a','a','c'))
 info->codec_id = AV_CODEC_ID_AAC;
 else if (info->codec_tag == MKTAG('z','a','c','3'))
-- 
2.40.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 01/15] configure: Make hls demuxer select AAC, AC3 and EAC3 demuxers

2024-03-22 Thread Andreas Rheinhardt
The code relies on their presence and would presumably crash
when retrieving in_fmt->name if an encrypted stream with a codec id
without demuxer were encountered.

Signed-off-by: Andreas Rheinhardt 
---
 configure | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure b/configure
index 343edb38ab..90d18e0970 100755
--- a/configure
+++ b/configure
@@ -3590,7 +3590,7 @@ flac_demuxer_select="flac_parser"
 flv_muxer_select="aac_adtstoasc_bsf"
 gxf_muxer_select="pcm_rechunk_bsf"
 hds_muxer_select="flv_muxer"
-hls_demuxer_select="adts_header ac3_parser mov_demuxer mpegts_demuxer"
+hls_demuxer_select="aac_demuxer ac3_demuxer adts_header ac3_parser 
eac3_demuxer mov_demuxer mpegts_demuxer"
 hls_muxer_select="mov_muxer mpegts_muxer"
 iamf_demuxer_select="iamfdec"
 iamf_muxer_select="iamfenc"
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH] avformat/mux: Remove check for AVFMT_ALLOW_FLUSH

2024-03-22 Thread Andreas Rheinhardt
Due to the bump it is now certain that all devices
that support flushing have the proper internal flag set.
(Notice that the check for LIBAVFORMAT_VERSION was wrong.)

Signed-off-by: Andreas Rheinhardt 
---
 libavformat/mux.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index f23eb0188d..630204a8ec 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1236,13 +1236,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *in)
 int ret;
 
 if (!in) {
-#if FF_API_ALLOW_FLUSH || LIBAVFORMAT_VERSION_MAJOR >= 61
-// Hint: The pulse audio output device has this set,
-// so we can't switch the check to FF_OFMT_FLAG_ALLOW_FLUSH 
immediately.
-if (s->oformat->flags & AVFMT_ALLOW_FLUSH) {
-#else
 if (ffofmt(s->oformat)->flags_internal & FF_OFMT_FLAG_ALLOW_FLUSH) {
-#endif
 ret = ffofmt(s->oformat)->write_packet(s, NULL);
 flush_if_needed(s);
 if (ret >= 0 && s->pb && s->pb->error < 0)
-- 
2.40.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 1/2] avformat/demux: Restore pkt->stream_index assert check

2024-03-22 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> It has been moved after "st  = s->streams[pkt->stream_index]"
> in b140b8332c617b0eef4f872f3ef90c469e99920f.
> Deduplicate ff_read_packet() and ff_buffer_packet()
> while fixing this.
> This also fixes shadowing in ff_read_packet().
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/demux.c | 75 +++--
>  1 file changed, 31 insertions(+), 44 deletions(-)
> 
> diff --git a/libavformat/demux.c b/libavformat/demux.c
> index 4c50eb5568..4345ed4c8c 100644
> --- a/libavformat/demux.c
> +++ b/libavformat/demux.c
> @@ -532,9 +532,6 @@ static void update_timestamps(AVFormatContext *s, 
> AVStream *st, AVPacket *pkt)
>  {
>  FFStream *const sti = ffstream(st);
>  
> -av_assert0(pkt->stream_index < (unsigned)s->nb_streams &&
> -   "Invalid stream index.\n");
> -
>  if (update_wrap_reference(s, st, pkt->stream_index, pkt) && 
> sti->pts_wrap_behavior == AV_PTS_WRAP_SUB_OFFSET) {
>  // correct first time stamps to negative values
>  if (!is_relative(sti->first_dts))
> @@ -555,13 +552,24 @@ static void update_timestamps(AVFormatContext *s, 
> AVStream *st, AVPacket *pkt)
>  pkt->dts = pkt->pts = av_rescale_q(av_gettime(), AV_TIME_BASE_Q, 
> st->time_base);
>  }
>  
> -int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
> +/**
> + * Handle a new packet and either return it directly if possible and
> + * allow_passthrough is true or queue the packet (or drop the packet
> + * if corrupt).
> + *
> + * @return < 0 on error, 0 if the packet was passed through,
> + * 1 if it was queued or dropped
> + */
> +static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int 
> allow_passthrough)
>  {
>  FFFormatContext *const si = ffformatcontext(s);
> -AVStream *st  = s->streams[pkt->stream_index];
> -FFStream *sti = ffstream(st);
> +AVStream *st;
> +FFStream *sti;
>  int err;
>  
> +av_assert0(pkt->stream_index < (unsigned)s->nb_streams &&
> +   "Invalid stream index.\n");
> +
>  if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
>  av_log(s, AV_LOG_WARNING,
> "Packet corrupt (stream = %d, dts = %s)",
> @@ -569,13 +577,19 @@ int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
>  if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
>  av_log(s, AV_LOG_WARNING, ", dropping it.\n");
>  av_packet_unref(pkt);
> -return 0;
> +return 1;
>  }
>  av_log(s, AV_LOG_WARNING, ".\n");
>  }
>  
> +st  = s->streams[pkt->stream_index];
> +sti = ffstream(st);
> +
>  update_timestamps(s, st, pkt);
>  
> +if (sti->request_probe <= 0 && allow_passthrough && 
> !si->raw_packet_buffer.head)
> +return 0;
> +
>  err = avpriv_packet_list_put(>raw_packet_buffer, pkt, NULL, 0);
>  if (err < 0) {
>  av_packet_unref(pkt);
> @@ -585,14 +599,18 @@ int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
>  pkt = >raw_packet_buffer.tail->pkt;
>  si->raw_packet_buffer_size += pkt->size;
>  
> -if (sti->request_probe <= 0)
> -return 0;
> -
>  err = probe_codec(s, st, pkt);
>  if (err < 0)
>  return err;
>  
> -return 0;
> +return 1;
> +}
> +
> +int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +int err = handle_new_packet(s, pkt, 0);
> +
> +return err < 0 ? err : 0;
>  }
>  
>  int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
> @@ -612,9 +630,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  
>  for (;;) {
>  PacketListEntry *pktl = si->raw_packet_buffer.head;
> -AVStream *st;
> -FFStream *sti;
> -const AVPacket *pkt1;
>  
>  if (pktl) {
>  AVStream *const st = s->streams[pktl->pkt.stream_index];
> @@ -656,36 +671,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  return err;
>  }
>  
> -if (pkt->flags & AV_PKT_FLAG_CORRUPT) {
> -av_log(s, AV_LOG_WARNING,
> -   "Packet corrupt (stream = %d, dts = %s)",
> -   pkt->stream_index, av_ts2str(pkt->dts));
> -if (s->flags & AVFMT_FLAG_DISCARD_CORRUPT) {
> -av_log(s, AV_LOG_WARNING, ", dropping it.\n");
> -av_packet_unref(pkt);
> -continue;
> -}
> -av_log(s, AV_LOG_WARNING, ".\n");
> -}
> -
> -st  = s->streams[pkt->stream_index];
> -sti = ffstream(st);
> -
> -update_timestamps(s, st, pkt);
> -
> -if (!pktl && sti->request_probe <= 0)
> -return 0;
> -
> -err = avpriv_packet_list_put(>raw_packet_buffer,
> - pkt, NULL, 0);
> -if (err < 0) {
> -av_packet_unref(pkt);
> -return err;
> -}
> -pkt1 = >raw_packet_buffer.tail->pkt;
> -si->raw_packet_buffer_size += pkt1->size;
> -
> -if ((err = probe_codec(s, st, pkt1)) < 0)

[FFmpeg-devel] [PATCH 5/5] avcodec/hevcdec: export global side data in AVCodecContext

2024-03-22 Thread James Almer
Signed-off-by: James Almer 
---
 libavcodec/avcodec.h   |   2 +-
 libavcodec/h2645_sei.c | 217 -
 libavcodec/h2645_sei.h |   2 +
 libavcodec/hevcdec.c   |   4 +
 4 files changed, 136 insertions(+), 89 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 83dc487251..968009a192 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2071,7 +2071,7 @@ typedef struct AVCodecContext {
  * - encoding: may be set by user before calling avcodec_open2() for
  * encoder configuration. Afterwards owned and freed by the
  * encoder.
- * - decoding: unused
+ * - decoding: may be set by libavcodec in avcodec_open2().
  */
 AVFrameSideData  **decoded_side_data;
 int nb_decoded_side_data;
diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index 2e098d1069..32bb4f841d 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -511,6 +511,124 @@ static int is_frame_packing_type_valid(SEIFpaType type, 
enum AVCodecID codec_id)
type >= SEI_FPA_TYPE_SIDE_BY_SIDE;
 }
 
+static int h2645_sei_to_side_data(AVCodecContext *avctx, H2645SEI *sei,
+  AVFrameSideData ***sd, int *nb_sd)
+{
+int ret;
+
+for (unsigned i = 0; i < sei->unregistered.nb_buf_ref; i++) {
+H2645SEIUnregistered *unreg = >unregistered;
+AVBufferRef *buf;
+
+if (!unreg->buf_ref[i])
+continue;
+
+buf = av_buffer_ref(unreg->buf_ref[i]);
+if (!buf)
+return AVERROR(ENOMEM);
+
+if (!av_frame_side_data_add(sd, nb_sd, AV_FRAME_DATA_SEI_UNREGISTERED, 
, 0)) {
+av_buffer_unref();
+return AVERROR(ENOMEM);
+}
+}
+
+if (sei->ambient_viewing_environment.present) {
+H2645SEIAmbientViewingEnvironment *env =
+>ambient_viewing_environment;
+AVBufferRef *buf;
+size_t size;
+
+AVAmbientViewingEnvironment *dst_env =
+av_ambient_viewing_environment_alloc();
+if (!dst_env)
+return AVERROR(ENOMEM);
+
+buf = av_buffer_create((uint8_t *)dst_env, size, NULL, NULL, 0);
+if (!buf) {
+av_free(dst_env);
+return AVERROR(ENOMEM);
+}
+
+ret = ff_frame_new_side_data_from_buf(avctx, sd, nb_sd,
+  
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT, );
+
+if (ret < 0)
+return ret;
+
+dst_env->ambient_illuminance = av_make_q(env->ambient_illuminance, 
1);
+dst_env->ambient_light_x = av_make_q(env->ambient_light_x, 
5);
+dst_env->ambient_light_y = av_make_q(env->ambient_light_y, 
5);
+}
+
+if (sei->mastering_display.present) {
+// HEVC uses a g,b,r ordering, which we convert to a more natural r,g,b
+const int mapping[3] = {2, 0, 1};
+const int chroma_den = 5;
+const int luma_den = 1;
+int i;
+AVMasteringDisplayMetadata *metadata;
+
+ret = ff_decode_mastering_display_new(avctx, sd, nb_sd, );
+if (ret < 0)
+return ret;
+
+if (metadata) {
+for (i = 0; i < 3; i++) {
+const int j = mapping[i];
+metadata->display_primaries[i][0].num = 
sei->mastering_display.display_primaries[j][0];
+metadata->display_primaries[i][0].den = chroma_den;
+metadata->display_primaries[i][1].num = 
sei->mastering_display.display_primaries[j][1];
+metadata->display_primaries[i][1].den = chroma_den;
+}
+metadata->white_point[0].num = 
sei->mastering_display.white_point[0];
+metadata->white_point[0].den = chroma_den;
+metadata->white_point[1].num = 
sei->mastering_display.white_point[1];
+metadata->white_point[1].den = chroma_den;
+
+metadata->max_luminance.num = sei->mastering_display.max_luminance;
+metadata->max_luminance.den = luma_den;
+metadata->min_luminance.num = sei->mastering_display.min_luminance;
+metadata->min_luminance.den = luma_den;
+metadata->has_luminance = 1;
+metadata->has_primaries = 1;
+
+av_log(avctx, AV_LOG_DEBUG, "Mastering Display Metadata:\n");
+av_log(avctx, AV_LOG_DEBUG,
+   "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, 
%5.4f)\n",
+   av_q2d(metadata->display_primaries[0][0]),
+   av_q2d(metadata->display_primaries[0][1]),
+   av_q2d(metadata->display_primaries[1][0]),
+   av_q2d(metadata->display_primaries[1][1]),
+   av_q2d(metadata->display_primaries[2][0]),
+   av_q2d(metadata->display_primaries[2][1]),
+   av_q2d(metadata->white_point[0]), 

[FFmpeg-devel] [PATCH 4/5] avcodec/decode: make the AVFrameSideData helper wrappers not depend on frames

2024-03-22 Thread James Almer
They can be useful to fill arrays stored in other structs.

Signed-off-by: James Almer 
---
 libavcodec/av1dec.c |  7 +--
 libavcodec/cri.c|  3 +-
 libavcodec/decode.c | 98 ++---
 libavcodec/decode.h | 28 ++--
 libavcodec/dpx.c|  3 +-
 libavcodec/h2645_sei.c  |  4 +-
 libavcodec/h264_slice.c |  3 +-
 libavcodec/hevcdec.c|  6 ++-
 libavcodec/libdav1d.c   |  7 +--
 libavcodec/libjxldec.c  |  3 +-
 libavcodec/mjpegdec.c   |  3 +-
 libavcodec/mpeg12dec.c  | 11 +++--
 libavcodec/pngdec.c |  8 ++--
 libavcodec/qsvdec.c |  4 +-
 libavcodec/tiff.c   |  3 +-
 libavcodec/webp.c   |  3 +-
 16 files changed, 118 insertions(+), 76 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 4d074c3908..d130244f13 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -964,7 +964,8 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame 
*frame,
 if (!ret)
 break;
 
-ret = ff_frame_new_side_data_from_buf(avctx, frame, 
AV_FRAME_DATA_A53_CC, , NULL);
+ret = ff_frame_new_side_data_from_buf(avctx, >side_data, 
>nb_side_data,
+  AV_FRAME_DATA_A53_CC, );
 if (ret < 0)
 return ret;
 
@@ -1028,7 +1029,7 @@ static int export_metadata(AVCodecContext *avctx, AVFrame 
*frame)
 if (s->mdcv) {
 AVMasteringDisplayMetadata *mastering;
 
-ret = ff_decode_mastering_display_new(avctx, frame, );
+ret = ff_decode_mastering_display_new(avctx, >side_data, 
>nb_side_data, );
 if (ret < 0)
 return ret;
 
@@ -1051,7 +1052,7 @@ static int export_metadata(AVCodecContext *avctx, AVFrame 
*frame)
 if (s->cll) {
 AVContentLightMetadata *light;
 
-ret = ff_decode_content_light_new(avctx, frame, );
+ret = ff_decode_content_light_new(avctx, >side_data, 
>nb_side_data, );
 if (ret < 0)
 return ret;
 
diff --git a/libavcodec/cri.c b/libavcodec/cri.c
index 990e52ac99..94468e7515 100644
--- a/libavcodec/cri.c
+++ b/libavcodec/cri.c
@@ -398,7 +398,8 @@ skip:
 }
 
 if (hflip || vflip) {
-ff_frame_new_side_data(avctx, p, AV_FRAME_DATA_DISPLAYMATRIX,
+ff_frame_new_side_data(avctx, >side_data, >nb_side_data,
+   AV_FRAME_DATA_DISPLAYMATRIX,
sizeof(int32_t) * 9, );
 if (rotation) {
 av_display_rotation_set((int32_t *)rotation->data, 0.f);
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 34bcb7cc64..e6b32fcb26 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1799,87 +1799,115 @@ int ff_decode_preinit(AVCodecContext *avctx)
  * @retval 0 side data of this type can be added to frame
  * @retval 1 side data of this type should not be added to frame
  */
-static int side_data_pref(const AVCodecContext *avctx, AVFrame *frame,
-  enum AVFrameSideDataType type)
+static int side_data_pref(const AVCodecContext *avctx, AVFrameSideData ***sd,
+  int *nb_sd, enum AVFrameSideDataType type)
 {
 DecodeContext *dc = decode_ctx(avctx->internal);
 
 // Note: could be skipped for `type` without corresponding packet sd
-if (av_frame_get_side_data(frame, type)) {
+if (av_frame_side_data_get(*sd, *nb_sd, type)) {
 if (dc->side_data_pref_mask & (1ULL << type))
 return 1;
-av_frame_remove_side_data(frame, type);
+av_frame_side_data_remove(sd, nb_sd, type);
 }
 
 return 0;
 }
 
-
-int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrame *frame,
-   enum AVFrameSideDataType type, size_t size,
+int ff_frame_new_side_data(const AVCodecContext *avctx, AVFrameSideData ***sd,
+   int *nb_sd, enum AVFrameSideDataType type, size_t 
size,
AVFrameSideData **psd)
 {
-AVFrameSideData *sd;
-
-if (side_data_pref(avctx, frame, type)) {
+if (side_data_pref(avctx, sd, nb_sd, type)) {
 if (psd)
 *psd = NULL;
 return 0;
 }
 
-sd = av_frame_new_side_data(frame, type, size);
-if (psd)
-*psd = sd;
+*psd = av_frame_side_data_new(sd, nb_sd, type, size, 
AV_FRAME_SIDE_DATA_FLAG_UNIQUE);
 
-return sd ? 0 : AVERROR(ENOMEM);
+return *psd ? 0 : AVERROR(ENOMEM);
 }
 
-int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx,
-AVFrame *frame, enum AVFrameSideDataType 
type,
-AVBufferRef **buf, AVFrameSideData **psd)
+int ff_frame_new_side_data_from_buf(const AVCodecContext *avctx, 
AVFrameSideData ***sd,
+int *nb_sd, enum AVFrameSideDataType type,
+AVBufferRef **buf)
 {
-AVFrameSideData *sd = NULL;
 int ret = 0;
 
-if 

[FFmpeg-devel] [PATCH 3/5] avutil/mastering_display_metadata: add a new allocator function that returns a size

2024-03-22 Thread James Almer
av_mastering_display_metadata_alloc() is not useful in scenarios where you need 
to
know the runtime size of AVMasteringDisplayMetadata.

Signed-off-by: James Almer 
---
Could also name it av_mastering_display_metadata_alloc2()

 libavutil/mastering_display_metadata.c | 13 +
 libavutil/mastering_display_metadata.h |  9 +
 2 files changed, 22 insertions(+)

diff --git a/libavutil/mastering_display_metadata.c 
b/libavutil/mastering_display_metadata.c
index 6069347617..ea41f13f9d 100644
--- a/libavutil/mastering_display_metadata.c
+++ b/libavutil/mastering_display_metadata.c
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include 
 #include 
 #include 
 
@@ -29,6 +30,18 @@ AVMasteringDisplayMetadata 
*av_mastering_display_metadata_alloc(void)
 return av_mallocz(sizeof(AVMasteringDisplayMetadata));
 }
 
+AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t 
*size)
+{
+AVMasteringDisplayMetadata *mastering = 
av_mallocz(sizeof(AVMasteringDisplayMetadata));
+if (!mastering)
+return NULL;
+
+if (size)
+*size = sizeof(*mastering);
+
+return mastering;
+}
+
 AVMasteringDisplayMetadata 
*av_mastering_display_metadata_create_side_data(AVFrame *frame)
 {
 AVFrameSideData *side_data = av_frame_new_side_data(frame,
diff --git a/libavutil/mastering_display_metadata.h 
b/libavutil/mastering_display_metadata.h
index c23b07c3cd..52fcef9e37 100644
--- a/libavutil/mastering_display_metadata.h
+++ b/libavutil/mastering_display_metadata.h
@@ -77,6 +77,15 @@ typedef struct AVMasteringDisplayMetadata {
  */
 AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc(void);
 
+/**
+ * Allocate an AVMasteringDisplayMetadata structure and set its fields to
+ * default values. The resulting struct can be freed using av_freep().
+ *
+ * @return An AVMasteringDisplayMetadata filled with default values or NULL
+ * on failure.
+ */
+AVMasteringDisplayMetadata *av_mastering_display_metadata_alloc_size(size_t 
*size);
+
 /**
  * Allocate a complete AVMasteringDisplayMetadata and add it to the frame.
  *
-- 
2.44.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/5] avutil/frame: add helper to remove side data of a given type from an array

2024-03-22 Thread James Almer
Signed-off-by: James Almer 
---
 libavutil/frame.c | 6 ++
 libavutil/frame.h | 5 +
 2 files changed, 11 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 0717d89711..3e225ce5a4 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -847,6 +847,12 @@ const AVFrameSideData *av_frame_side_data_get_c(const 
AVFrameSideData * const *s
 return NULL;
 }
 
+void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
+   enum AVFrameSideDataType type)
+{
+remove_side_data(sd, nb_sd, type);
+}
+
 AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
 enum AVFrameSideDataType type)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index e3733ce928..671f75698c 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1093,6 +1093,11 @@ const AVFrameSideData 
*av_frame_side_data_get(AVFrameSideData * const *sd,
 nb_sd, type);
 }
 
+/**
+ * Remove and free all side data instances of the given type from an array.
+ */
+void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd,
+   enum AVFrameSideDataType type);
 /**
  * @}
  */
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 1/5] avutil/frame: add helper for adding side data w/ AVBufferRef to array

2024-03-22 Thread James Almer
Signed-off-by: James Almer 
---
Now taking ownership of the passed in buffer, as Anton suggested.

 libavutil/frame.c | 22 ++
 libavutil/frame.h | 23 +++
 2 files changed, 45 insertions(+)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index d7a32cdc92..0717d89711 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -782,6 +782,28 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 return ret;
 }
 
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **buf,
+unsigned int flags)
+{
+AVFrameSideData *sd_dst  = NULL;
+
+if (!sd || !buf || !nb_sd || (*nb_sd && !*sd))
+return NULL;
+
+if (flags & AV_FRAME_SIDE_DATA_FLAG_UNIQUE)
+remove_side_data(sd, nb_sd, type);
+
+sd_dst = add_side_data_from_buf(sd, nb_sd, type, *buf);
+if (!sd_dst)
+return NULL;
+
+*buf = NULL;
+
+return sd_dst;
+}
+
 int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd,
  const AVFrameSideData *src, unsigned int flags)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index 373866c600..e3733ce928 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1021,6 +1021,29 @@ AVFrameSideData *av_frame_side_data_new(AVFrameSideData 
***sd, int *nb_sd,
 enum AVFrameSideDataType type,
 size_t size, unsigned int flags);
 
+/**
+ * Add a new side data entry to an array from an existing AVBufferRef.
+ *
+ * @param sdpointer to array of side data to which to add another entry,
+ *  or to NULL in order to start a new array.
+ * @param nb_sd pointer to an integer containing the number of entries in
+ *  the array.
+ * @param type  type of the added side data
+ * @param buf   Pointer to AVBufferRef to add to the array. On success,
+ *  the ownership of the AVBufferRef is transferred to the frame
+ *  and *buf is set to NULL.
+ * @param flags Some combination of AV_FRAME_SIDE_DATA_FLAG_* flags, or 0.
+ *
+ * @return newly added side data on success, NULL on error. In case of
+ * AV_FRAME_SIDE_DATA_FLAG_UNIQUE being set, entries of matching
+ * AVFrameSideDataType will be removed before the addition is
+ * attempted.
+ */
+AVFrameSideData *av_frame_side_data_add(AVFrameSideData ***sd, int *nb_sd,
+enum AVFrameSideDataType type,
+AVBufferRef **buf,
+unsigned int flags);
+
 /**
  * Add a new side data entry to an array based on existing side data, taking
  * a reference towards the contained AVBufferRef.
-- 
2.44.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 3/3] avformat/aiffdec: Check for previously set channels

2024-03-22 Thread Michael Niedermayer
Fixes: out of array access (av_channel_layout_copy())
Fixes: 
67087/clusterfuzz-testcase-minimized-ffmpeg_dem_AIFF_fuzzer-4920720268263424

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, 2 insertions(+)

diff --git a/libavformat/aiffdec.c b/libavformat/aiffdec.c
index 9318943f96..fc01ffcbf1 100644
--- a/libavformat/aiffdec.c
+++ b/libavformat/aiffdec.c
@@ -106,6 +106,8 @@ static int get_aiff_header(AVFormatContext *s, int64_t size,
 size++;
 par->codec_type = AVMEDIA_TYPE_AUDIO;
 channels = avio_rb16(pb);
+if (par->ch_layout.nb_channels && par->ch_layout.nb_channels != channels)
+return AVERROR_INVALIDDATA;
 par->ch_layout.nb_channels = channels;
 num_frames = avio_rb32(pb);
 par->bits_per_coded_sample = avio_rb16(pb);
-- 
2.17.1

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

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


[FFmpeg-devel] [PATCH 2/3] avformat/mov: Do not deallocate heif_item in a input dependant way

2024-03-22 Thread Michael Niedermayer
Fixes: out of array access
Fixes: 
67070/clusterfuzz-testcase-minimized-ffmpeg_IO_DEMUXER_fuzzer-5685384082161664

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

diff --git a/libavformat/mov.c b/libavformat/mov.c
index f954b924a0..a87ce5cefe 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -8077,7 +8077,7 @@ static int mov_read_iloc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 }
 item_count = (version < 2) ? avio_rb16(pb) : avio_rb32(pb);
 
-heif_item = av_realloc_array(c->heif_item, item_count, 
sizeof(*c->heif_item));
+heif_item = av_realloc_array(c->heif_item, FFMAX(item_count, 
c->nb_heif_item), sizeof(*c->heif_item));
 if (!heif_item)
 return AVERROR(ENOMEM);
 c->heif_item = heif_item;
@@ -8202,7 +8202,7 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 avio_rb24(pb);  // flags.
 entry_count = version ? avio_rb32(pb) : avio_rb16(pb);
 
-heif_item = av_realloc_array(c->heif_item, entry_count, 
sizeof(*c->heif_item));
+heif_item = av_realloc_array(c->heif_item, FFMAX(entry_count, 
c->nb_heif_item), sizeof(*c->heif_item));
 if (!heif_item)
 return AVERROR(ENOMEM);
 c->heif_item = heif_item;
-- 
2.17.1

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

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


[FFmpeg-devel] [PATCH 1/3] avformat/cafdec: sanity check channels and bps

2024-03-22 Thread Michael Niedermayer
Fixes: Timeout
Fixes: 
67044/clusterfuzz-testcase-minimized-ffmpeg_dem_CAF_fuzzer-5791144363491328

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

diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c
index 426c56b9bd..334077efb5 100644
--- a/libavformat/cafdec.c
+++ b/libavformat/cafdec.c
@@ -33,6 +33,7 @@
 #include "isom.h"
 #include "mov_chan.h"
 #include "libavcodec/flac.h"
+#include "libavcodec/internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/intfloat.h"
 #include "libavutil/dict.h"
@@ -87,6 +88,10 @@ static int read_desc_chunk(AVFormatContext *s)
 st->codecpar->ch_layout.nb_channels = avio_rb32(pb);
 st->codecpar->bits_per_coded_sample = avio_rb32(pb);
 
+if (st->codecpar->ch_layout.nb_channels > FF_SANE_NB_CHANNELS ||
+st->codecpar->bits_per_coded_sample > 64)
+return AVERROR_INVALIDDATA;
+
 if (caf->bytes_per_packet < 0 || caf->frames_per_packet < 0 || 
st->codecpar->ch_layout.nb_channels < 0)
 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".


Re: [FFmpeg-devel] [PATCH] tests: Remove fate-libx265-hdr10

2024-03-22 Thread Jan Ekström
On Fri, Mar 22, 2024 at 10:18 PM Anton Khirnov  wrote:
>
> Quoting Zhao Zhili (2024-03-22 13:43:43)
> > From: Zhao Zhili 
> >
> > The test depends on the compile option of x265. It failed when
> > HIGH_BIT_DEPTH isn't enabled. It also failed when asan is enabled
> > because of memory issue inside of x265, which I don't think can
> > be fixed within FFmpeg.
>
> I suggested some time ago we should mark x265 as experimental. It didn't
> receive much enthusiasm, and some probably considered it a joke, but I
> was mostly serious. It has major memory safety issues that have been
> ignored for years.
>

Yea, I recall when I was testing my patch set with valgrind about half
a year ago, some of the memory issues showed up there as well. The
problem being that most users are happily oblivious to these issues as
long as the piece of software "seems to work". Which is a line that
x265 does cross.

Thus at least on my side the reason for not much enthusiasm for
marking it experimental at this point came from it being on the output
side (and thus not handling random input/being a parser) as well as it
most likely receiving much less understanding from users than just
complaints about command lines which had worked for ages suddenly
breaking.

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 5/5] avutil/frame: Use av_realloc_array(), improve overflow check

2024-03-22 Thread Jan Ekström
On Fri, Mar 22, 2024 at 4:41 PM Andreas Rheinhardt
 wrote:
>
> Also use sizeof of the proper type, namely sizeof(**sd)
> and not sizeof(*sd).
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavutil/frame.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index 7dd37e5490..d7a32cdc92 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -721,10 +721,11 @@ static AVFrameSideData 
> *add_side_data_from_buf(AVFrameSideData ***sd,
>  if (!buf)
>  return NULL;
>
> -if (*nb_sd > INT_MAX / sizeof(*sd) - 1)
> +// *nb_sd + 1 needs to fit into an int and a size_t.
> +if ((unsigned)*nb_sd >= FFMIN(INT_MAX, SIZE_MAX))
>  return NULL;
>
> -tmp = av_realloc(*sd, (*nb_sd + 1) * sizeof(*sd));
> +tmp = av_realloc_array(*sd, sizeof(**sd), *nb_sd + 1);
>  if (!tmp)
>  return NULL;
>  *sd = tmp;
> --

Thanks for noticing these things like the AVClass-usage, figuring out
a workaround for the getter and improving on the overflow check as
well as doing the AVBPrint to snprintf switch.

Will have to think why I thought that AVClass thing was somehow a good idea.

Set LGTM.

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] avutil/timestamp: keep microsecond precision in av_ts_make_time_string

2024-03-22 Thread Andreas Rheinhardt
Marton Balint:
> 
> 
> On Wed, 20 Mar 2024, Andreas Rheinhardt wrote:
> 
>> Andreas Rheinhardt:
>>> Marton Balint:
 av_ts_make_time_string() used "%.6g" format in the past, but this
 format was
 losing precision even when the timestamp to be printed was not that
 large. For
 example for 3 hours (10800) seconds, only 1 decimal digit was
 printed, which
 made this format inaccurate when it was used in e.g. the
 silencedetect filter.
 Other detection filters printing timestamps had similar issues.

 So let's change the used format to "%.6f" instead, we have plenty of
 space in
 the string buffer, we can somewhat imitate existing behaviour of %g
 by trimming
 ending zeroes and the potential decimal point, which can be any
 non-numeric
 character. In order not to trim "inf" as well, we assume that the
 decimal
 point does not contain the letter "f".

 We also no longer use scientific representation to make parsing and
 printing
 easier, because the theoretical maximum of INT64_MAX*INT32_MAX still
 fits into
 the string buffer in normal form.

 Since the additional processing yields more code, inlineing this
 function no
 longer make sense, so this commit also changes the API to actually
 export the
 function instead of having it inlinable in the header.

 Thanks for Allan Cady for bringing up this issue.

 Signed-off-by: Marton Balint 
 ---
  doc/APIchanges   |  3 ++
  libavutil/Makefile   |  1 +
  libavutil/timestamp.c    | 33 
  libavutil/timestamp.h    |  8 +
  libavutil/version.h  |  2 +-
  tests/ref/fate/filter-metadata-scdet | 12 +++
  tests/ref/fate/filter-metadata-silencedetect |  2 +-
  7 files changed, 46 insertions(+), 15 deletions(-)
  create mode 100644 libavutil/timestamp.c

 diff --git a/doc/APIchanges b/doc/APIchanges
 index a44c8e4f10..1afde062a5 100644
 --- a/doc/APIchanges
 +++ b/doc/APIchanges
 @@ -2,6 +2,9 @@ The last version increases of all libraries were on
 2024-03-07

  API changes, most recent first:

 +2024-03-xx - xx - lavu 59.3.100 - timestamp.h
 +  av_ts_make_time_string() is no longer an inline function. It is
 now exported.
 +
  2024-03-xx - xx - lavu 59.2.100 - channel_layout.h
    Add AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL.

 diff --git a/libavutil/Makefile b/libavutil/Makefile
 index e7709b97d0..5e75aa1855 100644
 --- a/libavutil/Makefile
 +++ b/libavutil/Makefile
 @@ -174,6 +174,7 @@ OBJS =
 adler32.o    \
    
 threadmessage.o  \
    
 time.o   \
    
 timecode.o   \
 +  
 timestamp.o  \
    
 tree.o   \
    
 twofish.o    \
    
 utils.o  \
 diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c
 new file mode 100644
 index 00..06fb47e94c
 --- /dev/null
 +++ b/libavutil/timestamp.c
 @@ -0,0 +1,33 @@
 +/*
 + * 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 "timestamp.h"
 +
 +char *av_ts_make_time_string(char *buf, int64_t ts, const
 AVRational *tb)
 +{
 +    if (ts == AV_NOPTS_VALUE) {
 +    snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
 +    } else {
 +    int last = snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6f",
 av_q2d(*tb) * ts);
 +    last = FFMIN(last, AV_TS_MAX_STRING_SIZE - 1) - 1;
 +    for (; last && buf[last] == '0'; 

[FFmpeg-devel] [PATCH v3] configure: Explicitly check for static_assert, _Static_assert

2024-03-22 Thread Andreas Rheinhardt
C11 provides static assertions via _Static_assert and
provides static_assert as a convenience define for this
in assert.h. Our codebase uses the latter, as _Static_assert
has actually already been deprecated in C23.

Not all toolchains that declare support for C11 actually
support it; e.g. MSVC 19.27 does not support _Static_assert,
but somehow supports static_assert. MSVC 19.27 admits to be
a "preview implementation of the ISO C11 standard",
so this is not surprising (MSVC 19.28 does not come with
this caveat).

Furthermore some FATE boxes [1] use old GCC toolchains (with
only experimental support for C11) where _Static_assert is
supported, but assert.h does not provide the fallback define.
They are broken since the first usage of static_assert.

This commit therefore checks whether static_assert and
_Static_assert work with assert.h included; if not,
configure errors out.

This intentionally drops support for MSVC 19.27. Users like
the old FATE boxes above can still add -Dstatic_assert=_Static_assert
to cflags as a workaround if desired.

[1]: 
https://fate.ffmpeg.org/report.cgi?time=20240321123620=sh4-debian-qemu-gcc-4.7

Signed-off-by: Andreas Rheinhardt 
---
 configure | 13 +
 1 file changed, 13 insertions(+)

diff --git a/configure b/configure
index 343edb38ab..fc366549bc 100755
--- a/configure
+++ b/configure
@@ -5589,6 +5589,19 @@ check_cxxflags_cc -std=$stdcxx ctype.h "__cplusplus >= 
201103L" ||
 check_cflags_cc -std=$stdc ctype.h "__STDC_VERSION__ >= 201112L" ||
 { check_cflags_cc -std=c11 ctype.h "__STDC_VERSION__ >= 201112L" && 
stdc="c11" || die "Compiler lacks C11 support"; }
 
+test_cc <
+#include 
+struct Foo {
+int a;
+void *ptr;
+} obj;
+static_assert(offsetof(struct Foo, a) == 0,
+  "First element of struct does not have offset 0");
+_Static_assert(offsetof(struct Foo, ptr) >= offsetof(struct Foo, a) + 
sizeof(obj.a),
+   "elements not properly ordered in struct");
+EOF
+
 check_cppflags -D_FILE_OFFSET_BITS=64
 check_cppflags -D_LARGEFILE_SOURCE
 
-- 
2.40.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] avutil/timestamp: keep microsecond precision in av_ts_make_time_string

2024-03-22 Thread Marton Balint



On Wed, 20 Mar 2024, Marton Balint wrote:




On Wed, 20 Mar 2024, Andreas Rheinhardt wrote:


 Andreas Rheinhardt:

 Marton Balint:

 av_ts_make_time_string() used "%.6g" format in the past, but this format
 was
 losing precision even when the timestamp to be printed was not that
 large. For
 example for 3 hours (10800) seconds, only 1 decimal digit was printed,
 which
 made this format inaccurate when it was used in e.g. the silencedetect
 filter.
 Other detection filters printing timestamps had similar issues.

 So let's change the used format to "%.6f" instead, we have plenty of
 space in
 the string buffer, we can somewhat imitate existing behaviour of %g by
 trimming
 ending zeroes and the potential decimal point, which can be any
 non-numeric
 character. In order not to trim "inf" as well, we assume that the
 decimal
 point does not contain the letter "f".

 We also no longer use scientific representation to make parsing and
 printing
 easier, because the theoretical maximum of INT64_MAX*INT32_MAX still
 fits into
 the string buffer in normal form.

 Since the additional processing yields more code, inlineing this
 function no
 longer make sense, so this commit also changes the API to actually
 export the
 function instead of having it inlinable in the header.

 Thanks for Allan Cady for bringing up this issue.

 Signed-off-by: Marton Balint 
 ---
  doc/APIchanges   |  3 ++
  libavutil/Makefile   |  1 +
  libavutil/timestamp.c| 33 
  libavutil/timestamp.h|  8 +
  libavutil/version.h  |  2 +-
  tests/ref/fate/filter-metadata-scdet | 12 +++
  tests/ref/fate/filter-metadata-silencedetect |  2 +-
  7 files changed, 46 insertions(+), 15 deletions(-)
  create mode 100644 libavutil/timestamp.c

 diff --git a/doc/APIchanges b/doc/APIchanges
 index a44c8e4f10..1afde062a5 100644
 --- a/doc/APIchanges
 +++ b/doc/APIchanges
@@  -2,6 +2,9 @@ The last version increases of all libraries were on 
@@  2024-03-07


  API changes, most recent first:

 +2024-03-xx - xx - lavu 59.3.100 - timestamp.h
 +  av_ts_make_time_string() is no longer an inline function. It is now
 exported.
 +
  2024-03-xx - xx - lavu 59.2.100 - channel_layout.h
Add AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL.

 diff --git a/libavutil/Makefile b/libavutil/Makefile
 index e7709b97d0..5e75aa1855 100644
 --- a/libavutil/Makefile
 +++ b/libavutil/Makefile
@@  -174,6 +174,7 @@ OBJS = adler32.o 
@@  \

 threadmessage.o
 \
 time.o
 \
 timecode.o
 \
 +   timestamp.o
 \
 tree.o
 \
 twofish.o
 \
 utils.o
 \
 diff --git a/libavutil/timestamp.c b/libavutil/timestamp.c
 new file mode 100644
 index 00..06fb47e94c
 --- /dev/null
 +++ b/libavutil/timestamp.c
@@  -0,0 +1,33 @@
 +/*
 + * 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 "timestamp.h"
 +
 +char *av_ts_make_time_string(char *buf, int64_t ts, const AVRational
 *tb)
 +{
 +if (ts == AV_NOPTS_VALUE) {
 +snprintf(buf, AV_TS_MAX_STRING_SIZE, "NOPTS");
 +} else {
 +int last = snprintf(buf, AV_TS_MAX_STRING_SIZE, "%.6f",
 av_q2d(*tb) * ts);
 +last = FFMIN(last, AV_TS_MAX_STRING_SIZE - 1) - 1;
 +for (; last && buf[last] == '0'; last--);
 +for (; last && buf[last] != 'f' && (buf[last] < '0' || buf[0] >
 '9'); last--);
 +buf[last + 1] = '\0';
 +}
 +return buf;
 +}


 As has already been said before: Simply using %.6f will discard
 significant digits for small timestamps. E.g. 10^-7 will simply print
 0.00, which will then be converted to "0" by your code. The old code
 printed 1.


Admittedly we will lose precision < 10^-6 by using %.6f, but I don't think 
this will cause any real problems, so I'd rather just leave this as is. Or 
you prefer some special handling of small values? E.g. using %.9f or 
something?




 Furthermore, there are more problems:
 "A double argument representing an infinity is converted in one of the
 styles [-]inf or [-]infinity — which style is implementation-defined."
 Your code would trim infinity 

Re: [FFmpeg-devel] [FFmpeg-cvslog] ffmpeg: pass first video AVFrame's side data to encoder

2024-03-22 Thread Anton Khirnov
Quoting James Almer (2024-03-22 20:38:38)
> On 3/22/2024 6:52 AM, Anton Khirnov wrote:
> > I objected to this indiscriminate copying in a previous review.
> > 
> > There is no reason to expect side data to apply to the whole stream just
> > because it happens to apply to the first frame. For many side data types
> > it does not even make sense, as they are fundamentally per-frame.
> 
> So this would need to be handled by having decoders export global side 
> data in decoded_side_data directly, so there's no need to take them from 
> frames here (which would include per frame side data, like hdr10 and 
> closed captions), right?

That's not enough, you still need to propagate this data through the
filtergraph.

I'm leaning towards something like a side data descriptor, that would
tell callers (among other things) whether a side data type is meaningful
in global headers.

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

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


[FFmpeg-devel] [PATCH] avfilter: propagate colorspace and color_range from buffer filter and between AVFilterLink.

2024-03-22 Thread Damiano Galassi
There two new fields were never sent down the filter chain, and no filter after 
the first had colorspace and color_range set, causing breakage in zscale and 
possible other filters.
---
 libavfilter/avfilter.c  | 4 
 libavfilter/buffersrc.c | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 831871de90..153fb700d3 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -391,6 +391,10 @@ int ff_filter_config_links(AVFilterContext *filter)
 link->w = inlink->w;
 if (!link->h)
 link->h = inlink->h;
+if (link->colorspace == AVCOL_SPC_UNSPECIFIED)
+link->colorspace = inlink->color_range;
+if (link->color_range == AVCOL_RANGE_UNSPECIFIED)
+link->color_range = inlink->color_range;
 } else if (!link->w || !link->h) {
 av_log(link->src, AV_LOG_ERROR,
"Video source filters must set their output link's "
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index ddcd403785..2760097edf 100644
--- a/libavfilter/buffersrc.c
+++ b/libavfilter/buffersrc.c
@@ -499,6 +499,8 @@ static int config_props(AVFilterLink *link)
 link->w = c->w;
 link->h = c->h;
 link->sample_aspect_ratio = c->pixel_aspect;
+link->colorspace = c->color_space;
+link->color_range = c->color_range;
 
 if (c->hw_frames_ctx) {
 link->hw_frames_ctx = av_buffer_ref(c->hw_frames_ctx);
-- 
2.39.3 (Apple Git-146)

___
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] [RFC] Channels

2024-03-22 Thread Michael Niedermayer
On Thu, Mar 21, 2024 at 11:59:17PM -0300, James Almer wrote:
> On 3/21/2024 11:25 PM, Michael Niedermayer wrote:
> > Hi all
> > 
> > we have code like
> > st->codecpar->ch_layout.nb_channels = avio_rb32(pb);
> > 
> > and then somewhere there is some code that uses this by first allocating
> > an array and that then hits OOM
> > (it was this here:
> >  map = av_calloc(nb_channels, sizeof(*channel_layout->u.map));)
> > 
> > is anyone against adding a max_channels field to AVFormatContext  or 
> > something
> > like that ?
> > 
> > alternative is "wont fix" for all such cases, or maybe someone sees another 
> > way ?
> > 
> > thx
> 
> We have FF_SANE_NB_CHANNELS, so maybe add a check for it to mxfdec.c (Where
> i assume this is happening) and mov_chan.c or mov.c before continuing with
> such a layout.

wasnt mxf, ill send a patch

thanks!

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

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire


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 08/12] lavc/frame_thread_encoder: avoid assigning a whole AVCodecContext

2024-03-22 Thread Andreas Rheinhardt
Anton Khirnov:
> It is highly unsafe, as AVCodecContext contains many allocated fields.
> Copying information via AVCodecParameters and with av_opt_copy() should
> handle everything needed by thread workers.
> ---
>  libavcodec/frame_thread_encoder.c | 26 --
>  1 file changed, 20 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/frame_thread_encoder.c 
> b/libavcodec/frame_thread_encoder.c
> index cda5158117..744062b776 100644
> --- a/libavcodec/frame_thread_encoder.c
> +++ b/libavcodec/frame_thread_encoder.c
> @@ -28,6 +28,7 @@
>  #include "libavutil/thread.h"
>  #include "avcodec.h"
>  #include "avcodec_internal.h"
> +#include "codec_par.h"
>  #include "encode.h"
>  #include "internal.h"
>  #include "pthread_internal.h"
> @@ -121,6 +122,7 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
> *avctx)
>  int i=0;
>  ThreadContext *c;
>  AVCodecContext *thread_avctx = NULL;
> +AVCodecParameters *par = NULL;
>  int ret;
>  
>  if(   !(avctx->thread_type & FF_THREAD_FRAME)
> @@ -194,18 +196,27 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
> *avctx)
>  }
>  }
>  
> +par = avcodec_parameters_alloc();
> +if (!par) {
> +ret = AVERROR(ENOMEM);
> +goto fail;
> +}
> +
> +ret = avcodec_parameters_from_context(par, avctx);
> +if (ret < 0)
> +goto fail;
> +
>  for(i=0; ithread_count ; i++){
> -void *tmpv;
>  thread_avctx = avcodec_alloc_context3(avctx->codec);
>  if (!thread_avctx) {
>  ret = AVERROR(ENOMEM);
>  goto fail;
>  }
> -tmpv = thread_avctx->priv_data;
> -*thread_avctx = *avctx;
> -thread_avctx->priv_data = tmpv;
> -thread_avctx->internal = NULL;
> -thread_avctx->hw_frames_ctx = NULL;
> +
> +ret = avcodec_parameters_to_context(thread_avctx, par);
> +if (ret < 0)
> +goto fail;
> +
>  ret = av_opt_copy(thread_avctx, avctx);
>  if (ret < 0)
>  goto fail;
> @@ -227,10 +238,13 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
> *avctx)
>  }
>  }
>  
> +avcodec_parameters_free();
> +
>  avctx->active_thread_type = FF_THREAD_FRAME;
>  
>  return 0;
>  fail:
> +avcodec_parameters_free();
>  ff_codec_close(thread_avctx);
>  av_freep(_avctx);
>  avctx->thread_count = i;

IIRC the mjpeg encoders use intra_matrix and this will now no longer be
copied to the worker threads.

- 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 09/12] lavc/decode: move sd_global_map to avcodec

2024-03-22 Thread Anton Khirnov
It will be shared with encoding code.
---
 libavcodec/avcodec.c  | 14 ++
 libavcodec/avcodec_internal.h | 16 +++-
 libavcodec/decode.c   | 33 +
 3 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index a9a87bb58c..525fe516bd 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -54,6 +54,20 @@
  */
 #define FF_MAX_EXTRADATA_SIZE ((1 << 28) - AV_INPUT_BUFFER_PADDING_SIZE)
 
+const SideDataMap ff_sd_global_map[] = {
+{ AV_PKT_DATA_REPLAYGAIN ,AV_FRAME_DATA_REPLAYGAIN },
+{ AV_PKT_DATA_DISPLAYMATRIX,  AV_FRAME_DATA_DISPLAYMATRIX },
+{ AV_PKT_DATA_SPHERICAL,  AV_FRAME_DATA_SPHERICAL },
+{ AV_PKT_DATA_STEREO3D,   AV_FRAME_DATA_STEREO3D },
+{ AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE 
},
+{ AV_PKT_DATA_MASTERING_DISPLAY_METADATA, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
+{ AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
+{ AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
+{ 
AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
 },
+{ AV_PKT_DATA_NB },
+};
+
+
 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, 
void *arg2), void *arg, int *ret, int count, int size)
 {
 size_t i;
diff --git a/libavcodec/avcodec_internal.h b/libavcodec/avcodec_internal.h
index 4d1cb3a314..0a024378ae 100644
--- a/libavcodec/avcodec_internal.h
+++ b/libavcodec/avcodec_internal.h
@@ -25,8 +25,22 @@
 #ifndef AVCODEC_AVCODEC_INTERNAL_H
 #define AVCODEC_AVCODEC_INTERNAL_H
 
+#include "libavutil/frame.h"
+
+#include "packet.h"
+
 struct AVCodecContext;
-struct AVFrame;
+
+typedef struct SideDataMap {
+enum AVPacketSideDataType packet;
+enum AVFrameSideDataType frame;
+} SideDataMap;
+
+/**
+ * A map between packet and frame side data types.
+ * Terminated with an entry where packet=AV_PKT_DATA_NB.
+ */
+extern const SideDataMap ff_sd_global_map[];
 
 /**
  * avcodec_receive_frame() implementation for decoders.
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 34bcb7cc64..ddb73b6934 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1376,21 +1376,6 @@ static int add_metadata_from_side_data(const AVPacket 
*avpkt, AVFrame *frame)
 return av_packet_unpack_dictionary(side_metadata, size, frame_md);
 }
 
-static const struct {
-enum AVPacketSideDataType packet;
-enum AVFrameSideDataType frame;
-} sd_global_map[] = {
-{ AV_PKT_DATA_REPLAYGAIN ,AV_FRAME_DATA_REPLAYGAIN },
-{ AV_PKT_DATA_DISPLAYMATRIX,  AV_FRAME_DATA_DISPLAYMATRIX },
-{ AV_PKT_DATA_SPHERICAL,  AV_FRAME_DATA_SPHERICAL },
-{ AV_PKT_DATA_STEREO3D,   AV_FRAME_DATA_STEREO3D },
-{ AV_PKT_DATA_AUDIO_SERVICE_TYPE, AV_FRAME_DATA_AUDIO_SERVICE_TYPE 
},
-{ AV_PKT_DATA_MASTERING_DISPLAY_METADATA, 
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA },
-{ AV_PKT_DATA_CONTENT_LIGHT_LEVEL,
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL },
-{ AV_PKT_DATA_ICC_PROFILE,AV_FRAME_DATA_ICC_PROFILE },
-{ 
AV_PKT_DATA_AMBIENT_VIEWING_ENVIRONMENT,AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
 },
-};
-
 int ff_decode_frame_props_from_pkt(const AVCodecContext *avctx,
AVFrame *frame, const AVPacket *pkt)
 {
@@ -1414,13 +1399,13 @@ FF_DISABLE_DEPRECATION_WARNINGS
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-for (int i = 0; i < FF_ARRAY_ELEMS(sd_global_map); i++) {
+for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {
 size_t size;
-const uint8_t *packet_sd = av_packet_get_side_data(pkt, 
sd_global_map[i].packet, );
+const uint8_t *packet_sd = av_packet_get_side_data(pkt, 
ff_sd_global_map[i].packet, );
 if (packet_sd) {
 AVFrameSideData *frame_sd;
 
-frame_sd = av_frame_new_side_data(frame, sd_global_map[i].frame, 
size);
+frame_sd = av_frame_new_side_data(frame, 
ff_sd_global_map[i].frame, size);
 if (!frame_sd)
 return AVERROR(ENOMEM);
 memcpy(frame_sd->data, packet_sd, size);
@@ -1461,12 +1446,12 @@ int ff_decode_frame_props(AVCodecContext *avctx, 
AVFrame *frame)
 {
 int ret;
 
-for (int i = 0; i < FF_ARRAY_ELEMS(sd_global_map); i++) {
+for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {
 const AVPacketSideData *packet_sd = ff_get_coded_side_data(avctx,
-   
sd_global_map[i].packet);
+   
ff_sd_global_map[i].packet);
 if (packet_sd) {
 AVFrameSideData *frame_sd = av_frame_new_side_data(frame,
- 

[FFmpeg-devel] [PATCH 01/12] tests/fate/ffmpeg: evaluate thread count in fate-run.sh rather than make

2024-03-22 Thread Anton Khirnov
Fixes fate-ffmpeg-loopback-decoding with THREADS=random*
---
 tests/fate/ffmpeg.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index 9cf05ead68..3c549b265e 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -259,5 +259,5 @@ FATE_FFMPEG-$(call REMUX, RAWVIDEO) += 
fate-ffmpeg-streamcopy-t
 fate-ffmpeg-loopback-decoding: tests/data/vsynth_lena.yuv
 fate-ffmpeg-loopback-decoding: CMD = transcode \
 "rawvideo -s 352x288 -pix_fmt yuv420p" 
$(TARGET_PATH)/tests/data/vsynth_lena.yuv nut \
-"-map 0:v:0 -c:v mpeg2video -f null - -flags +bitexact -idct simple 
-threads $(THREADS) -dec 0:0 -filter_complex '[0:v][dec:0]hstack[stack]' -map 
'[stack]' -c:v ffv1" ""
+"-map 0:v:0 -c:v mpeg2video -f null - -flags +bitexact -idct simple 
-threads $$threads -dec 0:0 -filter_complex '[0:v][dec:0]hstack[stack]' -map 
'[stack]' -c:v ffv1" ""
 FATE_FFMPEG-$(call ENCDEC2, MPEG2VIDEO, FFV1, NUT, HSTACK_FILTER PIPE_PROTOCOL 
FRAMECRC_MUXER) += fate-ffmpeg-loopback-decoding
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 06/12] fftools/ffmpeg_dec: apply cropping manually

2024-03-22 Thread Anton Khirnov
lavfi does not require aligned buffers, so we can safely apply top/left
cropping by any amount, without passing any special flags to lavc.
Longer term, an even better solution would probably be auto-inserting
the crop filter (or its hwaccel versions) as needed.

Multiple FATE tests no longer need -flags unaligned.
---
 fftools/ffmpeg_dec.c | 14 ++
 tests/fate/h264.mak  |  2 +-
 tests/fate/hevc.mak  |  8 
 tests/fate/vvc.mak   |  2 +-
 4 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index b8bfae469f..e3ed0b3978 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -51,6 +51,7 @@ typedef struct DecoderPriv {
 
 // a combination of DECODER_FLAG_*, provided to dec_open()
 int flags;
+int apply_cropping;
 
 enum AVPixelFormat  hwaccel_pix_fmt;
 enum HWAccelID  hwaccel_id;
@@ -404,6 +405,15 @@ static int video_frame_process(DecoderPriv *dp, AVFrame 
*frame)
 if (dp->sar_override.num)
 frame->sample_aspect_ratio = dp->sar_override;
 
+if (dp->apply_cropping) {
+// lavfi does not require aligned frame data
+int ret = av_frame_apply_cropping(frame, AV_FRAME_CROP_UNALIGNED);
+if (ret < 0) {
+av_log(dp, AV_LOG_ERROR, "Error applying decoder cropping\n");
+return ret;
+}
+}
+
 return 0;
 }
 
@@ -1214,6 +1224,10 @@ static int dec_open(DecoderPriv *dp, AVDictionary 
**dec_opts,
 if (o->flags & DECODER_FLAG_BITEXACT)
 dp->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
 
+// we apply cropping outselves
+dp->apply_cropping  = dp->dec_ctx->apply_cropping;
+dp->dec_ctx->apply_cropping = 0;
+
 if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
 av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
av_err2str(ret));
diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
index 674054560b..88f06d7b15 100644
--- a/tests/fate/h264.mak
+++ b/tests/fate/h264.mak
@@ -312,7 +312,7 @@ fate-h264-conformance-ci1_ft_b:   CMD = 
framecrc -i $(TARGET_SAM
 fate-h264-conformance-ci_mw_d:CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CI_MW_D.264
 fate-h264-conformance-cvbs3_sony_c:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVBS3_Sony_C.jsv
 fate-h264-conformance-cvcanlma2_sony_c:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVCANLMA2_Sony_C.jsv
-fate-h264-conformance-cvfc1_sony_c:   CMD = framecrc -flags 
unaligned -i $(TARGET_SAMPLES)/h264-conformance/CVFC1_Sony_C.jsv
+fate-h264-conformance-cvfc1_sony_c:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFC1_Sony_C.jsv
 fate-h264-conformance-cvfi1_sony_d:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFI1_Sony_D.jsv
 fate-h264-conformance-cvfi1_sva_c:CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFI1_SVA_C.264
 fate-h264-conformance-cvfi2_sony_h:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264-conformance/CVFI2_Sony_H.jsv
diff --git a/tests/fate/hevc.mak b/tests/fate/hevc.mak
index 4889ee8237..720603c112 100644
--- a/tests/fate/hevc.mak
+++ b/tests/fate/hevc.mak
@@ -200,8 +200,8 @@ $(HEVC_TESTS_444_8BIT): SCALE_OPTS := -pix_fmt yuv444p
 $(HEVC_TESTS_10BIT): SCALE_OPTS := -pix_fmt yuv420p10le -vf scale
 $(HEVC_TESTS_422_10BIT) $(HEVC_TESTS_422_10BIN): SCALE_OPTS := -pix_fmt 
yuv422p10le -vf scale
 $(HEVC_TESTS_444_12BIT): SCALE_OPTS := -pix_fmt yuv444p12le -vf scale
-fate-hevc-conformance-%: CMD = framecrc -flags unaligned -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bit 
$(SCALE_OPTS)
-$(HEVC_TESTS_422_10BIN): CMD = framecrc -flags unaligned -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bin 
$(SCALE_OPTS)
+fate-hevc-conformance-%: CMD = framecrc -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bit 
$(SCALE_OPTS)
+$(HEVC_TESTS_422_10BIN): CMD = framecrc -i 
$(TARGET_SAMPLES)/hevc-conformance/$(subst fate-hevc-conformance-,,$(@)).bin 
$(SCALE_OPTS)
 
 FATE_HEVC-$(call FRAMECRC, HEVC, HEVC, HEVC_PARSER) += $(HEVC_TESTS_8BIT) 
$(HEVC_TESTS_444_8BIT)
 FATE_HEVC-$(call FRAMECRC, HEVC, HEVC, HEVC_PARSER SCALE_FILTER) += \
@@ -252,10 +252,10 @@ FATE_HEVC_FFPROBE-$(call DEMDEC, MOV, HEVC) += 
fate-hevc-dv-rpu
 fate-hevc-two-first-slice: CMD = threads=2 framemd5 -i 
$(TARGET_SAMPLES)/hevc/two_first_slice.mp4 -sws_flags bitexact -t 00:02.00 -an
 FATE_HEVC-$(call FRAMEMD5, MOV, HEVC) += fate-hevc-two-first-slice
 
-fate-hevc-cabac-tudepth: CMD = framecrc -flags unaligned -i 
$(TARGET_SAMPLES)/hevc/cbf_cr_cb_TUDepth_4_circle.h265 -pix_fmt yuv444p
+fate-hevc-cabac-tudepth: CMD = framecrc -i 
$(TARGET_SAMPLES)/hevc/cbf_cr_cb_TUDepth_4_circle.h265 -pix_fmt yuv444p
 FATE_HEVC-$(call FRAMECRC, HEVC, HEVC) += fate-hevc-cabac-tudepth
 

[FFmpeg-devel] [PATCH 10/12] lavc/encode: map AVCodecContext.decoded_side_data to coded_side_data

2024-03-22 Thread Anton Khirnov
This way it can be automagically propagated through the encoder to
muxing.
---
 libavcodec/encode.c  | 23 +++
 tests/ref/fate/libx265-hdr10 | 24 
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 7fc9737e93..46e46a055e 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -782,6 +782,29 @@ int ff_encode_preinit(AVCodecContext *avctx)
 return AVERROR(ENOMEM);
 }
 
+for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {
+const enum AVPacketSideDataType type_packet = 
ff_sd_global_map[i].packet;
+const enum AVFrameSideDataType  type_frame  = 
ff_sd_global_map[i].frame;
+const AVFrameSideData *sd_frame;
+AVPacketSideData  *sd_packet;
+
+sd_frame = av_frame_side_data_get(avctx->decoded_side_data,
+  avctx->nb_decoded_side_data,
+  type_frame);
+if (!sd_frame ||
+av_packet_side_data_get(avctx->coded_side_data, 
avctx->nb_coded_side_data,
+type_packet))
+
+continue;
+
+sd_packet = av_packet_side_data_new(>coded_side_data, 
>nb_coded_side_data,
+type_packet, sd_frame->size, 0);
+if (!sd_packet)
+return AVERROR(ENOMEM);
+
+memcpy(sd_packet->data, sd_frame->data, sd_frame->size);
+}
+
 if (CONFIG_FRAME_THREAD_ENCODER) {
 ret = ff_frame_thread_encoder_init(avctx);
 if (ret < 0)
diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10
index 571c837cac..68511202a5 100644
--- a/tests/ref/fate/libx265-hdr10
+++ b/tests/ref/fate/libx265-hdr10
@@ -1,16 +1,16 @@
 frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data 
Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data 
Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display 
metadata"
-frames.frame.0.side_data_list.side_data.2.red_x="13250/5"
-frames.frame.0.side_data_list.side_data.2.red_y="34500/5"
-frames.frame.0.side_data_list.side_data.2.green_x="7500/5"
-frames.frame.0.side_data_list.side_data.2.green_y="3000/5"
-frames.frame.0.side_data_list.side_data.2.blue_x="34000/5"
-frames.frame.0.side_data_list.side_data.2.blue_y="16000/5"
-frames.frame.0.side_data_list.side_data.2.white_point_x="15635/5"
-frames.frame.0.side_data_list.side_data.2.white_point_y="16450/5"
-frames.frame.0.side_data_list.side_data.2.min_luminance="50/1"
-frames.frame.0.side_data_list.side_data.2.max_luminance="1000/1"
+frames.frame.0.side_data_list.side_data.1.side_data_type="Mastering display 
metadata"
+frames.frame.0.side_data_list.side_data.1.red_x="13250/5"
+frames.frame.0.side_data_list.side_data.1.red_y="34500/5"
+frames.frame.0.side_data_list.side_data.1.green_x="7500/5"
+frames.frame.0.side_data_list.side_data.1.green_y="3000/5"
+frames.frame.0.side_data_list.side_data.1.blue_x="34000/5"
+frames.frame.0.side_data_list.side_data.1.blue_y="16000/5"
+frames.frame.0.side_data_list.side_data.1.white_point_x="15635/5"
+frames.frame.0.side_data_list.side_data.1.white_point_y="16450/5"
+frames.frame.0.side_data_list.side_data.1.min_luminance="50/1"
+frames.frame.0.side_data_list.side_data.1.max_luminance="1000/1"
+frames.frame.0.side_data_list.side_data.2.side_data_type="H.26[45] User Data 
Unregistered SEI message"
 frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level 
metadata"
 frames.frame.0.side_data_list.side_data.3.max_content=1000
 frames.frame.0.side_data_list.side_data.3.max_average=200
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 12/12] fftools/ffmpeg_demux: make InputStream.autorotate private

2024-03-22 Thread Anton Khirnov
It is no longer accessed outside of ffmpeg_demux.
---
 fftools/ffmpeg.h   | 2 --
 fftools/ffmpeg_demux.c | 8 +---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 1437b36b0d..84475434f3 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -370,8 +370,6 @@ typedef struct InputStream {
 int   top_field_first;
 #endif
 
-int   autorotate;
-
 int   fix_sub_duration;
 
 /* decoded data from this stream goes into all those filters
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index af4b4cfd1e..d815dd3696 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -64,6 +64,8 @@ typedef struct DemuxStream {
 int  streamcopy_needed;
 int  have_sub2video;
 int  reinit_filters;
+int  autorotate;
+
 
 int  wrap_correction_done;
 int  saw_first_ts;
@@ -1055,7 +1057,7 @@ int ist_filter_add(InputStream *ist, InputFilter 
*ifilter, int is_simple,
 if (!opts->name)
 return AVERROR(ENOMEM);
 
-opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ist->autorotate) |
+opts->flags |= IFILTER_FLAG_AUTOROTATE * !!(ds->autorotate) |
IFILTER_FLAG_REINIT * !!(ds->reinit_filters);
 
 return ds->sch_idx_dec;
@@ -1235,8 +1237,8 @@ static int ist_add(const OptionsContext *o, Demuxer *d, 
AVStream *st)
 ds->ts_scale = 1.0;
 MATCH_PER_STREAM_OPT(ts_scale, dbl, ds->ts_scale, ic, st);
 
-ist->autorotate = 1;
-MATCH_PER_STREAM_OPT(autorotate, i, ist->autorotate, ic, st);
+ds->autorotate = 1;
+MATCH_PER_STREAM_OPT(autorotate, i, ds->autorotate, ic, st);
 
 MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
 if (codec_tag) {
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 11/12] fftools/ffmpeg_enc: stop copying demuxer side data to the muxer

2024-03-22 Thread Anton Khirnov
All side data should be propagated through the trancoding pipeline.
---
 fftools/ffmpeg_enc.c | 23 ---
 1 file changed, 23 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f01be1c22f..138044da24 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -360,29 +360,6 @@ int enc_open(void *opaque, const AVFrame *frame)
 return ret;
 }
 
-/*
- * Add global input side data. For now this is naive, and copies it
- * from the input stream's global side data. All side data should
- * really be funneled over AVFrame and libavfilter, then added back to
- * packet side data, and then potentially using the first packet for
- * global side data.
- */
-if (ist) {
-for (int i = 0; i < ist->st->codecpar->nb_coded_side_data; i++) {
-AVPacketSideData *sd_src = >st->codecpar->coded_side_data[i];
-if (sd_src->type != AV_PKT_DATA_CPB_PROPERTIES) {
-AVPacketSideData *sd_dst = 
av_packet_side_data_new(>par_in->coded_side_data,
-   
>par_in->nb_coded_side_data,
-   
sd_src->type, sd_src->size, 0);
-if (!sd_dst)
-return AVERROR(ENOMEM);
-memcpy(sd_dst->data, sd_src->data, sd_src->size);
-if (ist->autorotate && sd_src->type == 
AV_PKT_DATA_DISPLAYMATRIX)
-av_display_rotation_set((int32_t *)sd_dst->data, 0);
-}
-}
-}
-
 // copy timebase while removing common factors
 if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0)
 ost->st->time_base = av_add_q(ost->enc_ctx->time_base, (AVRational){0, 
1});
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 03/12] fftools/cmdutils: do not use a random codec's private options

2024-03-22 Thread Anton Khirnov
There is only a single caller of filter_codec_opts() that passes
a NULL codec to it, which is streamcopy in ffmpeg CLI. In that case we
only want generic AVCodecContext options, not private options of any
specific encoder.
---
 fftools/cmdutils.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index f3c258bb99..1bb26f44f4 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -998,10 +998,6 @@ int filter_codec_opts(const AVDictionary *opts, enum 
AVCodecID codec_id,
 char  prefix = 0;
 const AVClass*cc = avcodec_get_class();
 
-if (!codec)
-codec= s->oformat ? avcodec_find_encoder(codec_id)
-  : avcodec_find_decoder(codec_id);
-
 switch (st->codecpar->codec_type) {
 case AVMEDIA_TYPE_VIDEO:
 prefix  = 'v';
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 08/12] lavc/frame_thread_encoder: avoid assigning a whole AVCodecContext

2024-03-22 Thread Anton Khirnov
It is highly unsafe, as AVCodecContext contains many allocated fields.
Copying information via AVCodecParameters and with av_opt_copy() should
handle everything needed by thread workers.
---
 libavcodec/frame_thread_encoder.c | 26 --
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/libavcodec/frame_thread_encoder.c 
b/libavcodec/frame_thread_encoder.c
index cda5158117..744062b776 100644
--- a/libavcodec/frame_thread_encoder.c
+++ b/libavcodec/frame_thread_encoder.c
@@ -28,6 +28,7 @@
 #include "libavutil/thread.h"
 #include "avcodec.h"
 #include "avcodec_internal.h"
+#include "codec_par.h"
 #include "encode.h"
 #include "internal.h"
 #include "pthread_internal.h"
@@ -121,6 +122,7 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
*avctx)
 int i=0;
 ThreadContext *c;
 AVCodecContext *thread_avctx = NULL;
+AVCodecParameters *par = NULL;
 int ret;
 
 if(   !(avctx->thread_type & FF_THREAD_FRAME)
@@ -194,18 +196,27 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
*avctx)
 }
 }
 
+par = avcodec_parameters_alloc();
+if (!par) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+ret = avcodec_parameters_from_context(par, avctx);
+if (ret < 0)
+goto fail;
+
 for(i=0; ithread_count ; i++){
-void *tmpv;
 thread_avctx = avcodec_alloc_context3(avctx->codec);
 if (!thread_avctx) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
-tmpv = thread_avctx->priv_data;
-*thread_avctx = *avctx;
-thread_avctx->priv_data = tmpv;
-thread_avctx->internal = NULL;
-thread_avctx->hw_frames_ctx = NULL;
+
+ret = avcodec_parameters_to_context(thread_avctx, par);
+if (ret < 0)
+goto fail;
+
 ret = av_opt_copy(thread_avctx, avctx);
 if (ret < 0)
 goto fail;
@@ -227,10 +238,13 @@ av_cold int ff_frame_thread_encoder_init(AVCodecContext 
*avctx)
 }
 }
 
+avcodec_parameters_free();
+
 avctx->active_thread_type = FF_THREAD_FRAME;
 
 return 0;
 fail:
+avcodec_parameters_free();
 ff_codec_close(thread_avctx);
 av_freep(_avctx);
 avctx->thread_count = i;
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 07/12] fftools/ffmpeg_filter: remove display matrix if we have applied it

2024-03-22 Thread Anton Khirnov
---
 fftools/ffmpeg_filter.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3d88482d07..9aa499a89e 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -143,6 +143,7 @@ typedef struct InputFilterPriv {
 AVBufferRef*hw_frames_ctx;
 
 int displaymatrix_present;
+int displaymatrix_applied;
 int32_t displaymatrix[9];
 
 // fallback parameters to use when no input is ever sent
@@ -1568,6 +1569,7 @@ static int configure_input_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 av_assert0(desc);
 
 // TODO: insert hwaccel enabled filters like transpose_vaapi into the graph
+ifp->displaymatrix_applied = 0;
 if ((ifp->opts.flags & IFILTER_FLAG_AUTOROTATE) &&
 !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
 int32_t *displaymatrix = ifp->displaymatrix;
@@ -1601,6 +1603,8 @@ static int configure_input_video_filter(FilterGraph *fg, 
AVFilterGraph *graph,
 }
 if (ret < 0)
 return ret;
+
+ifp->displaymatrix_applied = 1;
 }
 
 snprintf(name, sizeof(name), "trim_in_%s", ifp->opts.name);
@@ -2697,6 +2701,9 @@ static int send_frame(FilterGraph *fg, FilterGraphThread 
*fgt,
 frame->duration  = av_rescale_q(frame->duration, frame->time_base, 
ifp->time_base);
 frame->time_base = ifp->time_base;
 
+if (ifp->displaymatrix_applied)
+av_frame_remove_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX);
+
 fd = frame_data(frame);
 if (!fd)
 return AVERROR(ENOMEM);
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 05/12] fftools/ffmpeg_{demux, dec}: pass -bitexact through DecoderFlags

2024-03-22 Thread Anton Khirnov
Avoids abusing AV_DICT_MULTIKEY and relying on undocumented AVDictionary
ordering behaviour.
---
 fftools/ffmpeg.h   |  2 ++
 fftools/ffmpeg_dec.c   |  2 ++
 fftools/ffmpeg_demux.c | 11 +--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 7454089c2d..1437b36b0d 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -304,6 +304,8 @@ enum DecoderFlags {
 DECODER_FLAG_TOP_FIELD_FIRST  = (1 << 3),
 #endif
 DECODER_FLAG_SEND_END_TS  = (1 << 4),
+// force bitexact decoding
+DECODER_FLAG_BITEXACT = (1 << 5),
 };
 
 typedef struct DecoderOpts {
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index ad02a64b60..b8bfae469f 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -1211,6 +1211,8 @@ static int dec_open(DecoderPriv *dp, AVDictionary 
**dec_opts,
 return ret;
 
 dp->dec_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
+if (o->flags & DECODER_FLAG_BITEXACT)
+dp->dec_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
 
 if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
 av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 73b0eb0da1..af4b4cfd1e 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -908,11 +908,11 @@ static int ist_use(InputStream *ist, int decoding_needed)
 if (decoding_needed && ds->sch_idx_dec < 0) {
 int is_audio = ist->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
 
-ds->dec_opts.flags = (!!ist->fix_sub_duration * 
DECODER_FLAG_FIX_SUB_DURATION) |
- (!!(d->f.ctx->iformat->flags & 
AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE) |
- (!!(d->loop && is_audio) * 
DECODER_FLAG_SEND_END_TS)
+ds->dec_opts.flags |= (!!ist->fix_sub_duration * 
DECODER_FLAG_FIX_SUB_DURATION) |
+  (!!(d->f.ctx->iformat->flags & 
AVFMT_NOTIMESTAMPS) * DECODER_FLAG_TS_UNRELIABLE) |
+  (!!(d->loop && is_audio) * 
DECODER_FLAG_SEND_END_TS)
 #if FFMPEG_OPT_TOP
- | ((ist->top_field_first >= 0) * 
DECODER_FLAG_TOP_FIELD_FIRST)
+  | ((ist->top_field_first >= 0) * 
DECODER_FLAG_TOP_FIELD_FIRST)
 #endif
  ;
 
@@ -1357,8 +1357,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, 
AVStream *st)
 ist->user_set_discard = ist->st->discard;
 }
 
-if (o->bitexact)
-av_dict_set(>decoder_opts, "flags", "+bitexact", AV_DICT_MULTIKEY);
+ds->dec_opts.flags |= DECODER_FLAG_BITEXACT * !!o->bitexact;
 
 /* Attached pics are sparse, therefore we would not want to delay their 
decoding
  * till EOF. */
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 04/12] fftools/ffmpeg_dec: apply decoder options manually

2024-03-22 Thread Anton Khirnov
Do not pass an options dictionary to avcodec_open2().

This should be equivalent to current behaviour, but will allow
overriding caller-supplied options in a cleaner and more robust manner.

We can now set the COPY_OPAQUE flag directly rather going through
dec_opts.
---
 fftools/ffmpeg_dec.c | 21 ++---
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index ed411b6bf8..ad02a64b60 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -21,6 +21,7 @@
 #include "libavutil/dict.h"
 #include "libavutil/error.h"
 #include "libavutil/log.h"
+#include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/pixfmt.h"
 #include "libavutil/time.h"
@@ -1191,8 +1192,6 @@ static int dec_open(DecoderPriv *dp, AVDictionary 
**dec_opts,
 if (!av_dict_get(*dec_opts, "threads", NULL, 0))
 av_dict_set(dec_opts, "threads", "auto", 0);
 
-av_dict_set(dec_opts, "flags", "+copy_opaque", AV_DICT_MULTIKEY);
-
 ret = hw_device_setup_for_decode(dp, codec, o->hwaccel_device);
 if (ret < 0) {
 av_log(dp, AV_LOG_ERROR,
@@ -1201,7 +1200,19 @@ static int dec_open(DecoderPriv *dp, AVDictionary 
**dec_opts,
 return ret;
 }
 
-if ((ret = avcodec_open2(dp->dec_ctx, codec, dec_opts)) < 0) {
+ret = av_opt_set_dict2(dp->dec_ctx, dec_opts, AV_OPT_SEARCH_CHILDREN);
+if (ret < 0) {
+av_log(dp, AV_LOG_ERROR, "Error applying decoder options: %s\n",
+   av_err2str(ret));
+return ret;
+}
+ret = check_avoptions(*dec_opts);
+if (ret < 0)
+return ret;
+
+dp->dec_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
+
+if ((ret = avcodec_open2(dp->dec_ctx, codec, NULL)) < 0) {
 av_log(dp, AV_LOG_ERROR, "Error while opening decoder: %s\n",
av_err2str(ret));
 return ret;
@@ -1220,10 +1231,6 @@ static int dec_open(DecoderPriv *dp, AVDictionary 
**dec_opts,
 dp->dec_ctx->extra_hw_frames = extra_frames;
 }
 
-ret = check_avoptions(*dec_opts);
-if (ret < 0)
-return ret;
-
 dp->dec.subtitle_header  = dp->dec_ctx->subtitle_header;
 dp->dec.subtitle_header_size = dp->dec_ctx->subtitle_header_size;
 
-- 
2.43.0

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

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


[FFmpeg-devel] [PATCH 02/12] fftools/ffmpeg_demux: only call filter_codec_opts() when we have a decoder

2024-03-22 Thread Anton Khirnov
It is pointless otherwise, as decoder options will not be used.
---
 fftools/ffmpeg_demux.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 47312c9fe1..73b0eb0da1 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1329,10 +1329,12 @@ static int ist_add(const OptionsContext *o, Demuxer *d, 
AVStream *st)
 if (ret < 0)
 return ret;
 
-ret = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id,
-ic, st, ist->dec, >decoder_opts);
-if (ret < 0)
-return ret;
+if (ist->dec) {
+ret = filter_codec_opts(o->g->codec_opts, ist->st->codecpar->codec_id,
+ic, st, ist->dec, >decoder_opts);
+if (ret < 0)
+return ret;
+}
 
 ds->reinit_filters = -1;
 MATCH_PER_STREAM_OPT(reinit_filters, i, ds->reinit_filters, ic, st);
-- 
2.43.0

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

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


Re: [FFmpeg-devel] [PATCH] tests: Remove fate-libx265-hdr10

2024-03-22 Thread Anton Khirnov
Quoting Zhao Zhili (2024-03-22 13:43:43)
> From: Zhao Zhili 
> 
> The test depends on the compile option of x265. It failed when
> HIGH_BIT_DEPTH isn't enabled. It also failed when asan is enabled
> because of memory issue inside of x265, which I don't think can
> be fixed within FFmpeg.

I suggested some time ago we should mark x265 as experimental. It didn't
receive much enthusiasm, and some probably considered it a joke, but I
was mostly serious. It has major memory safety issues that have been
ignored for years.

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

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] ffmpeg: pass first video AVFrame's side data to encoder

2024-03-22 Thread James Almer

On 3/22/2024 6:52 AM, Anton Khirnov wrote:

Quoting Jan Ekström (2024-03-20 18:31:49)

ffmpeg | branch: master | Jan Ekström  | Mon Jan  9 20:52:30 
2023 +0200| [8f4b173029aa9ecefb1370c954ef769664920d08] | committer: Jan Ekström

ffmpeg: pass first video AVFrame's side data to encoder

This enables further configuration of output based on the results
of input decoding and filtering in a similar manner as the color
information.


http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8f4b173029aa9ecefb1370c954ef769664920d08

---

  fftools/ffmpeg_enc.c | 15 +++
  1 file changed, 15 insertions(+)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index c9a12af139..f01be1c22f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -246,6 +246,21 @@ int enc_open(void *opaque, const AVFrame *frame)
  enc_ctx->colorspace = frame->colorspace;
  enc_ctx->chroma_sample_location = frame->chroma_location;
  
+for (int i = 0; i < frame->nb_side_data; i++) {

+ret = av_frame_side_data_clone(
+_ctx->decoded_side_data, _ctx->nb_decoded_side_data,
+frame->side_data[i], AV_FRAME_SIDE_DATA_FLAG_UNIQUE);


I objected to this indiscriminate copying in a previous review.

There is no reason to expect side data to apply to the whole stream just
because it happens to apply to the first frame. For many side data types
it does not even make sense, as they are fundamentally per-frame.


So this would need to be handled by having decoders export global side 
data in decoded_side_data directly, so there's no need to take them from 
frames here (which would include per frame side data, like hdr10 and 
closed captions), right?

___
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 6/6] MAINTAINERS: Add maintainer for LC3 audio codec wrapper

2024-03-22 Thread Michael Niedermayer
On Fri, Mar 22, 2024 at 05:25:27PM +, Kieran Kunhya wrote:
> > You've merged nothing yet and you want push access already?
> >
> 
> I think this was done in good-faith saying they want to maintain. I
> wouldn't antagonise people for no reason.

+1

thx

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

The worst form of inequality is to try to make unequal things equal.
-- Aristotle


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] avcodec/libx264: Remove unused variable

2024-03-22 Thread Zhao Zhili

> -Original Message-
> From: ffmpeg-devel  On Behalf Of Andreas 
> Rheinhardt
> Sent: 2024年3月22日 21:03
> To: ffmpeg-devel@ffmpeg.org
> Cc: Andreas Rheinhardt 
> Subject: [FFmpeg-devel] [PATCH] avcodec/libx264: Remove unused variable
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/libx264.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
> index 2653941eb9..3d195fa6b6 100644
> --- a/libavcodec/libx264.c
> +++ b/libavcodec/libx264.c
> @@ -867,7 +867,6 @@ static int save_sei(AVCodecContext *avctx, x264_nal_t 
> *nal)
>  #if CONFIG_LIBX264_ENCODER
>  static int set_avcc_extradata(AVCodecContext *avctx, x264_nal_t *nal, int 
> nnal)
>  {
> -X264Context *x4 = avctx->priv_data;
>  x264_nal_t *sps_nal = NULL;
>  x264_nal_t *pps_nal = NULL;
>  uint8_t *p, *sps;

LGTM.

> --
> 2.40.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 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 6/6] MAINTAINERS: Add maintainer for LC3 audio codec wrapper

2024-03-22 Thread Kieran Kunhya
> You've merged nothing yet and you want push access already?
>

I think this was done in good-faith saying they want to maintain. I
wouldn't antagonise people for no reason.

Kieran
___
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 6/6] MAINTAINERS: Add maintainer for LC3 audio codec wrapper

2024-03-22 Thread Lynne
Mar 22, 2024, 18:02 by ffmpeg-devel@ffmpeg.org:

> Signed-off-by: Antoine Soulier 
> Signed-off-by: Antoine SOULIER 
> ---
>  MAINTAINERS | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index dd633f37e8..d07512fc0c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -188,6 +188,7 @@ Codecs:
>  libdavs2.cHuiwen Ren
>  libjxl*.c, libjxl.h   Leo Izen
>  libgsm.c  Michel Bardiaux
> +  liblc3*   Antoine Soulier
>  libkvazaar.c  Arttu Ylä-Outinen
>  libopenh264enc.c  Martin Storsjo, Linjie Fu
>  libopenjpeg.c Jaikrishnan Menon
> @@ -393,6 +394,7 @@ Muxers/Demuxers:
>  jpegxl*   Leo Izen
>  jvdec.c   Peter Ross
>  kvag.cZane van Iperen
> +  lc3*  Antoine Soulier
>  libmodplug.c  Clément Bœsch
>  libopenmpt.c  Josh de Kock
>  lmlm4.c   Ivo van Poorten
>

You've merged nothing yet and you want push access already?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 1/4] fftools/ffmpeg_enc: strip DOVI config record for AV1

2024-03-22 Thread Niklas Haas
On Fri, 22 Mar 2024 14:08:07 +0100 Niklas Haas  wrote:
> On Fri, 22 Mar 2024 10:41:13 +0100 Anton Khirnov  wrote:
> > Quoting Niklas Haas (2024-03-21 13:11:32)
> > > On Thu, 21 Mar 2024 11:16:57 +0100 Anton Khirnov  
> > > wrote:
> > > > Quoting Niklas Haas (2024-03-19 20:16:39)
> > > > > From: Niklas Haas 
> > > > > 
> > > > > AV1 streams don't use configuration records, so delete them when
> > > > > encoding to AV1. Ideally this would be, as the comment suggests, 
> > > > > handled
> > > > > at the frame-level (and stripped by the av1 encoder), but given the
> > > > > status quo of copying the packet-level data here directly, we should
> > > > > definitely make an effort to strip it.
> > > > > ---
> > > > >  fftools/ffmpeg_enc.c | 25 ++---
> > > > >  1 file changed, 14 insertions(+), 11 deletions(-)
> > > > 
> > > > I'm very much not a fan of having codec-specific code in ffmpeg CLI. It
> > > > implies that every single caller must now be aware of this
> > > > (undocumented?) interaction of this specific side data with this
> > > > specific codec ID.
> > > 
> > > Note: This is an existing bug, not introduced by this series. This
> > > series just makes it obvious. The status quo is that, beacuse of this
> > > logic in ffmpeg_enc.c, we incorrectly forward dolby vision configuration
> > > records when transcoding to AV1.
> > 
> > I know pretty much nothing about dolby vision, so could you please
> > explain why precisely is this incorrect? And at what point in the
> > transcoding chain does the side data become invalid?
> 
> Dolby Vision basically consists of two separate pieces of metadata:
> 
> 1. The (per-stream) configuration struct, AV_PKT_DATA_DOVI_CONF
> 2. The per-frame structs (RPUs), AV_FRAME_DATA_DOVI_METADATA
>  (ditto AV_FRAME_DATA_DOVI_RPU_BUFFER, which is the same)
> 
> A valid HEVC dolby vision file should contain both - the configuration
> struct tells the decoder that hey, this file is dolby vision (and what
> profile to expect, whether there's an enhancement layer, etc.). The RPUs
> contain the actual DV-specific details of how each frame is encoded.
> 
> A valid AV1 dolby vision file, on the other hand, only uses the
> per-frame RPUs, it does not have a configuration struct at all.

Correction: AV1 still uses configuration records, I was not looking at
spec-compliant sample files. So at least, this difference evaporates.

> The current logic in ffmpeg_enc.c copies over all stream-level metadata,
> including the DOVI_CONF struct, to the output file. This generates
> a stream which is *marked* as being Dolby Vision, but in which none of
> the frames actually contain DV RPUs. This *probably* violates some spec
> somewhere, and at the very least is not desirable behavior. (And for
> AV1, the configuration struct's presence is definitely a no-go)
> 
> Basically, we want to handle all of these scenarios:
> 
> 1. When transcoding DV HEVC (profile 8) to DV AV1 (profile 10), we need
>to strip the configuration struct somewhere
> 2. When transcoding DV HEVC (profile 8) to HEVC, we need to strip the
>configuration struct IFF we're also stripping the per-frame RPUs
>(e.g. as a result of filtering).
> 3. When transcoding DV AV1 (profile 10) to HEVC, we need to *synthesize*
>a configuration struct containing the correct values.
> 
> I think the best way forward for now is:
> 
> 1. Always strip the dovi configuration record when transcoding
> 2. Have the encoder generate (and attach to avctx.coded_side_data) the
>correct configuration record.

As discussed on IRC, removing this logic entirely will cover the first
point.

> I will write a patch for #2.
> 
> > > Or, indeed, when transcoding to *any* format - since current FFmpeg also
> > > does not propagate dolby vision RPUs, we generate broken files pretty
> > > much always when transcoding dolby vision. So we definitely need to
> > > strip the metadata from the stream muxer *somewhere*. Where else comes
> > > to mind?
> > > 
> > > This also gets into another topic I wanted to touch on, which is that
> > > the presence of dynamic dolby vision metadata currently hinders the
> > > ability of libavfilter to treat the video primaries/gamma as
> > > a negotiable colorspace property (the way it is done currently for YUV
> > > matrix/range). This is because when interpreted as such, DV metadata
> > > fundamentally changes the colorspace of the incoming video stream.
> > > Ideally we would like some way to negotiate DV metadata on the
> > > query_formats() level.
> > > 
> > > Ideally, we'd want something like AVCOL_SPC_DOLBYVISION, but we can't
> > > easily introduce that without breaking ISO/IEC 23091 compatibility..
> > 
> > In principle it could be yet another negotiated field, could it not? You
> > just added a bunch of those recently, what's another one?
> 
> Adding more fields to this negotiation process is a very obnoxious and
> tedious process, with lots of boilerplate for each new field added.
> Maybe we 

[FFmpeg-devel] [PATCH 6/6] MAINTAINERS: Add maintainer for LC3 audio codec wrapper

2024-03-22 Thread Antoine Soulier via ffmpeg-devel
Signed-off-by: Antoine Soulier 
Signed-off-by: Antoine SOULIER 
---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index dd633f37e8..d07512fc0c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -188,6 +188,7 @@ Codecs:
   libdavs2.cHuiwen Ren
   libjxl*.c, libjxl.h   Leo Izen
   libgsm.c  Michel Bardiaux
+  liblc3*   Antoine Soulier
   libkvazaar.c  Arttu Ylä-Outinen
   libopenh264enc.c  Martin Storsjo, Linjie Fu
   libopenjpeg.c Jaikrishnan Menon
@@ -393,6 +394,7 @@ Muxers/Demuxers:
   jpegxl*   Leo Izen
   jvdec.c   Peter Ross
   kvag.cZane van Iperen
+  lc3*  Antoine Soulier
   libmodplug.c  Clément Bœsch
   libopenmpt.c  Josh de Kock
   lmlm4.c   Ivo van Poorten
-- 
2.44.0.396.g6e790dbe36-goog

___
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/6] Changelog: Add LC3/LC3plus decoding/encoding support

2024-03-22 Thread Antoine Soulier via ffmpeg-devel
Signed-off-by: Antoine Soulier 
Signed-off-by: Antoine SOULIER 
---
 Changelog | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Changelog b/Changelog
index c6e8f6bcaf..fb08ee2f81 100644
--- a/Changelog
+++ b/Changelog
@@ -2,6 +2,7 @@ Entries are sorted chronologically from oldest to youngest 
within each release,
 releases are sorted from youngest to oldest.
 
 version :
+- LC3/LC3plus decoding/encoding using external library liblc3
 - DXV DXT1 encoder
 - LEAD MCMP decoder
 - EVC decoding using external library libxevd
-- 
2.44.0.396.g6e790dbe36-goog

___
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/6] configure: Add option for enabling LC3/LC3plus wrapper

2024-03-22 Thread Antoine Soulier via ffmpeg-devel
Signed-off-by: Antoine Soulier 
Signed-off-by: Antoine SOULIER 
---
 configure | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/configure b/configure
index 343edb38ab..eb8ff81a11 100755
--- a/configure
+++ b/configure
@@ -244,6 +244,7 @@ External library support:
   --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-liblc3  enable LC3 de/encoding via liblc3 [no]
   --enable-liblensfun  enable lensfun lens correction [no]
   --enable-libmodplug  enable ModPlug via libmodplug [no]
   --enable-libmp3lame  enable MP3 encoding via libmp3lame [no]
@@ -1926,6 +1927,7 @@ EXTERNAL_LIBRARY_LIST="
 libjxl
 libklvanc
 libkvazaar
+liblc3
 libmodplug
 libmp3lame
 libmysofa
@@ -3501,6 +3503,10 @@ libilbc_encoder_deps="libilbc"
 libjxl_decoder_deps="libjxl libjxl_threads"
 libjxl_encoder_deps="libjxl libjxl_threads"
 libkvazaar_encoder_deps="libkvazaar"
+liblc3_lc3_decoder_deps="liblc3"
+liblc3_lc3plus_decoder_deps="liblc3"
+liblc3_encoder_deps="liblc3"
+liblc3_encoder_select="audio_frame_queue"
 libmodplug_demuxer_deps="libmodplug"
 libmp3lame_encoder_deps="libmp3lame"
 libmp3lame_encoder_select="audio_frame_queue mpegaudioheader"
@@ -6858,6 +6864,7 @@ enabled libjxl&& require_pkg_config libjxl 
"libjxl >= 0.7.0" jxl/dec
  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 >= 2.0.0" 
kvazaar.h kvz_api_get
+enabled liblc3&& require_pkg_config liblc3 "lc3 >= 1.1.0" lc3.h 
lc3_hr_setup_encoder
 enabled liblensfun&& require_pkg_config liblensfun lensfun lensfun.h 
lf_db_create
 
 if enabled libmfx && enabled libvpl; then
-- 
2.44.0.396.g6e790dbe36-goog

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

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


[FFmpeg-devel] [PATCH 4/6] doc: Add LC3/LC3plus muxer and encoder parameters documentation

2024-03-22 Thread Antoine Soulier via ffmpeg-devel
Signed-off-by: Antoine Soulier 
Signed-off-by: Antoine SOULIER 
---
 doc/encoders.texi | 57 +++
 doc/general_contents.texi | 12 -
 doc/muxers.texi   |  4 +++
 3 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index 7c223ed74c..0719ba13cc 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -814,6 +814,63 @@ ffmpeg -i input.wav -c:a libfdk_aac -profile:a aac_he -b:a 
64k output.m4a
 @end example
 @end itemize
 
+@anchor{liblc3-enc}
+@section liblc3
+
+liblc3 LC3 (Low Complexity Communication Codec) encoder wrapper.
+
+Requires the presence of the liblc3 headers and library during configuration.
+You need to explicitly configure the build with @code{--enable-liblc3}.
+
+This encoder has support for the Bluetooth SIG LC3 codec for the LE Audio
+protocol, and the following features of LC3plus:
+@itemize @minus
+@item
+Frame duration of 2.5 and 5ms.
+@item
+High-Resolution mode, 48 KHz, and 96 kHz sampling rates.
+@end itemize
+
+For more information see the liblc3 project at
+@url{https://github.com/google/liblc3}.
+
+@subsection Options
+
+The following options are mapped on the shared FFmpeg codec options.
+
+@table @option
+@item b
+Set the bit rate in bits/s. This will determine the fixed size of the encoded
+frames, for a selected frame duration.
+
+@item ar
+Set the audio sampling rate (in Hz).
+
+@item channels
+Set the number of audio channels.
+
+@item frame_duration
+Set the audio frame duration in milliseconds. Default value is 10ms.
+Allowed frame durations are 2.5ms, 5ms, 7.5ms and 10ms.
+LC3 (Bluetooth LE Audio), allows 7.5ms and 10ms; and LC3plus 2.5ms, 5ms
+and 10ms.
+
+The 10ms frame duration is available in LC3 and LC3 plus standard.
+In this mode, the produced bitstream can be referenced either as LC3 or 
LC3plus.
+
+@item high_resolution
+Enable the high-resolution mode if set to 1. The high-resolution mode is
+available with all LC3plus frame durations and for a sampling rate 48 KHz,
+and 96 KHz.
+
+The encoder automatically turns off this mode at lower sampling rates and
+activates it at 96 KHz.
+
+This mode should be preferred at high bitrates. In this mode, the audio
+bandwidth is always up to the Nyquist frequency, compared to LC3 at 48 KHz,
+which limits the bandwidth to 20 KHz.
+@end table
+
 @anchor{libmp3lame}
 @section libmp3lame
 
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index f269cbd1a9..9e340fce7b 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -237,6 +237,14 @@ Go to @url{http://sourceforge.net/projects/opencore-amr/} 
and follow the
 instructions for installing the library.
 Then pass @code{--enable-libfdk-aac} to configure to enable it.
 
+@subsection LC3 library
+
+FFmpeg can make use of the Google LC3 library for LC3 decoding & encoding.
+
+Go to @url{https://github.com/google/liblc3/} and follow the instructions for
+installing the library.
+Then pass @code{--enable-liblc3} to configure to enable it.
+
 @section OpenH264
 
 FFmpeg can make use of the OpenH264 library for H.264 decoding and encoding.
@@ -1300,7 +1308,9 @@ following image formats are supported:
 @tab encoding and decoding supported through external library libilbc
 @item IMC (Intel Music Coder)  @tab @tab  X
 @item Interplay ACM@tab @tab  X
-@item MACE (Macintosh Audio Compression/Expansion) 3:1  @tab @tab  X
+@item LC3@tab E  @tab  E
+@tab supported through external library liblc3
+@item LC3plus@tab  E  @tab  E
 @item MACE (Macintosh Audio Compression/Expansion) 6:1  @tab @tab  X
 @item Marian's A-pac audio @tab @tab  X
 @item MI-SC4 (Micronas SC-4 Audio)  @tab @tab  X
diff --git a/doc/muxers.texi b/doc/muxers.texi
index d9dd72e613..43dabe4499 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -132,6 +132,10 @@ to Annex B syntax if it's in length-prefixed mode.
 ITU-T H.265 / MPEG-H Part 2 HEVC video. Bitstream shall be converted
 to Annex B syntax if it's in length-prefixed mode.
 
+@item lc3 @emph{audio} (lc3)
+Bluetooth SIG Low Complexity Communication Codec audio.
+ETSI TS 103 634 Low Complexity Communication Codec plus (LC3plus).
+
 @item m4v @emph{video}
 MPEG-4 Part 2 video
 
-- 
2.44.0.396.g6e790dbe36-goog

___
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/6] avformat/lc3: Add file format for LC3/LC3plus transport

2024-03-22 Thread Antoine Soulier via ffmpeg-devel
A file format is described in Bluetooth SIG LC3 and ETSI TS 103 634, for
test purpose. This is the format implemented here.

Signed-off-by: Antoine Soulier 
Signed-off-by: Antoine SOULIER 
---
 libavformat/Makefile |   3 +
 libavformat/allformats.c |   3 +
 libavformat/lc3dec.c | 140 +++
 libavformat/lc3enc.c | 118 +
 4 files changed, 264 insertions(+)
 create mode 100644 libavformat/lc3dec.c
 create mode 100644 libavformat/lc3enc.c

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 94a949f555..29a38c1d94 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -332,6 +332,9 @@ OBJS-$(CONFIG_KVAG_DEMUXER)  += kvag.o
 OBJS-$(CONFIG_KVAG_MUXER)+= kvag.o rawenc.o
 OBJS-$(CONFIG_LAF_DEMUXER)   += lafdec.o
 OBJS-$(CONFIG_LATM_MUXER)+= latmenc.o rawenc.o
+OBJS-$(CONFIG_LC3_DEMUXER)   += lc3dec.o
+OBJS-$(CONFIG_LC3_MUXER) += lc3enc.o
+OBJS-$(CONFIG_LC3_PLUS_MUXER)+= lc3enc.o
 OBJS-$(CONFIG_LMLM4_DEMUXER) += lmlm4.o
 OBJS-$(CONFIG_LOAS_DEMUXER)  += loasdec.o rawdec.o
 OBJS-$(CONFIG_LUODAT_DEMUXER)+= luodatdec.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index e15d0fa6d7..551b0f0d7b 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -252,6 +252,9 @@ extern const FFInputFormat  ff_kvag_demuxer;
 extern const FFOutputFormat ff_kvag_muxer;
 extern const FFInputFormat  ff_laf_demuxer;
 extern const FFOutputFormat ff_latm_muxer;
+extern const FFInputFormat  ff_lc3_demuxer;
+extern const FFOutputFormat ff_lc3_muxer;
+extern const FFOutputFormat ff_lc3_plus_muxer;
 extern const FFInputFormat  ff_lmlm4_demuxer;
 extern const FFInputFormat  ff_loas_demuxer;
 extern const FFInputFormat  ff_luodat_demuxer;
diff --git a/libavformat/lc3dec.c b/libavformat/lc3dec.c
new file mode 100644
index 00..563384f786
--- /dev/null
+++ b/libavformat/lc3dec.c
@@ -0,0 +1,140 @@
+/*
+ * LC3 demuxer
+ * Copyright (C) 2024  Antoine Soulier 
+ *
+ * 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
+ * Based on the file format specified by :
+ *
+ * - Bluetooth SIG - Low Complexity Communication Codec Test Suite
+ *   https://www.bluetooth.org/docman/handlers/downloaddoc.ashx?doc_id=502301
+ *   3.2.8.2 Reference LC3 Codec Bitstream Format
+ *
+ * - ETSI TI 103 634 V1.4.1 - Low Complexity Communication Codec plus
+ *   
https://www.etsi.org/deliver/etsi_ts/103600_103699/103634/01.04.01_60/ts_103634v010401p.pdf
+ *   LC3plus conformance script package
+ */
+
+#include 
+
+#include "libavcodec/avcodec.h"
+#include "libavcodec/packet.h"
+#include "libavutil/intreadwrite.h"
+
+#include "avformat.h"
+#include "avio.h"
+#include "demux.h"
+#include "internal.h"
+
+typedef struct LC3DemuxContext {
+int frame_samples;
+int64_t position;
+int64_t length;
+} LC3DemuxContext;
+
+static int lc3_read_header(AVFormatContext *s)
+{
+LC3DemuxContext *lc3 = s->priv_data;
+AVStream *st = NULL;
+uint16_t tag, hdr_size;
+uint16_t frame_us;
+uint32_t length;
+bool ep_mode, hr_mode;
+int srate_hz, channels, bit_rate;
+int num_extra_params, ret;
+
+tag = avio_rb16(s->pb);
+hdr_size = avio_rl16(s->pb);
+
+if (tag != 0x1ccc || hdr_size < 9 * sizeof(uint16_t))
+return AVERROR_INVALIDDATA;
+
+num_extra_params = hdr_size / sizeof(uint16_t) - 9;
+
+srate_hz = avio_rl16(s->pb) * 100;
+bit_rate = avio_rl16(s->pb) * 100;
+channels = avio_rl16(s->pb);
+frame_us = avio_rl16(s->pb) * 10;
+ep_mode  = avio_rl16(s->pb) != 0;
+length   = avio_rl32(s->pb);
+hr_mode  = num_extra_params >= 1 && avio_rl16(s->pb);
+
+st = avformat_new_stream(s, NULL);
+if (!st)
+return AVERROR(ENOMEM);
+
+avpriv_set_pts_info(st, 32, 1, srate_hz);
+st->duration = length;
+
+st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+st->codecpar->codec_id = frame_us <= 5000 || ep_mode || hr_mode ?
+ AV_CODEC_ID_LC3_PLUS : AV_CODEC_ID_LC3;
+st->codecpar->sample_rate = srate_hz;
+st->codecpar->bit_rate = bit_rate;
+st->codecpar->ch_layout.nb_channels = 

[FFmpeg-devel] [PATCH 1/6] avcodec/liblc3: Add encoding/decoding support of LC3 audio codec

2024-03-22 Thread Antoine Soulier via ffmpeg-devel
The LC3 audio codec is the default codec of Bluetooth LE audio.
This is a wrapper over the liblc3 library (https://github.com/google/liblc3).

Signed-off-by: Antoine Soulier 
Signed-off-by: Antoine SOULIER 
---
 libavcodec/Makefile |   3 +
 libavcodec/allcodecs.c  |   3 +
 libavcodec/codec_desc.c |  14 +++
 libavcodec/codec_id.h   |   2 +
 libavcodec/liblc3dec.c  | 146 ++
 libavcodec/liblc3enc.c  | 191 
 6 files changed, 359 insertions(+)
 create mode 100644 libavcodec/liblc3dec.c
 create mode 100644 libavcodec/liblc3enc.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 708434ac76..7d2cf3076d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1123,6 +1123,9 @@ 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_LIBLC3_ENCODER) += liblc3enc.o
+OBJS-$(CONFIG_LIBLC3_LC3_DECODER) += liblc3dec.o
+OBJS-$(CONFIG_LIBLC3_LC3PLUS_DECODER) += liblc3dec.o
 OBJS-$(CONFIG_LIBMP3LAME_ENCODER) += libmp3lame.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER)  += libopencore-amr.o
 OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER)  += libopencore-amr.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 2386b450a6..29aedaeac6 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -776,6 +776,9 @@ 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_liblc3_encoder;
+extern const FFCodec ff_liblc3_lc3_decoder;
+extern const FFCodec ff_liblc3_lc3plus_decoder;
 extern const FFCodec ff_libmp3lame_encoder;
 extern const FFCodec ff_libopencore_amrnb_encoder;
 extern const FFCodec ff_libopencore_amrnb_decoder;
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 3bab86db62..230bba2a09 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3425,6 +3425,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
 .long_name = NULL_IF_CONFIG_SMALL("QOA (Quite OK Audio)"),
 .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
 },
+{
+.id= AV_CODEC_ID_LC3,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "lc3",
+.long_name = NULL_IF_CONFIG_SMALL("LC3 (Low Complexity Communication 
Codec)"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+},
+{
+.id= AV_CODEC_ID_LC3_PLUS,
+.type  = AVMEDIA_TYPE_AUDIO,
+.name  = "lc3_plus",
+.long_name = NULL_IF_CONFIG_SMALL("LC3plus (Low Complexity 
Communication Codec plus)"),
+.props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
+},
 
 /* subtitle codecs */
 {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index c8dc21da74..7e4cb39049 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -543,6 +543,8 @@ enum AVCodecID {
 AV_CODEC_ID_AC4,
 AV_CODEC_ID_OSQ,
 AV_CODEC_ID_QOA,
+AV_CODEC_ID_LC3,
+AV_CODEC_ID_LC3_PLUS,
 
 /* subtitle codecs */
 AV_CODEC_ID_FIRST_SUBTITLE = 0x17000,  ///< A dummy ID pointing at 
the start of subtitle codecs.
diff --git a/libavcodec/liblc3dec.c b/libavcodec/liblc3dec.c
new file mode 100644
index 00..e97cecc68f
--- /dev/null
+++ b/libavcodec/liblc3dec.c
@@ -0,0 +1,146 @@
+/*
+ * LC3 decoder wrapper
+ * Copyright (C) 2024  Antoine Soulier 
+ *
+ * This file is part of FFmpeg.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include 
+
+#include "libavutil/intreadwrite.h"
+
+#include "avcodec.h"
+#include "codec.h"
+#include "codec_internal.h"
+#include "decode.h"
+#include "internal.h"
+
+#define DECODER_MAX_CHANNELS  2
+
+typedef struct LibLC3DecContext {
+int frame_us, srate_hz;
+bool hr_mode;
+lc3_decoder_t decoder[DECODER_MAX_CHANNELS];
+} LibLC3DecContext;
+
+static av_cold int liblc3_decode_init(AVCodecContext *avctx)
+{
+LibLC3DecContext *liblc3 = avctx->priv_data;
+int channels = 

Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg_enc: Don't call frame_data twice

2024-03-22 Thread Jan Ekström
On Fri, Mar 22, 2024 at 6:07 PM Andreas Rheinhardt
 wrote:
>
> Signed-off-by: Andreas Rheinhardt 
> ---
>  fftools/ffmpeg_enc.c | 1 -
>  1 file changed, 1 deletion(-)
>
> diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
> index f01be1c22f..5f7fcf8a5f 100644
> --- a/fftools/ffmpeg_enc.c
> +++ b/fftools/ffmpeg_enc.c
> @@ -646,7 +646,6 @@ static int encode_frame(OutputFile *of, OutputStream 
> *ost, AVFrame *frame,
>  if (frame) {
>  FrameData *fd = frame_data(frame);
>
> -fd = frame_data(frame);
>  if (!fd)
>  return AVERROR(ENOMEM);
>

Good catch, LGTM.

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] fftools/ffmpeg_enc: Don't call frame_data twice

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 fftools/ffmpeg_enc.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index f01be1c22f..5f7fcf8a5f 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -646,7 +646,6 @@ static int encode_frame(OutputFile *of, OutputStream *ost, 
AVFrame *frame,
 if (frame) {
 FrameData *fd = frame_data(frame);
 
-fd = frame_data(frame);
 if (!fd)
 return AVERROR(ENOMEM);
 
-- 
2.40.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] avutil/channel_layout: don't clear the opaque pointer on type conversion

2024-03-22 Thread James Almer
Otherwise it would not be lossless.

Signed-off-by: James Almer 
---
 libavutil/channel_layout.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c
index a83618bcc7..3054ee08a5 100644
--- a/libavutil/channel_layout.c
+++ b/libavutil/channel_layout.c
@@ -902,9 +902,11 @@ int av_channel_layout_retype(AVChannelLayout 
*channel_layout, enum AVChannelOrde
 lossy = 1;
 }
 if (!lossy || allow_lossy) {
+void *opaque = channel_layout->opaque;
 av_channel_layout_uninit(channel_layout);
 channel_layout->order   = AV_CHANNEL_ORDER_UNSPEC;
 channel_layout->nb_channels = nb_channels;
+channel_layout->opaque  = opaque;
 return lossy;
 }
 return AVERROR(ENOSYS);
@@ -916,8 +918,10 @@ int av_channel_layout_retype(AVChannelLayout 
*channel_layout, enum AVChannelOrde
 return AVERROR(ENOSYS);
 lossy = has_channel_names(channel_layout);
 if (!lossy || allow_lossy) {
+void *opaque = channel_layout->opaque;
 av_channel_layout_uninit(channel_layout);
 av_channel_layout_from_mask(channel_layout, mask);
+channel_layout->opaque = opaque;
 return lossy;
 }
 }
@@ -925,6 +929,7 @@ int av_channel_layout_retype(AVChannelLayout 
*channel_layout, enum AVChannelOrde
 case AV_CHANNEL_ORDER_CUSTOM: {
 AVChannelLayout custom = { 0 };
 int ret = av_channel_layout_custom_init(, 
channel_layout->nb_channels);
+void *opaque = channel_layout->opaque;
 if (ret < 0)
 return ret;
 if (channel_layout->order != AV_CHANNEL_ORDER_UNSPEC)
@@ -932,6 +937,7 @@ int av_channel_layout_retype(AVChannelLayout 
*channel_layout, enum AVChannelOrde
 custom.u.map[i].id = 
av_channel_layout_channel_from_index(channel_layout, i);
 av_channel_layout_uninit(channel_layout);
 *channel_layout = custom;
+channel_layout->opaque = opaque;
 return 0;
 }
 case AV_CHANNEL_ORDER_AMBISONIC:
@@ -946,10 +952,12 @@ int av_channel_layout_retype(AVChannelLayout 
*channel_layout, enum AVChannelOrde
 return AVERROR(ENOSYS);
 lossy = has_channel_names(channel_layout);
 if (!lossy || allow_lossy) {
+void *opaque = channel_layout->opaque;
 av_channel_layout_uninit(channel_layout);
 channel_layout->order   = AV_CHANNEL_ORDER_AMBISONIC;
 channel_layout->nb_channels = nb_channels;
 channel_layout->u.mask  = mask;
+channel_layout->opaque  = opaque;
 return lossy;
 }
 }
-- 
2.44.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 5/5] avutil/frame: Use av_realloc_array(), improve overflow check

2024-03-22 Thread Andreas Rheinhardt
Also use sizeof of the proper type, namely sizeof(**sd)
and not sizeof(*sd).

Signed-off-by: Andreas Rheinhardt 
---
 libavutil/frame.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 7dd37e5490..d7a32cdc92 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -721,10 +721,11 @@ static AVFrameSideData 
*add_side_data_from_buf(AVFrameSideData ***sd,
 if (!buf)
 return NULL;
 
-if (*nb_sd > INT_MAX / sizeof(*sd) - 1)
+// *nb_sd + 1 needs to fit into an int and a size_t.
+if ((unsigned)*nb_sd >= FFMIN(INT_MAX, SIZE_MAX))
 return NULL;
 
-tmp = av_realloc(*sd, (*nb_sd + 1) * sizeof(*sd));
+tmp = av_realloc_array(*sd, sizeof(**sd), *nb_sd + 1);
 if (!tmp)
 return NULL;
 *sd = tmp;
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 4/4] avutil/frame: Rename av_frame_side_data_get and add wrapper for it

2024-03-22 Thread Andreas Rheinhardt
av_frame_side_data_get() has a const AVFrameSideData * const *sd
parameter; so calling it with an AVFramesSideData **sd like
AVCodecContext.decoded_side_data (or with a AVFramesSideData * const
*sd) is safe, but the conversion is not performed automatically
in C. All users of this function therefore resort to a cast.

This commit changes this: av_frame_side_data_get() is renamed
to av_frame_side_data_get_c(); furthermore, a static inline
wrapper for it name av_frame_side_data_get() is added
that accepts an AVFramesSideData * const * and converts this
to const AVFramesSideData * const * in a Wcast-qual safe way.

This also allows to remove the casts from the current users.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/libsvtav1.c |  6 ++
 libavcodec/libx264.c   |  6 ++
 libavcodec/libx265.c   |  6 ++
 libavutil/frame.c  |  8 
 libavutil/frame.h  | 19 +--
 5 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 6400a6507a..8fa42d590b 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -180,12 +180,10 @@ static void handle_side_data(AVCodecContext *avctx,
  EbSvtAv1EncConfiguration *param)
 {
 const AVFrameSideData *cll_sd =
-av_frame_side_data_get(
-(const AVFrameSideData **)avctx->decoded_side_data,
+av_frame_side_data_get(avctx->decoded_side_data,
 avctx->nb_decoded_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
 const AVFrameSideData *mdcv_sd =
-av_frame_side_data_get(
-(const AVFrameSideData **)avctx->decoded_side_data,
+av_frame_side_data_get(avctx->decoded_side_data,
 avctx->nb_decoded_side_data,
 AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
 
diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 3d195fa6b6..eadb20d2b3 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -1044,12 +1044,10 @@ static void handle_side_data(AVCodecContext *avctx, 
x264_param_t *params)
 {
 #if CONFIG_LIBX264_HDR10
 const AVFrameSideData *cll_sd =
-av_frame_side_data_get(
-(const AVFrameSideData **)avctx->decoded_side_data,
+av_frame_side_data_get(avctx->decoded_side_data,
 avctx->nb_decoded_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
 const AVFrameSideData *mdcv_sd =
-av_frame_side_data_get(
-(const AVFrameSideData **)avctx->decoded_side_data,
+av_frame_side_data_get(avctx->decoded_side_data,
 avctx->nb_decoded_side_data,
 AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
 
diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 45349a85b9..d3e74eaacf 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -211,12 +211,10 @@ static int handle_side_data(AVCodecContext *avctx, const 
x265_api *api,
 x265_param *params)
 {
 const AVFrameSideData *cll_sd =
-av_frame_side_data_get(
-(const AVFrameSideData **)avctx->decoded_side_data,
+av_frame_side_data_get(avctx->decoded_side_data,
 avctx->nb_decoded_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
 const AVFrameSideData *mdcv_sd =
-av_frame_side_data_get(
-(const AVFrameSideData **)avctx->decoded_side_data,
+av_frame_side_data_get(avctx->decoded_side_data,
 avctx->nb_decoded_side_data,
 AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
 
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 8598aa98a2..7dd37e5490 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -813,9 +813,9 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int 
*nb_sd,
 return 0;
 }
 
-const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData * const 
*sd,
-  const int nb_sd,
-  enum AVFrameSideDataType type)
+const AVFrameSideData *av_frame_side_data_get_c(const AVFrameSideData * const 
*sd,
+const int nb_sd,
+enum AVFrameSideDataType type)
 {
 for (int i = 0; i < nb_sd; i++) {
 if (sd[i]->type == type)
@@ -828,7 +828,7 @@ AVFrameSideData *av_frame_get_side_data(const AVFrame 
*frame,
 enum AVFrameSideDataType type)
 {
 return (AVFrameSideData *)av_frame_side_data_get(
-(const AVFrameSideData **)frame->side_data, frame->nb_side_data,
+frame->side_data, frame->nb_side_data,
 type
 );
 }
diff --git a/libavutil/frame.h b/libavutil/frame.h
index cf9ffe1ba9..373866c600 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1051,9 +1051,24 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int 
*nb_sd,
  * @return a pointer to the side data of a given type on success, NULL if there
  * is no side data with 

[FFmpeg-devel] [PATCH 3/4] avutil/frame: Constify av_frame_side_data_get()

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
Will bump minor and add an APIChanges entry for patches 3+4
on push.

 libavutil/frame.c | 2 +-
 libavutil/frame.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavutil/frame.c b/libavutil/frame.c
index 89db687d9c..8598aa98a2 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -813,7 +813,7 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int 
*nb_sd,
 return 0;
 }
 
-const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData **sd,
+const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData * const 
*sd,
   const int nb_sd,
   enum AVFrameSideDataType type)
 {
diff --git a/libavutil/frame.h b/libavutil/frame.h
index a7fc909ad8..cf9ffe1ba9 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -1051,7 +1051,7 @@ int av_frame_side_data_clone(AVFrameSideData ***sd, int 
*nb_sd,
  * @return a pointer to the side data of a given type on success, NULL if there
  * is no side data with such type in this set.
  */
-const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData **sd,
+const AVFrameSideData *av_frame_side_data_get(const AVFrameSideData * const 
*sd,
   const int nb_sd,
   enum AVFrameSideDataType type);
 
-- 
2.40.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] avcodec/libx265: Pass logctx as void*, not AVClass**

2024-03-22 Thread Andreas Rheinhardt
The latter need not be save, because av_log() expects
to get a pointer to an AVClass-enabled structure
and not only a fake object. If this function were actually
be called in the following way:

const AVClass *avcl = avctx->av_class;
handle_mdcv(, );

the AVClass's item_name would expect to point to an actual
AVCodecContext, potentially leading to a segfault.

Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/libx265.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index d7620878b8..45349a85b9 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -175,7 +175,7 @@ static av_cold int libx265_param_parse_int(AVCodecContext 
*avctx,
 return 0;
 }
 
-static int handle_mdcv(const AVClass **avcl, const x265_api *api,
+static int handle_mdcv(void *logctx, const x265_api *api,
x265_param *params,
const AVMasteringDisplayMetadata *mdcv)
 {
@@ -198,7 +198,7 @@ static int handle_mdcv(const AVClass **avcl, const x265_api 
*api,
 
 if (api->param_parse(params, "master-display", buf) ==
 X265_PARAM_BAD_VALUE) {
-av_log(avcl, AV_LOG_ERROR,
+av_log(logctx, AV_LOG_ERROR,
"Invalid value \"%s\" for param \"master-display\".\n",
buf);
 return AVERROR(EINVAL);
@@ -230,7 +230,7 @@ static int handle_side_data(AVCodecContext *avctx, const 
x265_api *api,
 
 if (mdcv_sd) {
 int ret = handle_mdcv(
->av_class, api, params,
+avctx, api, params,
 (AVMasteringDisplayMetadata *)mdcv_sd->data);
 if (ret < 0)
 return ret;
-- 
2.40.1

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

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


[FFmpeg-devel] [PATCH 1/2] avcodec/libx265: Don't use AVBPrint unnecessarily

2024-03-22 Thread Andreas Rheinhardt
This code uses the AVBPrint API for exactly one av_bprintf()
in a scenario in which a good upper bound for the needed
size of the buffer is available (with said upper bound being
much smaller than sizeof(AVBPrint)). So one can simply use
snprintf() instead. This also avoids the (always-false due to
the current size of the internal AVBPrint buffer) check for
whether the AVBPrint is complete.

Furthermore, the old code used AV_BPRINT_SIZE_AUTOMATIC
which implies that the AVBPrint buffer will never be
(re)allocated and yet it used av_bprint_finalize().
This has of course also been removed.

Signed-off-by: Andreas Rheinhardt 
---
This has actually been mentioned in my review of v3
of this patchset:
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20230817214858.184010-13-jee...@gmail.com/

 libavcodec/libx265.c | 31 ++-
 1 file changed, 6 insertions(+), 25 deletions(-)

diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
index 70ec6d3539..d7620878b8 100644
--- a/libavcodec/libx265.c
+++ b/libavcodec/libx265.c
@@ -28,17 +28,14 @@
 #include 
 
 #include "libavutil/avassert.h"
-#include "libavutil/bprint.h"
 #include "libavutil/buffer.h"
 #include "libavutil/internal.h"
-#include "libavutil/common.h"
 #include "libavutil/mastering_display_metadata.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "avcodec.h"
 #include "codec_internal.h"
 #include "encode.h"
-#include "internal.h"
 #include "packet_internal.h"
 #include "atsc_a53.h"
 #include "sei.h"
@@ -182,13 +179,10 @@ static int handle_mdcv(const AVClass **avcl, const 
x265_api *api,
x265_param *params,
const AVMasteringDisplayMetadata *mdcv)
 {
-int ret = AVERROR_BUG;
-AVBPrint buf;
-av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
+char buf[10 /* # of PRId64s */ * 20 /* max strlen for %PRId64 */ + 
sizeof("G(,)B(,)R(,)WP(,)L(,)")];
 
 // G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u)
-av_bprintf(
-,
+snprintf(buf, sizeof(buf),
 "G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")"
 "WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")",
 av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 5 
}),
@@ -202,28 +196,15 @@ static int handle_mdcv(const AVClass **avcl, const 
x265_api *api,
 av_rescale_q(1, mdcv->max_luminance,  (AVRational){ 1, 1 }),
 av_rescale_q(1, mdcv->min_luminance,  (AVRational){ 1, 1 }));
 
-if (!av_bprint_is_complete()) {
-av_log(avcl, AV_LOG_ERROR,
-  "MDCV string too long for its available space!\n");
-ret = AVERROR(ENOMEM);
-goto end;
-}
-
-if (api->param_parse(params, "master-display", buf.str) ==
+if (api->param_parse(params, "master-display", buf) ==
 X265_PARAM_BAD_VALUE) {
 av_log(avcl, AV_LOG_ERROR,
"Invalid value \"%s\" for param \"master-display\".\n",
-   buf.str);
-ret = AVERROR(EINVAL);
-goto end;
+   buf);
+return AVERROR(EINVAL);
 }
 
-ret = 0;
-
-end:
-av_bprint_finalize(, NULL);
-
-return ret;
+return 0;
 }
 
 static int handle_side_data(AVCodecContext *avctx, const x265_api *api,
-- 
2.40.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 1/4] fftools/ffmpeg_enc: strip DOVI config record for AV1

2024-03-22 Thread Niklas Haas
On Fri, 22 Mar 2024 10:41:13 +0100 Anton Khirnov  wrote:
> Quoting Niklas Haas (2024-03-21 13:11:32)
> > On Thu, 21 Mar 2024 11:16:57 +0100 Anton Khirnov  wrote:
> > > Quoting Niklas Haas (2024-03-19 20:16:39)
> > > > From: Niklas Haas 
> > > > 
> > > > AV1 streams don't use configuration records, so delete them when
> > > > encoding to AV1. Ideally this would be, as the comment suggests, handled
> > > > at the frame-level (and stripped by the av1 encoder), but given the
> > > > status quo of copying the packet-level data here directly, we should
> > > > definitely make an effort to strip it.
> > > > ---
> > > >  fftools/ffmpeg_enc.c | 25 ++---
> > > >  1 file changed, 14 insertions(+), 11 deletions(-)
> > > 
> > > I'm very much not a fan of having codec-specific code in ffmpeg CLI. It
> > > implies that every single caller must now be aware of this
> > > (undocumented?) interaction of this specific side data with this
> > > specific codec ID.
> > 
> > Note: This is an existing bug, not introduced by this series. This
> > series just makes it obvious. The status quo is that, beacuse of this
> > logic in ffmpeg_enc.c, we incorrectly forward dolby vision configuration
> > records when transcoding to AV1.
> 
> I know pretty much nothing about dolby vision, so could you please
> explain why precisely is this incorrect? And at what point in the
> transcoding chain does the side data become invalid?

Dolby Vision basically consists of two separate pieces of metadata:

1. The (per-stream) configuration struct, AV_PKT_DATA_DOVI_CONF
2. The per-frame structs (RPUs), AV_FRAME_DATA_DOVI_METADATA
 (ditto AV_FRAME_DATA_DOVI_RPU_BUFFER, which is the same)

A valid HEVC dolby vision file should contain both - the configuration
struct tells the decoder that hey, this file is dolby vision (and what
profile to expect, whether there's an enhancement layer, etc.). The RPUs
contain the actual DV-specific details of how each frame is encoded.

A valid AV1 dolby vision file, on the other hand, only uses the
per-frame RPUs, it does not have a configuration struct at all.

The current logic in ffmpeg_enc.c copies over all stream-level metadata,
including the DOVI_CONF struct, to the output file. This generates
a stream which is *marked* as being Dolby Vision, but in which none of
the frames actually contain DV RPUs. This *probably* violates some spec
somewhere, and at the very least is not desirable behavior. (And for
AV1, the configuration struct's presence is definitely a no-go)

Basically, we want to handle all of these scenarios:

1. When transcoding DV HEVC (profile 8) to DV AV1 (profile 10), we need
   to strip the configuration struct somewhere
2. When transcoding DV HEVC (profile 8) to HEVC, we need to strip the
   configuration struct IFF we're also stripping the per-frame RPUs
   (e.g. as a result of filtering).
3. When transcoding DV AV1 (profile 10) to HEVC, we need to *synthesize*
   a configuration struct containing the correct values.

I think the best way forward for now is:

1. Always strip the dovi configuration record when transcoding
2. Have the encoder generate (and attach to avctx.coded_side_data) the
   correct configuration record.

I will write a patch for #2.

> > Or, indeed, when transcoding to *any* format - since current FFmpeg also
> > does not propagate dolby vision RPUs, we generate broken files pretty
> > much always when transcoding dolby vision. So we definitely need to
> > strip the metadata from the stream muxer *somewhere*. Where else comes
> > to mind?
> > 
> > This also gets into another topic I wanted to touch on, which is that
> > the presence of dynamic dolby vision metadata currently hinders the
> > ability of libavfilter to treat the video primaries/gamma as
> > a negotiable colorspace property (the way it is done currently for YUV
> > matrix/range). This is because when interpreted as such, DV metadata
> > fundamentally changes the colorspace of the incoming video stream.
> > Ideally we would like some way to negotiate DV metadata on the
> > query_formats() level.
> > 
> > Ideally, we'd want something like AVCOL_SPC_DOLBYVISION, but we can't
> > easily introduce that without breaking ISO/IEC 23091 compatibility..
> 
> In principle it could be yet another negotiated field, could it not? You
> just added a bunch of those recently, what's another one?

Adding more fields to this negotiation process is a very obnoxious and
tedious process, with lots of boilerplate for each new field added.
Maybe we can come up with some better mechanism first?
___
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] [RFC] clarifying the TC conflict of interest rule

2024-03-22 Thread Gyan Doshi




On 2024-03-22 06:22 pm, Anton Khirnov wrote:

Michael,
following up on the previous discussion in this thread - if you,
personally, would like to vote for a different option than those
suggested so far, please propose one.
I am not going to add a large number of options that nobody actually
wants to vote for, as it imposes a burden on the voters who have to
carefully read and compare all the options.

Beyond that, I am planning to start the vote on Monday 2024-03-25.


Please do post the final text and options a day in advance.

Regards,
Gyan

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

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


[FFmpeg-devel] [PATCH] avcodec/libx264: Remove unused variable

2024-03-22 Thread Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt 
---
 libavcodec/libx264.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c
index 2653941eb9..3d195fa6b6 100644
--- a/libavcodec/libx264.c
+++ b/libavcodec/libx264.c
@@ -867,7 +867,6 @@ static int save_sei(AVCodecContext *avctx, x264_nal_t *nal)
 #if CONFIG_LIBX264_ENCODER
 static int set_avcc_extradata(AVCodecContext *avctx, x264_nal_t *nal, int nnal)
 {
-X264Context *x4 = avctx->priv_data;
 x264_nal_t *sps_nal = NULL;
 x264_nal_t *pps_nal = NULL;
 uint8_t *p, *sps;
-- 
2.40.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] [RFC] clarifying the TC conflict of interest rule

2024-03-22 Thread Nicolas George
Anton Khirnov (12024-03-22):
> I am not going to add a large number of options that nobody actually
> wants to vote for, as it imposes a burden on the voters who have to
> carefully read and compare all the options.

The one organizing the vote should not be one of the persons defending
an option.

Please let somebody else do it.

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

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


Re: [FFmpeg-devel] [RFC] clarifying the TC conflict of interest rule

2024-03-22 Thread Anton Khirnov
Michael,
following up on the previous discussion in this thread - if you,
personally, would like to vote for a different option than those
suggested so far, please propose one.
I am not going to add a large number of options that nobody actually
wants to vote for, as it imposes a burden on the voters who have to
carefully read and compare all the options.

Beyond that, I am planning to start the vote on Monday 2024-03-25.

-- 
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 v6] avcodec/libx264: fix extradata when config annexb=0

2024-03-22 Thread Zhao Zhili



> On Mar 22, 2024, at 18:36, Anton Khirnov  wrote:
> 
>> Subject: Re: [FFmpeg-devel] [PATCH v6] avcodec/libx264: fix extradata when 
>> config annexb=0
> 
> This could really use more explanation on what exactly is broken.

Added detailed description and pushed, thanks!

> 
> -- 
> Anton Khirnov
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

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

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


[FFmpeg-devel] [PATCH] tests: Remove fate-libx265-hdr10

2024-03-22 Thread Zhao Zhili
From: Zhao Zhili 

The test depends on the compile option of x265. It failed when
HIGH_BIT_DEPTH isn't enabled. It also failed when asan is enabled
because of memory issue inside of x265, which I don't think can
be fixed within FFmpeg.
---
 tests/fate/enc_external.mak  |  5 -
 tests/ref/fate/libx265-hdr10 | 16 
 2 files changed, 21 deletions(-)
 delete mode 100644 tests/ref/fate/libx265-hdr10

diff --git a/tests/fate/enc_external.mak b/tests/fate/enc_external.mak
index 30021efbcd..4095a4b51a 100644
--- a/tests/fate/enc_external.mak
+++ b/tests/fate/enc_external.mak
@@ -12,10 +12,5 @@ FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX264 HEVC, MOV, 
LIBX264_HDR10 HEVC_DEMUXER H
 fate-libx264-hdr10: CMD = enc_external 
$(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \
 mp4 "-c:v libx264" "-show_frames -show_entries frame=side_data_list -of 
flat"
 
-# test for x265 MDCV and CLL passthrough during encoding
-FATE_ENC_EXTERNAL-$(call ENCDEC, LIBX265 HEVC, MOV, HEVC_DEMUXER) += 
fate-libx265-hdr10
-fate-libx265-hdr10: CMD = enc_external 
$(TARGET_SAMPLES)/hevc/hdr10_plus_h265_sample.hevc \
-mp4 "-c:v libx265" "-show_frames -show_entries frame=side_data_list -of 
flat"
-
 FATE_SAMPLES_FFMPEG_FFPROBE += $(FATE_ENC_EXTERNAL-yes)
 fate-enc-external: $(FATE_ENC_EXTERNAL-yes)
diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10
deleted file mode 100644
index 571c837cac..00
--- a/tests/ref/fate/libx265-hdr10
+++ /dev/null
@@ -1,16 +0,0 @@
-frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data 
Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data 
Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display 
metadata"
-frames.frame.0.side_data_list.side_data.2.red_x="13250/5"
-frames.frame.0.side_data_list.side_data.2.red_y="34500/5"
-frames.frame.0.side_data_list.side_data.2.green_x="7500/5"
-frames.frame.0.side_data_list.side_data.2.green_y="3000/5"
-frames.frame.0.side_data_list.side_data.2.blue_x="34000/5"
-frames.frame.0.side_data_list.side_data.2.blue_y="16000/5"
-frames.frame.0.side_data_list.side_data.2.white_point_x="15635/5"
-frames.frame.0.side_data_list.side_data.2.white_point_y="16450/5"
-frames.frame.0.side_data_list.side_data.2.min_luminance="50/1"
-frames.frame.0.side_data_list.side_data.2.max_luminance="1000/1"
-frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level 
metadata"
-frames.frame.0.side_data_list.side_data.3.max_content=1000
-frames.frame.0.side_data_list.side_data.3.max_average=200
-- 
2.25.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 01/13] avformat/mp3enc: Improve query_codec

2024-03-22 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Signal that anything except MP3 and the ID3V2 attached pic types
> are forbidden.
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavformat/mp3enc.c | 6 +-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/mp3enc.c b/libavformat/mp3enc.c
> index cb250a46ca..4a02a45069 100644
> --- a/libavformat/mp3enc.c
> +++ b/libavformat/mp3enc.c
> @@ -495,12 +495,16 @@ static int mp3_write_trailer(struct AVFormatContext *s)
>  static int query_codec(enum AVCodecID id, int std_compliance)
>  {
>  const CodecMime *cm= ff_id3v2_mime_tags;
> +
> +if (id == AV_CODEC_ID_MP3)
> +return 1;
> +
>  while(cm->id != AV_CODEC_ID_NONE) {
>  if(id == cm->id)
>  return MKTAG('A', 'P', 'I', 'C');
>  cm++;
>  }
> -return -1;
> +return 0;
>  }
>  
>  static const AVOption options[] = {

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 v10 14/14] avcodec/libx265: add support for writing out CLL and MDCV

2024-03-22 Thread Zhao Zhili


> On Mar 19, 2024, at 05:31, Jan Ekström  wrote:
> 
> The newer of these two are the separate integers for content light
> level, introduced in 3952bf3e98c76c31594529a3fe34e056d3e3e2ea ,
> with X265_BUILD 75. As we already require X265_BUILD of at least
> 89, no further conditions are required.

The fate test not only depends on the version of x265, but also depends on
the compile option of x265. The test failed when HIGH_BIT_DEPTH isn’t enabled.
It also failed when asan is enabled because of memory issue inside of x265.

> ---
> libavcodec/libx265.c | 89 
> tests/fate/enc_external.mak  |  5 ++
> tests/ref/fate/libx265-hdr10 | 16 +++
> 3 files changed, 110 insertions(+)
> create mode 100644 tests/ref/fate/libx265-hdr10
> 
> diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c
> index 92183b9ca2..70ec6d3539 100644
> --- a/libavcodec/libx265.c
> +++ b/libavcodec/libx265.c
> @@ -28,9 +28,11 @@
> #include 
> 
> #include "libavutil/avassert.h"
> +#include "libavutil/bprint.h"
> #include "libavutil/buffer.h"
> #include "libavutil/internal.h"
> #include "libavutil/common.h"
> +#include "libavutil/mastering_display_metadata.h"
> #include "libavutil/opt.h"
> #include "libavutil/pixdesc.h"
> #include "avcodec.h"
> @@ -176,6 +178,86 @@ static av_cold int 
> libx265_param_parse_int(AVCodecContext *avctx,
> return 0;
> }
> 
> +static int handle_mdcv(const AVClass **avcl, const x265_api *api,
> +   x265_param *params,
> +   const AVMasteringDisplayMetadata *mdcv)
> +{
> +int ret = AVERROR_BUG;
> +AVBPrint buf;
> +av_bprint_init(, 0, AV_BPRINT_SIZE_AUTOMATIC);
> +
> +// G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u)
> +av_bprintf(
> +,
> +"G(%"PRId64",%"PRId64")B(%"PRId64",%"PRId64")R(%"PRId64",%"PRId64")"
> +"WP(%"PRId64",%"PRId64")L(%"PRId64",%"PRId64")",
> +av_rescale_q(1, mdcv->display_primaries[1][0], (AVRational){ 1, 
> 5 }),
> +av_rescale_q(1, mdcv->display_primaries[1][1], (AVRational){ 1, 
> 5 }),
> +av_rescale_q(1, mdcv->display_primaries[2][0], (AVRational){ 1, 
> 5 }),
> +av_rescale_q(1, mdcv->display_primaries[2][1], (AVRational){ 1, 
> 5 }),
> +av_rescale_q(1, mdcv->display_primaries[0][0], (AVRational){ 1, 
> 5 }),
> +av_rescale_q(1, mdcv->display_primaries[0][1], (AVRational){ 1, 
> 5 }),
> +av_rescale_q(1, mdcv->white_point[0], (AVRational){ 1, 5 }),
> +av_rescale_q(1, mdcv->white_point[1], (AVRational){ 1, 5 }),
> +av_rescale_q(1, mdcv->max_luminance,  (AVRational){ 1, 1 }),
> +av_rescale_q(1, mdcv->min_luminance,  (AVRational){ 1, 1 }));
> +
> +if (!av_bprint_is_complete()) {
> +av_log(avcl, AV_LOG_ERROR,
> +  "MDCV string too long for its available space!\n");
> +ret = AVERROR(ENOMEM);
> +goto end;
> +}
> +
> +if (api->param_parse(params, "master-display", buf.str) ==
> +X265_PARAM_BAD_VALUE) {
> +av_log(avcl, AV_LOG_ERROR,
> +   "Invalid value \"%s\" for param \"master-display\".\n",
> +   buf.str);
> +ret = AVERROR(EINVAL);
> +goto end;
> +}
> +
> +ret = 0;
> +
> +end:
> +av_bprint_finalize(, NULL);
> +
> +return ret;
> +}
> +
> +static int handle_side_data(AVCodecContext *avctx, const x265_api *api,
> +x265_param *params)
> +{
> +const AVFrameSideData *cll_sd =
> +av_frame_side_data_get(
> +(const AVFrameSideData **)avctx->decoded_side_data,
> +avctx->nb_decoded_side_data, AV_FRAME_DATA_CONTENT_LIGHT_LEVEL);
> +const AVFrameSideData *mdcv_sd =
> +av_frame_side_data_get(
> +(const AVFrameSideData **)avctx->decoded_side_data,
> +avctx->nb_decoded_side_data,
> +AV_FRAME_DATA_MASTERING_DISPLAY_METADATA);
> +
> +if (cll_sd) {
> +const AVContentLightMetadata *cll =
> +(AVContentLightMetadata *)cll_sd->data;
> +
> +params->maxCLL  = cll->MaxCLL;
> +params->maxFALL = cll->MaxFALL;
> +}
> +
> +if (mdcv_sd) {
> +int ret = handle_mdcv(
> +>av_class, api, params,
> +(AVMasteringDisplayMetadata *)mdcv_sd->data);
> +if (ret < 0)
> +return ret;
> +}
> +
> +return 0;
> +}
> +
> static av_cold int libx265_encode_init(AVCodecContext *avctx)
> {
> libx265Context *ctx = avctx->priv_data;
> @@ -336,6 +418,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
> return AVERROR_BUG;
> }
> 
> +ret = handle_side_data(avctx, ctx->api, ctx->params);
> +if (ret < 0) {
> +av_log(avctx, AV_LOG_ERROR, "Failed handling side data! (%s)\n",
> +   av_err2str(ret));
> +return ret;
> +}
> +
> if (ctx->crf >= 0) {
> char crf[6];
> 
> diff --git a/tests/fate/enc_external.mak 

Re: [FFmpeg-devel] [PATCH] doc/ffmpeg: mention how to pass options to loopback decoders

2024-03-22 Thread Anton Khirnov
Quoting Stefano Sabatini (2024-03-19 15:58:03)
> On date Thursday 2024-03-14 11:12:31 +0100, Anton Khirnov wrote:
> > ---
> >  doc/ffmpeg.texi | 14 ++
> >  1 file changed, 10 insertions(+), 4 deletions(-)
> > 
> > diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi
> > index a38ef834e1..801c083705 100644
> > --- a/doc/ffmpeg.texi
> > +++ b/doc/ffmpeg.texi
> > @@ -229,12 +229,16 @@ successive integers starting at zero. These indices 
> > should then be used to refer
> >  to loopback decoders in complex filtergraph link labels, as described in 
> > the
> >  documentation for @option{-filter_complex}.
> >  
> 
> > +Decoding AVOptions can be passed to loopback decoders by placing them 
> > before
> 
> AVOptions => options (rationale: we have only a few references to
> AVOptions and no direct ones in ffmpeg.texi, and there is no need to
> assume arbitrary AV/FF jargon).

This is how these options are described by ffmpeg -h full.

-- 
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 v6] avcodec/libx264: fix extradata when config annexb=0

2024-03-22 Thread Anton Khirnov
> Subject: Re: [FFmpeg-devel] [PATCH v6] avcodec/libx264: fix extradata when 
> config annexb=0

This could really use more explanation on what exactly is broken.

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

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


[FFmpeg-devel] [PATCH 2/2] lavf/movenc: small cleanup for style

2024-03-22 Thread Jun Zhao
From: Jun Zhao 

Small cleanup for style, indent, switch case lables.
BTW, the preferred way to ease multiple indentation levels in a
switch statement is to align the switch and its subordinate
case labels in the same column

Signed-off-by: Jun Zhao 
---
 libavformat/movenc.c | 71 ++--
 1 file changed, 35 insertions(+), 36 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 029b08c0b0..2f0a883013 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -668,10 +668,10 @@ static int mov_write_enda_tag(AVIOContext *pb)
 
 static int mov_write_enda_tag_be(AVIOContext *pb)
 {
-  avio_wb32(pb, 10);
-  ffio_wfourcc(pb, "enda");
-  avio_wb16(pb, 0); /* big endian */
-  return 10;
+avio_wb32(pb, 10);
+ffio_wfourcc(pb, "enda");
+avio_wb16(pb, 0); /* big endian */
+return 10;
 }
 
 static void put_descr(AVIOContext *pb, int tag, unsigned int size)
@@ -979,9 +979,9 @@ static int mov_write_wave_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra
 ffio_wfourcc(pb, "wave");
 
 if (track->par->codec_id != AV_CODEC_ID_QDM2) {
-avio_wb32(pb, 12);/* size */
-ffio_wfourcc(pb, "frma");
-avio_wl32(pb, track->tag);
+avio_wb32(pb, 12);/* size */
+ffio_wfourcc(pb, "frma");
+avio_wl32(pb, track->tag);
 }
 
 if (track->par->codec_id == AV_CODEC_ID_AAC) {
@@ -991,9 +991,9 @@ static int mov_write_wave_tag(AVFormatContext *s, 
AVIOContext *pb, MOVTrack *tra
 avio_wb32(pb, 0);
 mov_write_esds_tag(pb, track);
 } else if (mov_pcm_le_gt16(track->par->codec_id))  {
-  mov_write_enda_tag(pb);
+mov_write_enda_tag(pb);
 } else if (mov_pcm_be_gt16(track->par->codec_id))  {
-  mov_write_enda_tag_be(pb);
+mov_write_enda_tag_be(pb);
 } else if (track->par->codec_id == AV_CODEC_ID_AMR_NB) {
 mov_write_amr_tag(pb, track);
 } else if (track->par->codec_id == AV_CODEC_ID_AC3) {
@@ -1805,11 +1805,11 @@ static const struct {
 
 static int mov_get_dnxhd_codec_tag(AVFormatContext *s, MOVTrack *track)
 {
-  int tag = MKTAG('A','V','d','n');
-  if (track->par->profile != AV_PROFILE_UNKNOWN &&
-  track->par->profile != AV_PROFILE_DNXHD)
-  tag = MKTAG('A','V','d','h');
-  return tag;
+int tag = MKTAG('A','V','d','n');
+if (track->par->profile != AV_PROFILE_UNKNOWN &&
+track->par->profile != AV_PROFILE_DNXHD)
+tag = MKTAG('A','V','d','h');
+return tag;
 }
 
 static int mov_get_rawvideo_codec_tag(AVFormatContext *s, MOVTrack *track)
@@ -2997,18 +2997,18 @@ static int mov_write_gmhd_tag(AVIOContext *pb, MOVTrack 
*track)
  * bytes are copied verbatim.
  */
 if (track->tag != MKTAG('c','6','0','8')) {
-avio_wb32(pb, 0x2C);   /* size */
-ffio_wfourcc(pb, "text");
-avio_wb16(pb, 0x01);
-avio_wb32(pb, 0x00);
-avio_wb32(pb, 0x00);
-avio_wb32(pb, 0x00);
-avio_wb32(pb, 0x01);
-avio_wb32(pb, 0x00);
-avio_wb32(pb, 0x00);
-avio_wb32(pb, 0x00);
-avio_wb32(pb, 0x4000);
-avio_wb16(pb, 0x);
+avio_wb32(pb, 0x2C);   /* size */
+ffio_wfourcc(pb, "text");
+avio_wb16(pb, 0x01);
+avio_wb32(pb, 0x00);
+avio_wb32(pb, 0x00);
+avio_wb32(pb, 0x00);
+avio_wb32(pb, 0x01);
+avio_wb32(pb, 0x00);
+avio_wb32(pb, 0x00);
+avio_wb32(pb, 0x00);
+avio_wb32(pb, 0x4000);
+avio_wb16(pb, 0x);
 }
 
 if (track->par->codec_tag == MKTAG('t','m','c','d')) {
@@ -4853,16 +4853,15 @@ static int mov_write_isml_manifest(AVIOContext *pb, 
MOVMuxContext *mov, AVFormat
 param_write_int(pb, "DisplayHeight", track->par->height);
 } else {
 if (track->par->codec_id == AV_CODEC_ID_AAC) {
-switch (track->par->profile)
-{
-case AV_PROFILE_AAC_HE_V2:
-param_write_string(pb, "FourCC", "AACP");
-break;
-case AV_PROFILE_AAC_HE:
-param_write_string(pb, "FourCC", "AACH");
-break;
-default:
-param_write_string(pb, "FourCC", "AACL");
+switch (track->par->profile) {
+case AV_PROFILE_AAC_HE_V2:
+param_write_string(pb, "FourCC", "AACP");
+break;
+case AV_PROFILE_AAC_HE:
+param_write_string(pb, "FourCC", "AACH");
+break;
+default:
+param_write_string(pb, "FourCC", "AACL");
 }
 } else if (track->par->codec_id == AV_CODEC_ID_WMAPRO) {
 param_write_string(pb, "FourCC", "WMAP");
-- 
2.25.1

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

To unsubscribe, visit link 

[FFmpeg-devel] [PATCH 1/2] lavc/vvc_parser: small cleanup for style

2024-03-22 Thread Jun Zhao
From: Jun Zhao 

small cleanup for style, redundant semicolons, goto labels,
in FFmpeg, we put goto labels at brace level.

Signed-off-by: Jun Zhao 
---
 libavcodec/vvc_parser.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/vvc_parser.c b/libavcodec/vvc_parser.c
index c661595e1e..245cb214c9 100644
--- a/libavcodec/vvc_parser.c
+++ b/libavcodec/vvc_parser.c
@@ -173,7 +173,7 @@ static void set_parser_ctx(AVCodecParserContext *s, 
AVCodecContext *avctx,
 h266_sub_width_c[sps->sps_chroma_format_idc];
 s->height = pps->pps_pic_height_in_luma_samples -
 (pps->pps_conf_win_top_offset + pps->pps_conf_win_bottom_offset) *
-h266_sub_height_c[sps->sps_chroma_format_idc];;
+h266_sub_height_c[sps->sps_chroma_format_idc];
 
 avctx->profile = sps->profile_tier_level.general_profile_idc;
 avctx->level = sps->profile_tier_level.general_level_idc;
@@ -317,7 +317,7 @@ static int get_pu_info(PuInfo *info, const 
CodedBitstreamH266Context *h266,
 }
 info->pic_type = get_pict_type(pu);
 return 0;
-  error:
+error:
 memset(info, 0, sizeof(*info));
 return ret;
 }
@@ -329,7 +329,7 @@ static int append_au(AVPacket *pkt, const uint8_t *buf, int 
buf_size)
 if ((ret = av_grow_packet(pkt, buf_size)) < 0)
 goto end;
 memcpy(pkt->data + offset, buf, buf_size);
-  end:
+end:
 return ret;
 }
 
@@ -376,7 +376,7 @@ static int parse_nal_units(AVCodecParserContext *s, const 
uint8_t *buf,
 } else {
 ret = 1; //not a completed au
 }
-  end:
+end:
 ff_cbs_fragment_reset(pu);
 return ret;
 }
-- 
2.25.1

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

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


Re: [FFmpeg-devel] [PATCH] [v4] avcodec/vaapi_encode: add customized surface alignment

2024-03-22 Thread Anton Khirnov
Quoting Araz Iusubov (2024-03-21 18:02:19)
> diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
> index bac30debae..1eb56aff78 100644
> --- a/libavutil/hwcontext.h
> +++ b/libavutil/hwcontext.h
> @@ -465,6 +465,13 @@ typedef struct AVHWFramesConstraints {
>   */
>  int max_width;
>  int max_height;
> +
> +/**
> + * The frame width/height log2 alignment when available
> + * the lower 4 bits, width; another 4 bits, height
> + * (Zero is not applied, use the default value)

Why this unnecessary complication? Just use two ints, or two uint8_t's
if you really need to save space, though that also seems unncessary as
this struct is allocated rarely and usually does not live long.

-- 
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] [RFC] Channels

2024-03-22 Thread Anton Khirnov
Quoting Michael Niedermayer (2024-03-22 03:25:25)
> Hi all
> 
> we have code like
> st->codecpar->ch_layout.nb_channels = avio_rb32(pb);
> 
> and then somewhere there is some code that uses this by first allocating
> an array and that then hits OOM
> (it was this here:
> map = av_calloc(nb_channels, sizeof(*channel_layout->u.map));)
> 
> is anyone against adding a max_channels field to AVFormatContext  or something
> like that ?

I am.

> alternative is "wont fix" for all such cases,

IMO it's not, in general, a bug, so EWONTFIX is the appropriate
response. If the user does not want us to do arbitrarily large
allocation, they have the appropriate OS-level mechanisms (e.g. ulimit,
cgroups on Linux) or av_max_alloc().

-- 
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 v2] avformat: enable UDP IPv6 multicast interface selection

2024-03-22 Thread RS

This message has been marked as Public on 03/22/2024 10:16Z.
On Friday, March 22, 2024 10:55 AM Rémi Denis-Courmont wrote:

> So why are you arguing now?

Because I still belive that using localaddr is the better approach.
However, I will create and submit v3 of this patch and also create
another patch following your suggestions of either using a new param
or using scope_id.

Both will be available, so the maintainers can choose. I think that’s fair.

Lazar Ignjatović
Associate Software Engineer

Cubic Defense
cubic.com
___
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 09/13] avutil/film_grain_params: add av_film_grain_params_select()

2024-03-22 Thread Anton Khirnov
Quoting Niklas Haas (2024-03-18 17:54:17)
> +const AVFilmGrainParams *av_film_grain_params_select(const AVFrame *frame);

Could this benefit from a flags parameter for future extensions?

-- 
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 v2] avformat: enable UDP IPv6 multicast interface selection

2024-03-22 Thread Rémi Denis-Courmont


Le 22 mars 2024 11:31:28 GMT+02:00, "Ignjatović, Lazar (RS)" 
 a écrit :
>>> I've compared ffmpeg 5.1.2 against my MR on IPv6 multicast. Here are
>>> the
>>> results:
>>
>> I don't care. That does not make your MR any less counter-sensical.
>
>If I may cite Marton Balint

I am not answerable for something somebody else did.

And yes, IPv4 selects multicast interfaces by IPv4 address. That was a poor 
design choice in hindsight and IPv6 was instead designed to select multicast 
interfaces by local link ID.

You've made it clear up-thread that you know all of this, as well as you know 
how to specify link IDs (with % or an additional parameter). So why are you 
arguing now?
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] ffmpeg: pass first video AVFrame's side data to encoder

2024-03-22 Thread Anton Khirnov
Quoting Jan Ekström (2024-03-20 18:31:49)
> ffmpeg | branch: master | Jan Ekström  | Mon Jan  9 
> 20:52:30 2023 +0200| [8f4b173029aa9ecefb1370c954ef769664920d08] | committer: 
> Jan Ekström
> 
> ffmpeg: pass first video AVFrame's side data to encoder
> 
> This enables further configuration of output based on the results
> of input decoding and filtering in a similar manner as the color
> information.
> 
> > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8f4b173029aa9ecefb1370c954ef769664920d08
> ---
> 
>  fftools/ffmpeg_enc.c | 15 +++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
> index c9a12af139..f01be1c22f 100644
> --- a/fftools/ffmpeg_enc.c
> +++ b/fftools/ffmpeg_enc.c
> @@ -246,6 +246,21 @@ int enc_open(void *opaque, const AVFrame *frame)
>  enc_ctx->colorspace = frame->colorspace;
>  enc_ctx->chroma_sample_location = frame->chroma_location;
>  
> +for (int i = 0; i < frame->nb_side_data; i++) {
> +ret = av_frame_side_data_clone(
> +_ctx->decoded_side_data, _ctx->nb_decoded_side_data,
> +frame->side_data[i], AV_FRAME_SIDE_DATA_FLAG_UNIQUE);

I objected to this indiscriminate copying in a previous review.

There is no reason to expect side data to apply to the whole stream just
because it happens to apply to the first frame. For many side data types
it does not even make sense, as they are fundamentally per-frame.

-- 
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/4] fftools/ffmpeg_enc: strip DOVI config record for AV1

2024-03-22 Thread Anton Khirnov
Quoting Niklas Haas (2024-03-21 13:11:32)
> On Thu, 21 Mar 2024 11:16:57 +0100 Anton Khirnov  wrote:
> > Quoting Niklas Haas (2024-03-19 20:16:39)
> > > From: Niklas Haas 
> > > 
> > > AV1 streams don't use configuration records, so delete them when
> > > encoding to AV1. Ideally this would be, as the comment suggests, handled
> > > at the frame-level (and stripped by the av1 encoder), but given the
> > > status quo of copying the packet-level data here directly, we should
> > > definitely make an effort to strip it.
> > > ---
> > >  fftools/ffmpeg_enc.c | 25 ++---
> > >  1 file changed, 14 insertions(+), 11 deletions(-)
> > 
> > I'm very much not a fan of having codec-specific code in ffmpeg CLI. It
> > implies that every single caller must now be aware of this
> > (undocumented?) interaction of this specific side data with this
> > specific codec ID.
> 
> Note: This is an existing bug, not introduced by this series. This
> series just makes it obvious. The status quo is that, beacuse of this
> logic in ffmpeg_enc.c, we incorrectly forward dolby vision configuration
> records when transcoding to AV1.

I know pretty much nothing about dolby vision, so could you please
explain why precisely is this incorrect? And at what point in the
transcoding chain does the side data become invalid?

> Or, indeed, when transcoding to *any* format - since current FFmpeg also
> does not propagate dolby vision RPUs, we generate broken files pretty
> much always when transcoding dolby vision. So we definitely need to
> strip the metadata from the stream muxer *somewhere*. Where else comes
> to mind?
> 
> This also gets into another topic I wanted to touch on, which is that
> the presence of dynamic dolby vision metadata currently hinders the
> ability of libavfilter to treat the video primaries/gamma as
> a negotiable colorspace property (the way it is done currently for YUV
> matrix/range). This is because when interpreted as such, DV metadata
> fundamentally changes the colorspace of the incoming video stream.
> Ideally we would like some way to negotiate DV metadata on the
> query_formats() level.
> 
> Ideally, we'd want something like AVCOL_SPC_DOLBYVISION, but we can't
> easily introduce that without breaking ISO/IEC 23091 compatibility..

In principle it could be yet another negotiated field, could it not? You
just added a bunch of those recently, what's another one?

-- 
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 v2] avformat: enable UDP IPv6 multicast interface selection

2024-03-22 Thread RS
>> I've compared ffmpeg 5.1.2 against my MR on IPv6 multicast. Here are
>> the
>> results:
>
> I don't care. That does not make your MR any less counter-sensical.

If I may cite Marton Balint
```
d3bda871f033be4825ecb69d444b3396bf2a2eb7
avformat/udp: specify the local address for some source filtered multicast joins

We already use localaddr for the multicast joins without source filters, so we
should use them for source filters as well. This patch only fixes the
IP_ADD_SOURCE_MEMBERSHIP and the IP_BLOCK_SOURCE case.

Unless we do this, the kernel automatically selects an interface based on the
source address, and that interface might be different from the one set in
localaddr. For blocked sources this even casues EINVAL because we joined the
multicast group on a different interface.

Signed-off-by: Marton Balint 
---
 ...
//TODO: Interface index should be looked up from local_addr
...
```

And another commit
```
ab0812c1a8925a95315354b88b41256faad5faa8
avformat/udp: always use IP_ADD_SOURCE_MEMBERSHIP for subscribing to an UDP 
multicast source group in IPv4

That alone supports specifying the interface based on its address. Getting the
interface index from the local address seems quite a bit of work in a platform
independent way...

Obviously for IPv6 we still always use MCAST_JOIN_SOURCE_GROUP.

As a side effect this also fixes ticket #7459.

Signed-off-by: Marton Balint 
```

From this I understand that the intention is to still use localaddr parameter
with the same semantics as with IPv4

> If you could infer the scope ID from the IPv6 address, there wouldn't be a
> scope ID field in the socket address in the first place. Is it that hard to
> understand?

Well, it's not that simple. Here I have to cite ipv6(7) — Linux manual page
```
   sin6_scope_id
   is an ID depending on the scope of the address.  It is new in
   Linux 2.4.  Linux supports it only for link-local addresses, in
   that case sin6_scope_id contains the interface index (see
   netdevice(7))
```

> That "problem" was solved before FFmpeg existed by adding a separate parameter
> (ping6) or prepending the interface name after a percent sign (glibc).

And this is the closest you've got to providing an alternate solution to the 
proposed.
Which is adding another parameter, or relying on % for every type of multicast.

> If you tests show anything, it's that LL addressing is not intended for 
> application protocols.

And just to clarify
FF11::1%eth0 is an interface-local multicast, thus supported
FF12::1%eth0 is a link-local multicast, thus supported

All other multicast scopes are not supported by Linux in respect to %scope.

If we choose to support ff15::1%eth0 for example, we are introducing something 
that
is not normally supported on Linux, potentially creating confusion among users.
Interface parameter seems like a better option than the %scope for everything.

Can someone else agree with this?

If this is, in fact, the preferred way, then okay. I will propose the v3 of the 
patch
done this way. Still, I prefer keeping the IPv4 semantics for v6.

Lazar Ignjatović
Associate Software Engineer

Cubic Defense
cubic.com

This message has been marked as Public on 03/22/2024 09:31Z.
___
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] configure: Explicitly check for static_assert

2024-03-22 Thread Martin Storsjö

On Fri, 22 Mar 2024, Andreas Rheinhardt wrote:


Martin Storsjö:


Both patches seem to work fine with MSVC 19.27 - I vaguely prefer the v2
version, which is simpler.


But to me, we could also just revert the change to
libavcodec/ccaption_dec.c, and declare that we require MSVC 19.28
instead. MSVC 19.27, when executed with -std:c11 without -nologo, it
prints this:

    /std:c11 is a preview implementation of the ISO C11 standard, and
    we're eager to hear about bugs and suggestions for improvements.
    However, note that these features are provided as-is without support.

And I don't have any specific reasons for wanting to use this compiler -
I just tested the lowest version that was supposed to be supported
earlier and noted that it had broken recently. So to me, reverting to
requiring _Static_assert would be quite ok as well.



We can actually do both: Test for static_assert and for _Static_assert
(to exclude MSVC 19.27; is 19.28 still supposed to be a preview
implementation?).


19.28 no longer has that preview implementation banner, so from there on, 
it should be fine.



The reason I prefer static_assert in the codebase is that _Static_assert
is actually deprecated with C23 (although I don't think it will be
removed any time).


Ah, I see. Right, with that in mind, unifying usage to static_assert 
sounds good.


No strong opinion either way about the configure checks still (or whether 
we should require _Static_assert to be supported), except that strictly 
requiring static_assert seems less kludgy than trying to define it 
ourselves.


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

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


Re: [FFmpeg-devel] [PATCH 1/7] lavc/vp9dsp: R-V mc copy_avg

2024-03-22 Thread flow gg
It might be a bit inconvenient to find the patches related to vp8, vp9 that
were sent earlier. Here, I've placed them in a zip file in this reply

flow gg  于2024年3月22日周五 14:03写道:

> (This should be used after applying these patches)
>
> ```
> [FFmpeg-devel] [PATCH 1/4] lavc/vp9dsp: R-V V ipred dc
> 1-4
> ```
>
<>
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 7/7] lavc/vp9dsp: R-V V mc tap hv

2024-03-22 Thread flow gg

From 5d29de366bab4736b1e05e2167d976d344dd8c44 Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 23:21:18 +0800
Subject: [PATCH 7/7] lavc/vp9dsp: R-V V mc tap hv

C908:
vp9_avg_8tap_smooth_4hv_8bpp_c: 32.2
vp9_avg_8tap_smooth_4hv_8bpp_rvv_i64: 15.2
vp9_avg_8tap_smooth_8hv_8bpp_c: 98.5
vp9_avg_8tap_smooth_8hv_8bpp_rvv_i64: 23.5
vp9_avg_8tap_smooth_16hv_8bpp_c: 355.5
vp9_avg_8tap_smooth_16hv_8bpp_rvv_i64: 46.2
vp9_avg_8tap_smooth_32hv_8bpp_c: 1270.7
vp9_avg_8tap_smooth_32hv_8bpp_rvv_i64: 133.2
vp9_avg_8tap_smooth_64hv_8bpp_c: 4936.5
vp9_avg_8tap_smooth_64hv_8bpp_rvv_i64: 521.7
vp9_put_8tap_smooth_4hv_8bpp_c: 30.2
vp9_put_8tap_smooth_4hv_8bpp_rvv_i64: 14.2
vp9_put_8tap_smooth_8hv_8bpp_c: 91.5
vp9_put_8tap_smooth_8hv_8bpp_rvv_i64: 22.7
vp9_put_8tap_smooth_16hv_8bpp_c: 330.0
vp9_put_8tap_smooth_16hv_8bpp_rvv_i64: 45.0
vp9_put_8tap_smooth_32hv_8bpp_c: 1296.5
vp9_put_8tap_smooth_32hv_8bpp_rvv_i64: 131.0
vp9_put_8tap_smooth_64hv_8bpp_c: 4497.7
vp9_put_8tap_smooth_64hv_8bpp_rvv_i64: 513.2
---
 libavcodec/riscv/vp9_mc_rvv.S  | 79 ++
 libavcodec/riscv/vp9dsp_init.c |  3 +-
 2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/libavcodec/riscv/vp9_mc_rvv.S b/libavcodec/riscv/vp9_mc_rvv.S
index 1fad17266d..0b054db522 100644
--- a/libavcodec/riscv/vp9_mc_rvv.S
+++ b/libavcodec/riscv/vp9_mc_rvv.S
@@ -445,12 +445,90 @@ subpel_filters_smooth:
 ret
 .endm
 
+.macro epel_hv_once len name do
+sub a2, a2, a3
+sub a2, a2, a3
+sub a2, a2, a3
+.irp n 0 2 4 6 8 10 12 14
+epel_load_inc   v\n \len put \name h 1 t
+.endr
+addia4, a4, -1
+1:
+addia4, a4, -1
+epel_load   v30 \len \do \name v 0 s
+vse8.v  v30, (a0)
+vmv.v.v v0, v2
+vmv.v.v v2, v4
+vmv.v.v v4, v6
+vmv.v.v v6, v8
+vmv.v.v v8, v10
+vmv.v.v v10, v12
+vmv.v.v v12, v14
+epel_load   v14 \len put \name h 1 t
+add a2, a2, a3
+add a0, a0, a1
+bneza4, 1b
+epel_load   v30 \len \do \name v 0 s
+vse8.v  v30, (a0)
+.endm
+
+.macro epel_hv do name len
+addisp, sp, -64
+.irp n 0,1,2,3,4,5,6,7
+sd  s\n, \n\()<<3(sp)
+.endr
+.ifc \len,64
+addisp, sp, -48
+.irp n 0,1,2,3,4,5
+sd  a\n, \n\()<<3(sp)
+.endr
+.endif
+.ifc \do,avg
+csrwi   vxrm, 0
+.endif
+epel_filter \name h t
+epel_filter \name v s
+.ifc \len,4
+vsetivlizero, 4, e8, mf4, ta, ma
+.elseif \len == 8
+vsetivlizero, 8, e8, mf2, ta, ma
+.elseif \len == 16
+vsetivlizero, 16, e8, m1, ta, ma
+.else
+li  a6, 32
+vsetvli zero, a6, e8, m2, ta, ma
+.endif
+epel_hv_once\len \name \do
+.ifc \len,64
+.irp n 0,1,2,3,4,5
+ld  a\n, \n\()<<3(sp)
+.endr
+addisp, sp, 48
+addia0, a0, 32
+addia2, a2, 32
+epel_filter \name h t
+epel_hv_once\len \name \do
+.endif
+.irp n 0,1,2,3,4,5,6,7
+ld  s\n, \n\()<<3(sp)
+.endr
+addisp, sp, 64
+
+ret
+.endm
+
 .macro gen_epel len do name type
 func ff_\do\()_8tap_\name\()_\len\()\type\()_rvv, zve32x
 epel \len \do \name \type
 endfunc
 .endm
 
+.macro gen_epelhv len name do
+func ff_\do\()_8tap_\name\()_\len\()hv_rvv, zve32x
+epel_hv \do \name \len
+endfunc
+.endm
+
 .irp len 64, 32, 16, 8, 4
 func ff_avg\len\()_rvv, zve32x
 copy_avg \len avg
@@ -480,6 +558,7 @@ endfunc
 .irp type h v
 gen_epel \len \do \name \type
 .endr
+gen_epelhv \len \name \do
 .endr
 .endr
 .endr
diff --git a/libavcodec/riscv/vp9dsp_init.c b/libavcodec/riscv/vp9dsp_init.c
index da09918796..d27f5e7b85 100644
--- a/libavcodec/riscv/vp9dsp_init.c
+++ b/libavcodec/riscv/vp9dsp_init.c
@@ -126,7 +126,8 @@ static av_cold void vp9dsp_mc_init_rvv(VP9DSPContext *dsp, int bpp)
 
 #define init_subpel3(idx, type) \
 init_subpel2(idx, 1, 0, h, type);   \
-init_subpel2(idx, 0, 1, v, type)
+init_subpel2(idx, 0, 1, v, type);   \
+init_subpel2(idx, 1, 1, hv, type)
 
 init_subpel3(0, put);
 init_subpel3(1, avg);
-- 
2.44.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 6/7] lavc/vp9dsp: R-V V mc bilin hv

2024-03-22 Thread flow gg

From 5df2835fd182378b78530e001669c65f3638946d Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 23:14:10 +0800
Subject: [PATCH 6/7] lavc/vp9dsp: R-V V mc bilin hv

C908:
vp9_avg_bilin_4hv_8bpp_c: 10.7
vp9_avg_bilin_4hv_8bpp_rvv_i64: 4.5
vp9_avg_bilin_8hv_8bpp_c: 38.7
vp9_avg_bilin_8hv_8bpp_rvv_i64: 8.2
vp9_avg_bilin_16hv_8bpp_c: 147.2
vp9_avg_bilin_16hv_8bpp_rvv_i64: 32.2
vp9_avg_bilin_32hv_8bpp_c: 590.7
vp9_avg_bilin_32hv_8bpp_rvv_i64: 47.5
vp9_avg_bilin_64hv_8bpp_c: 2323.7
vp9_avg_bilin_64hv_8bpp_rvv_i64: 153.5
vp9_put_bilin_4hv_8bpp_c: 10.0
vp9_put_bilin_4hv_8bpp_rvv_i64: 3.7
vp9_put_bilin_8hv_8bpp_c: 35.2
vp9_put_bilin_8hv_8bpp_rvv_i64: 7.2
vp9_put_bilin_16hv_8bpp_c: 133.7
vp9_put_bilin_16hv_8bpp_rvv_i64: 14.2
vp9_put_bilin_32hv_8bpp_c: 521.7
vp9_put_bilin_32hv_8bpp_rvv_i64: 43.0
vp9_put_bilin_64hv_8bpp_c: 2098.0
vp9_put_bilin_64hv_8bpp_rvv_i64: 144.5
---
 libavcodec/riscv/vp9_mc_rvv.S | 37 +++
 1 file changed, 37 insertions(+)

diff --git a/libavcodec/riscv/vp9_mc_rvv.S b/libavcodec/riscv/vp9_mc_rvv.S
index 2d4b56516f..1fad17266d 100644
--- a/libavcodec/riscv/vp9_mc_rvv.S
+++ b/libavcodec/riscv/vp9_mc_rvv.S
@@ -160,6 +160,37 @@
 ret
 .endm
 
+.macro bilin_hv len type
+.ifc \type,avg
+csrwi   vxrm, 0
+.endif
+neg t1, a5
+neg t2, a6
+li  t4, 8
+li  t5, 1
+bilin_h_loadv24, \len, put
+add a2, a2, a3
+1:
+addia4, a4, -1
+bilin_h_loadv4, \len, put
+vwmulu.vx   v16, v4, a6
+vwmaccsu.vx v16, t2, v24
+vwadd.wxv16, v16, t4
+vnsra.wiv16, v16, 4
+vadd.vv v0, v16, v24
+.ifc \type,avg
+vle8.v  v16, (a0)
+vaaddu.vv   v0, v0, v16
+.endif
+vse8.v  v0, (a0)
+vmv.v.v v24, v4
+add a2, a2, a3
+add a0, a0, a1
+bneza4, 1b
+
+ret
+.endm
+
 .irp len 64, 32, 16
 func ff_copy\len\()_rvv, zve32x
 copy_avg \len copy
@@ -437,6 +468,12 @@ endfunc
 func ff_avg_bilin_\len\()v_rvv, zve32x
 bilin_v \len avg
 endfunc
+func ff_put_bilin_\len\()hv_rvv, zve32x
+bilin_hv \len put
+endfunc
+func ff_avg_bilin_\len\()hv_rvv, zve32x
+bilin_hv \len avg
+endfunc
 
 .irp name regular sharp smooth
 .irp do put avg
-- 
2.44.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 5/7] lavc/vp9dsp: R-V V mc tap v

2024-03-22 Thread flow gg

From 94aacf6d1d49cc009669f89c91db71038a13285d Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 23:08:01 +0800
Subject: [PATCH 5/7] lavc/vp9dsp: R-V V mc tap v

C908:
vp9_avg_8tap_smooth_4v_8bpp_c: 13.7
vp9_avg_8tap_smooth_4v_8bpp_rvv_i64: 5.0
vp9_avg_8tap_smooth_8v_8bpp_c: 49.7
vp9_avg_8tap_smooth_8v_8bpp_rvv_i64: 9.2
vp9_avg_8tap_smooth_16v_8bpp_c: 191.5
vp9_avg_8tap_smooth_16v_8bpp_rvv_i64: 21.2
vp9_avg_8tap_smooth_32v_8bpp_c: 770.5
vp9_avg_8tap_smooth_32v_8bpp_rvv_i64: 66.0
vp9_avg_8tap_smooth_64v_8bpp_c: 3068.0
vp9_avg_8tap_smooth_64v_8bpp_rvv_i64: 262.5
vp9_put_8tap_smooth_4v_8bpp_c: 12.0
vp9_put_8tap_smooth_4v_8bpp_rvv_i64: 4.5
vp9_put_8tap_smooth_8v_8bpp_c: 43.7
vp9_put_8tap_smooth_8v_8bpp_rvv_i64: 8.5
vp9_put_8tap_smooth_16v_8bpp_c: 168.7
vp9_put_8tap_smooth_16v_8bpp_rvv_i64: 20.0
vp9_put_8tap_smooth_32v_8bpp_c: 681.5
vp9_put_8tap_smooth_32v_8bpp_rvv_i64: 63.7
vp9_put_8tap_smooth_64v_8bpp_c: 2692.7
vp9_put_8tap_smooth_64v_8bpp_rvv_i64: 253.5
---
 libavcodec/riscv/vp9_mc_rvv.S  | 32 +++-
 libavcodec/riscv/vp9dsp_init.c |  3 ++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/libavcodec/riscv/vp9_mc_rvv.S b/libavcodec/riscv/vp9_mc_rvv.S
index 9458a2e82b..2d4b56516f 100644
--- a/libavcodec/riscv/vp9_mc_rvv.S
+++ b/libavcodec/riscv/vp9_mc_rvv.S
@@ -221,7 +221,11 @@ subpel_filters_smooth:
 .macro epel_filter name type regtype
 lla \regtype\()2, subpel_filters_\name
 li  \regtype\()1, 8
+.ifc \type,v
+mul \regtype\()0, a6, \regtype\()1
+.elseif \type == h
 mul \regtype\()0, a5, \regtype\()1
+.endif
 add \regtype\()0, \regtype\()0, \regtype\()2
 .irp n 1,2,3,4,5,6
 lb  \regtype\n, \n(\regtype\()0)
@@ -238,6 +242,19 @@ subpel_filters_smooth:
 li  a5, 64
 .ifc \from_mem, 1
 vle8.v  v22, (a2)
+.ifc \type,v
+sub a2, a2, a3
+vle8.v  v20, (a2)
+add a2, a2, a3
+add a2, a2, a3
+vle8.v  v24, (a2)
+add a2, a2, a3
+vle8.v  v26, (a2)
+add a2, a2, a3
+vle8.v  v28, (a2)
+add a2, a2, a3
+vle8.v  v30, (a2)
+.elseif \type == h
 addia2, a2, -1
 vle8.v  v20, (a2)
 addia2, a2, 2
@@ -248,6 +265,7 @@ subpel_filters_smooth:
 vle8.v  v28, (a2)
 addia2, a2, 1
 vle8.v  v30, (a2)
+.endif
 
 .ifc \name,smooth
 vwmulu.vx   v16, v24, \regtype\()4
@@ -266,11 +284,23 @@ subpel_filters_smooth:
 vwmaccsu.vx v16, s7, v30
 .endif
 
+.ifc \type,v
+.rept 6
+sub a2, a2, a3
+.endr
+vle8.v  v28, (a2)
+sub a2, a2, a3
+vle8.v  v26, (a2)
+.rept 3
+add a2, a2, a3
+.endr
+.elseif \type == h
 addia2, a2, -6
 vle8.v  v28, (a2)
 addia2, a2, -1
 vle8.v  v26, (a2)
 addia2, a2, 3
+.endif
 
 .ifc \name,smooth
 vwmaccsu.vx v16, \regtype\()1, v28
@@ -410,7 +440,7 @@ endfunc
 
 .irp name regular sharp smooth
 .irp do put avg
-.irp type h
+.irp type h v
 gen_epel \len \do \name \type
 .endr
 .endr
diff --git a/libavcodec/riscv/vp9dsp_init.c b/libavcodec/riscv/vp9dsp_init.c
index 413b203e5f..da09918796 100644
--- a/libavcodec/riscv/vp9dsp_init.c
+++ b/libavcodec/riscv/vp9dsp_init.c
@@ -125,7 +125,8 @@ static av_cold void vp9dsp_mc_init_rvv(VP9DSPContext *dsp, int bpp)
 init_subpel1(4, idx, idxh, idxv,  4, dir, type)
 
 #define init_subpel3(idx, type) \
-init_subpel2(idx, 1, 0, h, type)
+init_subpel2(idx, 1, 0, h, type);   \
+init_subpel2(idx, 0, 1, v, type)
 
 init_subpel3(0, put);
 init_subpel3(1, avg);
-- 
2.44.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 4/7] lavc/vp9dsp: R-V V mc bilin v

2024-03-22 Thread flow gg

From eb004dcf5cc6a3c379cb6cb7b8592afa65626c5c Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 23:00:19 +0800
Subject: [PATCH 4/7] lavc/vp9dsp: R-V V mc bilin v

C908:
vp9_avg_bilin_4v_8bpp_c: 5.5
vp9_avg_bilin_4v_8bpp_rvv_i64: 2.2
vp9_avg_bilin_8v_8bpp_c: 20.7
vp9_avg_bilin_8v_8bpp_rvv_i64: 4.2
vp9_avg_bilin_16v_8bpp_c: 82.2
vp9_avg_bilin_16v_8bpp_rvv_i64: 9.0
vp9_avg_bilin_32v_8bpp_c: 342.5
vp9_avg_bilin_32v_8bpp_rvv_i64: 27.0
vp9_avg_bilin_64v_8bpp_c: 1319.2
vp9_avg_bilin_64v_8bpp_rvv_i64: 93.2
vp9_put_bilin_4v_8bpp_c: 4.7
vp9_put_bilin_4v_8bpp_rvv_i64: 1.7
vp9_put_bilin_8v_8bpp_c: 17.7
vp9_put_bilin_8v_8bpp_rvv_i64: 3.2
vp9_put_bilin_16v_8bpp_c: 69.2
vp9_put_bilin_16v_8bpp_rvv_i64: 7.5
vp9_put_bilin_32v_8bpp_c: 274.2
vp9_put_bilin_32v_8bpp_rvv_i64: 23.2
vp9_put_bilin_64v_8bpp_c: 1109.5
vp9_put_bilin_64v_8bpp_rvv_i64: 82.2
---
 libavcodec/riscv/vp9_mc_rvv.S | 49 +++
 1 file changed, 49 insertions(+)

diff --git a/libavcodec/riscv/vp9_mc_rvv.S b/libavcodec/riscv/vp9_mc_rvv.S
index eacc174bc4..9458a2e82b 100644
--- a/libavcodec/riscv/vp9_mc_rvv.S
+++ b/libavcodec/riscv/vp9_mc_rvv.S
@@ -117,6 +117,49 @@
 ret
 .endm
 
+.macro bilin_v len type
+.ifc \type,avg
+csrwi   vxrm, 0
+.endif
+.ifc \len,4
+vsetivlizero, 4, e8, mf4, ta, ma
+.elseif \len == 8
+vsetivlizero, 8, e8, mf2, ta, ma
+.elseif \len == 16
+vsetivlizero, 16, e8, m1, ta, ma
+.elseif \len == 32
+li  t0, 32
+vsetvli zero, t0, e8, m2, ta, ma
+.elseif \len == 64
+li  t0, 64
+vsetvli zero, t0, e8, m4, ta, ma
+.endif
+li  t4, 8
+neg t1, a6
+1:
+add t2, a2, a3
+addia4, a4, -1
+vle8.v  v0, (a2)
+vle8.v  v8, (t2)
+.ifc \type,avg
+vle8.v  v16, (a0)
+.endif
+vwmulu.vx   v24, v8, a6
+vwmaccsu.vx v24, t1, v0
+vwadd.wxv24, v24, t4
+vnsra.wiv24, v24, 4
+vadd.vv v0, v24, v0
+.ifc \type,avg
+vaaddu.vv   v0, v0, v16
+.endif
+vse8.v  v0, (a0)
+add a2, a2, a3
+add a0, a0, a1
+bneza4, 1b
+
+ret
+.endm
+
 .irp len 64, 32, 16
 func ff_copy\len\()_rvv, zve32x
 copy_avg \len copy
@@ -358,6 +401,12 @@ endfunc
 func ff_avg_bilin_\len\()h_rvv, zve32x
 bilin_h \len avg
 endfunc
+func ff_put_bilin_\len\()v_rvv, zve32x
+bilin_v \len put
+endfunc
+func ff_avg_bilin_\len\()v_rvv, zve32x
+bilin_v \len avg
+endfunc
 
 .irp name regular sharp smooth
 .irp do put avg
-- 
2.44.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 3/7] lavc/vp9dsp: R-V V mc tap h

2024-03-22 Thread flow gg
The order of some instructions appears imperfect because, when len==32, the
registers for operations like hv can only just suffice, making it difficult
to adjust.
It's possible to create a separate function for len<32, but it likely won't
have a significant impact, so this hasn't been done yet.
From d9044b400f5a161928a920f0399e5e0715f0c8e6 Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 22:53:59 +0800
Subject: [PATCH 3/7] lavc/vp9dsp: R-V V mc tap h

C908:
vp9_avg_8tap_smooth_4h_8bpp_c: 12.7
vp9_avg_8tap_smooth_4h_8bpp_rvv_i64: 5.0
vp9_avg_8tap_smooth_8h_8bpp_c: 48.5
vp9_avg_8tap_smooth_8h_8bpp_rvv_i64: 9.2
vp9_avg_8tap_smooth_16h_8bpp_c: 191.7
vp9_avg_8tap_smooth_16h_8bpp_rvv_i64: 21.0
vp9_avg_8tap_smooth_32h_8bpp_c: 780.0
vp9_avg_8tap_smooth_32h_8bpp_rvv_i64: 66.5
vp9_avg_8tap_smooth_64h_8bpp_c: 3123.7
vp9_avg_8tap_smooth_64h_8bpp_rvv_i64: 264.2
vp9_put_8tap_smooth_4h_8bpp_c: 11.0
vp9_put_8tap_smooth_4h_8bpp_rvv_i64: 4.2
vp9_put_8tap_smooth_8h_8bpp_c: 42.0
vp9_put_8tap_smooth_8h_8bpp_rvv_i64: 8.2
vp9_put_8tap_smooth_16h_8bpp_c: 165.5
vp9_put_8tap_smooth_16h_8bpp_rvv_i64: 19.7
vp9_put_8tap_smooth_32h_8bpp_c: 659.0
vp9_put_8tap_smooth_32h_8bpp_rvv_i64: 64.0
vp9_put_8tap_smooth_64h_8bpp_c: 2682.0
vp9_put_8tap_smooth_64h_8bpp_rvv_i64: 272.2
---
 libavcodec/riscv/vp9_mc_rvv.S  | 232 +
 libavcodec/riscv/vp9dsp_init.c |   8 +-
 2 files changed, 239 insertions(+), 1 deletion(-)

diff --git a/libavcodec/riscv/vp9_mc_rvv.S b/libavcodec/riscv/vp9_mc_rvv.S
index a97807633e..eacc174bc4 100644
--- a/libavcodec/riscv/vp9_mc_rvv.S
+++ b/libavcodec/riscv/vp9_mc_rvv.S
@@ -123,6 +123,230 @@ func ff_copy\len\()_rvv, zve32x
 endfunc
 .endr
 
+subpel_filters_regular:
+.byte  0,  0,   0, 128,   0,   0,  0,  0
+.byte  0,  1,  -5, 126,   8,  -3,  1,  0
+.byte -1,  3, -10, 122,  18,  -6,  2,  0
+.byte -1,  4, -13, 118,  27,  -9,  3, -1
+.byte -1,  4, -16, 112,  37, -11,  4, -1
+.byte -1,  5, -18, 105,  48, -14,  4, -1
+.byte -1,  5, -19,  97,  58, -16,  5, -1
+.byte -1,  6, -19,  88,  68, -18,  5, -1
+.byte -1,  6, -19,  78,  78, -19,  6, -1
+.byte -1,  5, -18,  68,  88, -19,  6, -1
+.byte -1,  5, -16,  58,  97, -19,  5, -1
+.byte -1,  4, -14,  48, 105, -18,  5, -1
+.byte -1,  4, -11,  37, 112, -16,  4, -1
+.byte -1,  3,  -9,  27, 118, -13,  4, -1
+.byte  0,  2,  -6,  18, 122, -10,  3, -1
+.byte  0,  1,  -3,   8, 126,  -5,  1,  0
+subpel_filters_sharp:
+.byte  0,  0,   0, 128,   0,   0,  0,  0
+.byte -1,  3,  -7, 127,   8,  -3,  1,  0
+.byte -2,  5, -13, 125,  17,  -6,  3, -1
+.byte -3,  7, -17, 121,  27, -10,  5, -2
+.byte -4,  9, -20, 115,  37, -13,  6, -2
+.byte -4, 10, -23, 108,  48, -16,  8, -3
+.byte -4, 10, -24, 100,  59, -19,  9, -3
+.byte -4, 11, -24,  90,  70, -21, 10, -4
+.byte -4, 11, -23,  80,  80, -23, 11, -4
+.byte -4, 10, -21,  70,  90, -24, 11, -4
+.byte -3,  9, -19,  59, 100, -24, 10, -4
+.byte -3,  8, -16,  48, 108, -23, 10, -4
+.byte -2,  6, -13,  37, 115, -20,  9, -4
+.byte -2,  5, -10,  27, 121, -17,  7, -3
+.byte -1,  3,  -6,  17, 125, -13,  5, -2
+.byte  0,  1,  -3,   8, 127,  -7,  3, -1
+subpel_filters_smooth:
+.byte  0,  0,   0, 128,   0,   0,  0,  0
+.byte -3, -1,  32,  64,  38,   1, -3,  0
+.byte -2, -2,  29,  63,  41,   2, -3,  0
+.byte -2, -2,  26,  63,  43,   4, -4,  0
+.byte -2, -3,  24,  62,  46,   5, -4,  0
+.byte -2, -3,  21,  60,  49,   7, -4,  0
+.byte -1, -4,  18,  59,  51,   9, -4,  0
+.byte -1, -4,  16,  57,  53,  12, -4, -1
+.byte -1, -4,  14,  55,  55,  14, -4, -1
+.byte -1, -4,  12,  53,  57,  16, -4, -1
+.byte  0, -4,   9,  51,  59,  18, -4, -1
+.byte  0, -4,   7,  49,  60,  21, -3, -2
+.byte  0, -4,   5,  46,  62,  24, -3, -2
+.byte  0, -4,   4,  43,  63,  26, -2, -2
+.byte  0, -3,   2,  41,  63,  29, -2, -2
+.byte  0, -3,   1,  38,  64,  32, -1, -3
+
+.macro epel_filter name type regtype
+lla \regtype\()2, subpel_filters_\name
+li  \regtype\()1, 8
+mul \regtype\()0, a5, \regtype\()1
+add \regtype\()0, \regtype\()0, \regtype\()2
+.irp n 1,2,3,4,5,6
+lb  \regtype\n, \n(\regtype\()0)
+.endr
+.ifc \regtype,t
+lb  a7, 7(\regtype\()0)
+.elseif \regtype == s
+lb  s7, 7(\regtype\()0)
+.endif
+lb  \regtype\()0, 0(\regtype\()0)
+.endm
+
+.macro epel_load dst len do name type from_mem regtype
+li  a5, 64
+.ifc \from_mem, 1
+vle8.v  v22, (a2)
+addia2, a2, -1
+vle8.v  v20, (a2)
+addia2, a2, 2
+vle8.v  

[FFmpeg-devel] [PATCH 2/7] lavc/vp9dsp: R-V V mc bilin h

2024-03-22 Thread flow gg

From 7ad03f4bc70e4c334d8e52dce2ea2b6f09a9a244 Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 22:11:26 +0800
Subject: [PATCH 2/7] lavc/vp9dsp: R-V V mc bilin h

C908:
vp9_avg_bilin_4h_8bpp_c: 5.5
vp9_avg_bilin_4h_8bpp_rvv_i64: 2.5
vp9_avg_bilin_8h_8bpp_c: 19.7
vp9_avg_bilin_8h_8bpp_rvv_i64: 5.0
vp9_avg_bilin_16h_8bpp_c: 78.2
vp9_avg_bilin_16h_8bpp_rvv_i64: 10.0
vp9_avg_bilin_32h_8bpp_c: 325.2
vp9_avg_bilin_32h_8bpp_rvv_i64: 28.5
vp9_avg_bilin_64h_8bpp_c: 1266.2
vp9_avg_bilin_64h_8bpp_rvv_i64: 115.0
vp9_put_bilin_4h_8bpp_c: 4.5
vp9_put_bilin_4h_8bpp_rvv_i64: 2.2
vp9_put_bilin_8h_8bpp_c: 16.7
vp9_put_bilin_8h_8bpp_rvv_i64: 4.2
vp9_put_bilin_16h_8bpp_c: 65.2
vp9_put_bilin_16h_8bpp_rvv_i64: 8.7
vp9_put_bilin_32h_8bpp_c: 273.5
vp9_put_bilin_32h_8bpp_rvv_i64: 26.7
vp9_put_bilin_64h_8bpp_c: 1041.0
vp9_put_bilin_64h_8bpp_rvv_i64: 87.2
---
 libavcodec/riscv/vp9_mc_rvv.S  | 73 ++
 libavcodec/riscv/vp9dsp_init.c | 17 
 2 files changed, 90 insertions(+)

diff --git a/libavcodec/riscv/vp9_mc_rvv.S b/libavcodec/riscv/vp9_mc_rvv.S
index ba9ec3431f..a97807633e 100644
--- a/libavcodec/riscv/vp9_mc_rvv.S
+++ b/libavcodec/riscv/vp9_mc_rvv.S
@@ -51,6 +51,72 @@
 ret
 .endm
 
+.macro bilin_h_load dst len type
+.ifc \len,4
+vsetivlizero, 5, e8, mf2, ta, ma
+.elseif \len == 8
+vsetivlizero, 9, e8, m1, ta, ma
+.elseif \len == 16
+vsetivlizero, 17, e8, m2, ta, ma
+.elseif \len == 32
+li  t0, 33
+vsetvli zero, t0, e8, m4, ta, ma
+.elseif \len == 64
+li  t0, 65
+vsetvli zero, t0, e8, m8, ta, ma
+.endif
+
+vle8.v  v8, (a2)
+vslide1down.vx  v0, v8, t5
+
+.ifc \len,4
+vsetivlizero, 4, e8, mf4, ta, ma
+.elseif \len == 8
+vsetivlizero, 8, e8, mf2, ta, ma
+.elseif \len == 16
+vsetivlizero, 16, e8, m1, ta, ma
+.elseif \len == 32
+li  t0, 32
+vsetvli zero, t0, e8, m2, ta, ma
+.elseif \len == 64
+li  t0, 64
+vsetvli zero, t0, e8, m4, ta, ma
+.endif
+
+vwmulu.vx   v16, v0, a5
+vwmaccsu.vx v16, t1, v8
+vwadd.wxv16, v16, t4
+vnsra.wiv16, v16, 4
+vadd.vv \dst, v16, v8
+
+.ifc \type,put
+vadd.vv \dst, v16, v8
+.elseif \type == avg
+vadd.vv v16, v16, v8
+vle8.v  \dst, (a0)
+vaaddu.vv   \dst, \dst, v16
+.endif
+
+.endm
+
+.macro bilin_h len type
+.ifc \type,avg
+csrwi   vxrm, 0
+.endif
+li  t4, 8
+li  t5, 1
+neg t1, a5
+1:
+addia4, a4, -1
+bilin_h_loadv0, \len, \type
+vse8.v  v0, (a0)
+add a2, a2, a3
+add a0, a0, a1
+bneza4, 1b
+
+ret
+.endm
+
 .irp len 64, 32, 16
 func ff_copy\len\()_rvv, zve32x
 copy_avg \len copy
@@ -61,4 +127,11 @@ endfunc
 func ff_avg\len\()_rvv, zve32x
 copy_avg \len avg
 endfunc
+
+func ff_put_bilin_\len\()h_rvv, zve32x
+bilin_h \len put
+endfunc
+func ff_avg_bilin_\len\()h_rvv, zve32x
+bilin_h \len avg
+endfunc
 .endr
diff --git a/libavcodec/riscv/vp9dsp_init.c b/libavcodec/riscv/vp9dsp_init.c
index c602c38bb2..d6d6fb52cc 100644
--- a/libavcodec/riscv/vp9dsp_init.c
+++ b/libavcodec/riscv/vp9dsp_init.c
@@ -106,6 +106,23 @@ static av_cold void vp9dsp_mc_init_rvv(VP9DSPContext *dsp, int bpp)
 #undef init_copy_avg
 #undef init_avg
 #undef init_fpel
+
+#define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type)  \
+dsp->mc[idx1][FILTER_BILINEAR][idx2][idxh][idxv] =   \
+ff_##type##_bilin_##sz##dir##_rvv;
+
+#define init_subpel2(idx, idxh, idxv, dir, type)  \
+init_subpel1(0, idx, idxh, idxv, 64, dir, type);  \
+init_subpel1(1, idx, idxh, idxv, 32, dir, type);  \
+init_subpel1(2, idx, idxh, idxv, 16, dir, type);  \
+init_subpel1(3, idx, idxh, idxv,  8, dir, type);  \
+init_subpel1(4, idx, idxh, idxv,  4, dir, type)
+
+#define init_subpel3(idx, type) \
+init_subpel2(idx, 1, 0, h, type)
+
+init_subpel3(0, put);
+init_subpel3(1, avg);
 }
 #endif
 #endif
-- 
2.44.0

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

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


[FFmpeg-devel] [PATCH 1/7] lavc/vp9dsp: R-V mc copy_avg

2024-03-22 Thread flow gg
(This should be used after applying these patches)

```
[FFmpeg-devel] [PATCH 1/4] lavc/vp9dsp: R-V V ipred dc
1-4
```
From ea81872215165ff859a0b5b2e003c5c678ea8ed0 Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 22:01:18 +0800
Subject: [PATCH 1/7] lavc/vp9dsp: R-V mc copy_avg

vp9_avg4_8bpp_c: 1.2
vp9_avg4_8bpp_rvv_i64: 1.0
vp9_avg8_8bpp_c: 3.7
vp9_avg8_8bpp_rvv_i64: 1.5
vp9_avg16_8bpp_c: 14.7
vp9_avg16_8bpp_rvv_i64: 3.5
vp9_avg32_8bpp_c: 57.7
vp9_avg32_8bpp_rvv_i64: 10.0
vp9_avg64_8bpp_c: 229.0
vp9_avg64_8bpp_rvv_i64: 31.7
vp9_put4_8bpp_c: 0.7
vp9_put4_8bpp_rvi: 0.2
vp9_put8_8bpp_c: 2.5
vp9_put8_8bpp_rvi: 0.5
vp9_put16_8bpp_c: 16.5
vp9_put16_8bpp_rvv_i64: 1.7
vp9_put32_8bpp_c: 37.2
vp9_put32_8bpp_rvv_i64: 5.7
vp9_put64_8bpp_c: 91.2
vp9_put64_8bpp_rvv_i64: 19.7
---
 libavcodec/riscv/Makefile  |  4 ++-
 libavcodec/riscv/vp9_mc_rvi.S  | 43 +++
 libavcodec/riscv/vp9_mc_rvv.S  | 64 ++
 libavcodec/riscv/vp9dsp_init.c | 47 +
 4 files changed, 157 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/riscv/vp9_mc_rvi.S
 create mode 100644 libavcodec/riscv/vp9_mc_rvv.S

diff --git a/libavcodec/riscv/Makefile b/libavcodec/riscv/Makefile
index c237e60800..dce1236b84 100644
--- a/libavcodec/riscv/Makefile
+++ b/libavcodec/riscv/Makefile
@@ -61,6 +61,8 @@ RVV-OBJS-$(CONFIG_VC1DSP) += riscv/vc1dsp_rvv.o
 OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_init.o
 RVV-OBJS-$(CONFIG_VP8DSP) += riscv/vp8dsp_rvv.o
 OBJS-$(CONFIG_VP9_DECODER) += riscv/vp9dsp_init.o
-RVV-OBJS-$(CONFIG_VP9_DECODER) += riscv/vp9_intra_rvv.o
+RV-OBJS-$(CONFIG_VP9_DECODER) += riscv/vp9_mc_rvi.o
+RVV-OBJS-$(CONFIG_VP9_DECODER) += riscv/vp9_intra_rvv.o \
+  riscv/vp9_mc_rvv.o
 OBJS-$(CONFIG_VORBIS_DECODER) += riscv/vorbisdsp_init.o
 RVV-OBJS-$(CONFIG_VORBIS_DECODER) += riscv/vorbisdsp_rvv.o
diff --git a/libavcodec/riscv/vp9_mc_rvi.S b/libavcodec/riscv/vp9_mc_rvi.S
new file mode 100644
index 00..03d8dbbbae
--- /dev/null
+++ b/libavcodec/riscv/vp9_mc_rvi.S
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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_copy8_rvi
+1:
+addi a4, a4, -1
+ld   t4, (a2)
+sd   t4, (a0)
+add  a2, a2, a3
+add  a0, a0, a1
+bnez a4, 1b
+ret
+endfunc
+
+func ff_copy4_rvi
+1:
+addi a4, a4, -1
+lw   t4, (a2)
+sw   t4, (a0)
+add  a2, a2, a3
+add  a0, a0, a1
+bnez a4, 1b
+ret
+endfunc
diff --git a/libavcodec/riscv/vp9_mc_rvv.S b/libavcodec/riscv/vp9_mc_rvv.S
new file mode 100644
index 00..ba9ec3431f
--- /dev/null
+++ b/libavcodec/riscv/vp9_mc_rvv.S
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU 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"
+
+.macro copy_avg len type
+.ifc \type,avg
+csrwi   vxrm, 0
+.endif
+.ifc \len,64
+li  t5, 64
+vsetvli t0, t5, e8, m4, ta, ma
+.elseif \len == 32
+li  t5, 32
+vsetvli t0, t5, e8, m2, ta, ma
+.elseif \len == 16
+vsetivlit0, 16, e8, m1, ta, ma
+.elseif \len == 8
+vsetivlit0, 8, e8, mf2, ta, ma
+.elseif \len == 4
+   

Re: [FFmpeg-devel] [PATCH 4/4] lavc/vp9dsp: R-V V ipred tm

2024-03-22 Thread flow gg
Because the previous patch was updated, so it was updated in this response

flow gg  于2024年3月3日周日 10:01写道:

> Due to the PATCH 1/4 update, updates are made here.
>
> flow gg  于2024年3月2日周六 15:42写道:
>
>>
>>
From 9561d35be25c330a0be3a371269289ce21f5ada3 Mon Sep 17 00:00:00 2001
From: sunyuechi 
Date: Thu, 21 Mar 2024 21:42:25 +0800
Subject: [PATCH 4/4] lavc/vp9dsp: R-V V ipred tm

C908:
vp9_tm_4x4_8bpp_c: 116.5
vp9_tm_4x4_8bpp_rvv_i32: 43.5
vp9_tm_8x8_8bpp_c: 416.2
vp9_tm_8x8_8bpp_rvv_i32: 86.0
vp9_tm_16x16_8bpp_c: 1665.5
vp9_tm_16x16_8bpp_rvv_i32: 187.2
vp9_tm_32x32_8bpp_c: 6974.2
vp9_tm_32x32_8bpp_rvv_i32: 625.7
---
 libavcodec/riscv/vp9_intra_rvv.S | 143 +++
 libavcodec/riscv/vp9dsp.h|   8 ++
 libavcodec/riscv/vp9dsp_init.c   |   4 +
 3 files changed, 155 insertions(+)

diff --git a/libavcodec/riscv/vp9_intra_rvv.S b/libavcodec/riscv/vp9_intra_rvv.S
index bf7f6d8692..81590e4f0f 100644
--- a/libavcodec/riscv/vp9_intra_rvv.S
+++ b/libavcodec/riscv/vp9_intra_rvv.S
@@ -213,3 +213,146 @@ func ff_h_8x8_rvv, zve32x
 
 ret
 endfunc
+
+.macro tm_sum dst, top, offset
+lbu  t3, \offset(a2)
+sub  t3, t3, a4
+vadd.vx  \dst, \top, t3
+.endm
+
+func ff_tm_32x32_rvv, zve32x
+lbu  a4, -1(a3)
+li   t5, 32
+
+.macro tm_sum32 n1,n2,n3,n4,n5,n6,n7,n8
+
+vsetvli  zero, t5, e16, m4, ta, ma
+vle8.v   v8, (a3)
+vzext.vf2v28, v8
+
+tm_sum   v0, v28, \n1
+tm_sum   v4, v28, \n2
+tm_sum   v8, v28, \n3
+tm_sum   v12, v28, \n4
+tm_sum   v16, v28, \n5
+tm_sum   v20, v28, \n6
+tm_sum   v24, v28, \n7
+tm_sum   v28, v28, \n8
+
+.irp n 0, 4, 8, 12, 16, 20, 24, 28
+vmax.vx  v\n, v\n, zero
+.endr
+
+vsetvli  zero, zero, e8, m2, ta, ma
+.irp n 0, 4, 8, 12, 16, 20, 24, 28
+vnclipu.wi   v\n, v\n, 0
+vse8.v   v\n, (a0)
+add  a0, a0, a1
+.endr
+
+.endm
+
+tm_sum32 31, 30, 29, 28, 27, 26, 25, 24
+tm_sum32 23, 22, 21, 20, 19, 18, 17, 16
+tm_sum32 15, 14, 13, 12, 11, 10, 9, 8
+tm_sum32 7, 6, 5, 4, 3, 2, 1, 0
+
+ret
+endfunc
+
+func ff_tm_16x16_rvv, zve32x
+vsetivli  zero, 16, e16, m2, ta, ma
+vle8.vv8, (a3)
+vzext.vf2 v30, v8
+lbu   a4, -1(a3)
+
+tm_sum   v0, v30, 15
+tm_sum   v2, v30, 14
+tm_sum   v4, v30, 13
+tm_sum   v6, v30, 12
+tm_sum   v8, v30, 11
+tm_sum   v10, v30, 10
+tm_sum   v12, v30, 9
+tm_sum   v14, v30, 8
+tm_sum   v16, v30, 7
+tm_sum   v18, v30, 6
+tm_sum   v20, v30, 5
+tm_sum   v22, v30, 4
+tm_sum   v24, v30, 3
+tm_sum   v26, v30, 2
+tm_sum   v28, v30, 1
+tm_sum   v30, v30, 0
+
+.irp n 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30
+vmax.vx  v\n, v\n, zero
+.endr
+
+vsetvli  zero, zero, e8, m1, ta, ma
+.irp n 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28
+vnclipu.wi   v\n, v\n, 0
+vse8.v   v\n, (a0)
+add  a0, a0, a1
+.endr
+vnclipu.wi   v30, v30, 0
+vse8.v   v30, (a0)
+
+ret
+endfunc
+
+func ff_tm_8x8_rvv, zve32x
+vsetivli zero, 8, e16, m1, ta, ma
+vle8.v   v8, (a3)
+vzext.vf2v28, v8
+lbu  a4, -1(a3)
+
+tm_sum   v16, v28, 7
+tm_sum   v17, v28, 6
+tm_sum   v18, v28, 5
+tm_sum   v19, v28, 4
+tm_sum   v20, v28, 3
+tm_sum   v21, v28, 2
+tm_sum   v22, v28, 1
+tm_sum   v23, v28, 0
+
+.irp n 16, 17, 18, 19, 20, 21, 22, 23
+vmax.vx  v\n, v\n, zero
+.endr
+
+vsetvli  zero, zero, e8, mf2, ta, ma
+.irp n 16, 17, 18, 19, 20, 21, 22
+vnclipu.wi   v\n, v\n, 0
+vse8.v   v\n, (a0)
+add  a0, a0, a1
+.endr
+vnclipu.wi   v24, v23, 0
+vse8.v   v24, (a0)
+
+ret
+endfunc
+
+func ff_tm_4x4_rvv, zve32x
+vsetivli zero, 4, e16, mf2, ta, ma
+vle8.v   v8, (a3)
+vzext.vf2v28, v8
+lbu  a4, -1(a3)
+
+tm_sum   v16, v28, 3
+tm_sum   v17, v28, 2
+tm_sum   v18, v28, 1
+tm_sum   v19, v28, 0
+
+.irp n 16, 17, 18, 19
+vmax.vx  v\n, v\n, zero
+.endr
+
+vsetvli  zero, zero, e8, mf4, ta, ma
+.irp n 16, 17, 18
+vnclipu.wi   v\n, v\n, 0
+vse8.v   v\n, (a0)
+add  a0, a0, a1
+.endr
+vnclipu.wi   v24, v19, 0
+vse8.v   

  1   2   >