ladybird/Libraries/LibMedia/VideoFrame.h
Aliaksandr Kalenik b5bace2391 LibGfx+LibMedia: Add IPC serialization for VideoFrame
Compositor video frame transport should not flatten frames into a
shareable bitmap before crossing an IPC boundary. That conversion loses
the native YUV representation and makes Web-side transport code own the
frame wire format.

Teach VideoFrame to encode its YUV planes into a shared anonymous buffer
with the color space, timing, subsampling, bit depth, and CICP metadata
needed to rebuild the frame on decode. Add YUVData helpers for checked
plane sizing and construction from validated plane bytes so malformed
buffers are rejected before a frame is created.

This is preparatory work required to add IPC between the main and
compositor threads.
2026-05-21 11:45:06 +01:00

67 lines
1.7 KiB
C++

/*
* Copyright (c) 2022-2026, Gregory Bertilson <gregory@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/Time.h>
#include <LibGfx/ColorSpace.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Size.h>
#include <LibIPC/Forward.h>
#include <LibMedia/Export.h>
namespace Media {
class MEDIA_API VideoFrame final : public AtomicRefCounted<VideoFrame> {
public:
VideoFrame(
AK::Duration timestamp,
AK::Duration duration,
Gfx::Size<u32> size,
u8 bit_depth,
Gfx::ColorSpace color_space,
NonnullOwnPtr<Gfx::YUVData> yuv_data);
~VideoFrame();
AK::Duration timestamp() const { return m_timestamp; }
AK::Duration duration() const { return m_duration; }
Gfx::Size<u32> size() const { return m_size; }
u32 width() const { return size().width(); }
u32 height() const { return size().height(); }
u8 bit_depth() const { return m_bit_depth; }
Gfx::ColorSpace const& color_space() const { return m_color_space; }
Gfx::YUVData const& yuv_data() const { return *m_yuv_data; }
private:
AK::Duration m_timestamp;
AK::Duration m_duration;
Gfx::Size<u32> m_size;
u8 m_bit_depth;
Gfx::ColorSpace m_color_space;
NonnullOwnPtr<Gfx::YUVData> m_yuv_data;
};
}
namespace IPC {
template<>
MEDIA_API ErrorOr<void> encode(Encoder&, Media::VideoFrame const&);
template<>
MEDIA_API ErrorOr<void> encode(Encoder&, NonnullRefPtr<Media::VideoFrame const> const&);
template<>
MEDIA_API ErrorOr<NonnullRefPtr<Media::VideoFrame const>> decode(Decoder&);
}