From fa4f45b8d39892db1ab3c7738ed7362f1fa4fb98 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 28 Jun 2022 16:35:58 -0400 Subject: [PATCH] python: Add a Gst.init_python function to be called from plugins Plugins know that they will be initialized after Gst was initialized so they can call the initialization function dedicated for the python bindings Part-of: --- .../gst-python/examples/plugins/python/audioplot.py | 2 +- .../gst-python/examples/plugins/python/exampleTransform.py | 2 +- subprojects/gst-python/examples/plugins/python/identity.py | 2 +- subprojects/gst-python/examples/plugins/python/mixer.py | 2 +- .../gst-python/examples/plugins/python/py_audiotestsrc.py | 2 ++ .../gst-python/examples/plugins/python/sinkelement.py | 2 +- subprojects/gst-python/gi/overrides/Gst.py | 7 +++++++ 7 files changed, 14 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-python/examples/plugins/python/audioplot.py b/subprojects/gst-python/examples/plugins/python/audioplot.py index cf1032fd4f..8747fee1a1 100644 --- a/subprojects/gst-python/examples/plugins/python/audioplot.py +++ b/subprojects/gst-python/examples/plugins/python/audioplot.py @@ -29,7 +29,7 @@ except ImportError: raise -Gst.init(None) +Gst.init_python() AUDIO_FORMATS = [f.strip() for f in GstAudio.AUDIO_FORMATS_ALL.strip('{ }').split(',')] diff --git a/subprojects/gst-python/examples/plugins/python/exampleTransform.py b/subprojects/gst-python/examples/plugins/python/exampleTransform.py index ed739048e9..d244acb478 100755 --- a/subprojects/gst-python/examples/plugins/python/exampleTransform.py +++ b/subprojects/gst-python/examples/plugins/python/exampleTransform.py @@ -15,7 +15,7 @@ from gi.repository import Gst, GObject, GstBase, GstVideo import numpy as np -Gst.init(None) +Gst.init_python() FIXED_CAPS = Gst.Caps.from_string('video/x-raw,format=GRAY8,width=[1,2147483647],height=[1,2147483647]') class ExampleTransform(GstBase.BaseTransform): diff --git a/subprojects/gst-python/examples/plugins/python/identity.py b/subprojects/gst-python/examples/plugins/python/identity.py index 0f42efcccd..23baf210e5 100644 --- a/subprojects/gst-python/examples/plugins/python/identity.py +++ b/subprojects/gst-python/examples/plugins/python/identity.py @@ -16,7 +16,7 @@ import gi gi.require_version('GstBase', '1.0') from gi.repository import Gst, GObject, GstBase -Gst.init(None) +Gst.init_python() # # Simple Identity element created entirely in python diff --git a/subprojects/gst-python/examples/plugins/python/mixer.py b/subprojects/gst-python/examples/plugins/python/mixer.py index 5d9aafe45c..846508a8a5 100644 --- a/subprojects/gst-python/examples/plugins/python/mixer.py +++ b/subprojects/gst-python/examples/plugins/python/mixer.py @@ -20,7 +20,7 @@ gi.require_version('GObject', '2.0') from gi.repository import Gst, GObject, GstBase -Gst.init(None) +Gst.init_python() try: from PIL import Image diff --git a/subprojects/gst-python/examples/plugins/python/py_audiotestsrc.py b/subprojects/gst-python/examples/plugins/python/py_audiotestsrc.py index 5e5ef3bfd9..3684d67347 100644 --- a/subprojects/gst-python/examples/plugins/python/py_audiotestsrc.py +++ b/subprojects/gst-python/examples/plugins/python/py_audiotestsrc.py @@ -22,6 +22,8 @@ except ImportError: Gst.error('py_audiotestsrc requires numpy') raise +Gst.init_python() + OCAPS = Gst.Caps.from_string ( 'audio/x-raw, format=F32LE, layout=interleaved, rate=44100, channels=2') diff --git a/subprojects/gst-python/examples/plugins/python/sinkelement.py b/subprojects/gst-python/examples/plugins/python/sinkelement.py index 2ec360880b..2fcb8660b6 100644 --- a/subprojects/gst-python/examples/plugins/python/sinkelement.py +++ b/subprojects/gst-python/examples/plugins/python/sinkelement.py @@ -17,7 +17,7 @@ # $ GST_DEBUG=python:4 gst-launch-1.0 fakesrc num-buffers=10 ! mysink from gi.repository import Gst, GObject, GstBase -Gst.init(None) +Gst.init_python() # # Simple Sink element created entirely in python diff --git a/subprojects/gst-python/gi/overrides/Gst.py b/subprojects/gst-python/gi/overrides/Gst.py index 788ba972cf..d0f2e82f49 100644 --- a/subprojects/gst-python/gi/overrides/Gst.py +++ b/subprojects/gst-python/gi/overrides/Gst.py @@ -747,7 +747,14 @@ def deinit(): deinit_pygst() return real_deinit() +def init_python(): + if not Gst.is_initialized(): + raise NotInitialized("Gst.init_python should never be called before GStreamer itself is initialized") + + init_pygst() + Gst.deinit = deinit +Gst.init_python = init_python if not Gst.is_initialized(): deinit_pygst()