Skip to content

Commit 172a452

Browse files
align with latest protos
1 parent 78646aa commit 172a452

9 files changed

Lines changed: 64 additions & 29 deletions

cpp-example-collection

include/livekit/room.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ class Room {
262262
TrackSource source, VideoFrameCallback callback,
263263
VideoStream::Options opts = {});
264264

265+
/**
266+
* @brief Sets the video frame callback via SubscriptionThreadDispatcher.
267+
*/
268+
void setOnVideoFrameCallback(const std::string &participant_identity,
269+
const std::string &track_name,
270+
VideoFrameCallback callback,
271+
VideoStream::Options opts = {});
272+
265273
/**
266274
* Set a rich callback for video frame events from a specific remote
267275
* participant and track source.
@@ -277,11 +285,7 @@ class Room {
277285
VideoStream::Options opts = {});
278286

279287
/**
280-
* Clear the audio frame callback for a specific (participant, source) pair.
281-
* Stops and joins any active reader thread.
282-
* No-op if no callback is registered for this key.
283-
* @param participant_identity Identity of the remote participant.
284-
* @param source Track source (e.g. SOURCE_MICROPHONE).
288+
* @brief Clears the audio frame callback via SubscriptionThreadDispatcher.
285289
*/
286290
void clearOnAudioFrameCallback(const std::string &participant_identity,
287291
TrackSource source);

include/livekit/subscription_thread_dispatcher.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ class SubscriptionThreadDispatcher {
141141
TrackSource source, VideoFrameCallback callback,
142142
VideoStream::Options opts = {});
143143

144+
/**
145+
* Register or replace a video frame callback for a remote subscription.
146+
*
147+
* The callback is keyed by remote participant identity plus \p track_name.
148+
* If the matching remote video track is already subscribed, \ref Room may
149+
* immediately call \ref handleTrackSubscribed to start a reader.
150+
*
151+
* @param participant_identity Identity of the remote participant.
152+
* @param track_name Track name to match.
153+
* @param callback Function invoked for each decoded video frame.
154+
* @param opts Options used when creating the backing
155+
* \ref VideoStream.
156+
*/
157+
void setOnVideoFrameCallback(const std::string &participant_identity,
158+
const std::string &track_name,
159+
VideoFrameCallback callback,
160+
VideoStream::Options opts = {});
161+
144162
/**
145163
* Register or replace a rich video frame event callback for a remote
146164
* subscription.

include/livekit/video_source.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum class VideoRotation {
4444
* feature can be negotiated separately.
4545
*/
4646
struct VideoFrameMetadata {
47-
std::optional<std::uint64_t> user_timestamp_us;
47+
std::optional<std::uint64_t> user_timestamp;
4848
std::optional<std::uint32_t> frame_id;
4949
};
5050

include/livekit/video_stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct VideoFrameEvent {
3838
// WebRTC frame timestamp in microseconds.
3939
// This may be translated onto WebRTC's internal capture-time timeline and
4040
// should not be expected to match application-provided metadata such as
41-
// VideoFrameMetadata::user_timestamp_us exactly.
41+
// VideoFrameMetadata::user_timestamp exactly.
4242
std::int64_t timestamp_us;
4343
VideoRotation rotation;
4444
std::optional<VideoFrameMetadata> metadata;

src/room.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ void Room::setOnVideoFrameCallback(const std::string &participant_identity,
304304
}
305305
}
306306

