Skip to content
Permalink
Browse files

Merge GStreamerBackend::init_with_plugins() in the previous implement…

…ation block
  • Loading branch information...
ceyusa committed Jul 10, 2019
1 parent 88c62ed commit 98aee1af7baf0a338903b74b5bff8d9df659fd90
Showing with 33 additions and 32 deletions.
  1. +33 −32 backends/gstreamer/lib.rs
@@ -79,7 +79,40 @@ pub struct GStreamerBackend {
next_muteable_id: AtomicUsize,
}

#[derive(Debug)]
pub struct ErrorLoadingPlugins(Vec<&'static str>);

impl GStreamerBackend {
pub fn init_with_plugins(
plugin_dir: PathBuf,
plugins: &[&'static str],
) -> Result<Box<dyn Backend>, ErrorLoadingPlugins> {
gst::init().unwrap();

let mut errors = vec![];
for plugin in plugins {
let mut path = plugin_dir.clone();
path.push(plugin);
let registry = gst::Registry::get();
if let Ok(p) = gst::Plugin::load_file(&path) {
if registry.add_plugin(&p).is_ok() {
continue;
}
}
errors.push(*plugin);
}

if !errors.is_empty() {
return Err(ErrorLoadingPlugins(errors));
}

Ok(Box::new(GStreamerBackend {
capture_mocking: AtomicBool::new(false),
muteables: Mutex::new(HashMap::new()),
next_muteable_id: AtomicUsize::new(0),
}))
}

fn remove_muteable(&self, id: &ClientContextId, muteable_id: usize) {
let mut muteables = self.muteables.lock().unwrap();
if let Some(vec) = muteables.get_mut(&id) {
@@ -259,44 +292,12 @@ impl WebRtcBackend for GStreamerBackend {
}
}

#[derive(Debug)]
pub struct ErrorLoadingPlugins(Vec<&'static str>);

impl BackendInit for GStreamerBackend {
fn init() -> Box<dyn Backend> {
Self::init_with_plugins(PathBuf::new(), &[]).unwrap()
}
}

impl GStreamerBackend {
pub fn init_with_plugins(plugin_dir: PathBuf, plugins: &[&'static str]) -> Result<Box<dyn Backend>, ErrorLoadingPlugins> {
gst::init().unwrap();

let mut errors = vec![];
for plugin in plugins {
let mut path = plugin_dir.clone();
path.push(plugin);
let registry = gst::Registry::get();
if let Ok(p) = gst::Plugin::load_file(&path) {
if registry.add_plugin(&p).is_ok() {
continue;
}
}
errors.push(*plugin);
}

if !errors.is_empty() {
return Err(ErrorLoadingPlugins(errors));
}

Ok(Box::new(GStreamerBackend {
capture_mocking: AtomicBool::new(false),
muteables: Mutex::new(HashMap::new()),
next_muteable_id: AtomicUsize::new(0),
}))
}
}

pub fn set_element_flags<T: glib::IsA<gst::Object> + glib::IsA<gst::Element>>(
element: &T,
flags: gst::ElementFlags,

0 comments on commit 98aee1a

Please sign in to comment.
You can’t perform that action at this time.