-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathvideo_source.rs
More file actions
79 lines (70 loc) · 2.83 KB
/
Copy pathvideo_source.rs
File metadata and controls
79 lines (70 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2025 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::{colorcvt, FfiHandle};
use crate::{proto, server, FfiError, FfiHandleId, FfiResult};
use livekit::webrtc::{prelude::*, video_frame::VideoFrame};
pub struct FfiVideoSource {
pub handle_id: FfiHandleId,
pub source_type: proto::VideoSourceType,
pub source: RtcVideoSource,
}
impl FfiHandle for FfiVideoSource {}
impl FfiVideoSource {
pub fn setup(
server: &'static server::FfiServer,
new_source: proto::NewVideoSourceRequest,
) -> FfiResult<proto::OwnedVideoSource> {
let source_type = new_source.r#type();
#[allow(unreachable_patterns)]
let source_inner = match source_type {
#[cfg(not(target_arch = "wasm32"))]
proto::VideoSourceType::VideoSourceNative => {
use livekit::webrtc::video_source::native::NativeVideoSource;
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())),
};
let handle_id = server.next_id();
let video_source = Self { handle_id, source_type, source: source_inner };
let source_info = proto::VideoSourceInfo::from(&video_source);
server.store_handle(handle_id, video_source);
Ok(proto::OwnedVideoSource {
handle: proto::FfiOwnedHandle { id: handle_id },
info: source_info,
})
}
pub unsafe fn capture_frame(
&self,
_server: &'static server::FfiServer,
capture: proto::CaptureVideoFrameRequest,
) -> FfiResult<()> {
match self.source {
#[cfg(not(target_arch = "wasm32"))]
RtcVideoSource::Native(ref source) => {
let buffer = colorcvt::to_libwebrtc_buffer(capture.buffer.clone());
let frame = VideoFrame {
rotation: capture.rotation().into(),
timestamp_us: capture.timestamp_us,
buffer,
};
source.capture_frame(&frame);
}
_ => {}
}
Ok(())
}
}