Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hack for setting ExternalImageSource::VideoFrame in wasm video processing #8217

Merged
merged 4 commits into from
Nov 26, 2024
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
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5870,7 +5870,6 @@ dependencies = [
"web-time",
"wgpu",
"wgpu-core",
"wgpu-types",
]

[[package]]
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ wgpu = { version = "23.0", default-features = false, features = [
"fragile-send-sync-non-atomic-wasm",
] }
wgpu-core = "23.0"
wgpu-types = "23.0"
xshell = "0.2"
zip = { version = "0.6", default-features = false } # We're stuck on 0.6 because https://crates.io/crates/protoc-prebuilt is still using 0.6

Expand Down
1 change: 0 additions & 1 deletion crates/viewer/re_renderer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ type-map.workspace = true
web-time.workspace = true
wgpu.workspace = true
wgpu-core.workspace = true # Needed for error handling when wgpu-core implemented backend is used.
wgpu-types.workspace = true

# optional
arrow2 = { workspace = true, optional = true }
Expand Down
39 changes: 7 additions & 32 deletions crates/viewer/re_renderer/src/video/chunk_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,38 +185,13 @@ fn copy_web_video_frame_to_texture(
depth_or_array_layers: 1,
};
let frame: &web_sys::VideoFrame = frame;

let source = {
// TODO(jan): The wgpu version we're using doesn't support `VideoFrame` yet.
// This got fixed in https://github.com/gfx-rs/wgpu/pull/6170 but hasn't shipped yet.
// So instead, we just pretend this is a `HtmlVideoElement` instead.
// SAFETY: Depends on the fact that `wgpu` passes the object through as-is,
// and doesn't actually inspect it in any way. The browser then does its own
// typecheck that doesn't care what kind of image source wgpu gave it.
#[allow(unsafe_code)]
let frame = unsafe {
std::mem::transmute::<web_sys::VideoFrame, web_sys::HtmlVideoElement>(
frame.clone().expect("Failed to clone the video frame"),
)
};
// Fake width & height to work around wgpu validating this as if it was a `HtmlVideoElement`.
// Since it thinks this is a `HtmlVideoElement`, it will want to call `videoWidth` and `videoHeight`
// on it to validate the size.
// We simply redirect `displayWidth`/`displayHeight` to `videoWidth`/`videoHeight` to make it work!
let display_width = js_sys::Reflect::get(&frame, &"displayWidth".into())
.expect("Failed to get displayWidth property from VideoFrame.");
js_sys::Reflect::set(&frame, &"videoWidth".into(), &display_width)
.expect("Failed to set videoWidth property.");
let display_height = js_sys::Reflect::get(&frame, &"displayHeight".into())
.expect("Failed to get displayHeight property from VideoFrame.");
js_sys::Reflect::set(&frame, &"videoHeight".into(), &display_height)
.expect("Failed to set videoHeight property.");

wgpu_types::ImageCopyExternalImage {
source: wgpu_types::ExternalImageSource::HTMLVideoElement(frame),
origin: wgpu_types::Origin2d { x: 0, y: 0 },
flip_y: false,
}
let source = wgpu::ImageCopyExternalImage {
// Careful: `web_sys::VideoFrame` has a custom `clone` method:
// https://developer.mozilla.org/en-US/docs/Web/API/VideoFrame/clone
// We instead just want to clone the js value wrapped in VideoFrame!
source: wgpu::ExternalImageSource::VideoFrame(Clone::clone(frame)),
Wumpf marked this conversation as resolved.
Show resolved Hide resolved
origin: wgpu::Origin2d { x: 0, y: 0 },
flip_y: false,
};
let dest = wgpu::ImageCopyTextureTagged {
texture: &target_texture.texture,
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_renderer/src/video/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum VideoPlayerError {
#[error("The decoder is lagging behind")]
EmptyBuffer,

#[error("Video seems to be empty, no segments have beem found.")]
#[error("Video is empty.")]
EmptyVideo,

/// e.g. unsupported codec
Expand Down
Loading