Media/getUserMedia: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Updated information to present day.)
Line 2: Line 2:


== Goal ==
== Goal ==
* Define and implement navigator.getUserMedia with the W3C's WebRTC WG and Media Capture Task Force
* Define and implement navigator.mediaDevices.getUserMedia() and associated functions with the W3C's WebRTC WG and Media Capture Task Force
* Current editor's draft: [http://dev.w3.org/2011/webrtc/editor/getusermedia.html W3 getUserMedia Editor's Draft]
* Current editor's draft: [http://dev.w3.org/2011/webrtc/editor/getusermedia.html W3 getUserMedia Editor's Draft]
* Scenarios: [https://dvcs.w3.org/hg/dap/raw-file/tip/media-stream-capture/scenarios.html W3 MediaStream Capture Scenarios]
* Scenarios: [https://dvcs.w3.org/hg/dap/raw-file/tip/media-stream-capture/scenarios.html W3 MediaStream Capture Scenarios]


== Status ==
== Status ==
* Implement getUserMedia on Desktop, then Android, then B2G -- Implemented on Desktop (Windows, Mac and Linux), defaults to enabled in FF20 and FF21
* Implemented getUserMedia on Desktop (Windows, Mac and Linux), Android, and B2G. Enabled in FF20+.
** Currently prefixed as mozGetUserMedia() since the spec is still in flux
** Still prefixed as mozGetUserMedia(). The spec is at Candidate Recommendation.
** For FF19 and before, you need to set <b><tt>media.navigator.enabled</tt></b> to true, or <tt><b> media.peerconnection.enabled</b></tt> to true.
** Can be turned off by setting <b><tt>media.navigator.enabled</tt></b> and <tt><b> media.peerconnection.enabled</b></tt> to false.
* Permissions UI is supported, allowing selecting a device or rejecting permission, with notifications that a tab is using a mic or camera, and a global dropdown of all tabs using mics/cameras.
* Permissions UI is supported, allowing selecting devices or rejecting permission, with notifications that a tab is using a mic or camera, and a global indicator on the desktop to locate tabs using mics/cameras.
* Persistent permissions are not yet supported
* Persistent permissions are supported.
* Explicit revocation of permission currently requires navigating away or closing the tab.
* Explicit revocation of permission is supported.
* Supports multiple tabs getting data from the same mic or camera (if the user allows)
* Supports multiple tabs getting data from the same mic or camera (if the user allows)
* Capture resolution currently fixed to 640x480 for video; 16000Hz for audio
* Capture resolution can be controlled with standard constraints for width, height, frameRate and (on mobile) facingMode can be used to choose between front/back camera. Supported in FF32+.
* No echo cancellation is turned on in getUserMedia, so connecting an captured audio stream to an audio element may cause feedback
* Audio rate is fixed at 16000Hz.
* Echo cancellation is on by default, but connecting a captured audio stream directly to an audio element on the same system may still cause feedback unless a headset is used.
* Promise-based mediaDevices.getUserMedia API is supported in FF36+.
* Input device enumeration through mediaDevices.enumerateDevices() is supported in FF39+.


* Minimal constraints supported: (Note: all of these booleans default to 'false')
== Examples ==
<pre>
  video:  true/false
  audio:  true/false
  fake:    true/false
  picture: true/false
</pre>


Example use in FF:
* See [https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Frame_rate mediaDevices.getUserMedia on developer.mozilla.org] for examples.
<pre>
  mozGetUserMedia({picture: true}, onsuccess(Blob blob), onerror);


  mozGetUserMedia({video: true, audio: true},
== Demos ==
                  function (MediaStream stream) { video.mozSrcObject = stream; },
                  function (err) { dump("mozGetUserMedia error: " + err); } );
</pre>


Demos: [http://mozilla.github.io/webrtc-landing  WebRTC demos including mozGetUserMedia]
* See [http://mozilla.github.io/webrtc-landing  WebRTC demos including mozGetUserMedia]


== Differences from Chrome webkitGetUserMedia() ==
== Differences from Chrome webkitGetUserMedia() ==
Line 43: Line 35:
** This behavior may change in the future
** This behavior may change in the future
* Both now support window.URL.createObjectURL(stream), though Mozilla recommends against using it unless you have to.  We expect Chrome to support srcObject = stream soon (perhaps prefixed as we are currently)
* Both now support window.URL.createObjectURL(stream), though Mozilla recommends against using it unless you have to.  We expect Chrome to support srcObject = stream soon (perhaps prefixed as we are currently)
* Firefox does not support Chrome's outdated constraints syntax.
* Firefox does not support MediaStreamTrack.getSources(), an outdated version of enumerateDevices.
* Use the [https://github.com/webrtc/adapter adapter.js] shim to bridge cross-browser differences (constraints polyfill should be forthcoming).

Revision as of 20:57, 2 April 2015

getUserMedia

Goal

Status

  • Implemented getUserMedia on Desktop (Windows, Mac and Linux), Android, and B2G. Enabled in FF20+.
    • Still prefixed as mozGetUserMedia(). The spec is at Candidate Recommendation.
    • Can be turned off by setting media.navigator.enabled and media.peerconnection.enabled to false.
  • Permissions UI is supported, allowing selecting devices or rejecting permission, with notifications that a tab is using a mic or camera, and a global indicator on the desktop to locate tabs using mics/cameras.
  • Persistent permissions are supported.
  • Explicit revocation of permission is supported.
  • Supports multiple tabs getting data from the same mic or camera (if the user allows)
  • Capture resolution can be controlled with standard constraints for width, height, frameRate and (on mobile) facingMode can be used to choose between front/back camera. Supported in FF32+.
  • Audio rate is fixed at 16000Hz.
  • Echo cancellation is on by default, but connecting a captured audio stream directly to an audio element on the same system may still cause feedback unless a headset is used.
  • Promise-based mediaDevices.getUserMedia API is supported in FF36+.
  • Input device enumeration through mediaDevices.enumerateDevices() is supported in FF39+.

Examples

Demos

Differences from Chrome webkitGetUserMedia()

Includes, but not limited to:

  • Name :-)
  • Firefox leaves the mic/camera active (light on, etc) until the application explicitly calls mediastream.stop(). Chrome turns them on when assigned to a media element or PeerConnection, and off again when removed.
    • Note that if an application drops all references to a MediaStream but does not call stop(), the camera will remain active for some period of time (or until you navigate to another page in the tab or close the tab).
    • This behavior may change in the future
  • Both now support window.URL.createObjectURL(stream), though Mozilla recommends against using it unless you have to. We expect Chrome to support srcObject = stream soon (perhaps prefixed as we are currently)
  • Firefox does not support Chrome's outdated constraints syntax.
  • Firefox does not support MediaStreamTrack.getSources(), an outdated version of enumerateDevices.
  • Use the adapter.js shim to bridge cross-browser differences (constraints polyfill should be forthcoming).