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
4545namespace {
4646
47+ constexpr const char *kTrackName = " timestamped-camera" ;
48+
4749std::atomic<bool > g_running{true };
4850
4951void 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
148150private:
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