2017-12-10 09:57:11 +00:00
|
|
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
use gst_sys;
|
|
|
|
use gst_video_sys;
|
2017-12-10 09:57:11 +00:00
|
|
|
|
2018-04-01 08:30:03 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_full, ToGlib};
|
2018-04-25 08:10:06 +00:00
|
|
|
use glib::ToSendValue;
|
2017-12-10 09:57:11 +00:00
|
|
|
use gst;
|
|
|
|
use gst::MiniObject;
|
2017-12-10 20:43:28 +00:00
|
|
|
use std::mem;
|
2017-12-10 09:57:11 +00:00
|
|
|
|
|
|
|
pub fn is_force_key_unit_event(event: &gst::EventRef) -> bool {
|
2019-03-19 07:58:20 +00:00
|
|
|
unsafe {
|
|
|
|
from_glib(gst_video_sys::gst_video_event_is_force_key_unit(
|
|
|
|
event.as_mut_ptr(),
|
|
|
|
))
|
|
|
|
}
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
2017-12-10 10:26:16 +00:00
|
|
|
// FIXME: Copy from gstreamer/src/event.rs
|
|
|
|
macro_rules! event_builder_generic_impl {
|
|
|
|
($new_fn:expr) => {
|
|
|
|
pub fn seqnum(self, seqnum: gst::Seqnum) -> Self {
|
|
|
|
Self {
|
|
|
|
seqnum: Some(seqnum),
|
|
|
|
.. self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn running_time_offset(self, running_time_offset: i64) -> Self {
|
|
|
|
Self {
|
|
|
|
running_time_offset: Some(running_time_offset),
|
|
|
|
.. self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn other_fields(self, other_fields: &[(&'a str, &'a ToSendValue)]) -> Self {
|
|
|
|
Self {
|
|
|
|
other_fields: self.other_fields.iter().cloned()
|
|
|
|
.chain(other_fields.iter().cloned())
|
|
|
|
.collect(),
|
|
|
|
.. self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn build(mut self) -> gst::Event {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
let event = $new_fn(&mut self);
|
|
|
|
if let Some(seqnum) = self.seqnum {
|
2019-03-19 07:58:20 +00:00
|
|
|
gst_sys::gst_event_set_seqnum(event, seqnum.to_glib());
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(running_time_offset) = self.running_time_offset {
|
2019-03-19 07:58:20 +00:00
|
|
|
gst_sys::gst_event_set_running_time_offset(event, running_time_offset);
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let s = gst::StructureRef::from_glib_borrow_mut(
|
2019-03-19 07:58:20 +00:00
|
|
|
gst_sys::gst_event_writable_structure(event)
|
2017-12-10 10:26:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
for (k, v) in self.other_fields {
|
|
|
|
s.set_value(k, v.to_send_value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
from_glib_full(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 20:43:28 +00:00
|
|
|
pub fn new_downstream_force_key_unit_event<'a>() -> DownstreamForceKeyUnitEventBuilder<'a> {
|
|
|
|
DownstreamForceKeyUnitEventBuilder::new()
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DownstreamForceKeyUnitEventBuilder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
|
|
|
other_fields: Vec<(&'a str, &'a ToSendValue)>,
|
|
|
|
timestamp: gst::ClockTime,
|
|
|
|
stream_time: gst::ClockTime,
|
|
|
|
running_time: gst::ClockTime,
|
|
|
|
all_headers: bool,
|
|
|
|
count: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> DownstreamForceKeyUnitEventBuilder<'a> {
|
2017-12-10 20:43:28 +00:00
|
|
|
fn new() -> Self {
|
2017-12-10 10:26:16 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
2017-12-10 20:43:28 +00:00
|
|
|
timestamp: gst::CLOCK_TIME_NONE,
|
|
|
|
stream_time: gst::CLOCK_TIME_NONE,
|
|
|
|
running_time: gst::CLOCK_TIME_NONE,
|
|
|
|
all_headers: true,
|
|
|
|
count: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn timestamp(self, timestamp: gst::ClockTime) -> Self {
|
2018-07-27 10:36:40 +00:00
|
|
|
Self { timestamp, ..self }
|
2017-12-10 20:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn stream_time(self, stream_time: gst::ClockTime) -> Self {
|
|
|
|
Self {
|
2018-07-20 07:21:06 +00:00
|
|
|
stream_time,
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn running_time(self, running_time: gst::ClockTime) -> Self {
|
|
|
|
Self {
|
2018-07-20 07:21:06 +00:00
|
|
|
running_time,
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn all_headers(self, all_headers: bool) -> Self {
|
|
|
|
Self {
|
2018-07-20 07:21:06 +00:00
|
|
|
all_headers,
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn count(self, count: u32) -> Self {
|
2018-07-27 10:36:40 +00:00
|
|
|
Self { count, ..self }
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
2017-12-10 10:26:16 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
event_builder_generic_impl!(|s: &mut Self| {
|
|
|
|
gst_video_sys::gst_video_event_new_downstream_force_key_unit(
|
2017-12-10 10:26:16 +00:00
|
|
|
s.timestamp.to_glib(),
|
|
|
|
s.stream_time.to_glib(),
|
|
|
|
s.running_time.to_glib(),
|
|
|
|
s.all_headers.to_glib(),
|
|
|
|
s.count,
|
|
|
|
)
|
2019-03-19 07:58:20 +00:00
|
|
|
});
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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<DownstreamForceKeyUnitEvent> {
|
|
|
|
unsafe {
|
2017-12-10 20:43:28 +00:00
|
|
|
let mut timestamp = mem::uninitialized();
|
|
|
|
let mut stream_time = mem::uninitialized();
|
|
|
|
let mut running_time = mem::uninitialized();
|
|
|
|
let mut all_headers = mem::uninitialized();
|
|
|
|
let mut count = mem::uninitialized();
|
2017-12-10 09:57:11 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
let res: bool = from_glib(
|
|
|
|
gst_video_sys::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,
|
|
|
|
),
|
|
|
|
);
|
2017-12-10 09:57:11 +00:00
|
|
|
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),
|
2018-07-20 07:21:06 +00:00
|
|
|
count,
|
2017-12-10 09:57:11 +00:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 20:43:28 +00:00
|
|
|
pub fn new_upstream_force_key_unit_event<'a>() -> UpstreamForceKeyUnitEventBuilder<'a> {
|
|
|
|
UpstreamForceKeyUnitEventBuilder::new()
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct UpstreamForceKeyUnitEventBuilder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
|
|
|
other_fields: Vec<(&'a str, &'a ToSendValue)>,
|
|
|
|
running_time: gst::ClockTime,
|
|
|
|
all_headers: bool,
|
|
|
|
count: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> UpstreamForceKeyUnitEventBuilder<'a> {
|
2017-12-10 20:43:28 +00:00
|
|
|
fn new() -> Self {
|
2017-12-10 10:26:16 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
2017-12-10 20:43:28 +00:00
|
|
|
running_time: gst::CLOCK_TIME_NONE,
|
|
|
|
all_headers: true,
|
|
|
|
count: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn running_time(self, running_time: gst::ClockTime) -> Self {
|
|
|
|
Self {
|
2018-07-20 07:21:06 +00:00
|
|
|
running_time,
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn all_headers(self, all_headers: bool) -> Self {
|
|
|
|
Self {
|
2018-07-20 07:21:06 +00:00
|
|
|
all_headers,
|
2017-12-10 20:43:28 +00:00
|
|
|
..self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn count(self, count: u32) -> Self {
|
2018-07-27 10:36:40 +00:00
|
|
|
Self { count, ..self }
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
2017-12-10 10:26:16 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
event_builder_generic_impl!(|s: &mut Self| {
|
|
|
|
gst_video_sys::gst_video_event_new_upstream_force_key_unit(
|
2017-12-10 10:26:16 +00:00
|
|
|
s.running_time.to_glib(),
|
|
|
|
s.all_headers.to_glib(),
|
|
|
|
s.count,
|
|
|
|
)
|
2019-03-19 07:58:20 +00:00
|
|
|
});
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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<UpstreamForceKeyUnitEvent> {
|
|
|
|
unsafe {
|
2017-12-10 20:43:28 +00:00
|
|
|
let mut running_time = mem::uninitialized();
|
|
|
|
let mut all_headers = mem::uninitialized();
|
|
|
|
let mut count = mem::uninitialized();
|
2017-12-10 09:57:11 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
let res: bool = from_glib(
|
|
|
|
gst_video_sys::gst_video_event_parse_upstream_force_key_unit(
|
|
|
|
event.as_mut_ptr(),
|
|
|
|
&mut running_time,
|
|
|
|
&mut all_headers,
|
|
|
|
&mut count,
|
|
|
|
),
|
|
|
|
);
|
2017-12-10 09:57:11 +00:00
|
|
|
if res {
|
|
|
|
Some(UpstreamForceKeyUnitEvent {
|
|
|
|
running_time: from_glib(running_time),
|
|
|
|
all_headers: from_glib(all_headers),
|
2018-07-20 07:21:06 +00:00
|
|
|
count,
|
2017-12-10 09:57:11 +00:00
|
|
|
})
|
|
|
|
} 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<ForceKeyUnitEvent> {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:26:16 +00:00
|
|
|
pub fn new_still_frame_event<'a>(in_still: bool) -> StillFrameEventBuilder<'a> {
|
|
|
|
StillFrameEventBuilder::new(in_still)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct StillFrameEventBuilder<'a> {
|
|
|
|
seqnum: Option<gst::Seqnum>,
|
|
|
|
running_time_offset: Option<i64>,
|
|
|
|
other_fields: Vec<(&'a str, &'a ToSendValue)>,
|
|
|
|
in_still: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> StillFrameEventBuilder<'a> {
|
|
|
|
fn new(in_still: bool) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
Self {
|
|
|
|
seqnum: None,
|
|
|
|
running_time_offset: None,
|
|
|
|
other_fields: Vec::new(),
|
2018-07-20 07:21:06 +00:00
|
|
|
in_still,
|
2017-12-10 10:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
event_builder_generic_impl!(
|
|
|
|
|s: &mut Self| gst_video_sys::gst_video_event_new_still_frame(s.in_still.to_glib())
|
|
|
|
);
|
2017-12-10 09:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct StillFrameEvent {
|
|
|
|
pub in_still: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse_still_frame_event(event: &gst::EventRef) -> Option<StillFrameEvent> {
|
|
|
|
unsafe {
|
2017-12-10 20:43:28 +00:00
|
|
|
let mut in_still = mem::uninitialized();
|
2017-12-10 09:57:11 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
let res: bool = from_glib(gst_video_sys::gst_video_event_parse_still_frame(
|
2017-12-10 09:57:11 +00:00
|
|
|
event.as_mut_ptr(),
|
|
|
|
&mut in_still,
|
|
|
|
));
|
|
|
|
if res {
|
|
|
|
Some(StillFrameEvent {
|
|
|
|
in_still: from_glib(in_still),
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|