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.
This commit is contained in:
Thibault Saunier 2019-01-30 15:45:21 -03:00
parent 8e42b63201
commit 96ecb22468
2 changed files with 43 additions and 34 deletions

View file

@ -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:

View file

@ -43,6 +43,12 @@ 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")
real_init()
@override
class EncodingVideoProfile(GstPbutils.EncodingVideoProfile):
@ -56,7 +62,6 @@ class EncodingVideoProfile(GstPbutils.EncodingVideoProfile):
self.set_restriction(restriction)
self.set_presence(presence)
@override
class EncodingAudioProfile(GstPbutils.EncodingAudioProfile):
def __init__(self, format, preset=None, restriction=None, presence=0):
@ -69,7 +74,6 @@ class EncodingAudioProfile(GstPbutils.EncodingAudioProfile):
self.set_restriction(restriction)
self.set_presence(presence)
@override
class EncodingContainerProfile(GstPbutils.EncodingContainerProfile):
def __init__(self, name, description, format, preset=None):
@ -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()