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