Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libwebrtc/src/native/video_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,8 @@ impl NativeVideoSource {
pub fn video_resolution(&self) -> VideoResolution {
self.sys_handle.video_resolution().into()
}

pub fn set_is_screencast(&self, is_screencast: bool) {
self.sys_handle.set_is_screencast(is_screencast);
}
}
8 changes: 8 additions & 0 deletions libwebrtc/src/video_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ impl RtcVideoSource {
[Native];
pub fn video_resolution(self: &Self) -> VideoResolution;
);
enum_dispatch!(
[Native];
pub fn set_is_screencast(self: &Self, is_screencast: bool);
);
}

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -81,6 +85,10 @@ pub mod native {
pub fn video_resolution(&self) -> VideoResolution {
self.handle.video_resolution()
}

pub fn set_is_screencast(&self, is_screencast: bool) {
self.handle.set_is_screencast(is_screencast);
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions livekit-protocol/src/enum_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,23 @@ macro_rules! enum_dispatch {
}
};

// Handle functions without a return type
(@fnc [$($variant:ident),+]: $vis:vis fn $fnc:ident($self:ident: $sty:ty $(, $arg:ident: $t:ty)*)) => {
#[inline]
$vis fn $fnc($self: $sty, $($arg: $t),*) {
enum_dispatch!(@match [$($variant),+]: $fnc, $self, ($($arg,)*))
}
};

($variants:tt; $($vis:vis fn $fnc:ident$args:tt -> $ret:ty;)+) => {
$(
enum_dispatch!(@fnc $variants: $vis fn $fnc$args -> $ret);
)+
};

($variants:tt; $($vis:vis fn $fnc:ident$args:tt;)+) => {
$(
enum_dispatch!(@fnc $variants: $vis fn $fnc$args);
)+
};
}
7 changes: 7 additions & 0 deletions livekit/src/room/participant/local_participant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ impl LocalParticipant {

encodings = compute_video_encodings(req.width, req.height, &options);
req.layers = video_layers_from_encodings(req.width, req.height, &encodings);

match options.source {
TrackSource::Screenshare => {
video_track.rtc_source().set_is_screencast(true);
}
_ => {}
}
}
LocalTrack::Audio(_audio_track) => {
// Setup audio encoding
Expand Down
4 changes: 4 additions & 0 deletions webrtc-sys/include/livekit/video_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ class VideoTrackSource {
bool remote() const override;
VideoResolution video_resolution() const;
bool on_captured_frame(const webrtc::VideoFrame& frame);
void set_is_screencast(bool is_screencast);

private:
mutable webrtc::Mutex mutex_;
webrtc::TimestampAligner timestamp_aligner_;
VideoResolution resolution_;
bool is_screencast_;
};

public:
Expand All @@ -116,6 +118,8 @@ class VideoTrackSource {

webrtc::scoped_refptr<InternalSource> get() const;

void set_is_screencast(bool is_screencast) const;

private:
webrtc::scoped_refptr<InternalSource> source_;
};
Expand Down
23 changes: 18 additions & 5 deletions webrtc-sys/src/video_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ VideoTrack::~VideoTrack() {

void VideoTrack::add_sink(const std::shared_ptr<NativeVideoSink>& sink) const {
webrtc::MutexLock lock(&mutex_);
track()->AddOrUpdateSink(sink.get(),
webrtc::VideoSinkWants()); // TODO(theomonnom): Expose
// VideoSinkWants to Rust?
track()->AddOrUpdateSink(
sink.get(),
webrtc::VideoSinkWants()); // TODO(theomonnom): Expose
// VideoSinkWants to Rust?
sinks_.push_back(sink);
}

Expand Down Expand Up @@ -106,12 +107,20 @@ std::shared_ptr<NativeVideoSink> new_native_video_sink(

VideoTrackSource::InternalSource::InternalSource(
const VideoResolution& resolution)
: webrtc::AdaptedVideoTrackSource(4), resolution_(resolution) {}
: webrtc::AdaptedVideoTrackSource(4),
resolution_(resolution),
is_screencast_(false) {}

VideoTrackSource::InternalSource::~InternalSource() {}

bool VideoTrackSource::InternalSource::is_screencast() const {
return false;
webrtc::MutexLock lock(&mutex_);
return is_screencast_;
}

void VideoTrackSource::InternalSource::set_is_screencast(bool is_screencast) {
webrtc::MutexLock lock(&mutex_);
is_screencast_ = is_screencast;
}

std::optional<bool> VideoTrackSource::InternalSource::needs_denoising() const {
Expand Down Expand Up @@ -189,6 +198,10 @@ bool VideoTrackSource::on_captured_frame(
return source_->on_captured_frame(rtc_frame);
}

void VideoTrackSource::set_is_screencast(bool is_screencast) const {
source_->set_is_screencast(is_screencast);
}

webrtc::scoped_refptr<VideoTrackSource::InternalSource> VideoTrackSource::get()
const {
return source_;
Expand Down
1 change: 1 addition & 0 deletions webrtc-sys/src/video_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod ffi {

fn video_resolution(self: &VideoTrackSource) -> VideoResolution;
fn on_captured_frame(self: &VideoTrackSource, frame: &UniquePtr<VideoFrame>) -> bool;
fn set_is_screencast(self: &VideoTrackSource, is_screencast: bool);
fn new_video_track_source(resolution: &VideoResolution) -> SharedPtr<VideoTrackSource>;
fn video_to_media(track: SharedPtr<VideoTrack>) -> SharedPtr<MediaStreamTrack>;
unsafe fn media_to_video(track: SharedPtr<MediaStreamTrack>) -> SharedPtr<VideoTrack>;
Expand Down
Loading