[FFmpeg-devel] [PATCH v3] avcodec/h264_mb: Fix tmp buffer overlap in mc_part_weighted

Michael Niedermayer michael at niedermayer.cc
Sun Dec 22 23:41:31 EET 2024


On Fri, Dec 20, 2024 at 01:26:37PM +0800, Bin Peng wrote:
> When decoding a bitstream with weighted-bipred enabled,
> the results on ARM and x86 platforms may differ.
> 
> The reason for the inconsistency is that the value of
> STRIDE_ALIGN differs between platforms. And STRIDE_ALIGN
> is set to the buffer stride of temporary buffers for U
> and V components in mc_part_weighted.
> 
> If the buffer stride is 32 or 64 (as on x86 platforms),
> the U and V pixels can be interleaved row by row without
> overlapping, resulting in correct output.
> However, on ARM platforms where the stride is 16,
> the V component will overwrite part of the U component's pixels,
> leading to incorrect predicted pixels.
> 
> Fixes: ticket 11357
> 
> Signed-off-by: Bin Peng <pengbin at visionular.com>
> ---
>  libavcodec/h264_mb.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c
> index 4e94136313..b480cd312b 100644
> --- a/libavcodec/h264_mb.c
> +++ b/libavcodec/h264_mb.c
> @@ -407,8 +407,8 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon
>          /* don't optimize for luma-only case, since B-frames usually
>           * use implicit weights => chroma too. */
>          uint8_t *tmp_cb = sl->bipred_scratchpad;
> -        uint8_t *tmp_cr = sl->bipred_scratchpad + (16 << pixel_shift);
> -        uint8_t *tmp_y  = sl->bipred_scratchpad + 16 * sl->mb_uvlinesize;
> +        uint8_t *tmp_cr = sl->bipred_scratchpad + (16 * sl->mb_uvlinesize);
> +        uint8_t *tmp_y  = sl->bipred_scratchpad + (32 * sl->mb_uvlinesize);

larger seperation wil decrease cache utilization and worsen speed.
cant we make sure stride is at least 32 without forcing alignment by 32 ?

thx

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

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20241222/51c83524/attachment.sig>


More information about the ffmpeg-devel mailing list