Skip to content
Merged
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
2 changes: 1 addition & 1 deletion examples/local_video/src/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ async fn run(args: Args, ctrl_c_received: Arc<AtomicBool>) -> Result<()> {
let pace_fps = args.fps as f64;

// Create LiveKit video source and track
let rtc_source = NativeVideoSource::new(VideoResolution { width, height });
let rtc_source = NativeVideoSource::new(VideoResolution { width, height }, false);
let track =
LocalVideoTrack::create_video_track("camera", RtcVideoSource::Native(rtc_source.clone()));

Expand Down
2 changes: 1 addition & 1 deletion examples/screensharing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ mod test {
let resolution = wait_for_resolution(&resolution_signal);
log::info!("Detected capture resolution: {}x{}", resolution.width, resolution.height);

let buffer_source = NativeVideoSource::new(resolution.clone());
let buffer_source = NativeVideoSource::new(resolution.clone(), true);
{
let mut slot = video_source_slot.lock().unwrap();
*slot = Some(buffer_source.clone());
Expand Down
8 changes: 4 additions & 4 deletions examples/wgpu_room/src/logo_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ pub struct LogoTrack {
impl LogoTrack {
pub fn new(room: Arc<Room>) -> Self {
Self {
rtc_source: NativeVideoSource::new(VideoResolution {
width: FB_WIDTH as u32,
height: FB_HEIGHT as u32,
}),
rtc_source: NativeVideoSource::new(
VideoResolution { width: FB_WIDTH as u32, height: FB_HEIGHT as u32 },
false,
),
room,
handle: None,
}
Expand Down
9 changes: 5 additions & 4 deletions libwebrtc/src/native/video_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ struct VideoSourceInner {
}

impl NativeVideoSource {
pub fn new(resolution: VideoResolution) -> NativeVideoSource {
pub fn new(resolution: VideoResolution, is_screencast: bool) -> NativeVideoSource {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a mode param for future proofing? if there are other presets that we'd want to define. maybe:

  • camera
  • avatar
  • screencast

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's closely tied to libwebrtc, so it's very unlikely.

But maybe this should be an option inside our TrackPublishOptions API

let source = Self {
sys_handle: vt_sys::ffi::new_video_track_source(&vt_sys::ffi::VideoResolution::from(
resolution.clone(),
)),
sys_handle: vt_sys::ffi::new_video_track_source(
&vt_sys::ffi::VideoResolution::from(resolution.clone()),
is_screencast,
),
inner: Arc::new(Mutex::new(VideoSourceInner { captured_frames: 0 })),
};

Expand Down
6 changes: 3 additions & 3 deletions libwebrtc/src/video_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ pub mod native {

impl Default for NativeVideoSource {
fn default() -> Self {
Self::new(VideoResolution::default())
Self::new(VideoResolution::default(), false)
}
}

impl NativeVideoSource {
pub fn new(resolution: VideoResolution) -> Self {
Self { handle: vs_imp::NativeVideoSource::new(resolution) }
pub fn new(resolution: VideoResolution, is_screencast: bool) -> Self {
Self { handle: vs_imp::NativeVideoSource::new(resolution, is_screencast) }
}

pub fn capture_frame<T: AsRef<dyn VideoBuffer>>(&self, frame: &VideoFrame<T>) {
Expand Down
8 changes: 7 additions & 1 deletion livekit-ffi-node-bindings/src/proto/video_frame_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,17 @@ export class NewVideoSourceRequest extends Message<NewVideoSourceRequest> {

/**
* Used to determine which encodings to use + simulcast layers
* Most of the time it corresponds to the source resolution
* Most of the time it corresponds to the source resolution
*
* @generated from field: required livekit.proto.VideoSourceResolution resolution = 2;
*/
resolution?: VideoSourceResolution;

/**
* @generated from field: optional bool is_screencast = 3;
*/
isScreencast?: boolean;

constructor(data?: PartialMessage<NewVideoSourceRequest>) {
super();
proto2.util.initPartial(data, this);
Expand All @@ -438,6 +443,7 @@ export class NewVideoSourceRequest extends Message<NewVideoSourceRequest> {
static readonly fields: FieldList = proto2.util.newFieldList(() => [
{ no: 1, name: "type", kind: "enum", T: proto2.getEnumType(VideoSourceType), req: true },
{ no: 2, name: "resolution", kind: "message", T: VideoSourceResolution, req: true },
{ no: 3, name: "is_screencast", kind: "scalar", T: 8 /* ScalarType.BOOL */, opt: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): NewVideoSourceRequest {
Expand Down
7 changes: 4 additions & 3 deletions livekit-ffi/protocol/video_frame.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ message VideoStreamFromParticipantResponse { required OwnedVideoStream stream =

// Create a new VideoSource
// VideoSource is used to send video frame to a track
message NewVideoSourceRequest {
required VideoSourceType type = 1;
message NewVideoSourceRequest {
required VideoSourceType type = 1;
// Used to determine which encodings to use + simulcast layers
// Most of the time it corresponds to the source resolution
// Most of the time it corresponds to the source resolution
required VideoSourceResolution resolution = 2;
optional bool is_screencast = 3;
}
message NewVideoSourceResponse { required OwnedVideoSource source = 1; }

Expand Down
4 changes: 3 additions & 1 deletion livekit-ffi/src/server/video_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ impl FfiVideoSource {
proto::VideoSourceType::VideoSourceNative => {
use livekit::webrtc::video_source::native::NativeVideoSource;

let video_source = NativeVideoSource::new(new_source.resolution.into());
let is_screencast = new_source.is_screencast.unwrap_or(false);
let video_source =
NativeVideoSource::new(new_source.resolution.into(), is_screencast);
RtcVideoSource::Native(video_source)
}
_ => return Err(FfiError::InvalidRequest("unsupported video source type".into())),
Expand Down
13 changes: 7 additions & 6 deletions webrtc-sys/include/livekit/video_track.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ std::shared_ptr<NativeVideoSink> new_native_video_sink(
class VideoTrackSource {
class InternalSource : public webrtc::AdaptedVideoTrackSource {
public:
InternalSource(const VideoResolution&
resolution); // (0, 0) means no resolution/optional, the
// source will guess the resolution at the
// first captured frame
InternalSource(const VideoResolution& resolution,
bool is_screencast); // (0, 0) means no resolution/optional, the
// source will guess the resolution at the
// first captured frame
~InternalSource() override;

bool is_screencast() const override;
Expand All @@ -104,10 +104,11 @@ class VideoTrackSource {
mutable webrtc::Mutex mutex_;
webrtc::TimestampAligner timestamp_aligner_;
VideoResolution resolution_;
bool is_screencast_;
};

public:
VideoTrackSource(const VideoResolution& resolution);
VideoTrackSource(const VideoResolution& resolution, bool is_screencast);

VideoResolution video_resolution() const;

Expand All @@ -121,7 +122,7 @@ class VideoTrackSource {
};

std::shared_ptr<VideoTrackSource> new_video_track_source(
const VideoResolution& resolution);
const VideoResolution& resolution, bool is_screencast);

static std::shared_ptr<MediaStreamTrack> video_to_media(
std::shared_ptr<VideoTrack> track) {
Expand Down
14 changes: 7 additions & 7 deletions webrtc-sys/src/video_track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ std::shared_ptr<NativeVideoSink> new_native_video_sink(
}

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

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

bool VideoTrackSource::InternalSource::is_screencast() const {
return false;
return is_screencast_;
}

std::optional<bool> VideoTrackSource::InternalSource::needs_denoising() const {
Expand Down Expand Up @@ -175,8 +175,8 @@ bool VideoTrackSource::InternalSource::on_captured_frame(
return true;
}

VideoTrackSource::VideoTrackSource(const VideoResolution& resolution) {
source_ = webrtc::make_ref_counted<InternalSource>(resolution);
VideoTrackSource::VideoTrackSource(const VideoResolution& resolution, bool is_screencast) {
source_ = webrtc::make_ref_counted<InternalSource>(resolution, is_screencast);
}

VideoResolution VideoTrackSource::video_resolution() const {
Expand All @@ -195,8 +195,8 @@ webrtc::scoped_refptr<VideoTrackSource::InternalSource> VideoTrackSource::get()
}

std::shared_ptr<VideoTrackSource> new_video_track_source(
const VideoResolution& resolution) {
return std::make_shared<VideoTrackSource>(resolution);
const VideoResolution& resolution, bool is_screencast) {
return std::make_shared<VideoTrackSource>(resolution, is_screencast);
}

} // namespace livekit_ffi
5 changes: 4 additions & 1 deletion webrtc-sys/src/video_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ pub mod ffi {

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