From 63b8fe3ae87a620c328d48387313eb9fdfbdd98a Mon Sep 17 00:00:00 2001 From: PulkoMandy Date: Thu, 23 Jul 2026 20:04:52 +0200 Subject: [PATCH] ffmpeg media add-on: add padding around video buffers The video buffer used for colorspace conversion was not aligned enough (it could need as much as 64 bytes alignment) and did not include enough padding (the functions work on 64 bytes blocks at once in some cases). This code could be made simpler by using sws_scale_frame instead of sws_scale, but that's more refactoring than I'm willing to do right now. Thanks to k32n13 for providing a script to generate test videos! Fixes #20200. Change-Id: I8b51fd777201cdb899ce1834152066378b258521 Reviewed-on: https://review.haiku-os.org/c/haiku/+/11343 Reviewed-by: waddlesplash (cherry picked from commit a0bfeae472eee24a9855e9685a507f6f85d91673) Reviewed-on: https://review.haiku-os.org/c/haiku/+/11344 --- src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp index b6f73a6e31..dba9cda35f 100644 --- a/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp +++ b/src/add-ons/media/plugins/ffmpeg/AVCodecDecoder.cpp @@ -1671,9 +1671,9 @@ AVCodecDecoder::_DeinterlaceAndColorConvertVideoFrame() fDecodedDataSizeInBytes = fHeader.size_used; if (fDecodedData == NULL) { - const size_t kOptimalAlignmentForColorConversion = 32; + const size_t kOptimalAlignmentForColorConversion = 64; posix_memalign(reinterpret_cast(&fDecodedData), - kOptimalAlignmentForColorConversion, fDecodedDataSizeInBytes); + kOptimalAlignmentForColorConversion, fDecodedDataSizeInBytes + 63); } if (fDecodedData == NULL) return B_NO_MEMORY;