LiveKit C++ SDK
Real-time audio/video SDK for C++
Loading...
Searching...
No Matches
track.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#include "livekit/ffi_handle.h"
19#include "livekit/stats.h"
20#include <cstdint>
21#include <future>
22#include <memory>
23#include <optional>
24#include <string>
25#include <unordered_map>
26#include <vector>
27
28#include <iostream>
29
30namespace livekit {
31
32enum class TrackKind {
33 KIND_UNKNOWN = 0,
34 KIND_AUDIO = 1,
35 KIND_VIDEO = 2,
36};
37
38enum class TrackSource {
39 SOURCE_UNKNOWN = 0,
40 SOURCE_CAMERA = 1,
41 SOURCE_MICROPHONE = 2,
42 SOURCE_SCREENSHARE = 3,
43 SOURCE_SCREENSHARE_AUDIO = 4,
44};
45
46enum class StreamState {
47 STATE_UNKNOWN = 0,
48 STATE_ACTIVE = 1,
49 STATE_PAUSED = 2,
50};
51
52enum class AudioTrackFeature {
53 TF_STEREO = 0,
54 TF_NO_DTX = 1,
55 TF_AUTO_GAIN_CONTROL = 2,
56 TF_ECHO_CANCELLATION = 3,
57 TF_NOISE_SUPPRESSION = 4,
58 TF_ENHANCED_NOISE_CANCELLATION = 5,
59 TF_PRECONNECT_BUFFER = 6,
60};
61
63 std::string participant_identity;
64 std::optional<bool> allow_all;
65 std::vector<std::string> allowed_track_sids;
66};
67
68// ============================================================
69// Base Track
70// ============================================================
71class Track {
72public:
73 virtual ~Track() = default;
74
75 // Read-only properties
76 const std::string &sid() const noexcept { return sid_; }
77 const std::string &name() const noexcept { return name_; }
78 TrackKind kind() const noexcept { return kind_; }
79 StreamState stream_state() const noexcept { return state_; }
80 bool muted() const noexcept { return muted_; }
81 bool remote() const noexcept { return remote_; }
82
83 // Optional publication info
84 std::optional<TrackSource> source() const noexcept { return source_; }
85 std::optional<bool> simulcasted() const noexcept { return simulcasted_; }
86 std::optional<uint32_t> width() const noexcept { return width_; }
87 std::optional<uint32_t> height() const noexcept { return height_; }
88 std::optional<std::string> mime_type() const noexcept { return mime_type_; }
89
90 // Handle access
91 bool has_handle() const noexcept { return !handle_.valid(); }
92 uintptr_t ffi_handle_id() const noexcept { return handle_.get(); }
93
94 // Async get stats
95 std::future<std::vector<RtcStats>> getStats() const;
96
97 // Internal updates (called by Room)
98 void setStreamState(StreamState s) noexcept { state_ = s; }
99 void setMuted(bool m) noexcept { muted_ = m; }
100 void setName(std::string n) noexcept { name_ = std::move(n); }
101
102protected:
103 Track(FfiHandle handle, std::string sid, std::string name, TrackKind kind,
104 StreamState state, bool muted, bool remote);
105
106 void setPublicationFields(std::optional<TrackSource> source,
107 std::optional<bool> simulcasted,
108 std::optional<uint32_t> width,
109 std::optional<uint32_t> height,
110 std::optional<std::string> mime_type);
111
112private:
113 FfiHandle handle_; // Owned
114
115 std::string sid_;
116 std::string name_;
117 TrackKind kind_{TrackKind::KIND_UNKNOWN};
118 StreamState state_{StreamState::STATE_UNKNOWN};
119 bool muted_{false};
120 bool remote_{false};
121
122 std::optional<TrackSource> source_;
123 std::optional<bool> simulcasted_;
124 std::optional<uint32_t> width_;
125 std::optional<uint32_t> height_;
126 std::optional<std::string> mime_type_;
127};
128
129} // namespace livekit
RAII wrapper for an FFI handle (uintptr_t) coming from Rust.
Definition ffi_handle.h:29
Definition track.h:71