RobotWebTools / webrtc_ros

Streaming of ROS Image Topics using WebRTC
Other
131 stars 52 forks source link

Is there an url to access the stream directly? #52

Open SnShine opened 3 years ago

SnShine commented 3 years ago

In web_video_server you have an option to directly access the stream via an url - https://github.com/RobotWebTools/web_video_server. But here it seems there is no provision for that feature. Only have an html page.

Is there any easier way to access the stream via url?

roehling commented 3 years ago

There is no static URL you could access, because WebRTC is not just a one-way streaming protocol but a full-blown peer-to-peer communication suite with several different protocols as parts. Significant portions are actually implemented in the browser itself. The important bits can be found in webrtc_ros.js.

The browser provides an RTCPeerConnection class that handles the low-level streaming. The client code and the server will exchange a few JSON-encoded messages via a WebSockets connection, mostly to figure out which ROS image topic shall be streamed. The actual message format doesn't really matter, it's just an invented protocol to exchange all information which is required by the RTCPeerConnection. The server will create a new session, add the requested video stream to it, and send the details to the browser, this time in a standardized format called Session Description Protocol or SDP. The RTCPeerConnection class can parse the SDP format and connect to the stream.

In the viewer.js, the stream is connected to a video HTML element. The video element (again implemented by the browser), knows how to decode and display the stream. The stream itself is pretty much a standard RTP connection.

There are a few complications in the initial message exchange, primarily to deal with firewalls or computers behind a router without their own public IP. But that's WebRTC in a nutshell.