Auto merge of #27302 - jdm:gst-package-mac, r=Manishearth

Make gstreamer packaging explicit

This change aligns Windows and macOS in terms of loading an explicit set of included plugins when initializing gstreamer. It also creates a single source of truth - the set of expected plugins is generated in a build script by the same python code that is used for packaging, so it should be impossible for platforms relying on this system to get out of sync.

Fixes #27293
This commit is contained in:
bors-servo 2020-07-17 10:51:57 -04:00 committed by GitHub
commit 86e7f9afc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 239 additions and 108 deletions

View file

@ -2,6 +2,11 @@
* 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::env;
use std::fs;
use std::path::Path;
use std::process::Command;
fn main() {
let layout_2013 = std::env::var_os("CARGO_FEATURE_LAYOUT_2013").is_some();
let layout_2020 = std::env::var_os("CARGO_FEATURE_LAYOUT_2020").is_some();
@ -12,9 +17,48 @@ fn main() {
if layout_2013 && layout_2020 {
error("Must not enable both of the `layout-2013` or `layout-2020` features.")
}
println!("cargo:rerun-if-changed=../../python/servo/gstreamer.py");
let output = Command::new(find_python())
.arg("../../python/servo/gstreamer.py")
.arg(std::env::var_os("TARGET").unwrap())
.output()
.unwrap();
if !output.status.success() {
eprintln!("{}", String::from_utf8_lossy(&output.stdout));
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
std::process::exit(1)
}
let path = Path::new(&env::var_os("OUT_DIR").unwrap()).join("gstreamer_plugins.rs");
fs::write(path, output.stdout).unwrap();
}
fn error(message: &str) {
print!("\n\n Error: {}\n\n", message);
std::process::exit(1)
std::process::exit(1);
}
fn find_python() -> String {
env::var("PYTHON2").ok().unwrap_or_else(|| {
let candidates = if cfg!(windows) {
["python2.7.exe", "python27.exe", "python.exe"]
} else {
["python2.7", "python2", "python"]
};
for &name in &candidates {
if Command::new(name)
.arg("--version")
.output()
.ok()
.map_or(false, |out| out.status.success())
{
return name.to_owned();
}
}
panic!(
"Can't find python (tried {})! Try fixing PATH or setting the PYTHON2 env var",
candidates.join(", ")
)
})
}

View file

@ -134,10 +134,15 @@ pub use servo_url as url;
#[cfg(feature = "media-gstreamer")]
mod media_platform {
#[cfg(any(windows, target_os = "macos"))]
mod gstreamer_plugins {
include!(concat!(env!("OUT_DIR"), "/gstreamer_plugins.rs"));
}
use super::ServoMedia;
use servo_media_gstreamer::GStreamerBackend;
#[cfg(target_os = "windows")]
#[cfg(feature = "uwp")]
fn set_gstreamer_log_handler() {
use gstreamer::{debug_add_log_function, debug_remove_default_log_function, DebugLevel};
@ -165,7 +170,7 @@ mod media_platform {
});
}
#[cfg(windows)]
#[cfg(any(windows, target_os = "macos"))]
pub fn init() {
// UWP apps have the working directory set appropriately. Win32 apps
// do not and need some assistance finding the DLLs.
@ -177,66 +182,24 @@ mod media_platform {
plugin_dir
};
let uwp_plugins = [
"gstapp.dll",
"gstaudioconvert.dll",
"gstaudiofx.dll",
"gstaudioparsers.dll",
"gstaudioresample.dll",
"gstautodetect.dll",
"gstcoreelements.dll",
"gstdeinterlace.dll",
"gstinterleave.dll",
"gstisomp4.dll",
"gstlibav.dll",
"gstplayback.dll",
"gstproxy.dll",
"gsttypefindfunctions.dll",
"gstvideoconvert.dll",
"gstvideofilter.dll",
"gstvideoparsersbad.dll",
"gstvideoscale.dll",
"gstvolume.dll",
"gstwasapi.dll",
];
let non_uwp_plugins = [
"gstmatroska.dll",
"gstnice.dll",
"gstogg.dll",
"gstopengl.dll",
"gstopus.dll",
"gstrtp.dll",
"gsttheora.dll",
"gstvorbis.dll",
"gstvpx.dll",
"gstwebrtc.dll",
];
let plugins: Vec<_> = if cfg!(feature = "uwp") {
uwp_plugins.to_vec()
} else {
uwp_plugins
.iter()
.map(|&s| s)
.chain(non_uwp_plugins.iter().map(|&s| s))
.collect()
};
let backend = match GStreamerBackend::init_with_plugins(plugin_dir, &plugins) {
let backend = match GStreamerBackend::init_with_plugins(
plugin_dir,
&gstreamer_plugins::GSTREAMER_PLUGINS,
) {
Ok(b) => b,
Err(e) => {
error!("Error initializing GStreamer: {:?}", e);
panic!()
eprintln!("Error initializing GStreamer: {:?}", e);
std::process::exit(1);
},
};
ServoMedia::init_with_backend(backend);
if cfg!(feature = "uwp") {
#[cfg(feature = "uwp")]
{
set_gstreamer_log_handler();
}
}
#[cfg(not(windows))]
#[cfg(not(any(windows, target_os = "macos")))]
pub fn init() {
ServoMedia::init::<GStreamerBackend>();
}