LiveKit C++ Client SDK v1.13.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
capture_source.h
1/*
2 * Copyright 2026 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 "livekit/build.h"
20
21// Internal SDK wrappers are built for both variants; consumers require capture.
22#if !LIVEKIT_CAPTURE_ENABLED && !defined(LIVEKIT_BUILDING_SDK)
23#error "Capture sources require a capture-enabled LiveKit SDK; rebuild with --capture."
24#endif
25
26#include <cstdint>
27#include <future>
28#include <memory>
29#include <optional>
30#include <string>
31
32#include "livekit/result.h"
33#include "livekit/room_event_types.h"
34#include "livekit/video_source.h"
35#include "livekit/visibility.h"
36
37namespace livekit {
38
39class FfiClient;
40
41namespace proto {
42class OwnedCaptureSource;
43} // namespace proto
44
45} // namespace livekit
46
49
53 Pixel = 0,
55 Encoded = 1,
56};
57
61 Bps = 0,
63 Kbps = 1,
64};
65
68 std::uint32_t width = 0;
69 std::uint32_t height = 0;
70};
71
84
91 std::string pipeline;
92
95 std::optional<VideoCodec> codec;
96
100 std::optional<CaptureResolution> resolution;
101
104 std::optional<GstreamerRateControl> rate_control;
105};
106
108enum class Pattern {
110 Gradient = 0,
112 Logo = 1,
113};
114
126
136
138enum class CaptureExit {
140 Stopped = 0,
142 EndOfStream = 1,
143};
144
148 Source = 0,
150 Rtc = 1,
152 Panicked = 2,
153};
154
163
172
194class LIVEKIT_API CaptureSource {
195public:
211 [[nodiscard]] static std::future<Result<std::shared_ptr<CaptureSource>, CaptureError>> create(
212 const GstreamerVideoSourceConfig& config);
213
227 [[nodiscard]] static std::future<Result<std::shared_ptr<CaptureSource>, CaptureError>> create(
229
242 [[nodiscard]] static std::future<Result<std::shared_ptr<CaptureSource>, CaptureError>> create(
244
246
247 CaptureSource(const CaptureSource&) = delete;
248 CaptureSource& operator=(const CaptureSource&) = delete;
249 CaptureSource(CaptureSource&&) = delete;
250 CaptureSource& operator=(CaptureSource&&) = delete;
251
254 CaptureSourceKind kind() const noexcept;
255
258 int width() const noexcept;
259
262 int height() const noexcept;
263
266 std::optional<VideoCodec> codec() const noexcept;
267
271 std::shared_ptr<VideoSource> videoSource() const noexcept;
272
281 TrackPublishOptions publishOptions(TrackPublishOptions options = {}) const;
282
290
302
314 [[nodiscard]] std::future<Result<CaptureResult, CaptureError>> join();
315
316private:
317 friend class livekit::FfiClient;
318
320
325 static std::shared_ptr<CaptureSource> fromOwned(const proto::OwnedCaptureSource& owned);
326
327 struct Impl;
328 std::unique_ptr<Impl> impl_;
329};
330
331} // namespace livekit::capture
Lightweight success-or-error return type for non-exceptional API failures.
Definition result.h:40
Represents a real-time video source that can accept frames from the application and feed them into th...
Definition video_source.h:65
A server-side capture source (livekit-capture) that produces video without per-frame FFI traffic.
Definition capture_source.h:194
static std::future< Result< std::shared_ptr< CaptureSource >, CaptureError > > create(const GstreamerVideoSourceConfig &config)
Create a capture source from a GStreamer pipeline configuration.
Result< void, CaptureError > start()
Start pumping frames into the RTC video source.
Result< void, CaptureError > stop()
Signal a running capture to stop after the frame in flight.
CaptureSourceKind kind() const noexcept
Kind of media this source produces.
std::future< Result< CaptureResult, CaptureError > > join()
Consume the running pump and wait asynchronously for it to exit.
static std::future< Result< std::shared_ptr< CaptureSource >, CaptureError > > create(ClockVideoSourceConfig config)
Create the built-in wall clock capture source.
static std::future< Result< std::shared_ptr< CaptureSource >, CaptureError > > create(PatternVideoSourceConfig config)
Create the built-in test pattern capture source.
Capture sources and their configuration types.
Definition capture_source.h:48
GstreamerBitrateUnit
Bitrate unit expected by a GStreamer encoder property.
Definition capture_source.h:59
CaptureSourceKind
Kind of media a capture source produces.
Definition capture_source.h:51
@ Pixel
Pixel frames, published through the WebRTC encoder.
@ Encoded
Pre-encoded access units, published as passthrough.
Pattern
Test pattern rendered by the built-in pattern source.
Definition capture_source.h:108
@ Gradient
Animated color gradient.
@ Logo
Bouncing LiveKit logo.
CaptureErrorKind
Terminal pump failure category; matches the FFI CaptureErrorKind enum.
Definition capture_source.h:146
@ Panicked
The pump thread panicked.
@ Rtc
The RTC video source rejected a frame.
@ Source
The capture source failed or violated its contract.
CaptureExit
Why a capture ended without error.
Definition capture_source.h:138
@ Stopped
Stopped via CaptureSource::stop (or source destruction).
@ EndOfStream
The producer reached the end of its stream.
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
VideoCodec
Codec used to publish a video track.
Definition video_codec.h:22
Options for publishing a track to the room.
Definition room_event_types.h:343
Structured terminal pump failure reported by the Rust FFI.
Definition capture_source.h:156
CaptureErrorKind kind
Error category.
Definition capture_source.h:161
std::string message
Human-readable error message.
Definition capture_source.h:158
Video resolution in pixels.
Definition capture_source.h:67
Successful terminal statistics of a started capture.
Definition capture_source.h:165
CaptureExit exit
Why the capture ended successfully.
Definition capture_source.h:170
std::uint64_t frames_captured
Number of frames or access units captured.
Definition capture_source.h:167
Wall clock with millisecond precision, rendered on the GPU.
Definition capture_source.h:129
CaptureResolution resolution
Output resolution; both components must be positive.
Definition capture_source.h:131
std::uint32_t framerate_fps
Output frame rate in frames per second; must be non-zero.
Definition capture_source.h:134
Binding from WebRTC rate-control targets to a GStreamer encoder property.
Definition capture_source.h:73
std::string element
Name of the encoder element in the pipeline (e.g. lk_encoder).
Definition capture_source.h:75
GstreamerBitrateUnit unit
Unit the property expects.
Definition capture_source.h:82
std::string property
Bitrate property to set on the element (e.g.
Definition capture_source.h:79
Configuration for encoded ingest from a GStreamer pipeline.
Definition capture_source.h:86
std::optional< VideoCodec > codec
Codec expected from the pipeline; inferred from pipeline caps when omitted.
Definition capture_source.h:95
std::optional< GstreamerRateControl > rate_control
Forwards WebRTC rate-control targets to an encoder element's bitrate property.
Definition capture_source.h:104
std::optional< CaptureResolution > resolution
Encoded frame resolution.
Definition capture_source.h:100
std::string pipeline
GStreamer launch description for the encoded producer pipeline.
Definition capture_source.h:91
Configuration for the built-in test source rendering a Pattern.
Definition capture_source.h:116
std::uint32_t framerate_fps
Output frame rate in frames per second; must be non-zero.
Definition capture_source.h:121
CaptureResolution resolution
Output resolution; both components must be positive.
Definition capture_source.h:118
Pattern pattern
Pattern to render.
Definition capture_source.h:124