Commit 96ecb224 authored by Thibault Saunier's avatar Thibault Saunier

Gst.init() has to be called before GstPbutils is imported

This makes sure that we do not try to use GstPbutils before Gst is init
and in case GstPbutils is imported while Gst is not imported, use the
`GstPbutils.pb_utils_init()` function to have the oportunity to
initialize the overrides.

Not that we also introduce a `GstPbutils.init()` variant because
`GstPbutils.pb_utils_init()` is an ugly name.
parent 8e42b632
Pipeline #16988 passed with stages
in 16 minutes and 51 seconds
......@@ -626,7 +626,7 @@ def init_pygst():
def deinit_pygst():
for fname, func in real_functions:
if fname not in ["init", "init_check", "deinit"]:
if fname not in ["init", "init_check", "deinit", "is_initialized"]:
setattr(Gst, fname, fake_method)
for cname_class, methods in class_methods:
for mname, method in methods:
......
......@@ -43,9 +43,15 @@ def override(cls):
return cls
real_init = GstPbutils.pb_utils_init
def init():
if not Gst.is_initialized():
raise RuntimeError("Gst.init() needs to be called before importing GstPbutils")
@override
class EncodingVideoProfile(GstPbutils.EncodingVideoProfile):
real_init()
@override
class EncodingVideoProfile(GstPbutils.EncodingVideoProfile):
def __init__(self, format, preset=None, restriction=None, presence=0):
GstPbutils.EncodingVideoProfile.__init__(self)
self.set_format(format)
......@@ -56,9 +62,8 @@ class EncodingVideoProfile(GstPbutils.EncodingVideoProfile):
self.set_restriction(restriction)
self.set_presence(presence)
@override
class EncodingAudioProfile(GstPbutils.EncodingAudioProfile):
@override
class EncodingAudioProfile(GstPbutils.EncodingAudioProfile):
def __init__(self, format, preset=None, restriction=None, presence=0):
GstPbutils.EncodingAudioProfile.__init__(self)
self.set_format(format)
......@@ -69,9 +74,8 @@ class EncodingAudioProfile(GstPbutils.EncodingAudioProfile):
self.set_restriction(restriction)
self.set_presence(presence)
@override
class EncodingContainerProfile(GstPbutils.EncodingContainerProfile):
@override
class EncodingContainerProfile(GstPbutils.EncodingContainerProfile):
def __init__(self, name, description, format, preset=None):
GstPbutils.EncodingContainerProfile.__init__(self)
self.set_format(format)
......@@ -81,3 +85,8 @@ class EncodingContainerProfile(GstPbutils.EncodingContainerProfile):
self.set_description(description)
if preset is not None:
self.set_preset(preset)
GstPbutils.pb_utils_init = init
GstPbutils.init = init
if Gst.is_initialized():
init()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment