Skip to content

Commit 7ea5f04

Browse files
committed
Set is_screencast in publish_track
1 parent d276130 commit 7ea5f04

File tree

12 files changed

+80
-46
lines changed

12 files changed

+80
-46
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
patch type="added" "Set is_screencast on VideoTrackSource creation" package="webrtc-sys"
2-
patch type="added" "Set is_screencast on NativeVideoSource creation" package="libwebrtc"
3-
patch type="added" "Extend NewVideoSourceRequest with is_screencast" package="livekit-ffi"
4-
patch type="changed" "Use new NativeVideoSource constructor in examples" package="examples"
1+
patch type="added" "Add a setter for is_screencast in InternalSource" package="webrtc-sys"
2+
patch type="added" "Expose set_is_screencast in NativeVideoSource" package="libwebrtc"
3+
patch type="added" "Extend enum_dispatch to create functions that don't have a return type" package="livekit-protocol"
4+
patch type="added" "Set is_screencast in publish_track when the source is Screenshare" package="livekit"

examples/wgpu_room/src/logo_track.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ pub struct LogoTrack {
4747
impl LogoTrack {
4848
pub fn new(room: Arc<Room>) -> Self {
4949
Self {
50-
rtc_source: NativeVideoSource::new(
51-
VideoResolution { width: FB_WIDTH as u32, height: FB_HEIGHT as u32 },
52-
false,
53-
),
50+
rtc_source: NativeVideoSource::new(VideoResolution {
51+
width: FB_WIDTH as u32,
52+
height: FB_HEIGHT as u32,
53+
}),
5454
room,
5555
handle: None,
5656
}

libwebrtc/src/native/video_source.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ struct VideoSourceInner {
5050
}
5151

5252
impl NativeVideoSource {
53-
pub fn new(resolution: VideoResolution, is_screencast: bool) -> NativeVideoSource {
53+
pub fn new(resolution: VideoResolution) -> NativeVideoSource {
5454
let source = Self {
55-
sys_handle: vt_sys::ffi::new_video_track_source(
56-
&vt_sys::ffi::VideoResolution::from(resolution.clone()),
57-
is_screencast,
58-
),
55+
sys_handle: vt_sys::ffi::new_video_track_source(&vt_sys::ffi::VideoResolution::from(
56+
resolution.clone(),
57+
)),
5958
inner: Arc::new(Mutex::new(VideoSourceInner { captured_frames: 0 })),
6059
};
6160

@@ -114,4 +113,8 @@ impl NativeVideoSource {
114113
pub fn video_resolution(&self) -> VideoResolution {
115114
self.sys_handle.video_resolution().into()
116115
}
116+
117+
pub fn set_is_screencast(&self, is_screencast: bool) {
118+
self.sys_handle.set_is_screencast(is_screencast);
119+
}
117120
}

libwebrtc/src/video_source.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ impl RtcVideoSource {
3636
[Native];
3737
pub fn video_resolution(self: &Self) -> VideoResolution;
3838
);
39+
enum_dispatch!(
40+
[Native];
41+
pub fn set_is_screencast(self: &Self, is_screencast: bool);
42+
);
3943
}
4044

4145
#[cfg(not(target_arch = "wasm32"))]
@@ -58,13 +62,13 @@ pub mod native {
5862

5963
impl Default for NativeVideoSource {
6064
fn default() -> Self {
61-
Self::new(VideoResolution::default(), false)
65+
Self::new(VideoResolution::default())
6266
}
6367
}
6468

6569
impl NativeVideoSource {
66-
pub fn new(resolution: VideoResolution, is_screencast: bool) -> Self {
67-
Self { handle: vs_imp::NativeVideoSource::new(resolution, is_screencast) }
70+
pub fn new(resolution: VideoResolution) -> Self {
71+
Self { handle: vs_imp::NativeVideoSource::new(resolution) }
6872
}
6973

7074
pub fn capture_frame<T: AsRef<dyn VideoBuffer>>(&self, frame: &VideoFrame<T>) {
@@ -74,6 +78,10 @@ pub mod native {
7478
pub fn video_resolution(&self) -> VideoResolution {
7579
self.handle.video_resolution()
7680
}
81+
82+
pub fn set_is_screencast(&self, is_screencast: bool) {
83+
self.handle.set_is_screencast(is_screencast)
84+
}
7785
}
7886
}
7987

livekit-ffi/protocol/video_frame.proto

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ message NewVideoSourceRequest {
4949
// Used to determine which encodings to use + simulcast layers
5050
// Most of the time it corresponds to the source resolution
5151
required VideoSourceResolution resolution = 2;
52-
optional bool is_screencast = 3;
5352
}
5453
message NewVideoSourceResponse { required OwnedVideoSource source = 1; }
5554

livekit-ffi/src/livekit.proto.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @generated
2+
// This file is @generated by prost-build.
23
#[allow(clippy::derive_partial_eq_without_eq)]
34
#[derive(Clone, PartialEq, ::prost::Message)]
45
pub struct FrameCryptor {
@@ -302,11 +303,11 @@ impl EncryptionState {
302303
/// # Safety
303304
/// The foreign language is responsable for disposing handles
304305
/// Forgetting to dispose the handle may lead to memory leaks
305-
///
306+
///
306307
/// Dropping a handle doesn't necessarily mean that the object is destroyed if it is still used
307308
/// on the FfiServer (Atomic reference counting)
308-
///
309-
/// When refering to a handle without owning it, we just use a uint32 without this message.
309+
///
310+
/// When refering to a handle without owning it, we just use a uint32 without this message.
310311
/// (the variable name is suffixed with "_handle")
311312
#[allow(clippy::derive_partial_eq_without_eq)]
312313
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -1765,8 +1766,6 @@ pub struct NewVideoSourceRequest {
17651766
/// Most of the time it corresponds to the source resolution
17661767
#[prost(message, required, tag="2")]
17671768
pub resolution: VideoSourceResolution,
1768-
#[prost(bool, optional, tag="3")]
1769-
pub is_screencast: ::core::option::Option<bool>,
17701769
}
17711770
#[allow(clippy::derive_partial_eq_without_eq)]
17721771
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -3455,7 +3454,7 @@ pub struct NewAudioSourceResponse {
34553454
#[prost(message, required, tag="1")]
34563455
pub source: OwnedAudioSource,
34573456
}
3458-
/// Push a frame to an AudioSource
3457+
/// Push a frame to an AudioSource
34593458
/// The data provided must be available as long as the client receive the callback.
34603459
#[allow(clippy::derive_partial_eq_without_eq)]
34613460
#[derive(Clone, PartialEq, ::prost::Message)]
@@ -4009,7 +4008,7 @@ pub struct RpcMethodInvocationEvent {
40094008
// that it receives from the server.
40104009
//
40114010
// Therefore, the ffi client is easier to implement if there is less handles to manage.
4012-
//
4011+
//
40134012
// - We are mainly using FfiHandle on info messages (e.g: RoomInfo, TrackInfo, etc...)
40144013
// For this reason, info are only sent once, at creation (We're not using them for updates, we can infer them from
40154014
// events on the client implementation).

livekit-ffi/src/server/video_source.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ impl FfiVideoSource {
3737
use livekit::webrtc::video_source::native::NativeVideoSource;
3838
let video_source = NativeVideoSource::new(
3939
new_source.resolution.into(),
40-
new_source.is_screencast(),
4140
);
4241
RtcVideoSource::Native(video_source)
4342
}

livekit-protocol/src/enum_dispatch.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 LiveKit, Inc.
1+
// Copyright 2023-2025 LiveKit, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -33,9 +33,23 @@ macro_rules! enum_dispatch {
3333
}
3434
};
3535

36+
// Handle functions without a return type
37+
(@fnc [$($variant:ident),+]: $vis:vis fn $fnc:ident($self:ident: $sty:ty $(, $arg:ident: $t:ty)*)) => {
38+
#[inline]
39+
$vis fn $fnc($self: $sty, $($arg: $t),*) {
40+
enum_dispatch!(@match [$($variant),+]: $fnc, $self, ($($arg,)*))
41+
}
42+
};
43+
3644
($variants:tt; $($vis:vis fn $fnc:ident$args:tt -> $ret:ty;)+) => {
3745
$(
3846
enum_dispatch!(@fnc $variants: $vis fn $fnc$args -> $ret);
3947
)+
4048
};
49+
50+
($variants:tt; $($vis:vis fn $fnc:ident$args:tt;)+) => {
51+
$(
52+
enum_dispatch!(@fnc $variants: $vis fn $fnc$args);
53+
)+
54+
};
4155
}

livekit/src/room/participant/local_participant.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 LiveKit, Inc.
1+
// Copyright 2023-2025 LiveKit, Inc.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -232,6 +232,13 @@ impl LocalParticipant {
232232

233233
encodings = compute_video_encodings(req.width, req.height, &options);
234234
req.layers = video_layers_from_encodings(req.width, req.height, &encodings);
235+
236+
match options.source {
237+
TrackSource::Screenshare => {
238+
video_track.rtc_source().set_is_screencast(true);
239+
}
240+
_ => {}
241+
}
235242
}
236243
LocalTrack::Audio(_audio_track) => {
237244
// Setup audio encoding

webrtc-sys/include/livekit/video_track.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class VideoTrackSource {
9191
* resolution set to (0, 0) means no resolution/optional, the source will
9292
* guess the resolution at the first captured frame.
9393
*/
94-
InternalSource(const VideoResolution& resolution, bool is_screencast);
94+
InternalSource(const VideoResolution& resolution);
9595
~InternalSource() override;
9696

9797
bool is_screencast() const override;
@@ -100,6 +100,7 @@ class VideoTrackSource {
100100
bool remote() const override;
101101
VideoResolution video_resolution() const;
102102
bool on_captured_frame(const webrtc::VideoFrame& frame);
103+
void set_is_screencast(bool is_screencast);
103104

104105
private:
105106
mutable webrtc::Mutex mutex_;
@@ -109,7 +110,7 @@ class VideoTrackSource {
109110
};
110111

111112
public:
112-
VideoTrackSource(const VideoResolution& resolution, bool is_screencast);
113+
VideoTrackSource(const VideoResolution& resolution);
113114

114115
VideoResolution video_resolution() const;
115116

@@ -118,13 +119,14 @@ class VideoTrackSource {
118119

119120
rtc::scoped_refptr<InternalSource> get() const;
120121

122+
void set_is_screencast(bool is_screencast) const;
123+
121124
private:
122125
rtc::scoped_refptr<InternalSource> source_;
123126
};
124127

125128
std::shared_ptr<VideoTrackSource> new_video_track_source(
126-
const VideoResolution& resolution,
127-
bool is_screencast);
129+
const VideoResolution& resolution);
128130

129131
static std::shared_ptr<MediaStreamTrack> video_to_media(
130132
std::shared_ptr<VideoTrack> track) {

0 commit comments

Comments
 (0)