From 947ac8db5c415f35556561631c9cadcccf5512b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 25 Jun 2020 19:22:25 +0300 Subject: [PATCH] Name functions returning a builder builder(), not new() And also make the video event API more consistent with the normal event API. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/269 --- examples/src/bin/appsink.rs | 2 +- examples/src/bin/appsrc.rs | 4 +- examples/src/bin/custom_events.rs | 9 +- examples/src/bin/custom_meta.rs | 4 +- examples/src/bin/glupload.rs | 2 +- gstreamer-app/src/app_sink.rs | 7 +- gstreamer-app/src/app_src.rs | 9 +- gstreamer-audio/src/audio_buffer.rs | 16 +- gstreamer-audio/src/audio_info.rs | 7 +- gstreamer-video/src/functions.rs | 9 +- gstreamer-video/src/lib.rs | 6 +- gstreamer-video/src/video_event.rs | 202 +++++++++++++------------- gstreamer-video/src/video_frame.rs | 8 +- gstreamer-video/src/video_info.rs | 9 +- gstreamer-video/src/video_meta.rs | 4 +- gstreamer/src/sample.rs | 5 +- gstreamer/src/sample_serde.rs | 8 +- gstreamer/src/stream_collection.rs | 3 +- gstreamer/src/tags_serde.rs | 4 +- tutorials/src/bin/basic-tutorial-8.rs | 2 +- 20 files changed, 162 insertions(+), 158 deletions(-) diff --git a/examples/src/bin/appsink.rs b/examples/src/bin/appsink.rs index 443f5e155..8c9547ba5 100644 --- a/examples/src/bin/appsink.rs +++ b/examples/src/bin/appsink.rs @@ -72,7 +72,7 @@ fn create_pipeline() -> Result { // Getting data out of the appsink is done by setting callbacks on it. // The appsink will then call those handlers, as soon as data is available. appsink.set_callbacks( - gst_app::AppSinkCallbacks::new() + gst_app::AppSinkCallbacks::builder() // Add a handler to the "new-sample" signal. .new_sample(|appsink| { // Pull the sample in question out of the appsink's buffer. diff --git a/examples/src/bin/appsrc.rs b/examples/src/bin/appsrc.rs index ca51e8bc5..b929751f3 100644 --- a/examples/src/bin/appsrc.rs +++ b/examples/src/bin/appsrc.rs @@ -57,7 +57,7 @@ fn create_pipeline() -> Result { // Specify the format we want to provide as application into the pipeline // by creating a video info with the given format and creating caps from it for the appsrc element. let video_info = - gst_video::VideoInfo::new(gst_video::VideoFormat::Bgrx, WIDTH as u32, HEIGHT as u32) + gst_video::VideoInfo::builder(gst_video::VideoFormat::Bgrx, WIDTH as u32, HEIGHT as u32) .fps(gst::Fraction::new(2, 1)) .build() .expect("Failed to create video info"); @@ -80,7 +80,7 @@ fn create_pipeline() -> Result { // buffers of all elements of the pipeline are still empty, this will be called // a couple of times until all of them are filled. After this initial period, // this handler will be called (on average) twice per second. - gst_app::AppSrcCallbacks::new() + gst_app::AppSrcCallbacks::builder() .need_data(move |appsrc, _| { // We only produce 100 frames if i == 100 { diff --git a/examples/src/bin/custom_events.rs b/examples/src/bin/custom_events.rs index 0cd31fabc..afaaee0e6 100644 --- a/examples/src/bin/custom_events.rs +++ b/examples/src/bin/custom_events.rs @@ -19,14 +19,15 @@ pub struct ExampleCustomEvent { impl ExampleCustomEvent { const EVENT_NAME: &'static str = "example-custom-event"; - pub fn new_event(send_eos: bool) -> gst::Event { + #[allow(clippy::new_ret_no_self)] + pub fn new(send_eos: bool) -> gst::Event { let s = gst::Structure::builder(Self::EVENT_NAME) .field("send_eos", &send_eos) .build(); gst::event::CustomDownstream::new(s) } - pub fn from_event(ev: &gst::Event) -> Option { + pub fn parse(ev: &gst::EventRef) -> Option { match ev.view() { gst::EventView::CustomDownstream(e) => { let s = match e.get_structure() { @@ -79,7 +80,7 @@ fn example_main() { Some(gst::PadProbeData::Event(ref ev)) if ev.get_type() == gst::EventType::CustomDownstream => { - if let Some(custom_event) = ExampleCustomEvent::from_event(ev) { + if let Some(custom_event) = ExampleCustomEvent::parse(ev) { if let Some(pipeline) = pipeline_weak.upgrade() { if custom_event.send_eos { /* Send EOS event to shut down the pipeline, but from an async callback, as we're @@ -121,7 +122,7 @@ fn example_main() { "Sending custom event to the pipeline with send_eos={}", send_eos ); - let ev = ExampleCustomEvent::new_event(*send_eos); + let ev = ExampleCustomEvent::new(*send_eos); if !pipeline.send_event(ev) { println!("Warning: Failed to send custom event"); } diff --git a/examples/src/bin/custom_meta.rs b/examples/src/bin/custom_meta.rs index 2a6f9ede6..03297c56c 100644 --- a/examples/src/bin/custom_meta.rs +++ b/examples/src/bin/custom_meta.rs @@ -200,7 +200,7 @@ fn example_main() { // of the closure of the need-data callback. let mut i = 0; appsrc.set_callbacks( - gst_app::AppSrcCallbacks::new() + gst_app::AppSrcCallbacks::builder() .need_data(move |appsrc, _| { // We only produce 5 buffers. if i == 5 { @@ -228,7 +228,7 @@ fn example_main() { // Getting data out of the appsink is done by setting callbacks on it. // The appsink will then call those handlers, as soon as data is available. appsink.set_callbacks( - gst_app::AppSinkCallbacks::new() + gst_app::AppSinkCallbacks::builder() // Add a handler to the "new-sample" signal. .new_sample(|appsink| { // Pull the sample in question out of the appsink's buffer. diff --git a/examples/src/bin/glupload.rs b/examples/src/bin/glupload.rs index 7b411bc62..44e58ef30 100644 --- a/examples/src/bin/glupload.rs +++ b/examples/src/bin/glupload.rs @@ -469,7 +469,7 @@ impl App { let events_proxy = events_loop.create_proxy(); let (sender, receiver) = mpsc::channel(); self.appsink.set_callbacks( - gst_app::AppSinkCallbacks::new() + gst_app::AppSinkCallbacks::builder() .new_sample(move |appsink| { let sample = appsink.pull_sample().map_err(|_| gst::FlowError::Eos)?; diff --git a/gstreamer-app/src/app_sink.rs b/gstreamer-app/src/app_sink.rs index 715684ce2..3f7134e5e 100644 --- a/gstreamer-app/src/app_sink.rs +++ b/gstreamer-app/src/app_sink.rs @@ -55,8 +55,7 @@ unsafe impl Send for AppSinkCallbacks {} unsafe impl Sync for AppSinkCallbacks {} impl AppSinkCallbacks { - #[allow(clippy::new_ret_no_self)] - pub fn new() -> AppSinkCallbacksBuilder { + pub fn builder() -> AppSinkCallbacksBuilder { skip_assert_initialized!(); AppSinkCallbacksBuilder { eos: None, @@ -366,7 +365,7 @@ impl AppSinkStream { let waker_reference = Arc::new(Mutex::new(None as Option)); app_sink.set_callbacks( - AppSinkCallbacks::new() + AppSinkCallbacks::builder() .new_sample({ let waker_reference = Arc::clone(&waker_reference); @@ -404,7 +403,7 @@ impl Drop for AppSinkStream { // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 if gst::version() >= (1, 16, 3, 0) { if let Some(app_sink) = self.app_sink.upgrade() { - app_sink.set_callbacks(AppSinkCallbacks::new().build()); + app_sink.set_callbacks(AppSinkCallbacks::builder().build()); } } } diff --git a/gstreamer-app/src/app_src.rs b/gstreamer-app/src/app_src.rs index c3836016e..3b58b9378 100644 --- a/gstreamer-app/src/app_src.rs +++ b/gstreamer-app/src/app_src.rs @@ -37,8 +37,7 @@ unsafe impl Send for AppSrcCallbacks {} unsafe impl Sync for AppSrcCallbacks {} impl AppSrcCallbacks { - #[allow(clippy::new_ret_no_self)] - pub fn new() -> AppSrcCallbacksBuilder { + pub fn builder() -> AppSrcCallbacksBuilder { skip_assert_initialized!(); AppSrcCallbacksBuilder { @@ -336,7 +335,7 @@ impl AppSrcSink { let waker_reference = Arc::new(Mutex::new(None as Option)); app_src.set_callbacks( - AppSrcCallbacks::new() + AppSrcCallbacks::builder() .need_data({ let waker_reference = Arc::clone(&waker_reference); @@ -362,7 +361,7 @@ impl Drop for AppSrcSink { // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/merge_requests/570 if gst::version() >= (1, 16, 3, 0) { if let Some(app_src) = self.app_src.upgrade() { - app_src.set_callbacks(AppSrcCallbacks::new().build()); + app_src.set_callbacks(AppSrcCallbacks::builder().build()); } } } @@ -446,7 +445,7 @@ mod tests { let sample_quantity = 5; let samples = (0..sample_quantity) - .map(|_| gst::Sample::new().buffer(&gst::Buffer::new()).build()) + .map(|_| gst::Sample::builder().buffer(&gst::Buffer::new()).build()) .collect::>(); let mut sample_stream = futures_util::stream::iter(samples).map(Ok); diff --git a/gstreamer-audio/src/audio_buffer.rs b/gstreamer-audio/src/audio_buffer.rs index 6722ecc52..d1b8f3d72 100644 --- a/gstreamer-audio/src/audio_buffer.rs +++ b/gstreamer-audio/src/audio_buffer.rs @@ -524,7 +524,7 @@ mod tests { fn test_map_read() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .build() .unwrap(); let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); @@ -554,7 +554,7 @@ mod tests { fn test_map_read_planar() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .layout(::AudioLayout::NonInterleaved) .build() .unwrap(); @@ -593,7 +593,7 @@ mod tests { fn test_map_write() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .build() .unwrap(); let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); @@ -623,7 +623,7 @@ mod tests { fn test_map_write_planar() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .layout(::AudioLayout::NonInterleaved) .build() .unwrap(); @@ -662,7 +662,7 @@ mod tests { fn test_map_ref_read() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .build() .unwrap(); let buffer = gst::Buffer::with_size(info.rate() as usize * info.bpf() as usize).unwrap(); @@ -683,7 +683,7 @@ mod tests { fn test_map_ref_read_planar() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .layout(::AudioLayout::NonInterleaved) .build() .unwrap(); @@ -712,7 +712,7 @@ mod tests { fn test_map_ref_write() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .build() .unwrap(); let mut buffer = @@ -738,7 +738,7 @@ mod tests { fn test_map_ref_write_planar() { gst::init().unwrap(); - let info = ::AudioInfo::new(::AUDIO_FORMAT_S16, 48000, 2) + let info = ::AudioInfo::builder(::AUDIO_FORMAT_S16, 48000, 2) .layout(::AudioLayout::NonInterleaved) .build() .unwrap(); diff --git a/gstreamer-audio/src/audio_info.rs b/gstreamer-audio/src/audio_info.rs index c08ee2930..6ba7c0141 100644 --- a/gstreamer-audio/src/audio_info.rs +++ b/gstreamer-audio/src/audio_info.rs @@ -137,8 +137,7 @@ impl<'a> AudioInfoBuilder<'a> { } impl AudioInfo { - #[allow(clippy::new_ret_no_self)] - pub fn new<'a>(format: ::AudioFormat, rate: u32, channels: u32) -> AudioInfoBuilder<'a> { + pub fn builder<'a>(format: ::AudioFormat, rate: u32, channels: u32) -> AudioInfoBuilder<'a> { assert_initialized_main_thread!(); AudioInfoBuilder { @@ -424,7 +423,7 @@ mod tests { fn test_new() { gst::init().unwrap(); - let info = AudioInfo::new(::AudioFormat::S16le, 48000, 2) + let info = AudioInfo::builder(::AudioFormat::S16le, 48000, 2) .build() .unwrap(); assert_eq!(info.format(), ::AudioFormat::S16le); @@ -442,7 +441,7 @@ mod tests { ::AudioChannelPosition::RearLeft, ::AudioChannelPosition::RearRight, ]; - let info = AudioInfo::new(::AudioFormat::S16le, 48000, 2) + let info = AudioInfo::builder(::AudioFormat::S16le, 48000, 2) .positions(&positions) .build() .unwrap(); diff --git a/gstreamer-video/src/functions.rs b/gstreamer-video/src/functions.rs index 58bca41d6..80d6470ba 100644 --- a/gstreamer-video/src/functions.rs +++ b/gstreamer-video/src/functions.rs @@ -245,14 +245,17 @@ mod tests { p[3] = 255; } } - let in_caps = ::VideoInfo::new(::VideoFormat::Rgba, 320, 240) + let in_caps = ::VideoInfo::builder(::VideoFormat::Rgba, 320, 240) .build() .unwrap() .to_caps() .unwrap(); - let sample = gst::Sample::new().buffer(&in_buffer).caps(&in_caps).build(); + let sample = gst::Sample::builder() + .buffer(&in_buffer) + .caps(&in_caps) + .build(); - let out_caps = ::VideoInfo::new(::VideoFormat::Abgr, 320, 240) + let out_caps = ::VideoInfo::builder(::VideoFormat::Abgr, 320, 240) .build() .unwrap() .to_caps() diff --git a/gstreamer-video/src/lib.rs b/gstreamer-video/src/lib.rs index 75d8f1ed5..8ba2f7d80 100644 --- a/gstreamer-video/src/lib.rs +++ b/gstreamer-video/src/lib.rs @@ -64,8 +64,10 @@ pub mod video_frame; pub use video_frame::{VideoBufferExt, VideoFrame, VideoFrameRef}; mod video_overlay; pub use video_overlay::{is_video_overlay_prepare_window_handle_message, VideoOverlayExtManual}; -mod video_event; -pub use video_event::*; +pub mod video_event; +pub use video_event::{ + DownstreamForceKeyUnitEvent, ForceKeyUnitEvent, StillFrameEvent, UpstreamForceKeyUnitEvent, +}; mod functions; pub use functions::*; mod video_rectangle; diff --git a/gstreamer-video/src/video_event.rs b/gstreamer-video/src/video_event.rs index 8cc401cbb..f4e80801f 100644 --- a/gstreamer-video/src/video_event.rs +++ b/gstreamer-video/src/video_event.rs @@ -15,15 +15,6 @@ use gst; use gst::MiniObject; use std::mem; -pub fn is_force_key_unit_event(event: &gst::EventRef) -> bool { - skip_assert_initialized!(); - unsafe { - from_glib(gst_video_sys::gst_video_event_is_force_key_unit( - event.as_mut_ptr(), - )) - } -} - // FIXME: Copy from gstreamer/src/event.rs macro_rules! event_builder_generic_impl { ($new_fn:expr) => { @@ -81,10 +72,6 @@ macro_rules! event_builder_generic_impl { }; } -pub fn new_downstream_force_key_unit_event<'a>() -> DownstreamForceKeyUnitEventBuilder<'a> { - DownstreamForceKeyUnitEventBuilder::new() -} - pub struct DownstreamForceKeyUnitEventBuilder<'a> { seqnum: Option, running_time_offset: Option, @@ -160,45 +147,47 @@ pub struct DownstreamForceKeyUnitEvent { pub count: u32, } -pub fn parse_downstream_force_key_unit_event( - event: &gst::EventRef, -) -> Result { - skip_assert_initialized!(); - unsafe { - let mut timestamp = mem::MaybeUninit::uninit(); - let mut stream_time = mem::MaybeUninit::uninit(); - let mut running_time = mem::MaybeUninit::uninit(); - let mut all_headers = mem::MaybeUninit::uninit(); - let mut count = mem::MaybeUninit::uninit(); +impl DownstreamForceKeyUnitEvent { + pub fn builder<'a>() -> DownstreamForceKeyUnitEventBuilder<'a> { + DownstreamForceKeyUnitEventBuilder::new() + } - let res: bool = from_glib( - gst_video_sys::gst_video_event_parse_downstream_force_key_unit( - event.as_mut_ptr(), - timestamp.as_mut_ptr(), - stream_time.as_mut_ptr(), - running_time.as_mut_ptr(), - all_headers.as_mut_ptr(), - count.as_mut_ptr(), - ), - ); - if res { - Ok(DownstreamForceKeyUnitEvent { - timestamp: from_glib(timestamp.assume_init()), - stream_time: from_glib(stream_time.assume_init()), - running_time: from_glib(running_time.assume_init()), - all_headers: from_glib(all_headers.assume_init()), - count: count.assume_init(), - }) - } else { - Err(glib_bool_error!("Failed to parse GstEvent")) + pub fn parse( + event: &gst::EventRef, + ) -> Result { + skip_assert_initialized!(); + unsafe { + let mut timestamp = mem::MaybeUninit::uninit(); + let mut stream_time = mem::MaybeUninit::uninit(); + let mut running_time = mem::MaybeUninit::uninit(); + let mut all_headers = mem::MaybeUninit::uninit(); + let mut count = mem::MaybeUninit::uninit(); + + let res: bool = from_glib( + gst_video_sys::gst_video_event_parse_downstream_force_key_unit( + event.as_mut_ptr(), + timestamp.as_mut_ptr(), + stream_time.as_mut_ptr(), + running_time.as_mut_ptr(), + all_headers.as_mut_ptr(), + count.as_mut_ptr(), + ), + ); + if res { + Ok(DownstreamForceKeyUnitEvent { + timestamp: from_glib(timestamp.assume_init()), + stream_time: from_glib(stream_time.assume_init()), + running_time: from_glib(running_time.assume_init()), + all_headers: from_glib(all_headers.assume_init()), + count: count.assume_init(), + }) + } else { + Err(glib_bool_error!("Failed to parse GstEvent")) + } } } } -pub fn new_upstream_force_key_unit_event<'a>() -> UpstreamForceKeyUnitEventBuilder<'a> { - UpstreamForceKeyUnitEventBuilder::new() -} - pub struct UpstreamForceKeyUnitEventBuilder<'a> { seqnum: Option, running_time_offset: Option, @@ -255,31 +244,37 @@ pub struct UpstreamForceKeyUnitEvent { pub count: u32, } -pub fn parse_upstream_force_key_unit_event( - event: &gst::EventRef, -) -> Result { - skip_assert_initialized!(); - unsafe { - let mut running_time = mem::MaybeUninit::uninit(); - let mut all_headers = mem::MaybeUninit::uninit(); - let mut count = mem::MaybeUninit::uninit(); +impl UpstreamForceKeyUnitEvent { + pub fn builder<'a>() -> UpstreamForceKeyUnitEventBuilder<'a> { + UpstreamForceKeyUnitEventBuilder::new() + } - let res: bool = from_glib( - gst_video_sys::gst_video_event_parse_upstream_force_key_unit( - event.as_mut_ptr(), - running_time.as_mut_ptr(), - all_headers.as_mut_ptr(), - count.as_mut_ptr(), - ), - ); - if res { - Ok(UpstreamForceKeyUnitEvent { - running_time: from_glib(running_time.assume_init()), - all_headers: from_glib(all_headers.assume_init()), - count: count.assume_init(), - }) - } else { - Err(glib_bool_error!("Failed to parse GstEvent")) + pub fn parse( + event: &gst::EventRef, + ) -> Result { + skip_assert_initialized!(); + unsafe { + let mut running_time = mem::MaybeUninit::uninit(); + let mut all_headers = mem::MaybeUninit::uninit(); + let mut count = mem::MaybeUninit::uninit(); + + let res: bool = from_glib( + gst_video_sys::gst_video_event_parse_upstream_force_key_unit( + event.as_mut_ptr(), + running_time.as_mut_ptr(), + all_headers.as_mut_ptr(), + count.as_mut_ptr(), + ), + ); + if res { + Ok(UpstreamForceKeyUnitEvent { + running_time: from_glib(running_time.assume_init()), + all_headers: from_glib(all_headers.assume_init()), + count: count.assume_init(), + }) + } else { + Err(glib_bool_error!("Failed to parse GstEvent")) + } } } } @@ -290,20 +285,24 @@ pub enum ForceKeyUnitEvent { Upstream(UpstreamForceKeyUnitEvent), } -pub fn parse_force_key_unit_event( - event: &gst::EventRef, -) -> Result { - skip_assert_initialized!(); - if event.is_upstream() { - parse_upstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Upstream) - } else { - parse_downstream_force_key_unit_event(event).map(ForceKeyUnitEvent::Downstream) +impl ForceKeyUnitEvent { + pub fn is(event: &gst::EventRef) -> bool { + skip_assert_initialized!(); + unsafe { + from_glib(gst_video_sys::gst_video_event_is_force_key_unit( + event.as_mut_ptr(), + )) + } } -} -pub fn new_still_frame_event<'a>(in_still: bool) -> StillFrameEventBuilder<'a> { - assert_initialized_main_thread!(); - StillFrameEventBuilder::new(in_still) + pub fn parse(event: &gst::EventRef) -> Result { + skip_assert_initialized!(); + if event.is_upstream() { + UpstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Upstream) + } else { + DownstreamForceKeyUnitEvent::parse(event).map(ForceKeyUnitEvent::Downstream) + } + } } pub struct StillFrameEventBuilder<'a> { @@ -334,23 +333,28 @@ pub struct StillFrameEvent { pub in_still: bool, } -pub fn parse_still_frame_event( - event: &gst::EventRef, -) -> Result { - skip_assert_initialized!(); - unsafe { - let mut in_still = mem::MaybeUninit::uninit(); +impl StillFrameEvent { + pub fn builder<'a>(in_still: bool) -> StillFrameEventBuilder<'a> { + assert_initialized_main_thread!(); + StillFrameEventBuilder::new(in_still) + } - let res: bool = from_glib(gst_video_sys::gst_video_event_parse_still_frame( - event.as_mut_ptr(), - in_still.as_mut_ptr(), - )); - if res { - Ok(StillFrameEvent { - in_still: from_glib(in_still.assume_init()), - }) - } else { - Err(glib_bool_error!("Invalid still-frame event")) + pub fn parse(event: &gst::EventRef) -> Result { + skip_assert_initialized!(); + unsafe { + let mut in_still = mem::MaybeUninit::uninit(); + + let res: bool = from_glib(gst_video_sys::gst_video_event_parse_still_frame( + event.as_mut_ptr(), + in_still.as_mut_ptr(), + )); + if res { + Ok(StillFrameEvent { + in_still: from_glib(in_still.assume_init()), + }) + } else { + Err(glib_bool_error!("Invalid still-frame event")) + } } } } diff --git a/gstreamer-video/src/video_frame.rs b/gstreamer-video/src/video_frame.rs index 7f78d0840..6ecc14b59 100644 --- a/gstreamer-video/src/video_frame.rs +++ b/gstreamer-video/src/video_frame.rs @@ -847,7 +847,7 @@ mod tests { fn test_map_read() { gst::init().unwrap(); - let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240) + let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240) .build() .unwrap(); let buffer = gst::Buffer::with_size(info.size()).unwrap(); @@ -877,7 +877,7 @@ mod tests { fn test_map_write() { gst::init().unwrap(); - let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240) + let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240) .build() .unwrap(); let buffer = gst::Buffer::with_size(info.size()).unwrap(); @@ -907,7 +907,7 @@ mod tests { fn test_map_ref_read() { gst::init().unwrap(); - let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240) + let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240) .build() .unwrap(); let buffer = gst::Buffer::with_size(info.size()).unwrap(); @@ -923,7 +923,7 @@ mod tests { fn test_map_ref_write() { gst::init().unwrap(); - let info = ::VideoInfo::new(::VideoFormat::Gray8, 320, 240) + let info = ::VideoInfo::builder(::VideoFormat::Gray8, 320, 240) .build() .unwrap(); let mut buffer = gst::Buffer::with_size(info.size()).unwrap(); diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index 9ed05cecf..ef8b013a7 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -511,8 +511,7 @@ impl<'a> VideoInfoBuilder<'a> { } impl VideoInfo { - #[allow(clippy::new_ret_no_self)] - pub fn new<'a>(format: ::VideoFormat, width: u32, height: u32) -> VideoInfoBuilder<'a> { + pub fn builder<'a>(format: ::VideoFormat, width: u32, height: u32) -> VideoInfoBuilder<'a> { assert_initialized_main_thread!(); #[cfg(not(any(feature = "v1_12", feature = "dox")))] @@ -950,7 +949,7 @@ mod tests { fn test_new() { gst::init().unwrap(); - let info = VideoInfo::new(::VideoFormat::I420, 320, 240) + let info = VideoInfo::builder(::VideoFormat::I420, 320, 240) .build() .unwrap(); assert_eq!(info.format(), ::VideoFormat::I420); @@ -963,7 +962,7 @@ mod tests { let offsets = [0, 640 * 240 + 16, 640 * 240 + 16 + 320 * 120 + 16]; let strides = [640, 320, 320]; - let info = VideoInfo::new(::VideoFormat::I420, 320, 240) + let info = VideoInfo::builder(::VideoFormat::I420, 320, 240) .offset(&offsets) .stride(&strides) .size(640 * 240 + 16 + 320 * 120 + 16 + 320 * 120 + 16) @@ -1023,7 +1022,7 @@ mod tests { fn test_video_align() { gst::init().unwrap(); - let mut info = ::VideoInfo::new(::VideoFormat::Nv16, 1920, 1080) + let mut info = ::VideoInfo::builder(::VideoFormat::Nv16, 1920, 1080) .build() .expect("Failed to create VideoInfo"); diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index 1b73d259a..72e374e94 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -36,7 +36,7 @@ impl VideoMeta { return Err(glib_bool_error!("Unsupported video format {}", format)); } - let info = ::VideoInfo::new(format, width, height).build()?; + let info = ::VideoInfo::builder(format, width, height).build()?; if !info.is_valid() { return Err(glib_bool_error!("Invalid video info")); @@ -83,7 +83,7 @@ impl VideoMeta { } let n_planes = offset.len() as u32; - let info = ::VideoInfo::new(format, width, height) + let info = ::VideoInfo::builder(format, width, height) .offset(offset) .stride(stride) .build()?; diff --git a/gstreamer/src/sample.rs b/gstreamer/src/sample.rs index a2003e4ce..b85d6bc46 100644 --- a/gstreamer/src/sample.rs +++ b/gstreamer/src/sample.rs @@ -104,8 +104,7 @@ impl<'a> SampleBuilder<'a> { } impl Sample { - #[allow(clippy::new_ret_no_self)] - pub fn new<'a>() -> SampleBuilder<'a> { + pub fn builder<'a>() -> SampleBuilder<'a> { SampleBuilder { buffer: None, buffer_list: None, @@ -239,7 +238,7 @@ mod tests { let info = Structure::builder("sample.info") .field("f3", &123i32) .build(); - let sample = Sample::new().info(info).build(); + let sample = Sample::builder().info(info).build(); assert!(sample.get_info().is_some()); } diff --git a/gstreamer/src/sample_serde.rs b/gstreamer/src/sample_serde.rs index b4799adfc..a8fc6762f 100644 --- a/gstreamer/src/sample_serde.rs +++ b/gstreamer/src/sample_serde.rs @@ -47,7 +47,7 @@ struct SampleDe { impl From for Sample { fn from(buf_de: SampleDe) -> Self { skip_assert_initialized!(); - let mut builder = Sample::new(); + let mut builder = Sample::builder(); if let Some(buffer) = buf_de.buffer.as_ref() { builder = builder.buffer(buffer); @@ -133,7 +133,7 @@ mod tests { .field("f3", &123i32) .build(); - Sample::new() + Sample::builder() .buffer(&buffer) .caps(&caps) .segment(&segment) @@ -196,7 +196,7 @@ mod tests { buffer.set_offset_end(4); buffer.set_duration(4.into()); } - Sample::new().buffer(&buffer).build() + Sample::builder().buffer(&buffer).build() }; // `Sample`'s `Segment` is allocated in GStreamer 1.x, should be fixed in version 2.0 @@ -363,7 +363,7 @@ mod tests { .field("f3", &123i32) .build(); - Sample::new() + Sample::builder() .buffer(&buffer) .caps(&caps) .segment(&segment) diff --git a/gstreamer/src/stream_collection.rs b/gstreamer/src/stream_collection.rs index fd099643d..eb96e2617 100644 --- a/gstreamer/src/stream_collection.rs +++ b/gstreamer/src/stream_collection.rs @@ -102,8 +102,7 @@ impl StreamCollectionBuilder { } impl StreamCollection { - #[allow(clippy::new_ret_no_self)] - pub fn new(upstream_id: Option<&str>) -> StreamCollectionBuilder { + pub fn builder(upstream_id: Option<&str>) -> StreamCollectionBuilder { assert_initialized_main_thread!(); let upstream_id = upstream_id.to_glib_none(); let (major, minor, _, _) = ::version(); diff --git a/gstreamer/src/tags_serde.rs b/gstreamer/src/tags_serde.rs index 761291a67..fafc403a5 100644 --- a/gstreamer/src/tags_serde.rs +++ b/gstreamer/src/tags_serde.rs @@ -366,7 +366,7 @@ mod tests { buffer.set_offset(0); buffer.set_offset_end(0); } - Sample::new().buffer(&buffer).build() + Sample::builder().buffer(&buffer).build() }; tags.add::(&sample, TagMergeMode::Append); // Sample } @@ -588,7 +588,7 @@ mod tests { buffer.set_offset(0); buffer.set_offset_end(0); } - Sample::new().buffer(&buffer).build() + Sample::builder().buffer(&buffer).build() }; tags.add::(&sample, TagMergeMode::Append); // Sample } diff --git a/tutorials/src/bin/basic-tutorial-8.rs b/tutorials/src/bin/basic-tutorial-8.rs index 8636698a7..9aa6f3edd 100644 --- a/tutorials/src/bin/basic-tutorial-8.rs +++ b/tutorials/src/bin/basic-tutorial-8.rs @@ -123,7 +123,7 @@ fn main() { tee_app_pad.link(&queue_app_pad).unwrap(); // configure appsrc - let info = AudioInfo::new(gst_audio::AudioFormat::S16le, SAMPLE_RATE, 1) + let info = AudioInfo::builder(gst_audio::AudioFormat::S16le, SAMPLE_RATE, 1) .build() .unwrap(); let audio_caps = info.to_caps().unwrap();