From ab0b99c4856e813cbce90477dd6c1a5386b88ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Mon, 11 Mar 2024 16:10:37 -0400 Subject: [PATCH] analytics: Allow empty object type Part-of: --- gstreamer-analytics/src/object_detection.rs | 12 ++++++++---- gstreamer-analytics/src/relation_meta.rs | 6 +++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/gstreamer-analytics/src/object_detection.rs b/gstreamer-analytics/src/object_detection.rs index d367d5e4a..443d355b5 100644 --- a/gstreamer-analytics/src/object_detection.rs +++ b/gstreamer-analytics/src/object_detection.rs @@ -82,11 +82,15 @@ unsafe fn from(t: ffi::GstAnalyticsMtd) -> ffi::GstAnalyticsODMtd { impl<'a> AnalyticsMtdRef<'a, AnalyticsODMtd> { #[doc(alias = "gst_analytics_od_mtd_get_obj_type")] - pub fn obj_type(&self) -> glib::Quark { + pub fn obj_type(&self) -> Option { unsafe { let mut mtd = from(ffi::GstAnalyticsMtd::unsafe_from(self)); let type_ = ffi::gst_analytics_od_mtd_get_obj_type(&mut mtd); - glib::Quark::from_glib(type_) + if type_ == 0 { + None + } else { + Some(glib::Quark::from_glib(type_)) + } } } @@ -143,7 +147,7 @@ mod tests { .add_od_mtd(glib::Quark::from_str("blb"), 0, 1, 10, 20, 0.8) .unwrap(); - assert_eq!(od.obj_type(), glib::Quark::from_str("blb")); + assert_eq!(od.obj_type().unwrap(), glib::Quark::from_str("blb")); let loc = od.location().unwrap(); @@ -159,7 +163,7 @@ mod tests { let meta2 = buf.meta::().unwrap(); let od2 = meta2.mtd::(0).unwrap(); - assert_eq!(od2.obj_type(), glib::Quark::from_str("blb")); + assert_eq!(od2.obj_type().unwrap(), glib::Quark::from_str("blb")); let loc = od2.location().unwrap(); assert_eq!(loc.x, 0); diff --git a/gstreamer-analytics/src/relation_meta.rs b/gstreamer-analytics/src/relation_meta.rs index 03e70349e..3fb566ddc 100644 --- a/gstreamer-analytics/src/relation_meta.rs +++ b/gstreamer-analytics/src/relation_meta.rs @@ -652,13 +652,13 @@ mod tests { assert_eq!(meta.len(), meta.iter::().count()); assert_eq!(meta.len(), meta.iter::().count()); for mtd in meta.iter::() { - assert_eq!(mtd.obj_type(), glib::Quark::from_str("blb")) + assert_eq!(mtd.obj_type().unwrap(), glib::Quark::from_str("blb")) } assert_eq!(meta.len(), meta.iter::().count()); for mtd in meta.iter::() { if let Ok(mtd) = mtd.downcast::() { - assert_eq!(mtd.obj_type(), glib::Quark::from_str("blb")) + assert_eq!(mtd.obj_type().unwrap(), glib::Quark::from_str("blb")) } } @@ -689,7 +689,7 @@ mod tests { 0 ); for mtd in meta.iter_direct_related::(od1_id, crate::RelTypes::IS_PART_OF) { - assert_eq!(mtd.obj_type(), glib::Quark::from_str("blb")) + assert_eq!(mtd.obj_type().unwrap(), glib::Quark::from_str("blb")) } let mut meta = buf.make_mut().meta_mut::().unwrap();