From d55e08a6a46291ac7a3a96650e04ad7fcabad3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 10 Dec 2017 11:57:11 +0200 Subject: [PATCH] Add bindings for force-keyunit and still-frame events --- gstreamer-video/src/lib.rs | 2 + gstreamer-video/src/video_event.rs | 164 +++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 gstreamer-video/src/video_event.rs diff --git a/gstreamer-video/src/lib.rs b/gstreamer-video/src/lib.rs index eac705e80..f08cea771 100644 --- a/gstreamer-video/src/lib.rs +++ b/gstreamer-video/src/lib.rs @@ -50,6 +50,8 @@ mod video_frame; pub use video_frame::VideoFrame; mod video_overlay; pub use video_overlay::VideoOverlayExtManual; +mod video_event; +pub use video_event::*; // Re-export all the traits in a prelude module, so that applications // can always "use gst::prelude::*" without getting conflicts diff --git a/gstreamer-video/src/video_event.rs b/gstreamer-video/src/video_event.rs new file mode 100644 index 000000000..d27d3fdeb --- /dev/null +++ b/gstreamer-video/src/video_event.rs @@ -0,0 +1,164 @@ +// Copyright (C) 2017 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use ffi; + +use gst; +use gst::MiniObject; +use glib::translate::{from_glib, from_glib_full, ToGlib}; + +pub fn is_force_key_unit_event(event: &gst::EventRef) -> bool { + unsafe { from_glib(ffi::gst_video_event_is_force_key_unit(event.as_mut_ptr())) } +} + +pub fn new_downstream_force_key_unit_event( + timestamp: gst::ClockTime, + stream_time: gst::ClockTime, + running_time: gst::ClockTime, + all_headers: bool, + count: u32, +) -> gst::Event { + unsafe { + from_glib_full(ffi::gst_video_event_new_downstream_force_key_unit( + timestamp.to_glib(), + stream_time.to_glib(), + running_time.to_glib(), + all_headers.to_glib(), + count, + )) + } +} + +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct DownstreamForceKeyUnitEvent { + pub timestamp: gst::ClockTime, + pub stream_time: gst::ClockTime, + pub running_time: gst::ClockTime, + pub all_headers: bool, + pub count: u32, +} + +pub fn parse_downstream_force_key_unit_event( + event: &gst::EventRef, +) -> Option { + unsafe { + let mut timestamp = 0; + let mut stream_time = 0; + let mut running_time = 0; + let mut all_headers = 0; + let mut count = 0; + + let res: bool = from_glib(ffi::gst_video_event_parse_downstream_force_key_unit( + event.as_mut_ptr(), + &mut timestamp, + &mut stream_time, + &mut running_time, + &mut all_headers, + &mut count, + )); + if res { + Some(DownstreamForceKeyUnitEvent { + timestamp: from_glib(timestamp), + stream_time: from_glib(stream_time), + running_time: from_glib(running_time), + all_headers: from_glib(all_headers), + count: count, + }) + } else { + None + } + } +} + +pub fn new_upstream_force_key_unit_event( + running_time: gst::ClockTime, + all_headers: bool, + count: u32, +) -> gst::Event { + unsafe { + from_glib_full(ffi::gst_video_event_new_upstream_force_key_unit( + running_time.to_glib(), + all_headers.to_glib(), + count, + )) + } +} + +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct UpstreamForceKeyUnitEvent { + pub running_time: gst::ClockTime, + pub all_headers: bool, + pub count: u32, +} + +pub fn parse_upstream_force_key_unit_event( + event: &gst::EventRef, +) -> Option { + unsafe { + let mut running_time = 0; + let mut all_headers = 0; + let mut count = 0; + + let res: bool = from_glib(ffi::gst_video_event_parse_upstream_force_key_unit( + event.as_mut_ptr(), + &mut running_time, + &mut all_headers, + &mut count, + )); + if res { + Some(UpstreamForceKeyUnitEvent { + running_time: from_glib(running_time), + all_headers: from_glib(all_headers), + count: count, + }) + } else { + None + } + } +} + +#[derive(Clone, PartialEq, Eq, Debug)] +pub enum ForceKeyUnitEvent { + Downstream(DownstreamForceKeyUnitEvent), + Upstream(UpstreamForceKeyUnitEvent), +} + +pub fn parse_force_key_unit_event(event: &gst::EventRef) -> Option { + if event.is_upstream() { + parse_upstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Upstream) + } else { + parse_downstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Downstream) + } +} + +pub fn new_still_frame_event(in_still: bool) -> gst::Event { + unsafe { from_glib_full(ffi::gst_video_event_new_still_frame(in_still.to_glib())) } +} + +#[derive(Clone, PartialEq, Eq, Debug)] +pub struct StillFrameEvent { + pub in_still: bool, +} + +pub fn parse_still_frame_event(event: &gst::EventRef) -> Option { + unsafe { + let mut in_still = 0; + + let res: bool = from_glib(ffi::gst_video_event_parse_still_frame( + event.as_mut_ptr(), + &mut in_still, + )); + if res { + Some(StillFrameEvent { + in_still: from_glib(in_still), + }) + } else { + None + } + } +}