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
32class LocalTrackPublication;
33
34enum class TrackKind {
35 KIND_UNKNOWN = 0,
36 KIND_AUDIO = 1,
37 KIND_VIDEO = 2,
38};
39
40enum class TrackSource {
41 SOURCE_UNKNOWN = 0,
42 SOURCE_CAMERA = 1,
43 SOURCE_MICROPHONE = 2,
44 SOURCE_SCREENSHARE = 3,
45 SOURCE_SCREENSHARE_AUDIO = 4,
46};
47
48enum class StreamState {
49 STATE_UNKNOWN = 0,
50 STATE_ACTIVE = 1,
51 STATE_PAUSED = 2,
52};
53
54enum class AudioTrackFeature {
55 TF_STEREO = 0,
56 TF_NO_DTX = 1,
57 TF_AUTO_GAIN_CONTROL = 2,
58 TF_ECHO_CANCELLATION = 3,
59 TF_NOISE_SUPPRESSION = 4,
60 TF_ENHANCED_NOISE_CANCELLATION = 5,
61 TF_PRECONNECT_BUFFER = 6,
62};
63
65 std::string participant_identity;
66 std::optional<bool> allow_all;
67 std::vector<std::string> allowed_track_sids;
68};
69
70// ============================================================
71// Base Track
72// ============================================================
73class Track {
74public:
75 virtual ~Track() = default;
76
77 // Read-only properties
78 const std::string &sid() const noexcept { return sid_; }
79 const std::string &name() const noexcept { return name_; }
80 TrackKind kind() const noexcept { return kind_; }
81 StreamState stream_state() const noexcept { return state_; }
82 bool muted() const noexcept { return muted_; }
83 bool remote() const noexcept { return remote_; }
84
85 // Optional publication info
86 std::optional<TrackSource> source() const noexcept { return source_; }
87 std::optional<bool> simulcasted() const noexcept { return simulcasted_; }
88 std::optional<uint32_t> width() const noexcept { return width_; }
89 std::optional<uint32_t> height() const noexcept { return height_; }
90 std::optional<std::string> mime_type() const noexcept { return mime_type_; }
91
92 // Handle access
93 bool has_handle() const noexcept { return handle_.valid(); }
94 uintptr_t ffi_handle_id() const noexcept { return handle_.get(); }
95
96 // Async get stats
97 std::future<std::vector<RtcStats>> getStats() const;
98
101 virtual void setPublication(
102 const std::shared_ptr<LocalTrackPublication> &publication) noexcept {
103 (void)publication;
104 }
105
106 // Internal updates (called by Room)
107 void setStreamState(StreamState s) noexcept { state_ = s; }
108 void setMuted(bool m) noexcept { muted_ = m; }
109 void setName(std::string n) noexcept { name_ = std::move(n); }
110
111protected:
112 Track(FfiHandle handle, std::string sid, std::string name, TrackKind kind,
113 StreamState state, bool muted, bool remote);
114
115 void setPublicationFields(std::optional<TrackSource> source,
116 std::optional<bool> simulcasted,
117 std::optional<uint32_t> width,
118 std::optional<uint32_t> height,
119 std::optional<std::string> mime_type);
120
121private:
122 FfiHandle handle_; // Owned
123
124 std::string sid_;
125 std::string name_;
126 TrackKind kind_{TrackKind::KIND_UNKNOWN};
127 StreamState state_{StreamState::STATE_UNKNOWN};
128 bool muted_{false};
129 bool remote_{false};
130
131 std::optional<TrackSource> source_;
132 std::optional<bool> simulcasted_;
133 std::optional<uint32_t> width_;
134 std::optional<uint32_t> height_;
135 std::optional<std::string> mime_type_;
136};
137
138} // namespace livekit
Definition track.h:73
virtual void setPublication(const std::shared_ptr< LocalTrackPublication > &publication) noexcept
Definition track.h:101