]> ToastFreeware Gitweb - toast/stream2beamer.git/commitdiff
Now RTSP is used without re-encoding video (however, some assumptions are made). rtsp_without_reencode
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 26 May 2021 19:04:46 +0000 (21:04 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 26 May 2021 19:06:08 +0000 (21:06 +0200)
lagarde.py

index 8ef74071c4b0ecd1d1e45b129001c353212049b6..a5de94f26d6449568db111a3a85eb756a3773728 100755 (executable)
@@ -144,75 +144,40 @@ class WebRTCClient:
         log.info('webrtcbin_pad_added')
         if pad.direction != Gst.PadDirection.SRC:
             return
-        decodebin = Gst.ElementFactory.make('decodebin')
-        decodebin.connect('pad-added', self.decodebin_pad_added)
-        self.pipe.add(decodebin)
-        decodebin.sync_state_with_parent()
-        self.webrtcbin.link(decodebin)
-
-    def decodebin_pad_added(self, element, pad):
-        log.info('decodebin_pad_added')
-        if not pad.has_current_caps():
-            log.info(pad, 'has no caps, ignoring')
+        demux = Gst.ElementFactory.make('rtpptdemux')
+        assert demux
+        self.pipe.add(demux)
+        demux.connect('pad-added', self.demux_pad_added)
+        demux.sync_state_with_parent()
+        ok = self.webrtcbin.link(demux)
+        assert ok
+
+    def demux_pad_added(self, element, pad):
+        log.info('demux_pad_added')
+        if pad.direction != Gst.PadDirection.SRC:
             return
-        caps = pad.get_current_caps()
-        padsize = caps.get_size()
-
-        for i in range(padsize):
-            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')
-                enc = Gst.ElementFactory.make('x264enc')
-                enc.set_property('bitrate', 1000)
-                enc.set_property('tune', 'zerolatency')
-                capsfilter = Gst.ElementFactory.make('capsfilter')
-                capsfilter.set_properties(Gst.Caps.from_string('video/x-h264,stream-format=(string)avc'))
-                flmux = Gst.ElementFactory.make('flvmux')
-                sink = Gst.ElementFactory.make('rtmpsink')
-                sink.set_property('location', self.rtmp_uri)
-                assert q and conv and enc and capsfilter and flmux and sink
-
-                self.pipe.add(q)
-                self.pipe.add(conv)
-                self.pipe.add(enc)
-                self.pipe.add(capsfilter)
-                self.pipe.add(flmux)
-                self.pipe.add(sink)
-
-                q_pad_sink = q.get_static_pad('sink')
-                assert q_pad_sink
-                pad_link_return = pad.link(q_pad_sink)
-                assert pad_link_return == Gst.PadLinkReturn.OK
-
-                ok = q.link(conv)
-                assert ok
-                ok = conv.link(enc)
-                assert ok
-                ok = enc.link(capsfilter)
-                assert ok
-                ok = capsfilter.link(flmux)
-                assert ok
-                ok = flmux.link(sink)
-                assert ok
-                self.pipe.set_state(Gst.State.PLAYING)
-                self.pipe.sync_children_states()
-
-            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)
-                self.pipe.add(conv)
-                self.pipe.add(resample)
-                self.pipe.add(sink)
-                self.pipe.sync_children_states()
-                pad.link(q.get_static_pad('sink'))
-                q.link(conv)
-                conv.link(resample)
-                resample.link(sink)
+        depay = Gst.ElementFactory.make('rtpvp8depay')
+        assert depay
+        self.pipe.add(depay)
+        ok = element.link(depay)
+        assert ok
+
+        q = Gst.ElementFactory.make('queue')
+        sink = Gst.ElementFactory.make('rtspclientsink')
+        sink.set_property('location', self.rtmp_uri)
+        sink.set_property('debug', True)
+        assert q and sink
+
+        self.pipe.add(q)
+        self.pipe.add(sink)
+        ok = depay.link(q)
+        assert ok
+        ok = q.link(sink)
+        assert ok
+
+        self.pipe.sync_children_states()
+        self.pipe.set_state(Gst.State.PLAYING)
+        self.pipe.sync_children_states()
 
     def set_remote_desciption_done(self, gst_promise):
         gst_promise = Gst.Promise.new_with_change_func(self.create_answer_done)
@@ -304,7 +269,7 @@ async def run(laplace_uri: str, rtmp_uri: str):
 def main():
     logging.basicConfig(level=logging.DEBUG, format='%(asctime)-15s %(message)s')
     default_source = 'wss://localhost:1234/ws_connect?id=cug'
-    default_dest = 'rtmp://localhost:1935/cug'
+    default_dest = 'rtsp://localhost:8554/cug'
     parser = argparse.ArgumentParser()
     parser.add_argument('-s', '--source', default=default_source,
                         help=f'Laplace signalling websocket URI, default: {default_source}')