Remove the servo-gst-plugin (#30976)

The CI doesn't build this by default and it's currently unused. It is
one thing that's currently making it a bit trickier to allow for
non-mach builds of Servo.
This commit is contained in:
Martin Robinson 2024-01-02 16:23:12 +01:00 committed by GitHub
parent 5b0c03801a
commit bbadef3365
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 0 additions and 1531 deletions

34
Cargo.lock generated
View file

@ -2255,16 +2255,6 @@ dependencies = [
"bitflags 2.4.1",
]
[[package]]
name = "gst-plugin-version-helper"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc81ae3a09f23761eb3b122f50e5daedea4b44fdf8242ec133bc87aa8e24f9b8"
dependencies = [
"chrono",
"toml",
]
[[package]]
name = "gstreamer"
version = "0.15.7"
@ -5156,30 +5146,6 @@ dependencies = [
"time-point",
]
[[package]]
name = "servo-gst-plugin"
version = "0.0.1"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-channel",
"euclid",
"glib",
"gst-plugin-version-helper",
"gstreamer",
"gstreamer-base",
"gstreamer-gl",
"gstreamer-gl-sys",
"gstreamer-sys",
"gstreamer-video",
"lazy_static",
"libservo",
"log",
"servo-media",
"sparkle",
"surfman",
"webxr",
]
[[package]]
name = "servo-media"
version = "0.1.0"

View file

