From 05c51dd7784dca898b1bd7c41bc0df6d7cbaf6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 5 Dec 2017 23:16:12 +0200 Subject: [PATCH] Change all values in Segment to FormatValue --- gstreamer/src/segment.rs | 256 ++++++++++++++++++++++++++------------- 1 file changed, 173 insertions(+), 83 deletions(-) diff --git a/gstreamer/src/segment.rs b/gstreamer/src/segment.rs index d22f96d60..d8b7e7c4e 100644 --- a/gstreamer/src/segment.rs +++ b/gstreamer/src/segment.rs @@ -7,7 +7,7 @@ // except according to those terms. use Format; -use ClockTime; +use FormatValue; use SeekFlags; use SeekType; use ffi; @@ -27,20 +27,31 @@ impl Segment { unsafe { Self::uninitialized() } } - pub fn clip(&self, format: Format, start: u64, stop: u64) -> Option<(u64, u64)> { + pub fn clip>( + &self, + start: V, + stop: V, + ) -> Option<(FormatValue, FormatValue)> { + let start = start.into(); + let stop = stop.into(); + assert_eq!(self.get_format(), start.to_format()); + assert_eq!(start.to_format(), stop.to_format()); unsafe { let mut clip_start = mem::uninitialized(); let mut clip_stop = mem::uninitialized(); let ret = from_glib(ffi::gst_segment_clip( self.to_glib_none().0, - format.to_glib(), - start, - stop, + start.to_format().to_glib(), + start.to_value() as u64, + stop.to_value() as u64, &mut clip_start, &mut clip_stop, )); if ret { - Some((clip_start, clip_stop)) + Some(( + FormatValue::new(self.get_format(), clip_start as i64), + FormatValue::new(self.get_format(), clip_stop as i64), + )) } else { None } @@ -54,28 +65,31 @@ impl Segment { } #[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))] - pub fn do_seek( + pub fn do_seek>( &mut self, rate: f64, - format: Format, flags: SeekFlags, start_type: SeekType, - start: u64, + start: V, stop_type: SeekType, - stop: u64, + stop: V, ) -> Option { skip_assert_initialized!(); + let start = start.into(); + let stop = stop.into(); + assert_eq!(self.get_format(), start.to_format()); + assert_eq!(start.to_format(), stop.to_format()); unsafe { let mut update = mem::uninitialized(); let ret = from_glib(ffi::gst_segment_do_seek( self.to_glib_none_mut().0, rate, - format.to_glib(), + self.get_format().to_glib(), flags.to_glib(), start_type.to_glib(), - start, + start.to_value() as u64, stop_type.to_glib(), - stop, + stop.to_value() as u64, &mut update, )); if ret { @@ -111,103 +125,159 @@ impl Segment { } } - pub fn position_from_running_time(&self, format: Format, running_time: u64) -> u64 { + pub fn position_from_running_time>(&self, running_time: V) -> FormatValue { + let running_time = running_time.into(); + assert_eq!(self.get_format(), running_time.to_format()); unsafe { - ffi::gst_segment_position_from_running_time( - self.to_glib_none().0, - format.to_glib(), - running_time, + FormatValue::new( + self.get_format(), + ffi::gst_segment_position_from_running_time( + self.to_glib_none().0, + self.get_format().to_glib(), + running_time.to_value() as u64, + ) as i64, ) } } - pub fn position_from_running_time_full(&self, format: Format, running_time: u64) -> (i32, u64) { + pub fn position_from_running_time_full>( + &self, + running_time: V, + ) -> (i32, FormatValue) { + let running_time = running_time.into(); + assert_eq!(self.get_format(), running_time.to_format()); unsafe { let mut position = mem::uninitialized(); let ret = ffi::gst_segment_position_from_running_time_full( self.to_glib_none().0, - format.to_glib(), - running_time, + self.get_format().to_glib(), + running_time.to_value() as u64, &mut position, ); - (ret, position) + (ret, FormatValue::new(self.get_format(), position as i64)) } } - pub fn position_from_stream_time(&self, format: Format, stream_time: u64) -> u64 { + pub fn position_from_stream_time>(&self, stream_time: V) -> FormatValue { + let stream_time = stream_time.into(); + assert_eq!(self.get_format(), stream_time.to_format()); unsafe { - ffi::gst_segment_position_from_stream_time( - self.to_glib_none().0, - format.to_glib(), - stream_time, + FormatValue::new( + self.get_format(), + ffi::gst_segment_position_from_stream_time( + self.to_glib_none().0, + self.get_format().to_glib(), + stream_time.to_value() as u64, + ) as i64, ) } } - pub fn position_from_stream_time_full(&self, format: Format, stream_time: u64) -> (i32, u64) { + pub fn position_from_stream_time_full>( + &self, + stream_time: V, + ) -> (i32, FormatValue) { + let stream_time = stream_time.into(); + assert_eq!(self.get_format(), stream_time.to_format()); unsafe { let mut position = mem::uninitialized(); let ret = ffi::gst_segment_position_from_stream_time_full( self.to_glib_none().0, - format.to_glib(), - stream_time, + self.get_format().to_glib(), + stream_time.to_value() as u64, &mut position, ); - (ret, position) + (ret, FormatValue::new(self.get_format(), position as i64)) } } - pub fn set_running_time(&mut self, format: Format, running_time: u64) -> bool { + pub fn set_running_time>(&mut self, running_time: V) -> bool { + let running_time = running_time.into(); + assert_eq!(self.get_format(), running_time.to_format()); unsafe { from_glib(ffi::gst_segment_set_running_time( self.to_glib_none_mut().0, - format.to_glib(), - running_time, + self.get_format().to_glib(), + running_time.to_value() as u64, )) } } - pub fn to_position(&self, format: Format, running_time: u64) -> u64 { + pub fn to_position>(&self, running_time: V) -> FormatValue { + let running_time = running_time.into(); + assert_eq!(self.get_format(), running_time.to_format()); unsafe { - ffi::gst_segment_to_position(self.to_glib_none().0, format.to_glib(), running_time) + FormatValue::new( + self.get_format(), + ffi::gst_segment_to_position( + self.to_glib_none().0, + self.get_format().to_glib(), + running_time.to_value() as u64, + ) as i64, + ) } } - pub fn to_running_time(&self, format: Format, position: u64) -> u64 { + pub fn to_running_time>(&self, position: V) -> FormatValue { + let position = position.into(); + assert_eq!(self.get_format(), position.to_format()); unsafe { - ffi::gst_segment_to_running_time(self.to_glib_none().0, format.to_glib(), position) + FormatValue::new( + self.get_format(), + ffi::gst_segment_to_running_time( + self.to_glib_none().0, + self.get_format().to_glib(), + position.to_value() as u64, + ) as i64, + ) } } - pub fn to_running_time_full(&self, format: Format, position: u64) -> (i32, u64) { + pub fn to_running_time_full>(&self, position: V) -> (i32, FormatValue) { + let position = position.into(); + assert_eq!(self.get_format(), position.to_format()); unsafe { let mut running_time = mem::uninitialized(); let ret = ffi::gst_segment_to_running_time_full( self.to_glib_none().0, - format.to_glib(), - position, + self.get_format().to_glib(), + position.to_value() as u64, &mut running_time, ); - (ret, running_time) + ( + ret, + FormatValue::new(self.get_format(), running_time as i64), + ) } } - pub fn to_stream_time(&self, format: Format, position: u64) -> u64 { + pub fn to_stream_time>(&self, position: V) -> FormatValue { + let position = position.into(); + assert_eq!(self.get_format(), position.to_format()); unsafe { - ffi::gst_segment_to_stream_time(self.to_glib_none().0, format.to_glib(), position) + FormatValue::new( + self.get_format(), + ffi::gst_segment_to_stream_time( + self.to_glib_none().0, + self.get_format().to_glib(), + position.to_value() as u64, + ) as i64, + ) } } - pub fn to_stream_time_full(&self, format: Format, position: u64) -> (i32, u64) { + pub fn to_stream_time_full>(&self, position: V) -> (i32, FormatValue) { + let position = position.into(); + assert_eq!(self.get_format(), position.to_format()); unsafe { let mut stream_time = mem::uninitialized(); let ret = ffi::gst_segment_to_stream_time_full( self.to_glib_none().0, - format.to_glib(), - position, + self.get_format().to_glib(), + position.to_value() as u64, &mut stream_time, ); - (ret, stream_time) + (ret, FormatValue::new(self.get_format(), stream_time as i64)) } } @@ -243,60 +313,74 @@ impl Segment { self.0.format = format.to_glib(); } - pub fn get_base(&self) -> u64 { - self.0.base + pub fn get_base(&self) -> FormatValue { + FormatValue::new(self.get_format(), self.0.base as i64) } - pub fn set_base(&mut self, base: u64) { - self.0.base = base; + pub fn set_base>(&mut self, base: V) { + let base = base.into(); + assert_eq!(self.get_format(), base.to_format()); + self.0.base = base.to_value() as u64; } - pub fn get_offset(&self) -> u64 { - self.0.offset + pub fn get_offset(&self) -> FormatValue { + FormatValue::new(self.get_format(), self.0.offset as i64) } - pub fn set_offset(&mut self, offset: u64) { - self.0.offset = offset; + pub fn set_offset>(&mut self, offset: V) { + let offset = offset.into(); + assert_eq!(self.get_format(), offset.to_format()); + self.0.offset = offset.to_value() as u64; } - pub fn get_start(&self) -> u64 { - self.0.start + pub fn get_start(&self) -> FormatValue { + FormatValue::new(self.get_format(), self.0.start as i64) } - pub fn set_start(&mut self, start: u64) { - self.0.start = start; + pub fn set_start>(&mut self, start: V) { + let start = start.into(); + assert_eq!(self.get_format(), start.to_format()); + self.0.start = start.to_value() as u64; } - pub fn get_stop(&self) -> u64 { - self.0.stop + pub fn get_stop(&self) -> FormatValue { + FormatValue::new(self.get_format(), self.0.stop as i64) } - pub fn set_stop(&mut self, stop: u64) { - self.0.stop = stop; + pub fn set_stop>(&mut self, stop: V) { + let stop = stop.into(); + assert_eq!(self.get_format(), stop.to_format()); + self.0.stop = stop.to_value() as u64; } - pub fn get_time(&self) -> u64 { - self.0.time + pub fn get_time(&self) -> FormatValue { + FormatValue::new(self.get_format(), self.0.time as i64) } - pub fn set_time(&mut self, time: u64) { - self.0.time = time; + pub fn set_time>(&mut self, time: V) { + let time = time.into(); + assert_eq!(self.get_format(), time.to_format()); + self.0.time = time.to_value() as u64; } - pub fn get_position(&self) -> u64 { - self.0.position + pub fn get_position(&self) -> FormatValue { + FormatValue::new(self.get_format(), self.0.position as i64) } - pub fn set_position(&mut self, position: u64) { - self.0.position = position; + pub fn set_position>(&mut self, position: V) { + let position = position.into(); + assert_eq!(self.get_format(), position.to_format()); + self.0.position = position.to_value() as u64; } - pub fn get_duration(&self) -> u64 { - self.0.duration + pub fn get_duration(&self) -> FormatValue { + FormatValue::new(self.get_format(), self.0.duration as i64) } - pub fn set_duration(&mut self, duration: u64) { - self.0.duration = duration; + pub fn set_duration>(&mut self, duration: V) { + let duration = duration.into(); + assert_eq!(self.get_format(), duration.to_format()); + self.0.duration = duration.to_value() as u64; } } @@ -325,21 +409,27 @@ impl fmt::Debug for Segment { .finish(), Format::Time => f.debug_struct("Segment") .field("format", &Format::Time) - .field("start", &ClockTime::from(self.get_start()).to_string()) - .field("offset", &ClockTime::from(self.get_offset()).to_string()) - .field("stop", &ClockTime::from(self.get_stop()).to_string()) + .field( + "start", + &self.get_start().try_to_time().unwrap().to_string(), + ) + .field( + "offset", + &self.get_offset().try_to_time().unwrap().to_string(), + ) + .field("stop", &self.get_stop().try_to_time().unwrap().to_string()) .field("rate", &self.get_rate()) .field("applied_rate", &self.get_applied_rate()) .field("flags", &self.get_flags()) - .field("time", &ClockTime::from(self.get_time()).to_string()) - .field("base", &ClockTime::from(self.get_base()).to_string()) + .field("time", &self.get_time().try_to_time().unwrap().to_string()) + .field("base", &self.get_base().try_to_time().unwrap().to_string()) .field( "position", - &ClockTime::from(self.get_position()).to_string(), + &self.get_position().try_to_time().unwrap().to_string(), ) .field( "duration", - &ClockTime::from(self.get_duration()).to_string(), + &self.get_duration().try_to_time().unwrap().to_string(), ) .finish(), _ => f.debug_struct("Segment")