LiveKit C++ Client SDK v1.1.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
video_frame.h
1/*
2 * Copyright 2025 LiveKit
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an “AS IS” BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cstddef>
20#include <cstdint>
21#include <optional>
22#include <vector>
23
24#include "livekit/visibility.h"
25
26namespace livekit {
27
29enum class VideoBufferType { RGBA = 0, ABGR, ARGB, BGRA, RGB24, I420, I420A, I422, I444, I010, NV12 };
30
33 std::uintptr_t data_ptr;
34 std::uint32_t stride;
35 std::uint32_t size;
36};
37
38namespace proto {
39class OwnedVideoBuffer;
40}
41
48class LIVEKIT_API VideoFrame {
49public:
50 VideoFrame();
51 VideoFrame(int width, int height, VideoBufferType type, std::vector<std::uint8_t> data);
52 virtual ~VideoFrame() = default;
53
54 VideoFrame(const VideoFrame&) = delete;
55 VideoFrame& operator=(const VideoFrame&) = delete;
56 VideoFrame(VideoFrame&&) noexcept = default;
57 VideoFrame& operator=(VideoFrame&&) noexcept = default;
58
61 static VideoFrame create(int width, int height, VideoBufferType type);
62
63 // Basic properties
64 int width() const noexcept { return width_; }
65 int height() const noexcept { return height_; }
66 VideoBufferType type() const noexcept { return type_; }
67
68 std::uint8_t* data() noexcept { return data_.data(); }
69 const std::uint8_t* data() const noexcept { return data_.data(); }
70 std::size_t dataSize() const noexcept { return data_.size(); }
71
76 std::vector<VideoPlaneInfo> planeInfos() const;
77
101 VideoFrame convert(VideoBufferType dst, bool flip_y = false) const;
102
103protected:
104 friend class VideoStream;
105 // Only internal classes (e.g., VideoStream)
106 // should construct frames directly from FFI buffers.
107 static VideoFrame fromOwnedInfo(const proto::OwnedVideoBuffer& owned);
108
109private:
110 int width_;
111 int height_;
112 VideoBufferType type_;
113 std::vector<std::uint8_t> data_;
114};
115
116} // namespace livekit
Public SDK representation of a video frame.
Definition video_frame.h:48
VideoFrame convert(VideoBufferType dst, bool flip_y=false) const
Convert this frame into another pixel format.
static VideoFrame create(int width, int height, VideoBufferType type)
Allocate a new frame with the correct buffer size for the given format.
std::vector< VideoPlaneInfo > planeInfos() const
Compute plane layout for this frame (Y/U/V, UV, etc.), in terms of pointers & sizes relative to this ...
Represents a pull-based stream of decoded video frames coming from a remote (or local) LiveKit track.
Definition video_stream.h:66
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
VideoBufferType
Mirror of WebRTC video buffer type.
Definition video_frame.h:29
Plane layout metadata for a VideoFrame buffer.
Definition video_frame.h:32
std::uintptr_t data_ptr
pointer to plane data (for FFI)
Definition video_frame.h:33
std::uint32_t stride
bytes per row
Definition video_frame.h:34
std::uint32_t size
plane size in bytes
Definition video_frame.h:35