From db03c8edd1b84d2b7866fcef5d2415303d5ae5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Wed, 17 Apr 2024 14:38:56 +0200 Subject: [PATCH] Add field_if_some setter for builder ClockTime fields Optional `ClockTime` fields already implemented their setters in such a way that they could accept either `Option` or `ClockTime`. This commit adds `field_if_some()` setter variants for builder `ClockTime` builder fields for consistency with other builder fields. Part-of: --- gstreamer-video/src/video_event.rs | 32 ++++++++++++++++++++++++ gstreamer/src/event.rs | 16 ++++++++++++ gstreamer/src/message.rs | 40 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) diff --git a/gstreamer-video/src/video_event.rs b/gstreamer-video/src/video_event.rs index 87516336d..fb12ea8bb 100644 --- a/gstreamer-video/src/video_event.rs +++ b/gstreamer-video/src/video_event.rs @@ -138,6 +138,14 @@ impl<'a> DownstreamForceKeyUnitEventBuilder<'a> { } } + pub fn timestamp_if_some(self, timestamp: Option) -> Self { + if let Some(timestamp) = timestamp { + self.timestamp(timestamp) + } else { + self + } + } + pub fn stream_time(self, stream_time: impl Into>) -> Self { Self { stream_time: stream_time.into(), @@ -145,6 +153,14 @@ impl<'a> DownstreamForceKeyUnitEventBuilder<'a> { } } + pub fn stream_time_if_some(self, stream_time: Option) -> Self { + if let Some(stream_time) = stream_time { + self.stream_time(stream_time) + } else { + self + } + } + pub fn running_time(self, running_time: impl Into>) -> Self { Self { running_time: running_time.into(), @@ -152,6 +168,14 @@ impl<'a> DownstreamForceKeyUnitEventBuilder<'a> { } } + pub fn running_time_if_some(self, running_time: Option) -> Self { + if let Some(running_time) = running_time { + self.running_time(running_time) + } else { + self + } + } + pub fn all_headers(self, all_headers: bool) -> Self { Self { all_headers, @@ -268,6 +292,14 @@ impl<'a> UpstreamForceKeyUnitEventBuilder<'a> { } } + pub fn running_time_if_some(self, running_time: Option) -> Self { + if let Some(running_time) = running_time { + self.running_time(running_time) + } else { + self + } + } + pub fn all_headers(self, all_headers: bool) -> Self { Self { all_headers, diff --git a/gstreamer/src/event.rs b/gstreamer/src/event.rs index d818c340b..6cdfdd500 100644 --- a/gstreamer/src/event.rs +++ b/gstreamer/src/event.rs @@ -2634,6 +2634,14 @@ impl<'a> GapBuilder<'a> { self } + pub fn duration_if_some(self, duration: Option) -> Self { + if let Some(duration) = duration { + self.duration(duration) + } else { + self + } + } + event_builder_generic_impl!(|s: &Self| { #[allow(clippy::let_and_return)] let ev = ffi::gst_event_new_gap(s.timestamp.into_glib(), s.duration.into_glib()); @@ -2700,6 +2708,14 @@ impl<'a> QosBuilder<'a> { self } + pub fn timestamp_if_some(self, timestamp: Option) -> Self { + if let Some(timestamp) = timestamp { + self.timestamp(timestamp) + } else { + self + } + } + event_builder_generic_impl!(|s: &Self| ffi::gst_event_new_qos( s.type_.into_glib(), s.proportion, diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index dec584945..639f4288b 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -3276,6 +3276,14 @@ impl<'a> AsyncDoneBuilder<'a> { self } + pub fn running_time_if_some(self, running_time: Option) -> Self { + if let Some(running_time) = running_time { + self.running_time(running_time) + } else { + self + } + } + message_builder_generic_impl!(|s: &mut Self, src| ffi::gst_message_new_async_done( src, s.running_time.into_glib() @@ -3375,21 +3383,53 @@ impl<'a> QosBuilder<'a> { self } + pub fn running_time_if_some(self, running_time: Option) -> Self { + if let Some(running_time) = running_time { + self.running_time(running_time) + } else { + self + } + } + pub fn stream_time(mut self, stream_time: impl Into>) -> Self { self.stream_time = stream_time.into(); self } + pub fn stream_time_if_some(self, stream_time: Option) -> Self { + if let Some(stream_time) = stream_time { + self.stream_time(stream_time) + } else { + self + } + } + pub fn timestamp(mut self, timestamp: impl Into>) -> Self { self.timestamp = timestamp.into(); self } + pub fn timestamp_if_some(self, timestamp: Option) -> Self { + if let Some(timestamp) = timestamp { + self.timestamp(timestamp) + } else { + self + } + } + pub fn duration(mut self, duration: impl Into>) -> Self { self.duration = duration.into(); self } + pub fn duration_if_some(self, duration: Option) -> Self { + if let Some(duration) = duration { + self.duration(duration) + } else { + self + } + } + pub fn values(self, jitter: i64, proportion: f64, quality: i32) -> Self { Self { values: Some((jitter, proportion, quality)),