Re: [FFmpeg-devel] [PATCH] avcodec/vlc: Reduce debug logging

2025-03-13 Thread Soft Works



> -Original Message-
> From: ffmpeg-devel  On Behalf Of
> Michael Niedermayer
> Sent: Freitag, 14. März 2025 01:28
> To: FFmpeg development discussions and patches 
> Subject: Re: [FFmpeg-devel] [PATCH] avcodec/vlc: Reduce debug logging
> 
> Hi
> 
> On Wed, Mar 12, 2025 at 03:48:20AM +, softworkz wrote:
> > From: softworkz 
> >
> > Signed-off-by: softworkz 
> > ---
> > avcodec/vlc: Reduce debug logging
> >
> > It made it hardly possible to enable debug logging for viewing
> other log
> > lines due to the excessive output created by this.
> >
> > Published-As: https://github.com/ffstaging/FFmpeg/releases/tag/pr-
> ffstaging-60%2Fsoftworkz%2Fsubmit_vlclogging-v1
> > Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg pr-
> ffstaging-60/softworkz/submit_vlclogging-v1
> > Pull-Request: https://github.com/ffstaging/FFmpeg/pull/60
> >
> >  libavcodec/vlc.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> will apply

Thanks!


> btw, speaking of excessive output,
> valgrind_backtrace (which is enabled by default when optimizations are
> disabled)

Only when you have it installed I suppose..? 
For me, it's 0 in config.h even after ./configure --disable-optimizations


> is also a feature that is rarely useful but very annoying noise wise
> (just saying in case anyone wants to reduce noise in general)

Might make sense to require it to enable explicitly.


What I meant by excessive in that case is that it exhausted the console buffer 
so that I couldn't even scroll back to ffmpeg startup and it took several 
seconds to react to break (q was hardly working at all), so it was an extreme 
case.

Thank you
sw



___
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 11/13] ffv1dec: reference the current packet into the main context

2025-03-13 Thread Lynne



On 13/03/2025 02:24, Andreas Rheinhardt wrote:

Lynne:

On 10/03/2025 18:42, Lynne wrote:

On 10/03/2025 04:14, Andreas Rheinhardt wrote:

Lynne:

---
   libavcodec/ffv1.h    |  3 +++
   libavcodec/ffv1dec.c | 19 +--
   2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 8c0e71284d..860a5c14b1 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -174,6 +174,9 @@ typedef struct FFV1Context {
    * NOT shared between frame threads.
    */
   uint8_t   frame_damaged;
+
+    /* Reference to the current packet */
+    AVPacket *pkt_ref;
   } FFV1Context;
   int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index eaa21eebdf..6396f22f79 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -469,6 +469,10 @@ static av_cold int decode_init(AVCodecContext
*avctx)
   f->pix_fmt = AV_PIX_FMT_NONE;
   f->configured_pix_fmt = AV_PIX_FMT_NONE;
+    f->pkt_ref = av_packet_alloc();
+    if (!f->pkt_ref)
+    return AVERROR(ENOMEM);
+
   if ((ret = ff_ffv1_common_init(avctx, f)) < 0)
   return ret;
@@ -701,6 +705,10 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *rframe,
   /* Start */
   if (hwaccel) {
+    ret = av_packet_ref(f->pkt_ref, avpkt);
+    if (ret < 0)
+    return ret;
+
   ret = hwaccel->start_frame(avctx, avpkt->data, avpkt->size);
   if (ret < 0)
   return ret;
@@ -720,15 +728,21 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *rframe,
   uint32_t len;
   ret = find_next_slice(avctx, avpkt->data, buf_end, i,
     &pos, &len);
-    if (ret < 0)
+    if (ret < 0) {
+    av_packet_unref(f->pkt_ref);
   return ret;
+    }
   buf_end -= len;
   ret = hwaccel->decode_slice(avctx, pos, len);
-    if (ret < 0)
+    if (ret < 0) {
+    av_packet_unref(f->pkt_ref);
   return ret;
+    }
   }
+
+    av_packet_unref(f->pkt_ref);
   } else {
   ret = decode_slices(avctx, c, avpkt);
   if (ret < 0)
@@ -827,6 +841,7 @@ static av_cold int
ffv1_decode_close(AVCodecContext *avctx)
   ff_progress_frame_unref(&s->last_picture);
   av_refstruct_unref(&s->hwaccel_last_picture_private);
+    av_packet_free(&s->pkt_ref);
   ff_ffv1_close(s);
   return 0;


Why not simply use a const AVPacket*?


No reason. Fixed locally.
Thanks.


*reverted this change.
We need to ref the packet, since we map its memory and let the GPU use
it directly without copying the contents. 6k16bit content at 24fps is
typically around 2Gbps when compressed, so avoiding copies is important.


How long does the hwaccel need this data?


Until the frame has been asynchronously decoded. We give an output frame 
with a semaphore that receivers need to wait on to determine when that is.


On the decoder-side, the hardware has a fixed number of queues where 
submissions can be sent to asynchronously. We treat it as a ring buffer 
and keep a reference to all resources our side for each submission, 
until we need to reuse the slot, at which point we wait on the frame 
decoding to complete (which it usually has), and we release all 
resources used.


Output frames also have a bit of state that has to be freed once the 
frame is marked (unreferenced) by the decoder as no longer being needed 
as a reference, this is done in the FFHWAccel.free_frame_priv callback. 
There, we have to wait for the last internal use of the frame to be 
finished (done via the vp->wait_semaphores() call in vulkan_decode.c).


This is valid for both ASIC hardware decoders and a compute shader based 
implementation, since the two share the same code, except for decode 
submissions.

___
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/1] avformat/avio: add configuration options for IO_BUFFER_SIZE

2025-03-13 Thread Nicolas George
姚靖威 (HE12025-03-13):
> The purpose of this patch is to modify the default buffer size of the avio
> module during compilation.

No, that is not the purpose, that is only what it does.

> On some resource-constrained devices to save memory, the current default
> value (32K), it can also be set to a smaller value.

THAT is the purpose. And it needs to go into the commit message.

> Nicolas George  于2025年3月11日周二 19:55写道:

Top-posting is forbidden on this list; if you do not know what it means
look it up.

Regards,

-- 
  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] [PATCH] Include field_mode information in NUT stream info

2025-03-13 Thread Michael Niedermayer
On Mon, Mar 10, 2025 at 11:46:10PM +0100, Anders Rein wrote:
> This will make it possible to transmit raw video over NUT without losing
> the field order information.
> ---
>  libavformat/nut.c|  36 ++
>  libavformat/nut.h|   3 +
>  libavformat/nutdec.c |  12 +
>  libavformat/nutenc.c |  11 +
>  tests/ref/fate/ffmpeg-loopback-decoding  |   4 +-
>  tests/ref/fate/ffprobe_compact   |  62 +--
>  tests/ref/fate/ffprobe_csv   |  62 +--
>  tests/ref/fate/ffprobe_default   |  66 ++--
>  tests/ref/fate/ffprobe_flat  |  66 ++--
>  tests/ref/fate/ffprobe_ini   |  66 ++--
>  tests/ref/fate/ffprobe_json  |  68 ++--
>  tests/ref/fate/ffprobe_xml   |  64 +--
>  tests/ref/fate/filter-crop   |   2 +-
>  tests/ref/fate/filter-crop_scale |   2 +-
>  tests/ref/fate/filter-crop_scale_vflip   |   2 +-
>  tests/ref/fate/filter-crop_vflip |   2 +-
>  tests/ref/fate/filter-edgedetect |   2 +-
>  tests/ref/fate/filter-edgedetect-colormix|   2 +-
>  tests/ref/fate/filter-hue1   |   2 +-
>  tests/ref/fate/filter-hue2   |   2 +-
>  tests/ref/fate/filter-hue3   |   2 +-
>  tests/ref/fate/filter-hue4   |   2 +-
>  tests/ref/fate/filter-median |   2 +-
>  tests/ref/fate/filter-null   |   2 +-
>  tests/ref/fate/filter-pad|   2 +-
>  tests/ref/fate/filter-pixdesc-0bgr   |   2 +-
>  tests/ref/fate/filter-pixdesc-0rgb   |   2 +-
>  tests/ref/fate/filter-pixdesc-abgr   |   2 +-
>  tests/ref/fate/filter-pixdesc-argb   |   2 +-
>  tests/ref/fate/filter-pixdesc-ayuv   |   2 +-
>  tests/ref/fate/filter-pixdesc-ayuv64be   |   2 +-
>  tests/ref/fate/filter-pixdesc-ayuv64le   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr0   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr24  |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr444be   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr444le   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr48be|   2 +-
>  tests/ref/fate/filter-pixdesc-bgr48le|   2 +-
>  tests/ref/fate/filter-pixdesc-bgr4_byte  |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr555be   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr555le   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr565be   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr565le   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgr8   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgra   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgra64be   |   2 +-
>  tests/ref/fate/filter-pixdesc-bgra64le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap10be  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap10le  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap12be  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap12le  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap14be  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap14le  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap16be  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrap16le  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrapf32be |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrapf32le |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp10be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp10le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp12be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp12le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp14be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp14le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp16be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp16le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp9be|   2 +-
>  tests/ref/fate/filter-pixdesc-gbrp9le|   2 +-
>  tests/ref/fate/filter-pixdesc-gbrpf32be  |   2 +-
>  tests/ref/fate/filter-pixdesc-gbrpf32le  |   2 +-
>  tests/ref/fate/filter-pixdesc-gray   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray10be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray10le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray12be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray12le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray14be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray14le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray16be   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray16le   |   2 +-
>  tests/ref/fate/filter-pixdesc-gray9be|   2 +-
>  tests/ref/fate/filter-pixdesc-gray9le|   2 +-
>  tests/ref/fate/filter-pixdesc-grayf32be  |   2 +-
>  tests/ref/fate/filter-pixdesc-grayf32le  |   2 +-
>  tests/ref/fate/filter-pixde

[FFmpeg-devel] [PATCH] avformat/avio: Add max_pkt_size option

2025-03-13 Thread Zhao Zhili
From: Zhao Zhili 

Optimizing memory footprint in memory-constrained systems.

Signed-off-by: Zhao Zhili 
---
 libavformat/avio.c| 2 ++
 libavformat/version.h | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index d109f3adff..e1b959ed73 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -61,6 +61,8 @@ static const AVOption options[] = {
 {"protocol_whitelist", "List of protocols that are allowed to be used", 
OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, D },
 {"protocol_blacklist", "List of protocols that are not allowed to be 
used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, 
D },
 {"rw_timeout", "Timeout for IO operations (in microseconds)", 
offsetof(URLContext, rw_timeout), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 
INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
+{"max_pkt_size", "Default maximum packet size in bytes, could be 
overwritten by particular protocol",
+offsetof(URLContext, max_packet_size), AV_OPT_TYPE_INT, { .i64 = 
IO_BUFFER_SIZE }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM | 
AV_OPT_FLAG_DECODING_PARAM },
 { NULL }
 };
 
diff --git a/libavformat/version.h b/libavformat/version.h
index 6ffdf61b43..e1ab967f5b 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
 #include "version_major.h"
 
 #define LIBAVFORMAT_VERSION_MINOR   9
-#define LIBAVFORMAT_VERSION_MICRO 107
+#define LIBAVFORMAT_VERSION_MICRO 108
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
-- 
2.46.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 v8 0/8] Properly decode ogg metadata in ogg/{vorbis, flac, opus} chained bitstreams

2025-03-13 Thread Romain Beauxis
Le jeu. 13 mars 2025 à 08:43, Michael Niedermayer
 a écrit :
>
> Hi Romain
>
> On Tue, Mar 11, 2025 at 11:56:37AM -0500, Romain Beauxis wrote:
> > Le mar. 11 mars 2025 à 11:55, Romain Beauxis
> >  a écrit :
> > >
> > > This is a series of patches to allow proper decoding of ogg metadata in 
> > > chained
> > > `ogg/vorbis, `ogg/flac` and `ogg/opus` streams.
> > >
> > > ## Changes since last version:
> > > * Moved textual reference output for tests to test/ref/fate
> > > * Updated test binary to only output stream metadata when
> > >   AVSTREAM_EVENT_FLAG_METADATA_UPDATED flag is set.
> >
> > Again, forgot to add that test samples are available here:
> > https://www.dropbox.com/scl/fo/xrtrna2rxr1j354hrtymq/AGwemlxHYecBLNmQ8Fsy--4?rlkey=lzilr4m9w4gfdqygoe172vvy8&dl=0
>
> please always cc samples-request for sample upload requests

Well noted!

> also in case this is not documented where you looked, feel free
> to send a patch to better document that

I see the documentation about it so I think it's properly documented.

But, now I know too!

Thanks,
-- Romain
___
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] avcodec/sanm: properly implement STOR/FTCH for ANIMv1

2025-03-13 Thread Manuel Lauss
Handle STOR/FTCH the same way the RA1 game engine does:
On STOR, save the next following FOBJ (not the decoded image)
in a buffer; decode it on FTCH.

Used extensively by Rebel Assault 1 for e.g. the cockpit: A STOR-ed
codec21 object which only covers parts of the buffer is FTCHed
as last object in the stack.

For ANIMv2 keep the current system to store the decoded image, as
replaying a FOBJ would not work with codecs37/47/48 due to sequence
violations.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 84 ---
 1 file changed, 80 insertions(+), 4 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 207db4a8fb..da7fb4a9e0 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -1671,6 +1671,57 @@ static int process_frame_obj(SANMVideoContext *ctx)
 }
 }
 
+static int process_ftch(SANMVideoContext *ctx, int size)
+{
+GetByteContext gb, *old_gb = ctx->gb;
+uint8_t *sf = ctx->stored_frame;
+int xoff, yoff, left, top, ret;
+uint32_t sz;
+
+/* FTCH defines additional x/y offsets */
+if (size != 12) {
+if (bytestream2_get_bytes_left(ctx->gb) < 6)
+return AVERROR_INVALIDDATA;
+bytestream2_skip(ctx->gb, 2);
+xoff = bytestream2_get_le16u(ctx->gb);
+yoff = bytestream2_get_le16u(ctx->gb);
+} else {
+if (bytestream2_get_bytes_left(ctx->gb) < 12)
+return AVERROR_INVALIDDATA;
+bytestream2_skip(ctx->gb, 4);
+xoff = bytestream2_get_be32u(ctx->gb);
+yoff = bytestream2_get_be32u(ctx->gb);
+}
+
+sz = *(uint32_t *)(sf + 0);
+if ((sz > 0) && (sz <= ctx->stored_frame_size - 4)) {
+/* add the FTCH offsets to the left/top values of the stored FOBJ */
+left = av_le2ne16(*(int16_t *)(sf + 4 + 2));
+top  = av_le2ne16(*(int16_t *)(sf + 4 + 4));
+*(int16_t *)(sf + 4 + 2) = av_le2ne16(left + xoff);
+*(int16_t *)(sf + 4 + 4) = av_le2ne16(top  + yoff);
+
+/* decode the stored FOBJ */
+bytestream2_init(&gb, sf + 4, sz);
+ctx->gb = &gb;
+ret = process_frame_obj(ctx);
+ctx->gb = old_gb;
+
+/* now restore the original left/top values again */
+*(int16_t *)(sf + 4 + 2) = av_le2ne16(left);
+*(int16_t *)(sf + 4 + 4) = av_le2ne16(top);
+} else {
+/* this happens a lot in RA1: The individual files are meant to
+ * be played in sequence, with some referencing objects STORed
+ * by previous files, e.g. the cockpit codec21 object in RA1 LVL8.
+ * But spamming the log with errors is also not helpful, so
+ * here we simply ignore this case.
+ */
+ ret = 0;
+}
+return ret;
+}
+
 static int process_xpal(SANMVideoContext *ctx, int size)
 {
 int16_t *dp = ctx->delta_pal;
@@ -2158,6 +2209,29 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 if (ret = process_frame_obj(ctx))
 return ret;
 have_pic = 1;
+
+/* STOR: for ANIMv0/1 store the whole FOBJ datablock, as it
+ * needs to be replayed on FTCH, since none of the codecs
+ * it uses work on the full buffer.
+ * For ANIMv2, it's enough to store the current framebuffer.
+ */
+if (to_store) {
+to_store = 0;
+if (ctx->subversion < 2) {
+if (size + 4 <= ctx->stored_frame_size) {
+int pos2 = bytestream2_tell(ctx->gb);
+bytestream2_seek(ctx->gb, pos, SEEK_SET);
+*(uint32_t *)(ctx->stored_frame) = size;
+bytestream2_get_bufferu(ctx->gb, ctx->stored_frame 
+ 4, size);
+bytestream2_seek(ctx->gb, pos2, SEEK_SET);
+} else {
+av_log(avctx, AV_LOG_ERROR, "FOBJ too large for 
STOR\n");
+ret = AVERROR(ENOMEM);
+}
+} else {
+memcpy(ctx->stored_frame, ctx->frm0, ctx->buf_size);
+}
+}
 break;
 case MKBETAG('X', 'P', 'A', 'L'):
 if (ret = process_xpal(ctx, size))
@@ -2167,8 +2241,12 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 to_store = 1;
 break;
 case MKBETAG('F', 'T', 'C', 'H'):
-memcpy(ctx->frm0, ctx->stored_frame, ctx->buf_size);
-have_pic = 1;
+if (ctx->subversion < 2) {
+if (ret = process_ftch(ctx, size))
+return ret;
+} else {
+memcpy(ctx->frm0, ctx->stored_frame, ctx->buf_size);
+}
 break;
 default:
 bytestream2

[FFmpeg-devel] [PATCH v3] ffbuild: read library linker objects from a file

2025-03-13 Thread Gyan Doshi
The linker command can exceed the maximum argument limit on MinGW,
especially for libavcodec.

The objects list is now stored in a file and passed to the linker.
---
v3:
  for reasons unknown to me, static linking doesn't appear to
  work on linux with escaped variables, so removed those.
  Someone please test on linux both static and shared builds.

 .gitignore  | 1 +
 ffbuild/common.mak  | 2 +-
 ffbuild/library.mak | 8 ++--
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/.gitignore b/.gitignore
index 9cfc78b414..430abaf91b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 *.a
 *.o
+*.objs
 *.o.*
 *.d
 *.def
diff --git a/ffbuild/common.mak b/ffbuild/common.mak
index 023adb8567..ca45a0f368 100644
--- a/ffbuild/common.mak
+++ b/ffbuild/common.mak
@@ -214,7 +214,7 @@ $(TOOLOBJS): | tools
 
 OUTDIRS := $(OUTDIRS) $(dir $(OBJS) $(HOBJS) $(HOSTOBJS) $(SLIBOBJS) 
$(SHLIBOBJS) $(STLIBOBJS) $(TESTOBJS))
 
-CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.pc *.ptx *.ptx.gz 
*.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
+CLEANSUFFIXES = *.d *.gcda *.gcno *.h.c *.ho *.map *.o *.objs *.pc *.ptx 
*.ptx.gz *.ptx.c *.ver *.version *$(DEFAULT_X86ASMD).asm *~ *.ilk *.pdb
 LIBSUFFIXES   = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a
 
 define RULES
diff --git a/ffbuild/library.mak b/ffbuild/library.mak
index 793e9d41fa..72e3872157 100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@ -35,8 +35,10 @@ OBJS += $(SHLIBOBJS)
 endif
 $(SUBDIR)$(LIBNAME): $(OBJS) $(STLIBOBJS)
$(RM) $@
-   $(AR) $(ARFLAGS) $(AR_O) $^
+   $(Q)echo $^ > $@.objs
+   $(AR) $(ARFLAGS) $(AR_O) @$@.objs
$(RANLIB) $@
+   -$(RM) $@.objs
 
 install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig
 
@@ -66,8 +68,10 @@ $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)
 
 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SHLIBOBJS) $(SLIBOBJS) 
$(SUBDIR)lib$(NAME).ver
$(SLIB_CREATE_DEF_CMD)
-   $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) $$(filter %.o,$$^) 
$(FFEXTRALIBS)
+   $(Q)echo $$(filter %.o,$$^) > $$@.objs
+   $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) @$$@.objs 
$(FFEXTRALIBS)
$(SLIB_EXTRA_CMD)
+   -$(RM) $$@.objs
 
 ifdef SUBDIR
 $(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(DEP_LIBS)
-- 
2.46.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 v6 3/3] doc/fftools-common-opts: document memaddresses log flag

2025-03-13 Thread softworkz
From: softworkz 

---
 doc/fftools-common-opts.texi | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index f6d452c40e..756c843c02 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -230,6 +230,8 @@ log to file.
 Indicates that log lines should be prefixed with time information.
 @item datetime
 Indicates that log lines should be prefixed with date and time information.
+@item memaddresses
+Indicates that context prefixes should be printed with memory addresses rather 
than logical ids.
 @end table
 Flags can also be used alone by adding a '+'/'-' prefix to set/reset a single
 flag without affecting other @var{flags} or changing @var{loglevel}. When
-- 
ffmpeg-codebot
___
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] avcodec/sanm: change GetByteContext member to pointer

2025-03-13 Thread Manuel Lauss
In order do properly support the ANIM STOR/FTCH system, the FTCH
must replay a stored FOBJ and change the SANMContext's "GetByteContext"
member temporarily.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 394 +++---
 1 file changed, 198 insertions(+), 196 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index a8a3e04156..207db4a8fb 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -262,7 +262,7 @@ static const int8_t c37_mv[] = {
 
 typedef struct SANMVideoContext {
 AVCodecContext *avctx;
-GetByteContext gb;
+GetByteContext *gb;
 
 int version, subversion, have_dimensions;
 uint32_t pal[PALETTE_SIZE];
@@ -606,11 +606,11 @@ static int codec4_load_tiles(SANMVideoContext *ctx, 
uint16_t param2, uint8_t clr
 if (param2 > 256)
 return AVERROR_INVALIDDATA;
 
-if (bytestream2_get_bytes_left(&ctx->gb) < loop)
+if (bytestream2_get_bytes_left(ctx->gb) < loop)
 return AVERROR_INVALIDDATA;
 
 while (loop--) {
-c = bytestream2_get_byteu(&ctx->gb);
+c = bytestream2_get_byteu(ctx->gb);
 *dst++ = (c >> 4) + clr;
 *dst++ = (c & 0xf) + clr;
 }
@@ -702,9 +702,9 @@ static int old_codec4(SANMVideoContext *ctx, int left, int 
top, int w, int h,
 pxoff = j + left + ((top + i) * p);
 if (param2 > 0) {
 if (bits == 0) {
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+if (bytestream2_get_bytes_left(ctx->gb) < 1)
 return AVERROR_INVALIDDATA;
-mask = bytestream2_get_byteu(&ctx->gb);
+mask = bytestream2_get_byteu(ctx->gb);
 bits = 8;
 }
 bit = !!(mask & 0x80);
@@ -714,9 +714,9 @@ static int old_codec4(SANMVideoContext *ctx, int left, int 
top, int w, int h,
 bit = 0;
 }
 
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+if (bytestream2_get_bytes_left(ctx->gb) < 1)
 return AVERROR_INVALIDDATA;
-idx = bytestream2_get_byteu(&ctx->gb);
+idx = bytestream2_get_byteu(ctx->gb);
 if ((bit == 0) && (idx == 0x80) && (codec != 5))
 continue;
 
@@ -761,18 +761,18 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t 
*dst, const int out_size)
 int opcode, color, run_len, left = out_size;
 
 while (left > 0) {
-opcode = bytestream2_get_byte(&ctx->gb);
+opcode = bytestream2_get_byte(ctx->gb);
 run_len = (opcode >> 1) + 1;
-if (run_len > left || bytestream2_get_bytes_left(&ctx->gb) <= 0)
+if (run_len > left || bytestream2_get_bytes_left(ctx->gb) <= 0)
 return AVERROR_INVALIDDATA;
 
 if (opcode & 1) {
-color = bytestream2_get_byte(&ctx->gb);
+color = bytestream2_get_byte(ctx->gb);
 memset(dst, color, run_len);
 } else {
-if (bytestream2_get_bytes_left(&ctx->gb) < run_len)
+if (bytestream2_get_bytes_left(ctx->gb) < run_len)
 return AVERROR_INVALIDDATA;
-bytestream2_get_bufferu(&ctx->gb, dst, run_len);
+bytestream2_get_bufferu(ctx->gb, dst, run_len);
 }
 
 dst  += run_len;
@@ -795,30 +795,30 @@ static int old_codec23(SANMVideoContext *ctx, int top, 
int left, int width,
 for (i = 0; i < 256; i++)
 lut[i] = (i + param + 0xd0) & 0xff;
 } else if (param2 == 256) {
-if (bytestream2_get_bytes_left(&ctx->gb) < 256)
+if (bytestream2_get_bytes_left(ctx->gb) < 256)
 return AVERROR_INVALIDDATA;
-bytestream2_get_bufferu(&ctx->gb, ctx->c23lut, 256);
+bytestream2_get_bufferu(ctx->gb, ctx->c23lut, 256);
 } else if (param2 < 256) {
 for (i = 0; i < 256; i++)
 lut[i] = (i + param2) & 0xff;
 } else {
 memcpy(lut, ctx->c23lut, 256);
 }
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+if (bytestream2_get_bytes_left(ctx->gb) < 1)
 return 0;  /* some c23 frames just set up the LUT */
 
 dst = (uint8_t *)ctx->frm0;
 for (i = 0; i < height; i++) {
-if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+if (bytestream2_get_bytes_left(ctx->gb) < 2)
 return 0;
 pxoff = left + ((top + i) * ctx->pitch);
-k = bytestream2_get_le16u(&ctx->gb);
+k = bytestream2_get_le16u(ctx->gb);
 sk = 1;
 pc = 0;
 while (k > 0 && pc <= width) {
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+if (bytestream2_get_bytes_left(ctx->gb) < 1)
 return AVERROR_INVALIDDATA;
-j = bytestream2_get_byteu(&ctx->gb);
+j = bytestream2_get_byteu(ctx->gb);
 if (sk) {
 pxoff += j;
 pc += j;
@@ -847,25 +847,25 @@ static int old_codec21(SANMVideoContext *ctx, int 

Re: [FFmpeg-devel] [PATCH] avfilter: POC: enable out-of-tree filters

2025-03-13 Thread Leandro Santiago
This is a follow-up to the my previous message:

https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/340895.html

On 3/13/25 13:18, Leandro Santiago wrote:
> This is a POC/prototype that aims to enable out of tree filters on
> FFmpeg.
>
> Here I name them "extra filters".
>
> It introduces the program `jq` as a new build dependency.
>
> To test it, create a directory, for instance, /tmp/my-shiny-filter/ and
> inside it, create the following files:
>
> `filter.json`, with the content:
>
> ```
> {
>   "check": "require_pkg_config json json-c json-c/json.h json_c_version_num",
>   "symbols": ["ff_vf_foo", "ff_vf_bar"]
> }
> ```
>
> `filter.mak`, with the content:
>
> ```
> OBJS += vf_shiny.o
> LIBOBJS += vf_shiny.o
>
> libavfilter/vf_shiny.o:
> $(CC) $(EXTRA_FILTER_FLAGS) -c -o $@ 
> $(EXTRA_FILTER_FOO_LOCATION)/vf_shiny.c
> ```
>
> `vf_shiny.c` file, with the content:
>
>
> ```
> #include "libavutil/internal.h"   
> 
> #include "avfilter.h" 
> 
> #include "filters.h"  
> 
> #include "video.h" 
>
> const FFFilter ff_vf_bar = {
> .p.name= "bar",
> .p.description = NULL_IF_CONFIG_SMALL("Example filter Baz"),
> .p.flags   = AVFILTER_FLAG_METADATA_ONLY,
> FILTER_INPUTS(ff_video_default_filterpad),
> FILTER_OUTPUTS(ff_video_default_filterpad),
> };
>
> const FFFilter ff_vf_foo = {
> .p.name= "foo",
> .p.description = NULL_IF_CONFIG_SMALL("Another foo filter"),
> .p.flags   = AVFILTER_FLAG_METADATA_ONLY,
> FILTER_INPUTS(ff_video_default_filterpad),
> FILTER_OUTPUTS(ff_video_default_filterpad),
> };
> ```
>
> Then, from the ffmpeg source tree, run configure specifying where the
> extra filter is located:
>
> ```
> ./configure --extra-filter=/tmp/my-shiny-filter
> make ffplay
> ```
>
> Now you can use the filters:
>
> ```
> ./ffplay /path/to/file.webm -vf 'foo,baz'
> ```
>
> What works:
>
> - Building C based filters with no extra dependencies.
> - Multiple filters in the same object file.
>
> What does not work:
>
> - The extra filters will not use the same CC flags used to build the
>   built-in filters as I could get it to work yet.
> - Due to the above limitation, you cannot include headers of extra
>   dependencies, for instance, `json.h` in the example.
> - You can pass arbitrary CFLAGS or LDFLAGS in the filter.json file,
>   but they should be passed only then building/linking `libavfilter`,
>   instead of other libraries.
>
> What was not implemented:
>
> - I believe it would be useful to check if the license of the filter is
>   compatible with the license used to build FFmpeg.
> - Only extra filters written in C (maybe C++?) are supported for now.
>   One of my goals is to enable Rust as well.
>
> Signed-off-by: Leandro Santiago 
> ---
>  .gitignore   |  3 ++
>  configure| 61 
>  libavfilter/Makefile |  4 +++
>  libavfilter/allfilters.c |  1 +
>  4 files changed, 69 insertions(+)
>
> diff --git a/.gitignore b/.gitignore
> index 9cfc78b414..4963e90191 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -43,3 +43,6 @@
>  /tools/python/__pycache__/
>  /libavcodec/vulkan/*.c
>  /libavfilter/vulkan/*.c
> +/ffbuild/extra-filters.txt
> +/ffbuild/extra-filters.mak
> +/libavfilter/extra_filters_extern.h
> diff --git a/configure b/configure
> index 750c99e3b9..6a2adc6c05 100755
> --- a/configure
> +++ b/configure
> @@ -179,6 +179,7 @@ Individual component options:
>--enable-filter=NAME enable filter NAME
>--disable-filter=NAMEdisable filter NAME
>--disable-filtersdisable all filters
> +  --extra-filter=/foo/bar  add extra filter from directory. This option can 
> be used multiple times
>  
>  External library support:
>  
> @@ -1798,6 +1799,7 @@ AVDEVICE_COMPONENTS="
>  
>  AVFILTER_COMPONENTS="
>  filters
> +extra_filters
>  "
>  
>  AVFORMAT_COMPONENTS="
> @@ -4382,6 +4384,8 @@ do_random(){
>  $action $(rand_list "$@" | awk "BEGIN { srand($random_seed) } \$1 == 
> \"prob\" { prob = \$2; next } rand() < prob { print }")
>  }
>  
> +rm -f ffbuild/extra-filters.txt
> +
>  # deprecated components (disabled by default)
>  disable sonic_encoder sonic_ls_encoder
>  
> @@ -4457,6 +4461,10 @@ for opt do
>  die_unknown $opt
>  fi
>  ;;
> +--extra-filter=*)
> +filter_path="${opt#--extra-filter=}"
> +echo "$filter_path" >> ffbuild/extra-filters.txt
> +;;
>  --list-*)
>  NAME="${opt#--list-}"
>  is_in $NAME $COMPONENT_LIST || die_unknown $opt
> @@ -4487,6 +4495,36 @@ for opt do

Re: [FFmpeg-devel] [PATCH v7 2/7] fftools/ffprobe: Change to use textformat api

2025-03-13 Thread Michael Niedermayer
On Wed, Mar 12, 2025 at 04:04:20AM +, softworkz wrote:
> From: softworkz 
> 
> Signed-off-by: softworkz 
> ---
>  fftools/Makefile  |   12 +
>  fftools/ffprobe.c | 1849 -
>  2 files changed, 142 insertions(+), 1719 deletions(-)

breaks build for x86-32

make
CC  fftools/textformat/avtextformat.o
src/fftools/textformat/avtextformat.c:672:1: fatal error: opening dependency 
file fftools/textformat/avtextformat.d: No such file or directory
 }
 ^
compilation terminated.
make: *** [src/ffbuild/common.mak:81: fftools/textformat/avtextformat.o] Error 1

thx

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

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


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH] ffbuild: read library linker objects from a file

2025-03-13 Thread Martin Storsjö

On Wed, 12 Mar 2025, Gyan Doshi wrote:


The linker command can exceed the maximum argument limit on MinGW,
especially for libavcodec.

The objects list is now stored in a file and passed to the linker.
---
ffbuild/library.mak | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ffbuild/library.mak b/ffbuild/library.mak
index 793e9d41fa..781b018e00 100644
--- a/ffbuild/library.mak
+++ b/ffbuild/library.mak
@@ -66,8 +66,10 @@ $(SUBDIR)$(SLIBNAME): $(SUBDIR)$(SLIBNAME_WITH_MAJOR)

$(SUBDIR)$(SLIBNAME_WITH_MAJOR): $(OBJS) $(SHLIBOBJS) $(SLIBOBJS) 
$(SUBDIR)lib$(NAME).ver
$(SLIB_CREATE_DEF_CMD)
-   $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) $$(filter %.o,$$^) 
$(FFEXTRALIBS)
+   $(Q)echo $$(filter %.o,$$^) > $$@.objs
+   $$(LD) $(SHFLAGS) $(LDFLAGS) $(LDSOFLAGS) $$(LD_O) @$$@.objs 
$(FFEXTRALIBS)
$(SLIB_EXTRA_CMD)
+   -$(RM) $$@.objs


Don't we need do the same for static libraries too?

On first glance, this looks quite reasonable... However, the limit that is 
an issue is the length of a command line. The .objs file is written with 
an "echo" command - doesn't that fundamentally also hit the same limit 
(just a little bit later, as there are fewer command line flags in this 
command)?


Or do we assume that make executes it with a shell, where the shell 
handles "echo" as a shell builtin so that it doesn't actually spawn a 
subprocess for this? Can you test it, if you could extend the list of 
object files to the point where the .objs file is clearly over 32 KB, and 
verify that it did include all the files you intended?


Secondly, less fundamental - even if we try to remove the .objs file here 
at the same time it's quite possible for it to be left behind (e.g. if the 
linking command fails) - so it would be good to make sure that it is 
removed on "make clean" too.


Plus we probably should include it in .gitignore, if someone does in-tree 
builds.


// 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 v4 15/16] FFHWAccel: add buffer_ref argument to start_frame

2025-03-13 Thread Andreas Rheinhardt
Lynne:
> This commit adds a reference to the buffer as an argument to
> start_frame, and adapts all existing code.
> 
> This allows for asynchronous hardware accelerators to skip
> copying packet data by referencing it.
> ---
>  libavcodec/av1dec.c   |  3 ++-
>  libavcodec/d3d12va_av1.c  |  5 -
>  libavcodec/d3d12va_h264.c |  5 +++--
>  libavcodec/d3d12va_hevc.c |  5 -
>  libavcodec/d3d12va_mpeg2.c|  5 -
>  libavcodec/d3d12va_vc1.c  |  5 -
>  libavcodec/d3d12va_vp9.c  |  5 -
>  libavcodec/dxva2_av1.c|  1 +
>  libavcodec/dxva2_h264.c   |  1 +
>  libavcodec/dxva2_hevc.c   |  1 +
>  libavcodec/dxva2_mpeg2.c  |  1 +
>  libavcodec/dxva2_vc1.c|  1 +
>  libavcodec/dxva2_vp9.c|  1 +
>  libavcodec/ffv1dec.c  |  2 +-
>  libavcodec/h263dec.c  |  2 +-
>  libavcodec/h264dec.c  |  8 +---
>  libavcodec/hevc/hevcdec.c |  5 -
>  libavcodec/hwaccel_internal.h |  4 +++-
>  libavcodec/mjpegdec.c |  2 +-
>  libavcodec/mpeg12dec.c|  2 +-
>  libavcodec/nvdec_av1.c|  4 +++-
>  libavcodec/nvdec_h264.c   |  1 +
>  libavcodec/nvdec_hevc.c   |  1 +
>  libavcodec/nvdec_mjpeg.c  |  4 +++-
>  libavcodec/nvdec_mpeg12.c |  3 ++-
>  libavcodec/nvdec_mpeg4.c  |  3 ++-
>  libavcodec/nvdec_vc1.c|  3 ++-
>  libavcodec/nvdec_vp8.c|  3 ++-
>  libavcodec/nvdec_vp9.c|  3 ++-
>  libavcodec/proresdec.c|  2 +-
>  libavcodec/vaapi_av1.c|  1 +
>  libavcodec/vaapi_h264.c   |  1 +
>  libavcodec/vaapi_hevc.c   |  1 +
>  libavcodec/vaapi_mjpeg.c  |  1 +
>  libavcodec/vaapi_mpeg2.c  |  5 -
>  libavcodec/vaapi_mpeg4.c  |  5 -
>  libavcodec/vaapi_vc1.c|  5 -
>  libavcodec/vaapi_vp8.c|  1 +
>  libavcodec/vaapi_vp9.c|  1 +
>  libavcodec/vaapi_vvc.c|  1 +
>  libavcodec/vc1dec.c   |  6 +++---
>  libavcodec/vdpau_av1.c|  3 ++-
>  libavcodec/vdpau_h264.c   |  1 +
>  libavcodec/vdpau_hevc.c   |  1 +
>  libavcodec/vdpau_mpeg12.c |  1 +
>  libavcodec/vdpau_mpeg4.c  |  1 +
>  libavcodec/vdpau_vc1.c|  1 +
>  libavcodec/vdpau_vp9.c|  3 ++-
>  libavcodec/videotoolbox.c |  8 ++--
>  libavcodec/videotoolbox_av1.c |  1 +
>  libavcodec/videotoolbox_vp9.c |  1 +
>  libavcodec/vp8.c  |  2 +-
>  libavcodec/vp9.c  |  2 +-
>  libavcodec/vt_internal.h  |  1 +
>  libavcodec/vulkan_av1.c   |  1 +
>  libavcodec/vulkan_h264.c  |  1 +
>  libavcodec/vulkan_hevc.c  |  1 +
>  libavcodec/vvc/dec.c  | 12 +++-
>  58 files changed, 118 insertions(+), 42 deletions(-)
> 
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index ed504ace85..baa9dea0f7 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -1380,7 +1380,8 @@ static int av1_receive_frame_internal(AVCodecContext 
> *avctx, AVFrame *frame)
>  s->cur_frame.temporal_id = header->temporal_id;
>  
>  if (avctx->hwaccel && s->cur_frame.f) {
> -ret = FF_HW_CALL(avctx, start_frame, unit->data, 
> unit->data_size);
> +ret = FF_HW_CALL(avctx, start_frame, s->pkt->buf,
> + unit->data, unit->data_size);
>  if (ret < 0) {
>  av_log(avctx, AV_LOG_ERROR, "HW accel start frame 
> fail.\n");
>  goto end;
> diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
> index 4a4d207b4f..230ca243fd 100644
> --- a/libavcodec/d3d12va_av1.c
> +++ b/libavcodec/d3d12va_av1.c
> @@ -45,7 +45,10 @@ typedef struct AV1DecodePictureContext {
>  unsignedbitstream_size;
>  } AV1DecodePictureContext;
>  
> -static int d3d12va_av1_start_frame(AVCodecContext *avctx, av_unused const 
> uint8_t *buffer,  av_unused uint32_t size)
> +static int d3d12va_av1_start_frame(AVCodecContext *avctx,
> +   av_unused AVBufferRef *buffer_ref,
> +   av_unused const uint8_t *buffer,
> +   av_unused uint32_t size)
>  {
>  const AV1DecContext *h   = avctx->priv_data;
>  AV1DecodePictureContext *ctx_pic = h->cur_frame.hwaccel_picture_private;
> diff --git a/libavcodec/d3d12va_h264.c b/libavcodec/d3d12va_h264.c
> index b2fe2955c8..80a1034fa5 100644
> --- a/libavcodec/d3d12va_h264.c
> +++ b/libavcodec/d3d12va_h264.c
> @@ -50,8 +50,9 @@ static void fill_slice_short(DXVA_Slice_H264_Short *slice,
>  }
>  
>  static int d3d12va_h264_start_frame(AVCodecContext *avctx,
> -  av_unused const uint8_t *buffer,
> -  av_unused uint32_t size)
> +av_unused AVBufferRef *buffer_ref,
> +av_unused const uint8_t *buffer,
> +av_unused uint32_t size)
>  {
>  const H264Co

Re: [FFmpeg-devel] [PATCH v8 0/8] Properly decode ogg metadata in ogg/{vorbis, flac, opus} chained bitstreams

2025-03-13 Thread Michael Niedermayer
Hi Romain

On Tue, Mar 11, 2025 at 11:56:37AM -0500, Romain Beauxis wrote:
> Le mar. 11 mars 2025 à 11:55, Romain Beauxis
>  a écrit :
> >
> > This is a series of patches to allow proper decoding of ogg metadata in 
> > chained
> > `ogg/vorbis, `ogg/flac` and `ogg/opus` streams.
> >
> > ## Changes since last version:
> > * Moved textual reference output for tests to test/ref/fate
> > * Updated test binary to only output stream metadata when
> >   AVSTREAM_EVENT_FLAG_METADATA_UPDATED flag is set.
> 
> Again, forgot to add that test samples are available here:
> https://www.dropbox.com/scl/fo/xrtrna2rxr1j354hrtymq/AGwemlxHYecBLNmQ8Fsy--4?rlkey=lzilr4m9w4gfdqygoe172vvy8&dl=0