307+
void Room::setOnVideoFrameCallback(const std::string &participant_identity,
308+
const std::string &track_name,
309+
VideoFrameCallback callback,
310+
VideoStream::Options opts) {
311+
if (subscription_thread_dispatcher_) {
312+
subscription_thread_dispatcher_->setOnVideoFrameCallback(
313+
participant_identity, track_name, std::move(callback), std::move(opts));
314+
}
315+
}
316+
307317
void Room::setOnVideoFrameEventCallback(const std::string &participant_identity,
308318
TrackSource source,
309319
VideoFrameEventCallback callback,

src/subscription_thread_dispatcher.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void SubscriptionThreadDispatcher::setOnVideoFrameCallback(
100100
void SubscriptionThreadDispatcher::setOnVideoFrameEventCallback(
101101
const std::string &participant_identity, TrackSource source,
102102
VideoFrameEventCallback callback, VideoStream::Options opts) {
103-
CallbackKey key{participant_identity, source};
103+
CallbackKey key{participant_identity, source, ""};
104104
std::lock_guard<std::mutex> lock(lock_);
105105
const bool replacing = video_callbacks_.find(key) != video_callbacks_.end();
106106
video_callbacks_[key] = RegisteredVideoCallback{
@@ -121,8 +121,11 @@ void SubscriptionThreadDispatcher::setOnVideoFrameCallback(
121121
track_name};
122122
std::lock_guard<std::mutex> lock(lock_);
123123
const bool replacing = video_callbacks_.find(key) != video_callbacks_.end();
124-
video_callbacks_[key] =
125-
RegisteredVideoCallback{std::move(callback), std::move(opts)};
124+
video_callbacks_[key] = RegisteredVideoCallback{
125+
std::move(callback),
126+
VideoFrameEventCallback{},
127+
std::move(opts),
128+
};
126129
LK_LOG_DEBUG(
127130
"Registered video frame callback for participant={} track_name={} "
128131
"replacing_existing={} total_video_callbacks={}",

src/tests/integration/test_video_frame_metadata.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ TEST(VideoFrameMetadataTest, EmptyMetadataIsOmittedFromProto) {
3434

3535
TEST(VideoFrameMetadataTest, UserTimestampOnlyIsPreserved) {
3636
VideoFrameMetadata metadata;
37-
metadata.user_timestamp_us = 123;
37+
metadata.user_timestamp = 123;
3838

3939
auto proto_metadata = toProto(metadata);
4040
ASSERT_TRUE(proto_metadata.has_value());
41-
EXPECT_TRUE(proto_metadata->has_user_timestamp_us());
42-
EXPECT_EQ(proto_metadata->user_timestamp_us(), 123u);
41+
EXPECT_TRUE(proto_metadata->has_user_timestamp());
42+
EXPECT_EQ(proto_metadata->user_timestamp(), 123u);
4343
EXPECT_FALSE(proto_metadata->has_frame_id());
4444

4545
auto round_trip = fromProto(*proto_metadata);
4646
ASSERT_TRUE(round_trip.has_value());
47-
EXPECT_EQ(round_trip->user_timestamp_us, std::optional<std::uint64_t>(123));
47+
EXPECT_EQ(round_trip->user_timestamp, std::optional<std::uint64_t>(123));
4848
EXPECT_EQ(round_trip->frame_id, std::nullopt);
4949
}
5050

@@ -54,29 +54,29 @@ TEST(VideoFrameMetadataTest, FrameIdOnlyIsPreserved) {
5454

5555
auto proto_metadata = toProto(metadata);
5656
ASSERT_TRUE(proto_metadata.has_value());
57-
EXPECT_FALSE(proto_metadata->has_user_timestamp_us());
57+
EXPECT_FALSE(proto_metadata->has_user_timestamp());
5858
EXPECT_TRUE(proto_metadata->has_frame_id());
5959
EXPECT_EQ(proto_metadata->frame_id(), 456u);
6060

6161
auto round_trip = fromProto(*proto_metadata);
6262
ASSERT_TRUE(round_trip.has_value());
63-
EXPECT_EQ(round_trip->user_timestamp_us, std::nullopt);
63+
EXPECT_EQ(round_trip->user_timestamp, std::nullopt);
6464
EXPECT_EQ(round_trip->frame_id, std::optional<std::uint32_t>(456));
6565
}
6666

6767
TEST(VideoFrameMetadataTest, BothFieldsArePreserved) {
6868
VideoFrameMetadata metadata;
69-
metadata.user_timestamp_us = 123;
69+
metadata.user_timestamp = 123;
7070
metadata.frame_id = 456;
7171

7272
auto proto_metadata = toProto(metadata);
7373
ASSERT_TRUE(proto_metadata.has_value());
74-
EXPECT_TRUE(proto_metadata->has_user_timestamp_us());
74+
EXPECT_TRUE(proto_metadata->has_user_timestamp());
7575
EXPECT_TRUE(proto_metadata->has_frame_id());
7676

7777
auto round_trip = fromProto(*proto_metadata);
7878
ASSERT_TRUE(round_trip.has_value());
79-
EXPECT_EQ(round_trip->user_timestamp_us, std::optional<std::uint64_t>(123));
79+
EXPECT_EQ(round_trip->user_timestamp, std::optional<std::uint64_t>(123));
8080
EXPECT_EQ(round_trip->frame_id, std::optional<std::uint32_t>(456));
8181
}
8282

@@ -129,8 +129,8 @@ TEST_F(VideoFrameMetadataServerTest,
129129
sender_identity, TrackSource::SOURCE_CAMERA,
130130
[&mutex, &cv, &received_user_timestamp_us](const VideoFrameEvent &event) {
131131
std::lock_guard<std::mutex> lock(mutex);
132-
if (event.metadata && event.metadata->user_timestamp_us.has_value()) {
133-
received_user_timestamp_us = event.metadata->user_timestamp_us;
132+
if (event.metadata && event.metadata->user_timestamp.has_value()) {
133+
received_user_timestamp_us = event.metadata->user_timestamp;
134134
cv.notify_all();
135135
}
136136
});
@@ -153,7 +153,7 @@ TEST_F(VideoFrameMetadataServerTest,
153153
capture_options.timestamp_us =
154154
static_cast<std::int64_t>(expected_user_timestamp_us);
155155
capture_options.metadata = VideoFrameMetadata{};
156-
capture_options.metadata->user_timestamp_us = expected_user_timestamp_us;
156+
capture_options.metadata->user_timestamp = expected_user_timestamp_us;
157157

158158
const auto deadline = std::chrono::steady_clock::now() + 10s;
159159
while (std::chrono::steady_clock::now() < deadline) {

src/video_utils.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ toProto(const std::optional<VideoFrameMetadata> &metadata) {
9393
}
9494

9595
proto::FrameMetadata proto_metadata;
96-
if (metadata->user_timestamp_us.has_value()) {
97-
proto_metadata.set_user_timestamp_us(*metadata->user_timestamp_us);
96+
if (metadata->user_timestamp.has_value()) {
97+
proto_metadata.set_user_timestamp(*metadata->user_timestamp);
9898
}
9999
if (metadata->frame_id.has_value()) {
100100
proto_metadata.set_frame_id(*metadata->frame_id);
101101
}
102102

103-
if (!proto_metadata.has_user_timestamp_us() && !proto_metadata.has_frame_id()) {
103+
if (!proto_metadata.has_user_timestamp() && !proto_metadata.has_frame_id()) {
104104
return std::nullopt;
105105
}
106106

@@ -109,14 +109,14 @@ toProto(const std::optional<VideoFrameMetadata> &metadata) {
109109

110110
std::optional<VideoFrameMetadata> fromProto(const proto::FrameMetadata &metadata) {
111111
VideoFrameMetadata out;
112-
if (metadata.has_user_timestamp_us()) {
113-
out.user_timestamp_us = metadata.user_timestamp_us();
112+
if (metadata.has_user_timestamp()) {
113+
out.user_timestamp = metadata.user_timestamp();
114114
}
115115
if (metadata.has_frame_id()) {
116116
out.frame_id = metadata.frame_id();
117117
}
118118

119-
if (!out.user_timestamp_us.has_value() && !out.frame_id.has_value()) {
119+
if (!out.user_timestamp.has_value() && !out.frame_id.has_value()) {
120120
return std::nullopt;
121121
}
122122

0 commit comments

Comments
 (0)