@ -2,7 +2,6 @@
resolver = "2"
members = [
"ports/servoshell",
"ports/gstplugin",
"ports/libsimpleservo/capi/",
"ports/libsimpleservo/jniapi/",
"tests/unit/*",

View file

@ -1,37 +0,0 @@
[package]
name = "servo-gst-plugin"
description = "A GStreamer plugin that provides servosrc"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
build = "build.rs"
repository = "https://github.com/servo/servo/"
publish = false
[lib]
name = "gstservoplugin"
crate-type = ["cdylib"]
path = "lib.rs"
[dependencies]
cfg-if = { workspace = true }
crossbeam-channel = { workspace = true }
euclid = { workspace = true }
glib = "0.9"
gstreamer = "0.15"
gstreamer-base = "0.15"
gstreamer-gl = "0.15"
gstreamer-gl-sys = { version = "0.8", features = ["wayland"] }
gstreamer-sys = "0.8"
gstreamer-video = "0.15"
lazy_static = { workspace = true }
libservo = { path = "../../components/servo" }
log = { workspace = true }
servo-media = { git = "https://github.com/servo/media" }
sparkle = { workspace = true }
surfman = { workspace = true }
webxr = { git = "https://github.com/servo/webxr", features = ["glwindow"] }
[build-dependencies]
gst-plugin-version-helper = "0.2"

View file

@ -1,193 +0,0 @@
# A GStreamer plugin which runs servo
## Supported platforms
* MacOS + CGL
* Linux + Wayland
## Build
```
./mach build -r -p servo-gst-plugin
```
## Install
By default, gstreamer's plugin finder will complain about any libraries it finds that aren't
gstreamer plugins, so we need to have a directory just for plugins:
```
mkdir target/gstplugins
```
To install:
```
cp target/release/libgstservoplugin.* target/gstplugins
```
## Run
To run locally:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 -e servowebsrc \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=1920,height=1080,format=RGBA \
! glimagesink rotate-method=vertical-flip
```
To stream over the network:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 -e servowebsrc \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=512,height=256 \
! glvideoflip video-direction=vert \
! glcolorconvert \
! gldownload \
! theoraenc \
! oggmux \
! tcpserversink host=127.0.0.1 port=8080
```
To stream to youtube live, first go to youtube studio and create a new live stream, with its token, then:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 -e servowebsrc \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=1960,height=1080 \
! glvideoflip video-direction=vert \
! glcolorconvert \
! gldownload \
! x264enc bitrate=6000 \
! flvmux name=mux \
! rtmpsink location="rtmp://a.rtmp.youtube.com/live2/x/$TOKEN" \
audiotestsrc wave=silence \
! voaacenc bitrate=128000 \
! mux.
```
To save to a file:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 -e servowebsrc \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=512,height=256 \
! glvideoflip video-direction=vert \
! glcolorconvert \
! gldownload \
! theoraenc \
! oggmux \
! filesink location=test.ogg
```
To stream webxr content and save to a file:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 -e servowebsrc url=... webxr=left-right \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=512,height=512,format=RGBA \
! glvideoflip video-direction=vert \
! glcolorconvert \
! gldownload \
! queue \
! x264enc \
! mp4mux \
! filesink location=test.mp4
```
This requires the webxr content to support the `sessionavailable` event for launching directly into immersive mode.
Values for `webxr` include `none`, `left-right`, `red-cyan`, `cubemap` and `spherical`.
To stream a Hubs room to twitch (there'll be ~30s black at the beginning while Hubs starts up):
```
GST_PLUGIN_PATH=$PWD/target/gstplugins \
gst-launch-1.0 -e servowebsrc \
url="https://hubs.mozilla.com/$ROOM?no_force_webvr&vr_entry_type=vr_now" \
webxr=red-cyan \
prefs='{"dom.gamepad.enabled":true, "dom.svg.enabled":true, "dom.canvas_capture.enabled": true, "dom.canvas_capture.enabled":true, "dom.webrtc.enabled":true, "dom.webrtc.transceiver.enabled":true}' \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=1920,height=1080,format=RGBA \
! glvideoflip video-direction=vert \
! glcolorconvert \
! gldownload \
! queue \
! x264enc bitrate=4500 \
! video/x-h264, profile=high \
! flvmux streamable=true \
! rtmpsink location="rtmp://$ENDPOINT.twitch.tv/app/$STREAM_KEY"
```
*Note*: killing the gstreamer pipeline with control-C sometimes locks up macOS to the point
of needing a power cycle. Killing the pipeline by closing the window seems to work.
## Troubleshooting building the plugin
You may need to make sure rust picks up the right gstreamer, for example:
```
PKG_CONFIG_PATH=$PWD/support/linux/gstreamer/gst/lib \
LD_LIBRARY_PATH=$PWD/support/linux/gstreamer/gst/lib \
./mach build -r -p servo-gst-plugin
```
## Troubleshooting running the plugin
First try:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-inspect-1.0 servowebsrc
```
If that doesn't work, try:
```
GST_PLUGIN_PATH=target/gstplugins \
gst-inspect-1.0 target/gstplugins/libgstservoplugin.so
```
If you get reports about the plugin being blacklisted, remove the (global!) gstreamer cache, e.g. under Linux:
```
rm -r ~/.cache/gstreamer-1.0
```
If you get complaints about not being able to find libraries, set `LD_LIBRARY_PATH`, e.g. to use Servo's Linux gstreamer:
```
LD_LIBRARY_PATH=$PWD/support/linux/gstreamer/gst/lib
```
If you get complaints `cannot allocate memory in static TLS block` this is caused by gstreamer initializing threads using
the system alloc, which causes problems if those threads run Rust code that uses jemalloc. The fix is to preload the plugin:
```
LD_PRELOAD=$PWD/target/gstplugins/libgstservoplugin.so
```
You may need to set `GST_PLUGIN_SCANNER`, e.g. to use Servo's:
```
GST_PLUGIN_SCANNER=$PWD/support/linux/gstreamer/gst/libexec/gstreamer-1.0/gst-plugin-scanner
```
You may need to include other directories on the plugin search path, e.g. Servo's gstreamer:
```
GST_PLUGIN_PATH=$PWD/target/gstplugins/:$PWD/support/linux/gstreamer/gst/lib
```
If you get complaints `could not get/set settings from/on resource.` right after finding a GL context then try `tee`-ing to `glimagesink` and `gldownload`:
```
LD_PRELOAD=$PWD/target/gstplugins/libgstservoplugin.so \
GST_PLUGIN_PATH=target/gstplugins \
gst-launch-1.0 servowebsrc \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=512,height=256 \
! tee name=t \
t. ! queue ! glimagesink
t. ! queue ! glcolorconvert ! gldownload ! theoraenc ! oggmux ! filesink location=test.ogg
```
Under X11 you may get complaints about X11 threads not being initialized:
```
GST_GL_XINITTHREADS=1
```
Under x11 you may get a frozen display from `autovideosink`, try `ximagesink` instead.
Putting that all together:
```
GST_GL_XINITTHREADS=1 \
GST_PLUGIN_PATH=$PWD/target/gstplugins/:$PWD/support/linux/gstreamer/gst/lib \
GST_PLUGIN_SCANNER=$PWD/support/linux/gstreamer/gst/libexec/gstreamer-1.0/gst-plugin-scanner \
LD_LIBRARY_PATH=$PWD/support/linux/gstreamer/gst/lib \
LD_PRELOAD=$PWD/target/gstplugins/libgstservoplugin.so \
gst-launch-1.0 servowebsrc \
! videoflip video-direction=vert \
! ximagesink
```

View file

@ -1,25 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::error::Error;
use std::path::Path;
fn main() -> Result<(), Box<dyn Error>> {
// Cargo does not expose the profile name to crates or their build scripts,
// but we can extract it from OUT_DIR and set a custom cfg() ourselves.
let out = std::env::var("OUT_DIR")?;
let out = Path::new(&out);
let krate = out.parent().unwrap();
let build = krate.parent().unwrap();
let profile = build.parent().unwrap();
if profile.file_name().unwrap() == "production" {
println!("cargo:rustc-cfg=servo_production");
} else {
println!("cargo:rustc-cfg=servo_do_not_use_in_production");
}
gst_plugin_version_helper::get_info();
Ok(())
}

View file

@ -1,40 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use glib::subclass::types::ObjectSubclass;
use gstreamer::gst_plugin_define;
use servowebsrc::ServoWebSrc;
mod logging;
mod resources;
mod servowebsrc;
gst_plugin_define!(
servoplugin,
env!("CARGO_PKG_DESCRIPTION"),
plugin_init,
concat!(env!("CARGO_PKG_VERSION"), "-", env!("COMMIT_ID")),
"MPL",
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_NAME"),
env!("CARGO_PKG_REPOSITORY"),
env!("BUILD_REL_DATE")
);
fn plugin_init(plugin: &gstreamer::Plugin) -> Result<(), glib::BoolError> {
gstreamer::gst_debug!(logging::CATEGORY, "Initializing logging");
log::set_logger(&logging::LOGGER).expect("Failed to set logger");
log::set_max_level(log::LevelFilter::Debug);
log::debug!("Initializing resources");
resources::init();
log::debug!("Registering plugin");
gstreamer::Element::register(
Some(plugin),
"servowebsrc",
gstreamer::Rank::None,
ServoWebSrc::get_type(),
)
}

View file

@ -1,41 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use gstreamer::{DebugCategory, DebugColorFlags, DebugLevel};
use lazy_static::lazy_static;
lazy_static! {
pub static ref CATEGORY: DebugCategory =
DebugCategory::new("servowebsrc", DebugColorFlags::empty(), Some("Servo"));
}
pub static LOGGER: ServoSrcLogger = ServoSrcLogger;
pub struct ServoSrcLogger;
impl log::Log for ServoSrcLogger {
fn enabled(&self, _metadata: &log::Metadata) -> bool {
true
}
fn log(&self, record: &log::Record) {
let lvl = match record.level() {
log::Level::Error => DebugLevel::Error,
log::Level::Warn => DebugLevel::Warning,
log::Level::Info => DebugLevel::Info,
log::Level::Debug => DebugLevel::Debug,
log::Level::Trace => DebugLevel::Trace,
};
CATEGORY.log::<gstreamer::Object>(
None,
lvl,
record.file().unwrap_or(""),
record.module_path().unwrap_or(""),
record.line().unwrap_or(0),
record.args().clone(),
);
}
fn flush(&self) {}
}

View file

@ -1,94 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
// This is a copy of the resource loader from the winit port
// TODO: move this to somewhere where it can be shared.
// https://github.com/servo/servo/issues/24853
use std::path::PathBuf;
use std::sync::Mutex;
use std::{env, fs};
use cfg_if::cfg_if;
use servo::embedder_traits::resources::{self, Resource};
lazy_static::lazy_static! {
static ref CMD_RESOURCE_DIR: Mutex<Option<PathBuf>> = Mutex::new(None);
}
struct ResourceReader;
pub fn init() {
resources::set(Box::new(ResourceReader));
}
fn resources_dir_path() -> PathBuf {
// This needs to be called before the process is sandboxed
// as we only give permission to read inside the resources directory,
// not the permissions the "search" for the resources directory.
let mut dir = CMD_RESOURCE_DIR.lock().unwrap();
if let Some(ref path) = *dir {
return PathBuf::from(path);
}
// Try ./resources and ./Resources relative to the directory containing the
// canonicalised executable path, then each of its ancestors.
let mut path = env::current_exe().unwrap().canonicalize().unwrap();
while path.pop() {
path.push("resources");
if path.is_dir() {
*dir = Some(path);
return dir.clone().unwrap();
}
path.pop();
// Check for Resources on mac when using a case sensitive filesystem.
path.push("Resources");
if path.is_dir() {
*dir = Some(path);
return dir.clone().unwrap();
}
path.pop();
}
cfg_if! {
if #[cfg(servo_production)] {
panic!("Can't find resources directory")
} else {
// Static assert that this is really a non-production build, rather
// than a failure of the build scripts production check.
const _: () = assert!(cfg!(servo_do_not_use_in_production));
// Try ./resources in the current directory, then each of its ancestors.
// Not to be used in production builds without considering the security implications!
let mut path = std::env::current_dir().unwrap();
loop {
path.push("resources");
if path.is_dir() {
*dir = Some(path);
return dir.clone().unwrap();
}
path.pop();
if !path.pop() {
panic!("Can't find resources directory")
}
}
}
}
}
impl resources::ResourceReaderMethods for ResourceReader {
fn read(&self, file: Resource) -> Vec<u8> {
let mut path = resources_dir_path();
path.push(file.filename());
fs::read(path).expect("Can't read file")
}
fn sandbox_access_files_dirs(&self) -> Vec<PathBuf> {
vec![resources_dir_path()]
}
fn sandbox_access_files(&self) -> Vec<PathBuf> {
vec![]
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,17 +0,0 @@
<video controls>
<source src="http://localhost:8080/" type="video/ogg">
</video>
<p>Start the video stream with:</p>
<pre>
gst-launch-1.0 servosrc url=https://mrdoob.neocities.org/018/ \
! videorate \
! video/x-raw\(memory:GLMemory\),framerate=50/1,width=512,height=256 \
! glcolorconvert \
! gldownload \
! videoflip video-direction=vert \
! theoraenc \
! oggmux \
! tcpserversink host=127.0.0.1 port=8080
</pre>