[FFmpeg-devel] [PATCH v2 3/2] avcodec/sanm: codec37 buffers are private

Manuel Lauss manuel.lauss at gmail.com
Mon Jan 13 23:00:24 EET 2025


codec37 operates on 2 buffers, which must be considered private to
the codec and must therefore not be changed by subsequent FOBJs.

Let codec37 therefore operate on frm1/2 instead of frm0/2, but copy
the decoded image to frm0 where other codecs operate on.

Fixes artifacts encountered in Full Throttle "dazed.san" and also
in a lot of Rebel Assault II gameplay videos: these videos consist of
frames with an initial codec37 FOBJ image to set the stage, and
optional codec1-23 FOBJs overlaid on top of that image.

Signed-off-by: Manuel Lauss <manuel.lauss at gmail.com>
---
v2: use FFSWAP() to swap the 2 buffers instead of open-coding that.

Applies on top of my previous patch "avcodec/sanm: simplify codec37 subcodec 3/4 path"

 libavcodec/sanm.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libavcodec/sanm.c b/libavcodec/sanm.c
index 51b8a2f54c..c30095ed32 100644
--- a/libavcodec/sanm.c
+++ b/libavcodec/sanm.c
@@ -645,10 +645,11 @@ static int old_codec37(SANMVideoContext *ctx, int top,
 
     ctx->rotate_code = 0;
 
-    if (((seq & 1) || !(flags & 1)) && (compr && compr != 2))
-        rotate_bufs(ctx, 1);
+    if (((seq & 1) || !(flags & 1)) && (compr && compr != 2)) {
+        FFSWAP(uint16_t*, ctx->frm1, ctx->frm2);
+    }
 
-    dst  = ((uint8_t*)ctx->frm0) + left + top * stride;
+    dst  = ((uint8_t*)ctx->frm1) + left + top * stride;
     prev = ((uint8_t*)ctx->frm2) + left + top * stride;
 
     if (mvoff > 2) {
@@ -662,7 +663,6 @@ static int old_codec37(SANMVideoContext *ctx, int top,
             bytestream2_get_buffer(&ctx->gb, dst, width);
             dst += stride;
         }
-        memset(ctx->frm1, 0, ctx->height * stride);
         memset(ctx->frm2, 0, ctx->height * stride);
         break;
     case 1:
@@ -729,7 +729,6 @@ static int old_codec37(SANMVideoContext *ctx, int top,
     case 2:
         if (rle_decode(ctx, dst, decoded_size))
             return AVERROR_INVALIDDATA;
-        memset(ctx->frm1, 0, ctx->frm1_size);
         memset(ctx->frm2, 0, ctx->frm2_size);
         break;
     case 3:
@@ -783,6 +782,7 @@ static int old_codec37(SANMVideoContext *ctx, int top,
         return AVERROR_PATCHWELCOME;
     }
 
+    memcpy(ctx->frm0, ctx->frm1, ctx->buf_size);
     return 0;
 }
 
-- 
2.47.1



More information about the ffmpeg-devel mailing list