From 96ecb224683f4a01217971308149e5a36f20895e Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 30 Jan 2019 15:45:21 -0300 Subject: 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. --- gi/overrides/Gst.py | 2 +- gi/overrides/GstPbutils.py | 75 ++++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py index 499e82f..075366b 100644 --- a/gi/overrides/Gst.py +++ b/gi/overrides/Gst.py @@ -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: diff --git a/gi/overrides/GstPbutils.py b/gi/overrides/GstPbutils.py index f8e5e73..74fd33e 100644 --- a/gi/overrides/GstPbutils.py +++ b/gi/overrides/GstPbutils.py @@ -43,41 +43,50 @@ 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): - def __init__(self, format, preset=None, restriction=None, presence=0): - GstPbutils.EncodingVideoProfile.__init__(self) - self.set_format(format) - if preset is not None: - self.set_preset(preset) - if restriction is None: - restriction = Gst.Caps('ANY') - self.set_restriction(restriction) - self.set_presence(presence) + 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) + if preset is not None: + self.set_preset(preset) + if restriction is None: + restriction = Gst.Caps('ANY') + self.set_restriction(restriction) + self.set_presence(presence) -@override -class EncodingAudioProfile(GstPbutils.EncodingAudioProfile): - def __init__(self, format, preset=None, restriction=None, presence=0): - GstPbutils.EncodingAudioProfile.__init__(self) - self.set_format(format) - if preset is not None: - self.set_preset(preset) - if restriction is None: - restriction = Gst.Caps('ANY') - self.set_restriction(restriction) - self.set_presence(presence) + @override + class EncodingAudioProfile(GstPbutils.EncodingAudioProfile): + def __init__(self, format, preset=None, restriction=None, presence=0): + GstPbutils.EncodingAudioProfile.__init__(self) + self.set_format(format) + if preset is not None: + self.set_preset(preset) + if restriction is None: + restriction = Gst.Caps('ANY') + self.set_restriction(restriction) + self.set_presence(presence) + @override + class EncodingContainerProfile(GstPbutils.EncodingContainerProfile): + def __init__(self, name, description, format, preset=None): + GstPbutils.EncodingContainerProfile.__init__(self) + self.set_format(format) + if name is not None: + self.set_name(name) + if description is not None: + self.set_description(description) + if preset is not None: + self.set_preset(preset) -@override -class EncodingContainerProfile(GstPbutils.EncodingContainerProfile): - def __init__(self, name, description, format, preset=None): - GstPbutils.EncodingContainerProfile.__init__(self) - self.set_format(format) - if name is not None: - self.set_name(name) - if description is not None: - 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 -- cgit v1.2.3