Skip to content

Commit

Permalink
Run a glib loop for the GStreamer backend
Browse files Browse the repository at this point in the history
This is a workaround for an issue where GStreamer does not deliver end
of stream signals unless there is a main loop running. See [1] for
more information.

1. #393 (comment)
  • Loading branch information
mrobinson committed Nov 17, 2023
1 parent 97515f6 commit 1b99e4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backends/gstreamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ipc-channel = { workspace = true }
lazy_static = "1.2.0"
log = "0.4"
mime = "0.3.13"
once_cell = "1.18.0"
servo-media = { path = "../../servo-media" }
servo-media-audio = { path = "../../audio" }
servo-media-gstreamer-render = { path = "render" }
Expand Down
9 changes: 9 additions & 0 deletions backends/gstreamer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use gst::ClockExt;
use ipc_channel::ipc::IpcSender;
use media_stream::GStreamerMediaStream;
use mime::Mime;
use once_cell::sync::OnceCell;
use registry_scanner::GSTREAMER_REGISTRY_SCANNER;
use servo_media::{Backend, BackendInit, SupportsMediaType};
use servo_media_audio::context::{AudioContext, AudioContextOptions};
Expand Down Expand Up @@ -78,6 +79,8 @@ lazy_static! {
static ref BACKEND_BASE_TIME: gst::ClockTime = gst::SystemClock::obtain().get_time();
}

static BACKEND_THREAD: OnceCell<bool> = OnceCell::new();

pub struct GStreamerBackend {
capture_mocking: AtomicBool,
instances: Arc<Mutex<HashMap<ClientContextId, Vec<(usize, Weak<Mutex<dyn MediaInstance>>)>>>>,
Expand All @@ -94,6 +97,12 @@ impl GStreamerBackend {
plugin_dir: PathBuf,
plugins: &[&'static str],
) -> Result<Box<dyn Backend>, ErrorLoadingPlugins> {

BACKEND_THREAD.get_or_init(|| {
thread::spawn(|| glib::MainLoop::new(None, false).run());
true
});

gst::init().unwrap();

let mut errors = vec![];
Expand Down

0 comments on commit 1b99e4c

Please sign in to comment.