Description
Using the webcam example, I can stream a single RTSP video from a server, to multiple clients in browsers:
async def offer(request):
...
peer_connection = RTCPeerConnection()
...
player = MediaPlayer("rtsp://myserver:8554/live.sdp") <- ONE PLAYER FOR EACH PEER
video = MediaRelay().subscribe(player.video)
peer_connection.addTrack(video)
...
However, this has an issue: since my video has 1920x1080, it consumes a lot of memory (two connections: 440Mb RAM). This is clear, since each MediaPlayer makes an additional connection for each peer.
An obvious option would be to use a single MediaPlayer for all peers:
player = MediaPlayer("rtsp://myserver:8554/live.sdp") # <- PLAYER IS UNIQUE
async def offer(request):
...
peer_connection = RTCPeerConnection()
...
video = MediaRelay().subscribe(player.video)
peer_connection.addTrack(video)
...
This seems fine (three connections: 300Mb). However, there is a big problem here: the application interleaves frames to browser clients (if there are two opened browsers, client 1 gets frames 1,3,5,7... and client 2 gets frames 2,4,6,8...)!
Using a single player, how can I stream all frames to all clients? Can someone please provide an example (or tell me how to override recv()
so that each frame is delivered to all browsers)?
Thanks and keep it up!