webrtc ... gwt & in-browser computation

53
WebRTC ... GWT & in-browser computation Alberto Mancini - [email protected] Francesca Tosi - [email protected]

Upload: jooink

Post on 15-Jan-2015

194 views

Category:

Technology


0 download

DESCRIPTION

Alberto Mancini - Francesca Tosi WebRTC ... GWT & in-browser computation Talk @ Open Source Day 2013

TRANSCRIPT

Page 1: WebRTC ... GWT & in-browser computation

WebRTC... GWT & in-browser computation

Alberto Mancini - [email protected]

Francesca Tosi - [email protected]

Page 2: WebRTC ... GWT & in-browser computation

WebRTCPlug-in free real-time 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: WebRTC ... GWT & in-browser computation

WebRTCJust 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: WebRTC ... GWT & in-browser computation

WebRTCJust 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 5: WebRTC ... GWT & in-browser computation

Once upon a time … browsers

(js-)applications were sandboxed and kept far away from the hosting computer’s resources.

Page 6: WebRTC ... GWT & in-browser computation

Once upon a time … browsers

(js-)applications were sandboxed and kept far away from the hosting computer’s resources.

Page 7: WebRTC ... GWT & in-browser computation

Browser Piercing (aka HTML5) a Javascript Application cannot

➔ access the filesystem

➔ open f/d socket connections

➔ use graphics accelerator

➔ span multiple threads

Page 8: WebRTC ... GWT & in-browser computation

Browser Piercing (aka HTML5) a Javascript Application cannot

➔ access the filesystem → and then FileAPI

➔ open f/d socket connections → and then WebSockets

➔ use graphics accelerator → and then WebGL

➔ span multiple threads → and then WebWorkers

Page 9: WebRTC ... GWT & in-browser computation

Browser Piercing

a Javascript Application cannot

➔ acquire audio and video

➔ communicate P2P

Page 10: WebRTC ... GWT & in-browser computation

Browser Piercing

a Javascript Application cannot

➔ acquire audio and video

➔ communicate P2P

Page 11: WebRTC ... GWT & in-browser computation

WebRTC … secure enough?

“… WebRTC has encryption baked right into it; there's actually no way to send unencrypted media using a WebRTC implementation … both Chrome and Firefox implement.”

Page 12: WebRTC ... GWT & in-browser computation

WebRTC … secure enough?But ...

“If the developers fail to carefully consider the security implications of their choices, the safeguards mandated by the specification will not be enough to guarantee the security of their WebRTC-based applications and the users.”

Page 13: WebRTC ... GWT & in-browser computation

WebRTC … secure enough?Do not ...

“... it would be very easy to inadvertently click on something that gave camera or microphone control to someone I don't know and don't care to know.”

Courtney Sato - nerd queen @ConstellationRG

Page 15: WebRTC ... GWT & in-browser computation

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

Page 16: WebRTC ... GWT & in-browser computation

WebRTC JS-API

Some code …

Page 17: WebRTC ... GWT & in-browser computation

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,

errorCallback);

Page 18: WebRTC ... GWT & in-browser computation

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints, successCallback,

errorCallback);

Page 19: WebRTC ... GWT & in-browser computation

WebRTC JS-APIConstraints

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

var constraints = {video: true};

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

Page 20: WebRTC ... GWT & in-browser computation

WebRTC JS-APIConstraints

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

var constraints = {video: true};

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

Page 21: WebRTC ... GWT & in-browser computation

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,

errorCallback);

Page 22: WebRTC ... GWT & in-browser computation

WebRTC JS-APIerrorCallback

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

;-)

Page 23: WebRTC ... GWT & in-browser computation

WebRTC JS-APIAcquiring video and audio

navigator.getUserMedia(constraints,

successCallback,errorCallback);

Page 24: WebRTC ... GWT & in-browser computation

WebRTC JS-APIsuccessCallback

function successCallback(stream) { ...}

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

Page 25: WebRTC ... GWT & in-browser computation

WebRTC JS-APIsuccessCallback

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

window.URL.createObjectURL(stream);

}

(W3C File API)

Page 26: WebRTC ... GWT & in-browser computation

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 27: WebRTC ... GWT & in-browser computation

WebRTC JS-APILive Demo - 1

http://goo.gl/7X91Ie

Page 28: WebRTC ... GWT & in-browser computation

WebRTC JS-APIRTCPeerConnection

→getUserMedia

+RTCPeerConnection

Page 29: WebRTC ... GWT & in-browser computation

WebRTC JS-APIRTCDataChannel

Bidirectional communication of arbitrary data

var position = {x: 3.0, y: -2.0};

...var message = {txt: ‘...’, timestamp: ...};

Page 30: WebRTC ... GWT & in-browser computation

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 31: WebRTC ... GWT & in-browser computation

RTCPeerConnection

Live Demo - 2

https://apprtc.appspot.com

Page 32: WebRTC ... GWT & in-browser computation

RTCPeerConnection

Page 33: WebRTC ... GWT & in-browser computation

RTCPeerConnection

Page 34: WebRTC ... GWT & in-browser computation

RTCPeerConnection

Page 35: WebRTC ... GWT & in-browser computation

STUN

Page 36: WebRTC ... GWT & in-browser computation

TURN

Page 38: WebRTC ... GWT & in-browser computation

Our target

Page 39: WebRTC ... GWT & in-browser computation

Our target

● getUserMedia: gives us real time stream from the camera

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

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

and then elaborate.

Page 40: WebRTC ... GWT & in-browser computation

Computing in the browsergoals- Almost native performance- Manage complex algorithms and applications on the browser

Page 41: WebRTC ... GWT & in-browser computation

Our target

cam WebRTC <video/> canvas ImageData

UInt8ArrayGWT(NyARToolkit)mv matrix

WebGL OBJ Model Loader3D Shaders

WebGL video

effects

Video

Page 42: WebRTC ... GWT & in-browser computation

Computing in the browserconstraints- reuse existing code- cross-browser (as much as possible)

Page 43: WebRTC ... GWT & in-browser computation

Computing in the browserour approach- javascript as a target language (GWT) - hand written optimized pieces of code

Page 44: WebRTC ... GWT & in-browser computation

GWTGWT Web Toolkit

- java to javascript (optimizing) compiler- emulated jre- widget set

- develop in java and execute in javascript

Page 45: WebRTC ... GWT & in-browser computation

JooinK’s WebRTC sample

Sample

http://picshare.jooink.com

Demo …

Page 46: WebRTC ... GWT & in-browser computation

PicShareTecnologies

● WebGL for 3D graphics● WebRTC for MediaSteams● ImgUR for pictures store● AppEngine to store indices

● GWT as the glue

Page 48: WebRTC ... GWT & in-browser computation

What’s nextChallanges

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

(BoofCV)

Page 49: WebRTC ... GWT & in-browser computation

What’s nextStrategy

● use TypedArrays everywhere ● offload computation to the graphic

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

Page 50: WebRTC ... GWT & in-browser computation

References

● http://io13webrtc.appspot.com/#1(where we got inspiration and most of the pictures)

● http://www.youtube.com/watch?v=p2HzZkd2A40● http://www.webrtc.org (spec)

Page 51: WebRTC ... GWT & in-browser computation

References

● http://www.jooink.com

● http://jooink.blogspot.com

● http://www.mokabyte.it

Page 52: WebRTC ... GWT & in-browser computation

That’s all folks!!!

Francesca [email protected]

Alberto [email protected]

Page 53: WebRTC ... GWT & in-browser computation

Markers - use at picshare.jooink.com