Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3816>
# Demo gstreamer app for negotiating and streaming a sendrecv webrtc stream
# with a browser JS app, implemented in Python.
# Demo gstreamer app for negotiating and streaming a sendrecv webrtc stream
# with a browser JS app, implemented in Python.
+from websockets.version import version as wsv
+from gi.repository import GstSdp
+from gi.repository import GstWebRTC
+from gi.repository import Gst
import random
import ssl
import websockets
import random
import ssl
import websockets
import gi
gi.require_version('Gst', '1.0')
import gi
gi.require_version('Gst', '1.0')
-from gi.repository import Gst
gi.require_version('GstWebRTC', '1.0')
gi.require_version('GstWebRTC', '1.0')
-from gi.repository import GstWebRTC
gi.require_version('GstSdp', '1.0')
gi.require_version('GstSdp', '1.0')
-from gi.repository import GstSdp
# Ensure that gst-python is installed
try:
# Ensure that gst-python is installed
try:
'VP8': PIPELINE_DESC_VP8,
}
'VP8': PIPELINE_DESC_VP8,
}
-from websockets.version import version as wsv
-
def print_status(msg):
print(f'--- {msg}')
def print_status(msg):
print(f'--- {msg}')
self.send_soon(msg)
def on_offer_created(self, promise, _, __):
self.send_soon(msg)
def on_offer_created(self, promise, _, __):
- assert(promise.wait() == Gst.PromiseResult.REPLIED)
+ assert promise.wait() == Gst.PromiseResult.REPLIED
reply = promise.get_reply()
offer = reply['offer']
promise = Gst.Promise.new()
reply = promise.get_reply()
offer = reply['offer']
promise = Gst.Promise.new()
self.pipe.set_state(Gst.State.PLAYING)
def on_answer_created(self, promise, _, __):
self.pipe.set_state(Gst.State.PLAYING)
def on_answer_created(self, promise, _, __):
- assert(promise.wait() == Gst.PromiseResult.REPLIED)
+ assert promise.wait() == Gst.PromiseResult.REPLIED
reply = promise.get_reply()
answer = reply['answer']
promise = Gst.Promise.new()
reply = promise.get_reply()
answer = reply['answer']
promise = Gst.Promise.new()
self.send_sdp(answer)
def on_offer_set(self, promise, _, __):
self.send_sdp(answer)
def on_offer_set(self, promise, _, __):
- assert(promise.wait() == Gst.PromiseResult.REPLIED)
+ assert promise.wait() == Gst.PromiseResult.REPLIED
promise = Gst.Promise.new_with_change_func(self.on_answer_created, None, None)
self.webrtc.emit('create-answer', None, promise)
promise = Gst.Promise.new_with_change_func(self.on_answer_created, None, None)
self.webrtc.emit('create-answer', None, promise)
if not self.webrtc:
print_status('Incoming call: received an offer, creating pipeline')
pts = get_payload_types(sdpmsg, video_encoding=self.video_encoding, audio_encoding='OPUS')
if not self.webrtc:
print_status('Incoming call: received an offer, creating pipeline')
pts = get_payload_types(sdpmsg, video_encoding=self.video_encoding, audio_encoding='OPUS')
- assert(self.video_encoding in pts)
- assert('OPUS' in pts)
+ assert self.video_encoding in pts
+ assert 'OPUS' in pts
self.start_pipeline(create_offer=False, video_pt=pts[self.video_encoding], audio_pt=pts['OPUS'])
self.start_pipeline(create_offer=False, video_pt=pts[self.video_encoding], audio_pt=pts['OPUS'])
offer = GstWebRTC.WebRTCSessionDescription.new(GstWebRTC.WebRTCSDPType.OFFER, sdpmsg)
promise = Gst.Promise.new_with_change_func(self.on_offer_set, None, None)
self.webrtc.emit('set-remote-description', offer, promise)
elif 'ice' in msg:
offer = GstWebRTC.WebRTCSessionDescription.new(GstWebRTC.WebRTCSDPType.OFFER, sdpmsg)
promise = Gst.Promise.new_with_change_func(self.on_offer_set, None, None)
self.webrtc.emit('set-remote-description', offer, promise)
elif 'ice' in msg:
ice = msg['ice']
candidate = ice['candidate']
sdpmlineindex = ice['sdpMLineIndex']
ice = msg['ice']
candidate = ice['candidate']
sdpmlineindex = ice['sdpMLineIndex']