please always cc samples-request for sample upload requests

also in case this is not documented where you looked, feel free
to send a patch to better document that

thx

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

The misfortune of the wise is better than the prosperity of the fool.
-- Epicurus


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 11/13] ffv1dec: reference the current packet into the main context

2025-03-13 Thread Lynne

On 13/03/2025 05:57, Andreas Rheinhardt wrote:

Lynne:



On 13/03/2025 02:24, Andreas Rheinhardt wrote:

Lynne:

On 10/03/2025 18:42, Lynne wrote:

On 10/03/2025 04:14, Andreas Rheinhardt wrote:

Lynne:

---
    libavcodec/ffv1.h    |  3 +++
    libavcodec/ffv1dec.c | 19 +--
    2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 8c0e71284d..860a5c14b1 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -174,6 +174,9 @@ typedef struct FFV1Context {
     * NOT shared between frame threads.
     */
    uint8_t   frame_damaged;
+
+    /* Reference to the current packet */
+    AVPacket *pkt_ref;
    } FFV1Context;
    int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index eaa21eebdf..6396f22f79 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -469,6 +469,10 @@ static av_cold int decode_init(AVCodecContext
*avctx)
    f->pix_fmt = AV_PIX_FMT_NONE;
    f->configured_pix_fmt = AV_PIX_FMT_NONE;
+    f->pkt_ref = av_packet_alloc();
+    if (!f->pkt_ref)
+    return AVERROR(ENOMEM);
+
    if ((ret = ff_ffv1_common_init(avctx, f)) < 0)
    return ret;
@@ -701,6 +705,10 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *rframe,
    /* Start */
    if (hwaccel) {
+    ret = av_packet_ref(f->pkt_ref, avpkt);
+    if (ret < 0)
+    return ret;
+
    ret = hwaccel->start_frame(avctx, avpkt->data, avpkt-

size);

    if (ret < 0)
    return ret;
@@ -720,15 +728,21 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *rframe,
    uint32_t len;
    ret = find_next_slice(avctx, avpkt->data, buf_end, i,
  &pos, &len);
-    if (ret < 0)
+    if (ret < 0) {
+    av_packet_unref(f->pkt_ref);
    return ret;
+    }
    buf_end -= len;
    ret = hwaccel->decode_slice(avctx, pos, len);
-    if (ret < 0)
+    if (ret < 0) {
+    av_packet_unref(f->pkt_ref);
    return ret;
+    }
    }
+
+    av_packet_unref(f->pkt_ref);
    } else {
    ret = decode_slices(avctx, c, avpkt);
    if (ret < 0)
@@ -827,6 +841,7 @@ static av_cold int
ffv1_decode_close(AVCodecContext *avctx)
    ff_progress_frame_unref(&s->last_picture);
    av_refstruct_unref(&s->hwaccel_last_picture_private);
+    av_packet_free(&s->pkt_ref);
    ff_ffv1_close(s);
    return 0;


Why not simply use a const AVPacket*?


No reason. Fixed locally.
Thanks.


*reverted this change.
We need to ref the packet, since we map its memory and let the GPU use
it directly without copying the contents. 6k16bit content at 24fps is
typically around 2Gbps when compressed, so avoiding copies is important.


How long does the hwaccel need this data?


Until the frame has been asynchronously decoded. We give an output frame
with a semaphore that receivers need to wait on to determine when that is.

On the decoder-side, the hardware has a fixed number of queues where
submissions can be sent to asynchronously. We treat it as a ring buffer
and keep a reference to all resources our side for each submission,
until we need to reuse the slot, at which point we wait on the frame
decoding to complete (which it usually has), and we release all
resources used.

Output frames also have a bit of state that has to be freed once the
frame is marked (unreferenced) by the decoder as no longer being needed
as a reference, this is done in the FFHWAccel.free_frame_priv callback.
There, we have to wait for the last internal use of the frame to be
finished (done via the vp->wait_semaphores() call in vulkan_decode.c).

This is valid for both ASIC hardware decoders and a compute shader based
implementation, since the two share the same code, except for decode
submissions.


1. If you need a reference to the packet's data, then reference
AVPacket.buf, not the whole AVPacket. This avoids allocating a spare
AVPacket as well as copying side data.
2. It sounds very wrong and fragile that the decoder has to keep a
reference because the hwaccel might need it. There may be future
hwaccels that don't need such a reference etc. It seems better to extend
e.g. the start_frame callback and pass a reference to the input data (no
need to change this for all other start_frame calls; they can pass NULL
until needed).
3. If the user closes the decoder (which is allowed at any time, even
without draining the decoder), ff_codec_close() uninitializes the
hwaccel after calling the decoder's close function; the latter
unreferences the reference to the packet. Is this really safe?


I wanted to avoid having to change the FFHWAccel API for a single 
hwaccel, so I opted to simply add a field to the codec private context.

I'll add an ar

Re: [FFmpeg-devel] [PATCH 1/1] avformat/avio: add configuration options for IO_BUFFER_SIZE

2025-03-13 Thread Zhao Zhili
On Mar 13, 2025, at 19:30, 姚靖威  wrote:
> 
> protocols like local socket and local file.  In our product, I set
> avio-buffer-size
> value to 1024 in order to reduce memory.The OS we use is based on nuttx, it
> can be used in very small resource chips.

How about runtime option like this?

https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/341107.html

Please don’t top-posting.

> 
> [image: image.png]
> 
> 
> Zhao Zhili  于2025年3月13日周四 18:26写道:
> 
>> 
>> 
>>> On Mar 13, 2025, at 17:40, 姚靖威  wrote:
>>> 
>>> The purpose of this patch is to modify the default buffer size of the
>> avio
>>> module during compilation.
>>> On some resource-constrained devices to save memory, the current default
>>> value (32K), it can also be set to a smaller value.
>> 
>> Which protocol? And what’s the value used to replace the default 32KB?
>> 
>>> 
>>> Nicolas George  于2025年3月11日周二 19:55写道:
>>> 
 joney...@gmail.com (HE12025-03-11):
> From: Jingwei Yao 
> 
> Signed-off-by: Jingwei Yao 
> ---
> configure | 6 ++
> libavformat/aviobuf.c | 2 +-
> 2 files changed, 7 insertions(+), 1 deletion(-)
 
 Thanks for the patch. It is missing the explanations about why.
 
 Regards,
 
 --
 Nicolas George
 ___
 ffmpeg-devel mailing list
 ffmpeg-devel@ffmpeg.org
 https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 
 To unsubscribe, visit link above, or email
 ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
 
>>> ___
>>> ffmpeg-devel 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 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 1/1] avformat/avio: add configuration options for IO_BUFFER_SIZE

2025-03-13 Thread Zhao Zhili


> On Mar 13, 2025, at 17:40, 姚靖威  wrote:
> 
> The purpose of this patch is to modify the default buffer size of the avio
> module during compilation.
> On some resource-constrained devices to save memory, the current default
> value (32K), it can also be set to a smaller value.

Which protocol? And what’s the value used to replace the default 32KB?

> 
> Nicolas George  于2025年3月11日周二 19:55写道:
> 
>> joney...@gmail.com (HE12025-03-11):
>>> From: Jingwei Yao 
>>> 
>>> Signed-off-by: Jingwei Yao 
>>> ---
>>> configure | 6 ++
>>> libavformat/aviobuf.c | 2 +-
>>> 2 files changed, 7 insertions(+), 1 deletion(-)
>> 
>> Thanks for the patch. It is missing the explanations about why.
>> 
>> Regards,
>> 
>> --
>>  Nicolas George
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>> 
> ___
> ffmpeg-devel 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 1/1] avformat/avio: add configuration options for IO_BUFFER_SIZE

2025-03-13 Thread 姚靖威
Zhao Zhili  于2025年3月13日周四 20:50写道:

> On Mar 13, 2025, at 19:30, 姚靖威  wrote:
> >
> > protocols like local socket and local file.  In our product, I set
> > avio-buffer-size
> > value to 1024 in order to reduce memory.The OS we use is based on nuttx,
> it
> > can be used in very small resource chips.
>
> How about runtime option like this?
>
> https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/341107.html
>
> Please don’t top-posting.
>
>

https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/341107.html
it's a better way to implement and can resolve my problem.  Thank you for
your advice!
___
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 v4 04/16] vulkan: copy host-mapping buffer code from hwcontext

2025-03-13 Thread Lynne
This is useful elsewhere.
---
 libavutil/vulkan.c | 163 -
 libavutil/vulkan.h |  18 -
 2 files changed, 178 insertions(+), 3 deletions(-)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 99c6af7e48..235c76d1d0 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1088,6 +1088,8 @@ int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer 
**buf, int nb_buffers,
 .memory = buf[i]->mem,
 .size   = VK_WHOLE_SIZE,
 };
+
+av_assert0(!buf[i]->host_ref);
 if (buf[i]->flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
 continue;
 flush_list[flush_count++] = flush_buf;
@@ -1119,12 +1121,18 @@ void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
 if (!buf || !s->hwctx)
 return;
 
-if (buf->mapped_mem)
+if (buf->mapped_mem && !buf->host_ref)
 ff_vk_unmap_buffer(s, buf, 0);
 if (buf->buf != VK_NULL_HANDLE)
 vk->DestroyBuffer(s->hwctx->act_dev, buf->buf, s->hwctx->alloc);
 if (buf->mem != VK_NULL_HANDLE)
 vk->FreeMemory(s->hwctx->act_dev, buf->mem, s->hwctx->alloc);
+if (buf->host_ref)
+av_buffer_unref(&buf->host_ref);
+
+buf->buf = VK_NULL_HANDLE;
+buf->mem = VK_NULL_HANDLE;
+buf->mapped_mem = NULL;
 }
 
 static void free_data_buf(void *opaque, uint8_t *data)
@@ -1201,6 +1209,157 @@ int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, 
AVBufferPool **buf_pool,
 return 0;
 }
 
+static int create_mapped_buffer(FFVulkanContext *s,
+FFVkBuffer *vkb, VkBufferUsageFlags usage,
+size_t size,
+VkExternalMemoryBufferCreateInfo *create_desc,
+VkImportMemoryHostPointerInfoEXT *import_desc,
+VkMemoryHostPointerPropertiesEXT props)
+{
+int err;
+VkResult ret;
+FFVulkanFunctions *vk = &s->vkfn;
+
+VkBufferCreateInfo buf_spawn = {
+.sType   = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
+.pNext   = create_desc,
+.usage   = usage,
+.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
+.size= size,
+};
+VkMemoryRequirements req = {
+.size   = size,
+.alignment  = s->hprops.minImportedHostPointerAlignment,
+.memoryTypeBits = props.memoryTypeBits,
+};
+
+err = ff_vk_alloc_mem(s, &req,
+  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
+  import_desc, &vkb->flags, &vkb->mem);
+if (err < 0)
+return err;
+
+ret = vk->CreateBuffer(s->hwctx->act_dev, &buf_spawn, s->hwctx->alloc, 
&vkb->buf);
+if (ret != VK_SUCCESS) {
+vk->FreeMemory(s->hwctx->act_dev, vkb->mem, s->hwctx->alloc);
+return AVERROR_EXTERNAL;
+}
+
+ret = vk->BindBufferMemory(s->hwctx->act_dev, vkb->buf, vkb->mem, 0);
+if (ret != VK_SUCCESS) {
+vk->FreeMemory(s->hwctx->act_dev, vkb->mem, s->hwctx->alloc);
+vk->DestroyBuffer(s->hwctx->act_dev, vkb->buf, s->hwctx->alloc);
+return AVERROR_EXTERNAL;
+}
+
+return 0;
+}
+
+static void destroy_avvkbuf(void *opaque, uint8_t *data)
+{
+FFVulkanContext *s = opaque;
+FFVkBuffer *buf = (FFVkBuffer *)data;
+ff_vk_free_buf(s, buf);
+av_free(buf);
+}
+
+int ff_vk_host_map_buffer(FFVulkanContext *s, AVBufferRef **dst,
+  uint8_t *src_data, AVBufferRef *src_buf,
+  VkBufferUsageFlags usage)
+{
+int err;
+VkResult ret;
+FFVulkanFunctions *vk = &s->vkfn;
+
+VkExternalMemoryBufferCreateInfo create_desc = {
+.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
+.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
+};
+VkMemoryAllocateFlagsInfo alloc_flags = {
+.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO,
+.flags = VK_MEMORY_ALLOCATE_DEVICE_ADDRESS_BIT,
+};
+VkImportMemoryHostPointerInfoEXT import_desc = {
+.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT,
+.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
+.pNext = usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT ? 
&alloc_flags : NULL,
+};
+VkMemoryHostPointerPropertiesEXT props;
+
+AVBufferRef *ref;
+FFVkBuffer *vkb;
+size_t offs;
+size_t buffer_size;
+
+*dst = NULL;
+
+/* Get the previous point at which mapping was possible and use it */
+offs = (uintptr_t)src_data % s->hprops.minImportedHostPointerAlignment;
+import_desc.pHostPointer = src_data - offs;
+
+props = (VkMemoryHostPointerPropertiesEXT) {
+VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT,
+};
+ret = vk->GetMemoryHostPointerPropertiesEXT(s->hwctx->act_dev,
+import_desc.handleType,
+   

[FFmpeg-devel] [PATCH v4 03/16] vulkan: add ff_vk_create_imageview

2025-03-13 Thread Lynne
---
 libavutil/vulkan.c | 51 ++
 libavutil/vulkan.h |  7 +++
 2 files changed, 58 insertions(+)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 3020f01bee..99c6af7e48 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1560,6 +1560,57 @@ static VkFormat map_fmt_to_rep(VkFormat fmt, enum 
FFVkShaderRepFormat rep_fmt)
 return VK_FORMAT_UNDEFINED;
 }
 
+int ff_vk_create_imageview(FFVulkanContext *s,
+   VkImageView *img_view, VkImageAspectFlags *aspect,
+   AVFrame *f, int plane, enum FFVkShaderRepFormat 
rep_fmt)
+{
+VkResult ret;
+FFVulkanFunctions *vk = &s->vkfn;
+AVHWFramesContext *hwfc = (AVHWFramesContext *)f->hw_frames_ctx->data;
+AVVulkanFramesContext *vkfc = hwfc->hwctx;
+const VkFormat *rep_fmts = av_vkfmt_from_pixfmt(hwfc->sw_format);
+AVVkFrame *vkf = (AVVkFrame *)f->data[0];
+const int nb_images = ff_vk_count_images(vkf);
+
+VkImageViewUsageCreateInfo view_usage_info = {
+.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO,
+.usage = vkfc->usage &
+ (~(VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR |
+VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)),
+};
+VkImageViewCreateInfo view_create_info = {
+.sType  = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
+.pNext  = &view_usage_info,
+.image  = vkf->img[FFMIN(plane, nb_images - 1)],
+.viewType   = VK_IMAGE_VIEW_TYPE_2D,
+.format = map_fmt_to_rep(rep_fmts[plane], rep_fmt),
+.components = ff_comp_identity_map,
+.subresourceRange = {
+.aspectMask = ff_vk_aspect_flag(f, plane),
+.levelCount = 1,
+.layerCount = 1,
+},
+};
+if (view_create_info.format == VK_FORMAT_UNDEFINED) {
+av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "
+"of format %i and mode %i\n",
+   rep_fmts[plane], rep_fmt);
+return AVERROR(EINVAL);
+}
+
+ret = vk->CreateImageView(s->hwctx->act_dev, &view_create_info,
+  s->hwctx->alloc, img_view);
+if (ret != VK_SUCCESS) {
+av_log(s, AV_LOG_ERROR, "Failed to create imageview: %s\n",
+   ff_vk_ret2str(ret));
+return AVERROR_EXTERNAL;
+}
+
+*aspect = view_create_info.subresourceRange.aspectMask;
+
+return 0;
+}
+
 int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
 VkImageView views[AV_NUM_DATA_POINTERS],
 AVFrame *f, enum FFVkShaderRepFormat rep_fmt)
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index b0db5b2396..baf9dc2009 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -457,6 +457,13 @@ int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, 
FFVkExecContext *e,
 AVFrame *f);
 void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e);
 
