From: gregor herrmann Date: Thu, 9 Jul 2020 18:07:47 +0000 (+0200) Subject: update handling of caps in decodebin_pad_added() X-Git-Url: https://git.toastfreeware.priv.at/toast/stream2beamer.git/commitdiff_plain/73fc7271463f53878788d77ca45f954f942c5853?ds=sidebyside update handling of caps in decodebin_pad_added() caps is a Gst.Caps object and it has no length: change assertion to check for caps.get_size() also caps is no list/not subscriptable, so iterate over its structures. (the rest is indentation whitespace noise) --- diff --git a/lagarde.py b/lagarde.py index 0603bbb..08c37b0 100755 --- a/lagarde.py +++ b/lagarde.py @@ -62,29 +62,33 @@ class Lagarde: return caps = pad.get_current_caps() - assert (len(caps)) - s = caps[0] - name = s.get_name() - if name.startswith('video'): - q = Gst.ElementFactory.make('queue') - conv = Gst.ElementFactory.make('videoconvert') - sink = Gst.ElementFactory.make('autovideosink') - self.pipe.add(q, conv, sink) - self.pipe.sync_children_states() - pad.link(q.get_static_pad('sink')) - q.link(conv) - conv.link(sink) - elif name.startswith('audio'): - q = Gst.ElementFactory.make('queue') - conv = Gst.ElementFactory.make('audioconvert') - resample = Gst.ElementFactory.make('audioresample') - sink = Gst.ElementFactory.make('autoaudiosink') - self.pipe.add(q, conv, resample, sink) - self.pipe.sync_children_states() - pad.link(q.get_static_pad('sink')) - q.link(conv) - conv.link(resample) - resample.link(sink) + # assert (len(caps)) # we have a Gst.Caps object and it has no length + # s = caps[0] # also, it's not a list + padsize = caps.get_size() + assert(padsize > 0) + for i in range(padsize): # pythonic?! + s = caps.get_structure(i) # Gst.Structure + name = s.get_name() + if name.startswith('video'): + q = Gst.ElementFactory.make('queue') + conv = Gst.ElementFactory.make('videoconvert') + sink = Gst.ElementFactory.make('autovideosink') + self.pipe.add(q, conv, sink) + self.pipe.sync_children_states() + pad.link(q.get_static_pad('sink')) + q.link(conv) + conv.link(sink) + elif name.startswith('audio'): + q = Gst.ElementFactory.make('queue') + conv = Gst.ElementFactory.make('audioconvert') + resample = Gst.ElementFactory.make('audioresample') + sink = Gst.ElementFactory.make('autoaudiosink') + self.pipe.add(q, conv, resample, sink) + self.pipe.sync_children_states() + pad.link(q.get_static_pad('sink')) + q.link(conv) + conv.link(resample) + resample.link(sink) async def listen_to_gstreamer_bus(self): Gst.init(None)