update handling of caps in decodebin_pad_added()
authorgregor herrmann <gregor@toastfreeware.priv.at>
Thu, 9 Jul 2020 18:07:47 +0000 (20:07 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Thu, 9 Jul 2020 18:22:42 +0000 (20:22 +0200)
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)

lagarde.py

index 0603bbbe11f586c0c365d85a80300e8dd4451113..08c37b0f428adf66d4e0d09d92c04823f3de9229 100755 (executable)
@@ -62,29 +62,33 @@ class Lagarde:
             return
 
         caps = pad.get_current_caps()
             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)
 
     async def listen_to_gstreamer_bus(self):
         Gst.init(None)