simplewebrtc / SimpleWebRTC

Simplest WebRTC ever
Other
4.65k stars 1.19k forks source link

Preventing remote stream decoding #451

Open alexey2baranov opened 8 years ago

alexey2baranov commented 8 years ago

Hello dear friends!

We have a project with 4 webcams and 4 SimpleWebRTC objects into one page which joined to one room. We would like each SimpleWebRTC object do two jobs only:

  1. Show local video
  2. Send local video to client (another webpage)

So we need to configure this 4 SimpleWebRTC objects they do not decode each other because this is very CPU expensive

fippo commented 8 years ago

as I said here you want to 'tune the receiveMedia options so that only one of the objects receives stuff'. Setting the options shown here for those client objects that should only publish should do the trick hopefully

alexey2baranov commented 8 years ago

We test this two cases with 3 webcams.

The first case below results 6 events "createdPeer" and 6 remote videos and 100+% CPU usage.

$(function () {
    var CAM_INDEX=1;
    navigator.mediaDevices.enumerateDevices()
        .then((devices)=> {
            // var isAudioNeeded= true;
            devices.forEach(eachDevice=> {
                if (eachDevice.kind == "videoinput") {

                    let nick= "cam"+ CAM_INDEX++;

                    console.log(nick);
                    console.log(eachDevice);
                    let webrtc = new SimpleWebRTC({
                        socketio: {'force new connection': true},
                        media: {
                            audio:false,
                            video: {
                                optional: [{
                                    sourceId: eachDevice.deviceId
                                }]
                            }
                        },
                        localVideoEl: 'localVideos',
                        remoteVideosEl: 'remoteVideos',
                        autoRequestMedia: true,
                        nick: nick
                    });

                    webrtc.on('readyToCall', function () {
                        webrtc.joinRoom("many-cams-test-room");
                    });

                    webrtc.on('createdPeer', function (peer) {
                        console.log(nick+' createdPeer', peer);
                    });
                }
            });
        });
});

The second case below results 3 events "createdPeer" and 3 remote videos only. 3 remote videos vs 6 remote videos get us -40% CPU usage. And this is not bad. Haw can we prevent this last 3 remote videos?

$(function () {
    var CAM_INDEX=1;
    navigator.mediaDevices.enumerateDevices()
        .then((devices)=> {
            // var isAudioNeeded= true;
            devices.forEach(eachDevice=> {
                if (eachDevice.kind == "videoinput") {

                    let nick= "cam"+ CAM_INDEX++;

                    console.log(nick);
                    console.log(eachDevice);
                    let webrtc = new SimpleWebRTC({
                        socketio: {'force new connection': true},
                        media: {
                            audio:false,
                            video: {
                                optional: [{
                                    sourceId: eachDevice.deviceId
                                }]
                            }
                        },
                        localVideoEl: 'localVideos',
                        remoteVideosEl: 'remoteVideos',
                        autoRequestMedia: true,
                        receiveMedia: {
                            offerToReceiveAudio: 0,
                            offerToReceiveVideo: 0
                        },
                        nick: nick
                    });

                    webrtc.on('readyToCall', function () {
                        webrtc.joinRoom("many-cams-test-room");
                    });

                    webrtc.on('createdPeer', function (peer) {
                        console.log(nick+' createdPeer', peer);
                    });
                }
            });
        });
});
alexey2baranov commented 8 years ago

Hello dear friend! We have try to tune receiveMedia and done some tests as written in prev post but have not resolve our question. As I written we have won +40% CPU usage but could not prevent 3 of 6 streams.

Can you guide us next step? We are very appreciate your help.