Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
95 lines (82 loc) · 2.74 KB
/
Copy path__init__.py
File metadata and controls
95 lines (82 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Pluggable element backend
# Copyright (C) 2024-2026 Collabora Ltd.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
"""Pluggable multimedia-framework backend for the ML elements.
The ML logic (engines, tasks, base classes) is framework-agnostic. The pieces
that DO depend on the framework are isolated behind this package:
* the element base classes `BaseTransform` / `BaseAggregator` / `VideoTransform`
* the `analytics` metadata interface (add/get/remove detections)
Select the active backend with the `PYML_BACKEND` environment variable
(default ``"gst"``). To add another backend, create a sibling package exposing
the same names (reusing `backend.core.MLEngineMixin` and implementing
`backend.analytics.AnalyticsBackend`) and add a branch below.
"""
from backend.analytics import AnalyticsBackend # noqa: F401 (re-exported)
from backend.frameio import FrameIO # noqa: F401 (re-exported)
from backend.core import MLEngineMixin # noqa: F401 (re-exported)
from utils.selected_backend import BACKEND
if BACKEND == "gst":
from backend.gst import (
BaseTransform,
BaseAggregator,
VideoTransform,
InPlaceVideoTransform,
InPlaceAudioTransform,
BaseSink,
analytics,
frameio,
FlowReturn,
GObject,
post_error,
post_model_load_error,
)
elif BACKEND == "g2g":
from backend.g2g import (
BaseTransform,
BaseAggregator,
VideoTransform,
InPlaceVideoTransform,
InPlaceAudioTransform,
BaseSink,
analytics,
frameio,
FlowReturn,
GObject,
post_error,
post_model_load_error,
)
else:
raise ImportError(
f"Unknown PYML_BACKEND={BACKEND!r}; supported backends: 'gst', 'g2g'"
)
def register_gst_element(name, cls, type_name=None):
"""Register `cls` with the GObject type system and return its factory tuple.
Leaf elements call this behind a `BACKEND == "gst"` guard: under g2g the
element base classes are plain Python objects, so type_register would fail.
"""
from backend.gst import Gst, GObject
GObject.type_register(cls, type_name)
return (name, Gst.Rank.NONE, cls)
__all__ = [
"BACKEND",
"register_gst_element",
"BaseTransform",
"BaseAggregator",
"VideoTransform",
"InPlaceVideoTransform",
"InPlaceAudioTransform",
"BaseSink",
"analytics",
"frameio",
"FlowReturn",
"GObject",
"post_error",
"post_model_load_error",
"AnalyticsBackend",
"FrameIO",
"MLEngineMixin",
]