python: More functions can be called before gst_init()
authorNirbheek Chauhan <nirbheek@centricular.com>
Tue, 30 May 2023 15:18:39 +0000 (20:48 +0530)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 2 Jun 2023 23:42:41 +0000 (23:42 +0000)
Configuration of our debugging system is possible before init, and in
fact is necessary too, otherwise the settings won't apply to logging
that happens during init.

For instance, since you cannot register a log function before you call
init in python, there is no way for you to log errors during init to
whatever logging service your app uses.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4763>

subprojects/gst-python/gi/overrides/Gst.py

index 307ba9c..6ecdec1 100644 (file)
@@ -760,6 +760,23 @@ for cname_klass in [o for o in inspect.getmembers(Gst) if isinstance(o[1], type(
                           for o in cname_klass[1].__dict__
                           if isinstance(cname_klass[1].__dict__[o], type(Gst.init))]))
 
+pre_init_functions = set([
+    "init",
+    "init_check",
+    "deinit",
+    "is_initialized",
+    "debug_add_log_function",
+    "debug_add_ring_buffer_logger",
+    "debug_remove_log_function",
+    "debug_remove_log_function_by_data",
+    "debug_remove_ring_buffer_logger",
+    "debug_set_active",
+    "debug_set_color_mode",
+    "debug_set_color_mode_from_string",
+    "debug_set_colored",
+    "debug_set_default_threshold",
+])
+
 
 def init_pygst():
     for fname, function in real_functions:
@@ -773,7 +790,7 @@ def init_pygst():
 
 def deinit_pygst():
     for fname, func in real_functions:
-        if fname not in ["init", "init_check", "deinit", "is_initialized"]:
+        if fname not in pre_init_functions:
             setattr(Gst, fname, fake_method)
     for cname_class, methods in class_methods:
         for mname, method in methods: