Gst.py: add high-level helpers

This commit is contained in:
Mathieu Duponchelle 2019-04-11 00:42:49 +02:00 committed by Mathieu Duponchelle
parent 6e51428cbd
commit 2e91b713f1

View file

@ -26,6 +26,7 @@
import sys
import inspect
import itertools
from ..overrides import override
from ..module import get_introspection_module
@ -64,6 +65,18 @@ class Bin(Gst.Bin):
if not Gst.Bin.add(self, arg):
raise AddError(arg)
def make_and_add(self, factory_name, instance_name=None):
'''
@raises: Gst.AddError
'''
elem = Gst.ElementFactory.make(factory_name, instance_name)
if not elem:
raise AddError(
'No such element: {}'.format(factory_name))
self.add(elem)
return elem
Bin = override(Bin)
__all__.append('Bin')
@ -571,6 +584,29 @@ class ValueList(Gst.ValueList):
ValueList = override(ValueList)
__all__.append('ValueList')
# From https://docs.python.org/3/library/itertools.html
def pairwise(iterable):
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)
class Element(Gst.Element):
@staticmethod
def link_many(*args):
'''
@raises: Gst.LinkError
'''
for pair in pairwise(args):
if not pair[0].link(pair[1]):
raise LinkError(
'Failed to link {} and {}'.format(pair[0], pair[1]))
Element = override(Element)
__all__.append('Element')
def TIME_ARGS(time):
if time == Gst.CLOCK_TIME_NONE: