Skip to content

Commit 98658f7

Browse files
create*Track -> publish*Track()
1 parent 9a1725a commit 98658f7

19 files changed

+268
-286
lines changed

bridge/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ options.dynacast = false;
2424
bridge.connect("wss://my-server.livekit.cloud", token, options);
2525

2626
// 2. Create outgoing tracks (RAII-managed)
27-
auto mic = bridge.createAudioTrack("mic", 48000, 2,
27+
auto mic = bridge.publishAudioTrack("mic", 48000, 2,
2828
livekit::TrackSource::SOURCE_MICROPHONE); // name, sample_rate, channels, source
29-
auto cam = bridge.createVideoTrack("cam", 1280, 720,
29+
auto cam = bridge.publishVideoTrack("cam", 1280, 720,
3030
livekit::TrackSource::SOURCE_CAMERA); // name, width, height, source
3131

3232
// 3. Push frames to remote participants
@@ -96,7 +96,7 @@ Your Application
9696
9797
**`LiveKitBridge`** -- The main entry point. Owns the full room lifecycle: SDK initialization, room connection, track publishing, and frame callback management.
9898
99-
**`BridgeAudioTrack` / `BridgeVideoTrack`** -- RAII handles for published local tracks. Created via `createAudioTrack()` / `createVideoTrack()`. When the `shared_ptr` is dropped, the track is automatically unpublished and all underlying SDK resources are freed. Call `pushFrame()` to send audio/video data to remote participants.
99+
**`BridgeAudioTrack` / `BridgeVideoTrack`** -- RAII handles for published local tracks. Created via `publishAudioTrack()` / `publishVideoTrack()`. When the `shared_ptr` is dropped, the track is automatically unpublished and all underlying SDK resources are freed. Call `pushFrame()` to send audio/video data to remote participants.
100100
101101
**`BridgeRoomDelegate`** -- Internal (not part of the public API; lives in `src/`). Listens for `onTrackSubscribed` / `onTrackUnsubscribed` events from the LiveKit SDK and wires up reader threads automatically.
102102
@@ -146,8 +146,8 @@ bridge.connect(url, token, options);
146146
| `connect(url, token, options)` | Connect to a LiveKit room. Initializes the SDK, creates a Room, and connects with auto-subscribe enabled. |
147147
| `disconnect()` | Disconnect and release all resources. Joins all reader threads. Safe to call multiple times. |
148148
| `isConnected()` | Returns whether the bridge is currently connected. |
149-
| `createAudioTrack(name, sample_rate, num_channels, source)` | Create and publish a local audio track with the given `TrackSource` (e.g. `SOURCE_MICROPHONE`, `SOURCE_SCREENSHARE_AUDIO`). Returns an RAII `shared_ptr<BridgeAudioTrack>`. |
150-
| `createVideoTrack(name, width, height, source)` | Create and publish a local video track with the given `TrackSource` (e.g. `SOURCE_CAMERA`, `SOURCE_SCREENSHARE`). Returns an RAII `shared_ptr<BridgeVideoTrack>`. |
149+
| `publishAudioTrack(name, sample_rate, num_channels, source)` | Create and publish a local audio track with the given `TrackSource` (e.g. `SOURCE_MICROPHONE`, `SOURCE_SCREENSHARE_AUDIO`). Returns an RAII `shared_ptr<BridgeAudioTrack>`. |
150+
| `publishVideoTrack(name, width, height, source)` | Create and publish a local video track with the given `TrackSource` (e.g. `SOURCE_CAMERA`, `SOURCE_SCREENSHARE`). Returns an RAII `shared_ptr<BridgeVideoTrack>`. |
151151
| `setOnAudioFrameCallback(identity, source, callback)` | Register a callback for audio frames from a specific remote participant + track source. |
152152
| `setOnVideoFrameCallback(identity, source, callback)` | Register a callback for video frames from a specific remote participant + track source. |
153153
| `clearOnAudioFrameCallback(identity, source)` | Clear the audio callback for a specific remote participant + track source. Stops and joins the reader thread if active. |

bridge/include/livekit_bridge/bridge_audio_track.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class BridgeAudioTrackTest;
4141
/**
4242
* Handle to a published local audio track.
4343
*
44-
* Created via LiveKitBridge::createAudioTrack(). The bridge retains a
44+
* Created via LiveKitBridge::publishAudioTrack(). The bridge retains a
4545
* reference to every track it creates and will automatically release all
4646
* tracks when disconnect() is called. To unpublish a track mid-session,
4747
* call release() explicitly; dropping the shared_ptr alone is not
@@ -60,7 +60,7 @@ class BridgeAudioTrackTest;
6060
* pushFrame() concurrently from multiple threads.
6161
*
6262
* Usage:
63-
* auto mic = bridge.createAudioTrack("mic", 48000, 2,
63+
* auto mic = bridge.publishAudioTrack("mic", 48000, 2,
6464
* livekit::TrackSource::SOURCE_MICROPHONE);
6565
* mic->pushFrame(pcm_data, samples_per_channel);
6666
* mic->mute();

bridge/include/livekit_bridge/bridge_video_track.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class BridgeVideoTrackTest;
4141
/**
4242
* Handle to a published local video track.
4343
*
44-
* Created via LiveKitBridge::createVideoTrack(). The bridge retains a
44+
* Created via LiveKitBridge::publishVideoTrack(). The bridge retains a
4545
* reference to every track it creates and will automatically release all
4646
* tracks when disconnect() is called. To unpublish a track mid-session,
4747
* call release() explicitly; dropping the shared_ptr alone is not
@@ -60,7 +60,7 @@ class BridgeVideoTrackTest;
6060
* pushFrame() concurrently from multiple threads.
6161
*
6262
* Usage:
63-
* auto cam = bridge.createVideoTrack("cam", 1280, 720,
63+
* auto cam = bridge.publishVideoTrack("cam", 1280, 720,
6464
* livekit::TrackSource::SOURCE_CAMERA);
6565
* cam->pushFrame(rgba_data, timestamp_us);
6666
* cam->mute();

bridge/include/livekit_bridge/livekit_bridge.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ using DataFrameCallback =
100100
* options.auto_subscribe = true;
101101
* bridge.connect("wss://my-server.livekit.cloud", my_token, options);
102102
*
103-
* auto mic = bridge.createAudioTrack("mic", 48000, 2,
103+
* auto mic = bridge.publishAudioTrack("mic", 48000, 2,
104104
* livekit::TrackSource::SOURCE_MICROPHONE);
105-
* auto cam = bridge.createVideoTrack("cam", 1280, 720,
105+
* auto cam = bridge.publishVideoTrack("cam", 1280, 720,
106106
* livekit::TrackSource::SOURCE_CAMERA);
107107
*
108108
* mic->pushFrame(pcm_data, samples_per_channel);
@@ -197,8 +197,8 @@ class LiveKitBridge {
197197
* @throws std::runtime_error if the bridge is not connected.
198198
*/
199199
std::shared_ptr<BridgeAudioTrack>
200-
createAudioTrack(const std::string &name, int sample_rate, int num_channels,
201-
livekit::TrackSource source);
200+
publishAudioTrack(const std::string &name, int sample_rate, int num_channels,
201+
livekit::TrackSource source);
202202

203203
/**
204204
* Create and publish a local video track.
@@ -224,8 +224,8 @@ class LiveKitBridge {
224224
* @throws std::runtime_error if the bridge is not connected.
225225
*/
226226
std::shared_ptr<BridgeVideoTrack>
227-
createVideoTrack(const std::string &name, int width, int height,
228-
livekit::TrackSource source);
227+
publishVideoTrack(const std::string &name, int width, int height,
228+
livekit::TrackSource source);
229229

230230
/**
231231
* Create and publish a local data track.
@@ -240,7 +240,7 @@ class LiveKitBridge {
240240
* @throws std::runtime_error if the bridge is not connected.
241241
*/
242242
std::shared_ptr<livekit::LocalDataTrack>
243-
createDataTrack(const std::string &name);
243+
publishDataTrack(const std::string &name);
244244

245245
// ---------------------------------------------------------------
246246
// Incoming frame callbacks

bridge/src/livekit_bridge.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,14 @@ bool LiveKitBridge::isConnected() const {
253253
// ---------------------------------------------------------------
254254

255255
std::shared_ptr<BridgeAudioTrack>
256-
LiveKitBridge::createAudioTrack(const std::string &name, int sample_rate,
257-
int num_channels, livekit::TrackSource source) {
256+
LiveKitBridge::publishAudioTrack(const std::string &name, int sample_rate,
257+
int num_channels,
258+
livekit::TrackSource source) {
258259
std::lock_guard<std::mutex> lock(mutex_);
259260

260261
if (!connected_ || !room_) {
261-
throw std::runtime_error(
262-
"createAudioTrack requires an active connection; call connect() first");
262+
throw std::runtime_error("publishAudioTrack requires an active connection; "
263+
"call connect() first");
263264
}
264265

265266
// 1. Create audio source (real-time mode, queue_size_ms=0)
@@ -288,13 +289,13 @@ LiveKitBridge::createAudioTrack(const std::string &name, int sample_rate,
288289
}
289290

290291
std::shared_ptr<BridgeVideoTrack>
291-
LiveKitBridge::createVideoTrack(const std::string &name, int width, int height,
292-
livekit::TrackSource source) {
292+
LiveKitBridge::publishVideoTrack(const std::string &name, int width, int height,
293+
livekit::TrackSource source) {
293294
std::lock_guard<std::mutex> lock(mutex_);
294295

295296
if (!connected_ || !room_) {
296-
throw std::runtime_error(
297-
"createVideoTrack requires an active connection; call connect() first");
297+
throw std::runtime_error("publishVideoTrack requires an active connection; "
298+
"call connect() first");
298299
}
299300

300301
// 1. Create video source
@@ -322,12 +323,12 @@ LiveKitBridge::createVideoTrack(const std::string &name, int width, int height,
322323
}
323324

324325
std::shared_ptr<livekit::LocalDataTrack>
325-
LiveKitBridge::createDataTrack(const std::string &name) {
326+
LiveKitBridge::publishDataTrack(const std::string &name) {
326327
std::lock_guard<std::mutex> lock(mutex_);
327328

328329
if (!connected_ || !room_) {
329330
throw std::runtime_error(
330-
"LiveKitBridge::createDataTrack: not connected to a room");
331+
"LiveKitBridge::publishDataTrack: not connected to a room");
331332
}
332333

333334
LK_LOG_INFO("[LiveKitBridge] Publishing data track \"{}\"...", name);

bridge/tests/integration/test_bridge_audio_roundtrip.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ TEST_F(BridgeAudioRoundtripTest, AudioFrameRoundTrip) {
8181

8282
std::cout << "Both bridges connected." << std::endl;
8383

84-
auto audio_track = caller.createAudioTrack(
84+
auto audio_track = caller.publishAudioTrack(
8585
"roundtrip-mic", kAudioSampleRate, kAudioChannels,
8686
livekit::TrackSource::SOURCE_MICROPHONE);
8787
ASSERT_NE(audio_track, nullptr);
@@ -149,8 +149,8 @@ TEST_F(BridgeAudioRoundtripTest, AudioFrameRoundTrip) {
149149

150150
// Clear callback before bridges go out of scope so the reader thread
151151
// is joined while the atomic counters above are still alive.
152-
receiver.clearOnAudioFrameCallback(
153-
caller_identity, livekit::TrackSource::SOURCE_MICROPHONE);
152+
receiver.clearOnAudioFrameCallback(caller_identity,
153+
livekit::TrackSource::SOURCE_MICROPHONE);
154154
}
155155

156156
// ---------------------------------------------------------------------------
@@ -170,9 +170,9 @@ TEST_F(BridgeAudioRoundtripTest, AudioLatencyMeasurement) {
170170

171171
ASSERT_TRUE(connectPair(caller, receiver));
172172

173-
auto audio_track = caller.createAudioTrack(
174-
"latency-mic", kAudioSampleRate, kAudioChannels,
175-
livekit::TrackSource::SOURCE_MICROPHONE);
173+
auto audio_track =
174+
caller.publishAudioTrack("latency-mic", kAudioSampleRate, kAudioChannels,
175+
livekit::TrackSource::SOURCE_MICROPHONE);
176176
ASSERT_NE(audio_track, nullptr);
177177

178178
LatencyStats stats;
@@ -221,10 +221,9 @@ TEST_F(BridgeAudioRoundtripTest, AudioLatencyMeasurement) {
221221
next_frame_time += frame_duration;
222222

223223
if (waiting_for_echo.load() && pulse_send_time > 0) {
224-
uint64_t now_us =
225-
std::chrono::duration_cast<std::chrono::microseconds>(
226-
std::chrono::steady_clock::now().time_since_epoch())
227-
.count();
224+
uint64_t now_us = std::chrono::duration_cast<std::chrono::microseconds>(
225+
std::chrono::steady_clock::now().time_since_epoch())
226+
.count();
228227
if (now_us - pulse_send_time > kEchoTimeoutUs) {
229228
std::cout << " Echo timeout for pulse " << pulses_sent << std::endl;
230229
waiting_for_echo.store(false);
@@ -239,16 +238,14 @@ TEST_F(BridgeAudioRoundtripTest, AudioLatencyMeasurement) {
239238
if (high_energy_remaining > 0) {
240239
frame_data = generateHighEnergyFrame(kSamplesPerFrame);
241240
high_energy_remaining--;
242-
} else if (frame_count > 0 &&
243-
frame_count % frames_between_pulses == 0 &&
241+
} else if (frame_count > 0 && frame_count % frames_between_pulses == 0 &&
244242
!waiting_for_echo.load()) {
245243
frame_data = generateHighEnergyFrame(kSamplesPerFrame);
246244
high_energy_remaining = kHighEnergyFramesPerPulse - 1;
247245

248-
pulse_send_time =
249-
std::chrono::duration_cast<std::chrono::microseconds>(
250-
std::chrono::steady_clock::now().time_since_epoch())
251-
.count();
246+
pulse_send_time = std::chrono::duration_cast<std::chrono::microseconds>(
247+
std::chrono::steady_clock::now().time_since_epoch())
248+
.count();
252249
last_send_time_us.store(pulse_send_time);
253250
waiting_for_echo.store(true);
254251
pulses_sent++;
@@ -273,8 +270,8 @@ TEST_F(BridgeAudioRoundtripTest, AudioLatencyMeasurement) {
273270
EXPECT_GT(stats.count(), 0u)
274271
<< "At least one audio latency measurement should be recorded";
275272

276-
receiver.clearOnAudioFrameCallback(
277-
caller_identity, livekit::TrackSource::SOURCE_MICROPHONE);
273+
receiver.clearOnAudioFrameCallback(caller_identity,
274+
livekit::TrackSource::SOURCE_MICROPHONE);
278275
}
279276

280277
// ---------------------------------------------------------------------------
@@ -301,7 +298,7 @@ TEST_F(BridgeAudioRoundtripTest, ConnectPublishDisconnectCycle) {
301298
bridge.connect(config_.url, config_.caller_token, options);
302299
ASSERT_TRUE(connected) << "Cycle " << i << ": connect failed";
303300

304-
auto track = bridge.createAudioTrack(
301+
auto track = bridge.publishAudioTrack(
305302
"cycle-mic", kAudioSampleRate, kAudioChannels,
306303
livekit::TrackSource::SOURCE_MICROPHONE);
307304
ASSERT_NE(track, nullptr);

bridge/tests/integration/test_bridge_data_roundtrip.cpp

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ TEST_F(BridgeDataRoundtripTest, DataFrameRoundTrip) {
5252
const std::string track_name = "roundtrip-data";
5353
const std::string caller_identity = "rpc-caller";
5454

55-
auto data_track = caller.createDataTrack(track_name);
55+
auto data_track = caller.publishDataTrack(track_name);
5656
ASSERT_NE(data_track, nullptr);
5757
ASSERT_TRUE(data_track->isPublished());
5858

@@ -141,7 +141,7 @@ TEST_F(BridgeDataRoundtripTest, LateCallbackRegistration) {
141141
const std::string track_name = "late-callback-data";
142142
const std::string caller_identity = "rpc-caller";
143143

144-
auto data_track = caller.createDataTrack(track_name);
144+
auto data_track = caller.publishDataTrack(track_name);
145145
ASSERT_NE(data_track, nullptr);
146146

147147
std::cout << "Data track published, waiting before registering callback..."
@@ -155,8 +155,7 @@ TEST_F(BridgeDataRoundtripTest, LateCallbackRegistration) {
155155

156156
receiver.setOnDataFrameCallback(
157157
caller_identity, track_name,
158-
[&](const std::vector<std::uint8_t> &,
159-
std::optional<std::uint64_t>) {
158+
[&](const std::vector<std::uint8_t> &, std::optional<std::uint64_t>) {
160159
frames_received++;
161160
rx_cv.notify_all();
162161
});
@@ -174,9 +173,8 @@ TEST_F(BridgeDataRoundtripTest, LateCallbackRegistration) {
174173

175174
{
176175
std::unique_lock<std::mutex> lock(rx_mutex);
177-
rx_cv.wait_for(lock, 10s, [&] {
178-
return frames_received.load() >= num_frames;
179-
});
176+
rx_cv.wait_for(lock, 10s,
177+
[&] { return frames_received.load() >= num_frames; });
180178
}
181179

182180
std::cout << "Frames received: " << frames_received.load() << std::endl;
@@ -206,21 +204,20 @@ TEST_F(BridgeDataRoundtripTest, VaryingPayloadSizes) {
206204
const std::string track_name = "size-test-data";
207205
const std::string caller_identity = "rpc-caller";
208206

209-
auto data_track = caller.createDataTrack(track_name);
207+
auto data_track = caller.publishDataTrack(track_name);
210208
ASSERT_NE(data_track, nullptr);
211209

212210
std::mutex rx_mutex;
213211
std::condition_variable rx_cv;
214212
std::vector<size_t> received_sizes;
215213

216-
receiver.setOnDataFrameCallback(
217-
caller_identity, track_name,
218-
[&](const std::vector<std::uint8_t> &payload,
219-
std::optional<std::uint64_t>) {
220-
std::lock_guard<std::mutex> lock(rx_mutex);
221-
received_sizes.push_back(payload.size());
222-
rx_cv.notify_all();
223-
});
214+
receiver.setOnDataFrameCallback(caller_identity, track_name,
215+
[&](const std::vector<std::uint8_t> &payload,
216+
std::optional<std::uint64_t>) {
217+
std::lock_guard<std::mutex> lock(rx_mutex);
218+
received_sizes.push_back(payload.size());
219+
rx_cv.notify_all();
220+
});
224221

225222
std::this_thread::sleep_for(3s);
226223

@@ -238,18 +235,17 @@ TEST_F(BridgeDataRoundtripTest, VaryingPayloadSizes) {
238235

239236
{
240237
std::unique_lock<std::mutex> lock(rx_mutex);
241-
rx_cv.wait_for(lock, 15s, [&] {
242-
return received_sizes.size() >= test_sizes.size();
243-
});
238+
rx_cv.wait_for(lock, 15s,
239+
[&] { return received_sizes.size() >= test_sizes.size(); });
244240
}
245241

246-
std::cout << "Received " << received_sizes.size() << "/"
247-
<< test_sizes.size() << " frames." << std::endl;
242+
std::cout << "Received " << received_sizes.size() << "/" << test_sizes.size()
243+
<< " frames." << std::endl;
248244

249245
EXPECT_EQ(received_sizes.size(), test_sizes.size());
250246

251-
for (size_t i = 0;
252-
i < std::min(received_sizes.size(), test_sizes.size()); ++i) {
247+
for (size_t i = 0; i < std::min(received_sizes.size(), test_sizes.size());
248+
++i) {
253249
EXPECT_EQ(received_sizes[i], test_sizes[i])
254250
<< "Size mismatch at index " << i;
255251
}
@@ -277,7 +273,7 @@ TEST_F(BridgeDataRoundtripTest, ConnectPublishDisconnectCycle) {
277273
bridge.connect(config_.url, config_.caller_token, options);
278274
ASSERT_TRUE(connected) << "Cycle " << i << ": connect failed";
279275

280-
auto track = bridge.createDataTrack("cycle-data");
276+
auto track = bridge.publishDataTrack("cycle-data");
281277
ASSERT_NE(track, nullptr);
282278

283279
for (int f = 0; f < 5; ++f) {

bridge/tests/integration/test_bridge_rpc_roundtrip.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ TEST_F(BridgeRemoteTrackControlTest, RemoteMuteAudioTrack) {
175175

176176
const std::string publisher_identity = "rpc-receiver";
177177

178-
auto audio_track = publisher.createAudioTrack(
178+
auto audio_track = publisher.publishAudioTrack(
179179
"mic", 48000, 1, livekit::TrackSource::SOURCE_MICROPHONE);
180180
ASSERT_NE(audio_track, nullptr);
181181

@@ -214,7 +214,7 @@ TEST_F(BridgeRemoteTrackControlTest, RemoteMuteVideoTrack) {
214214

215215
const std::string publisher_identity = "rpc-receiver";
216216

217-
auto video_track = publisher.createVideoTrack(
217+
auto video_track = publisher.publishVideoTrack(
218218
"cam", 320, 240, livekit::TrackSource::SOURCE_CAMERA);
219219
ASSERT_NE(video_track, nullptr);
220220

0 commit comments

Comments
 (0)