From 798936afc98b50064b8991202652dcf0ec2da1ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Brzezi=C5=84ski?= Date: Fri, 2 Aug 2024 17:33:22 +0200 Subject: [PATCH] cmafmux: Add send-headers signal Forces cmafmux to output headers for the init segment again, alongside the next chunk. Needed for hlscmafsink to support changing output paths on the fly, without going back to READY. Part-of: --- docs/plugins/gst_plugins_cache.json | 10 +++++++++- mux/fmp4/src/fmp4mux/imp.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json index c0880b61..c5c81281 100644 --- a/docs/plugins/gst_plugins_cache.json +++ b/docs/plugins/gst_plugins_cache.json @@ -2111,7 +2111,15 @@ "presence": "always" } }, - "rank": "primary" + "rank": "primary", + "signals": { + "send-headers": { + "action": true, + "args": [], + "return-type": "void", + "when": "last" + } + } }, "dashmp4mux": { "author": "Sebastian Dröge ", diff --git a/mux/fmp4/src/fmp4mux/imp.rs b/mux/fmp4/src/fmp4mux/imp.rs index 7df90c95..2012f4f8 100644 --- a/mux/fmp4/src/fmp4mux/imp.rs +++ b/mux/fmp4/src/fmp4mux/imp.rs @@ -2398,6 +2398,7 @@ impl FMP4Mux { fmp4_header = Some(buffer); + gst::debug!(CAT, imp = self, "Headers will be sent now"); state.sent_headers = true; } @@ -3631,6 +3632,8 @@ impl FMP4MuxImpl for ISOFMP4Mux { const VARIANT: super::Variant = super::Variant::ISO; } +static CMAF_SIGNAL_SEND_HEADERS: &str = "send-headers"; + #[derive(Default)] pub(crate) struct CMAFMux; @@ -3641,7 +3644,31 @@ impl ObjectSubclass for CMAFMux { type ParentType = super::FMP4Mux; } -impl ObjectImpl for CMAFMux {} +impl ObjectImpl for CMAFMux { + fn signals() -> &'static [glib::subclass::Signal] { + static SIGNALS: Lazy> = Lazy::new(|| { + vec![glib::subclass::Signal::builder(CMAF_SIGNAL_SEND_HEADERS) + .action() + .class_handler(|_token, args| { + let element = args[0].get::().expect("signal arg"); + let imp = element.imp(); + let mut state = imp.state.lock().unwrap(); + + state.sent_headers = false; + gst::debug!( + CAT, + obj = element, + "Init headers will be re-sent alongside the next chunk" + ); + + None + }) + .build()] + }); + + SIGNALS.as_ref() + } +} impl GstObjectImpl for CMAFMux {}