LibMedia: Port to Windows

This commit is contained in:
stasoid 2024-12-18 10:33:53 +05:00 committed by Andrew Kaster
commit 49c5c0bb8a
Notes: github-actions[bot] 2025-02-11 11:08:27 +00:00
2 changed files with 15 additions and 9 deletions

View file

@ -1,6 +1,6 @@
include(audio) include(audio)
if (NOT ANDROID AND NOT WIN32) if (NOT ANDROID)
include(ffmpeg) include(ffmpeg)
endif() endif()
@ -20,7 +20,7 @@ set(SOURCES
serenity_lib(LibMedia media) serenity_lib(LibMedia media)
target_link_libraries(LibMedia PRIVATE LibCore LibCrypto LibRIFF LibIPC LibGfx LibThreading LibUnicode) target_link_libraries(LibMedia PRIVATE LibCore LibCrypto LibRIFF LibIPC LibGfx LibThreading LibUnicode)
if (NOT ANDROID AND NOT WIN32) if (NOT ANDROID)
target_sources(LibMedia PRIVATE target_sources(LibMedia PRIVATE
Audio/FFmpegLoader.cpp Audio/FFmpegLoader.cpp
FFmpeg/FFmpegVideoDecoder.cpp FFmpeg/FFmpegVideoDecoder.cpp

View file

@ -10,6 +10,13 @@
#include "VideoFrame.h" #include "VideoFrame.h"
#ifdef AK_OS_WINDOWS
# define aligned_alloc(alignment, size) _aligned_malloc(size, alignment)
# define aligned_free _aligned_free
#else
# define aligned_free free
#endif
namespace Media { namespace Media {
ErrorOr<NonnullOwnPtr<SubsampledYUVFrame>> SubsampledYUVFrame::try_create( ErrorOr<NonnullOwnPtr<SubsampledYUVFrame>> SubsampledYUVFrame::try_create(
@ -23,10 +30,9 @@ ErrorOr<NonnullOwnPtr<SubsampledYUVFrame>> SubsampledYUVFrame::try_create(
size_t alignment_size = max(bit_depth > 8 ? sizeof(u16) : sizeof(u8), sizeof(void*)); size_t alignment_size = max(bit_depth > 8 ? sizeof(u16) : sizeof(u8), sizeof(void*));
auto alloc_buffer = [&](size_t size) -> ErrorOr<u8*> { auto alloc_buffer = [&](size_t size) -> ErrorOr<u8*> {
void* buffer = nullptr; void* buffer = aligned_alloc(alignment_size, round_up_to_power_of_two(size, alignment_size));
auto result = posix_memalign(&buffer, alignment_size, size); if (!buffer)
if (result != 0) return Error::from_errno(ENOMEM);
return Error::from_errno(result);
return reinterpret_cast<u8*>(buffer); return reinterpret_cast<u8*>(buffer);
}; };
@ -64,9 +70,9 @@ ErrorOr<NonnullOwnPtr<SubsampledYUVFrame>> SubsampledYUVFrame::try_create_from_d
SubsampledYUVFrame::~SubsampledYUVFrame() SubsampledYUVFrame::~SubsampledYUVFrame()
{ {
free(m_y_buffer); aligned_free(m_y_buffer);
free(m_u_buffer); aligned_free(m_u_buffer);
free(m_v_buffer); aligned_free(m_v_buffer);
} }
template<u32 subsampling_horizontal, typename T> template<u32 subsampling_horizontal, typename T>