LiveKit C++ Client SDK v1.1.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
video_stream.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 <condition_variable>
20#include <cstdint>
21#include <deque>
22#include <functional>
23#include <memory>
24#include <mutex>
25#include <optional>
26
27#include "livekit/ffi_handle.h"
28#include "livekit/participant.h"
29#include "livekit/track.h"
30#include "livekit/video_frame.h"
31#include "livekit/video_source.h"
32#include "livekit/visibility.h"
33
34namespace livekit {
35
38 VideoFrame frame;
43 std::int64_t timestamp_us;
44 VideoRotation rotation;
45 std::optional<VideoFrameMetadata> metadata;
46};
47
48namespace proto {
49class FfiEvent;
50}
51
66class LIVEKIT_API VideoStream {
67public:
69 struct Options {
75 std::size_t capacity{0};
76
79 VideoBufferType format{VideoBufferType::RGBA};
80 };
81
83 static std::shared_ptr<VideoStream> fromTrack(const std::shared_ptr<Track>& track, const Options& options);
84
86 static std::shared_ptr<VideoStream> fromParticipant(Participant& participant, TrackSource track_source,
87 const Options& options);
88
89 virtual ~VideoStream();
90
91 VideoStream(const VideoStream&) = delete;
92 VideoStream& operator=(const VideoStream&) = delete;
93 VideoStream(VideoStream&&) noexcept;
94 VideoStream& operator=(VideoStream&&) noexcept;
95
102 bool read(VideoFrameEvent& out);
103
109 void close();
110
111private:
112 VideoStream() = default;
113
114 // Internal init helpers, used by the factories
115 void initFromTrack(const std::shared_ptr<Track>& track, const Options& options);
116 void initFromParticipant(Participant& participant, TrackSource source, const Options& options);
117
118 // FFI event handler (registered with FfiClient)
119 void onFfiEvent(const proto::FfiEvent& event);
120
121 // Queue helpers
122 void pushFrame(VideoFrameEvent&& ev);
123 void pushEos();
124
125 mutable std::mutex mutex_;
126 std::condition_variable cv_;
127 std::deque<VideoFrameEvent> queue_;
128 std::size_t capacity_{0};
129 bool eof_{false};
130 bool closed_{false};
131
132 // Underlying FFI handle for the video stream
133 FfiHandle stream_handle_;
134
135 // Listener id registered on FfiClient
136 std::int32_t listener_id_{0};
137};
138
139} // namespace livekit
Base class for local and remote room participants.
Definition participant.h:34
Base class for local and remote media tracks.
Definition track.h:77
Public SDK representation of a video frame.
Definition video_frame.h:48
Represents a pull-based stream of decoded video frames coming from a remote (or local) LiveKit track.
Definition video_stream.h:66
static std::shared_ptr< VideoStream > fromTrack(const std::shared_ptr< Track > &track, const Options &options)
Factory: create a VideoStream bound to a specific Track.
static std::shared_ptr< VideoStream > fromParticipant(Participant &participant, TrackSource track_source, const Options &options)
Factory: create a VideoStream from a Participant + TrackSource.
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
VideoRotation
Rotation of a video frame.
Definition video_source.h:32
VideoBufferType
Mirror of WebRTC video buffer type.
Definition video_frame.h:29
TrackSource
Source category for a published track.
Definition track.h:43
A single video frame event delivered by VideoStream::read().
Definition video_stream.h:37
std::int64_t timestamp_us
WebRTC frame timestamp in microseconds.
Definition video_stream.h:43
Options for creating a decoded video frame stream.
Definition video_stream.h:69