diff --git a/examples/src/bin/appsink.rs b/examples/src/bin/appsink.rs index 2f96c36bf..a425a853f 100644 --- a/examples/src/bin/appsink.rs +++ b/examples/src/bin/appsink.rs @@ -141,7 +141,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .bus() .expect("Pipeline without bus. Shouldn't happen!"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/appsrc.rs b/examples/src/bin/appsrc.rs index 1f36f694a..5349750dc 100644 --- a/examples/src/bin/appsrc.rs +++ b/examples/src/bin/appsrc.rs @@ -98,7 +98,7 @@ fn create_pipeline() -> Result { // For each frame we produce, we set the timestamp when it should be displayed // (pts = presentation time stamp) // The autovideosink will use this information to display the frame at the right time. - buffer.set_pts(i * 500 * gst::MSECOND); + buffer.set_pts(i * 500 * gst::ClockTime::MSECOND); // At this point, buffer is only a reference to an existing memory region somewhere. // When we want to access its content, we have to map it while requesting the required @@ -150,7 +150,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .bus() .expect("Pipeline without bus. Shouldn't happen!"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/custom_meta.rs b/examples/src/bin/custom_meta.rs index 46e4e5a58..d06fdc917 100644 --- a/examples/src/bin/custom_meta.rs +++ b/examples/src/bin/custom_meta.rs @@ -264,7 +264,7 @@ fn example_main() { .expect("Pipeline without bus. Shouldn't happen!"); // And run until EOS or an error happened. - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/debug_ringbuffer.rs b/examples/src/bin/debug_ringbuffer.rs index 9ab651ee8..a3284ca7f 100644 --- a/examples/src/bin/debug_ringbuffer.rs +++ b/examples/src/bin/debug_ringbuffer.rs @@ -46,7 +46,7 @@ fn example_main() { .set_state(gst::State::Playing) .expect("Unable to set the pipeline to the `Playing` state"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/decodebin.rs b/examples/src/bin/decodebin.rs index 454544300..264ec2250 100644 --- a/examples/src/bin/decodebin.rs +++ b/examples/src/bin/decodebin.rs @@ -236,7 +236,7 @@ fn example_main() -> Result<(), Error> { // In the callback ("pad-added" on the decodebin), we sent better error information // using a bus message. This is the position where we get those messages and log // the contained information. - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/encodebin.rs b/examples/src/bin/encodebin.rs index 93a64057f..651d99ddc 100644 --- a/examples/src/bin/encodebin.rs +++ b/examples/src/bin/encodebin.rs @@ -261,7 +261,7 @@ fn example_main() -> Result<(), Error> { .bus() .expect("Pipeline without bus. Shouldn't happen!"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/ges.rs b/examples/src/bin/ges.rs index 3ea65285d..890b05a29 100644 --- a/examples/src/bin/ges.rs +++ b/examples/src/bin/ges.rs @@ -74,12 +74,16 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> { // Retrieve the asset that was automatically used behind the scenes, to // extract the clip from. let asset = clip.asset().unwrap(); - let duration = asset.downcast::().unwrap().duration(); + let duration = asset + .downcast::() + .unwrap() + .duration() + .expect("unknown duration"); println!( "Clip duration: {} - playing file from {} for {}", duration, duration / 2, - duration / 4 + duration / 4, ); // The inpoint specifies where in the clip we start, the duration specifies @@ -94,7 +98,7 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> { .expect("Unable to set the pipeline to the `Playing` state"); let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/gtksink.rs b/examples/src/bin/gtksink.rs index 6e775bcee..2d6b4a35d 100644 --- a/examples/src/bin/gtksink.rs +++ b/examples/src/bin/gtksink.rs @@ -91,7 +91,7 @@ fn create_ui(app: >k::Application) { // Query the current playing position from the underlying pipeline. let position = pipeline.query_position::(); // Display the playing position in the gui. - label.set_text(&format!("Position: {:.0}", position)); + label.set_text(&format!("Position: {:.0}", position.display())); // Tell the callback to continue calling this closure. glib::Continue(true) }); diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index 24fb9fffd..e78b996f4 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -196,7 +196,7 @@ fn create_ui(app: >k::Application) { // Query the current playing position from the underlying pipeline. let position = pipeline.query_position::(); // Display the playing position in the gui. - label.set_text(&format!("Position: {:.0}", position)); + label.set_text(&format!("Position: {:.0}", position.display())); // Tell the timeout to continue calling this callback. glib::Continue(true) }); diff --git a/examples/src/bin/launch.rs b/examples/src/bin/launch.rs index 86fecfb9f..7d625c944 100644 --- a/examples/src/bin/launch.rs +++ b/examples/src/bin/launch.rs @@ -46,7 +46,7 @@ fn example_main() { .set_state(gst::State::Playing) .expect("Unable to set the pipeline to the `Playing` state"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/overlay-composition.rs b/examples/src/bin/overlay-composition.rs index 3fdca7e5b..aece2d3f1 100644 --- a/examples/src/bin/overlay-composition.rs +++ b/examples/src/bin/overlay-composition.rs @@ -142,15 +142,15 @@ fn create_pipeline() -> Result { let _overlay = args[0].get::().unwrap(); let sample = args[1].get::().unwrap(); let buffer = sample.buffer().unwrap(); - let timestamp = buffer.pts(); + let timestamp = buffer.pts().unwrap(); let info = drawer.info.as_ref().unwrap(); let layout = drawer.layout.borrow(); let angle = 2.0 * PI - * ((timestamp % (10 * gst::SECOND)).unwrap() as f64 - / (10.0 * gst::SECOND_VAL as f64)); + * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64 + / (10.0 * gst::ClockTime::SECOND.nseconds() as f64); /* Create a gst::Buffer for Cairo to draw into */ let frame_width = info.width() as usize; @@ -296,7 +296,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .bus() .expect("Pipeline without bus. Shouldn't happen!"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/pad_probes.rs b/examples/src/bin/pad_probes.rs index b5a354f16..d806e72fa 100644 --- a/examples/src/bin/pad_probes.rs +++ b/examples/src/bin/pad_probes.rs @@ -77,7 +77,7 @@ fn example_main() { .expect("Unable to set the pipeline to the `Playing` state"); let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/pango-cairo.rs b/examples/src/bin/pango-cairo.rs index 4763a8e7a..93415a4fc 100644 --- a/examples/src/bin/pango-cairo.rs +++ b/examples/src/bin/pango-cairo.rs @@ -143,10 +143,8 @@ fn create_pipeline() -> Result { let info = drawer.info.as_ref().unwrap(); let layout = drawer.layout.borrow(); - let angle = 2.0 - * PI - * ((timestamp % (10 * gst::SECOND)).unwrap() as f64 - / (10.0 * gst::SECOND_VAL as f64)); + let angle = 2.0 * PI * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64 + / (10.0 * gst::ClockTime::SECOND.nseconds() as f64); // The image we draw (the text) will be static, but we will change the // transformation on the drawing context, which rotates and shifts everything @@ -227,7 +225,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .bus() .expect("Pipeline without bus. Shouldn't happen!"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/playbin.rs b/examples/src/bin/playbin.rs index 954002c4e..d3cf02286 100644 --- a/examples/src/bin/playbin.rs +++ b/examples/src/bin/playbin.rs @@ -106,7 +106,7 @@ fn example_main() { .set_state(gst::State::Playing) .expect("Unable to set the pipeline to the `Playing` state"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/queries.rs b/examples/src/bin/queries.rs index c340248f2..22de6b1c2 100644 --- a/examples/src/bin/queries.rs +++ b/examples/src/bin/queries.rs @@ -58,7 +58,7 @@ fn example_main() { //let pos = pipeline.query_position(gst::Format::Time).unwrap_or(-1); //let dur = pipeline.query_duration(gst::Format::Time).unwrap_or(-1); - let pos: gst::ClockTime = { + let pos: Option = { // Create a new position query and send it to the pipeline. // This will traverse all elements in the pipeline, until one feels // capable of answering the query. @@ -72,7 +72,7 @@ fn example_main() { .and_then(|pos| pos.try_into().ok()) .unwrap(); - let dur: gst::ClockTime = { + let dur: Option = { // Create a new duration query and send it to the pipeline. // This will traverse all elements in the pipeline, until one feels // capable of answering the query. @@ -86,7 +86,7 @@ fn example_main() { .and_then(|dur| dur.try_into().ok()) .unwrap(); - println!("{} / {}", pos, dur); + println!("{} / {}", pos.display(), dur.display()); glib::Continue(true) }); diff --git a/examples/src/bin/rtpfecclient.rs b/examples/src/bin/rtpfecclient.rs index e6c6bf5be..06d6747b3 100644 --- a/examples/src/bin/rtpfecclient.rs +++ b/examples/src/bin/rtpfecclient.rs @@ -248,7 +248,7 @@ fn example_main() -> Result<(), Error> { .set_state(gst::State::Playing) .expect("Unable to set the pipeline to the `Playing` state"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/rtpfecserver.rs b/examples/src/bin/rtpfecserver.rs index 6441728c3..bf4ed843d 100644 --- a/examples/src/bin/rtpfecserver.rs +++ b/examples/src/bin/rtpfecserver.rs @@ -171,7 +171,7 @@ fn example_main() -> Result<(), Error> { .set_state(gst::State::Playing) .expect("Unable to set the pipeline to the `Playing` state"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/subclass.rs b/examples/src/bin/subclass.rs index a539f0d79..89e2630be 100644 --- a/examples/src/bin/subclass.rs +++ b/examples/src/bin/subclass.rs @@ -314,7 +314,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { .bus() .expect("Pipeline without bus. Shouldn't happen!"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/tagsetter.rs b/examples/src/bin/tagsetter.rs index 1a1a78861..fea739965 100644 --- a/examples/src/bin/tagsetter.rs +++ b/examples/src/bin/tagsetter.rs @@ -85,7 +85,7 @@ fn example_main() -> Result<(), Error> { pipeline.set_state(gst::State::Playing)?; - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/thumbnail.rs b/examples/src/bin/thumbnail.rs index a39de1266..017414ef3 100644 --- a/examples/src/bin/thumbnail.rs +++ b/examples/src/bin/thumbnail.rs @@ -161,7 +161,7 @@ fn main_loop(pipeline: gst::Pipeline, position: u64) -> Result<(), Error> { let mut seeked = false; - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { @@ -171,7 +171,7 @@ fn main_loop(pipeline: gst::Pipeline, position: u64) -> Result<(), Error> { println!("Got AsyncDone message, seeking to {}s", position); if pipeline - .seek_simple(gst::SeekFlags::FLUSH, position * gst::SECOND) + .seek_simple(gst::SeekFlags::FLUSH, position * gst::ClockTime::SECOND) .is_err() { println!("Failed to seek, taking first frame"); diff --git a/examples/src/bin/toc.rs b/examples/src/bin/toc.rs index 535006cb5..7b34347ec 100644 --- a/examples/src/bin/toc.rs +++ b/examples/src/bin/toc.rs @@ -87,7 +87,7 @@ fn example_main() { // functionality like timeouts or GLib socket notifications, so this is sufficient. // The bus is manually operated by repeatedly calling timed_pop on the bus with // the desired timeout for when to stop waiting for new messages. (None = Wait forever) - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/transmux.rs b/examples/src/bin/transmux.rs index 977ea6666..718cdb141 100644 --- a/examples/src/bin/transmux.rs +++ b/examples/src/bin/transmux.rs @@ -146,7 +146,7 @@ fn example_main() -> Result<(), Error> { .bus() .expect("Pipeline without bus. Shouldn't happen!"); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/examples/src/bin/video_converter.rs b/examples/src/bin/video_converter.rs index ffcc6713e..3ffe49e73 100644 --- a/examples/src/bin/video_converter.rs +++ b/examples/src/bin/video_converter.rs @@ -52,7 +52,7 @@ fn example_main() { * although in this example the only error we'll hopefully * get is if the user closes the output window */ let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index bafa1d33a..91c4cf112 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -311,9 +311,10 @@ impl AppSink { #[doc(alias = "gst_base_sink_get_processing_deadline")] pub fn processing_deadline(&self) -> gst::ClockTime { unsafe { - from_glib(gst_base::ffi::gst_base_sink_get_processing_deadline( + try_from_glib(gst_base::ffi::gst_base_sink_get_processing_deadline( self.as_ptr() as *mut gst_base::ffi::GstBaseSink, )) + .expect("undefined processing_deadline") } } @@ -321,9 +322,10 @@ impl AppSink { #[doc(alias = "gst_base_sink_get_render_delay")] pub fn render_delay(&self) -> gst::ClockTime { unsafe { - from_glib(gst_base::ffi::gst_base_sink_get_render_delay( + try_from_glib(gst_base::ffi::gst_base_sink_get_render_delay( self.as_ptr() as *mut gst_base::ffi::GstBaseSink )) + .expect("undefined render_delay") } } @@ -958,7 +960,7 @@ impl Stream for AppSinkStream { }; app_sink - .try_pull_sample(gst::ClockTime::zero()) + .try_pull_sample(gst::ClockTime::ZERO) .map(|sample| Poll::Ready(Some(sample))) .unwrap_or_else(|| { if app_sink.is_eos() { diff --git a/gstreamer-app/src/app_src.rs b/gstreamer-app/src/app_src.rs index ddc755e30..76b2e2ae7 100644 --- a/gstreamer-app/src/app_src.rs +++ b/gstreamer-app/src/app_src.rs @@ -266,15 +266,23 @@ impl AppSrc { } #[doc(alias = "gst_app_src_set_latency")] - pub fn set_latency(&self, min: gst::ClockTime, max: gst::ClockTime) { + pub fn set_latency( + &self, + min: impl Into>, + max: impl Into>, + ) { unsafe { - ffi::gst_app_src_set_latency(self.to_glib_none().0, min.into_glib(), max.into_glib()); + ffi::gst_app_src_set_latency( + self.to_glib_none().0, + min.into().into_glib(), + max.into().into_glib(), + ); } } #[doc(alias = "get_latency")] #[doc(alias = "gst_app_src_get_latency")] - pub fn latency(&self) -> (gst::ClockTime, gst::ClockTime) { + pub fn latency(&self) -> (Option, Option) { unsafe { let mut min = mem::MaybeUninit::uninit(); let mut max = mem::MaybeUninit::uninit(); diff --git a/gstreamer-audio/src/audio_encoder.rs b/gstreamer-audio/src/audio_encoder.rs index 01a991c7b..ae0f9df9b 100644 --- a/gstreamer-audio/src/audio_encoder.rs +++ b/gstreamer-audio/src/audio_encoder.rs @@ -23,10 +23,6 @@ pub trait AudioEncoderExtManual: 'static { #[doc(alias = "get_allocator")] #[doc(alias = "gst_audio_encoder_get_allocator")] fn allocator(&self) -> (Option, gst::AllocationParams); - - #[doc(alias = "get_latency")] - #[doc(alias = "gst_audio_encoder_get_latency")] - fn latency(&self) -> (gst::ClockTime, gst::ClockTime); } impl> AudioEncoderExtManual for O { @@ -83,19 +79,4 @@ impl> AudioEncoderExtManual for O { (from_glib_full(allocator), params.into()) } } - - fn latency(&self) -> (gst::ClockTime, gst::ClockTime) { - unsafe { - let mut min = mem::MaybeUninit::uninit(); - let mut max = mem::MaybeUninit::uninit(); - ffi::gst_audio_encoder_get_latency( - self.as_ref().to_glib_none().0, - min.as_mut_ptr(), - max.as_mut_ptr(), - ); - let min = min.assume_init(); - let max = max.assume_init(); - (from_glib(min), from_glib(max)) - } - } } diff --git a/gstreamer-audio/src/audio_info.rs b/gstreamer-audio/src/audio_info.rs index d3b631fec..c904a5dd2 100644 --- a/gstreamer-audio/src/audio_info.rs +++ b/gstreamer-audio/src/audio_info.rs @@ -186,7 +186,7 @@ impl AudioInfo { if from_glib(ffi::gst_audio_info_convert( &self.0, src_val.format().into_glib(), - src_val.to_raw_value(), + src_val.into_raw_value(), U::default_format().into_glib(), dest_val.as_mut_ptr(), )) { @@ -210,7 +210,7 @@ impl AudioInfo { if from_glib(ffi::gst_audio_info_convert( &self.0, src_val.format().into_glib(), - src_val.to_raw_value(), + src_val.into_raw_value(), dest_fmt.into_glib(), dest_val.as_mut_ptr(), )) { diff --git a/gstreamer-audio/src/audio_meta.rs b/gstreamer-audio/src/audio_meta.rs index 00474d3e6..9a15a7e2c 100644 --- a/gstreamer-audio/src/audio_meta.rs +++ b/gstreamer-audio/src/audio_meta.rs @@ -301,17 +301,17 @@ mod tests { { let cmeta = AudioClippingMeta::add( buffer.get_mut().unwrap(), - gst::format::Default(Some(1)), - gst::format::Default(Some(2)), + gst::format::Default(1), + gst::format::Default(2), ); - assert_eq!(cmeta.start().try_into(), Ok(gst::format::Default(Some(1)))); - assert_eq!(cmeta.end().try_into(), Ok(gst::format::Default(Some(2)))); + assert_eq!(cmeta.start().try_into(), Ok(Some(gst::format::Default(1)))); + assert_eq!(cmeta.end().try_into(), Ok(Some(gst::format::Default(2)))); } { let cmeta = buffer.meta::().unwrap(); - assert_eq!(cmeta.start().try_into(), Ok(gst::format::Default(Some(1)))); - assert_eq!(cmeta.end().try_into(), Ok(gst::format::Default(Some(2)))); + assert_eq!(cmeta.start().try_into(), Ok(Some(gst::format::Default(1)))); + assert_eq!(cmeta.end().try_into(), Ok(Some(gst::format::Default(2)))); } } diff --git a/gstreamer-audio/src/audio_stream_align.rs b/gstreamer-audio/src/audio_stream_align.rs index fcab75413..02f823299 100644 --- a/gstreamer-audio/src/audio_stream_align.rs +++ b/gstreamer-audio/src/audio_stream_align.rs @@ -30,8 +30,8 @@ impl AudioStreamAlign { )); ( ret, - from_glib(out_timestamp.assume_init()), - from_glib(out_duration.assume_init()), + try_from_glib(out_timestamp.assume_init()).expect("undefined out_timestamp"), + try_from_glib(out_duration.assume_init()).expect("undefined out_duration"), out_sample_position.assume_init(), ) } diff --git a/gstreamer-audio/src/subclass/audio_src.rs b/gstreamer-audio/src/subclass/audio_src.rs index a5a4a1f2a..c2d1b2d70 100644 --- a/gstreamer-audio/src/subclass/audio_src.rs +++ b/gstreamer-audio/src/subclass/audio_src.rs @@ -40,7 +40,7 @@ pub trait AudioSrcImpl: AudioSrcImplExt + BaseSrcImpl { &self, src: &Self::Type, audio_data: &mut [u8], - ) -> Result<(u32, gst::ClockTime), LoggableError> { + ) -> Result<(u32, Option), LoggableError> { self.parent_read(src, audio_data) } @@ -63,7 +63,7 @@ pub trait AudioSrcImplExt: ObjectSubclass { &self, src: &Self::Type, audio_data: &mut [u8], - ) -> Result<(u32, gst::ClockTime), LoggableError>; + ) -> Result<(u32, Option), LoggableError>; fn parent_reset(&self, src: &Self::Type); } @@ -160,13 +160,13 @@ impl AudioSrcImplExt for T { &self, src: &Self::Type, buffer: &mut [u8], - ) -> Result<(u32, gst::ClockTime), LoggableError> { + ) -> Result<(u32, Option), LoggableError> { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioSrcClass; let f = match (*parent_class).read { Some(f) => f, - None => return Ok((0, gst::CLOCK_TIME_NONE)), + None => return Ok((0, gst::ClockTime::NONE)), }; let buffer_ptr = buffer.as_mut_ptr() as *mut _; let mut timestamp = mem::MaybeUninit::uninit(); @@ -319,7 +319,7 @@ unsafe extern "C" fn audiosrc_read( gst::panic_to_error!(&wrap, &imp.panicked(), 0, { let (res, timestamp_res) = imp .read(wrap.unsafe_cast_ref(), data_slice) - .unwrap_or((0, gst::CLOCK_TIME_NONE)); + .unwrap_or((0, gst::ClockTime::NONE)); *timestamp = timestamp_res.into_glib(); res diff --git a/gstreamer-base/src/adapter.rs b/gstreamer-base/src/adapter.rs index 870d48720..dab8f6923 100644 --- a/gstreamer-base/src/adapter.rs +++ b/gstreamer-base/src/adapter.rs @@ -302,7 +302,7 @@ impl UniqueAdapter { #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - pub fn dts_at_discont(&self) -> gst::ClockTime { + pub fn dts_at_discont(&self) -> Option { self.0.dts_at_discont() } @@ -356,11 +356,11 @@ impl UniqueAdapter { self.0.offset_at_discont() } - pub fn prev_dts(&self) -> (gst::ClockTime, u64) { + pub fn prev_dts(&self) -> (Option, u64) { self.0.prev_dts() } - pub fn prev_dts_at_offset(&self, offset: usize) -> (gst::ClockTime, u64) { + pub fn prev_dts_at_offset(&self, offset: usize) -> (Option, u64) { self.0.prev_dts_at_offset(offset) } @@ -370,17 +370,17 @@ impl UniqueAdapter { self.0.prev_offset() } - pub fn prev_pts(&self) -> (gst::ClockTime, u64) { + pub fn prev_pts(&self) -> (Option, u64) { self.0.prev_pts() } - pub fn prev_pts_at_offset(&self, offset: usize) -> (gst::ClockTime, u64) { + pub fn prev_pts_at_offset(&self, offset: usize) -> (Option, u64) { self.0.prev_pts_at_offset(offset) } #[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_10")))] - pub fn pts_at_discont(&self) -> gst::ClockTime { + pub fn pts_at_discont(&self) -> Option { self.0.pts_at_discont() } diff --git a/gstreamer-base/src/aggregator.rs b/gstreamer-base/src/aggregator.rs index 23aebfb1c..9f64f07e6 100644 --- a/gstreamer-base/src/aggregator.rs +++ b/gstreamer-base/src/aggregator.rs @@ -55,16 +55,16 @@ pub trait AggregatorExtManual: 'static { #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[doc(alias = "gst_aggregator_update_segment")] - fn update_segment(&self, segment: &gst::FormattedSegment); + fn update_segment(&self, segment: &gst::FormattedSegment); #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[doc(alias = "gst_aggregator_selected_samples")] fn selected_samples( &self, - pts: gst::ClockTime, - dts: gst::ClockTime, - duration: gst::ClockTime, + pts: impl Into>, + dts: impl Into>, + duration: impl Into>, info: Option<&gst::StructureRef>, ); @@ -75,9 +75,9 @@ pub trait AggregatorExtManual: 'static { F: Fn( &P, &gst::Segment, - gst::ClockTime, - gst::ClockTime, - gst::ClockTime, + Option, + Option, + Option, Option<&gst::StructureRef>, ) + Send + 'static, @@ -174,7 +174,7 @@ impl> AggregatorExtManual for O { } #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] - fn update_segment(&self, segment: &gst::FormattedSegment) { + fn update_segment(&self, segment: &gst::FormattedSegment) { unsafe { ffi::gst_aggregator_update_segment( self.as_ref().to_glib_none().0, @@ -187,17 +187,17 @@ impl> AggregatorExtManual for O { #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] fn selected_samples( &self, - pts: gst::ClockTime, - dts: gst::ClockTime, - duration: gst::ClockTime, + pts: impl Into>, + dts: impl Into>, + duration: impl Into>, info: Option<&gst::StructureRef>, ) { unsafe { ffi::gst_aggregator_selected_samples( self.as_ref().to_glib_none().0, - pts.into_glib(), - dts.into_glib(), - duration.into_glib(), + pts.into().into_glib(), + dts.into().into_glib(), + duration.into().into_glib(), info.as_ref() .map(|s| s.as_ptr() as *mut _) .unwrap_or(ptr::null_mut()), @@ -212,9 +212,9 @@ impl> AggregatorExtManual for O { F: Fn( &P, &gst::Segment, - gst::ClockTime, - gst::ClockTime, - gst::ClockTime, + Option, + Option, + Option, Option<&gst::StructureRef>, ) + Send + 'static, @@ -230,9 +230,9 @@ impl> AggregatorExtManual for O { F: Fn( &P, &gst::Segment, - gst::ClockTime, - gst::ClockTime, - gst::ClockTime, + Option, + Option, + Option, Option<&gst::StructureRef>, ) + Send + 'static, diff --git a/gstreamer-base/src/base_parse.rs b/gstreamer-base/src/base_parse.rs index b1b9e9197..e014eb4ba 100644 --- a/gstreamer-base/src/base_parse.rs +++ b/gstreamer-base/src/base_parse.rs @@ -88,7 +88,7 @@ impl> BaseParseExtManual for O { let ret = from_glib(ffi::gst_base_parse_convert_default( self.as_ref().to_glib_none().0, src_val.format().into_glib(), - src_val.to_raw_value(), + src_val.into_raw_value(), U::default_format().into_glib(), dest_val.as_mut_ptr(), )); @@ -111,7 +111,7 @@ impl> BaseParseExtManual for O { let ret = from_glib(ffi::gst_base_parse_convert_default( self.as_ref().to_glib_none().0, src_val.format().into_glib(), - src_val.to_raw_value(), + src_val.into_raw_value(), dest_format.into_glib(), dest_val.as_mut_ptr(), )); diff --git a/gstreamer-base/src/base_sink.rs b/gstreamer-base/src/base_sink.rs index b55f07e1d..052e7fc3b 100644 --- a/gstreamer-base/src/base_sink.rs +++ b/gstreamer-base/src/base_sink.rs @@ -12,7 +12,7 @@ pub trait BaseSinkExtManual: 'static { #[doc(alias = "gst_base_sink_query_latency")] fn query_latency( &self, - ) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError>; + ) -> Result<(bool, bool, Option, Option), glib::BoolError>; } impl> BaseSinkExtManual for O { @@ -26,7 +26,7 @@ impl> BaseSinkExtManual for O { fn query_latency( &self, - ) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError> { + ) -> Result<(bool, bool, Option, Option), glib::BoolError> { unsafe { let mut live = mem::MaybeUninit::uninit(); let mut upstream_live = mem::MaybeUninit::uninit(); diff --git a/gstreamer-base/src/base_src.rs b/gstreamer-base/src/base_src.rs index 15aca9b8e..e2c3eae54 100644 --- a/gstreamer-base/src/base_src.rs +++ b/gstreamer-base/src/base_src.rs @@ -16,7 +16,9 @@ pub trait BaseSrcExtManual: 'static { fn segment(&self) -> gst::Segment; #[doc(alias = "gst_base_src_query_latency")] - fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError>; + fn query_latency( + &self, + ) -> Result<(bool, Option, Option), glib::BoolError>; #[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] @@ -46,7 +48,9 @@ impl> BaseSrcExtManual for O { } } - fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError> { + fn query_latency( + &self, + ) -> Result<(bool, Option, Option), glib::BoolError> { unsafe { let mut live = mem::MaybeUninit::uninit(); let mut min_latency = mem::MaybeUninit::uninit(); diff --git a/gstreamer-base/src/subclass/aggregator.rs b/gstreamer-base/src/subclass/aggregator.rs index b21d86384..3e2bf9c89 100644 --- a/gstreamer-base/src/subclass/aggregator.rs +++ b/gstreamer-base/src/subclass/aggregator.rs @@ -115,7 +115,7 @@ pub trait AggregatorImpl: AggregatorImplExt + ElementImpl { self.parent_stop(aggregator) } - fn next_time(&self, aggregator: &Self::Type) -> gst::ClockTime { + fn next_time(&self, aggregator: &Self::Type) -> Option { self.parent_next_time(aggregator) } @@ -243,7 +243,7 @@ pub trait AggregatorImplExt: ObjectSubclass { fn parent_stop(&self, aggregator: &Self::Type) -> Result<(), gst::ErrorMessage>; - fn parent_next_time(&self, aggregator: &Self::Type) -> gst::ClockTime; + fn parent_next_time(&self, aggregator: &Self::Type) -> Option; fn parent_create_new_pad( &self, @@ -557,7 +557,7 @@ impl AggregatorImplExt for T { } } - fn parent_next_time(&self, aggregator: &Self::Type) -> gst::ClockTime { + fn parent_next_time(&self, aggregator: &Self::Type) -> Option { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GstAggregatorClass; @@ -569,7 +569,7 @@ impl AggregatorImplExt for T { .to_glib_none() .0)) }) - .unwrap_or(gst::CLOCK_TIME_NONE) + .unwrap_or(gst::ClockTime::NONE) } } @@ -987,7 +987,7 @@ unsafe extern "C" fn aggregator_get_next_time( let imp = instance.impl_(); let wrap: Borrowed = from_glib_borrow(ptr); - gst::panic_to_error!(&wrap, &imp.panicked(), gst::CLOCK_TIME_NONE, { + gst::panic_to_error!(&wrap, &imp.panicked(), gst::ClockTime::NONE, { imp.next_time(wrap.unsafe_cast_ref()) }) .into_glib() diff --git a/gstreamer-base/src/subclass/base_parse.rs b/gstreamer-base/src/subclass/base_parse.rs index e66778f63..256cbffe7 100644 --- a/gstreamer-base/src/subclass/base_parse.rs +++ b/gstreamer-base/src/subclass/base_parse.rs @@ -179,7 +179,7 @@ impl BaseParseImplExt for T { let res = from_glib(f( element.unsafe_cast_ref::().to_glib_none().0, src_val.format().into_glib(), - src_val.to_raw_value(), + src_val.into_raw_value(), dest_format.into_glib(), dest_val.as_mut_ptr(), )); @@ -314,7 +314,7 @@ unsafe extern "C" fn base_parse_convert( match res { Some(dest) => { - *dest_value = dest.to_raw_value(); + *dest_value = dest.into_raw_value(); true } _ => false, diff --git a/gstreamer-base/src/subclass/base_src.rs b/gstreamer-base/src/subclass/base_src.rs index cc04468c9..046d486da 100644 --- a/gstreamer-base/src/subclass/base_src.rs +++ b/gstreamer-base/src/subclass/base_src.rs @@ -39,7 +39,7 @@ pub trait BaseSrcImpl: BaseSrcImplExt + ElementImpl { &self, element: &Self::Type, buffer: &gst::BufferRef, - ) -> (gst::ClockTime, gst::ClockTime) { + ) -> (Option, Option) { self.parent_times(element, buffer) } @@ -122,7 +122,7 @@ pub trait BaseSrcImplExt: ObjectSubclass { &self, element: &Self::Type, buffer: &gst::BufferRef, - ) -> (gst::ClockTime, gst::ClockTime); + ) -> (Option, Option); fn parent_fill( &self, @@ -247,7 +247,7 @@ impl BaseSrcImplExt for T { &self, element: &Self::Type, buffer: &gst::BufferRef, - ) -> (gst::ClockTime, gst::ClockTime) { + ) -> (Option, Option) { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseSrcClass; @@ -267,7 +267,7 @@ impl BaseSrcImplExt for T { from_glib(stop.assume_init()), ) }) - .unwrap_or((gst::CLOCK_TIME_NONE, gst::CLOCK_TIME_NONE)) + .unwrap_or((gst::ClockTime::NONE, gst::ClockTime::NONE)) } } diff --git a/gstreamer-check/src/harness.rs b/gstreamer-check/src/harness.rs index ef8dd948a..99e372b34 100644 --- a/gstreamer-check/src/harness.rs +++ b/gstreamer-check/src/harness.rs @@ -243,7 +243,7 @@ impl Harness { #[doc(alias = "get_last_pushed_timestamp")] #[doc(alias = "gst_harness_get_last_pushed_timestamp")] - pub fn last_pushed_timestamp(&self) -> gst::ClockTime { + pub fn last_pushed_timestamp(&self) -> Option { unsafe { from_glib(ffi::gst_harness_get_last_pushed_timestamp(self.0.as_ptr())) } } @@ -346,7 +346,7 @@ impl Harness { } #[doc(alias = "gst_harness_query_latency")] - pub fn query_latency(&self) -> gst::ClockTime { + pub fn query_latency(&self) -> Option { unsafe { from_glib(ffi::gst_harness_query_latency(self.0.as_ptr())) } } diff --git a/gstreamer-controller/src/control_point.rs b/gstreamer-controller/src/control_point.rs index 9d1659b88..75af56a6e 100644 --- a/gstreamer-controller/src/control_point.rs +++ b/gstreamer-controller/src/control_point.rs @@ -18,7 +18,7 @@ impl ControlPoint { pub fn timestamp(&self) -> gst::ClockTime { unsafe { let ptr = self.to_glib_none().0; - from_glib((*ptr).timestamp) + try_from_glib((*ptr).timestamp).expect("undefined timestamp") } } diff --git a/gstreamer-pbutils/src/discoverer.rs b/gstreamer-pbutils/src/discoverer.rs index a8eb6bb12..293125e67 100644 --- a/gstreamer-pbutils/src/discoverer.rs +++ b/gstreamer-pbutils/src/discoverer.rs @@ -31,7 +31,7 @@ impl Discoverer { value.to_glib_none_mut().0, ); } - value.get().expect("Discoverer::get_property_timeout") + value.get().expect("undefined timeout") } #[doc(alias = "timeout")] diff --git a/gstreamer-player/src/player.rs b/gstreamer-player/src/player.rs index 8c52d6db3..58c4fc066 100644 --- a/gstreamer-player/src/player.rs +++ b/gstreamer-player/src/player.rs @@ -46,7 +46,7 @@ impl Player { } } - pub fn connect_duration_changed( + pub fn connect_duration_changed) + Send + 'static>( &self, f: F, ) -> SignalHandlerId { @@ -64,7 +64,7 @@ impl Player { } } - pub fn connect_position_updated( + pub fn connect_position_updated) + Send + 'static>( &self, f: F, ) -> SignalHandlerId { @@ -102,25 +102,25 @@ impl Player { } unsafe extern "C" fn duration_changed_trampoline< - F: Fn(&Player, gst::ClockTime) + Send + 'static, + F: Fn(&Player, Option) + Send + 'static, >( this: *mut ffi::GstPlayer, object: u64, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); - f(&from_glib_borrow(this), gst::ClockTime(Some(object))) + f(&from_glib_borrow(this), FromGlib::from_glib(object)) } unsafe extern "C" fn position_updated_trampoline< - F: Fn(&Player, gst::ClockTime) + Send + 'static, + F: Fn(&Player, Option) + Send + 'static, >( this: *mut ffi::GstPlayer, object: u64, f: glib::ffi::gpointer, ) { let f: &F = &*(f as *const F); - f(&from_glib_borrow(this), gst::ClockTime(Some(object))) + f(&from_glib_borrow(this), FromGlib::from_glib(object)) } unsafe extern "C" fn seek_done_trampoline( @@ -129,5 +129,8 @@ unsafe extern "C" fn seek_done_trampoline RTSPMediaImplExt for T { { None } else { - Some(from_glib(position.assume_init() as u64)) + from_glib(position.assume_init() as u64) } } else { None @@ -276,7 +276,7 @@ impl RTSPMediaImplExt for T { { None } else { - Some(from_glib(stop.assume_init() as u64)) + from_glib(stop.assume_init() as u64) } } else { None diff --git a/gstreamer-video/src/functions.rs b/gstreamer-video/src/functions.rs index f8cfce66a..8bf700355 100644 --- a/gstreamer-video/src/functions.rs +++ b/gstreamer-video/src/functions.rs @@ -34,7 +34,7 @@ pub fn convert_sample( pub fn convert_sample_async( sample: &gst::Sample, caps: &gst::Caps, - timeout: gst::ClockTime, + timeout: Option, func: F, ) where F: FnOnce(Result) + Send + 'static, @@ -46,7 +46,7 @@ pub fn convert_sample_async( pub fn convert_sample_async_local( sample: &gst::Sample, caps: &gst::Caps, - timeout: gst::ClockTime, + timeout: Option, func: F, ) where F: FnOnce(Result) + Send + 'static, @@ -61,7 +61,7 @@ pub fn convert_sample_async_local( unsafe fn convert_sample_async_unsafe( sample: &gst::Sample, caps: &gst::Caps, - timeout: gst::ClockTime, + timeout: Option, func: F, ) where F: FnOnce(Result) + 'static, @@ -104,7 +104,7 @@ unsafe fn convert_sample_async_unsafe( pub fn convert_sample_future( sample: &gst::Sample, caps: &gst::Caps, - timeout: gst::ClockTime, + timeout: Option, ) -> std::pin::Pin> + 'static>> { skip_assert_initialized!(); @@ -256,7 +256,7 @@ mod tests { let l_clone = l.clone(); let res_store = Arc::new(Mutex::new(None)); let res_store_clone = res_store.clone(); - convert_sample_async(&sample, &out_caps, gst::CLOCK_TIME_NONE, move |res| { + convert_sample_async(&sample, &out_caps, gst::ClockTime::NONE, move |res| { *res_store_clone.lock().unwrap() = Some(res); l_clone.quit(); }); diff --git a/gstreamer-video/src/video_codec_frame.rs b/gstreamer-video/src/video_codec_frame.rs index e38653497..a76334665 100644 --- a/gstreamer-video/src/video_codec_frame.rs +++ b/gstreamer-video/src/video_codec_frame.rs @@ -91,35 +91,35 @@ impl<'a> VideoCodecFrame<'a> { } #[doc(alias = "get_dts")] - pub fn dts(&self) -> gst::ClockTime { + pub fn dts(&self) -> Option { unsafe { from_glib((*self.to_glib_none().0).dts) } } - pub fn set_dts(&mut self, dts: gst::ClockTime) { + pub fn set_dts(&mut self, dts: impl Into>) { unsafe { - (*self.to_glib_none().0).dts = dts.into_glib(); + (*self.to_glib_none().0).dts = dts.into().into_glib(); } } #[doc(alias = "get_pts")] - pub fn pts(&self) -> gst::ClockTime { + pub fn pts(&self) -> Option { unsafe { from_glib((*self.to_glib_none().0).pts) } } - pub fn set_pts(&mut self, pts: gst::ClockTime) { + pub fn set_pts(&mut self, pts: impl Into>) { unsafe { - (*self.to_glib_none().0).pts = pts.into_glib(); + (*self.to_glib_none().0).pts = pts.into().into_glib(); } } #[doc(alias = "get_duration")] - pub fn duration(&self) -> gst::ClockTime { + pub fn duration(&self) -> Option { unsafe { from_glib((*self.to_glib_none().0).duration) } } - pub fn set_duration(&mut self, duration: gst::ClockTime) { + pub fn set_duration(&mut self, duration: impl Into>) { unsafe { - (*self.to_glib_none().0).duration = duration.into_glib(); + (*self.to_glib_none().0).duration = duration.into().into_glib(); } } @@ -188,7 +188,7 @@ impl<'a> VideoCodecFrame<'a> { } #[doc(alias = "get_deadline")] - pub fn deadline(&self) -> gst::ClockTime { + pub fn deadline(&self) -> Option { unsafe { from_glib((*self.to_glib_none().0).deadline) } } diff --git a/gstreamer-video/src/video_decoder.rs b/gstreamer-video/src/video_decoder.rs index 1defc97c9..d9cf0be89 100644 --- a/gstreamer-video/src/video_decoder.rs +++ b/gstreamer-video/src/video_decoder.rs @@ -51,8 +51,12 @@ pub trait VideoDecoderExtManual: 'static { fn drop_frame(&self, frame: VideoCodecFrame) -> Result; #[doc(alias = "get_latency")] - fn latency(&self) -> (gst::ClockTime, gst::ClockTime); - fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime); + fn latency(&self) -> (gst::ClockTime, Option); + fn set_latency( + &self, + min_latency: gst::ClockTime, + max_latency: impl Into>, + ); #[doc(alias = "get_output_state")] fn output_state(&self) -> Option>; @@ -152,7 +156,7 @@ impl> VideoDecoderExtManual for O { } #[doc(alias = "gst_video_decoder_get_latency")] - fn latency(&self) -> (gst::ClockTime, gst::ClockTime) { + fn latency(&self) -> (gst::ClockTime, Option) { let mut min_latency = gst::ffi::GST_CLOCK_TIME_NONE; let mut max_latency = gst::ffi::GST_CLOCK_TIME_NONE; @@ -163,17 +167,24 @@ impl> VideoDecoderExtManual for O { &mut max_latency, ); - (from_glib(min_latency), from_glib(max_latency)) + ( + try_from_glib(min_latency).expect("undefined min_latency"), + from_glib(max_latency), + ) } } #[doc(alias = "gst_video_decoder_set_latency")] - fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime) { + fn set_latency( + &self, + min_latency: gst::ClockTime, + max_latency: impl Into>, + ) { unsafe { ffi::gst_video_decoder_set_latency( self.as_ref().to_glib_none().0, min_latency.into_glib(), - max_latency.into_glib(), + max_latency.into().into_glib(), ); } } diff --git a/gstreamer-video/src/video_encoder.rs b/gstreamer-video/src/video_encoder.rs index d1bee4a66..8d3a280a1 100644 --- a/gstreamer-video/src/video_encoder.rs +++ b/gstreamer-video/src/video_encoder.rs @@ -46,9 +46,13 @@ pub trait VideoEncoderExtManual: 'static { #[doc(alias = "get_latency")] #[doc(alias = "gst_video_encoder_get_latency")] - fn latency(&self) -> (gst::ClockTime, gst::ClockTime); + fn latency(&self) -> (gst::ClockTime, Option); #[doc(alias = "gst_video_encoder_set_latency")] - fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime); + fn set_latency( + &self, + min_latency: gst::ClockTime, + max_latency: impl Into>, + ); #[doc(alias = "get_output_state")] #[doc(alias = "gst_video_encoder_get_output_state")] @@ -120,7 +124,7 @@ impl> VideoEncoderExtManual for O { } } - fn latency(&self) -> (gst::ClockTime, gst::ClockTime) { + fn latency(&self) -> (gst::ClockTime, Option) { let mut min_latency = gst::ffi::GST_CLOCK_TIME_NONE; let mut max_latency = gst::ffi::GST_CLOCK_TIME_NONE; @@ -131,16 +135,23 @@ impl> VideoEncoderExtManual for O { &mut max_latency, ); - (from_glib(min_latency), from_glib(max_latency)) + ( + try_from_glib(min_latency).expect("undefined min_latency"), + from_glib(max_latency), + ) } } - fn set_latency(&self, min_latency: gst::ClockTime, max_latency: gst::ClockTime) { + fn set_latency( + &self, + min_latency: gst::ClockTime, + max_latency: impl Into>, + ) { unsafe { ffi::gst_video_encoder_set_latency( self.as_ref().to_glib_none().0, min_latency.into_glib(), - max_latency.into_glib(), + max_latency.into().into_glib(), ); } } diff --git a/gstreamer-video/src/video_event.rs b/gstreamer-video/src/video_event.rs index f74c12e60..30c95acf6 100644 --- a/gstreamer-video/src/video_event.rs +++ b/gstreamer-video/src/video_event.rs @@ -68,9 +68,9 @@ pub struct DownstreamForceKeyUnitEventBuilder<'a> { seqnum: Option, running_time_offset: Option, other_fields: Vec<(&'a str, &'a (dyn ToSendValue + Sync))>, - timestamp: gst::ClockTime, - stream_time: gst::ClockTime, - running_time: gst::ClockTime, + timestamp: Option, + stream_time: Option, + running_time: Option, all_headers: bool, count: u32, } @@ -82,28 +82,31 @@ impl<'a> DownstreamForceKeyUnitEventBuilder<'a> { seqnum: None, running_time_offset: None, other_fields: Vec::new(), - timestamp: gst::CLOCK_TIME_NONE, - stream_time: gst::CLOCK_TIME_NONE, - running_time: gst::CLOCK_TIME_NONE, + timestamp: gst::ClockTime::NONE, + stream_time: gst::ClockTime::NONE, + running_time: gst::ClockTime::NONE, all_headers: true, count: 0, } } - pub fn timestamp(self, timestamp: gst::ClockTime) -> Self { - Self { timestamp, ..self } - } - - pub fn stream_time(self, stream_time: gst::ClockTime) -> Self { + pub fn timestamp(self, timestamp: impl Into>) -> Self { Self { - stream_time, + timestamp: timestamp.into(), ..self } } - pub fn running_time(self, running_time: gst::ClockTime) -> Self { + pub fn stream_time(self, stream_time: impl Into>) -> Self { Self { - running_time, + stream_time: stream_time.into(), + ..self + } + } + + pub fn running_time(self, running_time: impl Into>) -> Self { + Self { + running_time: running_time.into(), ..self } } @@ -132,9 +135,9 @@ impl<'a> DownstreamForceKeyUnitEventBuilder<'a> { #[derive(Clone, PartialEq, Eq, Debug)] pub struct DownstreamForceKeyUnitEvent { - pub timestamp: gst::ClockTime, - pub stream_time: gst::ClockTime, - pub running_time: gst::ClockTime, + pub timestamp: Option, + pub stream_time: Option, + pub running_time: Option, pub all_headers: bool, pub count: u32, } @@ -181,7 +184,7 @@ pub struct UpstreamForceKeyUnitEventBuilder<'a> { seqnum: Option, running_time_offset: Option, other_fields: Vec<(&'a str, &'a (dyn ToSendValue + Sync))>, - running_time: gst::ClockTime, + running_time: Option, all_headers: bool, count: u32, } @@ -193,15 +196,15 @@ impl<'a> UpstreamForceKeyUnitEventBuilder<'a> { seqnum: None, running_time_offset: None, other_fields: Vec::new(), - running_time: gst::CLOCK_TIME_NONE, + running_time: gst::ClockTime::NONE, all_headers: true, count: 0, } } - pub fn running_time(self, running_time: gst::ClockTime) -> Self { + pub fn running_time(self, running_time: impl Into>) -> Self { Self { - running_time, + running_time: running_time.into(), ..self } } @@ -228,7 +231,7 @@ impl<'a> UpstreamForceKeyUnitEventBuilder<'a> { #[derive(Clone, PartialEq, Eq, Debug)] pub struct UpstreamForceKeyUnitEvent { - pub running_time: gst::ClockTime, + pub running_time: Option, pub all_headers: bool, pub count: u32, } diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index ecb614f7e..2ca78aeb9 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -761,7 +761,7 @@ impl VideoInfo { if from_glib(ffi::gst_video_info_convert( &self.0 as *const _ as *mut _, src_val.format().into_glib(), - src_val.to_raw_value(), + src_val.into_raw_value(), U::default_format().into_glib(), dest_val.as_mut_ptr(), )) { @@ -785,7 +785,7 @@ impl VideoInfo { if from_glib(ffi::gst_video_info_convert( &self.0 as *const _ as *mut _, src_val.format().into_glib(), - src_val.to_raw_value(), + src_val.into_raw_value(), dest_fmt.into_glib(), dest_val.as_mut_ptr(), )) { diff --git a/gstreamer/src/buffer.rs b/gstreamer/src/buffer.rs index 680c5f47b..68194b34b 100644 --- a/gstreamer/src/buffer.rs +++ b/gstreamer/src/buffer.rs @@ -1352,10 +1352,7 @@ mod tests { true }); - assert_eq!( - &[Some(ClockTime::ZERO), Some(ClockTime::SECOND)][..], - &res[..] - ); + assert_eq!(&[ClockTime::ZERO, ClockTime::SECOND][..], &res[..]); } #[cfg(any(feature = "v1_14", feature = "dox"))] @@ -1387,17 +1384,14 @@ mod tests { .downcast_ref::() .unwrap(); res.push(meta.timestamp()); - if let Some(ClockTime::SECOND) = meta.timestamp() { + if meta.timestamp() == ClockTime::SECOND { Ok(false) } else { Ok(true) } }); - assert_eq!( - &[Some(ClockTime::ZERO), Some(ClockTime::SECOND)][..], - &res[..] - ); + assert_eq!(&[ClockTime::ZERO, ClockTime::SECOND][..], &res[..]); let mut res = vec![]; buffer.foreach_meta(|meta| { @@ -1408,6 +1402,6 @@ mod tests { true }); - assert_eq!(&[Some(ClockTime::ZERO)][..], &res[..]); + assert_eq!(&[ClockTime::ZERO][..], &res[..]); } } diff --git a/gstreamer/src/bus.rs b/gstreamer/src/bus.rs index d8907b9fd..fe6416aee 100644 --- a/gstreamer/src/bus.rs +++ b/gstreamer/src/bus.rs @@ -206,8 +206,11 @@ impl Bus { self.iter_timed(Some(crate::ClockTime::ZERO)) } - pub fn iter_timed(&self, timeout: Option) -> Iter { - Iter { bus: self, timeout } + pub fn iter_timed(&self, timeout: impl Into>) -> Iter { + Iter { + bus: self, + timeout: timeout.into(), + } } pub fn iter_filtered<'a>( @@ -219,7 +222,7 @@ impl Bus { pub fn iter_timed_filtered<'a>( &'a self, - timeout: Option, + timeout: impl Into>, msg_types: &'a [MessageType], ) -> impl Iterator + 'a { self.iter_timed(timeout) @@ -228,11 +231,11 @@ impl Bus { pub fn timed_pop_filtered( &self, - timeout: Option, + timeout: impl Into> + Clone, msg_types: &[MessageType], ) -> Option { loop { - let msg = self.timed_pop(timeout)?; + let msg = self.timed_pop(timeout.clone())?; if msg_types.contains(&msg.type_()) { return Some(msg); } diff --git a/gstreamer/src/clock.rs b/gstreamer/src/clock.rs index a3e932ad6..17130c5bc 100644 --- a/gstreamer/src/clock.rs +++ b/gstreamer/src/clock.rs @@ -35,8 +35,11 @@ glib::wrapper! { impl ClockId { #[doc(alias = "get_time")] #[doc(alias = "gst_clock_id_get_time")] - pub fn time(&self) -> Option { - unsafe { from_glib(ffi::gst_clock_id_get_time(self.to_glib_none().0)) } + pub fn time(&self) -> ClockTime { + unsafe { + try_from_glib(ffi::gst_clock_id_get_time(self.to_glib_none().0)) + .expect("undefined time") + } } #[doc(alias = "gst_clock_id_unschedule")] @@ -242,7 +245,7 @@ impl PeriodicClockId { pub fn interval(&self) -> ClockTime { unsafe { let ptr: *mut ffi::GstClockEntry = self.to_glib_none().0 as *mut _; - Option::<_>::from_glib((*ptr).interval).expect("undefined interval") + try_from_glib((*ptr).interval).expect("undefined interval") } } @@ -360,10 +363,10 @@ impl Clock { cexternal: ClockTime, cnum: ClockTime, cdenom: ClockTime, - ) -> Option { + ) -> ClockTime { skip_assert_initialized!(); unsafe { - from_glib(ffi::gst_clock_adjust_with_calibration( + try_from_glib(ffi::gst_clock_adjust_with_calibration( ptr::null_mut(), internal_target.into_glib(), cinternal.into_glib(), @@ -371,6 +374,7 @@ impl Clock { cnum.into_glib(), cdenom.into_glib(), )) + .expect("undefined ClockTime") } } @@ -381,10 +385,10 @@ impl Clock { cexternal: ClockTime, cnum: ClockTime, cdenom: ClockTime, - ) -> Option { + ) -> ClockTime { skip_assert_initialized!(); unsafe { - from_glib(ffi::gst_clock_unadjust_with_calibration( + try_from_glib(ffi::gst_clock_unadjust_with_calibration( ptr::null_mut(), external_target.into_glib(), cinternal.into_glib(), @@ -392,6 +396,7 @@ impl Clock { cnum.into_glib(), cdenom.into_glib(), )) + .expect("undefined ClockTime") } } } diff --git a/gstreamer/src/element.rs b/gstreamer/src/element.rs index b9eb4f52c..5ddd5f97d 100644 --- a/gstreamer/src/element.rs +++ b/gstreamer/src/element.rs @@ -784,7 +784,9 @@ impl> ElementExtManual for O { let base_time = self.base_time(); let clock_time = self.current_clock_time(); - clock_time.zip(base_time).map(|(ct, bt)| ct - bt) + clock_time + .zip(base_time) + .and_then(|(ct, bt)| ct.checked_sub(bt)) } fn current_clock_time(&self) -> Option { diff --git a/gstreamer/src/event.rs b/gstreamer/src/event.rs index 90fb920b8..e339048f8 100644 --- a/gstreamer/src/event.rs +++ b/gstreamer/src/event.rs @@ -11,7 +11,9 @@ use std::num::NonZeroU32; use std::ops::Deref; use std::ptr; -use glib::translate::{from_glib, from_glib_full, from_glib_none, IntoGlib, ToGlibPtr}; +use glib::translate::{ + from_glib, from_glib_full, from_glib_none, try_from_glib, IntoGlib, ToGlibPtr, +}; use glib::value::ToSendValue; #[cfg(any(feature = "v1_10", feature = "dox"))] @@ -766,17 +768,20 @@ impl<'a> SegmentDone<'a> { declare_concrete_event!(Gap); impl<'a> Gap<'a> { #[allow(clippy::new_ret_no_self)] - pub fn new(timestamp: crate::ClockTime, duration: crate::ClockTime) -> Event { + pub fn new( + timestamp: crate::ClockTime, + duration: impl Into>, + ) -> Event { skip_assert_initialized!(); - Self::builder(timestamp, duration).build() + Self::builder(timestamp).duration(duration).build() } - pub fn builder(timestamp: crate::ClockTime, duration: crate::ClockTime) -> GapBuilder<'a> { + pub fn builder(timestamp: crate::ClockTime) -> GapBuilder<'a> { assert_initialized_main_thread!(); - GapBuilder::new(timestamp, duration) + GapBuilder::new(timestamp) } - pub fn get(&self) -> (Option, Option) { + pub fn get(&self) -> (crate::ClockTime, Option) { unsafe { let mut timestamp = mem::MaybeUninit::uninit(); let mut duration = mem::MaybeUninit::uninit(); @@ -788,7 +793,7 @@ impl<'a> Gap<'a> { ); ( - from_glib(timestamp.assume_init()), + try_from_glib(timestamp.assume_init()).expect("undefined timestamp"), from_glib(duration.assume_init()), ) } @@ -802,20 +807,17 @@ impl<'a> Qos<'a> { type_: crate::QOSType, proportion: f64, diff: i64, - timestamp: crate::ClockTime, + timestamp: impl Into>, ) -> Event { skip_assert_initialized!(); - Self::builder(type_, proportion, diff, timestamp).build() + Self::builder(type_, proportion, diff) + .timestamp(timestamp) + .build() } - pub fn builder( - type_: crate::QOSType, - proportion: f64, - diff: i64, - timestamp: crate::ClockTime, - ) -> QosBuilder<'a> { + pub fn builder(type_: crate::QOSType, proportion: f64, diff: i64) -> QosBuilder<'a> { assert_initialized_main_thread!(); - QosBuilder::new(type_, proportion, diff, timestamp) + QosBuilder::new(type_, proportion, diff) } pub fn get(&self) -> (crate::QOSType, f64, i64, Option) { @@ -962,13 +964,13 @@ impl<'a> Latency<'a> { #[doc(alias = "get_latency")] #[doc(alias = "gst_event_parse_latency")] - pub fn latency(&self) -> Option { + pub fn latency(&self) -> crate::ClockTime { unsafe { let mut latency = mem::MaybeUninit::uninit(); ffi::gst_event_parse_latency(self.as_mut_ptr(), latency.as_mut_ptr()); - from_glib(latency.assume_init()) + try_from_glib(latency.assume_init()).expect("undefined latency") } } } @@ -1616,19 +1618,24 @@ impl<'a> SegmentDoneBuilder<'a> { pub struct GapBuilder<'a> { builder: EventBuilder<'a>, timestamp: crate::ClockTime, - duration: crate::ClockTime, + duration: Option, } impl<'a> GapBuilder<'a> { - fn new(timestamp: crate::ClockTime, duration: crate::ClockTime) -> Self { + fn new(timestamp: crate::ClockTime) -> Self { skip_assert_initialized!(); Self { builder: EventBuilder::new(), timestamp, - duration, + duration: None, } } + pub fn duration(mut self, duration: impl Into>) -> Self { + self.duration = duration.into(); + self + } + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_gap( s.timestamp.into_glib(), s.duration.into_glib() @@ -1640,21 +1647,26 @@ pub struct QosBuilder<'a> { type_: crate::QOSType, proportion: f64, diff: i64, - timestamp: crate::ClockTime, + timestamp: Option, } impl<'a> QosBuilder<'a> { - fn new(type_: crate::QOSType, proportion: f64, diff: i64, timestamp: crate::ClockTime) -> Self { + fn new(type_: crate::QOSType, proportion: f64, diff: i64) -> Self { skip_assert_initialized!(); Self { builder: EventBuilder::new(), type_, proportion, diff, - timestamp, + timestamp: None, } } + pub fn timestamp(mut self, timestamp: impl Into>) -> Self { + self.timestamp = timestamp.into(); + self + } + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_qos( s.type_.into_glib(), s.proportion, @@ -1697,6 +1709,14 @@ impl<'a> SeekBuilder<'a> { } } + pub fn trickmode_interval( + mut self, + trickmode_interval: impl Into>, + ) -> Self { + self.trickmode_interval = trickmode_interval.into(); + self + } + event_builder_generic_impl!(|s: &Self| { #[allow(clippy::let_and_return)] { diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index 8f62498b7..f85018b6a 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -17,7 +17,7 @@ use std::ops::Deref; use std::ptr; use glib::translate::{ - from_glib, from_glib_full, from_glib_none, mut_override, IntoGlib, ToGlibPtr, + from_glib, from_glib_full, from_glib_none, mut_override, try_from_glib, IntoGlib, ToGlibPtr, }; mini_object_wrapper!(Message, MessageRef, ffi::GstMessage, || { @@ -945,14 +945,14 @@ impl<'a> AsyncStart<'a> { declare_concrete_message!(AsyncDone); impl<'a> AsyncDone<'a> { #[allow(clippy::new_ret_no_self)] - pub fn new(running_time: crate::ClockTime) -> Message { + pub fn new(running_time: impl Into>) -> Message { skip_assert_initialized!(); - Self::builder(running_time).build() + Self::builder().running_time(running_time).build() } - pub fn builder(running_time: crate::ClockTime) -> AsyncDoneBuilder<'a> { + pub fn builder() -> AsyncDoneBuilder<'a> { assert_initialized_main_thread!(); - AsyncDoneBuilder::new(running_time) + AsyncDoneBuilder::new() } #[doc(alias = "get_running_time")] @@ -1055,24 +1055,23 @@ impl<'a> Qos<'a> { #[allow(clippy::new_ret_no_self)] pub fn new( live: bool, - running_time: crate::ClockTime, - stream_time: crate::ClockTime, - timestamp: crate::ClockTime, - duration: crate::ClockTime, + running_time: impl Into>, + stream_time: impl Into>, + timestamp: impl Into>, + duration: impl Into>, ) -> Message { skip_assert_initialized!(); - Self::builder(live, running_time, stream_time, timestamp, duration).build() + Self::builder(live) + .running_time(running_time) + .stream_time(stream_time) + .timestamp(timestamp) + .duration(duration) + .build() } - pub fn builder( - live: bool, - running_time: crate::ClockTime, - stream_time: crate::ClockTime, - timestamp: crate::ClockTime, - duration: crate::ClockTime, - ) -> QosBuilder<'a> { + pub fn builder(live: bool) -> QosBuilder<'a> { assert_initialized_main_thread!(); - QosBuilder::new(live, running_time, stream_time, timestamp, duration) + QosBuilder::new(live) } pub fn get( @@ -1241,13 +1240,13 @@ impl<'a> ResetTime<'a> { } #[doc(alias = "get_running_time")] - pub fn running_time(&self) -> Option { + pub fn running_time(&self) -> crate::ClockTime { unsafe { let mut running_time = mem::MaybeUninit::uninit(); ffi::gst_message_parse_reset_time(self.as_mut_ptr(), running_time.as_mut_ptr()); - from_glib(running_time.assume_init()) + try_from_glib(running_time.assume_init()).expect("undefined running_time") } } } @@ -2346,18 +2345,23 @@ impl<'a> AsyncStartBuilder<'a> { pub struct AsyncDoneBuilder<'a> { builder: MessageBuilder<'a>, - running_time: crate::ClockTime, + running_time: Option, } impl<'a> AsyncDoneBuilder<'a> { - fn new(running_time: crate::ClockTime) -> Self { + fn new() -> Self { skip_assert_initialized!(); Self { builder: MessageBuilder::new(), - running_time, + running_time: None, } } + pub fn running_time(mut self, running_time: impl Into>) -> Self { + self.running_time = running_time.into(); + self + } + message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_async_done( src, s.running_time.into_glib() @@ -2426,35 +2430,49 @@ impl<'a> StepStartBuilder<'a> { pub struct QosBuilder<'a> { builder: MessageBuilder<'a>, live: bool, - running_time: crate::ClockTime, - stream_time: crate::ClockTime, - timestamp: crate::ClockTime, - duration: crate::ClockTime, + running_time: Option, + stream_time: Option, + timestamp: Option, + duration: Option, values: Option<(i64, f64, i32)>, stats: Option<(GenericFormattedValue, GenericFormattedValue)>, } impl<'a> QosBuilder<'a> { - fn new( - live: bool, - running_time: crate::ClockTime, - stream_time: crate::ClockTime, - timestamp: crate::ClockTime, - duration: crate::ClockTime, - ) -> Self { + fn new(live: bool) -> Self { skip_assert_initialized!(); Self { builder: MessageBuilder::new(), live, - running_time, - stream_time, - timestamp, - duration, + running_time: None, + stream_time: None, + timestamp: None, + duration: None, values: None, stats: None, } } + pub fn running_time(mut self, running_time: impl Into>) -> Self { + self.running_time = running_time.into(); + self + } + + pub fn stream_time(mut self, stream_time: impl Into>) -> Self { + self.stream_time = stream_time.into(); + self + } + + pub fn timestamp(mut self, timestamp: impl Into>) -> Self { + self.timestamp = timestamp.into(); + self + } + + pub fn duration(mut self, duration: impl Into>) -> Self { + self.duration = duration.into(); + self + } + pub fn values(self, jitter: i64, proportion: f64, quality: i32) -> Self { Self { values: Some((jitter, proportion, quality)), diff --git a/gstreamer/src/meta.rs b/gstreamer/src/meta.rs index 4d7498753..ca5a1be24 100644 --- a/gstreamer/src/meta.rs +++ b/gstreamer/src/meta.rs @@ -16,10 +16,10 @@ use crate::CapsRef; #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] use crate::ClockTime; +use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr}; #[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_14")))] -use glib::translate::IntoGlib; -use glib::translate::{from_glib, from_glib_none, FromGlib, ToGlibPtr}; +use glib::translate::{try_from_glib, IntoGlib}; pub unsafe trait MetaAPI: Sync + Send + Sized { type GstType; @@ -403,8 +403,8 @@ impl ReferenceTimestampMeta { } #[doc(alias = "get_timestamp")] - pub fn timestamp(&self) -> Option { - unsafe { from_glib(self.0.timestamp) } + pub fn timestamp(&self) -> ClockTime { + unsafe { try_from_glib(self.0.timestamp).expect("undefined timestamp") } } #[doc(alias = "get_duration")] diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index b258023d1..dadd1b39a 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -324,7 +324,7 @@ impl Default for Latency { impl Latency { #[doc(alias = "get_result")] - pub fn result(&self) -> (bool, Option, Option) { + pub fn result(&self) -> (bool, crate::ClockTime, Option) { unsafe { let mut live = mem::MaybeUninit::uninit(); let mut min = mem::MaybeUninit::uninit(); @@ -339,7 +339,7 @@ impl Latency { ( from_glib(live.assume_init()), - from_glib(min.assume_init()), + try_from_glib(min.assume_init()).expect("undefined min latency"), from_glib(max.assume_init()), ) } @@ -348,13 +348,18 @@ impl Latency { impl Latency { #[doc(alias = "gst_query_set_latency")] - pub fn set(&mut self, live: bool, min: crate::ClockTime, max: crate::ClockTime) { + pub fn set( + &mut self, + live: bool, + min: crate::ClockTime, + max: impl Into>, + ) { unsafe { ffi::gst_query_set_latency( self.0.as_mut_ptr(), live.into_glib(), min.into_glib(), - max.into_glib(), + max.into().into_glib(), ); } } diff --git a/gstreamer/src/subclass/clock.rs b/gstreamer/src/subclass/clock.rs index bce62825e..2c1a89ee8 100644 --- a/gstreamer/src/subclass/clock.rs +++ b/gstreamer/src/subclass/clock.rs @@ -18,15 +18,15 @@ pub trait ClockImpl: ClockImplExt + ObjectImpl + Send + Sync { clock: &Self::Type, old_resolution: ClockTime, new_resolution: ClockTime, - ) -> Option { + ) -> ClockTime { self.parent_change_resolution(clock, old_resolution, new_resolution) } - fn resolution(&self, clock: &Self::Type) -> Option { + fn resolution(&self, clock: &Self::Type) -> ClockTime { self.parent_resolution(clock) } - fn internal_time(&self, clock: &Self::Type) -> Option { + fn internal_time(&self, clock: &Self::Type) -> ClockTime { self.parent_internal_time(clock) } @@ -53,11 +53,11 @@ pub trait ClockImplExt: ObjectSubclass { clock: &Self::Type, old_resolution: ClockTime, new_resolution: ClockTime, - ) -> Option; + ) -> ClockTime; - fn parent_resolution(&self, clock: &Self::Type) -> Option; + fn parent_resolution(&self, clock: &Self::Type) -> ClockTime; - fn parent_internal_time(&self, clock: &Self::Type) -> Option; + fn parent_internal_time(&self, clock: &Self::Type) -> ClockTime; fn parent_wait( &self, @@ -85,48 +85,51 @@ impl ClockImplExt for T { clock: &Self::Type, old_resolution: ClockTime, new_resolution: ClockTime, - ) -> Option { + ) -> ClockTime { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; if let Some(func) = (*parent_class).change_resolution { - from_glib(func( + try_from_glib(func( clock.unsafe_cast_ref::().to_glib_none().0, old_resolution.into_glib(), new_resolution.into_glib(), )) + .expect("undefined resolution") } else { self.resolution(clock) } } } - fn parent_resolution(&self, clock: &Self::Type) -> Option { + fn parent_resolution(&self, clock: &Self::Type) -> ClockTime { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; - from_glib( + try_from_glib( (*parent_class) .get_resolution .map(|f| f(clock.unsafe_cast_ref::().to_glib_none().0)) .unwrap_or(1), ) + .expect("undefined resolution") } } - fn parent_internal_time(&self, clock: &Self::Type) -> Option { + fn parent_internal_time(&self, clock: &Self::Type) -> ClockTime { unsafe { let data = Self::type_data(); let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; - from_glib( + try_from_glib( (*parent_class) .get_internal_time .map(|f| f(clock.unsafe_cast_ref::().to_glib_none().0)) .unwrap_or(0), ) + .expect("undefined internal_time") } } diff --git a/tutorials/src/bin/basic-tutorial-1.rs b/tutorials/src/bin/basic-tutorial-1.rs index 5346c9d01..a3df4a251 100644 --- a/tutorials/src/bin/basic-tutorial-1.rs +++ b/tutorials/src/bin/basic-tutorial-1.rs @@ -19,7 +19,7 @@ fn tutorial_main() { // Wait until error or EOS let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/tutorials/src/bin/basic-tutorial-13.rs b/tutorials/src/bin/basic-tutorial-13.rs index 0d5b010b1..2247fd141 100644 --- a/tutorials/src/bin/basic-tutorial-13.rs +++ b/tutorials/src/bin/basic-tutorial-13.rs @@ -181,7 +181,7 @@ USAGE: Choose one of the following options, then press enter: .get::>() { // Send the event - let step = Step::new(gst::format::Buffers(Some(1)), rate.abs(), true, false); + let step = Step::new(gst::format::Buffers(1), rate.abs(), true, false); video_sink.send_event(step); println!("Stepping one frame\r"); } diff --git a/tutorials/src/bin/basic-tutorial-2.rs b/tutorials/src/bin/basic-tutorial-2.rs index 77a3b0694..0cb0a8067 100644 --- a/tutorials/src/bin/basic-tutorial-2.rs +++ b/tutorials/src/bin/basic-tutorial-2.rs @@ -30,7 +30,7 @@ fn tutorial_main() { // Wait until error or EOS let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/tutorials/src/bin/basic-tutorial-3.rs b/tutorials/src/bin/basic-tutorial-3.rs index 69c04ead5..85686b4b0 100644 --- a/tutorials/src/bin/basic-tutorial-3.rs +++ b/tutorials/src/bin/basic-tutorial-3.rs @@ -78,7 +78,7 @@ fn tutorial_main() { // Wait until error or EOS let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/tutorials/src/bin/basic-tutorial-4.rs b/tutorials/src/bin/basic-tutorial-4.rs index 5a4a598f5..60562bfed 100644 --- a/tutorials/src/bin/basic-tutorial-4.rs +++ b/tutorials/src/bin/basic-tutorial-4.rs @@ -6,12 +6,18 @@ use std::io::Write; mod tutorials_common; struct CustomData { - playbin: gst::Element, // Our one and only element - playing: bool, // Are we in the PLAYING state? - terminate: bool, // Should we terminate execution? - seek_enabled: bool, // Is seeking enabled for this media? - seek_done: bool, // Have we performed the seek already? - duration: gst::ClockTime, // How long does this media last, in nanoseconds + /// Our one and only element + playbin: gst::Element, + /// Are we in the PLAYING state? + playing: bool, + /// Should we terminate execution? + terminate: bool, + /// Is seeking enabled for this media? + seek_enabled: bool, + /// Have we performed the seek already? + seek_done: bool, + /// How long does this media last, in nanoseconds + duration: Option, } fn tutorial_main() { @@ -42,11 +48,11 @@ fn tutorial_main() { terminate: false, seek_enabled: false, seek_done: false, - duration: gst::CLOCK_TIME_NONE, + duration: gst::ClockTime::NONE, }; while !custom_data.terminate { - let msg = bus.timed_pop(100 * gst::MSECOND); + let msg = bus.timed_pop(100 * gst::ClockTime::MSECOND); match msg { Some(msg) => { @@ -65,7 +71,11 @@ fn tutorial_main() { } // Print current position and total duration - print!("\rPosition {} / {}", position, custom_data.duration); + print!( + "\rPosition {} / {}", + position, + custom_data.duration.display() + ); io::stdout().flush().unwrap(); if custom_data.seek_enabled @@ -77,7 +87,7 @@ fn tutorial_main() { .playbin .seek_simple( gst::SeekFlags::FLUSH | gst::SeekFlags::KEY_UNIT, - 30 * gst::SECOND, + 30 * gst::ClockTime::SECOND, ) .expect("Failed to seek."); custom_data.seek_done = true; @@ -113,7 +123,7 @@ fn handle_message(custom_data: &mut CustomData, msg: &gst::Message) { } MessageView::DurationChanged(_) => { // The duration has changed, mark the current one as invalid - custom_data.duration = gst::CLOCK_TIME_NONE; + custom_data.duration = gst::ClockTime::NONE; } MessageView::StateChanged(state_changed) => { if state_changed @@ -136,7 +146,7 @@ fn handle_message(custom_data: &mut CustomData, msg: &gst::Message) { let (seekable, start, end) = seeking.result(); custom_data.seek_enabled = seekable; if seekable { - println!("Seeking is ENABLED from {:?} to {:?}", start, end) + println!("Seeking is ENABLED from {} to {}", start, end) } else { println!("Seeking is DISABLED for this stream.") } diff --git a/tutorials/src/bin/basic-tutorial-5.rs b/tutorials/src/bin/basic-tutorial-5.rs index 50ab9c301..a32c10bcf 100644 --- a/tutorials/src/bin/basic-tutorial-5.rs +++ b/tutorials/src/bin/basic-tutorial-5.rs @@ -123,7 +123,7 @@ mod tutorial5 { if pipeline .seek_simple( gst::SeekFlags::FLUSH | gst::SeekFlags::KEY_UNIT, - value * gst::SECOND, + value * gst::ClockTime::SECOND, ) .is_err() { diff --git a/tutorials/src/bin/basic-tutorial-6.rs b/tutorials/src/bin/basic-tutorial-6.rs index e08ae91f3..bca32490e 100644 --- a/tutorials/src/bin/basic-tutorial-6.rs +++ b/tutorials/src/bin/basic-tutorial-6.rs @@ -117,7 +117,7 @@ fn tutorial_main() { // Wait until error, EOS or State Change let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/tutorials/src/bin/basic-tutorial-7.rs b/tutorials/src/bin/basic-tutorial-7.rs index 8aa5f0d93..3bc3f23ef 100644 --- a/tutorials/src/bin/basic-tutorial-7.rs +++ b/tutorials/src/bin/basic-tutorial-7.rs @@ -67,7 +67,7 @@ fn tutorial_main() { .set_state(gst::State::Playing) .expect("Unable to set the pipeline to the `Playing` state"); let bus = pipeline.bus().unwrap(); - for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { + for msg in bus.iter_timed(gst::ClockTime::NONE) { use gst::MessageView; match msg.view() { diff --git a/tutorials/src/bin/basic-tutorial-8.rs b/tutorials/src/bin/basic-tutorial-8.rs index 14e182da1..ed24e454e 100644 --- a/tutorials/src/bin/basic-tutorial-8.rs +++ b/tutorials/src/bin/basic-tutorial-8.rs @@ -160,10 +160,10 @@ fn main() { let mut data = data.lock().unwrap(); let mut buffer = gst::Buffer::with_size(CHUNK_SIZE).unwrap(); let num_samples = CHUNK_SIZE / 2; /* Each sample is 16 bits */ - let pts = gst::SECOND + let pts = gst::ClockTime::SECOND .mul_div_floor(data.num_samples, u64::from(SAMPLE_RATE)) .expect("u64 overflow"); - let duration = gst::SECOND + let duration = gst::ClockTime::SECOND .mul_div_floor(num_samples as u64, u64::from(SAMPLE_RATE)) .expect("u64 overflow"); diff --git a/tutorials/src/bin/basic-tutorial-9.rs b/tutorials/src/bin/basic-tutorial-9.rs index ddc32fb1e..40cac7b41 100644 --- a/tutorials/src/bin/basic-tutorial-9.rs +++ b/tutorials/src/bin/basic-tutorial-9.rs @@ -150,7 +150,7 @@ fn run_discoverer() -> Result<(), Error> { println!("Discovering {}", uri); let loop_ = glib::MainLoop::new(None, false); - let timeout = 5 * gst::SECOND; + let timeout = 5 * gst::ClockTime::SECOND; let discoverer = gst_pbutils::Discoverer::new(timeout)?; discoverer.connect_discovered(on_discovered); let loop_clone = loop_.clone(); diff --git a/tutorials/src/bin/playback-tutorial-4.rs b/tutorials/src/bin/playback-tutorial-4.rs index e1a5aa04e..ab97c379a 100644 --- a/tutorials/src/bin/playback-tutorial-4.rs +++ b/tutorials/src/bin/playback-tutorial-4.rs @@ -130,15 +130,15 @@ fn tutorial_main() -> Result<(), Error> { let start = range.0; let stop = range.1; let start = if let Percent(start) = start { - start.unwrap() + *start.unwrap() } else { 0 - } / gst::FORMAT_PERCENT_MAX; + } / gst::format::Percent::MAX; let stop = if let Percent(stop) = stop { - stop.unwrap() + *stop.unwrap() } else { 0 - } / gst::FORMAT_PERCENT_MAX; + } / gst::format::Percent::MAX; if start == 0 && stop == 0 { continue; }