PR #21231 opened by cenzhanquan1
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21231
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21231.patch

Problem:
Compilation fails when building with Opus library due to type mismatch in
OPUS_GET_LOOKAHEAD macro call. The error is:
"invalid operands to binary - (have 'int *' and 'opus_int32 *')"

Root cause:
- AVCodecContext.initial_padding is of type 'int', so &avctx->initial_padding 
is 'int*';
- Opus's OPUS_GET_LOOKAHEAD macro expands to __opus_check_int_ptr, which 
requires
  a 'opus_int32*' pointer for pointer subtraction;
- Mismatched pointer types trigger compilation error in the macro's pointer 
arithmetic.

Solution:
Use an intermediate 'opus_int32' variable to adapt the type:
1. Declare opus_int32 lookahead and initialize with avctx->initial_padding;
2. Pass &lookahead to OPUS_GET_LOOKAHEAD (matches required 'opus_int32*' type);
3. Sync the result back to avctx->initial_padding to preserve original logic.

This fix maintains full functionality while resolving the type mismatch, with no
performance impact or behavior changes.

Signed-off-by: cenzhanquan1 <[email protected]>


>From daca8ca736f3b1266ebc23cda88a75a1ddd217ab Mon Sep 17 00:00:00 2001
From: cenzhanquan1 <[email protected]>
Date: Thu, 18 Dec 2025 14:38:48 +0800
Subject: [PATCH] libavcodec/libopusenc: fix type mismatch in
 OPUS_GET_LOOKAHEAD call

Problem:
Compilation fails when building with Opus library due to type mismatch in
OPUS_GET_LOOKAHEAD macro call. The error is:
"invalid operands to binary - (have 'int *' and 'opus_int32 *')"

Root cause:
- AVCodecContext.initial_padding is of type 'int', so &avctx->initial_padding 
is 'int*';
- Opus's OPUS_GET_LOOKAHEAD macro expands to __opus_check_int_ptr, which 
requires
  a 'opus_int32*' pointer for pointer subtraction;
- Mismatched pointer types trigger compilation error in the macro's pointer 
arithmetic.

Solution:
Use an intermediate 'opus_int32' variable to adapt the type:
1. Declare opus_int32 lookahead and initialize with avctx->initial_padding;
2. Pass &lookahead to OPUS_GET_LOOKAHEAD (matches required 'opus_int32*' type);
3. Sync the result back to avctx->initial_padding to preserve original logic.

This fix maintains full functionality while resolving the type mismatch, with no
performance impact or behavior changes.

Signed-off-by: cenzhanquan1 <[email protected]>
---
 libavcodec/libopusenc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c
index 131886c8ea..543d4eba24 100644
--- a/libavcodec/libopusenc.c
+++ b/libavcodec/libopusenc.c
@@ -419,7 +419,7 @@ static av_cold int libopus_encode_init(AVCodecContext 
*avctx)
         goto fail;
     }
 
-    ret = opus_multistream_encoder_ctl(enc, 
OPUS_GET_LOOKAHEAD(&avctx->initial_padding));
+    ret = opus_multistream_encoder_ctl(enc, 
OPUS_GET_LOOKAHEAD((opus_int32*)&avctx->initial_padding));
     if (ret != OPUS_OK)
         av_log(avctx, AV_LOG_WARNING,
                "Unable to get number of lookahead samples: %s\n",
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to