Skip to content

Commit bbab802

Browse files
use track name as key instead of source
1 parent e7d3ec3 commit bbab802

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

user_timestamped_video/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
This example is split into two executables and can demonstrate all four
44
producer/consumer combinations:
55

6-
- `UserTimestampedVideoProducer` publishes a synthetic camera track and stamps
7-
each frame with `VideoCaptureOptions::metadata.user_timestamp`.
8-
- `UserTimestampedVideoConsumer` subscribes to remote camera frames with
9-
either the rich or legacy callback path.
6+
- `UserTimestampedVideoProducer` publishes a synthetic video track named
7+
`"timestamped-camera"` and stamps each frame with
8+
`VideoCaptureOptions::metadata.user_timestamp`.
9+
- `UserTimestampedVideoConsumer` subscribes to the remote
10+
`"timestamped-camera"` track by name with either the rich or legacy callback
11+
path.
1012

1113
Run them in the same room with different participant identities:
1214

user_timestamped_video/consumer/main.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/// UserTimestampedVideoConsumer
1818
///
19-
/// Receives remote camera frames via `Room::setOnVideoFrameEventCallback()` and
19+
/// Receives remote video frames via `Room::setOnVideoFrameEventCallback()` and
2020
/// logs any `VideoFrameMetadata::user_timestamp` values that arrive. Pair
2121
/// with `UserTimestampedVideoProducer` running in another process.
2222
///
@@ -44,6 +44,8 @@ using namespace livekit;
4444

4545
namespace {
4646

47+
constexpr const char *kTrackName = "timestamped-camera";
48+
4749
std::atomic<bool> g_running{true};
4850

4951
void handleSignal(int) { g_running.store(false); }
@@ -112,7 +114,7 @@ class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
112114
void registerExistingParticipants() {
113115
for (const auto &participant : room_.remoteParticipants()) {
114116
if (participant) {
115-
registerRemoteCameraCallback(participant->identity());
117+
registerRemoteVideoCallback(participant->identity());
116118
}
117119
}
118120
}
@@ -125,7 +127,7 @@ class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
125127

126128
std::cout << "[consumer] participant connected: "
127129
<< event.participant->identity() << "\n";
128-
registerRemoteCameraCallback(event.participant->identity());
130+
registerRemoteVideoCallback(event.participant->identity());
129131
}
130132

131133
void onParticipantDisconnected(
@@ -135,7 +137,7 @@ class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
135137
}
136138

137139
const std::string identity = event.participant->identity();
138-
room_.clearOnVideoFrameCallback(identity, TrackSource::SOURCE_CAMERA);
140+
room_.clearOnVideoFrameCallback(identity, std::string(kTrackName));
139141

140142
{
141143
std::lock_guard<std::mutex> lock(mutex_);
@@ -146,7 +148,7 @@ class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
146148
}
147149

148150
private:
149-
void registerRemoteCameraCallback(const std::string &identity) {
151+
void registerRemoteVideoCallback(const std::string &identity) {
150152
{
151153
std::lock_guard<std::mutex> lock(mutex_);
152154
if (!registered_identities_.insert(identity).second) {
@@ -159,7 +161,7 @@ class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
159161

160162
if (read_user_timestamp_) {
161163
room_.setOnVideoFrameEventCallback(
162-
identity, TrackSource::SOURCE_CAMERA,
164+
identity, std::string(kTrackName),
163165
[identity](const VideoFrameEvent &event) {
164166
std::cout << "[consumer] from=" << identity
165167
<< " size=" << event.frame.width() << "x"
@@ -172,7 +174,7 @@ class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
172174
stream_options);
173175
} else {
174176
room_.setOnVideoFrameCallback(
175-
identity, TrackSource::SOURCE_CAMERA,
177+
identity, std::string(kTrackName),
176178
[identity](const VideoFrame &frame, const std::int64_t timestamp_us) {
177179
std::cout << "[consumer] from=" << identity
178180
<< " size=" << frame.width() << "x" << frame.height()
@@ -182,8 +184,8 @@ class UserTimestampedVideoConsumerDelegate : public RoomDelegate {
182184
stream_options);
183185
}
184186

185-
std::cout << "[consumer] listening for camera frames from " << identity
186-
<< " with user timestamp "
187+
std::cout << "[consumer] listening for video frames from " << identity
188+
<< " track=\"" << kTrackName << "\" with user timestamp "
187189
<< (read_user_timestamp_ ? "enabled" : "ignored") << "\n";
188190
}
189191

@@ -241,7 +243,7 @@ int main(int argc, char *argv[]) {
241243
for (const auto &participant : room.remoteParticipants()) {
242244
if (participant) {
243245
room.clearOnVideoFrameCallback(participant->identity(),
244-
TrackSource::SOURCE_CAMERA);
246+
std::string(kTrackName));
245247
}
246248
}
247249
}

0 commit comments

Comments
 (0)