From 68b885ee775c96bd2855aff012ebaeaa71105688 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Fri, 23 May 2025 18:35:03 -0500 Subject: [PATCH] Adding 32 bit alignment for simd into our AV_ALLOCATE_IMAGE macro, and some code cleanup --- src/FFmpegReader.cpp | 7 +++---- src/FFmpegUtilities.h | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index b5c70fe6..59453dd7 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -1307,10 +1307,9 @@ bool FFmpegReader::GetAVFrame() { frameFinished = 1; packet_status.video_decoded++; - // align 32 for simd - if (av_image_alloc(pFrame->data, pFrame->linesize, info.width, - info.height, (AVPixelFormat)(pStream->codecpar->format), 32) <= 0) { - throw OutOfMemory("Failed to allocate image buffer", path); + // Allocate image (align 32 for simd) + if (AV_ALLOCATE_IMAGE(pFrame, (AVPixelFormat)(pStream->codecpar->format), info.width, info.height) <= 0) { + throw OutOfMemory("Failed to allocate image buffer", path); } av_image_copy(pFrame->data, pFrame->linesize, (const uint8_t**)next_frame->data, next_frame->linesize, (AVPixelFormat)(pStream->codecpar->format), info.width, info.height); diff --git a/src/FFmpegUtilities.h b/src/FFmpegUtilities.h index 143b3427..4a6a4170 100644 --- a/src/FFmpegUtilities.h +++ b/src/FFmpegUtilities.h @@ -160,7 +160,7 @@ inline static bool ffmpeg_has_alpha(PixelFormat pix_fmt) { #define MY_INPUT_BUFFER_PADDING_SIZE AV_INPUT_BUFFER_PADDING_SIZE #define AV_ALLOCATE_FRAME() av_frame_alloc() #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) \ - av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) + av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 32) #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet) @@ -198,7 +198,7 @@ inline static bool ffmpeg_has_alpha(PixelFormat pix_fmt) { #define MY_INPUT_BUFFER_PADDING_SIZE FF_INPUT_BUFFER_PADDING_SIZE #define AV_ALLOCATE_FRAME() av_frame_alloc() #define AV_ALLOCATE_IMAGE(av_frame, pix_fmt, width, height) \ - av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 1) + av_image_alloc(av_frame->data, av_frame->linesize, width, height, pix_fmt, 32) #define AV_RESET_FRAME(av_frame) av_frame_unref(av_frame) #define AV_FREE_FRAME(av_frame) av_frame_free(av_frame) #define AV_FREE_PACKET(av_packet) av_packet_unref(av_packet)