From 644661e38dfb86d6c911fa4847e5471b80bf4c4f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 7 Oct 2024 13:14:30 -0600 Subject: [PATCH] Disable subtitles for now, as they can cause video stream hangs. Add bindings for fullscreen --- src/gstreamer/mod.rs | 30 +++++++++++++++++++++++++++++- src/key_bind.rs | 2 ++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/gstreamer/mod.rs b/src/gstreamer/mod.rs index 31ef858..a97242b 100644 --- a/src/gstreamer/mod.rs +++ b/src/gstreamer/mod.rs @@ -34,6 +34,10 @@ use crate::{ static CONTROLS_TIMEOUT: Duration = Duration::new(2, 0); +const GST_PLAY_FLAG_VIDEO: i32 = 1 << 0; +const GST_PLAY_FLAG_AUDIO: i32 = 1 << 1; +const GST_PLAY_FLAG_TEXT: i32 = 1 << 2; + /// Runs application with these settings #[rustfmt::skip] pub fn main() -> Result<(), Box> { @@ -78,6 +82,7 @@ pub fn main() -> Result<(), Box> { #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum Action { + Fullscreen, PlayPause, SeekBackward, SeekForward, @@ -86,6 +91,7 @@ pub enum Action { impl Action { pub fn message(&self) -> Message { match self { + Self::Fullscreen => Message::Fullscreen, Self::PlayPause => Message::PlayPause, Self::SeekBackward => Message::SeekRelative(-10.0), Self::SeekForward => Message::SeekRelative(10.0), @@ -195,7 +201,29 @@ impl App { self.current_text = pipeline.property::("current-text"); //TODO: Flags can be used to enable/disable subtitles - println!("flags {:?}", pipeline.property_value("flags")); + let flags_value = pipeline.property_value("flags"); + println!("original flags {:?}", flags_value); + match flags_value.transform::() { + Ok(flags_transform) => match flags_transform.get::() { + Ok(mut flags) => { + flags |= GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_AUDIO; + flags &= !GST_PLAY_FLAG_TEXT; + match gst::glib::Value::from(flags).transform_with_type(flags_value.type_()) { + Ok(value) => pipeline.set_property("flags", value), + Err(err) => { + log::warn!("failed to transform int to flags: {err}"); + } + } + } + Err(err) => { + log::warn!("failed to get flags as int: {err}"); + } + }, + Err(err) => { + log::warn!("failed to transform flags to int: {err}"); + } + } + println!("updated flags {:?}", pipeline.property_value("flags")); self.update_title() } diff --git a/src/key_bind.rs b/src/key_bind.rs index f664004..588a0e7 100644 --- a/src/key_bind.rs +++ b/src/key_bind.rs @@ -61,6 +61,8 @@ pub fn key_binds() -> HashMap { } //TODO: key bindings + bind!([], Key::Character("f".into()), Fullscreen); + bind!([Alt], Key::Named(Named::Enter), Fullscreen); bind!([], Key::Named(Named::Space), PlayPause); bind!([], Key::Named(Named::ArrowLeft), SeekBackward); bind!([], Key::Named(Named::ArrowRight), SeekForward);