mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-22 08:07:07 +00:00
net: fix faillible PtpClock::new()
`PtpClock::new()` can fail in which case it panicked due to an assertion failure. This commit makes it return a `Result` instead. Also sets the `name` argument optional, similar to what is done for `NtpClock`. See also: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6251 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1405>
This commit is contained in:
parent
353e3d1611
commit
ffad1188b9
2 changed files with 18 additions and 3 deletions
|
@ -57,3 +57,14 @@ final_type = true
|
|||
name = "GstNet.PtpClock"
|
||||
status = "generate"
|
||||
final_type = true
|
||||
[[object.function]]
|
||||
name = "new"
|
||||
[[object.function.parameter]]
|
||||
name = "name"
|
||||
# See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6251
|
||||
nullable = true
|
||||
|
||||
[object.function.return]
|
||||
# See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6251
|
||||
nullable = true
|
||||
nullable_return_is_error = "Can't create gst::PtpClock"
|
||||
|
|
|
@ -21,11 +21,15 @@ glib::wrapper! {
|
|||
|
||||
impl PtpClock {
|
||||
#[doc(alias = "gst_ptp_clock_new")]
|
||||
pub fn new(name: &str, domain: u32) -> PtpClock {
|
||||
pub fn new(name: Option<&str>, domain: u32) -> Result<PtpClock, glib::BoolError> {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
gst::Clock::from_glib_full(ffi::gst_ptp_clock_new(name.to_glib_none().0, domain))
|
||||
.unsafe_cast()
|
||||
Option::<gst::Clock>::from_glib_full(ffi::gst_ptp_clock_new(
|
||||
name.to_glib_none().0,
|
||||
domain,
|
||||
))
|
||||
.map(|o| o.unsafe_cast())
|
||||
.ok_or_else(|| glib::bool_error!("Can't create gst::PtpClock"))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue