Call set-local-description before sending it as SDP answer.
[toast/stream2beamer.git] / lagarde.py
index 55b1e1f21cacff70c8e5dfe8d068f5d8a6526f4d..f31bc2dbbfdcfb75c7c97de24bcf2c287711cfef 100755 (executable)
@@ -223,22 +223,28 @@ class WebRTCClient:
     def create_answer_done(self, gst_promise):
         reply = gst_promise.get_reply()
         answer = reply.get_value('answer')
+        gst_promise = Gst.Promise.new_with_change_func(self.set_local_description_done)
+        self.webrtcbin.emit('set-local-description', answer, gst_promise)
+
         sdp_message = answer.sdp
         mids = [sdp_message.get_media(i).get_attribute_val('mid')
                 for i in range(sdp_message.medias_len())]
         user_fragments = [sdp_message.get_media(i).get_attribute_val('ice-ufrag')
                           for i in range(sdp_message.medias_len())]
-        self.events.sdp_info.put_nowait((mids, user_fragments))
         sdp_answer = sdp_message.as_text()
-        log.info(f'Send SDP answer')
-        log.debug(f'SDP answer:\n{sdp_answer}')
-        self.events.sdp_answer.put_nowait(sdp_answer)
-        gst_promise = Gst.Promise.new_with_change_func(self.set_local_description_done)
-        self.webrtcbin.emit('set-local-description', answer, gst_promise)
+        self.mids_uf = mids, user_fragments
+        self.answer = sdp_answer
 
     def set_local_description_done(self, gst_promise):
         gst_promise.get_reply()
 
+        sdp_answer = self.answer
+        log.info(f'Send SDP answer')
+        log.debug(f'SDP answer:\n{sdp_answer}')
+        self.events.sdp_answer.put_nowait(sdp_answer)
+        mids, user_fragments = self.mids_uf
+        self.events.sdp_info.put_nowait((mids, user_fragments))
+
     async def run(self):
         bus = Gst.Pipeline.get_bus(self.pipe)
         self.pipe.set_state(Gst.State.PLAYING)