From 86d1676a67f1bf48f2a3d44e61e11fc609747028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 10 Dec 2017 12:34:53 +0200 Subject: [PATCH] Request a keyframe whenever we're going to wait for a keyframe --- gst-plugin-togglerecord/Cargo.toml | 1 + gst-plugin-togglerecord/src/lib.rs | 1 + gst-plugin-togglerecord/src/togglerecord.rs | 27 ++++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/gst-plugin-togglerecord/Cargo.toml b/gst-plugin-togglerecord/Cargo.toml index 63488354..05d0f84a 100644 --- a/gst-plugin-togglerecord/Cargo.toml +++ b/gst-plugin-togglerecord/Cargo.toml @@ -7,6 +7,7 @@ license = "LGPL-2.1+" [dependencies] glib = { git = "https://github.com/gtk-rs/glib" } gstreamer = { git = "https://github.com/sdroege/gstreamer-rs", features = ["v1_10"] } +gstreamer-video = { git = "https://github.com/sdroege/gstreamer-rs", features = ["v1_10"] } gst-plugin = { path = "../gst-plugin" } gtk = { git = "https://github.com/gtk-rs/gtk", features = ["v3_6"], optional = true } gio = { git = "https://github.com/gtk-rs/gio", optional = true } diff --git a/gst-plugin-togglerecord/src/lib.rs b/gst-plugin-togglerecord/src/lib.rs index 959f8418..bc18d13c 100644 --- a/gst-plugin-togglerecord/src/lib.rs +++ b/gst-plugin-togglerecord/src/lib.rs @@ -22,6 +22,7 @@ extern crate glib; extern crate gst_plugin; #[macro_use] extern crate gstreamer as gst; +extern crate gstreamer_video as gst_video; mod togglerecord; diff --git a/gst-plugin-togglerecord/src/togglerecord.rs b/gst-plugin-togglerecord/src/togglerecord.rs index 8479c2dd..f79143af 100644 --- a/gst-plugin-togglerecord/src/togglerecord.rs +++ b/gst-plugin-togglerecord/src/togglerecord.rs @@ -19,6 +19,7 @@ use glib; use glib::prelude::*; use gst; use gst::prelude::*; +use gst_video; use gst_plugin::properties::*; use gst_plugin::object::*; @@ -376,16 +377,30 @@ impl ToggleRecord { // First check if we have to update our recording state let mut rec_state = self.state.lock().unwrap(); - match rec_state.recording_state { - RecordingState::Recording => if !settings.record { + let settings_changed = match rec_state.recording_state { + RecordingState::Recording if !settings.record => { gst_debug!(self.cat, obj: pad, "Stopping recording"); rec_state.recording_state = RecordingState::Stopping; - }, - RecordingState::Stopped => if settings.record { + true + } + RecordingState::Stopped if settings.record => { gst_debug!(self.cat, obj: pad, "Starting recording"); rec_state.recording_state = RecordingState::Starting; - }, - _ => (), + true + } + _ => false, + }; + + if settings_changed { + drop(rec_state); + drop(state); + gst_debug!(self.cat, obj: pad, "Requesting a new keyframe"); + stream.sinkpad.push_event( + gst_video::new_upstream_force_key_unit_event(gst::CLOCK_TIME_NONE, true, 0).build(), + ); + + state = stream.state.lock().unwrap(); + rec_state = self.state.lock().unwrap(); } match rec_state.recording_state {