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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2737>
This commit is contained in:
Thibault Saunier 2022-06-28 16:35:58 -04:00 committed by Tim-Philipp Müller
parent f50c68d4e2
commit fa4f45b8d3
7 changed files with 14 additions and 5 deletions

View file

@ -29,7 +29,7 @@ except ImportError:
raise raise
Gst.init(None) Gst.init_python()
AUDIO_FORMATS = [f.strip() for f in AUDIO_FORMATS = [f.strip() for f in
GstAudio.AUDIO_FORMATS_ALL.strip('{ }').split(',')] GstAudio.AUDIO_FORMATS_ALL.strip('{ }').split(',')]

View file

@ -15,7 +15,7 @@ from gi.repository import Gst, GObject, GstBase, GstVideo
import numpy as np 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]') FIXED_CAPS = Gst.Caps.from_string('video/x-raw,format=GRAY8,width=[1,2147483647],height=[1,2147483647]')
class ExampleTransform(GstBase.BaseTransform): class ExampleTransform(GstBase.BaseTransform):

View file

@ -16,7 +16,7 @@ import gi
gi.require_version('GstBase', '1.0') gi.require_version('GstBase', '1.0')
from gi.repository import Gst, GObject, GstBase from gi.repository import Gst, GObject, GstBase
Gst.init(None) Gst.init_python()
# #
# Simple Identity element created entirely in python # Simple Identity element created entirely in python

View file

@ -20,7 +20,7 @@ gi.require_version('GObject', '2.0')
from gi.repository import Gst, GObject, GstBase from gi.repository import Gst, GObject, GstBase
Gst.init(None) Gst.init_python()
try: try:
from PIL import Image from PIL import Image

View file

@ -22,6 +22,8 @@ except ImportError:
Gst.error('py_audiotestsrc requires numpy') Gst.error('py_audiotestsrc requires numpy')
raise raise
Gst.init_python()
OCAPS = Gst.Caps.from_string ( OCAPS = Gst.Caps.from_string (
'audio/x-raw, format=F32LE, layout=interleaved, rate=44100, channels=2') 'audio/x-raw, format=F32LE, layout=interleaved, rate=44100, channels=2')

View file

@ -17,7 +17,7 @@
# $ GST_DEBUG=python:4 gst-launch-1.0 fakesrc num-buffers=10 ! mysink # $ GST_DEBUG=python:4 gst-launch-1.0 fakesrc num-buffers=10 ! mysink
from gi.repository import Gst, GObject, GstBase from gi.repository import Gst, GObject, GstBase
Gst.init(None) Gst.init_python()
# #
# Simple Sink element created entirely in python # Simple Sink element created entirely in python

View file

@ -747,7 +747,14 @@ def deinit():
deinit_pygst() deinit_pygst()
return real_deinit() 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.deinit = deinit
Gst.init_python = init_python
if not Gst.is_initialized(): if not Gst.is_initialized():
deinit_pygst() deinit_pygst()