38
WebRTC ... GWT & Browser Performance Alberto Mancini, Francesca Tosi JooinK.com

JooinK - DevFest Piemonte 2013

  • Upload
    jooink

  • View
    1.997

  • Download
    2

Embed Size (px)

DESCRIPTION

WebRTC, and most of HTML5 tecnologies as File API, WebGL, WebWorkers, ...,answer to a common problem, i.e. to make 'in browser' apps able to do operations impossible before, as access to the video and audio stream by a javascript api.

Citation preview

Page 1: JooinK - DevFest Piemonte 2013

WebRTC... GWT & Browser Performance

Alberto Mancini, Francesca TosiJooinK.com

Page 2: JooinK - DevFest Piemonte 2013

WebRTCPlug-in free realtime communication …

WebRTC is a free, open project that enables web browsers with Real-Time Communications (RTC) capabilities via simple Javascript APIs.

source: webrtc.org

Page 3: JooinK - DevFest Piemonte 2013

WebRTC

Just another JS API

or

WebRTC is a new front in the long war for an open and unencumbered webBrendan Eich (Mozilla CTO and inventor of JavaScript)

?

Page 4: JooinK - DevFest Piemonte 2013

Browser PiercingOnce upon a time ...

LDP: Firewall Piercing mini-HOWTOFrançois-René Rideauv0.97, 24 November 2001

Page 5: JooinK - DevFest Piemonte 2013

Browser Piercing

a Javascript Application cannot

➔ access the filesystem and then File API

➔ open full-duplex socket connection and then WebSockets

Page 6: JooinK - DevFest Piemonte 2013

Browser Piercing

a Javascript Application cannot

➔ use graphics accelerator and then WebGL

➔ span multiple threads and then WebWorkers

Page 7: JooinK - DevFest Piemonte 2013

Browser Piercing

a Javascript Application cannot

➔ acquire audio and video and then WebRTC

➔ communicate P2P and then WebRTC

Page 8: JooinK - DevFest Piemonte 2013

WebRTC across platforms● Chrome (mobile too)● Firefox (mobile too)● Opera● Native Java and Obj-C

Page 9: JooinK - DevFest Piemonte 2013

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,

errorCallback);

Page 10: JooinK - DevFest Piemonte 2013

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints, successCallback,

errorCallback);

Page 11: JooinK - DevFest Piemonte 2013

WebRTC JS-APIConstraints

● Controls the contents of the MediaStream● Media type, resolution, frame rate

var constraints = {video: true};

video: { mandatory: { ... }, optional [{... }]}

Page 12: JooinK - DevFest Piemonte 2013

WebRTC JS-APIConstraints

● Controls the contents of the MediaStream● Media type, resolution, frame rate

var constraints = {video: true};

video: { mandatory: { chromeMediaSource: ‘screen’ }, optional [{... }]}

Page 13: JooinK - DevFest Piemonte 2013

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,

errorCallback);

Page 14: JooinK - DevFest Piemonte 2013

WebRTC JS-APIerrorCallback

function errorCallback(error) { console.log("error: ", error);}

;-)

Page 15: JooinK - DevFest Piemonte 2013

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,errorCallback);

Page 16: JooinK - DevFest Piemonte 2013

WebRTC JS-APIsuccessCallback

function successCallback(stream) { ...}

stream: MediaStream; a flux of audio- or video-related data.

Page 17: JooinK - DevFest Piemonte 2013

WebRTC JS-APIsuccessCallback

function successCallback(stream) { var video = ... video.src =

window.URL.createObjectURL(stream);

}

(W3C File API)

Page 18: JooinK - DevFest Piemonte 2013

WebRTC JS-APIfull sample

var constraints = {video: true};

function successCallback(stream) { var video = document.querySelector("video"); video.src = window.URL.createObjectURL(stream);}

function errorCallback(error) { console.log("navigator.getUserMedia error: ", error);}

navigator.getUserMedia(constraints, successCallback, errorCallback);

Page 19: JooinK - DevFest Piemonte 2013

WebRTC JS-APIDo not forget

● to play the video

● to polyfill getUserMedia (moz*,webkit*,ms*)

Page 20: JooinK - DevFest Piemonte 2013

WebRTC JS-APIRTCPeerConnection

→getUserMedia

+RTCPeerConnection

Page 21: JooinK - DevFest Piemonte 2013

WebRTC JS-APIRTCDataChannel

Bidirectional communication of arbitrary data

● low latency● API similar to WebSockets

Page 22: JooinK - DevFest Piemonte 2013

RTCPeerConnection samplepc = new RTCPeerConnection(null);pc.onaddstream = gotRemoteStream;pc.addStream(localStream);pc.createOffer(gotOffer);

function gotOffer(desc) { pc.setLocalDescription(desc); sendOffer(desc);}

function gotAnswer(desc) { pc.setRemoteDescription(desc);}

function gotRemoteStream(e) { attachMediaStream(remoteVideo, e.stream);}

Page 23: JooinK - DevFest Piemonte 2013

RTCPeerConnection

Page 24: JooinK - DevFest Piemonte 2013

RTCPeerConnection

.

Page 25: JooinK - DevFest Piemonte 2013

RTCPeerConnection

.

Page 26: JooinK - DevFest Piemonte 2013

STUN

.

Page 27: JooinK - DevFest Piemonte 2013

TURN

.

Page 29: JooinK - DevFest Piemonte 2013

Yes BUT

● getUserMedia: gives us real time stream from the cam

● we can draw the <video/> into a <canvas/>

● from the canvas we can extract pixel data getImageData()

and then elaborate.

Page 30: JooinK - DevFest Piemonte 2013

Computing (GWT 4 us)goals- Almost native performance- Manage complex algorithms and applications

Page 31: JooinK - DevFest Piemonte 2013

Computing (GWT 4 us)goals- Almost native performance- Manage complex algorithms and applications

our approach- javascript as a target language (GWT) - hand written optimized pieces of code

Page 32: JooinK - DevFest Piemonte 2013

JooinK’s WebRTC sample

Sample

http://picshare.jooink.com

Demo …

Page 33: JooinK - DevFest Piemonte 2013

PicShareTecnologies

● WebGL for 3D graphics● WebRTC for MediaSteams● ImgUR for pictures store● AppEngine as a glue

Page 35: JooinK - DevFest Piemonte 2013

What’s nextChallanges

● real-time on mobile apps● real world recognition: computer vision

(BoofCV)

Page 36: JooinK - DevFest Piemonte 2013

What’s nextOur approach

● use TypedArrays everywhere ● offload computation to the graphic

accelerator through WebGL● help the JIT compiler/optimizer by asm.js

Page 37: JooinK - DevFest Piemonte 2013

That’s all folks!!!

Alberto [email protected]

Page 38: JooinK - DevFest Piemonte 2013

Markers