尝试使用gstreamer webrtc进行流式传输时,“按需协商”如何工作?

时间:2018-12-17 00:38:30

标签: webrtc gstreamer

webrtc管道如何获取有关其对等方的任何信息?

这就是我假设on_negotiation_needed回调的作用吗?

def start_pipeline(self):
        self.pipe = Gst.parse_launch(PIPELINE_DESC)
        self.webrtc = self.pipe.get_by_name('sendrecv')
        **self.webrtc.connect('on-negotiation-needed', self.on_negotiation_needed)**
        self.webrtc.connect('on-ice-candidate', self.send_ice_candidate_message)
        self.webrtc.connect('pad-added', self.on_incoming_stream)
        self.pipe.set_state(Gst.State.PLAYING)

我看到它具有on_negotiation_needed回调,但是不清楚元素变量来自何处?我在这里:http://blog.nirbheek.in/2018/02/gstreamer-webrtc.html和这里:https://github.com/centricular/gstwebrtc-demos看了一下,但对于这种协商的工作方式我仍然感到困惑。据我了解,有2个(或更多)对等端,并且它们两个都必须连接到信令服务器,然后其中一个必须创建要约。

我等待(假设)来自信令服务器上的gstreamer webrtcbin的消息:

print (websocket.remote_address)
#get message from client
message = await asyncio.wait_for(websocket.recv(), 3000)

当管道开始时出现此错误:

('192.168.11.138', 44120)
Error in connection handler
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 674, in transfer_data
    message = yield from self.read_message()
  File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 742, in read_message
    frame = yield from self.read_data_frame(max_size=self.max_size)
  File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 815, in read_data_frame
    frame = yield from self.read_frame(max_size)
  File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 884, in read_frame
    extensions=self.extensions,
  File "/usr/local/lib/python3.6/dist-packages/websockets/framing.py", line 99, in read
    data = yield from reader(2)
  File "/usr/lib/python3.6/asyncio/streams.py", line 672, in readexactly
    raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/websockets/server.py", line 169, in handler
    yield from self.ws_handler(self, path)
  File "signaling_server.py", line 34, in signaling
    message = await asyncio.wait_for(websocket.recv(), 3000)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 434, in recv
    yield from self.ensure_open()
  File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 646, in ensure_open
    ) from self.transfer_data_exc
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason

1 个答案:

答案 0 :(得分:1)

我无法谈论Python(不幸的是,无法在Windows上使GStreamer的Python绑定能够正常工作),但是,演示程序是从C#进行的(我刚刚检查过)。

首先,您应该使用浏览器连接到https://webrtc.nirbheek.in/,并获取“我们的ID”值。

您的Python Gstreamer应该连接到wss://webrtc.nirbheek.in:8443,并使用浏览器中的ID值。

浏览器将从GStreamer获取测试图像流,GStreamer应用程序将从浏览器获取Webcam图像。

HTH,汤姆

以下是屏幕截图:

enter image description here