summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Saunier <tsaunier@gnome.org>2015-04-15 19:55:16 +0200
committerThibault Saunier <tsaunier@gnome.org>2015-04-24 09:16:53 +0200
commit6b32ccbbb250f7516f36a1ea82c0fbba8925af09 (patch)
treea8786170a1baf45dbb67ea1cc23b4be8d8497ba7
parent67d7adc895f8395be711141e98912de82673339c (diff)
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
-rw-r--r--gi/overrides/Gst.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/gi/overrides/Gst.py b/gi/overrides/Gst.py
index 5041f1c..b21ba75 100644
--- a/gi/overrides/Gst.py
+++ b/gi/overrides/Gst.py
@@ -28,6 +28,8 @@ import sys
from inspect import signature
from ..overrides import override
from ..importer import modules
+from inspect import getmembers
+
if sys.version_info >= (3, 0):
_basestring = str
@@ -335,3 +337,60 @@ Gst.warning = _gi_gst.warning
Gst.error = _gi_gst.error
Gst.fixme = _gi_gst.fixme
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()