AirenSoft / OvenMediaEngine

OvenMediaEngine (OME) is a Sub-Second Latency Live Streaming Server with Large-Scale and High-Definition. #WebRTC #LLHLS
https://OvenMediaEngine.com/ome
GNU Affero General Public License v3.0
2.53k stars 1.06k forks source link

ABR supported in WebRTC #805

Closed getroot closed 1 year ago

getroot commented 2 years ago

Finally, ABR is available for WebRTC. You can test it with the latest master branch.

WebRTC ABR only works with the latest OvenPlayer.

image

Please refer to the manual for how to use it.

https://airensoft.gitbook.io/ovenmediaengine/v/master-1/streaming/webrtc-publishing#adaptive-bitrates-streaming-abr

The algorithm of Auto ABR (a function that automatically switches rendition by measuring the bandwidth of the player session on the server) must be continuously improved. This needs more testing. If you would like to contribute to improving this feature, you can start with the code below.

https://github.com/AirenSoft/OvenMediaEngine/blob/0d09b5b89af1ebc2890953cf756a4fcacd7abb46/src/projects/publishers/webrtc/rtc_session.cpp#L801

Thanks a lot for your feedback. (The information "It works well" is also very helpful.)

danruser commented 2 years ago

Hello I've been testing for several hours now and everything is great. Thank you for the good work

nums commented 2 years ago

Hello,

does WebRTC ABR take advantage of the WebRTC simulcast: https://www.w3.org/TR/webrtc-svc/#simulcasttemporal-example* ?

On SFUs that implement this logic, there is no server-side transcoding, it's the "producer" that sends the same stream with several dimensions. Is is the same here ?

On the other hand, for an RTMP source, I imagine that we take advantage of the server-side transcoding.

getroot commented 2 years ago

@nums OME's WebRTC Provider (Ingest) does not yet support simulcast. OME's WebRTC Publisher (Streaming) provides ABR with server-side transcoding. The simulcast developed in the future will pass-through server-side transcoding.

Supporting simulcast for WebRTC Provider is a low priority as there are not many cases of using WebRTC input with OME yet. Most OME users still use RTMP, SRT, MPEG-TS and RTSP inputs.

The link you wrote is SVC, not simulcast. SVC is also a standard that should be supported someday.

nums commented 2 years ago

@getroot Thank you for the clarification. Indeed it is great for "livestreaming" use.

Sorry, the link anchor was missing, I made the edit in my previous comment.

One last question, is the management of the connection / disconnection to the WebRTC stream no longer dependent on the WebSocket connection? I think there was a feed on it but I can't find it anymore.

I will carry out tests on my side with a hundred simultaneous connections

getroot commented 2 years ago

@nums The WebRTC player must always maintain a WebSocket connection to OME during playback. OME notifies the ABR rendition switching result via this WebSocket session. OME determines that a player that loses a WebSocket connection has closed the connection and cleans up the session.

basisbit commented 2 years ago

Do there exist any rough estimates how much ABR / the changed code impacts CPU or memory requirements in a use case of few concurrent streams but many concurrent viewers? For example during the tests I did end of last year, WebRTC required roughly 50 to 100% more CPU power per concurrent viewer, compared to having these viewers watch the same stream over HLS (with encryption enabled, 6 seconds chunks). I'd love to test and provide test results of OME with WebRTC ABR with thousands of concurrent users, but I currently have no "small" events where I could test this, so I at least need some rough estimates of changes in CPU/memory requirements. Thanks!

getroot commented 2 years ago

@basisbit The most CPU-intensive logic for viewers in WebRTC is SRTP encryption and the send() system call. (WebRTC makes a lot more send() system calls than HLS.)

WebRTC ABR is not affected by this. So it's probably not much different from what you tested at the end of last year.

However, there have been several patches to improve performance in recent months, so the latest version may have reduced CPU usage.

davidghukasyan commented 2 years ago

We've been testing a couple of days now. It works as intended. As mentioned above will require contineous improvement, however I think with the current implementation it's worth to push an official release. There will be lots of usecases and senarios to shape out in future , including delivering via 3G/4G networks, but at this stage of testing it works fine. We'll try to do also a stress test to see the impact on ABR, Engine and hardware.

nums commented 2 years ago

I have tested with some different setup, it's working great. I noticed that the "degraded" stream generated a latency of just under 1 second compared to the original stream.

mpisat commented 2 years ago

I tested it today. FWIW Simulcast based ABR works much better. When there are multiple transcoded tracks available in WebRTC stream, browser handles (?) stream switching automatically and it happens smoothly. OME ABR is pretty usable in my opinion, but not as good as Simulcast ABR.

getroot commented 2 years ago

@mpisat Simulcast is a specification for how to transmit multiple video tracks simultaneously from an encoder (browser). Instead, the current OME transcodes itself without receiving multiple encoded videos via simulcast.

And ABR is that the server transmits a suitable track according to the viewer's estimated bandwidth among multiple video tracks. This has nothing to do with simulcast. For bandwidth estimation, use REMB or transport-cc specifications.

What specifically does Simulcast based ABR better mean? video quality? Or an accurate bandwidth estimate?

mpisat commented 2 years ago

@getroot I've seen ABR implementation via MediaSoup at an adult entertainment cam site. Resolution changes were happening without any stutter when you limit your bandwidth with netlimiter (win) or network link conditioner (xcode tool -- mac).

For example:

Stats graphs for RTCInboundRTPAudioStream_557470284 (inbound-rtp) Stats graphs for RTCInboundRTPAudioStream_846147500 (inbound-rtp) Stats graphs for RTCInboundRTPVideoStream_1234 (inbound-rtp) Stats graphs for RTCInboundRTPVideoStream_379218108 (inbound-rtp) Stats graphs for RTCInboundRTPVideoStream_992103075 (inbound-rtp) Stats graphs for RTCMediaStreamTrack_receiver_15 (track) Stats graphs for RTCMediaStreamTrack_receiver_16 (track) Stats graphs for RTCMediaStreamTrack_receiver_17 (track) Stats graphs for RTCMediaStreamTrack_receiver_18 (track) Stats graphs for RTCMediaStreamTrack_receiver_19 (track)

These tracks are transcoded on the server side and fed to MediaSoup, which is the SFU and handles media playback requests from the visitors.

I'm no simulcast expert here, but from what I understand, the browser was selecting the video/audio track according to the browser's estimated bandwidth or network speed and handling video playback.

getroot commented 2 years ago

@mpisat

Perhaps OME's ABR and MediaSoup's ABR will estimate bandwidth and switch tracks in the same way. I don't think it's a problem caused by the difference between the encoder encoding method (Simulcast) and the server encoding method.

Do you have problems with stutter when switching ABR in OME? Maybe you have a mix of bypass and encoded tracks in your playlist? The encoded track is a bit slower than the bypass track, so you may feel like there is a little stutter when you switch between the two. Try composing all the tracks in your playlist as encoded tracks.

mpisat commented 2 years ago

@getroot I used the sample from WebRTC ABR help page, and it consists of entirely transcoded tracks (video + audio), no bypass (raw) video in the list.

When I inspect webrtc-internals page on Chrome, it only contains one video + audio track (not simulcast)

Stats graphs for RTCInboundRTPAudioStream_2100345181 (inbound-rtp) Stats graphs for RTCInboundRTPVideoStream_2331789112 (inbound-rtp) Stats graphs for RTCMediaStreamTrack_receiver_1 (track) Stats graphs for RTCMediaStreamTrack_receiver_2 (track) Stats graphs for RTCPeerConnection (peer-connection) Stats graphs for RTCRemoteOutboundRTPAudioStream_2100345181 (remote-outbound-rtp) Stats graphs for RTCTransport_aBph23_1 (transport)

The difference between Mediasoup + Simulcast ABR vs OME implementation is the number of audio / video tracks and who is switching them (browser vs frontend?)

Please don't get me wrong, I already love OME WebRTC ABR. One of the biggest players in Streaming doesn't even have this feature built in (Wowza).

mpisat commented 2 years ago

When I tested WebRTC ABR today, the stutter was unnoticeable during stream switching. It happens under 200 ms (give or take) and I'm very satisfied with how it performs. Perhaps I had some connectivity issues when I tested it yesterday. I have 180 ms latency to my server in France so I guess that's the culprit.

natzakaria commented 2 years ago

I am getting issues with web sessions disconnects when selecting 1080 on one browser while another browser on 720 and another at 480. Any suggestions?

Log: [2022-08-10 08:56:43.093] W [Rescaler:70] ov.Queue | queue.h:268 | [0x7f879819b6e8] Input queue of Encoder. codec(h264/27) size has exceeded the threshold: queue: 227, threshold: 120, peak: 312