LiveKit C++ SDK
Real-time audio/video 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
24namespace livekit {
25
26// Mirror of WebRTC video buffer type
27enum class VideoBufferType {
28 RGBA = 0,
29 ABGR,
30 ARGB,
31 BGRA,
32 RGB24,
33 I420,
34 I420A,
35 I422,
36 I444,
37 I010,
38 NV12
39};
40
42 std::uintptr_t data_ptr; // pointer to plane data (for FFI)
43 std::uint32_t stride; // bytes per row
44 std::uint32_t size; // plane size in bytes
45};
46
47namespace proto {
48class OwnedVideoBuffer;
49}
50
60public:
61 VideoFrame();
62 VideoFrame(int width, int height, VideoBufferType type,
63 std::vector<std::uint8_t> data);
64 virtual ~VideoFrame() = default;
65
66 VideoFrame(const VideoFrame &) = delete;
67 VideoFrame &operator=(const VideoFrame &) = delete;
68 VideoFrame(VideoFrame &&) noexcept = default;
69 VideoFrame &operator=(VideoFrame &&) noexcept = default;
70
75 static VideoFrame create(int width, int height, VideoBufferType type);
76
77 // Basic properties
78 int width() const noexcept { return width_; }
79 int height() const noexcept { return height_; }
80 VideoBufferType type() const noexcept { return type_; }
81
82 std::uint8_t *data() noexcept { return data_.data(); }
83 const std::uint8_t *data() const noexcept { return data_.data(); }
84 std::size_t dataSize() const noexcept { return data_.size(); }
85
92 std::vector<VideoPlaneInfo> planeInfos() const;
93
119 VideoFrame convert(VideoBufferType dst, bool flip_y = false) const;
120
121protected:
122 friend class VideoStream;
123 // Only internal classes (e.g., VideoStream)
124 // should construct frames directly from FFI buffers.
125 static VideoFrame fromOwnedInfo(const proto::OwnedVideoBuffer &owned);
126
127private:
128 int width_;
129 int height_;
130 VideoBufferType type_;
131 std::vector<std::uint8_t> data_;
132};
133
134} // namespace livekit
Definition video_frame.h:59
VideoFrame convert(VideoBufferType dst, bool flip_y=false) const
static VideoFrame create(int width, int height, VideoBufferType type)
std::vector< VideoPlaneInfo > planeInfos() const
Definition video_stream.h:60
Definition video_frame.h:41