simplewebrtc / SimpleWebRTC

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

is there anyway to detect if the camera died or camera driver failed to feed the live stream? #276

Open shamun opened 9 years ago

shamun commented 9 years ago

We have bought some HP EliteOne 800 equipments.

It looks like the camera driver is causing the problem. I am trying to resolve the issue with camera feed detection. Is there anyway to check if camera capture was dead or camera capture was killed by camera driver or webrtc?

Scenario:

1 - Bob is watching himself with Talky (from 8AM till 2PM worked fine) 2 - Now suddenly Bob do not see himself anymore after 2PM to 5.30PM (black screen) 3 - Bob refresh the browser or restart the web browser or reboot the PC then it works again

tgabi333 commented 9 years ago

Just a tip: Try to watch for the stream properties

shamun commented 9 years ago

Do you mean this? which one has the live feed alive or dead event handler?

webrtc.on('localStream', function (stream) {  videoTracks = stream.getVideoTracks();  }
webrtc.on('readyToCall', function () {}
webrtc.on('localMediaError', function (err) {}
webrtc.on('videoAdded', function (video, peer) {}
webrtc.on('localScreen', function(streams) {}
webrtc.on('videoRemoved', function (video, peer) {}
webrtc.on('connectivityError', function (peer) { }

NOTE: you are watching your camera feed, suddenly black-screen. like the camera crashed or driver stop giving camera feed to webrtc or webrtc stopped the feed. it happend with many camera's. therefore i am trying to find the exact event which can at-least tell me "listen then live feed is dead" then i can do other actions based on that event info.

tgabi333 commented 9 years ago

There is no event for this as i experienced, even videoRemoved wont be fired, thats why you see black screen, i remember a solution when we checked the added stream tracks readystate property in an interval in the receiver side.

https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack/readyState

On Thursday, July 9, 2015, Shamun Toha notifications@github.com wrote:

Do you mean this? which one has the live feed alive or dead event handler?

webrtc.on('localStream', function (stream) { } webrtc.on('readyToCall', function () {} webrtc.on('localMediaError', function (err) {} webrtc.on('videoAdded', function (video, peer) {} webrtc.on('localScreen', function(streams) {} webrtc.on('videoRemoved', function (video, peer) {} webrtc.on('connectivityError', function (peer) { }

— Reply to this email directly or view it on GitHub https://github.com/HenrikJoreteg/SimpleWebRTC/issues/276#issuecomment-119860613 .

Üdvözlettel: Tóth Gábor

shamun commented 9 years ago

This is what i have, that means the readyState should be used in this event from videoTracks? Like i was doing audio tracking used in Hangout.

// Here is the stream from where we do mute/unmute
webrtc.on('localStream', function (stream) {
  videoTracks = stream.getVideoTracks();  
  audioTracks = stream.getAudioTracks();
  document.getElementById('getit_three').style.display = 'none';
  document.getElementById('getit_four').style.display = 'none';
  display_for_allow_deny = false;

    //audioContext = new webkitAudioContext();
    audioContext = new AudioContext();
    analyser = audioContext.createAnalyser();
    microphone = audioContext.createMediaStreamSource(stream);
    javascriptNode = audioContext.createScriptProcessor(2048, 1, 1);

    analyser.smoothingTimeConstant = 0.3;
    analyser.fftSize = 1024;

    microphone.connect(analyser);
    analyser.connect(javascriptNode);
    javascriptNode.connect(audioContext.destination);
    canvasContext = document.getElementById("test");
    canvasContext= canvasContext.getContext("2d");

    javascriptNode.onaudioprocess = function() {
      //console.log('doing.... bla bla');
        var array =  new Uint8Array(analyser.frequencyBinCount);
        analyser.getByteFrequencyData(array);
        var values = 0;

        var length = array.length;
        for (var i = 0; i < length; i++) {
            values += array[i];
        }

        var average = values / length;
        //canvasContext.clearRect(0, 0, 300, 130);        
        //canvasContext.fillStyle = '#00ff00';
        //canvasContext.fillRect(0,130-average,300,130);
        canvasContext.clearRect(0, 0, 300, 130);        
        canvasContext.fillStyle = '#00ff00';
        canvasContext.fillRect(average,0,50,130);

    };

});