From f9690817ad151ddcb5e038054a42988618cba7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 18 Oct 2022 14:16:04 +0300 Subject: [PATCH] Fix nullability handling in some functions in manual code --- examples/src/bin/cairo_compositor.rs | 2 +- examples/src/bin/discoverer.rs | 9 +--- examples/src/bin/fd_allocator.rs | 8 ++- examples/src/glupload.rs | 2 +- gstreamer-allocators/src/dma_buf_allocator.rs | 14 ++++-- gstreamer-allocators/src/fd_allocator.rs | 10 +++- gstreamer-gl/src/context.rs | 9 ++-- gstreamer-gl/src/gl_base_memory.rs | 11 ++-- gstreamer-pbutils/src/functions.rs | 33 +++--------- gstreamer-rtp/src/rtp_buffer.rs | 50 ++++++++++--------- gstreamer-rtsp-server/src/rtsp_token.rs | 10 ++-- gstreamer-validate/src/lib.rs | 1 + gstreamer/src/gtype.rs | 3 +- gstreamer/src/message.rs | 11 ++-- gstreamer/src/query.rs | 25 +++++++--- gstreamer/src/tags.rs | 14 ++---- gstreamer/src/toc.rs | 31 +++++++++--- gstreamer/src/toc_serde.rs | 24 ++++----- tutorials/src/bin/basic-tutorial-9.rs | 3 +- 19 files changed, 135 insertions(+), 135 deletions(-) diff --git a/examples/src/bin/cairo_compositor.rs b/examples/src/bin/cairo_compositor.rs index 3666771b7..64ec19393 100644 --- a/examples/src/bin/cairo_compositor.rs +++ b/examples/src/bin/cairo_compositor.rs @@ -200,7 +200,7 @@ mod cairo_compositor { caps }; - q.set_result(&caps); + q.set_result(Some(&caps)); true } diff --git a/examples/src/bin/discoverer.rs b/examples/src/bin/discoverer.rs index 36f25c5a8..36f2a8971 100644 --- a/examples/src/bin/discoverer.rs +++ b/examples/src/bin/discoverer.rs @@ -41,9 +41,7 @@ fn print_tags(info: &DiscovererInfo) { fn print_stream_info(stream: &DiscovererStreamInfo) { println!("Stream: "); - if let Some(id) = stream.stream_id() { - println!(" Stream id: {}", id); - } + println!(" Stream id: {}", stream.stream_id()); let caps_str = match stream.caps() { Some(caps) => caps.to_string(), None => String::from("--"), @@ -52,10 +50,7 @@ fn print_stream_info(stream: &DiscovererStreamInfo) { } fn print_discoverer_info(info: &DiscovererInfo) -> Result<(), Error> { - let uri = info - .uri() - .ok_or(DiscovererError("URI should not be null"))?; - println!("URI: {}", uri); + println!("URI: {}", info.uri()); println!("Duration: {}", info.duration().display()); print_tags(info); print_stream_info( diff --git a/examples/src/bin/fd_allocator.rs b/examples/src/bin/fd_allocator.rs index 22432897d..8094d087a 100644 --- a/examples/src/bin/fd_allocator.rs +++ b/examples/src/bin/fd_allocator.rs @@ -107,11 +107,9 @@ fn create_receiver_pipeline( // ownership of the passed file descriptor. The file descriptor // will be closed when the memory is released. let memory = unsafe { - fd_allocator.alloc( - *fd, - video_info.size(), - gst_allocators::FdMemoryFlags::NONE, - ) + fd_allocator + .alloc(*fd, video_info.size(), gst_allocators::FdMemoryFlags::NONE) + .unwrap() }; let mut buffer = gst::Buffer::new(); let buffer_mut = buffer.make_mut(); diff --git a/examples/src/glupload.rs b/examples/src/glupload.rs index 92cda349b..7b007ae61 100644 --- a/examples/src/glupload.rs +++ b/examples/src/glupload.rs @@ -428,7 +428,7 @@ impl App { msg.src().map(|s| s.downcast::().unwrap()) { let context = gst::Context::new(context_type, true); - context.set_gl_display(&gl_display); + context.set_gl_display(Some(&gl_display)); el.set_context(&context); } } diff --git a/gstreamer-allocators/src/dma_buf_allocator.rs b/gstreamer-allocators/src/dma_buf_allocator.rs index af115d646..34a9f83ef 100644 --- a/gstreamer-allocators/src/dma_buf_allocator.rs +++ b/gstreamer-allocators/src/dma_buf_allocator.rs @@ -45,13 +45,18 @@ impl DmaBufMemoryRef { impl DmaBufAllocator { #[doc(alias = "gst_dmabuf_allocator_alloc")] - pub unsafe fn alloc(&self, fd: A, size: usize) -> gst::Memory { + pub unsafe fn alloc( + &self, + fd: A, + size: usize, + ) -> Result { assert_initialized_main_thread!(); - from_glib_full(ffi::gst_dmabuf_allocator_alloc( + Option::<_>::from_glib_full(ffi::gst_dmabuf_allocator_alloc( self.unsafe_cast_ref::().to_glib_none().0, fd.into_raw_fd(), size, )) + .ok_or_else(|| glib::bool_error!("Failed to allocate memory")) } #[cfg(any(feature = "v1_16", feature = "dox"))] @@ -62,13 +67,14 @@ impl DmaBufAllocator { fd: RawFd, size: usize, flags: FdMemoryFlags, - ) -> gst::Memory { + ) -> Result { assert_initialized_main_thread!(); - from_glib_full(ffi::gst_dmabuf_allocator_alloc_with_flags( + Option::<_>::from_glib_full(ffi::gst_dmabuf_allocator_alloc_with_flags( self.unsafe_cast_ref::().to_glib_none().0, fd, size, flags.into_glib(), )) + .ok_or_else(|| glib::bool_error!("Failed to allocate memory")) } } diff --git a/gstreamer-allocators/src/fd_allocator.rs b/gstreamer-allocators/src/fd_allocator.rs index bffca225c..f3934535d 100644 --- a/gstreamer-allocators/src/fd_allocator.rs +++ b/gstreamer-allocators/src/fd_allocator.rs @@ -47,13 +47,19 @@ impl FdMemoryRef { impl FdAllocator { #[doc(alias = "gst_fd_allocator_alloc")] - pub unsafe fn alloc(&self, fd: RawFd, size: usize, flags: FdMemoryFlags) -> gst::Memory { + pub unsafe fn alloc( + &self, + fd: RawFd, + size: usize, + flags: FdMemoryFlags, + ) -> Result { assert_initialized_main_thread!(); - from_glib_full(ffi::gst_fd_allocator_alloc( + Option::<_>::from_glib_full(ffi::gst_fd_allocator_alloc( self.unsafe_cast_ref::().to_glib_none().0, fd, size, flags.into_glib(), )) + .ok_or_else(|| glib::bool_error!("Failed to allocate memory")) } } diff --git a/gstreamer-gl/src/context.rs b/gstreamer-gl/src/context.rs index 1226dcecb..6a3bce047 100644 --- a/gstreamer-gl/src/context.rs +++ b/gstreamer-gl/src/context.rs @@ -11,7 +11,7 @@ pub trait ContextGLExt { #[doc(alias = "gst_context_get_gl_display")] fn gl_display(&self) -> Option; #[doc(alias = "gst_context_set_gl_display")] - fn set_gl_display>(&self, display: &T); + fn set_gl_display>(&self, display: Option<&T>); } impl ContextGLExt for ContextRef { @@ -29,9 +29,12 @@ impl ContextGLExt for ContextRef { } } - fn set_gl_display>(&self, display: &T) { + fn set_gl_display>(&self, display: Option<&T>) { unsafe { - ffi::gst_context_set_gl_display(self.as_mut_ptr(), display.as_ref().to_glib_none().0); + ffi::gst_context_set_gl_display( + self.as_mut_ptr(), + display.map(|d| d.as_ref()).to_glib_none().0, + ); } } } diff --git a/gstreamer-gl/src/gl_base_memory.rs b/gstreamer-gl/src/gl_base_memory.rs index d221bd324..161b86fcb 100644 --- a/gstreamer-gl/src/gl_base_memory.rs +++ b/gstreamer-gl/src/gl_base_memory.rs @@ -7,7 +7,6 @@ use crate::GLBaseMemoryAllocator; use ffi::GstGLBaseMemory; use gst::MemoryRef; -use gst::{result_from_gboolean, LoggableError, CAT_RUST}; gst::memory_object_wrapper!( GLBaseMemory, @@ -51,16 +50,15 @@ impl GLBaseMemoryRef { dest: &mut GLBaseMemory, offset: isize, size: isize, - ) -> Result<(), LoggableError> { + ) -> Result<(), glib::BoolError> { Self::init_once(); - result_from_gboolean!( + glib::result_from_gboolean!( ffi::gst_gl_base_memory_memcpy( mut_override(&self.0), dest.to_glib_none_mut().0, offset, size, ), - CAT_RUST, "Failed to copy memory" ) } @@ -69,14 +67,15 @@ impl GLBaseMemoryRef { pub fn alloc>( allocator: &P, params: &GLAllocationParams, - ) -> Option { + ) -> Result { skip_assert_initialized!(); Self::init_once(); unsafe { - from_glib_full(ffi::gst_gl_base_memory_alloc( + Option::<_>::from_glib_full(ffi::gst_gl_base_memory_alloc( allocator.as_ref().to_glib_none().0, mut_override(params.to_glib_none().0), )) + .ok_or_else(|| glib::bool_error!("Failed to allocate memory")) } } diff --git a/gstreamer-pbutils/src/functions.rs b/gstreamer-pbutils/src/functions.rs index 9d4d3e0c8..83dc53f60 100644 --- a/gstreamer-pbutils/src/functions.rs +++ b/gstreamer-pbutils/src/functions.rs @@ -48,42 +48,21 @@ pub fn pb_utils_add_codec_description_to_tag_list( } #[doc(alias = "gst_pb_utils_get_encoder_description")] -pub fn pb_utils_get_encoder_description( - caps: &gst::CapsRef, -) -> Result { +pub fn pb_utils_get_encoder_description(caps: &gst::CapsRef) -> glib::GString { assert_initialized_main_thread!(); - unsafe { - match from_glib_full(ffi::gst_pb_utils_get_encoder_description(caps.as_ptr())) { - Some(s) => Ok(s), - None => Err(glib::bool_error!("Failed to get encoder description")), - } - } + unsafe { from_glib_full(ffi::gst_pb_utils_get_encoder_description(caps.as_ptr())) } } #[doc(alias = "gst_pb_utils_get_decoder_description")] -pub fn pb_utils_get_decoder_description( - caps: &gst::CapsRef, -) -> Result { +pub fn pb_utils_get_decoder_description(caps: &gst::CapsRef) -> glib::GString { assert_initialized_main_thread!(); - unsafe { - match from_glib_full(ffi::gst_pb_utils_get_decoder_description(caps.as_ptr())) { - Some(s) => Ok(s), - None => Err(glib::bool_error!("Failed to get decoder description")), - } - } + unsafe { from_glib_full(ffi::gst_pb_utils_get_decoder_description(caps.as_ptr())) } } #[doc(alias = "gst_pb_utils_get_codec_description")] -pub fn pb_utils_get_codec_description( - caps: &gst::CapsRef, -) -> Result { +pub fn pb_utils_get_codec_description(caps: &gst::CapsRef) -> glib::GString { assert_initialized_main_thread!(); - unsafe { - match from_glib_full(ffi::gst_pb_utils_get_codec_description(caps.as_ptr())) { - Some(s) => Ok(s), - None => Err(glib::bool_error!("Failed to get codec description")), - } - } + unsafe { from_glib_full(ffi::gst_pb_utils_get_codec_description(caps.as_ptr())) } } #[doc(alias = "gst_codec_utils_aac_caps_set_level_and_profile")] diff --git a/gstreamer-rtp/src/rtp_buffer.rs b/gstreamer-rtp/src/rtp_buffer.rs index 408eeed16..8aff5c063 100644 --- a/gstreamer-rtp/src/rtp_buffer.rs +++ b/gstreamer-rtp/src/rtp_buffer.rs @@ -425,26 +425,6 @@ impl<'a, T> RTPBuffer<'a, T> { } } -impl RTPBuffer<'_, ()> { - #[doc(alias = "gst_rtp_buffer_calc_header_len")] - pub fn calc_header_len(csrc_count: u8) -> u32 { - skip_assert_initialized!(); - unsafe { ffi::gst_rtp_buffer_calc_header_len(csrc_count) } - } - - #[doc(alias = "gst_rtp_buffer_calc_packet_len")] - pub fn calc_packet_len(payload_len: u32, pad_len: u8, csrc_count: u8) -> u32 { - skip_assert_initialized!(); - unsafe { ffi::gst_rtp_buffer_calc_packet_len(payload_len, pad_len, csrc_count) } - } - - #[doc(alias = "gst_rtp_buffer_calc_payload_len")] - pub fn calc_payload_len(packet_len: u32, pad_len: u8, csrc_count: u8) -> u32 { - skip_assert_initialized!(); - unsafe { ffi::gst_rtp_buffer_calc_payload_len(packet_len, pad_len, csrc_count) } - } -} - impl<'a, T> Drop for RTPBuffer<'a, T> { fn drop(&mut self) { unsafe { @@ -485,6 +465,30 @@ pub fn compare_seqnum(seqnum1: u16, seqnum2: u16) -> i32 { unsafe { ffi::gst_rtp_buffer_compare_seqnum(seqnum1, seqnum2) } } +#[doc(alias = "gst_rtp_buffer_calc_header_len")] +pub fn calc_header_len(csrc_count: u8) -> u32 { + skip_assert_initialized!(); + unsafe { ffi::gst_rtp_buffer_calc_header_len(csrc_count) } +} + +#[doc(alias = "gst_rtp_buffer_calc_packet_len")] +pub fn calc_packet_len(payload_len: u32, pad_len: u8, csrc_count: u8) -> u32 { + skip_assert_initialized!(); + unsafe { ffi::gst_rtp_buffer_calc_packet_len(payload_len, pad_len, csrc_count) } +} + +#[doc(alias = "gst_rtp_buffer_calc_payload_len")] +pub fn calc_payload_len(packet_len: u32, pad_len: u8, csrc_count: u8) -> u32 { + skip_assert_initialized!(); + unsafe { ffi::gst_rtp_buffer_calc_payload_len(packet_len, pad_len, csrc_count) } +} + +#[doc(alias = "gst_rtp_buffer_ext_timestamp")] +pub fn ext_timestamp(exttimestamp: &mut u64, timestamp: u32) -> u64 { + skip_assert_initialized!(); + unsafe { ffi::gst_rtp_buffer_ext_timestamp(exttimestamp, timestamp) } +} + #[cfg(test)] mod tests { use super::*; @@ -692,11 +696,11 @@ mod tests { #[test] fn test_calc_functions() { - let res = RTPBuffer::calc_header_len(0); + let res = super::calc_header_len(0); assert_eq!(res, 12); - let res = RTPBuffer::calc_packet_len(100, 10, 2); + let res = super::calc_packet_len(100, 10, 2); assert_eq!(res, 130); - let res = RTPBuffer::calc_payload_len(100, 5, 4); + let res = super::calc_payload_len(100, 5, 4); assert_eq!(res, 67); } } diff --git a/gstreamer-rtsp-server/src/rtsp_token.rs b/gstreamer-rtsp-server/src/rtsp_token.rs index d0d1a98d2..ef5a02a17 100644 --- a/gstreamer-rtsp-server/src/rtsp_token.rs +++ b/gstreamer-rtsp-server/src/rtsp_token.rs @@ -22,7 +22,7 @@ impl RTSPToken { { let token = token.get_mut().unwrap(); - let structure = token.structure_mut().unwrap(); + let structure = token.structure_mut(); for &(f, v) in values { structure.set_value(f, v.to_send_value()); @@ -62,14 +62,10 @@ impl RTSPTokenRef { } #[doc(alias = "get_mut_structure")] - pub fn structure_mut(&mut self) -> Option<&mut gst::StructureRef> { + pub fn structure_mut(&mut self) -> &mut gst::StructureRef { unsafe { let structure = ffi::gst_rtsp_token_writable_structure(self.as_mut_ptr()); - if structure.is_null() { - None - } else { - Some(gst::StructureRef::from_glib_borrow_mut(structure)) - } + gst::StructureRef::from_glib_borrow_mut(structure) } } } diff --git a/gstreamer-validate/src/lib.rs b/gstreamer-validate/src/lib.rs index 454f53719..5668b0d92 100644 --- a/gstreamer-validate/src/lib.rs +++ b/gstreamer-validate/src/lib.rs @@ -39,6 +39,7 @@ macro_rules! skip_assert_initialized { #[allow(clippy::too_many_arguments)] #[allow(clippy::match_same_arms)] #[allow(non_snake_case)] +#[allow(clippy::needless_borrow)] #[allow(clippy::use_self)] #[allow(unused_imports)] mod auto; diff --git a/gstreamer/src/gtype.rs b/gstreamer/src/gtype.rs index 7c22c0f17..485edd27e 100644 --- a/gstreamer/src/gtype.rs +++ b/gstreamer/src/gtype.rs @@ -46,9 +46,8 @@ impl PluginApiExt for glib::Type { self.into_glib(), flags.as_mut_ptr(), )); - let flags = flags.assume_init(); if ret { - Some(from_glib(flags)) + Some(from_glib(flags.assume_init())) } else { None } diff --git a/gstreamer/src/message.rs b/gstreamer/src/message.rs index 006920ef4..01af9a2a5 100644 --- a/gstreamer/src/message.rs +++ b/gstreamer/src/message.rs @@ -1532,14 +1532,17 @@ declare_concrete_message!(PropertyNotify, T); impl PropertyNotify { #[doc(alias = "gst_message_new_property_notify")] #[allow(clippy::new_ret_no_self)] - pub fn new(property_name: &str) -> Message { + pub fn new(object: &impl IsA, property_name: &str) -> Message { skip_assert_initialized!(); - Self::builder(property_name).build() + Self::builder(object, property_name).build() } - pub fn builder(property_name: &str) -> PropertyNotifyBuilder { + pub fn builder<'a>( + object: &'a impl IsA, + property_name: &'a str, + ) -> PropertyNotifyBuilder<'a> { assert_initialized_main_thread!(); - PropertyNotifyBuilder::new(property_name) + PropertyNotifyBuilder::new(property_name).src(object) } #[doc(alias = "gst_message_parse_property_notify")] diff --git a/gstreamer/src/query.rs b/gstreamer/src/query.rs index 0f554eeb2..5c6acb13b 100644 --- a/gstreamer/src/query.rs +++ b/gstreamer/src/query.rs @@ -939,7 +939,7 @@ impl Default for Uri { impl Uri { #[doc(alias = "get_uri")] #[doc(alias = "gst_query_parse_uri")] - pub fn uri(&self) -> Option { + pub fn uri(&self) -> Option { unsafe { let mut uri = ptr::null_mut(); ffi::gst_query_parse_uri(self.as_mut_ptr(), &mut uri); @@ -950,7 +950,7 @@ impl Uri { #[doc(alias = "get_redirection")] #[doc(alias = "gst_query_parse_uri_redirection")] #[doc(alias = "gst_query_parse_uri_redirection_permanent")] - pub fn redirection(&self) -> (Option, bool) { + pub fn redirection(&self) -> (Option, bool) { unsafe { let mut uri = ptr::null_mut(); ffi::gst_query_parse_uri_redirection(self.as_mut_ptr(), &mut uri); @@ -965,7 +965,7 @@ impl Uri { } #[doc(alias = "gst_query_set_uri")] - pub fn set_uri(&mut self, uri: &str) { + pub fn set_uri(&mut self, uri: Option<&str>) { unsafe { ffi::gst_query_set_uri(self.as_mut_ptr(), uri.to_glib_none().0); } @@ -973,7 +973,7 @@ impl Uri { #[doc(alias = "gst_query_set_uri_redirection")] #[doc(alias = "gst_query_set_uri_redirection_permanent")] - pub fn set_redirection(&mut self, uri: &str, permanent: bool) { + pub fn set_redirection(&mut self, uri: Option<&str>, permanent: bool) { unsafe { ffi::gst_query_set_uri_redirection(self.as_mut_ptr(), uri.to_glib_none().0); ffi::gst_query_set_uri_redirection_permanent( @@ -1453,9 +1453,13 @@ impl Caps { } #[doc(alias = "gst_query_set_caps_result")] - pub fn set_result(&mut self, caps: &crate::Caps) { + pub fn set_result(&mut self, caps: Option<&crate::Caps>) { unsafe { - ffi::gst_query_set_caps_result(self.as_mut_ptr(), caps.as_mut_ptr()); + ffi::gst_query_set_caps_result( + self.as_mut_ptr(), + caps.map(|caps| caps.as_mut_ptr()) + .unwrap_or(ptr::null_mut()), + ); } } } @@ -1523,9 +1527,14 @@ impl Context { } #[doc(alias = "gst_query_set_context")] - pub fn set_context(&mut self, context: &crate::Context) { + pub fn set_context(&mut self, context: Option<&crate::Context>) { unsafe { - ffi::gst_query_set_context(self.as_mut_ptr(), context.as_mut_ptr()); + ffi::gst_query_set_context( + self.as_mut_ptr(), + context + .map(|context| context.as_mut_ptr()) + .unwrap_or(ptr::null_mut()), + ); } } } diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index a216493a0..cff9041ba 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -1027,16 +1027,11 @@ pub fn tag_get_type(name: &str) -> glib::Type { } #[doc(alias = "gst_tag_get_nick")] -pub fn tag_get_nick<'b>(name: &str) -> Option<&'b str> { +pub fn tag_get_nick(name: &str) -> &str { skip_assert_initialized!(); unsafe { let ptr = ffi::gst_tag_get_nick(name.to_glib_none().0); - - if ptr.is_null() { - None - } else { - Some(CStr::from_ptr(ptr).to_str().unwrap()) - } + CStr::from_ptr(ptr).to_str().unwrap() } } @@ -1324,10 +1319,7 @@ mod tests { tag_get_type(MyCustomTag::tag_name()), ::TagType::static_type() ); - assert_eq!( - tag_get_nick(MyCustomTag::tag_name()), - Some(MyCustomTag::NICK) - ); + assert_eq!(tag_get_nick(MyCustomTag::tag_name()), MyCustomTag::NICK); assert_eq!( tag_get_description(MyCustomTag::tag_name()), Some(MyCustomTag::DESCRIPTION) diff --git a/gstreamer/src/toc.rs b/gstreamer/src/toc.rs index 7ab5bf885..5fbbdb8f3 100644 --- a/gstreamer/src/toc.rs +++ b/gstreamer/src/toc.rs @@ -3,6 +3,7 @@ use std::ffi::CStr; use std::fmt; use std::mem; +use std::ptr; use glib::translate::{ from_glib, from_glib_full, from_glib_none, FromGlibPtrContainer, IntoGlib, IntoGlibPtr, @@ -57,16 +58,25 @@ impl TocRef { } #[doc(alias = "gst_toc_set_tags")] - pub fn set_tags(&mut self, tag_list: TagList) { + pub fn set_tags(&mut self, tag_list: Option) { unsafe { - ffi::gst_toc_set_tags(self.as_mut_ptr(), tag_list.into_glib_ptr()); + ffi::gst_toc_set_tags( + self.as_mut_ptr(), + tag_list + .map(|t| t.into_glib_ptr()) + .unwrap_or(ptr::null_mut()), + ); } } #[doc(alias = "gst_toc_merge_tags")] - pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) { + pub fn merge_tags(&mut self, tag_list: Option<&TagList>, mode: TagMergeMode) { unsafe { - ffi::gst_toc_merge_tags(self.as_mut_ptr(), tag_list.as_mut_ptr(), mode.into_glib()); + ffi::gst_toc_merge_tags( + self.as_mut_ptr(), + tag_list.map(|l| l.as_mut_ptr()).unwrap_or(ptr::null_mut()), + mode.into_glib(), + ); } } @@ -182,18 +192,23 @@ impl TocEntryRef { } #[doc(alias = "gst_toc_entry_set_tags")] - pub fn set_tags(&mut self, tag_list: TagList) { + pub fn set_tags(&mut self, tag_list: Option) { unsafe { - ffi::gst_toc_entry_set_tags(self.as_mut_ptr(), tag_list.into_glib_ptr()); + ffi::gst_toc_entry_set_tags( + self.as_mut_ptr(), + tag_list + .map(|t| t.into_glib_ptr()) + .unwrap_or(ptr::null_mut()), + ); } } #[doc(alias = "gst_toc_entry_merge_tags")] - pub fn merge_tags(&mut self, tag_list: &TagList, mode: TagMergeMode) { + pub fn merge_tags(&mut self, tag_list: Option<&TagList>, mode: TagMergeMode) { unsafe { ffi::gst_toc_entry_merge_tags( self.as_mut_ptr(), - tag_list.as_mut_ptr(), + tag_list.map(|l| l.as_mut_ptr()).unwrap_or(ptr::null_mut()), mode.into_glib(), ); } diff --git a/gstreamer/src/toc_serde.rs b/gstreamer/src/toc_serde.rs index 9d497ec9f..09010ad18 100644 --- a/gstreamer/src/toc_serde.rs +++ b/gstreamer/src/toc_serde.rs @@ -57,9 +57,7 @@ impl From for Toc { let mut toc = Toc::new(toc_de.scope); { let toc = toc.get_mut().unwrap(); - if let Some(tags) = toc_de.tags.take() { - toc.set_tags(tags); - } + toc.set_tags(toc_de.tags.take()); let entry_iter = toc_de.entries.drain(..); for entry in entry_iter { toc.append_entry(entry); @@ -96,9 +94,7 @@ impl From for TocEntry { if let Some(start_stop) = toc_entry_de.start_stop.take() { toc_entry.set_start_stop_times(start_stop.0, start_stop.1); } - if let Some(tags) = toc_entry_de.tags.take() { - toc_entry.set_tags(tags); - } + toc_entry.set_tags(toc_entry_de.tags.take()); if let Some(loop_) = toc_entry_de.loop_.take() { toc_entry.set_loop(loop_.0, loop_.1); } @@ -139,7 +135,7 @@ mod tests { tags.get_mut() .unwrap() .add::(&"toc", TagMergeMode::Append); - toc.set_tags(tags); + toc.set_tags(Some(tags)); let mut toc_edition = TocEntry::new(TocEntryType::Edition, "edition"); { @@ -158,7 +154,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.1", TagMergeMode::Append); - toc_chap_1_1.set_tags(tags); + toc_chap_1_1.set_tags(Some(tags)); } toc_chap_1.append_sub_entry(toc_chap_1_1); @@ -170,7 +166,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.2", TagMergeMode::Append); - toc_chap_1_2.set_tags(tags); + toc_chap_1_2.set_tags(Some(tags)); } toc_chap_1.append_sub_entry(toc_chap_1_2); } @@ -184,7 +180,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 2", TagMergeMode::Append); - toc_chap_2.set_tags(tags); + toc_chap_2.set_tags(Some(tags)); } toc_edition.append_sub_entry(toc_chap_2); } @@ -419,7 +415,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"toc", TagMergeMode::Append); - toc.set_tags(tags); + toc.set_tags(Some(tags)); let mut toc_edition = TocEntry::new(TocEntryType::Edition, "edition"); { @@ -438,7 +434,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.1", TagMergeMode::Append); - toc_chap_1_1.set_tags(tags); + toc_chap_1_1.set_tags(Some(tags)); } toc_chap_1.append_sub_entry(toc_chap_1_1); @@ -450,7 +446,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 1.2", TagMergeMode::Append); - toc_chap_1_2.set_tags(tags); + toc_chap_1_2.set_tags(Some(tags)); } toc_chap_1.append_sub_entry(toc_chap_1_2); } @@ -464,7 +460,7 @@ mod tests { tags.get_mut() .unwrap() .add::<Title>(&"chapter 2", TagMergeMode::Append); - toc_chap_2.set_tags(tags); + toc_chap_2.set_tags(Some(tags)); } toc_edition.append_sub_entry(toc_chap_2); } diff --git a/tutorials/src/bin/basic-tutorial-9.rs b/tutorials/src/bin/basic-tutorial-9.rs index 40cac7b41..52bf4ab55 100644 --- a/tutorials/src/bin/basic-tutorial-9.rs +++ b/tutorials/src/bin/basic-tutorial-9.rs @@ -24,7 +24,6 @@ fn print_stream_info(info: &DiscovererStreamInfo, depth: usize) { let caps_str = if let Some(caps) = info.caps() { if caps.is_fixed() { gst_pbutils::pb_utils_get_codec_description(&caps) - .unwrap_or_else(|_| glib::GString::from("unknown codec")) } else { glib::GString::from(caps.to_string()) } @@ -82,7 +81,7 @@ fn on_discovered( discoverer_info: &DiscovererInfo, error: Option<&glib::Error>, ) { - let uri = discoverer_info.uri().unwrap(); + let uri = discoverer_info.uri(); match discoverer_info.result() { DiscovererResult::Ok => println!("Discovered {}", uri), DiscovererResult::UriInvalid => println!("Invalid uri {}", uri),