LiveKit C++ Client SDK v1.13.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
video_source.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 <cstdint>
20#include <optional>
21#include <vector>
22
23#include "livekit/ffi_handle.h"
24#include "livekit/visibility.h"
25
26namespace livekit {
27
28class VideoFrame;
29class EncodedVideoSource;
30struct VideoSourceAccess;
31
35enum class VideoRotation {
36 VIDEO_ROTATION_0 = 0,
37 VIDEO_ROTATION_90 = 90,
38 VIDEO_ROTATION_180 = 180,
39 VIDEO_ROTATION_270 = 270,
40};
41
48 std::optional<std::uint64_t> user_timestamp_us;
50 std::optional<std::uint32_t> frame_id;
52 std::optional<std::vector<std::uint8_t>> user_data;
53};
54
57 std::int64_t timestamp_us = 0;
58 VideoRotation rotation = VideoRotation::VIDEO_ROTATION_0;
60 std::optional<VideoFrameMetadata> metadata;
61};
62
65class LIVEKIT_API VideoSource {
66public:
74 VideoSource(int width, int height);
75 virtual ~VideoSource() = default;
76
77 VideoSource(const VideoSource&) = delete;
78 VideoSource& operator=(const VideoSource&) = delete;
79 VideoSource(VideoSource&&) noexcept = default;
80 VideoSource& operator=(VideoSource&&) noexcept = default;
81
83 int width() const noexcept { return width_; }
84 int height() const noexcept { return height_; }
85
87 std::uint64_t ffiHandleId() const noexcept { return handle_.get(); }
88
93 void captureFrame(const VideoFrame& frame, const VideoCaptureOptions& options);
94
96 void captureFrame(const VideoFrame& frame, std::int64_t timestamp_us = 0,
97 VideoRotation rotation = VideoRotation::VIDEO_ROTATION_0);
98
99private:
100 friend class EncodedVideoSource;
101 friend struct VideoSourceAccess;
102
103 enum class SourceType { Native, Encoded };
104 VideoSource(int width, int height, SourceType source_type);
105
110 VideoSource(FfiHandle&& handle, int width, int height) noexcept
111 : handle_(std::move(handle)), width_(width), height_(height) {}
112
113 FfiHandle handle_; // owned FFI handle
114 int width_{0};
115 int height_{0};
116};
117
118} // namespace livekit
Video source for publishing pre-encoded access units without re-encoding.
Definition encoded_video_source.h:34
RAII wrapper for an FFI handle (uintptr_t) coming from Rust.
Definition ffi_handle.h:29
Public SDK representation of a video frame.
Definition video_frame.h:48
Represents a real-time video source that can accept frames from the application and feed them into th...
Definition video_source.h:65
void captureFrame(const VideoFrame &frame, const VideoCaptureOptions &options)
Push a VideoFrame into the FFI video source.
std::uint64_t ffiHandleId() const noexcept
Underlying FFI handle ID (0 if invalid).
Definition video_source.h:87
VideoSource(int width, int height)
Create a new native video source with a fixed resolution.
void captureFrame(const VideoFrame &frame, std::int64_t timestamp_us=0, VideoRotation rotation=VideoRotation::VIDEO_ROTATION_0)
Backward-compatible convenience overload for timestamp + rotation only.
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
VideoRotation
Rotation of a video frame.
Definition video_source.h:35
Capture options for a single outbound video frame.
Definition video_source.h:56
std::optional< VideoFrameMetadata > metadata
Optional per-frame metadata (timestamps, frame IDs, user data).
Definition video_source.h:60
Optional packet-trailer metadata carried alongside a video frame.
Definition video_source.h:46
std::optional< std::uint32_t > frame_id
Monotonically increasing frame identifier.
Definition video_source.h:50
std::optional< std::uint64_t > user_timestamp_us
User-supplied capture time in microseconds.
Definition video_source.h:48
std::optional< std::vector< std::uint8_t > > user_data
Free-form data to attach to the frame.
Definition video_source.h:52