LiveKit C++ Client SDK v1.9.0
Real-time audio/video/data 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
19#include <cstdint>
20#include <future>
21#include <memory>
22#include <optional>
23#include <string>
24#include <vector>
25
26#include "livekit/ffi_handle.h"
27#include "livekit/stats.h"
28#include "livekit/visibility.h"
29
30namespace livekit {
31
32class LocalTrackPublication;
33
35enum class TrackKind {
36 KIND_UNKNOWN = 0,
37 KIND_AUDIO = 1,
38 KIND_VIDEO = 2,
39};
40
42enum class TrackSource {
43 SOURCE_UNKNOWN = 0,
44 SOURCE_CAMERA = 1,
45 SOURCE_MICROPHONE = 2,
46 SOURCE_SCREENSHARE = 3,
47 SOURCE_SCREENSHARE_AUDIO = 4,
48};
49
51enum class StreamState {
52 STATE_UNKNOWN = 0,
53 STATE_ACTIVE = 1,
54 STATE_PAUSED = 2,
55};
56
58enum class VideoQuality {
59 LOW,
60 MEDIUM,
61 HIGH,
62};
63
66 TF_STEREO = 0,
67 TF_NO_DTX = 1,
68 TF_AUTO_GAIN_CONTROL = 2,
69 TF_ECHO_CANCELLATION = 3,
70 TF_NOISE_SUPPRESSION = 4,
71 TF_ENHANCED_NOISE_CANCELLATION = 5,
72 TF_PRECONNECT_BUFFER = 6,
73};
74
77 std::string participant_identity;
78 std::optional<bool> allow_all;
79 std::vector<std::string> allowed_track_sids;
80};
81
83class LIVEKIT_API Track {
84public:
85 virtual ~Track() = default;
86
87 // Read-only properties
88 const std::string& sid() const noexcept { return sid_; }
89 const std::string& name() const noexcept { return name_; }
90 TrackKind kind() const noexcept { return kind_; }
91 StreamState streamState() const noexcept { return state_; }
92 bool muted() const noexcept { return muted_; }
93 bool remote() const noexcept { return remote_; }
94
95 // Optional publication info
96 std::optional<TrackSource> source() const noexcept { return source_; }
97 std::optional<bool> simulcasted() const noexcept { return simulcasted_; }
98 std::optional<uint32_t> width() const noexcept { return width_; }
99 std::optional<uint32_t> height() const noexcept { return height_; }
100 // std::string can actually throw, suppressing for now to maintain API
101 // compatibility
102 // NOLINTNEXTLINE(bugprone-exception-escape)
103 std::optional<std::string> mimeType() const noexcept { return mime_type_; }
104
105 // Handle access
106 bool hasHandle() const noexcept { return handle_.valid(); }
107 uintptr_t ffiHandleId() const noexcept { return handle_.get(); }
108
109 // Async get stats
110 std::future<std::vector<RtcStats>> getStats() const;
111
114 virtual void setPublication(const std::shared_ptr<LocalTrackPublication>& publication) noexcept { (void)publication; }
115
116 // Internal updates (called by Room)
117 void setStreamState(StreamState s) noexcept { state_ = s; }
118 void setMuted(bool m) noexcept { muted_ = m; }
119 void setName(std::string n) noexcept { name_ = std::move(n); }
120
121protected:
122 Track(FfiHandle handle, std::string sid, std::string name, TrackKind kind, StreamState state, bool muted,
123 bool remote);
124
125 void setPublicationFields(std::optional<TrackSource> source, std::optional<bool> simulcasted,
126 std::optional<uint32_t> width, std::optional<uint32_t> height,
127 std::optional<std::string> mime_type);
128
129private:
130 FfiHandle handle_; // Owned
131
132 std::string sid_;
133 std::string name_;
134 TrackKind kind_{TrackKind::KIND_UNKNOWN};
135 StreamState state_{StreamState::STATE_UNKNOWN};
136 bool muted_{false};
137 bool remote_{false};
138
139 std::optional<TrackSource> source_;
140 std::optional<bool> simulcasted_;
141 std::optional<uint32_t> width_;
142 std::optional<uint32_t> height_;
143 std::optional<std::string> mime_type_;
144};
145
146} // namespace livekit
Base class for local and remote media tracks.
Definition track.h:83
virtual void setPublication(const std::shared_ptr< LocalTrackPublication > &publication) noexcept
After publishing a local track, associates the LocalTrackPublication with this track.
Definition track.h:114
Public API for the LiveKit C++ Client SDK.
Definition audio_frame.h:25
AudioTrackFeature
Optional audio processing or encoding feature advertised for a track.
Definition track.h:65
StreamState
Stream state reported for a subscribed track.
Definition track.h:51
TrackKind
Media kind for an audio or video track.
Definition track.h:35
TrackSource
Source category for a published track.
Definition track.h:42
VideoQuality
Maximum receive quality requested for a remote video track.
Definition track.h:58
Per-participant track subscription permission configuration.
Definition track.h:76