+/**
+ * Create a single imageview for a given plane.
+ */
+int ff_vk_create_imageview(FFVulkanContext *s,
+   VkImageView *img_view, VkImageAspectFlags *aspect,
+   AVFrame *f, int plane, enum FFVkShaderRepFormat 
rep_fmt);
+
 /**
  * Create an imageview and add it as a dependency to an execution.
  */
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 05/16] hwcontext_vulkan: use the common host map function to map frame data

2025-03-13 Thread Lynne
---
 libavutil/hwcontext_vulkan.c | 190 ++-
 1 file changed, 54 insertions(+), 136 deletions(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index fcff34b5e2..1104e02cfd 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -4033,155 +4033,73 @@ static int get_plane_buf(AVHWFramesContext *hwfc, 
AVBufferRef **dst,
 return 0;
 }
 
-static int create_mapped_buffer(AVHWFramesContext *hwfc,
-FFVkBuffer *vkb, VkBufferUsageFlags usage,
-size_t size,
-VkExternalMemoryBufferCreateInfo *create_desc,
-VkImportMemoryHostPointerInfoEXT *import_desc,
-VkMemoryHostPointerPropertiesEXT props)
-{
-int err;
-VkResult ret;
-VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
-FFVulkanFunctions *vk = &p->vkctx.vkfn;
-AVVulkanDeviceContext *hwctx = &p->p;
-
-VkBufferCreateInfo buf_spawn = {
-.sType   = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
-.pNext   = create_desc,
-.usage   = usage,
-.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
-.size= size,
-};
-VkMemoryRequirements req = {
-.size   = size,
-.alignment  = p->hprops.minImportedHostPointerAlignment,
-.memoryTypeBits = props.memoryTypeBits,
-};
-
-err = ff_vk_alloc_mem(&p->vkctx, &req,
-  VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
-  import_desc, &vkb->flags, &vkb->mem);
-if (err < 0)
-return err;
-
-ret = vk->CreateBuffer(hwctx->act_dev, &buf_spawn, hwctx->alloc, 
&vkb->buf);
-if (ret != VK_SUCCESS) {
-vk->FreeMemory(hwctx->act_dev, vkb->mem, hwctx->alloc);
-return AVERROR_EXTERNAL;
-}
-
-ret = vk->BindBufferMemory(hwctx->act_dev, vkb->buf, vkb->mem, 0);
-if (ret != VK_SUCCESS) {
-vk->FreeMemory(hwctx->act_dev, vkb->mem, hwctx->alloc);
-vk->DestroyBuffer(hwctx->act_dev, vkb->buf, hwctx->alloc);
-return AVERROR_EXTERNAL;
-}
-
-return 0;
-}
-
-static void destroy_avvkbuf(void *opaque, uint8_t *data)
-{
-FFVulkanContext *s = opaque;
-FFVkBuffer *buf = (FFVkBuffer *)data;
-ff_vk_free_buf(s, buf);
-av_free(buf);
-}
-
 static int host_map_frame(AVHWFramesContext *hwfc, AVBufferRef **dst, int 
*nb_bufs,
   AVFrame *swf, VkBufferImageCopy *region, int upload)
 {
 int err;
-VkResult ret;
 VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
-FFVulkanFunctions *vk = &p->vkctx.vkfn;
-AVVulkanDeviceContext *hwctx = &p->p;
 
+uint32_t p_w, p_h;
+int nb_src_bufs = 0;
 const int planes = av_pix_fmt_count_planes(swf->format);
 
-VkExternalMemoryBufferCreateInfo create_desc = {
-.sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
-.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
-};
-VkImportMemoryHostPointerInfoEXT import_desc = {
-.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT,
-.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
-};
-VkMemoryHostPointerPropertiesEXT props;
-
-for (int i = 0; i < planes; i++) {
-FFVkBuffer *vkb;
-uint32_t p_w, p_h;
-size_t offs;
-size_t buffer_size;
-
-/* We can't host map images with negative strides */
-if (swf->linesize[i] < 0) {
-err = AVERROR(EINVAL);
-goto fail;
-}
-
-get_plane_wh(&p_w, &p_h, swf->format, swf->width, swf->height, i);
-
-/* Get the previous point at which mapping was possible and use it */
-offs = (uintptr_t)swf->data[i] % 
p->hprops.minImportedHostPointerAlignment;
-import_desc.pHostPointer = swf->data[i] - offs;
-
-props = (VkMemoryHostPointerPropertiesEXT) {
-VK_STRUCTURE_TYPE_MEMORY_HOST_POINTER_PROPERTIES_EXT,
-};
-ret = vk->GetMemoryHostPointerPropertiesEXT(hwctx->act_dev,
-import_desc.handleType,
-import_desc.pHostPointer,
-&props);
-if (!(ret == VK_SUCCESS && props.memoryTypeBits)) {
-err = AVERROR(EINVAL);
-goto fail;
-}
-
-/* Buffer region for this plane */
-region[i] = (VkBufferImageCopy) {
-.bufferOffset = offs,
-.bufferRowLength = swf->linesize[i],
-.bufferImageHeight = p_h,
-.imageSubresource.layerCount = 1,
-.imageExtent = (VkExtent3D){ p_w, p_h, 1 },
-/* Rest of the fields adjusted/filled in later */
-};
+/* We can't host map images with negative strides */
+for (int i = 0; i < planes; i++)
+if (s

[FFmpeg-devel] [PATCH v4 01/16] pixfmt: add AV_PIX_FMT_GBRAP32

2025-03-13 Thread Lynne
This commit adds a 32-bit *integer* planar RGBA format.
Vulkan FFv1 decoding is best performed on separate planes, rather than
packed RGBA (i.e. RGBA128), hence this is useful as an intermediate format.
---
 libavutil/pixdesc.c | 28 
 libavutil/pixfmt.h  |  4 
 2 files changed, 32 insertions(+)

diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c
index 1917ae74d8..53adde5aba 100644
--- a/libavutil/pixdesc.c
+++ b/libavutil/pixdesc.c
@@ -1991,6 +1991,34 @@ static const AVPixFmtDescriptor 
av_pix_fmt_descriptors[AV_PIX_FMT_NB] = {
 .flags = AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_PLANAR |
  AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_ALPHA,
 },
+[AV_PIX_FMT_GBRAP32LE] = {
+.name = "gbrap32le",
+.nb_components = 4,
+.log2_chroma_w = 0,
+.log2_chroma_h = 0,
+.comp = {
+{ 2, 4, 0, 0, 32 },   /* R */
+{ 0, 4, 0, 0, 32 },   /* G */
+{ 1, 4, 0, 0, 32 },   /* B */
+{ 3, 4, 0, 0, 32 },   /* A */
+},
+.flags = AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB |
+ AV_PIX_FMT_FLAG_ALPHA,
+},
+[AV_PIX_FMT_GBRAP32BE] = {
+.name = "gbrap32be",
+.nb_components = 4,
+.log2_chroma_w = 0,
+.log2_chroma_h = 0,
+.comp = {
+{ 2, 4, 0, 0, 32 },   /* R */
+{ 0, 4, 0, 0, 32 },   /* G */
+{ 1, 4, 0, 0, 32 },   /* B */
+{ 3, 4, 0, 0, 32 },   /* A */
+},
+.flags = AV_PIX_FMT_FLAG_BE | AV_PIX_FMT_FLAG_PLANAR |
+ AV_PIX_FMT_FLAG_RGB | AV_PIX_FMT_FLAG_ALPHA,
+},
 [AV_PIX_FMT_VDPAU] = {
 .name = "vdpau",
 .log2_chroma_w = 1,
diff --git a/libavutil/pixfmt.h b/libavutil/pixfmt.h
index e6d2b08c5c..bf1b8ed008 100644
--- a/libavutil/pixfmt.h
+++ b/libavutil/pixfmt.h
@@ -485,6 +485,9 @@ enum AVPixelFormat {
 AV_PIX_FMT_YAF16BE,  ///< IEEE-754 half precision packed YA, 16 bits gray, 
16 bits alpha, 32bpp, big-endian
 AV_PIX_FMT_YAF16LE,  ///< IEEE-754 half precision packed YA, 16 bits gray, 
16 bits alpha, 32bpp, little-endian
 
+AV_PIX_FMT_GBRAP32BE,   ///< planar GBRA 4:4:4:4 128bpp, big-endian
+AV_PIX_FMT_GBRAP32LE,   ///< planar GBRA 4:4:4:4 128bpp, little-endian
+
 AV_PIX_FMT_NB ///< number of pixel formats, DO NOT USE THIS if you 
want to link with shared libav* because the number of formats might differ 
between versions
 };
 
@@ -546,6 +549,7 @@ enum AVPixelFormat {
 #define AV_PIX_FMT_GBRAP12   AV_PIX_FMT_NE(GBRAP12BE,   GBRAP12LE)
 #define AV_PIX_FMT_GBRAP14   AV_PIX_FMT_NE(GBRAP14BE,   GBRAP14LE)
 #define AV_PIX_FMT_GBRAP16   AV_PIX_FMT_NE(GBRAP16BE,   GBRAP16LE)
+#define AV_PIX_FMT_GBRAP32   AV_PIX_FMT_NE(GBRAP32BE,   GBRAP32LE)
 
 #define AV_PIX_FMT_BAYER_BGGR16 AV_PIX_FMT_NE(BAYER_BGGR16BE,
BAYER_BGGR16LE)
 #define AV_PIX_FMT_BAYER_RGGB16 AV_PIX_FMT_NE(BAYER_RGGB16BE,
BAYER_RGGB16LE)
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 06/16] vulkan: workaround BGR storage image undefined behaviour

2025-03-13 Thread Lynne
---
 libavutil/vulkan.c | 25 +
 1 file changed, 25 insertions(+)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 235c76d1d0..e517a42b86 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1719,6 +1719,29 @@ static VkFormat map_fmt_to_rep(VkFormat fmt, enum 
FFVkShaderRepFormat rep_fmt)
 return VK_FORMAT_UNDEFINED;
 }
 
+static void bgr_workaround(AVVulkanFramesContext *vkfc,
+   VkImageViewCreateInfo *ci)
+{
+if (!(vkfc->usage & VK_IMAGE_USAGE_STORAGE_BIT))
+return;
+switch (ci->format) {
+#define REMAP(src, dst)   \
+case src: \
+ci->format = dst; \
+return;
+REMAP(VK_FORMAT_B8G8R8A8_UNORM,   VK_FORMAT_R8G8B8A8_UNORM)
+REMAP(VK_FORMAT_B8G8R8A8_SINT,VK_FORMAT_R8G8B8A8_SINT)
+REMAP(VK_FORMAT_B8G8R8A8_UINT,VK_FORMAT_R8G8B8A8_UINT)
+REMAP(VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM)
+REMAP(VK_FORMAT_B8G8R8_SINT,  VK_FORMAT_R8G8B8_SINT)
+REMAP(VK_FORMAT_B8G8R8_UINT,  VK_FORMAT_R8G8B8_UINT)
+REMAP(VK_FORMAT_A2B10G10R10_UNORM_PACK32, 
VK_FORMAT_A2R10G10B10_UNORM_PACK32)
+#undef REMAP
+default:
+return;
+}
+}
+
 int ff_vk_create_imageview(FFVulkanContext *s,
VkImageView *img_view, VkImageAspectFlags *aspect,
AVFrame *f, int plane, enum FFVkShaderRepFormat 
rep_fmt)
@@ -1750,6 +1773,7 @@ int ff_vk_create_imageview(FFVulkanContext *s,
 .layerCount = 1,
 },
 };
+bgr_workaround(vkfc, &view_create_info);
 if (view_create_info.format == VK_FORMAT_UNDEFINED) {
 av_log(s, AV_LOG_ERROR, "Unable to find a compatible representation "
 "of format %i and mode %i\n",
@@ -1811,6 +1835,7 @@ int ff_vk_create_imageviews(FFVulkanContext *s, 
FFVkExecContext *e,
 .layerCount = 1,
 },
 };
+bgr_workaround(vkfc, &view_create_info);
 if (view_create_info.format == VK_FORMAT_UNDEFINED) {
 av_log(s, AV_LOG_ERROR, "Unable to find a compatible 
representation "
 "of format %i and mode %i\n",
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 08/16] vulkan_decode: support multiple image views

2025-03-13 Thread Lynne
Enables non-monochrome video decoding using all our existing functions
in the context of an SDR decoder.
---
 libavcodec/vulkan_av1.c|  4 +-
 libavcodec/vulkan_decode.c | 90 --
 libavcodec/vulkan_decode.h | 12 ++---
 libavcodec/vulkan_h264.c   |  4 +-
 libavcodec/vulkan_hevc.c   |  4 +-
 5 files changed, 60 insertions(+), 54 deletions(-)

diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c
index 6659f9d812..7dd7b204d7 100644
--- a/libavcodec/vulkan_av1.c
+++ b/libavcodec/vulkan_av1.c
@@ -123,7 +123,7 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const 
AV1Frame **ref_src,
 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
 .baseArrayLayer = ((has_grain || dec->dedicated_dpb) && 
ctx->common.layered_dpb) ?
   hp->frame_id : 0,
-.imageViewBinding = vkpic->img_view_ref,
+.imageViewBinding = vkpic->view.ref[0],
 };
 
 *ref_slot = (VkVideoReferenceSlotInfoKHR) {
@@ -346,7 +346,7 @@ static int vk_av1_start_frame(AVCodecContext  
*avctx,
 .codedOffset = (VkOffset2D){ 0, 0 },
 .codedExtent = (VkExtent2D){ pic->f->width, pic->f->height },
 .baseArrayLayer = 0,
-.imageViewBinding = vp->img_view_out,
+.imageViewBinding = vp->view.out[0],
 },
 };
 
diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 594764a904..7f638d6fc6 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -130,9 +130,11 @@ static void init_frame(FFVulkanDecodeContext *dec, 
FFVulkanDecodePicture *vkpic)
 FFVulkanFunctions *vk = &ctx->s.vkfn;
 
 vkpic->dpb_frame = NULL;
-vkpic->img_view_ref  = VK_NULL_HANDLE;
-vkpic->img_view_out  = VK_NULL_HANDLE;
-vkpic->img_view_dest = VK_NULL_HANDLE;
+for (int i = 0; i < AV_NUM_DATA_POINTERS; i++) {
+vkpic->view.ref[i]  = VK_NULL_HANDLE;
+vkpic->view.out[i]  = VK_NULL_HANDLE;
+vkpic->view.dst[i]  = VK_NULL_HANDLE;
+}
 
 vkpic->destroy_image_view = vk->DestroyImageView;
 vkpic->wait_semaphores = vk->WaitSemaphores;
@@ -149,14 +151,14 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext 
*dec, AVFrame *pic,
 
 /* If the decoder made a blank frame to make up for a missing ref, or the
  * frame is the current frame so it's missing one, create a 
re-representation */
-if (vkpic->img_view_ref)
+if (vkpic->view.ref[0])
 return 0;
 
 init_frame(dec, vkpic);
 
 if (ctx->common.layered_dpb && alloc_dpb) {
-vkpic->img_view_ref = ctx->common.layered_view;
-vkpic->img_aspect_ref = ctx->common.layered_aspect;
+vkpic->view.ref[0] = ctx->common.layered_view;
+vkpic->view.aspect_ref[0] = ctx->common.layered_aspect;
 } else if (alloc_dpb) {
 AVHWFramesContext *dpb_frames = (AVHWFramesContext 
*)ctx->common.dpb_hwfc_ref->data;
 AVVulkanFramesContext *dpb_hwfc = dpb_frames->hwctx;
@@ -166,13 +168,13 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext 
*dec, AVFrame *pic,
 return AVERROR(ENOMEM);
 
 err = ff_vk_create_view(&ctx->s, &ctx->common,
-&vkpic->img_view_ref, &vkpic->img_aspect_ref,
+&vkpic->view.ref[0], 
&vkpic->view.aspect_ref[0],
 (AVVkFrame *)vkpic->dpb_frame->data[0],
 dpb_hwfc->format[0], !is_current);
 if (err < 0)
 return err;
 
-vkpic->img_view_dest = vkpic->img_view_ref;
+vkpic->view.dst[0] = vkpic->view.ref[0];
 }
 
 if (!alloc_dpb || is_current) {
@@ -180,15 +182,15 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext 
*dec, AVFrame *pic,
 AVVulkanFramesContext *hwfc = frames->hwctx;
 
 err = ff_vk_create_view(&ctx->s, &ctx->common,
-&vkpic->img_view_out, &vkpic->img_aspect,
+&vkpic->view.out[0], &vkpic->view.aspect[0],
 (AVVkFrame *)pic->data[0],
 hwfc->format[0], !is_current);
 if (err < 0)
 return err;
 
 if (!alloc_dpb) {
-vkpic->img_view_ref = vkpic->img_view_out;
-vkpic->img_aspect_ref = vkpic->img_aspect;
+vkpic->view.ref[0] = vkpic->view.out[0];
+vkpic->view.aspect_ref[0] = vkpic->view.aspect[0];
 }
 }
 
@@ -201,41 +203,41 @@ int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext 
*dec, AVFrame *pic,
 {
 int err;
 FFVulkanDecodeShared *ctx = dec->shared_ctx;
+AVHWFramesContext *frames = (AVHWFramesContext *)pic->hw_frames_ctx->data;
 
 vkpic->slices_size = 0;
 
-if (vkpic->img_view_ref)
+if (vkpic->view.ref[0])
 return 0;
 
 init_frame(dec, vkpic);
 
-if (ctx->common.layered_dpb && alloc_dpb) {
-vkpic->img_view_ref = ctx->common.

[FFmpeg-devel] [PATCH v4 10/16] ffv1enc_vulkan: refactor shaders slightly to support sharing

2025-03-13 Thread Lynne
The shaders were written to support sharing, but needed slight
tweaking.
---
 libavcodec/Makefile   |   2 +-
 libavcodec/ffv1_vulkan.c  | 123 ++
 libavcodec/ffv1_vulkan.h  |  60 +++
 libavcodec/ffv1enc_vulkan.c   | 234 +-
 libavcodec/vulkan/ffv1_common.comp|  24 ++-
 libavcodec/vulkan/ffv1_enc_setup.comp |  18 +-
 libavcodec/vulkan/ffv1_reset.comp |   3 +-
 libavcodec/vulkan/rangecoder.comp |  27 +--
 8 files changed, 302 insertions(+), 189 deletions(-)
 create mode 100644 libavcodec/ffv1_vulkan.c
 create mode 100644 libavcodec/ffv1_vulkan.h

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3c7043a617..5522ed43e5 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -371,7 +371,7 @@ OBJS-$(CONFIG_EXR_ENCODER) += exrenc.o 
float2half.o
 OBJS-$(CONFIG_FASTAUDIO_DECODER)   += fastaudio.o
 OBJS-$(CONFIG_FFV1_DECODER)+= ffv1dec.o ffv1_parse.o ffv1.o
 OBJS-$(CONFIG_FFV1_ENCODER)+= ffv1enc.o ffv1_parse.o ffv1.o
-OBJS-$(CONFIG_FFV1_VULKAN_ENCODER) += ffv1enc.o ffv1.o ffv1enc_vulkan.o
+OBJS-$(CONFIG_FFV1_VULKAN_ENCODER) += ffv1enc.o ffv1.o ffv1_vulkan.o 
ffv1enc_vulkan.o
 OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o
 OBJS-$(CONFIG_FIC_DECODER) += fic.o
 OBJS-$(CONFIG_FITS_DECODER)+= fitsdec.o fits.o
diff --git a/libavcodec/ffv1_vulkan.c b/libavcodec/ffv1_vulkan.c
new file mode 100644
index 00..6f49e2ebb1
--- /dev/null
+++ b/libavcodec/ffv1_vulkan.c
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2025 Lynne 
+ *
+ * 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 "ffv1_vulkan.h"
+#include "libavutil/crc.h"
+
+int ff_ffv1_vk_update_state_transition_data(FFVulkanContext *s,
+FFVkBuffer *vkb, FFV1Context *f)
+{
+int err;
+uint8_t *buf_mapped;
+
+RET(ff_vk_map_buffer(s, vkb, &buf_mapped, 0));
+
+for (int i = 1; i < 256; i++) {
+buf_mapped[256 + i] = f->state_transition[i];
+buf_mapped[256 - i] = 256 - (int)f->state_transition[i];
+}
+
+RET(ff_vk_unmap_buffer(s, vkb, 1));
+
+fail:
+return err;
+}
+
+static int init_state_transition_data(FFVulkanContext *s,
+  FFVkBuffer *vkb, FFV1Context *f,
+  int (*write_data)(FFVulkanContext *s,
+FFVkBuffer *vkb, 
FFV1Context *f))
+{
+int err;
+size_t buf_len = 512*sizeof(uint8_t);
+
+RET(ff_vk_create_buf(s, vkb,
+ buf_len,
+ NULL, NULL,
+ VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
+ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
+
+write_data(s, vkb, f);
+
+fail:
+return err;
+}
+
+int ff_ffv1_vk_init_state_transition_data(FFVulkanContext *s,
+  FFVkBuffer *vkb, FFV1Context *f)
+{
+return init_state_transition_data(s, vkb, f,
+  ff_ffv1_vk_update_state_transition_data);
+}
+
+int ff_ffv1_vk_init_quant_table_data(FFVulkanContext *s,
+ FFVkBuffer *vkb, FFV1Context *f)
+{
+int err;
+
+int16_t *buf_mapped;
+size_t buf_len = MAX_QUANT_TABLES*
+ MAX_CONTEXT_INPUTS*
+ MAX_QUANT_TABLE_SIZE*sizeof(int16_t);
+
+RET(ff_vk_create_buf(s, vkb,
+ buf_len,
+ NULL, NULL,
+ VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT |
+ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
+ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
+ VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
+RET(ff_vk_map_buffer(s, vkb, (void *)&buf_mapped, 0));
+
+memcpy(buf_mapped, f->quant_tables,
+   sizeof(f->quant_tables));
+
+RET(ff_vk_unmap_buffer(s, vkb, 1));
+
+fail:
+return err;
+}
+
+int ff_ffv1_vk_init_crc_table_data(FFVulkanContext *s,
+

[FFmpeg-devel] [PATCH v4 09/16] vulkan_decode: adjust number of async contexts created

2025-03-13 Thread Lynne
This caps the number of contexts we create based on thread count.
This saves VRAM and filters out cases where more async is of lesser
benefit.
---
 libavcodec/vulkan_decode.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index 7f638d6fc6..cd77e10e12 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -1122,6 +1122,7 @@ int ff_vk_decode_init(AVCodecContext *avctx)
 FFVulkanDecodeShared *ctx;
 FFVulkanContext *s;
 FFVulkanFunctions *vk;
+int async_depth;
 const VkVideoProfileInfoKHR *profile;
 const FFVulkanDecodeDescriptor *vk_desc;
 const VkPhysicalDeviceDriverProperties *driver_props;
@@ -1191,9 +1192,14 @@ int ff_vk_decode_init(AVCodecContext *avctx)
 /* Create decode exec context for this specific main thread.
  * 2 async contexts per thread was experimentally determined to be optimal
  * for a majority of streams. */
+async_depth = 2*ctx->qf->num;
+/* We don't need more than 2 per thread context */
+async_depth = FFMIN(async_depth, 2*avctx->thread_count);
+/* Make sure there are enough async contexts for each thread */
+async_depth = FFMAX(async_depth, avctx->thread_count);
+
 err = ff_vk_exec_pool_init(s, ctx->qf, &ctx->exec_pool,
-   FFMAX(2*ctx->qf->num, avctx->thread_count),
-   0, 0, 0, profile);
+   async_depth, 0, 0, 0, profile);
 if (err < 0)
 goto fail;
 
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 11/16] vulkan: unify handling of BGR and simplify ffv1_rct

2025-03-13 Thread Lynne
---
 libavcodec/ffv1_vulkan.h|  1 +
 libavcodec/ffv1enc_vulkan.c |  2 ++
 libavcodec/vulkan/ffv1_enc_rct.comp | 17 ++---
 libavutil/vulkan.c  | 38 +
 libavutil/vulkan.h  |  6 +
 5 files changed, 54 insertions(+), 10 deletions(-)

diff --git a/libavcodec/ffv1_vulkan.h b/libavcodec/ffv1_vulkan.h
index 0da6dc2d33..599afae66e 100644
--- a/libavcodec/ffv1_vulkan.h
+++ b/libavcodec/ffv1_vulkan.h
@@ -37,6 +37,7 @@ int ff_ffv1_vk_init_crc_table_data(FFVulkanContext *s,
FFVkBuffer *vkb, FFV1Context *f);
 
 typedef struct FFv1VkRCTParameters {
+int fmt_lut[4];
 int offset;
 uint8_t bits;
 uint8_t planar_rgb;
diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c
index 17a93834f3..f8fe3bec1a 100644
--- a/libavcodec/ffv1enc_vulkan.c
+++ b/libavcodec/ffv1enc_vulkan.c
@@ -264,6 +264,7 @@ static int run_rct(AVCodecContext *avctx, FFVkExecContext 
*exec,
   (ff_vk_count_images((AVVkFrame *)enc_in->data[0]) > 1),
 .transparency = f->transparency,
 };
+ff_vk_set_perm(src_hwfc->sw_format, pd.fmt_lut);
 ff_vk_shader_update_push_const(&fv->s, exec, &fv->rct,
VK_SHADER_STAGE_COMPUTE_BIT,
0, sizeof(pd), &pd);
@@ -1157,6 +1158,7 @@ static int init_rct_shader(AVCodecContext *avctx, 
FFVkSPIRVCompiler *spv)
 GLSLD(ff_source_common_comp);
 
 GLSLC(0, layout(push_constant, scalar) uniform pushConstants { 
);
+GLSLC(1,ivec4 fmt_lut; 
);
 GLSLC(1,int offset;
);
 GLSLC(1,uint8_t bits;  
);
 GLSLC(1,uint8_t planar_rgb;
);
diff --git a/libavcodec/vulkan/ffv1_enc_rct.comp 
b/libavcodec/vulkan/ffv1_enc_rct.comp
index a615381c90..b611f4be98 100644
--- a/libavcodec/vulkan/ffv1_enc_rct.comp
+++ b/libavcodec/vulkan/ffv1_enc_rct.comp
@@ -22,17 +22,14 @@
 
 ivec4 load_components(ivec2 pos)
 {
-if (planar_rgb == 0)
-return ivec4(imageLoad(src[0], pos));
+ivec4 pix = ivec4(imageLoad(src[0], pos));
+if (planar_rgb != 0) {
+for (int i = 1; i < (3 + transparency); i++)
+pix[i] = int(imageLoad(src[i], pos)[0]);
+}
 
-ivec4 pix;
-for (int i = 0; i < (3 + transparency); i++)
-pix[i] = int(imageLoad(src[i], pos)[0]);
-
-/* Swizzle out the difference */
-if (bits > 8 && bits < 16 && transparency == 0)
-return pix.bgra;
-return pix.brga;
+return ivec4(pix[fmt_lut[0]], pix[fmt_lut[1]],
+ pix[fmt_lut[2]], pix[fmt_lut[3]]);
 }
 
 void bypass_sample(ivec2 pos)
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index e517a42b86..b7cdc3a086 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1451,6 +1451,44 @@ int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
 return 0;
 }
 
+void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4])
+{
+switch (pix_fmt) {
+case AV_PIX_FMT_BGRA:
+case AV_PIX_FMT_BGR0:
+case AV_PIX_FMT_BGR565:
+case AV_PIX_FMT_X2BGR10:
+lut[0] = 2;
+lut[1] = 1;
+lut[2] = 0;
+lut[3] = 3;
+return;
+case AV_PIX_FMT_GBRAP:
+case AV_PIX_FMT_GBRP:
+case AV_PIX_FMT_GBRAP10:
+case AV_PIX_FMT_GBRAP12:
+case AV_PIX_FMT_GBRAP14:
+case AV_PIX_FMT_GBRAP16:
+case AV_PIX_FMT_GBRP10:
+case AV_PIX_FMT_GBRP12:
+case AV_PIX_FMT_GBRP14:
+case AV_PIX_FMT_GBRP16:
+case AV_PIX_FMT_GBRPF32:
+case AV_PIX_FMT_GBRAPF32:
+lut[0] = 1;
+lut[1] = 0;
+lut[2] = 2;
+lut[3] = 3;
+return;
+default:
+lut[0] = 0;
+lut[1] = 1;
+lut[2] = 2;
+lut[3] = 3;
+return;
+}
+}
+
 const char *ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt,
  enum FFVkShaderRepFormat rep_fmt)
 {
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 29249fe95d..ef2c2fe4a2 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -371,6 +371,12 @@ const char *ff_vk_ret2str(VkResult res);
  */
 int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt);
 
+/**
+ * Since storage images may not be swizzled, we have to do this in the
+ * shader itself. This fills in a lookup table to do it.
+ */
+void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int lut[4]);
+
 /**
  * Get the aspect flag for a plane from an image.
  */
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 12/16] vulkan: add ff_vk_exec_add_dep_wait_sem()

2025-03-13 Thread Lynne
This adds a function which adds a regular timeline semaphore
as a wait-only dependency.
---
 libavutil/vulkan.c | 28 
 libavutil/vulkan.h |  3 +++
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index b7cdc3a086..08d042a195 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -620,6 +620,23 @@ static void destroy_tmp_semaphores(void *opaque, uint8_t 
*data)
 av_free(ts);
 }
 
+int ff_vk_exec_add_dep_wait_sem(FFVulkanContext *s, FFVkExecContext *e,
+VkSemaphore sem, uint64_t val,
+VkPipelineStageFlagBits2 stage)
+{
+VkSemaphoreSubmitInfo *sem_wait;
+ARR_REALLOC(e, sem_wait, &e->sem_wait_alloc, e->sem_wait_cnt);
+
+e->sem_wait[e->sem_wait_cnt++] = (VkSemaphoreSubmitInfo) {
+.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
+.semaphore = sem,
+.value = val,
+.stageMask = stage,
+};
+
+return 0;
+}
+
 int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e,
 VkSemaphore *sem, int nb,
 VkPipelineStageFlagBits2 stage,
@@ -672,14 +689,9 @@ int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, 
FFVkExecContext *e,
 }
 
 for (int i = 0; i < nb; i++) {
-VkSemaphoreSubmitInfo *sem_wait;
-ARR_REALLOC(e, sem_wait, &e->sem_wait_alloc, e->sem_wait_cnt);
-
-e->sem_wait[e->sem_wait_cnt++] = (VkSemaphoreSubmitInfo) {
-.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
-.semaphore = sem[i],
-.stageMask = stage,
-};
+err = ff_vk_exec_add_dep_wait_sem(s, e, sem[i], 0, stage);
+if (err < 0)
+return err;
 }
 
 return 0;
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index ef2c2fe4a2..5f5f4e1fc4 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -456,6 +456,9 @@ void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext 
*e);
  */
 int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e,
