Skip to content
Snippets Groups Projects
Commit 6b32ccbb authored by Thibault Saunier's avatar Thibault Saunier :cactus:
Browse files

overrides: Disable all GStreamer APIs until Gst has been initialized

Summary:
And throw an exception if the user tries to call any Gst API without
initializing gst.

https://bugzilla.gnome.org/show_bug.cgi?id=747555

Reviewers: Mathieu_Du

Differential Revision: http://phabricator.freedesktop.org/D87
parent 67d7adc8
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,8 @@ import sys ...@@ -28,6 +28,8 @@ import sys
from inspect import signature from inspect import signature
from ..overrides import override from ..overrides import override
from ..importer import modules from ..importer import modules
from inspect import getmembers
if sys.version_info >= (3, 0): if sys.version_info >= (3, 0):
_basestring = str _basestring = str
...@@ -335,3 +337,60 @@ Gst.warning = _gi_gst.warning ...@@ -335,3 +337,60 @@ Gst.warning = _gi_gst.warning
Gst.error = _gi_gst.error Gst.error = _gi_gst.error
Gst.fixme = _gi_gst.fixme Gst.fixme = _gi_gst.fixme
Gst.memdump = _gi_gst.memdump Gst.memdump = _gi_gst.memdump
# Make sure PyGst is not usable if GStreamer has not been initialized
class NotInitalized(Exception):
pass
__all__.append('NotInitalized')
def fake_method(*args):
raise NotInitalized("Please call Gst.init(argv) before using GStreamer")
real_functions = [o for o in getmembers(Gst) if isinstance(o[1], type(Gst.init))]
class_methods = []
for cname_klass in [o for o in getmembers(Gst) if isinstance(o[1], type(Gst.Element)) or isinstance(o[1], type(Gst.Caps))]:
class_methods.append((cname_klass,
[(o, cname_klass[1].__dict__[o])
for o in cname_klass[1].__dict__
if isinstance(cname_klass[1].__dict__[o], type(Gst.init))]))
def init_pygst():
for fname, function in real_functions:
if fname not in ["init", "init_check", "deinit"]:
setattr(Gst, fname, function)
for cname_class, methods in class_methods:
for mname, method in methods:
setattr(cname_class[1], mname, method)
def deinit_pygst():
for fname, func in real_functions:
if fname not in ["init", "init_check", "deinit"]:
setattr(Gst, fname, fake_method)
for cname_class, methods in class_methods:
for mname, method in methods:
setattr(cname_class[1], mname, fake_method)
real_init = Gst.init
def init(argv):
init_pygst()
return real_init(argv)
Gst.init = init
real_init_check = Gst.init_check
def init_check(argv):
init_pygst()
return real_init_check(argv)
Gst.init_check = init_check
real_deinit = Gst.deinit
def deinit():
deinit_pygst()
return real_deinit()
Gst.deinit = deinit
deinit_pygst()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment