Client Side Video Forwarding

I am aware that this is probably outside the scope of what Mediasoup currently does, so I will be working on implementing this at WebRTC level, but I first wanted to ask if there are any mechanisms in Mediasoup(maybe one that I have missed as I look) that allows this kind of operation.

Basically, what I would like to do is use a client as a relay center for a set of other clients. These clients will pass their data over that client, and also will receive videos from rest of the clients again over this relay center.

This is possible, but something that mediasoup is designed to replace due to the fact that this design doesn’t scale beyond a few participants.

UPD: You can’t actually just “forward” data yet, you’ll need to re-encode it for every participant, which means A LOT of CPU usage typically.

1 Like

I think @alpaylan needs to specify a little more what their goal/idea is, but from a very narrow perspective this seems implementable. What I’m envisioning is actually running mediasoup server on the client side, and having that communicate with the main server via pipeTransport. The client-side server would be capable of forwarding raw RTP to other clients as long as they’re able to connect to it via ICE LITE, but this is obviously NOT guaranteed unless you have some kind of control over what kind of network the forwarding client exists on.

@nazar-pc mentions a very important point about scalability. WebRTC mesh networking is basically not scalable at all, and peer to peer connections only work like 80% of the time. The rest of the time you need to rely on TURN to forward data between peers over a central server… in which case you’re no better off than you were just using an SFU (mediasoup).

An additional warning for @alpaylan … be careful about trying to implement forwarding in WebRTC (mediasoup developers have ALREADY done the work for you here). I initially tried to build my own SFU using node-webrtc, and found out after like 50 hours of labor that there was no way to forward/pass through an incoming stream to an outgoing connection without first decoding and then encoding it again (not with node-turn or any Chromium based solution that I’m aware of). Massive CPU usage.

Learn from my pain!

This is impossible with browser tech as it is today.

This is impossible too regardless of above.

You’re right. I was thinking he might be building an installable app that runs outside of a browser, so could be possible to package server libraries/binary with it. But yeah on second thought that’s not very cross platformy… I didn’t really think it through.

Probably not possible with webassembly in browser either because of the networking limitations of what you can do within a browser.

@dimoochka and @nazar-pc first of all, thank you so much for the detailed response. One thing though, why do need the decode/encode process? Normally, webrtc allows stream forwarding for different peer connections, wouldn’t it be possible to implement such a mechanism?

There is no access to raw audio/video data in WebRTC to forward them unmodified from one connection to another, not yet.

@alpaylan I think it ultimately depends on the WebRTC library you use and if it has some nonstandard low level API. There’s nothing I’m aware of in the current WebRTC API that allows you to just forward RTP without transcoding it, but I’m definitely not a master. If you discover a way I’d love to know about it.

I tried with node-webrtc which provides a node implementation of RTCPeerConnection. I could not find any way to disable transcoding here. It was identical in implementation / objects to browser javascript, so I’m fairly certain you would encounter the same roadblock if you tried to do this within a chromium based process.

What @nazar-pc said :joy:

Why reencode? Don’t get it. You absolutely don’t need to. You need to-reencrypt it for each participant but it takes nowhere nearly as much CPU as encoding

Because there is no other way with currently available browser APIs.
You can do that on server and that is what mediasoup exists for.

I am unsure this is the case. GitHub - muaz-khan/WebRTC-Scalable-Broadcast: This module simply initializes and configures it in a way that single broadcast can be relayed over unlimited users without any bandwidth/CPU usage issues. Everything happens peer-to-peer! is this one uses re-encoding? i guess not.

A 7 years old project which is just about using for signaling and then end-to-end (peer-to-peer) media flow. How is this related to doing RTP forwarding in client side without decoding/encoding? It’s not at all. Completely unrelated.

Yes i know, that’s what i assume it was. This is what the OP seems to be asking for: “how to forward media through some client from one client to several others”, and that’s what it seems to be doing. But ofc absolutely unrelated to mediasoup, sorry for being off topic.

Such a project is not about forwarding media at all. Every peer encodes a separate stream for everyone else.