AVBufferRef **deps, int nb_deps, int ref);
+int ff_vk_exec_add_dep_wait_sem(FFVulkanContext *s, FFVkExecContext *e,
+VkSemaphore sem, uint64_t val,
+VkPipelineStageFlagBits2 stage);
 int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e,
 VkSemaphore *sem, int nb,
 VkPipelineStageFlagBits2 stage,
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 13/16] vulkan: add support for AV_PIX_FMT_GBRAP32

2025-03-13 Thread Lynne
---
 libavutil/hwcontext_vulkan.c |  1 +
 libavutil/vulkan.c   | 12 +++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 1104e02cfd..9720f427c4 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -347,6 +347,7 @@ static const struct FFVkFormatEntry {
 { VK_FORMAT_R16_UNORM,  AV_PIX_FMT_GBRAP12,  VK_IMAGE_ASPECT_COLOR_BIT, 4, 
4, 4, { VK_FORMAT_R16_UNORM,  VK_FORMAT_R16_UNORM,  VK_FORMAT_R16_UNORM,  
VK_FORMAT_R16_UNORM  } },
 { VK_FORMAT_R16_UNORM,  AV_PIX_FMT_GBRAP14,  VK_IMAGE_ASPECT_COLOR_BIT, 4, 
4, 4, { VK_FORMAT_R16_UNORM,  VK_FORMAT_R16_UNORM,  VK_FORMAT_R16_UNORM,  
VK_FORMAT_R16_UNORM  } },
 { VK_FORMAT_R16_UNORM,  AV_PIX_FMT_GBRAP16,  VK_IMAGE_ASPECT_COLOR_BIT, 4, 
4, 4, { VK_FORMAT_R16_UNORM,  VK_FORMAT_R16_UNORM,  VK_FORMAT_R16_UNORM,  
VK_FORMAT_R16_UNORM  } },
+{ VK_FORMAT_R32_UINT,   AV_PIX_FMT_GBRAP32,  VK_IMAGE_ASPECT_COLOR_BIT, 4, 
4, 4, { VK_FORMAT_R32_UINT,   VK_FORMAT_R32_UINT,   VK_FORMAT_R32_UINT,   
VK_FORMAT_R32_UINT   } },
 { VK_FORMAT_R32_SFLOAT, AV_PIX_FMT_GBRAPF32, VK_IMAGE_ASPECT_COLOR_BIT, 4, 
4, 4, { VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, VK_FORMAT_R32_SFLOAT, 
VK_FORMAT_R32_SFLOAT } },
 
 /* Two-plane 420 YUV at 8, 10, 12 and 16 bits */
diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 08d042a195..a088069d8a 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -1454,7 +1454,7 @@ int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
 pix_fmt == AV_PIX_FMT_GBRP14  || pix_fmt == AV_PIX_FMT_GBRP16 ||
 pix_fmt == AV_PIX_FMT_GBRAP   || pix_fmt == AV_PIX_FMT_GBRAP10 ||
 pix_fmt == AV_PIX_FMT_GBRAP12 || pix_fmt == AV_PIX_FMT_GBRAP14 ||
-pix_fmt == AV_PIX_FMT_GBRAP16 ||
+pix_fmt == AV_PIX_FMT_GBRAP16 || pix_fmt == AV_PIX_FMT_GBRAP32 ||
 pix_fmt == AV_PIX_FMT_GBRPF32 || pix_fmt == AV_PIX_FMT_GBRAPF32 ||
 pix_fmt == AV_PIX_FMT_X2RGB10 || pix_fmt == AV_PIX_FMT_X2BGR10 ||
 pix_fmt == AV_PIX_FMT_RGBAF32 || pix_fmt == AV_PIX_FMT_RGBF32 ||
@@ -1486,6 +1486,7 @@ void ff_vk_set_perm(enum AVPixelFormat pix_fmt, int 
lut[4])
 case AV_PIX_FMT_GBRP14:
 case AV_PIX_FMT_GBRP16:
 case AV_PIX_FMT_GBRPF32:
+case AV_PIX_FMT_GBRAP32:
 case AV_PIX_FMT_GBRAPF32:
 lut[0] = 1;
 lut[1] = 0;
@@ -1624,6 +1625,15 @@ const char *ff_vk_shader_rep_fmt(enum AVPixelFormat 
pix_fmt,
 };
 return rep_tab[rep_fmt];
 };
+case AV_PIX_FMT_GBRAP32: {
+const char *rep_tab[] = {
+[FF_VK_REP_NATIVE] = "r32ui",
+[FF_VK_REP_FLOAT] = NULL,
+[FF_VK_REP_INT] = "r32i",
+[FF_VK_REP_UINT] = "r32ui",
+};
+return rep_tab[rep_fmt];
+};
 case AV_PIX_FMT_NV12:
 case AV_PIX_FMT_NV16:
 case AV_PIX_FMT_NV24: {
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 16/16] ffv1: add a Vulkan-based decoder

2025-03-13 Thread Lynne
This patch adds a fully-featured level 3 and 4 decoder for FFv1,
supporting Golomb and all Range coding variants, all pixel formats,
and all features, except for the newly added floating-point formats.

On a 6000 Ada, for 3840x2160 bgr0 content at 50Mbps (standard desktop
recording), it is able to do 400fps.
An Alder Lake with 24 threads can barely do 100fps.
---
 configure |2 +
 libavcodec/Makefile   |1 +
 libavcodec/ffv1dec.c  |6 +
 libavcodec/hwaccels.h |1 +
 libavcodec/vulkan/Makefile|6 +
 libavcodec/vulkan/common.comp |   95 ++
 libavcodec/vulkan/ffv1_common.comp|5 +
 libavcodec/vulkan/ffv1_dec.comp   |  290 ++
 libavcodec/vulkan/ffv1_dec_rct.comp   |   88 ++
 libavcodec/vulkan/ffv1_dec_setup.comp |  138 +++
 libavcodec/vulkan/ffv1_rct.comp   |   90 ++
 libavcodec/vulkan/ffv1_vlc.comp   |   37 +
 libavcodec/vulkan/rangecoder.comp |   74 ++
 libavcodec/vulkan_decode.c|   17 +
 libavcodec/vulkan_ffv1.c  | 1296 +
 15 files changed, 2146 insertions(+)
 create mode 100644 libavcodec/vulkan/ffv1_dec.comp
 create mode 100644 libavcodec/vulkan/ffv1_dec_rct.comp
 create mode 100644 libavcodec/vulkan/ffv1_dec_setup.comp
 create mode 100644 libavcodec/vulkan/ffv1_rct.comp
 create mode 100644 libavcodec/vulkan_ffv1.c

diff --git a/configure b/configure
index 750c99e3b9..b0c9369a60 100755
--- a/configure
+++ b/configure
@@ -3195,6 +3195,8 @@ av1_videotoolbox_hwaccel_deps="videotoolbox"
 av1_videotoolbox_hwaccel_select="av1_decoder"
 av1_vulkan_hwaccel_deps="vulkan"
 av1_vulkan_hwaccel_select="av1_decoder"
+ffv1_vulkan_hwaccel_deps="vulkan spirv_compiler"
+ffv1_vulkan_hwaccel_select="ffv1_decoder"
 h263_vaapi_hwaccel_deps="vaapi"
 h263_vaapi_hwaccel_select="h263_decoder"
 h263_videotoolbox_hwaccel_deps="videotoolbox"
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5522ed43e5..858334b87a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1017,6 +1017,7 @@ OBJS-$(CONFIG_AV1_VAAPI_HWACCEL)  += vaapi_av1.o
 OBJS-$(CONFIG_AV1_VDPAU_HWACCEL)  += vdpau_av1.o
 OBJS-$(CONFIG_AV1_VIDEOTOOLBOX_HWACCEL)   += videotoolbox_av1.o
 OBJS-$(CONFIG_AV1_VULKAN_HWACCEL) += vulkan_decode.o vulkan_av1.o
