Skip to content

Commit

Permalink
LibMedia: Port to Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stasoid authored and ADKaster committed Feb 11, 2025
1 parent f143a9b commit 49c5c0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Libraries/LibMedia/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include(audio)

if (NOT ANDROID AND NOT WIN32)
if (NOT ANDROID)
include(ffmpeg)
endif()

Expand All @@ -20,7 +20,7 @@ set(SOURCES
serenity_lib(LibMedia media)
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
Audio/FFmpegLoader.cpp
FFmpeg/FFmpegVideoDecoder.cpp
Expand Down
20 changes: 13 additions & 7 deletions Libraries/LibMedia/VideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

#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 {

ErrorOr<NonnullOwnPtr<SubsampledYUVFrame>> SubsampledYUVFrame::try_create(
Expand All @@ -23,10 +30,9 @@ ErrorOr<NonnullOwnPtr<SubsampledYUVFrame>> SubsampledYUVFrame::try_create(
size_t alignment_size = max(bit_depth > 8 ? sizeof(u16) : sizeof(u8), sizeof(void*));

auto alloc_buffer = [&](size_t size) -> ErrorOr<u8*> {
void* buffer = nullptr;
auto result = posix_memalign(&buffer, alignment_size, size);
if (result != 0)
return Error::from_errno(result);
void* buffer = aligned_alloc(alignment_size, round_up_to_power_of_two(size, alignment_size));
if (!buffer)
return Error::from_errno(ENOMEM);
return reinterpret_cast<u8*>(buffer);
};

Expand Down Expand Up @@ -64,9 +70,9 @@ ErrorOr<NonnullOwnPtr<SubsampledYUVFrame>> SubsampledYUVFrame::try_create_from_d

SubsampledYUVFrame::~SubsampledYUVFrame()
{
free(m_y_buffer);
free(m_u_buffer);
free(m_v_buffer);
aligned_free(m_y_buffer);
aligned_free(m_u_buffer);
aligned_free(m_v_buffer);
}

template<u32 subsampling_horizontal, typename T>
Expand Down

0 comments on commit 49c5c0b

Please sign in to comment.