python: Add __eq__ to Mtd classes

Also programatically iterate all of the base classes to register them.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8237>
This commit is contained in:
Olivier Crête 2025-01-20 14:53:36 -06:00 committed by GStreamer Marge Bot
parent ad4fa052e5
commit 86bac82c8e
2 changed files with 25 additions and 7 deletions

View file

@ -35,11 +35,30 @@ _gi_gst_analytics
__mtd_types__ = {} __mtd_types__ = {}
def init(): class Mtd(GstAnalytics.Mtd):
__mtd_types__[GstAnalytics.ODMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_od_mtd def __eq__(self, other):
__mtd_types__[GstAnalytics.ClsMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_cls_mtd if not hasattr(other, 'meta') or not hasattr(other, 'id'):
__mtd_types__[GstAnalytics.TrackingMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_tracking_mtd return False
__mtd_types__[GstAnalytics.SegmentationMtd.get_mtd_type()] = GstAnalytics.RelationMeta.get_segmentation_mtd return self.meta == other.meta and self.id == other.id
__all__.append('Mtd')
def _wrap_mtd(module, name, getter):
baseclass = getattr(module, name)
wrapper = type(name, (baseclass, Mtd), {})
globals()[name] = wrapper
__mtd_types__[baseclass.get_mtd_type()] = getter
__all__.append(name)
for c in dir(GstAnalytics):
if c.endswith('Mtd') and c != 'Mtd':
lower_c = c[:-3].lower()
getter = getattr(GstAnalytics.RelationMeta, 'get_' + lower_c + '_mtd')
_wrap_mtd(GstAnalytics, c, getter)
def _get_mtd(mtd_type, rmeta, mtd_id): def _get_mtd(mtd_type, rmeta, mtd_id):
@ -55,4 +74,3 @@ class RelationMeta(GstAnalytics.RelationMeta):
__all__.append('RelationMeta') __all__.append('RelationMeta')
__all__.append('init')

View file

@ -37,7 +37,6 @@ from gi.repository import Gst
from gi.repository import GstAnalytics from gi.repository import GstAnalytics
from gi.repository import GstVideo from gi.repository import GstVideo
Gst.init(None) Gst.init(None)
GstAnalytics.init()
class TestAnalyticsODMtd(TestCase): class TestAnalyticsODMtd(TestCase):
@ -280,6 +279,7 @@ class TestAnalyticsRelationMetaIterator(TestCase):
self.assertEqual(len(mtds), len(mtds_from_iter)) self.assertEqual(len(mtds), len(mtds_from_iter))
for e, i in zip(mtds, rmeta): for e, i in zip(mtds, rmeta):
assert i == e[0]
assert e[0].id == i.id assert e[0].id == i.id
assert e[0].meta == i.meta assert e[0].meta == i.meta
assert e[1] == i.get_mtd_type() assert e[1] == i.get_mtd_type()