+OBJS-$(CONFIG_FFV1_VULKAN_HWACCEL)+= vulkan_decode.o ffv1_vulkan.o 
vulkan_ffv1.o
 OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o
 OBJS-$(CONFIG_H263_VIDEOTOOLBOX_HWACCEL)  += videotoolbox.o
 OBJS-$(CONFIG_H264_D3D11VA_HWACCEL)   += dxva2_h264.o
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 523b9139d8..b595a76553 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -386,6 +386,9 @@ static int decode_slice(AVCodecContext *c, void *arg)
 static enum AVPixelFormat get_pixel_format(FFV1Context *f)
 {
 enum AVPixelFormat pix_fmts[] = {
+#if CONFIG_FFV1_VULKAN_HWACCEL
+AV_PIX_FMT_VULKAN,
+#endif
 f->pix_fmt,
 AV_PIX_FMT_NONE,
 };
@@ -884,6 +887,9 @@ const FFCodec ff_ffv1_decoder = {
 .caps_internal  = FF_CODEC_CAP_INIT_CLEANUP |
   FF_CODEC_CAP_USES_PROGRESSFRAMES,
 .hw_configs = (const AVCodecHWConfigInternal *const []) {
+#if CONFIG_FFV1_VULKAN_HWACCEL
+HWACCEL_VULKAN(ffv1),
+#endif
 NULL
 },
 };
diff --git a/libavcodec/hwaccels.h b/libavcodec/hwaccels.h
index 910a024032..0b2c725247 100644
--- a/libavcodec/hwaccels.h
+++ b/libavcodec/hwaccels.h
@@ -28,6 +28,7 @@ extern const struct FFHWAccel ff_av1_vaapi_hwaccel;
 extern const struct FFHWAccel ff_av1_vdpau_hwaccel;
 extern const struct FFHWAccel ff_av1_videotoolbox_hwaccel;
 extern const struct FFHWAccel ff_av1_vulkan_hwaccel;
+extern const struct FFHWAccel ff_ffv1_vulkan_hwaccel;
 extern const struct FFHWAccel ff_h263_vaapi_hwaccel;
 extern const struct FFHWAccel ff_h263_videotoolbox_hwaccel;
 extern const struct FFHWAccel ff_h264_d3d11va_hwaccel;
diff --git a/libavcodec/vulkan/Makefile b/libavcodec/vulkan/Makefile
index 351332ee44..e6bad486bd 100644
--- a/libavcodec/vulkan/Makefile
+++ b/libavcodec/vulkan/Makefile
@@ -11,6 +11,12 @@ OBJS-$(CONFIG_FFV1_VULKAN_ENCODER)  +=  vulkan/common.o \
vulkan/ffv1_enc_vlc.o 
vulkan/ffv1_enc_ac.o \
vulkan/ffv1_enc.o vulkan/ffv1_enc_rgb.o
 
+OBJS-$(CONFIG_FFV1_VULKAN_HWACCEL)  +=  vulkan/common.o \
+   vulkan/rangecoder.o vulkan/ffv1_vlc.o \
+   vulkan/ffv1_common.o 
vulkan/ffv1_reset.o \
+   vulkan/ffv1_dec_setup.o 
vulkan/ffv1_dec.o \
+   vulkan/ffv1_dec_rct.o
+
 VULKAN = $(subst $(SRC_PATH)/,,$(wildcard 
$(SRC_PATH)/libavcodec/vulkan/*.comp))
 .SECONDARY: $(VULKAN:.comp=.c)
 libavcodec/vulkan/%.c: TAG = VULKAN
diff --git a/libavcodec/vulkan/common.comp b/libavco

[FFmpeg-devel] [PATCH v4 07/16] vulkan_decode: support software-defined decoders

2025-03-13 Thread Lynne
---
 libavcodec/vulkan_decode.c | 194 +++--
 libavcodec/vulkan_decode.h |  11 +++
 2 files changed, 154 insertions(+), 51 deletions(-)

diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c
index c57998108c..594764a904 100644
--- a/libavcodec/vulkan_decode.c
+++ b/libavcodec/vulkan_decode.c
@@ -24,6 +24,9 @@
 #include "libavutil/mem.h"
 #include "libavutil/vulkan_loader.h"
 
+#define DECODER_IS_SDR(codec_id) \
+((codec_id) == AV_CODEC_ID_FFV1)
+
 #if CONFIG_H264_VULKAN_HWACCEL
 extern const FFVulkanDecodeDescriptor ff_vk_dec_h264_desc;
 #endif
@@ -63,7 +66,9 @@ static const VkVideoProfileInfoKHR 
*get_video_profile(FFVulkanDecodeShared *ctx,
 codec_id == AV_CODEC_ID_H264 ? 
VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_PROFILE_INFO_KHR :
 codec_id == AV_CODEC_ID_HEVC ? 
VK_STRUCTURE_TYPE_VIDEO_DECODE_H265_PROFILE_INFO_KHR :
 codec_id == AV_CODEC_ID_AV1  ? 
VK_STRUCTURE_TYPE_VIDEO_DECODE_AV1_PROFILE_INFO_KHR :
-0;
+   VK_STRUCTURE_TYPE_MAX_ENUM;
+if (profile_struct_type == VK_STRUCTURE_TYPE_MAX_ENUM)
+return NULL;
 
 profile_list = ff_vk_find_struct(ctx->s.hwfc->create_pnext,
  
VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR);
@@ -119,13 +124,26 @@ static AVFrame *vk_get_dpb_pool(FFVulkanDecodeShared *ctx)
 return avf;
 }
 
+static void init_frame(FFVulkanDecodeContext *dec, FFVulkanDecodePicture 
*vkpic)
+{
+FFVulkanDecodeShared *ctx = dec->shared_ctx;
+FFVulkanFunctions *vk = &ctx->s.vkfn;
+
+vkpic->dpb_frame = NULL;
+vkpic->img_view_ref  = VK_NULL_HANDLE;
+vkpic->img_view_out  = VK_NULL_HANDLE;
+vkpic->img_view_dest = VK_NULL_HANDLE;
+
+vkpic->destroy_image_view = vk->DestroyImageView;
+vkpic->wait_semaphores = vk->WaitSemaphores;
+}
+
 int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, AVFrame *pic,
FFVulkanDecodePicture *vkpic, int is_current,
int alloc_dpb)
 {
 int err;
 FFVulkanDecodeShared *ctx = dec->shared_ctx;
-FFVulkanFunctions *vk = &ctx->s.vkfn;
 
 vkpic->slices_size = 0;
 
@@ -134,13 +152,7 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, 
AVFrame *pic,
 if (vkpic->img_view_ref)
 return 0;
 
-vkpic->dpb_frame = NULL;
-vkpic->img_view_ref  = VK_NULL_HANDLE;
-vkpic->img_view_out  = VK_NULL_HANDLE;
-vkpic->img_view_dest = VK_NULL_HANDLE;
-
-vkpic->destroy_image_view = vk->DestroyImageView;
-vkpic->wait_semaphores = vk->WaitSemaphores;
+init_frame(dec, vkpic);
 
 if (ctx->common.layered_dpb && alloc_dpb) {
 vkpic->img_view_ref = ctx->common.layered_view;
@@ -183,6 +195,53 @@ int ff_vk_decode_prepare_frame(FFVulkanDecodeContext *dec, 
AVFrame *pic,
 return 0;
 }
 
+int ff_vk_decode_prepare_frame_sdr(FFVulkanDecodeContext *dec, AVFrame *pic,
+   FFVulkanDecodePicture *vkpic, int 
is_current,
+   enum FFVkShaderRepFormat rep_fmt, int 
alloc_dpb)
+{
+int err;
+FFVulkanDecodeShared *ctx = dec->shared_ctx;
+
+vkpic->slices_size = 0;
+
+if (vkpic->img_view_ref)
+return 0;
+
+init_frame(dec, vkpic);
+
+if (ctx->common.layered_dpb && alloc_dpb) {
+vkpic->img_view_ref = ctx->common.layered_view;
+vkpic->img_aspect_ref = ctx->common.layered_aspect;
+} else if (alloc_dpb) {
+vkpic->dpb_frame = vk_get_dpb_pool(ctx);
+if (!vkpic->dpb_frame)
+return AVERROR(ENOMEM);
+
+err = ff_vk_create_imageview(&ctx->s,
+ &vkpic->img_view_ref, 
&vkpic->img_aspect_ref,
+ vkpic->dpb_frame, 0, rep_fmt);
+if (err < 0)
+return err;
+
+vkpic->img_view_dest = vkpic->img_view_ref;
+}
+
+if (!alloc_dpb || is_current) {
+err = ff_vk_create_imageview(&ctx->s,
+ &vkpic->img_view_out, &vkpic->img_aspect,
+ pic, 0, rep_fmt);
+if (err < 0)
+return err;
+
+if (!alloc_dpb) {
+vkpic->img_view_ref = vkpic->img_view_out;
+vkpic->img_aspect_ref = vkpic->img_aspect;
+}
+}
+
+return 0;
+}
+
 int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp,
const uint8_t *data, size_t size, int add_startcode,
uint32_t *nb_slices, const uint32_t **offsets)
@@ -223,9 +282,14 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, 
FFVulkanDecodePicture *vp,
 buf_size = 2 << av_log2(buf_size);
 
 err = ff_vk_get_pooled_buffer(&ctx->s, &ctx->buf_pool, &new_ref,
+  DECODER_IS_SDR(avctx->codec_id) ?
+  (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
+  

[FFmpeg-devel] [PATCH v4 02/16] vulkan: rename ff_vk_set_descriptor_image to ff_vk_shader_update_img

2025-03-13 Thread Lynne
---
 libavutil/vulkan.c | 34 +-
 libavutil/vulkan.h |  8 
 2 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c
index 8f6ee8a276..3020f01bee 100644
--- a/libavutil/vulkan.c
+++ b/libavutil/vulkan.c
@@ -2355,10 +2355,10 @@ static inline void 
update_set_pool_write(FFVulkanContext *s, FFVkExecContext *e,
 }
 }
 
-int ff_vk_set_descriptor_image(FFVulkanContext *s, FFVulkanShader *shd,
-   FFVkExecContext *e, int set, int bind, int offs,
-   VkImageView view, VkImageLayout layout,
-   VkSampler sampler)
+int ff_vk_shader_update_img(FFVulkanContext *s, FFVkExecContext *e,
+FFVulkanShader *shd, int set, int bind, int offs,
+VkImageView view, VkImageLayout layout,
+VkSampler sampler)
 {
 FFVulkanDescriptorSet *desc_set = &shd->desc_set[set];
 
@@ -2420,6 +2420,19 @@ int ff_vk_set_descriptor_image(FFVulkanContext *s, 
FFVulkanShader *shd,
 return 0;
 }
 
+void ff_vk_shader_update_img_array(FFVulkanContext *s, FFVkExecContext *e,
+   FFVulkanShader *shd, AVFrame *f,
+   VkImageView *views, int set, int binding,
+   VkImageLayout layout, VkSampler sampler)
+{
+AVHWFramesContext *hwfc = (AVHWFramesContext *)f->hw_frames_ctx->data;
+const int nb_planes = av_pix_fmt_count_planes(hwfc->sw_format);
+
+for (int i = 0; i < nb_planes; i++)
+ff_vk_shader_update_img(s, e, shd, set, binding, i,
+views[i], layout, sampler);
+}
+
 int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e,
 FFVulkanShader *shd,
 int set, int bind, int elem,
@@ -2486,19 +2499,6 @@ int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, 
FFVkExecContext *e,
 return 0;
 }
 
-void ff_vk_shader_update_img_array(FFVulkanContext *s, FFVkExecContext *e,
-   FFVulkanShader *shd, AVFrame *f,
-   VkImageView *views, int set, int binding,
-   VkImageLayout layout, VkSampler sampler)
-{
-AVHWFramesContext *hwfc = (AVHWFramesContext *)f->hw_frames_ctx->data;
-const int nb_planes = av_pix_fmt_count_planes(hwfc->sw_format);
-
-for (int i = 0; i < nb_planes; i++)
-ff_vk_set_descriptor_image(s, shd, e, set, binding, i,
-   views[i], layout, sampler);
-}
-
 void ff_vk_shader_update_push_const(FFVulkanContext *s, FFVkExecContext *e,
 FFVulkanShader *shd,
 VkShaderStageFlagBits stage,
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 91510cbb69..b0db5b2396 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -590,10 +590,10 @@ int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, 
FFVkExecContext *e,
 /**
  * Sets an image descriptor for specified shader and binding.
  */
-int ff_vk_set_descriptor_image(FFVulkanContext *s, FFVulkanShader *shd,
-   FFVkExecContext *e, int set, int bind, int offs,
-   VkImageView view, VkImageLayout layout,
-   VkSampler sampler);
+int ff_vk_shader_update_img(FFVulkanContext *s, FFVkExecContext *e,
+FFVulkanShader *shd, int set, int bind, int offs,
+VkImageView view, VkImageLayout layout,
+VkSampler sampler);
 
 /**
  * Update a descriptor in a buffer with an image array..
-- 
2.47.2
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH v4 00/16] Add a Vulkan compute based FFv1 hwaccel

2025-03-13 Thread Lynne
This series of commits adds a fully compliant version 3 and 4 hardware
accelerator code for FFv1 written in Vulkan.

Changes from the previous version:
 - Use the exported host_map code in hwcontext_vulkan.c
 - Add a buffer_ref argument to FFHWAccel.start_frame
 - Various optimizations in the shader code

Lynne (16):
  pixfmt: add AV_PIX_FMT_GBRAP32
  vulkan: rename ff_vk_set_descriptor_image to ff_vk_shader_update_img
  vulkan: add ff_vk_create_imageview
  vulkan: copy host-mapping buffer code from hwcontext
  hwcontext_vulkan: use the common host map function to map frame data
  vulkan: workaround BGR storage image undefined behaviour
  vulkan_decode: support software-defined decoders
  vulkan_decode: support multiple image views
  vulkan_decode: adjust number of async contexts created
  ffv1enc_vulkan: refactor shaders slightly to support sharing
  vulkan: unify handling of BGR and simplify ffv1_rct
  vulkan: add ff_vk_exec_add_dep_wait_sem()
  vulkan: add support for AV_PIX_FMT_GBRAP32
  ffv1dec: add support for hwaccels
  FFHWAccel: add buffer_ref argument to start_frame
  ffv1: add a Vulkan-based decoder

 configure |2 +
 libavcodec/Makefile   |3 +-
 libavcodec/av1dec.c   |3 +-
 libavcodec/d3d12va_av1.c  |5 +-
 libavcodec/d3d12va_h264.c |5 +-
 libavcodec/d3d12va_hevc.c |5 +-
 libavcodec/d3d12va_mpeg2.c|5 +-
 libavcodec/d3d12va_vc1.c  |5 +-
 libavcodec/d3d12va_vp9.c  |5 +-
 libavcodec/dxva2_av1.c|1 +
 libavcodec/dxva2_h264.c   |1 +
 libavcodec/dxva2_hevc.c   |1 +
 libavcodec/dxva2_mpeg2.c  |1 +
 libavcodec/dxva2_vc1.c|1 +
 libavcodec/dxva2_vp9.c|1 +
 libavcodec/ffv1.h |2 +
 libavcodec/ffv1_vulkan.c  |  123 +++
 libavcodec/ffv1_vulkan.h  |   61 ++
 libavcodec/ffv1dec.c  |   87 +-
 libavcodec/ffv1enc_vulkan.c   |  236 ++---
 libavcodec/h263dec.c  |2 +-
 libavcodec/h264dec.c  |8 +-
 libavcodec/hevc/hevcdec.c |5 +-
 libavcodec/hwaccel_internal.h |4 +-
 libavcodec/hwaccels.h |1 +
 libavcodec/mjpegdec.c |2 +-
 libavcodec/mpeg12dec.c|2 +-
 libavcodec/nvdec_av1.c|4 +-
 libavcodec/nvdec_h264.c   |1 +
 libavcodec/nvdec_hevc.c   |1 +
 libavcodec/nvdec_mjpeg.c  |4 +-
 libavcodec/nvdec_mpeg12.c |3 +-
 libavcodec/nvdec_mpeg4.c  |3 +-
 libavcodec/nvdec_vc1.c|3 +-
 libavcodec/nvdec_vp8.c|3 +-
 libavcodec/nvdec_vp9.c|3 +-
 libavcodec/proresdec.c|2 +-
 libavcodec/vaapi_av1.c|1 +
 libavcodec/vaapi_h264.c   |1 +
 libavcodec/vaapi_hevc.c   |1 +
 libavcodec/vaapi_mjpeg.c  |1 +
 libavcodec/vaapi_mpeg2.c  |5 +-
 libavcodec/vaapi_mpeg4.c  |5 +-
 libavcodec/vaapi_vc1.c|5 +-
 libavcodec/vaapi_vp8.c|1 +
 libavcodec/vaapi_vp9.c|1 +
 libavcodec/vaapi_vvc.c|1 +
 libavcodec/vc1dec.c   |6 +-
 libavcodec/vdpau_av1.c|3 +-
 libavcodec/vdpau_h264.c   |1 +
 libavcodec/vdpau_hevc.c   |1 +
 libavcodec/vdpau_mpeg12.c |1 +
 libavcodec/vdpau_mpeg4.c  |1 +
 libavcodec/vdpau_vc1.c|1 +
 libavcodec/vdpau_vp9.c|3 +-
 libavcodec/videotoolbox.c |8 +-
 libavcodec/videotoolbox_av1.c |1 +
 libavcodec/videotoolbox_vp9.c |1 +
 libavcodec/vp8.c  |2 +-
 libavcodec/vp9.c  |2 +-
 libavcodec/vt_internal.h  |1 +
 libavcodec/vulkan/Makefile|6 +
 libavcodec/vulkan/common.comp |   95 ++
 libavcodec/vulkan/ffv1_common.comp|   25 +-
 libavcodec/vulkan/ffv1_dec.comp   |  290 ++
 libavcodec/vulkan/ffv1_dec_rct.comp   |   88 ++
 libavcodec/vulkan/ffv1_dec_setup.comp |  138 +++
 libavcodec/vulkan/ffv1_enc_rct.comp   |   17 +-
 libavcodec/vulkan/ffv1_enc_setup.comp |   18 +-
 libavcodec/vulkan/ffv1_rct.comp   |   90 ++
 libavcodec/vulkan/ffv1_reset.comp |3 +-
 libavcodec/vulkan/ffv1_vlc.comp   |   37 +
 libavcodec/vulkan/rangecoder.comp |  101 +-
 libavcodec/vulkan_av1.c   |5 +-
 libavcodec/vulkan_decode.c|  257 +++--
 libavcodec/vulkan_decode.h|   23 +-
 libavcodec/vulkan_ffv1.c  | 1296 +
 libavcodec/vulkan_h264.c  |5 +-
 libavcodec/vulkan_hevc.c  | 

[FFmpeg-devel] [PATCH v4 15/16] FFHWAccel: add buffer_ref argument to start_frame

2025-03-13 Thread Lynne
This commit adds a reference to the buffer as an argument to
start_frame, and adapts all existing code.

This allows for asynchronous hardware accelerators to skip
copying packet data by referencing it.
---
 libavcodec/av1dec.c   |  3 ++-
 libavcodec/d3d12va_av1.c  |  5 -
 libavcodec/d3d12va_h264.c |  5 +++--
 libavcodec/d3d12va_hevc.c |  5 -
 libavcodec/d3d12va_mpeg2.c|  5 -
 libavcodec/d3d12va_vc1.c  |  5 -
 libavcodec/d3d12va_vp9.c  |  5 -
 libavcodec/dxva2_av1.c|  1 +
 libavcodec/dxva2_h264.c   |  1 +
 libavcodec/dxva2_hevc.c   |  1 +
 libavcodec/dxva2_mpeg2.c  |  1 +
 libavcodec/dxva2_vc1.c|  1 +
 libavcodec/dxva2_vp9.c|  1 +
 libavcodec/ffv1dec.c  |  2 +-
 libavcodec/h263dec.c  |  2 +-
 libavcodec/h264dec.c  |  8 +---
 libavcodec/hevc/hevcdec.c |  5 -
 libavcodec/hwaccel_internal.h |  4 +++-
 libavcodec/mjpegdec.c |  2 +-
 libavcodec/mpeg12dec.c|  2 +-
 libavcodec/nvdec_av1.c|  4 +++-
 libavcodec/nvdec_h264.c   |  1 +
 libavcodec/nvdec_hevc.c   |  1 +
 libavcodec/nvdec_mjpeg.c  |  4 +++-
 libavcodec/nvdec_mpeg12.c |  3 ++-
 libavcodec/nvdec_mpeg4.c  |  3 ++-
 libavcodec/nvdec_vc1.c|  3 ++-
 libavcodec/nvdec_vp8.c|  3 ++-
 libavcodec/nvdec_vp9.c|  3 ++-
 libavcodec/proresdec.c|  2 +-
 libavcodec/vaapi_av1.c|  1 +
 libavcodec/vaapi_h264.c   |  1 +
 libavcodec/vaapi_hevc.c   |  1 +
 libavcodec/vaapi_mjpeg.c  |  1 +
 libavcodec/vaapi_mpeg2.c  |  5 -
 libavcodec/vaapi_mpeg4.c  |  5 -
 libavcodec/vaapi_vc1.c|  5 -
 libavcodec/vaapi_vp8.c|  1 +
 libavcodec/vaapi_vp9.c|  1 +
 libavcodec/vaapi_vvc.c|  1 +
 libavcodec/vc1dec.c   |  6 +++---
 libavcodec/vdpau_av1.c|  3 ++-
 libavcodec/vdpau_h264.c   |  1 +
 libavcodec/vdpau_hevc.c   |  1 +
 libavcodec/vdpau_mpeg12.c |  1 +
 libavcodec/vdpau_mpeg4.c  |  1 +
 libavcodec/vdpau_vc1.c|  1 +
 libavcodec/vdpau_vp9.c|  3 ++-
 libavcodec/videotoolbox.c |  8 ++--
 libavcodec/videotoolbox_av1.c |  1 +
 libavcodec/videotoolbox_vp9.c |  1 +
 libavcodec/vp8.c  |  2 +-
 libavcodec/vp9.c  |  2 +-
 libavcodec/vt_internal.h  |  1 +
 libavcodec/vulkan_av1.c   |  1 +
 libavcodec/vulkan_h264.c  |  1 +
 libavcodec/vulkan_hevc.c  |  1 +
 libavcodec/vvc/dec.c  | 12 +++-
 58 files changed, 118 insertions(+), 42 deletions(-)

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index ed504ace85..baa9dea0f7 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -1380,7 +1380,8 @@ static int av1_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 s->cur_frame.temporal_id = header->temporal_id;
 
 if (avctx->hwaccel && s->cur_frame.f) {
-ret = FF_HW_CALL(avctx, start_frame, unit->data, 
unit->data_size);
+ret = FF_HW_CALL(avctx, start_frame, s->pkt->buf,
+ unit->data, unit->data_size);
 if (ret < 0) {
 av_log(avctx, AV_LOG_ERROR, "HW accel start frame 
fail.\n");
 goto end;
diff --git a/libavcodec/d3d12va_av1.c b/libavcodec/d3d12va_av1.c
index 4a4d207b4f..230ca243fd 100644
--- a/libavcodec/d3d12va_av1.c
+++ b/libavcodec/d3d12va_av1.c
@@ -45,7 +45,10 @@ typedef struct AV1DecodePictureContext {
 unsignedbitstream_size;
 } AV1DecodePictureContext;
 
-static int d3d12va_av1_start_frame(AVCodecContext *avctx, av_unused const 
uint8_t *buffer,  av_unused uint32_t size)
+static int d3d12va_av1_start_frame(AVCodecContext *avctx,
+   av_unused AVBufferRef *buffer_ref,
+   av_unused const uint8_t *buffer,
+   av_unused uint32_t size)
 {
 const AV1DecContext *h   = avctx->priv_data;
 AV1DecodePictureContext *ctx_pic = h->cur_frame.hwaccel_picture_private;
diff --git a/libavcodec/d3d12va_h264.c b/libavcodec/d3d12va_h264.c
index b2fe2955c8..80a1034fa5 100644
--- a/libavcodec/d3d12va_h264.c
+++ b/libavcodec/d3d12va_h264.c
@@ -50,8 +50,9 @@ static void fill_slice_short(DXVA_Slice_H264_Short *slice,
 }
 
 static int d3d12va_h264_start_frame(AVCodecContext *avctx,
-  av_unused const uint8_t *buffer,
-  av_unused uint32_t size)
+av_unused AVBufferRef *buffer_ref,
+av_unused const uint8_t *buffer,
+av_unused uint32_t size)
 {
 const H264Context*h   = avctx->priv_data;
 H264DecodePictureContext *ctx_pic = 
h->cur_pic_ptr->hwaccel_picture_private;
diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 7686f0eb6c..a8c80c65d9 100644
--- a/lib

[FFmpeg-devel] [PATCH v4 14/16] ffv1dec: add support for hwaccels

2025-03-13 Thread Lynne
This commit adds support for hardware accelerated decoding to
the decoder.
The previous commits already refactored the decoder, this commit
simply adds calls to hooks to decode.
---
 libavcodec/ffv1.h|  2 ++
 libavcodec/ffv1dec.c | 81 +++-
 2 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index c23d64d54a..8c0e71284d 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -125,8 +125,10 @@ typedef struct FFV1Context {
 int64_t picture_number;
 int key_frame;
 ProgressFrame picture, last_picture;
+void *hwaccel_picture_private, *hwaccel_last_picture_private;
 uint32_t crcref;
 enum AVPixelFormat pix_fmt;
+enum AVPixelFormat configured_pix_fmt;
 
 const AVFrame *cur_enc_frame;
 int plane_count;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 37b14c0410..387fedc79c 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -41,6 +41,9 @@
 #include "libavutil/refstruct.h"
 #include "thread.h"
 #include "decode.h"
+#include "hwconfig.h"
+#include "hwaccel_internal.h"
+#include "config_components.h"
 
 static inline int get_vlc_symbol(GetBitContext *gb, VlcState *const state,
  int bits)
@@ -402,9 +405,12 @@ static int read_header(FFV1Context *f, RangeCoder *c)
 if (ret < 0)
 return ret;
 
-f->avctx->pix_fmt = get_pixel_format(f);
-if (f->avctx->pix_fmt < 0)
-return AVERROR(EINVAL);
+if (f->configured_pix_fmt != f->pix_fmt) {
+f->avctx->pix_fmt = get_pixel_format(f);
+if (f->avctx->pix_fmt < 0)
+return AVERROR(EINVAL);
+f->configured_pix_fmt = f->pix_fmt;
+}
 
 ff_dlog(f->avctx, "%d %d %d\n",
 f->chroma_h_shift, f->chroma_v_shift, f->pix_fmt);
@@ -497,6 +503,9 @@ static av_cold int decode_init(AVCodecContext *avctx)
 FFV1Context *f = avctx->priv_data;
 int ret;
 
+f->pix_fmt = AV_PIX_FMT_NONE;
+f->configured_pix_fmt = AV_PIX_FMT_NONE;
+
 if ((ret = ff_ffv1_common_init(avctx, f)) < 0)
 return ret;
 
@@ -681,13 +690,16 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 FFV1Context *f  = avctx->priv_data;
 int ret;
 AVFrame *p;
+const FFHWAccel *hwaccel = NULL;
 
 /* This is copied onto the first slice's range coder context */
 RangeCoder c;
 
 ff_progress_frame_unref(&f->last_picture);
-FFSWAP(ProgressFrame, f->picture, f->last_picture);
+av_refstruct_unref(&f->hwaccel_last_picture_private);
 
+FFSWAP(ProgressFrame, f->picture, f->last_picture);
+FFSWAP(void *, f->hwaccel_picture_private, 
f->hwaccel_last_picture_private);
 
 f->avctx = avctx;
 f->frame_damaged = 0;
@@ -696,11 +708,18 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 if (ret < 0)
 return ret;
 
+if (avctx->hwaccel)
+hwaccel = ffhwaccel(avctx->hwaccel);
+
 ret = ff_progress_frame_get_buffer(avctx, &f->picture,
AV_GET_BUFFER_FLAG_REF);
 if (ret < 0)
 return ret;
 
+ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private);
+if (ret < 0)
+return ret;
+
 p = f->picture.f;
 
 p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
@@ -717,15 +736,53 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 av_log(avctx, AV_LOG_DEBUG, "ver:%d keyframe:%d coder:%d ec:%d 
slices:%d bps:%d\n",
f->version, !!(p->flags & AV_FRAME_FLAG_KEY), f->ac, f->ec, 
f->slice_count, f->avctx->bits_per_raw_sample);
 
+/* Start */
+if (hwaccel) {
+ret = hwaccel->start_frame(avctx, avpkt->data, avpkt->size);
+if (ret < 0)
+return ret;
+}
+
 ff_thread_finish_setup(avctx);
 
-ret = decode_slices(avctx, c, avpkt);
-if (ret < 0)
-return ret;
+/* Decode slices */
+if (hwaccel) {
+uint8_t *buf_end = avpkt->data + avpkt->size;
+
+if (!(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
+ff_progress_frame_await(&f->last_picture, f->slice_count - 1);
+
+for (int i = f->slice_count - 1; i >= 0; i--) {
+uint8_t *pos;
+uint32_t len;
+ret = find_next_slice(avctx, avpkt->data, buf_end, i,
+  &pos, &len);
+if (ret < 0)
+return ret;
+
+buf_end -= len;
+
+ret = hwaccel->decode_slice(avctx, pos, len);
+if (ret < 0)
+return ret;
+}
+} else {
+ret = decode_slices(avctx, c, avpkt);
+if (ret < 0)
+return ret;
+}
+
+/* Finalize */
+if (hwaccel) {
+ret = hwaccel->end_frame(avctx);
+if (ret < 0)
+return ret;
+}
 
 ff_progress_frame_report(&f->picture, INT_MAX);
 
 ff_progress_frame_unref(&f->last_picture);
+av_refstruct_unre

Re: [FFmpeg-devel] [PATCH 11/13] ffv1dec: reference the current packet into the main context

2025-03-13 Thread Andreas Rheinhardt
Lynne:
> On 13/03/2025 05:57, Andreas Rheinhardt wrote:
>> Lynne:
>>>
>>>
>>> On 13/03/2025 02:24, Andreas Rheinhardt wrote:
 Lynne:
> On 10/03/2025 18:42, Lynne wrote:
>> On 10/03/2025 04:14, Andreas Rheinhardt wrote:
>>> Lynne:
 ---
     libavcodec/ffv1.h    |  3 +++
     libavcodec/ffv1dec.c | 19 +--
     2 files changed, 20 insertions(+), 2 deletions(-)

 diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
 index 8c0e71284d..860a5c14b1 100644
 --- a/libavcodec/ffv1.h
 +++ b/libavcodec/ffv1.h
 @@ -174,6 +174,9 @@ typedef struct FFV1Context {
  * NOT shared between frame threads.
  */
     uint8_t   frame_damaged;
 +
 +    /* Reference to the current packet */
 +    AVPacket *pkt_ref;
     } FFV1Context;
     int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s);
 diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
 index eaa21eebdf..6396f22f79 100644
 --- a/libavcodec/ffv1dec.c
 +++ b/libavcodec/ffv1dec.c
 @@ -469,6 +469,10 @@ static av_cold int decode_init(AVCodecContext
 *avctx)
     f->pix_fmt = AV_PIX_FMT_NONE;
     f->configured_pix_fmt = AV_PIX_FMT_NONE;
 +    f->pkt_ref = av_packet_alloc();
 +    if (!f->pkt_ref)
 +    return AVERROR(ENOMEM);
 +
     if ((ret = ff_ffv1_common_init(avctx, f)) < 0)
     return ret;
 @@ -701,6 +705,10 @@ static int decode_frame(AVCodecContext *avctx,
 AVFrame *rframe,
     /* Start */
     if (hwaccel) {
 +    ret = av_packet_ref(f->pkt_ref, avpkt);
 +    if (ret < 0)
 +    return ret;
 +
     ret = hwaccel->start_frame(avctx, avpkt->data, avpkt-
> size);
     if (ret < 0)
     return ret;
 @@ -720,15 +728,21 @@ static int decode_frame(AVCodecContext
 *avctx,
 AVFrame *rframe,
     uint32_t len;
     ret = find_next_slice(avctx, avpkt->data,
 buf_end, i,
   &pos, &len);
 -    if (ret < 0)
 +    if (ret < 0) {
 +    av_packet_unref(f->pkt_ref);
     return ret;
 +    }
     buf_end -= len;
     ret = hwaccel->decode_slice(avctx, pos, len);
 -    if (ret < 0)
 +    if (ret < 0) {
 +    av_packet_unref(f->pkt_ref);
     return ret;
 +    }
     }
 +
 +    av_packet_unref(f->pkt_ref);
     } else {
     ret = decode_slices(avctx, c, avpkt);
     if (ret < 0)
 @@ -827,6 +841,7 @@ static av_cold int
 ffv1_decode_close(AVCodecContext *avctx)
     ff_progress_frame_unref(&s->last_picture);
     av_refstruct_unref(&s->hwaccel_last_picture_private);
 +    av_packet_free(&s->pkt_ref);
     ff_ffv1_close(s);
     return 0;
>>>
>>> Why not simply use a const AVPacket*?
>>
>> No reason. Fixed locally.
>> Thanks.
>
> *reverted this change.
> We need to ref the packet, since we map its memory and let the GPU use
> it directly without copying the contents. 6k16bit content at 24fps is
> typically around 2Gbps when compressed, so avoiding copies is
> important.

 How long does the hwaccel need this data?
>>>
>>> Until the frame has been asynchronously decoded. We give an output frame
>>> with a semaphore that receivers need to wait on to determine when
>>> that is.

Does this mean that the frames the caller of avcodec_receive_frame()
receives are not completely decoded yet?

>>>
>>> On the decoder-side, the hardware has a fixed number of queues where
>>> submissions can be sent to asynchronously. We treat it as a ring buffer
>>> and keep a reference to all resources our side for each submission,
>>> until we need to reuse the slot, at which point we wait on the frame
>>> decoding to complete (which it usually has), and we release all
>>> resources used.
>>>
>>> Output frames also have a bit of state that has to be freed once the
>>> frame is marked (unreferenced) by the decoder as no longer being needed
>>> as a reference, this is done in the FFHWAccel.free_frame_priv callback.
>>> There, we have to wait for the last internal use of the frame to be
>>> finished (done via the vp->wait_semaphores() call in vulkan_decode.c).
>>>
>>> This is valid for both ASIC hardware decoders and a compute shader based
>>> implementation, since the two share the same code, exce

Re: [FFmpeg-devel] [PATCH 11/13] ffv1dec: reference the current packet into the main context

2025-03-13 Thread Lynne



On 13/03/2025 18:48, Andreas Rheinhardt wrote:

Lynne:

On 13/03/2025 05:57, Andreas Rheinhardt wrote:

Lynne:



On 13/03/2025 02:24, Andreas Rheinhardt wrote:

Lynne:

On 10/03/2025 18:42, Lynne wrote:

On 10/03/2025 04:14, Andreas Rheinhardt wrote:

Lynne:

---
     libavcodec/ffv1.h    |  3 +++
     libavcodec/ffv1dec.c | 19 +--
     2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 8c0e71284d..860a5c14b1 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -174,6 +174,9 @@ typedef struct FFV1Context {
  * NOT shared between frame threads.
  */
     uint8_t   frame_damaged;
+
+    /* Reference to the current packet */
+    AVPacket *pkt_ref;
     } FFV1Context;
     int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index eaa21eebdf..6396f22f79 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -469,6 +469,10 @@ static av_cold int decode_init(AVCodecContext
*avctx)
     f->pix_fmt = AV_PIX_FMT_NONE;
     f->configured_pix_fmt = AV_PIX_FMT_NONE;
+    f->pkt_ref = av_packet_alloc();
+    if (!f->pkt_ref)
+    return AVERROR(ENOMEM);
+
     if ((ret = ff_ffv1_common_init(avctx, f)) < 0)
     return ret;
@@ -701,6 +705,10 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame *rframe,
     /* Start */
     if (hwaccel) {
+    ret = av_packet_ref(f->pkt_ref, avpkt);
+    if (ret < 0)
+    return ret;
+
     ret = hwaccel->start_frame(avctx, avpkt->data, avpkt-

size);

     if (ret < 0)
     return ret;
@@ -720,15 +728,21 @@ static int decode_frame(AVCodecContext
*avctx,
AVFrame *rframe,
     uint32_t len;
     ret = find_next_slice(avctx, avpkt->data,
buf_end, i,
   &pos, &len);
-    if (ret < 0)
+    if (ret < 0) {
+    av_packet_unref(f->pkt_ref);
     return ret;
+    }
     buf_end -= len;
     ret = hwaccel->decode_slice(avctx, pos, len);
-    if (ret < 0)
+    if (ret < 0) {
+    av_packet_unref(f->pkt_ref);
     return ret;
+    }
     }
+
+    av_packet_unref(f->pkt_ref);
     } else {
     ret = decode_slices(avctx, c, avpkt);
     if (ret < 0)
@@ -827,6 +841,7 @@ static av_cold int
ffv1_decode_close(AVCodecContext *avctx)
     ff_progress_frame_unref(&s->last_picture);
     av_refstruct_unref(&s->hwaccel_last_picture_private);
+    av_packet_free(&s->pkt_ref);
     ff_ffv1_close(s);
     return 0;


Why not simply use a const AVPacket*?


No reason. Fixed locally.
Thanks.


*reverted this change.
We need to ref the packet, since we map its memory and let the GPU use
it directly without copying the contents. 6k16bit content at 24fps is
typically around 2Gbps when compressed, so avoiding copies is
important.


How long does the hwaccel need this data?


Until the frame has been asynchronously decoded. We give an output frame
with a semaphore that receivers need to wait on to determine when
that is.


Does this mean that the frames the caller of avcodec_receive_frame()
receives are not completely decoded yet?



On the decoder-side, the hardware has a fixed number of queues where
submissions can be sent to asynchronously. We treat it as a ring buffer
and keep a reference to all resources our side for each submission,
until we need to reuse the slot, at which point we wait on the frame
decoding to complete (which it usually has), and we release all
resources used.

Output frames also have a bit of state that has to be freed once the
frame is marked (unreferenced) by the decoder as no longer being needed
as a reference, this is done in the FFHWAccel.free_frame_priv callback.
There, we have to wait for the last internal use of the frame to be
finished (done via the vp->wait_semaphores() call in vulkan_decode.c).

This is valid for both ASIC hardware decoders and a compute shader based
implementation, since the two share the same code, except for decode
submissions.


1. If you need a reference to the packet's data, then reference
AVPacket.buf, not the whole AVPacket. This avoids allocating a spare
AVPacket as well as copying side data.
2. It sounds very wrong and fragile that the decoder has to keep a
reference because the hwaccel might need it. There may be future
hwaccels that don't need such a reference etc. It seems better to extend
e.g. the start_frame callback and pass a reference to the input data (no
need to change this for all other start_frame calls; they can pass NULL
until needed).
3. If the user closes the decoder (which is allowed at any time, even
without draining the decoder), ff_codec_close() uninitializes the
hwaccel after calling the decoder's close function; the latter
unreferences th

[FFmpeg-devel] [PATCH] speexdec: fix framesize for ultra-wideband

2025-03-13 Thread Tristan Matthews
This matches how the libspeex decoder is calculating frame size (except in 
clamp form).

Fixes #11495
---
 libavcodec/speexdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/speexdec.c b/libavcodec/speexdec.c
index b335e2fbe8..0990338341 100644
--- a/libavcodec/speexdec.c
+++ b/libavcodec/speexdec.c
@@ -1425,7 +1425,7 @@ static int parse_speex_extradata(AVCodecContext *avctx,
 if (s->frame_size < NB_FRAME_SIZE << (s->mode > 1) ||
 s->frame_size > INT32_MAX >> (s->mode > 1))
 return AVERROR_INVALIDDATA;
-s->frame_size <<= (s->mode > 1);
+s->frame_size = FFMIN(s->frame_size << (s->mode > 1), NB_FRAME_SIZE << 
s->mode);
 s->vbr = bytestream_get_le32(&buf);
 s->frames_per_packet = bytestream_get_le32(&buf);
 if (s->frames_per_packet <= 0 ||
-- 
2.45.2

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

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


Re: [FFmpeg-devel] [FFmpeg-cvslog] swscale: use 16-bit intermediate precision for RGB/XYZ conversion

2025-03-13 Thread Niklas Haas
On Fri, 14 Mar 2025 00:54:25 +0100 Michael Niedermayer  
wrote:
> Hi
> 
> On Sun, Jan 26, 2025 at 07:26:59PM +0100, Michael Niedermayer wrote:
> > On Thu, Dec 26, 2024 at 07:33:23PM +, Niklas Haas wrote:
> > > ffmpeg | branch: master | Niklas Haas  | Mon Dec 16 
> > > 14:49:39 2024 +0100| [af6d52eec66961f6a502b0f2f390c12226d087cd] | 
> > > committer: Niklas Haas
> > > 
> > > swscale: use 16-bit intermediate precision for RGB/XYZ conversion
> > > 
> > > The current logic uses 12-bit linear light math, which is woefully 
> > > insufficient
> > > and leads to nasty postarization artifacts. This patch simply switches the
> > > internal logic to 16-bit precision.
> > > 
> > > This raises the memory requirement of these tables from 32 kB to 272 kB.
> > > 
> > > All relevant FATE tests updated for improved accuracy.
> > > 
> > > Fixes: #4829
> > > Signed-off-by: Niklas Haas 
> > > Sponsored-by: Sovereign Tech Fund
> > > 
> > > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=af6d52eec66961f6a502b0f2f390c12226d087cd
> > > ---
> > 
> > this breaks on x86-32
> 
> ping
> 
> the fate tests for a major architecture are broken since this
> This impacts future bisections over that range for example

My bad, missed this email for some reason.

Will investigate and fix tomorrow.

> 
> you can trivially test this on x86-64 with something like:
> --cross-prefix=/usr/i686-linux-gnu/bin/ --cc='ccache i686-linux-gnu-gcc-7' 
> --arch=x86_32  --target-os=linux --enable-cross-compile
> if you have the correponding packages installed
> 
> before af6d52eec66961f6a502b0f2f390c12226d087cd
> TESTfilter-pixdesc-xyz12be
> 
> after af6d52eec66961f6a502b0f2f390c12226d087cd:
> --- src/tests/ref/fate/filter-pixdesc-xyz12be 2025-03-14 00:46:40.445681223 
> +0100
> +++ tests/data/fate/filter-pixdesc-xyz12be2025-03-14 00:47:08.301903796 
> +0100
> @@ -1 +1 @@
> -pixdesc-xyz12be 1508a33dea936c45d9ee13f7743af00d
> +pixdesc-xyz12be 198f43f452bc55f4ca1e0e0171de5c4c
> Test filter-pixdesc-xyz12be failed. Look at 
> tests/data/fate/filter-pixdesc-xyz12be.err for details.
> make: *** [src/tests/Makefile:311: fate-filter-pixdesc-xyz12be] Error 1
> 
> in master:
> --- src/tests/ref/fate/filter-pixdesc-xyz12be 2025-03-14 00:46:40.445681223 
> +0100
> +++ tests/data/fate/filter-pixdesc-xyz12be2025-03-14 00:48:43.042660972 
> +0100
> @@ -1 +1 @@
> -pixdesc-xyz12be 1508a33dea936c45d9ee13f7743af00d
> +pixdesc-xyz12be 198f43f452bc55f4ca1e0e0171de5c4c
> Test filter-pixdesc-xyz12be failed. Look at 
> tests/data/fate/filter-pixdesc-xyz12be.err for details.
> make: *** [src/tests/Makefile:315: fate-filter-pixdesc-xyz12be] Error 1
> 
> 
> thx
> 
> [...]
> 
> -- 
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Never trust a computer, one day, it may think you are the virus. -- Compn
___
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] Mark C globals with small code model

2025-03-13 Thread Pranav Kant via ffmpeg-devel
Thank you for taking a look.

On Tue, Mar 11, 2025 at 4:45 PM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Pranav Kant via ffmpeg-devel:
> > By default, all globals in C/C++ compiled by clang are allocated
> > in non-large data sections. See [1] for background on code models.
> > For PIC (Position independent code), this is fine as long as binary is
> > small but as binary size increases, users maybe want to use medium/large
> > code models (-mcmodel=medium) which moves data in to large sections.
> > As data in these large sections cannot be accessed using PIC code
> > anymore (as it may be too far away), compiler ends up using a different
> > instruction sequence when building C/C++ code -- using GOT to access
> > these globals (which can be relaxed by linker at link time if binary
> > ends up being smaller). However, assembly files continue to access these
> > globals defined in C/C++ files using older (and invalid instruction
> > sequence). So, we mark all such globals with an attribute that forces
> > them to be allocated in small sections allowing them to validly be
> > accessed from the assembly code.
> >
> > This patch should not have any affect on builds that use small code
> > model, which is the default mode.
> >
> > [1]
> https://eli.thegreenplace.net/2012/01/03/understanding-the-x64-code-models
> >
> > Signed-off-by: Pranav Kant 
> > ---
> >  libavcodec/ac3dsp.c |  2 ++
> >  libavcodec/cabac.c  |  2 ++
> >  libavcodec/x86/constants.c  |  8 
> >  libavutil/attributes.h  |  6 ++
> >  libavutil/attributes_internal.h | 16 
> >  5 files changed, 34 insertions(+)
> >
> > diff --git a/libavcodec/ac3dsp.c b/libavcodec/ac3dsp.c
> > index 730fa70fff..d16b6c24c3 100644
> > --- a/libavcodec/ac3dsp.c
> > +++ b/libavcodec/ac3dsp.c
> > @@ -25,6 +25,7 @@
> >
> >  #include "config.h"
> >  #include "libavutil/attributes.h"
> > +#include "libavutil/attributes_internal.h"
> >  #include "libavutil/common.h"
> >  #include "libavutil/intmath.h"
> >  #include "libavutil/mem_internal.h"
> > @@ -104,6 +105,7 @@ static void ac3_update_bap_counts_c(uint16_t
> mant_cnt[16], uint8_t *bap,
> >  mant_cnt[bap[len]]++;
> >  }
> >
> > +attribute_mcmodel_small
> >  DECLARE_ALIGNED(16, const uint16_t, ff_ac3_bap_bits)[16] = {
>
> Shouldn't stuff like this be applied to the declaration so that C code
> can also take advantage of the knowledge that this object will be placed
> in the small code section?
>

That's right. I will have it corrected in the newer version.


>
> >  0,  0,  0,  3,  0,  4,  5,  6,  7,  8,  9, 10, 11, 12, 14, 16
> >  };
> > diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
> > index 7d41cd2ae6..b8c6db29a2 100644
> > --- a/libavcodec/cabac.c
> > +++ b/libavcodec/cabac.c
> > @@ -24,11 +24,13 @@
> >   * Context Adaptive Binary Arithmetic Coder.
> >   */
> >
> > +#include "libavutil/attributes_internal.h"
> >  #include "libavutil/error.h"
> >  #include "libavutil/mem_internal.h"
> >
> >  #include "cabac.h"
> >
> > +attribute_mcmodel_small
> >  DECLARE_ASM_ALIGNED(1, const uint8_t, ff_h264_cabac_tables)[512 +
> 4*2*64 + 4*64 + 63] = {
>
> Your commit message ("However, assembly files continue to access")
> speaks only of assembly files, i.e. external asm. Yet this here is only
> used by inline ASM. Looking through the code the reason for this is that
> I thought that specifying the memory model is only necessary for stuff
> used by external asm, yet ff_h264_cabac_tables does not seem to be used
> by external ASM at all, only inline ASM. If I see this correctly, the
> reason for this is that LOCAL_MANGLE (and therefore MANGLE) uses rip
> addressing on x64 when configure sets the RIP define. But this means
> that the set of files needing attribute_mcmodel_small is a superset of
> the files currently using DECLARE_ASM_ALIGNED. This means that one would
> only need two macros for the variables accessed by ASM: One for only
> external ASM and one for inline ASM (and potentially external ASM)
> instead of adding attribute_mcmodel_small at various places in the
> codebase.
>


By "However, assembly files continue to access", I meant all assembly
references,
and yes, as you noted, LOCAL_MANGLE uses rip relative addressing. I will
have
the description fixed in the next version.

Making this attribute part of these macros makes sense. However, I have
noted
that not all such globals are marked with such macros. Eg: See ff_pw_1 in
libavcodec/x86/constants.c. This is accessed by "external" asm but not
marked
with any macro that would indicate such. This is even more true for globals
defined
 in header files (eg: constants.c referenced above). I am guessing this is
not intentional.

I can go ahead with using DECLARE_ASM_VAR and DECLARE_INLINE_ASM_VAR
as you suggested for all such variables.


>
> >  9,8,7,7,6,6,6,6,5,5,5,5,5,5,5,5,
> >  4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
> > diff --git a/libavcodec/x86/constants.c b/libavcodec

Re: [FFmpeg-devel] [PATCH] avcodec/x86/constants: Move constants only used by cavsdsp to, it

2025-03-13 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Patch attached.
> 
> - Andreas
> 

Will apply.

- Andreas

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

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


Re: [FFmpeg-devel] [PATCH] avcodec/ffv1enc: Factor set_micro_version() out of ff_ffv1_write_extradata()

2025-03-13 Thread Michael Niedermayer
On Tue, Mar 11, 2025 at 02:04:30PM +0100, Michael Niedermayer wrote:
> and call it from ff_ffv1_encode_init()
> 
> setting micro version from code writing the extradata is messy, this should
> be cleaner
> 
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/ffv1enc.c | 27 +++
>  1 file changed, 19 insertions(+), 8 deletions(-)

will apply

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

Never trust a computer, one day, it may think you are the virus. -- Compn


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


Re: [FFmpeg-devel] [PATCH 1/4] avcodec/ffv1enc: add space for the remap table to max_size

2025-03-13 Thread Michael Niedermayer
On Sun, Mar 09, 2025 at 11:58:03PM +0100, Michael Niedermayer wrote:
> Sponsored-by: Sovereign Tech Fund
> Signed-off-by: Michael Niedermayer 
> ---
>  libavcodec/ffv1enc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
> index b4080f29002..7c73ff12c2f 100644
> --- a/libavcodec/ffv1enc.c
> +++ b/libavcodec/ffv1enc.c
> @@ -1211,7 +1211,8 @@ size_t ff_ffv1_encode_buffer_size(AVCodecContext *avctx)
>  size_t maxsize = avctx->width*avctx->height * (1 + f->transparency);
>  if (f->chroma_planes)
>  maxsize += AV_CEIL_RSHIFT(avctx->width, f->chroma_h_shift) * 
> AV_CEIL_RSHIFT(f->height, f->chroma_v_shift) * 2;
> -maxsize += f->slice_count * 800; //for slice header
> +maxsize += f->slice_count * 800; //for slice header and
> +maxsize += f->slice_count * 9000 * !!f->flt; //remap table
>  if (f->version > 3) {
>  maxsize *= f->bits_per_raw_sample + 1;
>  } else {

will apply this without the typo and with a more correct estimation

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

Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety -- Benjamin Franklin


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] [FFmpeg-cvslog] swscale: use 16-bit intermediate precision for RGB/XYZ conversion

2025-03-13 Thread Michael Niedermayer
Hi

On Sun, Jan 26, 2025 at 07:26:59PM +0100, Michael Niedermayer wrote:
> On Thu, Dec 26, 2024 at 07:33:23PM +, Niklas Haas wrote:
> > ffmpeg | branch: master | Niklas Haas  | Mon Dec 16 
> > 14:49:39 2024 +0100| [af6d52eec66961f6a502b0f2f390c12226d087cd] | 
> > committer: Niklas Haas
> > 
> > swscale: use 16-bit intermediate precision for RGB/XYZ conversion
> > 
> > The current logic uses 12-bit linear light math, which is woefully 
> > insufficient
> > and leads to nasty postarization artifacts. This patch simply switches the
> > internal logic to 16-bit precision.
> > 
> > This raises the memory requirement of these tables from 32 kB to 272 kB.
> > 
> > All relevant FATE tests updated for improved accuracy.
> > 
> > Fixes: #4829
> > Signed-off-by: Niklas Haas 
> > Sponsored-by: Sovereign Tech Fund
> > 
> > > http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=af6d52eec66961f6a502b0f2f390c12226d087cd
> > ---
> 
> this breaks on x86-32

ping

the fate tests for a major architecture are broken since this
This impacts future bisections over that range for example

you can trivially test this on x86-64 with something like:
--cross-prefix=/usr/i686-linux-gnu/bin/ --cc='ccache i686-linux-gnu-gcc-7' 
--arch=x86_32  --target-os=linux --enable-cross-compile
if you have the correponding packages installed

before af6d52eec66961f6a502b0f2f390c12226d087cd
TESTfilter-pixdesc-xyz12be

after af6d52eec66961f6a502b0f2f390c12226d087cd:
--- src/tests/ref/fate/filter-pixdesc-xyz12be   2025-03-14 00:46:40.445681223 
+0100
+++ tests/data/fate/filter-pixdesc-xyz12be  2025-03-14 00:47:08.301903796 
+0100
@@ -1 +1 @@
-pixdesc-xyz12be 1508a33dea936c45d9ee13f7743af00d
+pixdesc-xyz12be 198f43f452bc55f4ca1e0e0171de5c4c
Test filter-pixdesc-xyz12be failed. Look at 
tests/data/fate/filter-pixdesc-xyz12be.err for details.
make: *** [src/tests/Makefile:311: fate-filter-pixdesc-xyz12be] Error 1

in master:
--- src/tests/ref/fate/filter-pixdesc-xyz12be   2025-03-14 00:46:40.445681223 
+0100
+++ tests/data/fate/filter-pixdesc-xyz12be  2025-03-14 00:48:43.042660972 
+0100
@@ -1 +1 @@
-pixdesc-xyz12be 1508a33dea936c45d9ee13f7743af00d
+pixdesc-xyz12be 198f43f452bc55f4ca1e0e0171de5c4c
Test filter-pixdesc-xyz12be failed. Look at 
tests/data/fate/filter-pixdesc-xyz12be.err for details.
make: *** [src/tests/Makefile:315: fate-filter-pixdesc-xyz12be] Error 1


thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Never trust a computer, one day, it may think you are the virus. -- Compn


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/ffv1: Implement jeromes idea of making remap flip optional

2025-03-13 Thread Michael Niedermayer
Hi Jerome

On Tue, Mar 11, 2025 at 04:33:11PM +0100, Jerome Martinez wrote:
> Le 11/03/2025 à 15:04, Michael Niedermayer a écrit :
> > Re: [FFmpeg-devel] [PATCH] avcodec/ffv1: Implement jeromes idea of making 
> > remap flip optional
> 
> Thanks.
> 
> 
> > -if (sc->remap > 1U ||
> > -sc->remap == 1 && !f->flt) {
> > +if (sc->remap > 2U ||
> > +sc->remap && !f->flt) {
> >   av_log(f->avctx, AV_LOG_ERROR, "unsupported remap %d\n", 
> > sc->remap);
> >   return AVERROR_INVALIDDATA;
> >   }
> 
> As the feature is now independent of f->flt, it seems that we can remove the
> "sc->remap && !f->flt" check, it should be supported with integers (actually
> whatever is the value of !f->flt) too.

yes, as soon as someone tests and verifies it works with integers


> 
> 
> > +{ "remap_mode", "Remap Mode", OFFSET(remap_mode), AV_OPT_TYPE_INT, { 
> > .i64 = -1 }, -1, 2, VE, .unit = "remap_mode" },
> > +{ "auto", "Automatic", 0, AV_OPT_TYPE_CONST,
> > +{ .i64 = -1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
> > +{ "off", "Disabled", 0, AV_OPT_TYPE_CONST,
> > +{ .i64 =  0 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
> > +{ "dualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
> > +{ .i64 =  1 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
> > +{ "flipdualrle", "Dual RLE", 0, AV_OPT_TYPE_CONST,
> > +{ .i64 =  2 }, INT_MIN, INT_MAX, VE, .unit = "remap_mode" },
> 
> Even better to have na option for it.
> LGTM.

will apply

thx

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

No snowflake in an avalanche ever feels responsible. -- 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] avcodec/x86/hevc/dsp_init: Rename, ff_hevc_put_hevc->ff_hevc_put

2025-03-13 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> Andreas Rheinhardt:
>> Patch attached.
>>
>> - Andreas
>>
> Now truely attached.
> 
> - Andreas
> 

Will apply this patch tomorrow unless there are objections.

- Andreas

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

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


[FFmpeg-devel] [PATCH v6 1/3] fftools: Add a local logging callback function

2025-03-13 Thread softworkz
From: softworkz 

This gets fftools its own management of log level and flags for and
provides an fftools-specific logging callback.
This makes it easier to implement specific logging behaviors which are
incompatible with direct use of the av libs and cannot be done in
libavutil.

Signed-off-by: softworkz 
---
 fftools/Makefile  |   7 +-
 fftools/cmdutils.c|   3 +-
 fftools/ffmpeg.c  |  10 +-
 fftools/ffplay.c  |   6 +-
 fftools/ffprobe.c |   4 +-
 fftools/fftools_log.c | 448 ++
 fftools/fftools_log.h |  96 +
 fftools/opt_common.c  |  41 ++--
 8 files changed, 586 insertions(+), 29 deletions(-)
 create mode 100644 fftools/fftools_log.c
 create mode 100644 fftools/fftools_log.h

diff --git a/fftools/Makefile b/fftools/Makefile
index 4499799818..5ae3e7af10 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -19,10 +19,15 @@ OBJS-ffmpeg +=  \
 fftools/ffmpeg_mux_init.o   \
 fftools/ffmpeg_opt.o\
 fftools/ffmpeg_sched.o  \
+fftools/fftools_log.o   \
 fftools/sync_queue.o\
 fftools/thread_queue.o  \
 
-OBJS-ffplay += fftools/ffplay_renderer.o
+OBJS-ffprobe += \
+fftools/fftools_log.o   \
+
+OBJS-ffplay += fftools/ffplay_renderer.o  \
+   fftools/fftools_log.o  \
 
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o 
$(OBJS-$(1)-yes)
diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 8ac20bf049..0bf453508d 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -46,6 +46,7 @@
 #include "libavutil/dict.h"
 #include "libavutil/opt.h"
 #include "cmdutils.h"
+#include "fftools_log.h"
 #include "fopen_utf8.h"
 #include "opt_common.h"
 #ifdef _WIN32
@@ -608,7 +609,7 @@ int opt_default(void *optctx, const char *opt, const char 
*arg)
 #endif
 
 if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
-av_log_set_level(AV_LOG_DEBUG);
+ff_log_set_level(AV_LOG_DEBUG);
 
 if (!(p = strchr(opt, ':')))
 p = opt + strlen(opt);
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index dc321fb4a2..b845fa2ba4 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -81,6 +81,7 @@
 #include "ffmpeg.h"
 #include "ffmpeg_sched.h"
 #include "ffmpeg_utils.h"
+#include "fftools_log.h"
 
 const char program_name[] = "ffmpeg";
 const int program_birth_year = 2000;
@@ -671,7 +672,7 @@ static void print_report(int is_last_report, int64_t 
timer_start, int64_t cur_ti
 
 if (print_stats || is_last_report) {
 const char end = is_last_report ? '\n' : '\r';
-if (print_stats==1 && AV_LOG_INFO > av_log_get_level()) {
+if (print_stats==1 && AV_LOG_INFO > ff_log_get_level()) {
 fprintf(stderr, "%s%c", buf.str, end);
 } else
 av_log(NULL, AV_LOG_INFO, "%s%c", buf.str, end);
@@ -801,8 +802,8 @@ static int check_keyboard_interaction(int64_t cur_time)
 av_log(NULL, AV_LOG_INFO, "\n\n[q] command received. Exiting.\n\n");
 return AVERROR_EXIT;
 }
-if (key == '+') av_log_set_level(av_log_get_level()+10);
-if (key == '-') av_log_set_level(av_log_get_level()-10);
+if (key == '+') ff_log_set_level(ff_log_get_level()+10);
+if (key == '-') ff_log_set_level(ff_log_get_level()-10);
 if (key == 'c' || key == 'C'){
 char buf[4096], target[64], command[256], arg[256] = {0};
 double time;
@@ -954,7 +955,8 @@ int main(int argc, char **argv)
 
 setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
 
-av_log_set_flags(AV_LOG_SKIP_REPEATED);
+ff_log_set_flags(FF_LOG_SKIP_REPEATED);
+init_logging();
 parse_loglevel(argc, argv, options);
 
 #if CONFIG_AVDEVICE
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 2a572fc3aa..1d4870fd99 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -57,6 +57,7 @@
 #include "cmdutils.h"
 #include "ffplay_renderer.h"
 #include "opt_common.h"
+#include "fftools_log.h"
 
 const char program_name[] = "ffplay";
 const int program_birth_year = 2003;
@@ -1735,7 +1736,7 @@ display:
   vqsize / 1024,
   sqsize);
 
-if (show_status == 1 && AV_LOG_INFO > av_log_get_level())
+if (show_status == 1 && AV_LOG_INFO > ff_log_get_level())
 fprintf(stderr, "%s", buf.str);
 else
 av_log(NULL, AV_LOG_INFO, "%s", buf.str);
@@ -3761,7 +3762,8 @@ int main(int argc, char **argv)
 
 init_dynload();
 
-av_log_set_flags(AV_LOG_SKIP_REPEATED);
+ff_log_set_flags(FF_LOG_SKIP_REPEATED);
+init_logging();
 parse_loglevel(argc, argv, options);
 
 /* register all codecs, demux and protocols */
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 7341731d2f..98540982c4 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -68,6 +68,7 @@
 #include "libavfilter/version.h"
 #include "cmdutils.h"
 #include "opt_common.h"
+#include "fftoo

Re: [FFmpeg-devel] [PATCH] avformat/avio: Add max_pkt_size option

2025-03-13 Thread Marton Balint




On Thu, 13 Mar 2025, Zhao Zhili wrote:


From: Zhao Zhili 

Optimizing memory footprint in memory-constrained systems.

Signed-off-by: Zhao Zhili 
---
libavformat/avio.c| 2 ++
libavformat/version.h | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index d109f3adff..e1b959ed73 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -61,6 +61,8 @@ static const AVOption options[] = {
{"protocol_whitelist", "List of protocols that are allowed to be used", 
OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, D },
{"protocol_blacklist", "List of protocols that are not allowed to be used", 
OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, D },
{"rw_timeout", "Timeout for IO operations (in microseconds)", 
offsetof(URLContext, rw_timeout), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, INT64_MAX, 
AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
+{"max_pkt_size", "Default maximum packet size in bytes, could be overwritten by 
particular protocol",
+offsetof(URLContext, max_packet_size), AV_OPT_TYPE_INT, { .i64 = 
IO_BUFFER_SIZE }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM | 
AV_OPT_FLAG_DECODING_PARAM },
{ NULL }
};



This feels super confusing. A *max_packet_size* option which might not do 
anything at all depending on the protocol the user is using, and which 
the user might override with the protocol specific *pkt_size* option if it 
exists. So I'd rather not expose ->max_pkt_size like that.


Regards,
Marton




diff --git a/libavformat/version.h b/libavformat/version.h
index 6ffdf61b43..e1ab967f5b 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
#include "version_major.h"

#define LIBAVFORMAT_VERSION_MINOR   9
-#define LIBAVFORMAT_VERSION_MICRO 107
+#define LIBAVFORMAT_VERSION_MICRO 108

#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
   LIBAVFORMAT_VERSION_MINOR, \
--
2.46.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 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 00/12] avcodec/sanm: various improvements

2025-03-13 Thread Michael Niedermayer
Hi Manuel

On Thu, Mar 13, 2025 at 12:14:53PM +0100, Manuel Lauss wrote:
> This patchset improves especially support for SMUSHv1 (Rebel Assault 1),
> adds missing codecs and functions and improves reliability of SMUSHv1/v2.
> 
> #1 improves frame size detection.
> #3 changes the left/top values to signed, as RA1 makes heavy use of
>negative offsets.
> #4 adds workarounds for RA1 oddities.
> #5-10 add missing codecs and fix existing ones.
> #11-12 implement the store/fetch feature for RA1 codecs:
>   the RA1 engine stores the raw frame object data in an aux
>   buffer and replays that when necessary.  Is required for
>   codecs1-34 since they only work on parts of the buffer,
>   and the existing scheme breaks the visuals here.
> 
> This patchset makes almost all RA1 videos now playable with
> generally correct content, although some hiccups remain.

please add yourself to the MAINTAINER file for sanm with a patch
you are already maintaining sanm, its just not written in the file

thx

[...]

-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad


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 09/12] avcodec/sanm: codec4/5/33/34 decoder

2025-03-13 Thread Andreas Rheinhardt
Manuel Lauss:
> This codec works on 4x4 pixel tiles, which can be generated and read
> from the datastream.  They're both identical, codec5 misses a tile
> index to skip the current tile.
> Codecs33/34 are the same as 4/5 but with a different tileset generator.
> Used only in Rebel Assault 1.
> 
> Signed-off-by: Manuel Lauss 
> ---
>  libavcodec/sanm.c | 229 ++
>  1 file changed, 229 insertions(+)
> 
> diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
> index bf2ec40df4..91c8ba658b 100644
> --- a/libavcodec/sanm.c
> +++ b/libavcodec/sanm.c
> @@ -293,6 +293,8 @@ typedef struct SANMVideoContext {
>  int8_t p8x8glyphs[NGLYPHS][64];
>  uint8_t c47itbl[0x1];
>  uint8_t c23lut[256];
> +uint8_t c4tbl[2][256][16];
> +uint16_t c4param;
>  } SANMVideoContext;
>  
>  typedef struct SANMFrameHeader {
> @@ -480,6 +482,142 @@ static av_cold int init_buffers(SANMVideoContext *ctx)
>  return 0;
>  }
>  
> +static void codec33_gen_tiles(SANMVideoContext *ctx, int8_t param1)
> +{
> +uint8_t *dst = &(ctx->c4tbl[0][0][0]);
> +int i, j, k, l, m, n, o, p;
> +
> +for (i = 0; i < 8; i++) {
> +for (k = 0; k < 8; k++) {
> +j = i + param1;
> +l = k + param1;
> +p = (j + k) / 2;
> +j = (j + p) / 2;
> +m = l / 2;
> +n = (i + param1);
> +o = (k + param1);
> +
> +*dst++ = p; *dst++ = p; *dst++ = j; *dst++ = n;
> +*dst++ = p; *dst++ = p; *dst++ = j; *dst++ = i;
> +*dst++ = m; *dst++ = m; *dst++ = p; *dst++ = j;
> +*dst++ = l; *dst++ = l; *dst++ = m; *dst++ = p;
> +}
> +}
> +
> +for (i = 0; i < 8; i++) {
> +for (k = 0; k < 8; k++) {
> +j = i + param1;
> +l = k + param1;
> +n = ((j + l) / 2);
> +m = ((l + n) / 2);
> +
> +*dst++ = j; *dst++ = j; *dst++ = j; *dst++ = j;
> +*dst++ = n; *dst++ = n; *dst++ = n; *dst++ = n;
> +*dst++ = m; *dst++ = m; *dst++ = m; *dst++ = m;
> +*dst++ = l; *dst++ = l; *dst++ = l; *dst++ = l;
> +}
> +}
> +
> +for (i = 0; i < 8; i++) {
> +for (k = 0; k < 8; k++) {
> +j = i + param1;
> +l = k + param1;
> +m = (j + l) / 2;
> +n = (j + m) / 2;
> +o = m / 2;
> +p = j & 0xff;
> +
> +*dst++ = p; *dst++ = p; *dst++ = n; *dst++ = m;
> +*dst++ = p; *dst++ = p; *dst++ = n; *dst++ = m;
> +*dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
> +*dst++ = m; *dst++ = m; *dst++ = o; *dst++ = l;
> +}
> +}
> +
> +for (i = 0; i < 8; i++) {
> +for (k = 0; k < 8; k++) {
> +j = i + param1;
> +l = k + param1;
> +m = (j + l) / 2;
> +n = m / 2;
> +
> +*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
> +*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
> +*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
> +*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
> +}
> +}
> +}
> +
> +static void codec4_gen_tiles(SANMVideoContext *ctx, uint16_t param1)
> +{
> +uint8_t *dst = &(ctx->c4tbl[0][0][0]);
> +int i, j, k, l, m, n, o;
> +
> +for (i = 1; i < 16; i += 2) {
> +for (k = 0; k < 16; k++) {
> +j = i + param1;
> +l = k + param1;
> +m = (j + l) / 2;
> +n = (j + m) / 2;
> +o = (l + m) / 2;
> +if (j == m || l == m) {
> +*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
> +*dst++ = j; *dst++ = l; *dst++ = j; *dst++ = j;
> +*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
> +*dst++ = l; *dst++ = l; *dst++ = j; *dst++ = l;
> +} else {
> +*dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
> +*dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
> +*dst++ = o; *dst++ = o; *dst++ = m; *dst++ = n;
> +*dst++ = l; *dst++ = l; *dst++ = o; *dst++ = m;
> +}
> +}
> +}
> +
> +for (i = 0; i < 16; i += 2) {
> +for (k = 0; k < 16; k++) {
> +j = i + param1;
> +l = k + param1;
> +m = (j + l) / 2;
> +n = (j + m) / 2;
> +o = (l + m) / 2;
> +if (m == j || m == l) {
> +*dst++ = j; *dst++ = j; *dst++ = l; *dst++ = j;
> +*dst++ = j; *dst++ = j; *dst++ = j; *dst++ = l;
> +*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = l;
> +*dst++ = j; *dst++ = l; *dst++ = j; *dst++ = l;
> +} else {
> +*dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
> +*dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
> +*dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
> +

Re: [FFmpeg-devel] [PATCH v4 15/16] FFHWAccel: add buffer_ref argument to start_frame

2025-03-13 Thread Lynne

On 14/03/2025 00:03, Lynne wrote:



On 13/03/2025 23:08, Andreas Rheinhardt wrote:

Lynne:

This commit adds a reference to the buffer as an argument to
start_frame, and adapts all existing code.

This allows for asynchronous hardware accelerators to skip
copying packet data by referencing it.
---
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index da8fdc5935..20ef821819 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3401,7 +3401,10 @@ static int hevc_frame_start(HEVCContext *s, 
HEVCLayerContext *l,

  goto fail;
  if (s->avctx->hwaccel) {
-    ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
+    AVCodecInternal *avci = s->avctx->internal;
+    AVPacket *avpkt = avci->in_pkt;
+    ret = FF_HW_CALL(s->avctx, start_frame,
+ avpkt->buf, NULL, 0);
  if (ret < 0)
  goto fail;
  }
diff --git a/libavcodec/hwaccel_internal.h b/libavcodec/ 
hwaccel_internal.h

index 77df4e0904..4eb74f0b34 100644
--- a/libavcodec/hwaccel_internal.h
+++ b/libavcodec/hwaccel_internal.h
@@ -52,11 +52,13 @@ typedef struct FFHWAccel {
   * Otherwise, this means the whole frame is available at this 
point.

   *
   * @param avctx the codec context
+ * @param buf_ref the frame data buffer reference (optional)
   * @param buf the frame data buffer base
   * @param buf_size the size of the frame in bytes
   * @return zero if successful, a negative value otherwise
   */
-    int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, 
uint32_t buf_size);

+    int (*start_frame)(AVCodecContext *avctx, AVBufferRef *buf_ref,


const AVBufferRef*, we are not passing ownership


Done locally.


Why did you not make this the last parameter (given that only very few
hwaccels will access it)?


It made more sense to have it upfront as it backs up the data given.
I can change it, but I'd rather not, unless you have a strong opinion.


+   const uint8_t *buf, uint32_t buf_size);
  /**
   * Callback for parameter data (SPS/PPS/VPS etc).
diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
index bd1b502e50..f3d940671e 100644
--- a/libavcodec/mjpegdec.c
+++ b/libavcodec/mjpegdec.c
@@ -808,7 +808,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
  if (!s->hwaccel_picture_private)
  return AVERROR(ENOMEM);
-    ret = hwaccel->start_frame(s->avctx, s->raw_image_buffer,
+    ret = hwaccel->start_frame(s->avctx, NULL, s->raw_image_buffer,
 s->raw_image_buffer_size);
  if (ret < 0)
  return ret;
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index ffe0710470..c21f220680 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1361,7 +1361,7 @@ static int mpeg_field_start(Mpeg1Context *s1, 
const uint8_t *buf, int buf_size)

  }
  if (avctx->hwaccel) {
-    if ((ret = FF_HW_CALL(avctx, start_frame, buf, buf_size)) < 0)
+    if ((ret = FF_HW_CALL(avctx, start_frame, NULL, buf, 
buf_size)) < 0)

  return ret;
  } else if (s->codec_tag == MKTAG('V', 'C', 'R', '2')) {
  // Exchange UV
diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c
index 6b408edb87..9b9be702d5 100644
--- a/libavcodec/nvdec_vp9.c
+++ b/libavcodec/nvdec_vp9.c
@@ -29,7 +29,8 @@
  #include "internal.h"
  #include "vp9shared.h"
-static int nvdec_vp9_start_frame(AVCodecContext *avctx, const 
uint8_t *buffer, uint32_t size)
+static int nvdec_vp9_start_frame(AVCodecContext *avctx, AVBufferRef 
*buffer_ref,

+ const uint8_t *buffer, uint32_t size)
  {
  VP9SharedContext *h = avctx->priv_data;
  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx- 
>sw_pix_fmt);

diff --git a/libavcodec/proresdec.c b/libavcodec/proresdec.c
index 01caa611a0..edc46e1442 100644
--- a/libavcodec/proresdec.c
+++ b/libavcodec/proresdec.c
@@ -793,7 +793,7 @@ static int decode_frame(AVCodecContext *avctx, 
AVFrame *frame,

  if (HWACCEL_MAX && avctx->hwaccel) {
  const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel);
-    ret = hwaccel->start_frame(avctx, NULL, 0);
+    ret = hwaccel->start_frame(avctx, avpkt->buf, NULL, 0);


Passing an AVBufferRef for NULL data seems fishy.


I misinterpreted what NULL means.
Changed this to be NULL.


Looked into proresdec.c and vp9.c, both of them had done the same,
start_frame(NULL, 0), and the code was copy pasted between both. But the 
size of the packet is already known in advance.

Changed to start_frame(avpkt->buf, avpkt->data, avpkt->size) for both.
mjpegdec.c is the only user of the API which has a genuine need to have 
buf as NULL, 0.


This isn't as niche as it sounds. This enables us to add a fast path for 
D3D12, Vulkan and likely VAAPI if anyone is interested.

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
h

Re: [FFmpeg-devel] [PATCH] avformat/avio: Add max_pkt_size option

2025-03-13 Thread Zhao Zhili


> On Mar 14, 2025, at 04:03, Marton Balint  wrote:
> 
> 
> On Thu, 13 Mar 2025, Zhao Zhili wrote:
> 
>> From: Zhao Zhili 
>> 
>> Optimizing memory footprint in memory-constrained systems.
>> 
>> Signed-off-by: Zhao Zhili 
>> ---
>> libavformat/avio.c| 2 ++
>> libavformat/version.h | 2 +-
>> 2 files changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/libavformat/avio.c b/libavformat/avio.c
>> index d109f3adff..e1b959ed73 100644
>> --- a/libavformat/avio.c
>> +++ b/libavformat/avio.c
>> @@ -61,6 +61,8 @@ static const AVOption options[] = {
>>{"protocol_whitelist", "List of protocols that are allowed to be used", 
>> OFFSET(protocol_whitelist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 0, D },
>>{"protocol_blacklist", "List of protocols that are not allowed to be 
>> used", OFFSET(protocol_blacklist), AV_OPT_TYPE_STRING, { .str = NULL },  0, 
>> 0, D },
>>{"rw_timeout", "Timeout for IO operations (in microseconds)", 
>> offsetof(URLContext, rw_timeout), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 
>> INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_DECODING_PARAM },
>> +{"max_pkt_size", "Default maximum packet size in bytes, could be 
>> overwritten by particular protocol",
>> +offsetof(URLContext, max_packet_size), AV_OPT_TYPE_INT, { .i64 
>> = IO_BUFFER_SIZE }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM | 
>> AV_OPT_FLAG_DECODING_PARAM },
>>{ NULL }
>> };
> 
> 
> This feels super confusing. A *max_packet_size* option which might not do 
> anything at all depending on the protocol the user is using, and which the 
> user might override with the protocol specific *pkt_size* option if it 
> exists. So I'd rather not expose ->max_pkt_size like that.

rw_timeout has the same issue, it’s still useful for users.

The patch is for 

https://ffmpeg.org/pipermail/ffmpeg-devel/2025-March/341114.html

We can add pkt_size for more protocols, but it sounds weird for tcp
with pkt_size option.

Use can change AVIOContext::max_packet_size directly. I’m not sure
if it’s better or valid.

> 
> Regards,
> Marton
> 
> 
>> 
>> diff --git a/libavformat/version.h b/libavformat/version.h
>> index 6ffdf61b43..e1ab967f5b 100644
>> --- a/libavformat/version.h
>> +++ b/libavformat/version.h
>> @@ -32,7 +32,7 @@
>> #include "version_major.h"
>> 
>> #define LIBAVFORMAT_VERSION_MINOR   9
>> -#define LIBAVFORMAT_VERSION_MICRO 107
>> +#define LIBAVFORMAT_VERSION_MICRO 108
>> 
>> #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
>>   LIBAVFORMAT_VERSION_MINOR, \
>> -- 
>> 2.46.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 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 v6 0/3] avutil/log: Replace addresses in log output with simple ids

2025-03-13 Thread ffmpegagent
..and individual numbering. The benefits are:

 * Smaller log file sizes
 * The disambiguation is much easier to recognize and to follow
 * It eventually allows comparing and viewing log file diffs without almost
   every line being different due to those addresses


Before
==

[hevc @ 018e72a89cc0] nal_unit_type:
[hevc @ 018e72a89cc0] Decoding PPS
[hevc @ 018e72a89cc0] nal_unit_type: 39(SEI_P.. [hevc @
018e72a89cc0] Decoding SEI
[mp4 @ 018e72a8e240] All [mp4 @ 018e72a8e240] Afte [hevc @
018e742f6b40] Decoded frame with POC .. detected 16 logical cores
[Parsed_scale_0 @ 018e74382f40] Setting 'w' t.. [Parsed_scale_0 @
018e74382f40] Setting 'h' t.. [Parsed_scale_1 @ 018e74382440]
Setting 'w' t.. [mjpeg @ 018e743210c0] Forcing thread count t.. [mjpeg @
018e743210c0] intra_quant_bias = 96


After
=

[hevc #0] nal_unit_type: [hevc #0] Decoding PPS
[hevc #0] nal_unit_type: 39(SEI_P.. [hevc #0] Decoding SEI
[mp4 #0] All info found
[mp4 #0] After avformat_find_ [hevc #1] Decoded frame with POC 2.
[Parsed_scale_0 #0] Setting 'w' t.. [Parsed_scale_0 #0] Setting 'h' t..
[Parsed_scale_1 #1] Setting 'w' t.. [mjpeg #2] Forcing thread count t..
[mjpeg #2] intra_quant_bias = 96


Versions



V2
==

 * Added log flag for optionally restoring the previous behavior (as
   requested by Gyan)


V3
==

 * Externalize the prefix formatting with a prefix_format callback


V4
==

 * Implement a custom logging callback function for fftools instead of the
   prefix formatting callback (as suggested by Hendrik Leppkes)


V5
==

 * Remove unused var
 * Add missing include to fix build error on PPC (thanks, Michael)


V6
==

 * No more changes to avutil involved
 * Let fftools have its own management of log level and flags (as figured to
   be most likely what Nicolas George was alluding to)

softworkz (3):
  fftools: Add a local logging callback function
  fftools/opt_common: add memaddresses log flag
  doc/fftools-common-opts: document memaddresses log flag

 doc/fftools-common-opts.texi |   2 +
 fftools/Makefile |   7 +-
 fftools/cmdutils.c   |   4 +-
 fftools/ffmpeg.c |  10 +-
 fftools/ffplay.c |   6 +-
 fftools/ffprobe.c|   4 +-
 fftools/fftools_log.c| 503 +++
 fftools/fftools_log.h| 101 +++
 fftools/opt_common.c |  47 ++--
 9 files changed, 655 insertions(+), 29 deletions(-)
 create mode 100644 fftools/fftools_log.c
 create mode 100644 fftools/fftools_log.h


base-commit: 1bce40cb73fffd9d1fb6e118d71ac8999cded808
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-59%2Fsoftworkz%2Fsubmit_logaddresses-v6
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-59/softworkz/submit_logaddresses-v6
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/59

Range-diff vs v5:

 1:  4be966796c < -:  -- avutil/log: Add AV_LOG_PRINT_MEMADDRESSES 
logging flag
 2:  e4f8213c24 < -:  -- fftools/opt_common: add memaddresses log flag
 3:  ba20f5b116 ! 1:  8080f15800 fftools: Provide a an fftools-specific logging 
callback function
 @@ Metadata
  Author: softworkz 
  
   ## Commit message ##
 -fftools: Provide a an fftools-specific logging callback function
 +fftools: Add a local logging callback function
  
 -This goes together with a change to logging of context prefixes, which
 -is printing logical ids instead of memory addresses.
 -The benefits are:
 +This gets fftools its own management of log level and flags for and
 +provides an fftools-specific logging callback.
 +This makes it easier to implement specific logging behaviors which are
 +incompatible with direct use of the av libs and cannot be done in
 +libavutil.
  
 -- Smaller log file sizes
 -- The disambiguation is much easier to recognize and to follow
 -- It eventually allows comparing and viewing log file diffs
 -  without almost every line being different due to those addresses
 +Signed-off-by: softworkz 
  
   ## fftools/Makefile ##
  @@ fftools/Makefile: OBJS-ffmpeg +=  \
 @@ fftools/Makefile: OBJS-ffmpeg +=  \
   define DOFFTOOL
   OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o 
$(OBJS-$(1)-yes)
  
 + ## fftools/cmdutils.c ##
 +@@
 + #include "libavutil/dict.h"
 + #include "libavutil/opt.h"
 + #include "cmdutils.h"
 ++#include "fftools_log.h"
 + #include "fopen_utf8.h"
 + #include "opt_common.h"
 + #ifdef _WIN32
 +@@ fftools/cmdutils.c: int opt_default(void *optctx, const char *opt, 
const char *arg)
 + #endif
 + 
 + if (!strcmp(opt, "debug") || !strcmp(opt, "fdebug"))
 +-av_log_set_level(AV_LOG_DEBUG);
 ++ff_log_set_level(AV_LOG_DEBUG);
 + 

[FFmpeg-devel] [PATCH v6 2/3] fftools/opt_common: add memaddresses log flag

2025-03-13 Thread softworkz
From: softworkz 

This commit adds the memaddresses log flag.
When specifying this flag at the command line, context prefixes will
be printed with memory addresses like in earlier ffmpeg versions.
Memory addresses are no longer printed by default.

The benefits are:

- Smaller log file sizes
- The disambiguation is much easier to recognize and to follow
- It eventually allows comparing and viewing log file diffs
  without almost every line being different due to those addresses

Example with memaddresses flag:

[hevc @ 018e72a89cc0] .

without (new behavior):

[hevc #0] .

Signed-off-by: softworkz 
---
 fftools/cmdutils.c|  1 +
 fftools/fftools_log.c | 67 +++
 fftools/fftools_log.h |  5 
 fftools/opt_common.c  |  6 
 4 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 0bf453508d..fb05f3fd2f 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -46,6 +46,7 @@
 #include "libavutil/dict.h"
 #include "libavutil/opt.h"
 #include "cmdutils.h"
+
 #include "fftools_log.h"
 #include "fopen_utf8.h"
 #include "opt_common.h"
diff --git a/fftools/fftools_log.c b/fftools/fftools_log.c
index f8f098fef9..b83c8abcaa 100644
--- a/fftools/fftools_log.c
+++ b/fftools/fftools_log.c
@@ -59,6 +59,53 @@ static inline struct tm *ff_localtime_r(const time_t* clock, 
struct tm *result)
 #define localtime_r ff_localtime_r
 #endif
 
+#define MAX_CLASS_IDS 1000
+static struct class_ids {
+void *avcl;
+uint64_t class_hash;
+unsigned id;
+} class_ids[MAX_CLASS_IDS];
+
+static uint64_t fnv_hash(const char *str)
+{
+// FNV-1a 64-bit hash algorithm
+uint64_t hash = 0xcbf29ce484222325ULL;
+while (*str) {
+hash ^= (unsigned char)*str++;
+hash *= 0x10001b3ULL;
+}
+return hash;
+}
+
+static unsigned get_class_id(void* avcl)
+{
+AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
+unsigned i, nb_ids = 0;
+uint64_t class_hash;
+
+for (i = 0; i < MAX_CLASS_IDS && class_ids[i].avcl; i++) {
+if (class_ids[i].avcl == avcl)
+return class_ids[i].id;
+}
+
+class_hash = fnv_hash(avc->class_name);
+
+for (i = 0; i < MAX_CLASS_IDS; i++) {
+if (class_ids[i].class_hash == class_hash)
+nb_ids++;
+
+if (!class_ids[i].avcl) {
+class_ids[i].avcl = avcl;
+class_ids[i].class_hash = class_hash;
+class_ids[i].id = nb_ids;
+return class_ids[i].id;
+}
+}
+
+// exceeded MAX_CLASS_IDS entries in class_ids[]
+return 0;
+}
+
 static AVMutex mutex = AV_MUTEX_INITIALIZER;
 
 #define LINE_SZ 1024
@@ -316,6 +363,15 @@ static void format_date_now(AVBPrint* bp_time, int 
include_date)
 }
 }
 
+static void log_formatprefix(AVBPrint* buffer, AVClass** avcl)
+{
+const int print_mem = ff_log_flags & FF_LOG_PRINT_MEMADDRESSES;
+if (print_mem)
+av_bprintf(buffer+0, "[%s @ %p] ", item_name(avcl, *avcl), avcl);
+else
+av_bprintf(buffer+0, "[%s #%u] ", item_name(avcl, *avcl), 
get_class_id(avcl));
+}
+
 static void format_line(void *avcl, int level, const char *fmt, va_list vl,
 AVBPrint part[5], int *print_prefix, int type[2])
 {
@@ -328,17 +384,16 @@ static void format_line(void *avcl, int level, const char 
*fmt, va_list vl,
 
 if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
 if (*print_prefix && avc) {
+
 if (avc->parent_log_context_offset) {
-AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
-   avc->parent_log_context_offset);
+AVClass** parent = *(AVClass ***) ((uint8_t *)avcl + 
avc->parent_log_context_offset);
 if (parent && *parent) {
-av_bprintf(part+0, "[%s @ %p] ",
-   item_name(parent, *parent), parent);
+log_formatprefix(part, parent);
 if(type) type[0] = get_category(parent);
 }
 }
-av_bprintf(part+1, "[%s @ %p] ",
-   item_name(avcl, avc), avcl);
+log_formatprefix(part, avcl);
+
 if(type) type[1] = get_category(avcl);
 }
 
diff --git a/fftools/fftools_log.h b/fftools/fftools_log.h
index 4dba15ff7f..6333e4d3c1 100644
--- a/fftools/fftools_log.h
+++ b/fftools/fftools_log.h
@@ -92,5 +92,10 @@ int ff_log_get_flags(void);
  */
 #define FF_LOG_PRINT_DATETIME 8
 
+/**
+ * Print memory addresses instead of logical ids in the AVClass prefix.
+ */
+#define FF_LOG_PRINT_MEMADDRESSES 16
+
 
 #endif /* FFTOOLS_FFTOOLS_LOG_H */
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 702f62a6fe..53b6fb2257 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -1305,6 +1305,12 @@ int opt_loglevel(void *optctx, const char *opt, const 
char *arg)
 } else {
 flags |= FF_LOG_PRINT_DATETIME;
 }
+} else if (av_strstart(token, "m

Re: [FFmpeg-devel] [PATCH 1/1] avformat/avio: add configuration options for IO_BUFFER_SIZE

2025-03-13 Thread 姚靖威
The purpose of this patch is to modify the default buffer size of the avio
module during compilation.
On some resource-constrained devices to save memory, the current default
value (32K), it can also be set to a smaller value.

Nicolas George  于2025年3月11日周二 19:55写道:

> joney...@gmail.com (HE12025-03-11):
> > From: Jingwei Yao 
> >
> > Signed-off-by: Jingwei Yao 
> > ---
> >  configure | 6 ++
> >  libavformat/aviobuf.c | 2 +-
> >  2 files changed, 7 insertions(+), 1 deletion(-)
>
> Thanks for the patch. It is missing the explanations about why.
>
> Regards,
>
> --
>   Nicolas George
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
___
ffmpeg-devel 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] lavc/videotoolboxenc: add hevc main42210 and p210

2025-03-13 Thread Zhao Zhili


> On Mar 11, 2025, at 22:46, Zhao Zhili  
> wrote:
> 
> 
>> 在 2025年3月11日,下午6:16,Wang Bin  写道:
>> 
>> Zhao Zhili  于2025年3月11日周二 16:45写道:
>> 
>>> 
>>> 
> On Mar 11, 2025, at 14:20, Wang Bin  wrote:
 supported by apple silicon
 ---
 libavcodec/videotoolboxenc.c | 10 ++
 1 file changed, 10 insertions(+)
 
 diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
 index 55a440c7b4..92a4762caa 100644
 --- a/libavcodec/videotoolboxenc.c
 +++ b/libavcodec/videotoolboxenc.c
 @@ -120,6 +120,7 @@ static struct{
 
CFStringRef kVTProfileLevel_HEVC_Main_AutoLevel;
CFStringRef kVTProfileLevel_HEVC_Main10_AutoLevel;
 +CFStringRef kVTProfileLevel_HEVC_Main42210_AutoLevel;
 
CFStringRef kVTCompressionPropertyKey_RealTime;
CFStringRef kVTCompressionPropertyKey_TargetQualityForAlpha;
 @@ -192,6 +193,7 @@ static void loadVTEncSymbols(void){
 
GET_SYM(kVTProfileLevel_HEVC_Main_AutoLevel,
>>> "HEVC_Main_AutoLevel");
GET_SYM(kVTProfileLevel_HEVC_Main10_AutoLevel,
>>> "HEVC_Main10_AutoLevel");
 +GET_SYM(kVTProfileLevel_HEVC_Main42210_AutoLevel,
>>> "HEVC_Main10_AutoLevel");
>>> 
>>> A copy-paste error.
>>> 
>>> 
>> oops!
>> <0001-lavc-videotoolboxenc-add-hevc-main42210-and-p210.patch>
> 
> LGTM.

Applied as 154c00514d889d27ae84a1001e00f9032fdc1c54, thanks.

> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> 
> ___
> ffmpeg-devel 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 v2] ffbuild: read library linker objects from a file

2025-03-13 Thread Michael Niedermayer
Hi Gyan

On Wed, Mar 12, 2025 at 08:22:56PM +0530, Gyan Doshi wrote:
> The linker command can exceed the maximum argument limit on MinGW,
> especially for libavcodec.
> 
> The objects list is now stored in a file and passed to the linker.
> ---
> v2:
>static linking also switched to use a file for object list
>objs added to clean target and to gitignore
> 
>  .gitignore  | 1 +
>  ffbuild/common.mak  | 2 +-
>  ffbuild/library.mak | 8 ++--
>  3 files changed, 8 insertions(+), 3 deletions(-)

fails build

./configure && make -j32
...
make

AR  libavdevice/libavdevice.a
ar: $^: No such file or directory
make: *** [ffbuild/library.mak:39: libavdevice/libavdevice.a] Error 1

thx

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

The real ebay dictionary, page 1
"Used only once"- "Some unspecified defect prevented a second use"
"In good condition" - "Can be repaird by experienced expert"
"As is" - "You wouldnt want it even if you were payed for it, if you knew ..."


signature.asc
Description: PGP signature
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

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


[FFmpeg-devel] [PATCH 01/12] avcodec/sanm: better frame size detection for old codecs

2025-03-13 Thread Manuel Lauss
The size of the video frame (FOBJ) of the old codecs (ANIMv0/1/2) can
very reliably be determined:
- ANIMv0/1 (=Rebel Assault 1) uses a 384x242 internal buffer for
  everything.  The codec parameters only describe the size and offset
  of the specific FOBJ on that buffer.
- ANIMv2 titles usually use one of the fullscreen codecs (37/47/48)
  as first FOBJ, and their dimensions can generally be trusted.
- RA2 uses 424x260 as internal buffer, use that if encountered.
- ignore sizes smaller than 2x2 or larger than 800x600.
- some game videos have an initial fobj with either 1x1 or -1x-1
  pixels in size, ignore them with a warning (Full Throttle
  and the Rebel Assault 2 xxRETRY.SAN videos).

Once a known/valid dimension set has been discovered, use it and
don't change it for subsequent FOBJs, rather clamp the large frame
to the determined dimensions.

Tested with RA1, RA2, Full Throttle, Dig, Outlaws, SotE and MotS
videos.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 63 ---
 1 file changed, 49 insertions(+), 14 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index a4f0a28c7c..0795d664fa 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -264,7 +264,7 @@ typedef struct SANMVideoContext {
 AVCodecContext *avctx;
 GetByteContext gb;
 
-int version, subversion;
+int version, subversion, have_dimensions;
 uint32_t pal[PALETTE_SIZE];
 int16_t delta_pal[PALETTE_DELTA];
 
@@ -1243,21 +1243,56 @@ static int process_frame_obj(SANMVideoContext *ctx)
 uint16_t w = bytestream2_get_le16u(&ctx->gb);
 uint16_t h = bytestream2_get_le16u(&ctx->gb);
 
-if (!w || !h) {
-av_log(ctx->avctx, AV_LOG_ERROR, "Dimensions are invalid.\n");
-return AVERROR_INVALIDDATA;
+if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) {
+av_log(ctx->avctx, AV_LOG_WARNING,
+   "ignoring invalid fobj dimensions: c%d %d %d @ %d %d\n",
+   codec, w, h, left, top);
+return 0;
 }
 
-if (ctx->width < left + w || ctx->height < top + h) {
-int ret = ff_set_dimensions(ctx->avctx, FFMAX(left + w, ctx->width),
-FFMAX(top + h, ctx->height));
-if (ret < 0)
-return ret;
-init_sizes(ctx, FFMAX(left + w, ctx->width),
-   FFMAX(top + h, ctx->height));
-if (init_buffers(ctx)) {
-av_log(ctx->avctx, AV_LOG_ERROR, "Error resizing buffers.\n");
-return AVERROR(ENOMEM);
+if (!ctx->have_dimensions) {
+int xres, yres;
+if (ctx->subversion < 2) {
+/* Rebel Assault 1: 384x242 internal size */
+xres = 384;
+yres = 242;
+ctx->have_dimensions = 1;
+} else if (codec == 37 || codec == 47 || codec == 48) {
+/* these codecs work on full frames, trust their dimensions */
+xres = w;
+yres = h;
+ctx->have_dimensions = 1;
+} else {
+/* Rebel Assault 2: 424x260 internal size */
+if (((left + w) == 424) && ((top + h) == 260))
+ctx->have_dimensions = 1;
+
+xres = FFMAX(left + w, ctx->width);
+yres = FFMAX(top + h, ctx->height);
+}
+
+if (ctx->width < xres || ctx->height < yres) {
+int ret = ff_set_dimensions(ctx->avctx, xres, yres);
+if (ret < 0)
+return ret;
+init_sizes(ctx, xres, yres);
+if (init_buffers(ctx)) {
+av_log(ctx->avctx, AV_LOG_ERROR, "Error resizing buffers.\n");
+return AVERROR(ENOMEM);
+}
+}
+} else {
+if ((left + w > ctx->width) || (top + h > ctx->height)) {
+/* correct unexpected overly large frames: this happens
+ * for instance with The Dig's sq1.san video: it has a few
+ * (all black) 640x480 frames halfway in, while the rest is
+ * 320x200.
+ */
+av_log(ctx->avctx, AV_LOG_WARNING,
+   "resizing too large fobj: %d %d @ %d %d  c %d\n", w, h, 
left, top, codec);
+left = top = 0;
+w = ctx->width;
+h = ctx->height;
 }
 }
 bytestream2_skip(&ctx->gb, 4);
-- 
2.48.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 00/12] avcodec/sanm: various improvements

2025-03-13 Thread Manuel Lauss
This patchset improves especially support for SMUSHv1 (Rebel Assault 1),
adds missing codecs and functions and improves reliability of SMUSHv1/v2.

#1 improves frame size detection.
#3 changes the left/top values to signed, as RA1 makes heavy use of
   negative offsets.
#4 adds workarounds for RA1 oddities.
#5-10 add missing codecs and fix existing ones.
#11-12 implement the store/fetch feature for RA1 codecs:
  the RA1 engine stores the raw frame object data in an aux
  buffer and replays that when necessary.  Is required for
  codecs1-34 since they only work on parts of the buffer,
  and the existing scheme breaks the visuals here.

This patchset makes almost all RA1 videos now playable with
generally correct content, although some hiccups remain.

Manuel Lauss (12):
  avcodec/sanm: better frame size detection for old codecs
  avcodec/sanm: disable left/top for fullscreen codecs
  avcodec/sanm: FOBJ left/top are signed values
  avcodec/sanm: misc fixes
  avcodec/sanm: fix codec3
  avcodec/sanm: codec2 support
  avcodec/sanm: codec23 decoder
  avcodec/sanm: codec21 decoder
  avcodec/sanm: codec4/5/33/34 decoder
  avcodec/sanm: codec37: reimplement comp4
  avcodec/sanm: change GetByteContext member to pointer
  avcodec/sanm: properly implement STOR/FTCH for ANIMv1

 libavcodec/sanm.c | 949 ++
 1 file changed, 717 insertions(+), 232 deletions(-)

-- 
2.48.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/12] avcodec/sanm: codec4/5/33/34 decoder

2025-03-13 Thread Manuel Lauss
This codec works on 4x4 pixel tiles, which can be generated and read
from the datastream.  They're both identical, codec5 misses a tile
index to skip the current tile.
Codecs33/34 are the same as 4/5 but with a different tileset generator.
Used only in Rebel Assault 1.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 229 ++
 1 file changed, 229 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index bf2ec40df4..91c8ba658b 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -293,6 +293,8 @@ typedef struct SANMVideoContext {
 int8_t p8x8glyphs[NGLYPHS][64];
 uint8_t c47itbl[0x1];
 uint8_t c23lut[256];
+uint8_t c4tbl[2][256][16];
+uint16_t c4param;
 } SANMVideoContext;
 
 typedef struct SANMFrameHeader {
@@ -480,6 +482,142 @@ static av_cold int init_buffers(SANMVideoContext *ctx)
 return 0;
 }
 
+static void codec33_gen_tiles(SANMVideoContext *ctx, int8_t param1)
+{
+uint8_t *dst = &(ctx->c4tbl[0][0][0]);
+int i, j, k, l, m, n, o, p;
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+p = (j + k) / 2;
+j = (j + p) / 2;
+m = l / 2;
+n = (i + param1);
+o = (k + param1);
+
+*dst++ = p; *dst++ = p; *dst++ = j; *dst++ = n;
+*dst++ = p; *dst++ = p; *dst++ = j; *dst++ = i;
+*dst++ = m; *dst++ = m; *dst++ = p; *dst++ = j;
+*dst++ = l; *dst++ = l; *dst++ = m; *dst++ = p;
+}
+}
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+n = ((j + l) / 2);
+m = ((l + n) / 2);
+
+*dst++ = j; *dst++ = j; *dst++ = j; *dst++ = j;
+*dst++ = n; *dst++ = n; *dst++ = n; *dst++ = n;
+*dst++ = m; *dst++ = m; *dst++ = m; *dst++ = m;
+*dst++ = l; *dst++ = l; *dst++ = l; *dst++ = l;
+}
+}
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = (j + m) / 2;
+o = m / 2;
+p = j & 0xff;
+
+*dst++ = p; *dst++ = p; *dst++ = n; *dst++ = m;
+*dst++ = p; *dst++ = p; *dst++ = n; *dst++ = m;
+*dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
+*dst++ = m; *dst++ = m; *dst++ = o; *dst++ = l;
+}
+}
+
+for (i = 0; i < 8; i++) {
+for (k = 0; k < 8; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = m / 2;
+
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+*dst++ = j; *dst++ = m; *dst++ = n; *dst++ = l;
+}
+}
+}
+
+static void codec4_gen_tiles(SANMVideoContext *ctx, uint16_t param1)
+{
+uint8_t *dst = &(ctx->c4tbl[0][0][0]);
+int i, j, k, l, m, n, o;
+
+for (i = 1; i < 16; i += 2) {
+for (k = 0; k < 16; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = (j + m) / 2;
+o = (l + m) / 2;
+if (j == m || l == m) {
+*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
+*dst++ = j; *dst++ = l; *dst++ = j; *dst++ = j;
+*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = j;
+*dst++ = l; *dst++ = l; *dst++ = j; *dst++ = l;
+} else {
+*dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
+*dst++ = m; *dst++ = m; *dst++ = n; *dst++ = j;
+*dst++ = o; *dst++ = o; *dst++ = m; *dst++ = n;
+*dst++ = l; *dst++ = l; *dst++ = o; *dst++ = m;
+}
+}
+}
+
+for (i = 0; i < 16; i += 2) {
+for (k = 0; k < 16; k++) {
+j = i + param1;
+l = k + param1;
+m = (j + l) / 2;
+n = (j + m) / 2;
+o = (l + m) / 2;
+if (m == j || m == l) {
+*dst++ = j; *dst++ = j; *dst++ = l; *dst++ = j;
+*dst++ = j; *dst++ = j; *dst++ = j; *dst++ = l;
+*dst++ = l; *dst++ = j; *dst++ = l; *dst++ = l;
+*dst++ = j; *dst++ = l; *dst++ = j; *dst++ = l;
+} else {
+*dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
+*dst++ = j; *dst++ = j; *dst++ = n; *dst++ = m;
+*dst++ = n; *dst++ = n; *dst++ = m; *dst++ = o;
+*dst++ = m; *dst++ = m; *dst++ = o; *dst++ = l;
+}
+}
+}
+}
+
+
+static int codec4_load_tiles(SANMVideoContext *ctx, uint16_t param2, uint8_t 
clr)
+{
+uint8_t c, *dst = (uint8_t *)&(ctx->c4tbl[1][0][0]);
+uint32_t loop = param2 * 8;
+
+i

[FFmpeg-devel] [PATCH 07/12] avcodec/sanm: codec23 decoder

2025-03-13 Thread Manuel Lauss
This codec alternatingly skips and changes existing pixels.
A second 16bit parameter in the FOBJ header indicates how to do
the pixel changes: either by specifying a LUT in the codec datastream
or by adding a constant value to the pixel.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 66 +--
 1 file changed, 64 insertions(+), 2 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index b88756d2c6..67963bb5d3 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -292,6 +292,7 @@ typedef struct SANMVideoContext {
 int8_t p4x4glyphs[NGLYPHS][16];
 int8_t p8x8glyphs[NGLYPHS][64];
 uint8_t c47itbl[0x1];
+uint8_t c23lut[256];
 } SANMVideoContext;
 
 typedef struct SANMFrameHeader {
@@ -557,6 +558,62 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, 
const int out_size)
 return 0;
 }
 
+static int old_codec23(SANMVideoContext *ctx, int top, int left, int width,
+   int height, uint8_t param, uint16_t param2)
+{
+const uint32_t maxpxo = ctx->height * ctx->pitch;
+uint8_t *dst, lut[256], c;
+int i, j, k, pc, sk;
+int32_t pxoff;
+
+if (ctx->subversion < 2) {
+/* Rebel Assault 1: constant offset + 0xd0 */
+for (i = 0; i < 256; i++)
+lut[i] = (i + param + 0xd0) & 0xff;
+} else if (param2 == 256) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 256)
+return AVERROR_INVALIDDATA;
+bytestream2_get_bufferu(&ctx->gb, ctx->c23lut, 256);
+} else if (param2 < 256) {
+for (i = 0; i < 256; i++)
+lut[i] = (i + param2) & 0xff;
+} else {
+memcpy(lut, ctx->c23lut, 256);
+}
+if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+return 0;  /* some c23 frames just set up the LUT */
+
+dst = (uint8_t *)ctx->frm0;
+for (i = 0; i < height; i++) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+return 0;
+pxoff = left + ((top + i) * ctx->pitch);
+k = bytestream2_get_le16u(&ctx->gb);
+sk = 1;
+pc = 0;
+while (k > 0 && pc <= width) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 1)
+return AVERROR_INVALIDDATA;
+j = bytestream2_get_byteu(&ctx->gb);
+if (sk) {
+pxoff += j;
+pc += j;
+} else {
+while (j--) {
+if (pxoff >=0 && pxoff < maxpxo) {
+c = *(dst + pxoff);
+*(dst + pxoff) = lut[c];
+}
+pxoff++;
+pc++;
+}
+}
+sk ^= 1;
+}
+}
+return 0;
+}
+
 static int old_codec1(SANMVideoContext *ctx, int top,
   int left, int width, int height, int opaque)
 {
@@ -1258,11 +1315,15 @@ static int old_codec48(SANMVideoContext *ctx, int 
width, int height)
 
 static int process_frame_obj(SANMVideoContext *ctx)
 {
-uint16_t codec = bytestream2_get_le16u(&ctx->gb);
+uint16_t parm2;
+uint8_t  codec = bytestream2_get_byteu(&ctx->gb);
+uint8_t  param = bytestream2_get_byteu(&ctx->gb);
 int16_t  left  = bytestream2_get_le16u(&ctx->gb);
 int16_t  top   = bytestream2_get_le16u(&ctx->gb);
 uint16_t w = bytestream2_get_le16u(&ctx->gb);
 uint16_t h = bytestream2_get_le16u(&ctx->gb);
+bytestream2_skip(&ctx->gb, 2);
+parm2 = bytestream2_get_le16u(&ctx->gb);
 
 if (w < 1 || h < 1 || w > 800 || h > 600 || left > 800 || top > 600) {
 av_log(ctx->avctx, AV_LOG_WARNING,
@@ -1316,7 +1377,6 @@ static int process_frame_obj(SANMVideoContext *ctx)
 h = ctx->height;
 }
 }
-bytestream2_skip(&ctx->gb, 4);
 
 switch (codec) {
 case 1:
@@ -1324,6 +1384,8 @@ static int process_frame_obj(SANMVideoContext *ctx)
 return old_codec1(ctx, top, left, w, h, codec == 3);
 case 2:
 return old_codec2(ctx, top, left, w, h);
+case 23:
+return old_codec23(ctx, top, left, w, h, param, parm2);
 case 37:
 return old_codec37(ctx, w, h);
 case 47:
-- 
2.48.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/12] avcodec/sanm: codec21 decoder

2025-03-13 Thread Manuel Lauss
similar to codec23, this one alternatingly skips and writes bytes.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 45 +
 1 file changed, 45 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 67963bb5d3..bf2ec40df4 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -614,6 +614,49 @@ static int old_codec23(SANMVideoContext *ctx, int top, int 
left, int width,
 return 0;
 }
 
+static int old_codec21(SANMVideoContext *ctx, int top, int left, int width,
+   int height)
+{
+const uint32_t maxpxo = ctx->height * ctx->pitch;
+uint8_t *dst = (uint8_t *)ctx->frm0, c;
+int i, j, k, pc, sk, pxoff;
+
+dst = (uint8_t *)ctx->frm0;
+for (i = 0; i < height; i++) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+return 0;
+pxoff = left + ((top + i) * ctx->pitch);
+k = bytestream2_get_le16u(&ctx->gb);
+sk = 1;
+pc = 0;
+while (k > 0 && pc <= width) {
+if (bytestream2_get_bytes_left(&ctx->gb) < 2)
+return AVERROR_INVALIDDATA;
+j = bytestream2_get_le16u(&ctx->gb);
+k -= 2;
+if (sk) {
+pxoff += j;
+pc += j;
+} else {
+if (bytestream2_get_bytes_left(&ctx->gb) < (j + 1))
+return AVERROR_INVALIDDATA;
+do {
+c = bytestream2_get_byteu(&ctx->gb);
+if (pxoff >=0 && pxoff < maxpxo) {
+*(dst + pxoff) = c;
+}
+pxoff++;
+pc++;
+j--;
+k--;
+} while (j > -1);
+}
+sk ^= 1;
+}
+}
+return 0;
+}
+
 static int old_codec1(SANMVideoContext *ctx, int top,
   int left, int width, int height, int opaque)
 {
@@ -1384,6 +1427,8 @@ static int process_frame_obj(SANMVideoContext *ctx)
 return old_codec1(ctx, top, left, w, h, codec == 3);
 case 2:
 return old_codec2(ctx, top, left, w, h);
+case 21:
+return old_codec21(ctx, top, left, w, h);
 case 23:
 return old_codec23(ctx, top, left, w, h, param, parm2);
 case 37:
-- 
2.48.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/12] avcodec/sanm: fix codec3

2025-03-13 Thread Manuel Lauss
codec3 is codec1 which writes zero values instead of skipping them.
This fixes a lot of RA1 videos.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index fbb6e7231a..d4a84febc7 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -558,7 +558,7 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t *dst, 
const int out_size)
 }
 
 static int old_codec1(SANMVideoContext *ctx, int top,
-  int left, int width, int height)
+  int left, int width, int height, int opaque)
 {
 int i, j, len, flag, code, val, end, pxoff;
 const int maxpxo = ctx->height * ctx->pitch;
@@ -581,7 +581,7 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 code = (code >> 1) + 1;
 if (flag) {
 val = bytestream2_get_byteu(&ctx->gb);
-if (val) {
+if (val || opaque) {
 for (j = 0; j < code; j++) {
 if (pxoff >= 0 && pxoff < maxpxo)
 *(dst + pxoff) = val;
@@ -595,7 +595,7 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 return AVERROR_INVALIDDATA;
 for (j = 0; j < code; j++) {
 val = bytestream2_get_byteu(&ctx->gb);
-if ((pxoff >= 0) && (pxoff < maxpxo) && val)
+if ((pxoff >= 0) && (pxoff < maxpxo) && (val || opaque))
 *(dst + pxoff) = val;
 pxoff++;
 }
@@ -1303,7 +1303,7 @@ static int process_frame_obj(SANMVideoContext *ctx)
 switch (codec) {
 case 1:
 case 3:
-return old_codec1(ctx, top, left, w, h);
+return old_codec1(ctx, top, left, w, h, codec == 3);
 case 37:
 return old_codec37(ctx, w, h);
 case 47:
-- 
2.48.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/12] avcodec/sanm: FOBJ left/top are signed values

2025-03-13 Thread Manuel Lauss
The left/top parameters of a FOBJ are signed values.  Adjust
codec1 code accordingly to not draw outside the buffer area.
Rebel Assault 1 makes heavy use of this.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 33 ++---
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 63956c01d6..9f656e6ba8 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -558,18 +558,18 @@ static int rle_decode(SANMVideoContext *ctx, uint8_t 
*dst, const int out_size)
 static int old_codec1(SANMVideoContext *ctx, int top,
   int left, int width, int height)
 {
-uint8_t *dst = ((uint8_t *)ctx->frm0) + left + top * ctx->pitch;
-int i, j, len, flag, code, val, pos, end;
+int i, j, len, flag, code, val, end, pxoff;
+const int maxpxo = ctx->height * ctx->pitch;
+uint8_t *dst = (uint8_t *)ctx->frm0;
 
 for (i = 0; i < height; i++) {
-pos = 0;
-
 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
 return AVERROR_INVALIDDATA;
 
 len = bytestream2_get_le16u(&ctx->gb);
 end = bytestream2_tell(&ctx->gb) + len;
 
+pxoff = left + ((top + i) * ctx->pitch);
 while (bytestream2_tell(&ctx->gb) < end) {
 if (bytestream2_get_bytes_left(&ctx->gb) < 2)
 return AVERROR_INVALIDDATA;
@@ -577,25 +577,28 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 code = bytestream2_get_byteu(&ctx->gb);
 flag = code & 1;
 code = (code >> 1) + 1;
-if (pos + code > width)
-return AVERROR_INVALIDDATA;
 if (flag) {
 val = bytestream2_get_byteu(&ctx->gb);
-if (val)
-memset(dst + pos, val, code);
-pos += code;
+if (val) {
+for (j = 0; j < code; j++) {
+if (pxoff >= 0 && pxoff < maxpxo)
+*(dst + pxoff) = val;
+pxoff++;
+}
+} else {
+pxoff += code;
+}
 } else {
 if (bytestream2_get_bytes_left(&ctx->gb) < code)
 return AVERROR_INVALIDDATA;
 for (j = 0; j < code; j++) {
 val = bytestream2_get_byteu(&ctx->gb);
-if (val)
-dst[pos] = val;
-pos++;
+if ((pxoff >= 0) && (pxoff < maxpxo) && val)
+*(dst + pxoff) = val;
+pxoff++;
 }
 }
 }
-dst += ctx->pitch;
 }
 ctx->rotate_code = 0;
 
@@ -1236,8 +1239,8 @@ static int old_codec48(SANMVideoContext *ctx, int width, 
int height)
 static int process_frame_obj(SANMVideoContext *ctx)
 {
 uint16_t codec = bytestream2_get_le16u(&ctx->gb);
-uint16_t left  = bytestream2_get_le16u(&ctx->gb);
-uint16_t top   = bytestream2_get_le16u(&ctx->gb);
+int16_t  left  = bytestream2_get_le16u(&ctx->gb);
+int16_t  top   = bytestream2_get_le16u(&ctx->gb);
 uint16_t w = bytestream2_get_le16u(&ctx->gb);
 uint16_t h = bytestream2_get_le16u(&ctx->gb);
 
-- 
2.48.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/12] avcodec/sanm: misc fixes

2025-03-13 Thread Manuel Lauss
- clear the front buffer with color 0 when processing data.
  Fixes a lot of Rebel Assault 1 videos and Rebel Assault 2 space
  scenes (e.g. 08PLAY.SAN which consists only of codec1/2/21 objects
  which only ever touch parts of the buffer).
- for ANIMv1 (Rebel Assault 1): set palette index 0 to all zeroes.
  This fixes a lot of stray colors in e.g L1HANGAR.ANM, L2INTRO.ANM,
  space scenes.
- Esp in RA1, there are a lot of FRME objects which don't contain
  any video data (prebuffering some audio only). Account for that.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 29 +++--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 9f656e6ba8..fbb6e7231a 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -515,6 +515,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
 ctx->subversion = AV_RL16(avctx->extradata);
 for (i = 0; i < PALETTE_SIZE; i++)
 ctx->pal[i] = 0xFFU << 24 | AV_RL32(avctx->extradata + 2 + i * 4);
+if (ctx->subversion < 2)
+ctx->pal[0] = 0xFFU << 24;
 }
 
 return 0;
@@ -1349,6 +1351,8 @@ static int process_xpal(SANMVideoContext *ctx, int size)
 if (size >= PALETTE_DELTA * 2 + 4 + PALETTE_SIZE * 3) {
 for (i = 0; i < PALETTE_SIZE; i++)
 ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->gb);
+if (ctx->subversion < 2)
+ctx->pal[0] = 0xFFU << 24;
 }
 }
 return 0;
@@ -1762,7 +1766,11 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 bytestream2_init(&ctx->gb, pkt->data, pkt->size);
 
 if (!ctx->version) {
-int to_store = 0;
+int to_store = 0, have_pic = 0;
+
+/* clear the front buffer */
+if (ctx->frm0_size)
+memset(ctx->frm0, 0, ctx->frm0_size);
 
 while (bytestream2_get_bytes_left(&ctx->gb) >= 8) {
 uint32_t sig, size;
@@ -1785,12 +1793,15 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 }
 for (i = 0; i < PALETTE_SIZE; i++)
 ctx->pal[i] = 0xFFU << 24 | 
bytestream2_get_be24u(&ctx->gb);
+if (ctx->subversion < 2)
+ctx->pal[0] = 0xFFU << 24;
 break;
 case MKBETAG('F', 'O', 'B', 'J'):
 if (size < 16)
 return AVERROR_INVALIDDATA;
 if (ret = process_frame_obj(ctx))
 return ret;
+have_pic = 1;
 break;
 case MKBETAG('X', 'P', 'A', 'L'):
 if (ret = process_xpal(ctx, size))
@@ -1801,6 +1812,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 break;
 case MKBETAG('F', 'T', 'C', 'H'):
 memcpy(ctx->frm0, ctx->stored_frame, ctx->buf_size);
+have_pic = 1;
 break;
 default:
 bytestream2_skip(&ctx->gb, size);
@@ -1815,9 +1827,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 }
 if (to_store)
 memcpy(ctx->stored_frame, ctx->frm0, ctx->buf_size);
-if ((ret = copy_output(ctx, NULL)))
-return ret;
-memcpy(ctx->frame->data[1], ctx->pal, 1024);
+
+if (have_pic && ctx->have_dimensions) {
+if ((ret = copy_output(ctx, NULL)))
+return ret;
+memcpy(ctx->frame->data[1], ctx->pal, 1024);
+*got_frame_ptr = 1;
+}
 } else {
 SANMFrameHeader header;
 
@@ -1848,12 +1864,13 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*frame,
 
 if ((ret = copy_output(ctx, &header)))
 return ret;
+
+*got_frame_ptr = 1;
+
 }
 if (ctx->rotate_code)
 rotate_bufs(ctx, ctx->rotate_code);
 
-*got_frame_ptr = 1;
-
 return pkt->size;
 }
 
-- 
2.48.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/1] avformat/avio: add configuration options for IO_BUFFER_SIZE

2025-03-13 Thread 姚靖威
 protocols like local socket and local file.  In our product, I set
avio-buffer-size
value to 1024 in order to reduce memory.The OS we use is based on nuttx, it
can be used in very small resource chips.

[image: image.png]


Zhao Zhili  于2025年3月13日周四 18:26写道:

>
>
> > On Mar 13, 2025, at 17:40, 姚靖威  wrote:
> >
> > The purpose of this patch is to modify the default buffer size of the
> avio
> > module during compilation.
> > On some resource-constrained devices to save memory, the current default
> > value (32K), it can also be set to a smaller value.
>
> Which protocol? And what’s the value used to replace the default 32KB?
>
> >
> > Nicolas George  于2025年3月11日周二 19:55写道:
> >
> >> joney...@gmail.com (HE12025-03-11):
> >>> From: Jingwei Yao 
> >>>
> >>> Signed-off-by: Jingwei Yao 
> >>> ---
> >>> configure | 6 ++
> >>> libavformat/aviobuf.c | 2 +-
> >>> 2 files changed, 7 insertions(+), 1 deletion(-)
> >>
> >> Thanks for the patch. It is missing the explanations about why.
> >>
> >> Regards,
> >>
> >> --
> >>  Nicolas George
> >> ___
> >> ffmpeg-devel mailing list
> >> ffmpeg-devel@ffmpeg.org
> >> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >>
> >> To unsubscribe, visit link above, or email
> >> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
> >>
> > ___
> > ffmpeg-devel 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 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] avcodec/sanm: disable left/top for fullscreen codecs

2025-03-13 Thread Manuel Lauss
The block-based codecs 37/47/48 work on the full frame, and there's no
existing LucasArts game video that uses left/top offsets for these,
as it doesn't make sense. Ignore the left/top parameters for these codecs.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 36 +---
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 0795d664fa..63956c01d6 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -621,8 +621,7 @@ static inline void codec37_mv(uint8_t *dst, const uint8_t 
*src,
 }
 }
 
-static int old_codec37(SANMVideoContext *ctx, int top,
-   int left, int width, int height)
+static int old_codec37(SANMVideoContext *ctx, int width, int height)
 {
 int i, j, k, l, t, run, len, code, skip, mx, my;
 ptrdiff_t stride = ctx->pitch;
@@ -638,8 +637,8 @@ static int old_codec37(SANMVideoContext *ctx, int top,
 flags = bytestream2_get_byte(&ctx->gb);
 bytestream2_skip(&ctx->gb, 3);
 
-if (decoded_size > ctx->height * stride - left - top * stride) {
-decoded_size = ctx->height * stride - left - top * stride;
+if (decoded_size > ctx->height * stride) {
+decoded_size = ctx->height * stride;
 av_log(ctx->avctx, AV_LOG_WARNING, "Decoded size is too large.\n");
 }
 
@@ -649,8 +648,8 @@ static int old_codec37(SANMVideoContext *ctx, int top,
 FFSWAP(uint16_t*, ctx->frm1, ctx->frm2);
 }
 
-dst  = ((uint8_t*)ctx->frm1) + left + top * stride;
-prev = ((uint8_t*)ctx->frm2) + left + top * stride;
+dst  = ((uint8_t*)ctx->frm1);
+prev = ((uint8_t*)ctx->frm2);
 
 if (mvoff > 2) {
 av_log(ctx->avctx, AV_LOG_ERROR, "Invalid motion base value %d.\n", 
mvoff);
@@ -925,15 +924,14 @@ static void codec47_comp1(SANMVideoContext *ctx, uint8_t 
*dst_in, int width,
 }
 }
 
-static int old_codec47(SANMVideoContext *ctx, int top,
-   int left, int width, int height)
+static int old_codec47(SANMVideoContext *ctx, int width, int height)
 {
 uint32_t decoded_size;
 int i, j;
 ptrdiff_t stride = ctx->pitch;
-uint8_t *dst   = (uint8_t *)ctx->frm0 + left + top * stride;
-uint8_t *prev1 = (uint8_t *)ctx->frm1 + left + top * stride;
-uint8_t *prev2 = (uint8_t *)ctx->frm2 + left + top * stride;
+uint8_t *dst   = (uint8_t *)ctx->frm0;
+uint8_t *prev1 = (uint8_t *)ctx->frm1;
+uint8_t *prev2 = (uint8_t *)ctx->frm2;
 uint8_t auxcol[2];
 int tbl_pos = bytestream2_tell(&ctx->gb);
 int seq = bytestream2_get_le16(&ctx->gb);
@@ -947,8 +945,8 @@ static int old_codec47(SANMVideoContext *ctx, int top,
 decoded_size = bytestream2_get_le32(&ctx->gb);
 bytestream2_skip(&ctx->gb, 8);
 
-if (decoded_size > ctx->height * stride - left - top * stride) {
-decoded_size = ctx->height * stride - left - top * stride;
+if (decoded_size > ctx->height * stride) {
+decoded_size = ctx->height * stride;
 av_log(ctx->avctx, AV_LOG_WARNING, "Decoded size is too large.\n");
 }
 
@@ -959,8 +957,8 @@ static int old_codec47(SANMVideoContext *ctx, int top,
 }
 if (!seq) {
 ctx->prev_seq = -1;
-memset(prev1, auxcol[0], (ctx->height - top) * stride);
-memset(prev2, auxcol[1], (ctx->height - top) * stride);
+memset(prev1, auxcol[0], ctx->height * stride);
+memset(prev2, auxcol[1], ctx->height * stride);
 }
 
 switch (compr) {
@@ -1282,7 +1280,8 @@ static int process_frame_obj(SANMVideoContext *ctx)
 }
 }
 } else {
-if ((left + w > ctx->width) || (top + h > ctx->height)) {
+if (((left + w > ctx->width) || (top + h > ctx->height))
+&& codec >= 37) {
 /* correct unexpected overly large frames: this happens
  * for instance with The Dig's sq1.san video: it has a few
  * (all black) 640x480 frames halfway in, while the rest is
@@ -1290,7 +1289,6 @@ static int process_frame_obj(SANMVideoContext *ctx)
  */
 av_log(ctx->avctx, AV_LOG_WARNING,
"resizing too large fobj: %d %d @ %d %d  c %d\n", w, h, 
left, top, codec);
-left = top = 0;
 w = ctx->width;
 h = ctx->height;
 }
@@ -1302,9 +1300,9 @@ static int process_frame_obj(SANMVideoContext *ctx)
 case 3:
 return old_codec1(ctx, top, left, w, h);
 case 37:
-return old_codec37(ctx, top, left, w, h);
+return old_codec37(ctx, w, h);
 case 47:
-return old_codec47(ctx, top, left, w, h);
+return old_codec47(ctx, w, h);
 case 48:
 return old_codec48(ctx, w, h);
 default:
-- 
2.48.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/12] avcodec/sanm: codec37: reimplement comp4

2025-03-13 Thread Manuel Lauss
Compression 4 code 0 means copy from delta buffer without mv,
AND start of a skip run.  This gets rid of the extra case and column
index manipulation and implements this as it is implemented in the
original game exe, i.e. as a special case for after mv copy.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 91c8ba658b..a8a3e04156 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -1106,16 +1106,14 @@ static int old_codec37(SANMVideoContext *ctx, int 
width, int height)
 t = bytestream2_get_byteu(&ctx->gb);
 for (k = 0; k < 4; k++)
 memset(dst + i + k * stride, t, 4);
-   } else if ((compr == 4) && (code == 0)) {
-if (bytestream2_get_bytes_left(&ctx->gb) < 1)
-return AVERROR_INVALIDDATA;
-skip_run = bytestream2_get_byteu(&ctx->gb) + 1;
-i -= 4;
} else {
 mx = c37_mv[(mvoff * 255 + code) * 2];
 my = c37_mv[(mvoff * 255 + code) * 2 + 1];
 codec37_mv(dst + i, prev + i + mx + my * stride,
ctx->height, stride, i + mx, j + my);
+
+if ((compr == 4) && (code == 0))
+skip_run = bytestream2_get_byteu(&ctx->gb);
 }
 }
 dst  += stride * 4;
-- 
2.48.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/12] avcodec/sanm: codec2 support

2025-03-13 Thread Manuel Lauss
this codec consists of 4 byte packets: 2bytes delta-x, 1 byte delta-y
and 1 byte color to put at that spot.
Used in Rebel Assault 1 only.

Signed-off-by: Manuel Lauss 
---
 libavcodec/sanm.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index d4a84febc7..b88756d2c6 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -607,6 +607,24 @@ static int old_codec1(SANMVideoContext *ctx, int top,
 return 0;
 }
 
+static int old_codec2(SANMVideoContext *ctx, int top,
+  int left, int width, int height)
+{
+uint8_t *dst = (uint8_t *)ctx->frm0, col;
+int16_t xpos = left, ypos = top;
+
+while (bytestream2_get_bytes_left(&ctx->gb) > 3) {
+xpos += bytestream2_get_le16u(&ctx->gb);
+ypos += bytestream2_get_byteu(&ctx->gb);
+col = bytestream2_get_byteu(&ctx->gb);
+if (xpos >= 0 && ypos >= 0 &&
+xpos < ctx->width && ypos < ctx->height) {
+*(dst + xpos + ypos * ctx->pitch) = col;
+}
+}
+return 0;
+}
+
 static inline void codec37_mv(uint8_t *dst, const uint8_t *src,
   int height, int stride, int x, int y)
 {
@@ -1304,6 +1322,8 @@ static int process_frame_obj(SANMVideoContext *ctx)
 case 1:
 case 3:
 return old_codec1(ctx, top, left, w, h, codec == 3);
+case 2:
+return old_codec2(ctx, top, left, w, h);
 case 37:
 return old_codec37(ctx, w, h);
 case 47:
-- 
2.48.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".