2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-07-28 16:47:23 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
use crate::Format;
|
|
|
|
use crate::FormattedValue;
|
|
|
|
use crate::GenericFormattedValue;
|
|
|
|
use crate::SeekFlags;
|
|
|
|
use crate::SeekType;
|
2017-07-31 09:45:04 +00:00
|
|
|
use glib::translate::*;
|
2017-12-01 09:21:20 +00:00
|
|
|
use std::fmt;
|
2017-12-09 16:20:21 +00:00
|
|
|
use std::marker::PhantomData;
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::mem;
|
|
|
|
use std::ptr;
|
2017-07-31 09:45:04 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub type Segment = FormattedSegment<GenericFormattedValue>;
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct FormattedSegment<T: FormattedValue>(ffi::GstSegment, PhantomData<T>);
|
2017-07-28 17:04:15 +00:00
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
impl Segment {
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn reset_with_format(&mut self, format: Format) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_init(self.to_glib_none_mut().0, format.to_glib());
|
2017-12-09 16:20:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_format(&mut self, format: Format) {
|
|
|
|
self.0.format = format.to_glib();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn downcast<T: FormattedValue>(self) -> Result<FormattedSegment<T>, Self> {
|
|
|
|
if T::get_default_format() == Format::Undefined
|
|
|
|
|| T::get_default_format() == self.get_format()
|
|
|
|
{
|
|
|
|
Ok(FormattedSegment(self.0, PhantomData))
|
|
|
|
} else {
|
|
|
|
Err(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn downcast_ref<T: FormattedValue>(&self) -> Option<&FormattedSegment<T>> {
|
|
|
|
if T::get_default_format() == Format::Undefined
|
|
|
|
|| T::get_default_format() == self.get_format()
|
|
|
|
{
|
2018-07-27 10:36:40 +00:00
|
|
|
Some(unsafe {
|
|
|
|
&*(self as *const FormattedSegment<GenericFormattedValue>
|
|
|
|
as *const FormattedSegment<T>)
|
|
|
|
})
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn downcast_mut<T: FormattedValue>(&mut self) -> Option<&mut FormattedSegment<T>> {
|
|
|
|
if T::get_default_format() == Format::Undefined
|
|
|
|
|| T::get_default_format() == self.get_format()
|
|
|
|
{
|
2018-07-27 10:36:40 +00:00
|
|
|
Some(unsafe {
|
|
|
|
&mut *(self as *mut FormattedSegment<GenericFormattedValue>
|
|
|
|
as *mut FormattedSegment<T>)
|
|
|
|
})
|
2017-12-09 16:20:21 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: FormattedValue> FormattedSegment<T> {
|
|
|
|
pub fn new() -> Self {
|
2017-07-31 09:45:04 +00:00
|
|
|
assert_initialized_main_thread!();
|
2017-12-09 16:20:21 +00:00
|
|
|
let segment = unsafe {
|
2019-07-11 13:02:46 +00:00
|
|
|
let mut segment = mem::MaybeUninit::zeroed();
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_init(segment.as_mut_ptr(), T::get_default_format().to_glib());
|
2019-07-11 13:02:46 +00:00
|
|
|
segment.assume_init()
|
2017-12-09 16:20:21 +00:00
|
|
|
};
|
|
|
|
FormattedSegment(segment, PhantomData)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn upcast(self) -> Segment {
|
|
|
|
FormattedSegment(self.0, PhantomData)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn upcast_ref(&self) -> &Segment {
|
2018-07-27 10:36:40 +00:00
|
|
|
unsafe {
|
|
|
|
&*(self as *const FormattedSegment<T> as *const FormattedSegment<GenericFormattedValue>)
|
|
|
|
}
|
2017-12-09 16:20:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn reset(&mut self) {
|
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_init(&mut self.0, T::get_default_format().to_glib());
|
2017-12-09 16:20:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn clip<V: Into<T>>(&self, start: V, stop: V) -> Option<(T, T)> {
|
2017-12-05 21:16:12 +00:00
|
|
|
let start = start.into();
|
|
|
|
let stop = stop.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), start.get_format());
|
|
|
|
assert_eq!(self.get_format(), stop.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut clip_start = mem::MaybeUninit::uninit();
|
|
|
|
let mut clip_stop = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_segment_clip(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
|
|
|
start.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
start.to_raw_value() as u64,
|
|
|
|
stop.to_raw_value() as u64,
|
2019-07-11 12:34:28 +00:00
|
|
|
clip_start.as_mut_ptr(),
|
|
|
|
clip_stop.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2017-12-05 21:16:12 +00:00
|
|
|
Some((
|
2019-07-11 12:34:28 +00:00
|
|
|
T::from_raw(self.get_format(), clip_start.assume_init() as i64),
|
|
|
|
T::from_raw(self.get_format(), clip_stop.assume_init() as i64),
|
2017-12-05 21:16:12 +00:00
|
|
|
))
|
2017-07-31 11:16:42 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn do_seek<V: Into<T>>(
|
2017-07-31 11:16:42 +00:00
|
|
|
&mut self,
|
|
|
|
rate: f64,
|
|
|
|
flags: SeekFlags,
|
|
|
|
start_type: SeekType,
|
2017-12-05 21:16:12 +00:00
|
|
|
start: V,
|
2017-07-31 11:16:42 +00:00
|
|
|
stop_type: SeekType,
|
2017-12-05 21:16:12 +00:00
|
|
|
stop: V,
|
2017-07-31 11:16:42 +00:00
|
|
|
) -> Option<bool> {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-12-05 21:16:12 +00:00
|
|
|
let start = start.into();
|
|
|
|
let stop = stop.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), start.get_format());
|
|
|
|
assert_eq!(self.get_format(), stop.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut update = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = from_glib(ffi::gst_segment_do_seek(
|
2017-12-09 16:20:21 +00:00
|
|
|
&mut self.0,
|
2017-07-31 11:16:42 +00:00
|
|
|
rate,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-07-31 11:16:42 +00:00
|
|
|
flags.to_glib(),
|
|
|
|
start_type.to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
start.to_raw_value() as u64,
|
2017-07-31 11:16:42 +00:00
|
|
|
stop_type.to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
stop.to_raw_value() as u64,
|
2019-07-11 12:34:28 +00:00
|
|
|
update.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
));
|
|
|
|
if ret {
|
2019-07-11 12:34:28 +00:00
|
|
|
Some(from_glib(update.assume_init()))
|
2017-07-31 11:16:42 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:56 +00:00
|
|
|
pub fn offset_running_time(&mut self, offset: i64) -> Result<(), glib::BoolError> {
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_offset_running_time(
|
2019-01-16 20:23:56 +00:00
|
|
|
&mut self.0,
|
|
|
|
self.get_format().to_glib(),
|
|
|
|
offset,
|
|
|
|
),
|
|
|
|
"Offset is not in the segment"
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn position_from_running_time<V: Into<T>>(&self, running_time: V) -> T {
|
2017-12-05 21:16:12 +00:00
|
|
|
let running_time = running_time.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), running_time.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2017-12-10 10:10:25 +00:00
|
|
|
T::from_raw(
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format(),
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_position_from_running_time(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
running_time.to_raw_value() as u64,
|
2017-12-05 21:16:12 +00:00
|
|
|
) as i64,
|
2017-07-31 11:16:42 +00:00
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn position_from_running_time_full<V: Into<T>>(&self, running_time: V) -> (i32, T) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let running_time = running_time.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), running_time.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut position = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = ffi::gst_segment_position_from_running_time_full(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
running_time.to_raw_value() as u64,
|
2019-07-11 12:34:28 +00:00
|
|
|
position.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
ret,
|
|
|
|
T::from_raw(self.get_format(), position.assume_init() as i64),
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn position_from_stream_time<V: Into<T>>(&self, stream_time: V) -> T {
|
2017-12-05 21:16:12 +00:00
|
|
|
let stream_time = stream_time.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), stream_time.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2017-12-10 10:10:25 +00:00
|
|
|
T::from_raw(
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format(),
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_position_from_stream_time(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
stream_time.to_raw_value() as u64,
|
2017-12-05 21:16:12 +00:00
|
|
|
) as i64,
|
2017-07-31 11:16:42 +00:00
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn position_from_stream_time_full<V: Into<T>>(&self, stream_time: V) -> (i32, T) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let stream_time = stream_time.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), stream_time.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut position = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = ffi::gst_segment_position_from_stream_time_full(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
stream_time.to_raw_value() as u64,
|
2019-07-11 12:34:28 +00:00
|
|
|
position.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
ret,
|
|
|
|
T::from_raw(self.get_format(), position.assume_init() as i64),
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-16 20:23:56 +00:00
|
|
|
pub fn set_running_time<V: Into<T>>(&mut self, running_time: V) -> Result<(), glib::BoolError> {
|
2017-12-05 21:16:12 +00:00
|
|
|
let running_time = running_time.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), running_time.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2020-12-17 22:38:06 +00:00
|
|
|
glib::result_from_gboolean!(
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_set_running_time(
|
2019-01-16 20:23:56 +00:00
|
|
|
&mut self.0,
|
|
|
|
self.get_format().to_glib(),
|
|
|
|
running_time.to_raw_value() as u64,
|
|
|
|
),
|
|
|
|
"Running time is not in the segment"
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn to_running_time<V: Into<T>>(&self, position: V) -> T {
|
2017-12-05 21:16:12 +00:00
|
|
|
let position = position.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), position.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2017-12-10 10:10:25 +00:00
|
|
|
T::from_raw(
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format(),
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_to_running_time(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
position.to_raw_value() as u64,
|
2017-12-05 21:16:12 +00:00
|
|
|
) as i64,
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn to_running_time_full<V: Into<T>>(&self, position: V) -> (i32, T) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let position = position.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), position.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut running_time = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = ffi::gst_segment_to_running_time_full(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
position.to_raw_value() as u64,
|
2019-07-11 12:34:28 +00:00
|
|
|
running_time.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
ret,
|
|
|
|
T::from_raw(self.get_format(), running_time.assume_init() as i64),
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn to_stream_time<V: Into<T>>(&self, position: V) -> T {
|
2017-12-05 21:16:12 +00:00
|
|
|
let position = position.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), position.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2017-12-10 10:10:25 +00:00
|
|
|
T::from_raw(
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format(),
|
2020-11-21 13:46:48 +00:00
|
|
|
ffi::gst_segment_to_stream_time(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
position.to_raw_value() as u64,
|
2017-12-05 21:16:12 +00:00
|
|
|
) as i64,
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn to_stream_time_full<V: Into<T>>(&self, position: V) -> (i32, T) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let position = position.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), position.get_format());
|
|
|
|
}
|
|
|
|
|
2017-07-28 16:47:23 +00:00
|
|
|
unsafe {
|
2019-07-11 12:34:28 +00:00
|
|
|
let mut stream_time = mem::MaybeUninit::uninit();
|
2020-11-21 13:46:48 +00:00
|
|
|
let ret = ffi::gst_segment_to_stream_time_full(
|
2017-12-09 16:20:21 +00:00
|
|
|
&self.0,
|
2017-12-05 21:16:12 +00:00
|
|
|
self.get_format().to_glib(),
|
2017-12-10 10:10:25 +00:00
|
|
|
position.to_raw_value() as u64,
|
2019-07-11 12:34:28 +00:00
|
|
|
stream_time.as_mut_ptr(),
|
2017-07-31 11:16:42 +00:00
|
|
|
);
|
2019-07-11 12:34:28 +00:00
|
|
|
(
|
|
|
|
ret,
|
|
|
|
T::from_raw(self.get_format(), stream_time.assume_init() as i64),
|
|
|
|
)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-08 22:29:49 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn get_flags(&self) -> crate::SegmentFlags {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.flags) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn set_flags(&mut self, flags: crate::SegmentFlags) {
|
2017-08-09 22:19:36 +00:00
|
|
|
self.0.flags = flags.to_glib();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_rate(&self) -> f64 {
|
|
|
|
self.0.rate
|
|
|
|
}
|
|
|
|
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::float_cmp)]
|
2017-08-09 22:19:36 +00:00
|
|
|
pub fn set_rate(&mut self, rate: f64) {
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_ne!(rate, 0.0);
|
2017-08-09 22:19:36 +00:00
|
|
|
self.0.rate = rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_applied_rate(&self) -> f64 {
|
|
|
|
self.0.applied_rate
|
|
|
|
}
|
|
|
|
|
2019-02-28 08:32:13 +00:00
|
|
|
#[allow(clippy::float_cmp)]
|
2017-08-09 22:19:36 +00:00
|
|
|
pub fn set_applied_rate(&mut self, applied_rate: f64) {
|
2017-12-09 16:20:21 +00:00
|
|
|
assert_ne!(applied_rate, 0.0);
|
2017-08-09 22:19:36 +00:00
|
|
|
self.0.applied_rate = applied_rate;
|
|
|
|
}
|
|
|
|
|
2017-12-01 09:21:20 +00:00
|
|
|
pub fn get_format(&self) -> Format {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.format) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_base(&self) -> T {
|
2017-12-10 10:10:25 +00:00
|
|
|
unsafe { T::from_raw(self.get_format(), self.0.base as i64) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_base<V: Into<T>>(&mut self, base: V) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let base = base.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), base.get_format());
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:10:25 +00:00
|
|
|
self.0.base = unsafe { base.to_raw_value() } as u64;
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_offset(&self) -> T {
|
2017-12-10 10:10:25 +00:00
|
|
|
unsafe { T::from_raw(self.get_format(), self.0.offset as i64) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_offset<V: Into<T>>(&mut self, offset: V) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let offset = offset.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), offset.get_format());
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:10:25 +00:00
|
|
|
self.0.offset = unsafe { offset.to_raw_value() } as u64;
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_start(&self) -> T {
|
2017-12-10 10:10:25 +00:00
|
|
|
unsafe { T::from_raw(self.get_format(), self.0.start as i64) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_start<V: Into<T>>(&mut self, start: V) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let start = start.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), start.get_format());
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:10:25 +00:00
|
|
|
self.0.start = unsafe { start.to_raw_value() } as u64;
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_stop(&self) -> T {
|
2017-12-10 10:10:25 +00:00
|
|
|
unsafe { T::from_raw(self.get_format(), self.0.stop as i64) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_stop<V: Into<T>>(&mut self, stop: V) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let stop = stop.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), stop.get_format());
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:10:25 +00:00
|
|
|
self.0.stop = unsafe { stop.to_raw_value() } as u64;
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_time(&self) -> T {
|
2017-12-10 10:10:25 +00:00
|
|
|
unsafe { T::from_raw(self.get_format(), self.0.time as i64) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_time<V: Into<T>>(&mut self, time: V) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let time = time.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), time.get_format());
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:10:25 +00:00
|
|
|
self.0.time = unsafe { time.to_raw_value() } as u64;
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_position(&self) -> T {
|
2017-12-10 10:10:25 +00:00
|
|
|
unsafe { T::from_raw(self.get_format(), self.0.position as i64) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_position<V: Into<T>>(&mut self, position: V) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let position = position.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), position.get_format());
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:10:25 +00:00
|
|
|
self.0.position = unsafe { position.to_raw_value() } as u64;
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn get_duration(&self) -> T {
|
2017-12-10 10:10:25 +00:00
|
|
|
unsafe { T::from_raw(self.get_format(), self.0.duration as i64) }
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
pub fn set_duration<V: Into<T>>(&mut self, duration: V) {
|
2017-12-05 21:16:12 +00:00
|
|
|
let duration = duration.into();
|
2017-12-09 16:20:21 +00:00
|
|
|
|
|
|
|
if T::get_default_format() == Format::Undefined {
|
|
|
|
assert_eq!(self.get_format(), duration.get_format());
|
|
|
|
}
|
|
|
|
|
2017-12-10 10:10:25 +00:00
|
|
|
self.0.duration = unsafe { duration.to_raw_value() } as u64;
|
2017-08-09 22:19:36 +00:00
|
|
|
}
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> PartialEq for FormattedSegment<T> {
|
2017-07-31 09:45:04 +00:00
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_segment_is_equal(&self.0, &other.0)) }
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> Eq for FormattedSegment<T> {}
|
2017-07-31 09:45:04 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
unsafe impl<T: FormattedValue> Send for FormattedSegment<T> {}
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl<T: FormattedValue> Sync for FormattedSegment<T> {}
|
2017-07-31 09:45:04 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> Clone for FormattedSegment<T> {
|
2017-07-31 09:45:04 +00:00
|
|
|
fn clone(&self) -> Self {
|
2017-12-09 16:20:21 +00:00
|
|
|
unsafe { FormattedSegment(ptr::read(&self.0), PhantomData) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: FormattedValue> AsRef<Segment> for FormattedSegment<T> {
|
|
|
|
fn as_ref(&self) -> &Segment {
|
2018-07-27 10:36:40 +00:00
|
|
|
unsafe {
|
|
|
|
&*(self as *const FormattedSegment<T> as *const FormattedSegment<GenericFormattedValue>)
|
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> fmt::Debug for FormattedSegment<T> {
|
2017-12-01 09:21:20 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-12-09 16:20:21 +00:00
|
|
|
let segment = self.as_ref();
|
|
|
|
match segment.get_format() {
|
2018-07-27 10:36:40 +00:00
|
|
|
Format::Undefined => f
|
|
|
|
.debug_struct("Segment")
|
2017-12-01 17:02:53 +00:00
|
|
|
.field("format", &Format::Undefined)
|
|
|
|
.finish(),
|
2017-12-09 16:20:21 +00:00
|
|
|
Format::Time => {
|
2020-11-21 13:46:48 +00:00
|
|
|
let segment = segment.downcast_ref::<crate::ClockTime>().unwrap();
|
2017-12-09 16:20:21 +00:00
|
|
|
f.debug_struct("Segment")
|
|
|
|
.field("format", &Format::Time)
|
|
|
|
.field("start", &segment.get_start().to_string())
|
|
|
|
.field("offset", &segment.get_offset().to_string())
|
|
|
|
.field("stop", &segment.get_stop().to_string())
|
|
|
|
.field("rate", &segment.get_rate())
|
|
|
|
.field("applied_rate", &segment.get_applied_rate())
|
|
|
|
.field("flags", &segment.get_flags())
|
|
|
|
.field("time", &segment.get_time().to_string())
|
|
|
|
.field("base", &segment.get_base().to_string())
|
|
|
|
.field("position", &segment.get_position().to_string())
|
|
|
|
.field("duration", &segment.get_duration().to_string())
|
|
|
|
.finish()
|
|
|
|
}
|
2018-07-27 10:36:40 +00:00
|
|
|
_ => f
|
|
|
|
.debug_struct("Segment")
|
2017-12-09 16:20:21 +00:00
|
|
|
.field("format", &segment.get_format())
|
|
|
|
.field("start", &segment.get_start())
|
|
|
|
.field("offset", &segment.get_offset())
|
|
|
|
.field("stop", &segment.get_stop())
|
|
|
|
.field("rate", &segment.get_rate())
|
|
|
|
.field("applied_rate", &segment.get_applied_rate())
|
|
|
|
.field("flags", &segment.get_flags())
|
|
|
|
.field("time", &segment.get_time())
|
|
|
|
.field("base", &segment.get_base())
|
|
|
|
.field("position", &segment.get_position())
|
|
|
|
.field("duration", &segment.get_duration())
|
2017-12-01 17:02:53 +00:00
|
|
|
.finish(),
|
2017-12-01 09:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> Default for FormattedSegment<T> {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> glib::types::StaticType for FormattedSegment<T> {
|
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { glib::translate::from_glib(ffi::gst_segment_get_type()) }
|
2017-09-10 11:54:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 09:45:04 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
impl<'a> glib::value::FromValueOptional<'a> for Segment {
|
|
|
|
unsafe fn from_value_optional(value: &glib::Value) -> Option<Self> {
|
2020-11-21 13:46:48 +00:00
|
|
|
Option::<Segment>::from_glib_none(glib::gobject_ffi::g_value_get_boxed(
|
|
|
|
value.to_glib_none().0,
|
|
|
|
) as *mut ffi::GstSegment)
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
2017-07-28 16:47:23 +00:00
|
|
|
|
2017-07-31 09:45:04 +00:00
|
|
|
#[doc(hidden)]
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> glib::value::SetValue for FormattedSegment<T> {
|
2017-07-31 09:45:04 +00:00
|
|
|
unsafe fn set_value(value: &mut glib::Value, this: &Self) {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::gobject_ffi::g_value_set_boxed(
|
2017-07-31 11:16:42 +00:00
|
|
|
value.to_glib_none_mut().0,
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::translate::ToGlibPtr::<*const ffi::GstSegment>::to_glib_none(this).0
|
|
|
|
as glib::ffi::gpointer,
|
2017-07-31 11:16:42 +00:00
|
|
|
)
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> glib::value::SetValueOptional for FormattedSegment<T> {
|
2017-07-31 09:45:04 +00:00
|
|
|
unsafe fn set_value_optional(value: &mut glib::Value, this: Option<&Self>) {
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::gobject_ffi::g_value_set_boxed(
|
2017-07-31 11:16:42 +00:00
|
|
|
value.to_glib_none_mut().0,
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::translate::ToGlibPtr::<*const ffi::GstSegment>::to_glib_none(&this).0
|
|
|
|
as glib::ffi::gpointer,
|
2017-07-31 11:16:42 +00:00
|
|
|
)
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2017-12-09 16:20:21 +00:00
|
|
|
impl<T: FormattedValue> glib::translate::GlibPtrDefault for FormattedSegment<T> {
|
2020-11-21 13:46:48 +00:00
|
|
|
type GlibType = *mut ffi::GstSegment;
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a, T: FormattedValue> glib::translate::ToGlibPtr<'a, *const ffi::GstSegment>
|
2018-02-22 10:18:37 +00:00
|
|
|
for FormattedSegment<T>
|
|
|
|
{
|
2017-12-09 16:20:21 +00:00
|
|
|
type Storage = &'a FormattedSegment<T>;
|
2017-07-31 09:45:04 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstSegment, Self> {
|
2017-07-31 09:45:04 +00:00
|
|
|
glib::translate::Stash(&self.0, self)
|
|
|
|
}
|
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_full(&self) -> *const ffi::GstSegment {
|
2017-07-31 09:45:04 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl<'a, T: FormattedValue> glib::translate::ToGlibPtrMut<'a, *mut ffi::GstSegment>
|
2018-02-22 10:18:37 +00:00
|
|
|
for FormattedSegment<T>
|
|
|
|
{
|
2017-12-09 16:20:21 +00:00
|
|
|
type Storage = &'a mut FormattedSegment<T>;
|
2017-07-31 09:45:04 +00:00
|
|
|
|
|
|
|
#[inline]
|
2020-11-21 13:46:48 +00:00
|
|
|
fn to_glib_none_mut(&'a mut self) -> glib::translate::StashMut<'a, *mut ffi::GstSegment, Self> {
|
2017-07-31 09:45:04 +00:00
|
|
|
glib::translate::StashMut(&mut self.0, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 15:41:02 +00:00
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl glib::translate::FromGlibPtrNone<*const ffi::GstSegment> for Segment {
|
2017-09-17 15:41:02 +00:00
|
|
|
#[inline]
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *const ffi::GstSegment) -> Self {
|
2017-12-09 16:20:21 +00:00
|
|
|
FormattedSegment(ptr::read(ptr), PhantomData)
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 09:45:04 +00:00
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl glib::translate::FromGlibPtrNone<*mut ffi::GstSegment> for Segment {
|
2017-07-31 09:45:04 +00:00
|
|
|
#[inline]
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *mut ffi::GstSegment) -> Self {
|
2017-12-09 16:20:21 +00:00
|
|
|
FormattedSegment(ptr::read(ptr), PhantomData)
|
2017-07-31 09:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-17 15:41:02 +00:00
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl glib::translate::FromGlibPtrBorrow<*mut ffi::GstSegment> for Segment {
|
2017-09-17 15:41:02 +00:00
|
|
|
#[inline]
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_borrow(ptr: *mut ffi::GstSegment) -> Borrowed<Self> {
|
2020-04-05 14:52:56 +00:00
|
|
|
Borrowed::new(FormattedSegment(ptr::read(ptr), PhantomData))
|
2017-09-17 15:41:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 09:45:04 +00:00
|
|
|
#[doc(hidden)]
|
2020-11-21 13:46:48 +00:00
|
|
|
impl glib::translate::FromGlibPtrFull<*mut ffi::GstSegment> for Segment {
|
2017-07-31 09:45:04 +00:00
|
|
|
#[inline]
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe fn from_glib_full(ptr: *mut ffi::GstSegment) -> Self {
|
2017-07-31 09:45:04 +00:00
|
|
|
let segment = from_glib_none(ptr);
|
2020-11-21 13:46:48 +00:00
|
|
|
glib::ffi::g_free(ptr as *mut _);
|
2017-07-31 09:45:04 +00:00
|
|
|
segment
|
2017-07-28 16:47:23 +00:00
|
|
|
}
|
|
|
|
}
|