LiveKit C++ SDK
Real-time audio/video SDK for C++
Loading...
Searching...
No Matches
data_track_stream.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/data_track_frame.h"
20#include "livekit/ffi_handle.h"
21
22#include <condition_variable>
23#include <cstdint>
24#include <deque>
25#include <memory>
26#include <mutex>
27#include <optional>
28
29namespace livekit {
30
31namespace proto {
32class FfiEvent;
33}
34
56public:
57 struct Options {
59 std::optional<std::uint32_t> buffer_size{std::nullopt};
60 };
61
62 virtual ~DataTrackStream();
63
64 DataTrackStream(const DataTrackStream &) = delete;
65 DataTrackStream &operator=(const DataTrackStream &) = delete;
66 // The FFI listener captures `this`, so moving the object would leave the
67 // registered callback pointing at the old address.
68 DataTrackStream(DataTrackStream &&) noexcept = delete;
69 // Instances are created and returned as std::shared_ptr, so value-move
70 // support is not required by the current API.
71 DataTrackStream &operator=(DataTrackStream &&) noexcept = delete;
72
80 bool read(DataTrackFrame &out);
81
88 void close();
89
90private:
91 friend class RemoteDataTrack;
92
93 DataTrackStream() = default;
95 void init(FfiHandle subscription_handle);
96
98 void onFfiEvent(const proto::FfiEvent &event);
99
101 void pushFrame(DataTrackFrame &&frame);
102
104 void pushEos();
105
107 mutable std::mutex mutex_;
108
110 std::condition_variable cv_;
111
115 std::optional<DataTrackFrame> frame_;
116
118 bool eof_{false};
119
121 bool closed_{false};
122
124 FfiHandle subscription_handle_;
125
127 std::int64_t listener_id_{0};
128};
129
130} // namespace livekit
Definition data_track_stream.h:55
bool read(DataTrackFrame &out)
RAII wrapper for an FFI handle (uintptr_t) coming from Rust.
Definition ffi_handle.h:29
Definition remote_data_track.h:53
Definition data_track_frame.h:36
Definition data_track_stream.h:57
std::optional< std::uint32_t > buffer_size
Maximum frames buffered on the Rust side. Rust defaults to 16.
Definition data_track_stream.h:59