SlideShare a Scribd company logo
1 of 26
Download to read offline
BINARY DATA ADVENTURES
IN BROWSER JAVASCRIPT
OR HILTCH / CTO @ STREAMRAIL
INTRO
• Background
• Evolution in the browser
• The Binary Arsenal in JS (type system,
inputs, outputs)
• Solving Cool, Practical Problems
00110110011100100101010100100
10101011101000001010100101010
01010010111010101001010101010
010101011111001010100010101110
0101010111101000000101010100
01011001010101010111100001010
TRADITIONALLY
• Outside of JS: 

Low level stuff: Compression (gzip/deflate), Bitfields (ACLs),
Networks (CRC32), Graphics (algorithms, positioning), ...
• Inside of JS: 

Solving weird issues
$http.post('/someUrl', {score:42}).

success(function(data, status, headers, config) {

// not today :-(

}).

error(function(data, status, headers, config) {

// data=Object {‘error’: ‘Float64 is not int’}

}
$http.post('/someUrl', {score:42}).

success(function(data, status, headers, config) {

// not today :-(

}).

error(function(data, status, headers, config) {

// data=Object {‘error’: ‘Float64 is not int’}

}
typeof 3.14159 === typeof 3
In JS, all numbers are of type Float64
But all bitwise ops are Int32!
Bitwise OR: number | 0
Bitwise NOT: ~~number
Shift: number >> 0
parseInt: parseInt(number, 10)
floor: Math.floor(number)
modulo: number - number % 1
BROWSERS, EVOLVED
• Type system: Blob, ArrayBuffer, TypedArray, DataView
• Inputs:

Input methods: XHR 2, File API, Canvas, WebSockets, WebRTC, ...
• Outputs:

MSE, Canvas, WebSockets, WebRTC, WebGL, ...
WHAT MAKES
TYPED ARRAYS FAST
• Passed to native interfaces completely AS IS (direct memory access)
• Native “endianness” - watch out!
• DataView adapter
Byte order
0x12345678 Hex inside a Uint32Array of 4
Little-endian: 78 56 34 12
12 34 56 78Big-endian:
STREAMING VIDEO
WITH JS
• No plugins (Netflix: silverlight, Facebook: flash)
• MSE: Pure JS DASH/HLS (YouTube)
• DRM Support (EME)
• MSE + WebRTC: Bittorrent, in the browser! (WebTorrent)
‘USE ASM’
sys/libkern/strlen.c


size_t strlen(const char *str) {
const char *s;
for (s = str; *s; ++s);
return(s - str);
}
asm.js


function strlen(ptr) {

ptr = ptr|0;

var curr = 0;

curr = ptr;

while (MEM8[curr]|0 != 0) {

curr = (curr + 1)|0;

}

return (curr - ptr)|0;

}
a subset of JS for handling numbers faster
• OdinMonkey - AOT in FF (fallback to IonMonkey JIT)
• Support by all major browsers (to an extent)
• Typed Array used as “memory”
• All add/sub are 32 bit (number | 0)
• DI: function(stdlib, foreign, heap)

‘USE ASM’
KRIPKEN TO THE RESCUE
C/C++ > LLVM > Emscripten > asm.js!
• Huge code bases (SQLite, BananaBread,J2ME VM, …)

- close to impossible by hand
• Enjoy Clang/LLVM optimizations

- decades of work done to optimize compiled code
• OpenGL > WebGL “for free”
- directly map a lot of OpenGL ES 2.0 command to WebGL
- not only for graphics rendering, also for GPU offloading
• Use Docker to run Emscripten
- lots of software (emscripten, emscripten-fastcomp, emscripten-
fastcomp-clang, llvm clang)
- build your own or use one from DockerHub
KRIPKEN TO THE RESCUE
emscripten in real life
• Obtain bytes of video (and audio) by downloading them
• Decode the video (and audio) using native decoders in the browser/OS
• Animate the frames to create the video experience


VIDEO TAG EMULATION
• Obtain bytes of video (and audio) by downloading them
> XHR 2.0, response type “arraybuffer”
• Decode the video (and audio) using native decoders in the browser/OS
> Cross compile a native decoder to JS using Emscripten
• Animate the frames to create the video experience
> For each decoded pixel, create a 2D Texture, transform it to RGBA using
a fragment shader, and render it with WebGL using canvas
(“experimental-webgl”).

VIDEO TAG EMULATION
YUV -> RGB
• Luma + (2 * Chroma) vs 

3 * (Chroma + Luma)
• Different needs, different inputs
• Color space conversion heavily
computational (floating point coefficients
matrix multiplication)
WEBGL RASTERIZATION
function yuv2canvas(buffer, width, height) {
var lumaSize = width * height;
var chromaSize = lumaSize >> 2;
webGLCanvas.YTexture
.fill(buffer.subarray(0, lumaSize));
webGLCanvas.UTexture
.fill(buffer.subarray(lumaSize, lumaSize + chromaSize));
webGLCanvas.VTexture
.fill(buffer.subarray(lumaSize + chromaSize,
lumaSize + 2 * chromaSize));
webGLCanvas.drawScene();
}
4:2:0
=
+
precision highp float;
varying highp vec2 vTextureCoord;
uniform sampler2D YTexture;
uniform sampler2D UTexture;
uniform sampler2D VTexture;
const mat4 YUV2RGB = mat4 (
1.1643828125, 0 , 1.59602734375, -.87078515625,
1.1643828125, -0.39176171875, -0.81296875 , .52959375,
1.1643828125, 2.017234375 , 0 , -1.081390625,
0 , 0 , 0 , 1
);
void main(void) {
gl_FragColor = vec4(texture2D(YTexture, vTextureCoord).x,
texture2D(UTexture, vTextureCoord).x,
texture2D(VTexture, vTextureCoord).x,
1)
* YUV2RGB;
}
<SCRIPT TYPE="X-SHADER/X-FRAGMENT">
LIVE DEMO
THANK YOU!
OR HILTCH / CTO @ STREAMRAIL

More Related Content

What's hot

Video game console specs 2
Video game console specs 2Video game console specs 2
Video game console specs 2gks1996
 
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018DevOpsDays Tel Aviv
 
Nvvp streams-3
Nvvp streams-3Nvvp streams-3
Nvvp streams-3Josh Wyatt
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyThe JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyConstantin Dumitrescu
 
Assembly programming
Assembly programmingAssembly programming
Assembly programmingPeter Cheung
 
PS5 vs XBOX SERIES X
PS5 vs XBOX SERIES XPS5 vs XBOX SERIES X
PS5 vs XBOX SERIES XGARFGAMER
 
Zsh & fish: better *bash* for hackers
Zsh & fish: better *bash* for hackersZsh & fish: better *bash* for hackers
Zsh & fish: better *bash* for hackersRuslan Sharipov
 
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트YEONG-CHEON YOU
 
CubiMap_Linkedin
CubiMap_LinkedinCubiMap_Linkedin
CubiMap_LinkedinJesus Albo
 
The Spock Guide to Think Out of The Vagrant Box
The Spock Guide to Think Out of The Vagrant BoxThe Spock Guide to Think Out of The Vagrant Box
The Spock Guide to Think Out of The Vagrant BoxErrazudin Ishak
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humansJuan De Bravo
 
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
NVidia CUDA for Bruteforce Attacks - DefCamp 2012NVidia CUDA for Bruteforce Attacks - DefCamp 2012
NVidia CUDA for Bruteforce Attacks - DefCamp 2012DefCamp
 

What's hot (19)

Video game console specs 2
Video game console specs 2Video game console specs 2
Video game console specs 2
 
Computer Organisation Part 2
Computer Organisation Part 2Computer Organisation Part 2
Computer Organisation Part 2
 
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
 
Nvvp streams-3
Nvvp streams-3Nvvp streams-3
Nvvp streams-3
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyThe JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / July
 
Assembly programming
Assembly programmingAssembly programming
Assembly programming
 
PS5 vs XBOX SERIES X
PS5 vs XBOX SERIES XPS5 vs XBOX SERIES X
PS5 vs XBOX SERIES X
 
Zsh & fish: better *bash* for hackers
Zsh & fish: better *bash* for hackersZsh & fish: better *bash* for hackers
Zsh & fish: better *bash* for hackers
 
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
 
CubiMap_Linkedin
CubiMap_LinkedinCubiMap_Linkedin
CubiMap_Linkedin
 
The Spock Guide to Think Out of The Vagrant Box
The Spock Guide to Think Out of The Vagrant BoxThe Spock Guide to Think Out of The Vagrant Box
The Spock Guide to Think Out of The Vagrant Box
 
HTML5 Gaming
HTML5 GamingHTML5 Gaming
HTML5 Gaming
 
VirtualOS-using-Qemu
VirtualOS-using-QemuVirtualOS-using-Qemu
VirtualOS-using-Qemu
 
Murano docker demo
Murano docker demoMurano docker demo
Murano docker demo
 
Zsh shell-for-humans
Zsh shell-for-humansZsh shell-for-humans
Zsh shell-for-humans
 
Shrink to grow
Shrink to growShrink to grow
Shrink to grow
 
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
NVidia CUDA for Bruteforce Attacks - DefCamp 2012NVidia CUDA for Bruteforce Attacks - DefCamp 2012
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
 
GPU
GPUGPU
GPU
 
Cuda
CudaCuda
Cuda
 

Viewers also liked

Trabajo final de empresarismo
Trabajo final de empresarismoTrabajo final de empresarismo
Trabajo final de empresarismomaryars182
 
Sistema oseo por Maria Fernanda Segovia
Sistema oseo por Maria Fernanda SegoviaSistema oseo por Maria Fernanda Segovia
Sistema oseo por Maria Fernanda SegoviaMariaFernandaSegovia
 
Opening session - CAPFITOGEN Programme introduction
Opening session - CAPFITOGEN Programme introductionOpening session - CAPFITOGEN Programme introduction
Opening session - CAPFITOGEN Programme introductionMauricio Parra Quijano
 
Presentation 4 - SelecVar, ELCmapas and ECOGEO tools
Presentation 4 - SelecVar, ELCmapas and ECOGEO toolsPresentation 4 - SelecVar, ELCmapas and ECOGEO tools
Presentation 4 - SelecVar, ELCmapas and ECOGEO toolsMauricio Parra Quijano
 
第三回R勉強会
第三回R勉強会第三回R勉強会
第三回R勉強会Paweł Rusin
 
Surveying CRIS and IR across Europe
Surveying CRIS and IR across EuropeSurveying CRIS and IR across Europe
Surveying CRIS and IR across EuropeLígia Maria Ribeiro
 
SharePoint Development Services
SharePoint Development ServicesSharePoint Development Services
SharePoint Development ServicesSergei Rabotai
 
Colegio técnico nacional de encarnación
Colegio técnico nacional de encarnaciónColegio técnico nacional de encarnación
Colegio técnico nacional de encarnaciónlucianokroug
 

Viewers also liked (20)

James tecnologia
James tecnologiaJames tecnologia
James tecnologia
 
Culturas andinas
Culturas andinasCulturas andinas
Culturas andinas
 
Congenit
CongenitCongenit
Congenit
 
ksspitzit nro2 2013
ksspitzit nro2 2013ksspitzit nro2 2013
ksspitzit nro2 2013
 
Eco school
Eco schoolEco school
Eco school
 
Trabajo final de empresarismo
Trabajo final de empresarismoTrabajo final de empresarismo
Trabajo final de empresarismo
 
Queenty tugas ipa
Queenty tugas ipaQueenty tugas ipa
Queenty tugas ipa
 
Sistema oseo por Maria Fernanda Segovia
Sistema oseo por Maria Fernanda SegoviaSistema oseo por Maria Fernanda Segovia
Sistema oseo por Maria Fernanda Segovia
 
Presentation 3 - Installation and use
Presentation 3 - Installation and usePresentation 3 - Installation and use
Presentation 3 - Installation and use
 
Opening session - CAPFITOGEN Programme introduction
Opening session - CAPFITOGEN Programme introductionOpening session - CAPFITOGEN Programme introduction
Opening session - CAPFITOGEN Programme introduction
 
Grão de Trigo
Grão de TrigoGrão de Trigo
Grão de Trigo
 
Presentation 4 - SelecVar, ELCmapas and ECOGEO tools
Presentation 4 - SelecVar, ELCmapas and ECOGEO toolsPresentation 4 - SelecVar, ELCmapas and ECOGEO tools
Presentation 4 - SelecVar, ELCmapas and ECOGEO tools
 
Presentation 5 representa di_vmapas
Presentation 5 representa di_vmapasPresentation 5 representa di_vmapas
Presentation 5 representa di_vmapas
 
Presentation1 ecogeographic basis
Presentation1 ecogeographic basisPresentation1 ecogeographic basis
Presentation1 ecogeographic basis
 
Crônicas no saresp profª
Crônicas no saresp    profªCrônicas no saresp    profª
Crônicas no saresp profª
 
第三回R勉強会
第三回R勉強会第三回R勉強会
第三回R勉強会
 
Struktur dan fugsi tumbuhan
Struktur dan fugsi tumbuhanStruktur dan fugsi tumbuhan
Struktur dan fugsi tumbuhan
 
Surveying CRIS and IR across Europe
Surveying CRIS and IR across EuropeSurveying CRIS and IR across Europe
Surveying CRIS and IR across Europe
 
SharePoint Development Services
SharePoint Development ServicesSharePoint Development Services
SharePoint Development Services
 
Colegio técnico nacional de encarnación
Colegio técnico nacional de encarnaciónColegio técnico nacional de encarnación
Colegio técnico nacional de encarnación
 

Similar to BINARY DATA ADVENTURES IN BROWSER JAVASCRIPT

44 con slides
44 con slides44 con slides
44 con slidesgeeksec80
 
44 con slides (1)
44 con slides (1)44 con slides (1)
44 con slides (1)geeksec80
 
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)Johan Andersson
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsServer Density
 
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...44CON
 
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)Daniel Lemire
 
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...Daosheng Mu
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013midnite_runr
 
Java gpu computing
Java gpu computingJava gpu computing
Java gpu computingArjan Lamers
 
HTML5: New UI Library for Games - Chad Austin
HTML5: New UI Library for Games - Chad AustinHTML5: New UI Library for Games - Chad Austin
HTML5: New UI Library for Games - Chad AustinChad Austin
 
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...MongoDB
 
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali ZaidiNatural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali ZaidiDatabricks
 
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法MITSUNARI Shigeo
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsSerge Stinckwich
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Patrick Chanezon
 

Similar to BINARY DATA ADVENTURES IN BROWSER JAVASCRIPT (20)

44 con slides
44 con slides44 con slides
44 con slides
 
44 con slides (1)
44 con slides (1)44 con slides (1)
44 con slides (1)
 
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
XRobots
XRobotsXRobots
XRobots
 
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...
44CON 2013 - Browser bug hunting - Memoirs of a last man standing - Atte Kett...
 
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)Next Generation Indexes For Big Data Engineering (ODSC East 2018)
Next Generation Indexes For Big Data Engineering (ODSC East 2018)
 
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
Using The New Flash Stage3D Web Technology To Build Your Own Next 3D Browser ...
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
 
Java Memory Model
Java Memory ModelJava Memory Model
Java Memory Model
 
Java gpu computing
Java gpu computingJava gpu computing
Java gpu computing
 
HTML5: New UI Library for Games - Chad Austin
HTML5: New UI Library for Games - Chad AustinHTML5: New UI Library for Games - Chad Austin
HTML5: New UI Library for Games - Chad Austin
 
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
 
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali ZaidiNatural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
 
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
20131212
2013121220131212
20131212
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 

Recently uploaded

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

BINARY DATA ADVENTURES IN BROWSER JAVASCRIPT

  • 1. BINARY DATA ADVENTURES IN BROWSER JAVASCRIPT OR HILTCH / CTO @ STREAMRAIL
  • 2. INTRO • Background • Evolution in the browser • The Binary Arsenal in JS (type system, inputs, outputs) • Solving Cool, Practical Problems 00110110011100100101010100100 10101011101000001010100101010 01010010111010101001010101010 010101011111001010100010101110 0101010111101000000101010100 01011001010101010111100001010
  • 3. TRADITIONALLY • Outside of JS: 
 Low level stuff: Compression (gzip/deflate), Bitfields (ACLs), Networks (CRC32), Graphics (algorithms, positioning), ... • Inside of JS: 
 Solving weird issues
  • 4. $http.post('/someUrl', {score:42}).
 success(function(data, status, headers, config) {
 // not today :-(
 }).
 error(function(data, status, headers, config) {
 // data=Object {‘error’: ‘Float64 is not int’}
 }
  • 5. $http.post('/someUrl', {score:42}).
 success(function(data, status, headers, config) {
 // not today :-(
 }).
 error(function(data, status, headers, config) {
 // data=Object {‘error’: ‘Float64 is not int’}
 }
  • 7. In JS, all numbers are of type Float64 But all bitwise ops are Int32! Bitwise OR: number | 0 Bitwise NOT: ~~number Shift: number >> 0 parseInt: parseInt(number, 10) floor: Math.floor(number) modulo: number - number % 1
  • 8.
  • 9. BROWSERS, EVOLVED • Type system: Blob, ArrayBuffer, TypedArray, DataView • Inputs:
 Input methods: XHR 2, File API, Canvas, WebSockets, WebRTC, ... • Outputs:
 MSE, Canvas, WebSockets, WebRTC, WebGL, ...
  • 10. WHAT MAKES TYPED ARRAYS FAST • Passed to native interfaces completely AS IS (direct memory access) • Native “endianness” - watch out! • DataView adapter Byte order 0x12345678 Hex inside a Uint32Array of 4 Little-endian: 78 56 34 12 12 34 56 78Big-endian:
  • 11. STREAMING VIDEO WITH JS • No plugins (Netflix: silverlight, Facebook: flash) • MSE: Pure JS DASH/HLS (YouTube) • DRM Support (EME) • MSE + WebRTC: Bittorrent, in the browser! (WebTorrent)
  • 12. ‘USE ASM’ sys/libkern/strlen.c 
 size_t strlen(const char *str) { const char *s; for (s = str; *s; ++s); return(s - str); } asm.js 
 function strlen(ptr) {
 ptr = ptr|0;
 var curr = 0;
 curr = ptr;
 while (MEM8[curr]|0 != 0) {
 curr = (curr + 1)|0;
 }
 return (curr - ptr)|0;
 }
  • 13. a subset of JS for handling numbers faster • OdinMonkey - AOT in FF (fallback to IonMonkey JIT) • Support by all major browsers (to an extent) • Typed Array used as “memory” • All add/sub are 32 bit (number | 0) • DI: function(stdlib, foreign, heap)
 ‘USE ASM’
  • 14.
  • 15.
  • 16. KRIPKEN TO THE RESCUE C/C++ > LLVM > Emscripten > asm.js! • Huge code bases (SQLite, BananaBread,J2ME VM, …)
 - close to impossible by hand • Enjoy Clang/LLVM optimizations
 - decades of work done to optimize compiled code • OpenGL > WebGL “for free” - directly map a lot of OpenGL ES 2.0 command to WebGL - not only for graphics rendering, also for GPU offloading
  • 17. • Use Docker to run Emscripten - lots of software (emscripten, emscripten-fastcomp, emscripten- fastcomp-clang, llvm clang) - build your own or use one from DockerHub KRIPKEN TO THE RESCUE
  • 19. • Obtain bytes of video (and audio) by downloading them • Decode the video (and audio) using native decoders in the browser/OS • Animate the frames to create the video experience 
 VIDEO TAG EMULATION
  • 20. • Obtain bytes of video (and audio) by downloading them > XHR 2.0, response type “arraybuffer” • Decode the video (and audio) using native decoders in the browser/OS > Cross compile a native decoder to JS using Emscripten • Animate the frames to create the video experience > For each decoded pixel, create a 2D Texture, transform it to RGBA using a fragment shader, and render it with WebGL using canvas (“experimental-webgl”).
 VIDEO TAG EMULATION
  • 21. YUV -> RGB • Luma + (2 * Chroma) vs 
 3 * (Chroma + Luma) • Different needs, different inputs • Color space conversion heavily computational (floating point coefficients matrix multiplication)
  • 23. function yuv2canvas(buffer, width, height) { var lumaSize = width * height; var chromaSize = lumaSize >> 2; webGLCanvas.YTexture .fill(buffer.subarray(0, lumaSize)); webGLCanvas.UTexture .fill(buffer.subarray(lumaSize, lumaSize + chromaSize)); webGLCanvas.VTexture .fill(buffer.subarray(lumaSize + chromaSize, lumaSize + 2 * chromaSize)); webGLCanvas.drawScene(); } 4:2:0 = +
  • 24. precision highp float; varying highp vec2 vTextureCoord; uniform sampler2D YTexture; uniform sampler2D UTexture; uniform sampler2D VTexture; const mat4 YUV2RGB = mat4 ( 1.1643828125, 0 , 1.59602734375, -.87078515625, 1.1643828125, -0.39176171875, -0.81296875 , .52959375, 1.1643828125, 2.017234375 , 0 , -1.081390625, 0 , 0 , 0 , 1 ); void main(void) { gl_FragColor = vec4(texture2D(YTexture, vTextureCoord).x, texture2D(UTexture, vTextureCoord).x, texture2D(VTexture, vTextureCoord).x, 1) * YUV2RGB; } <SCRIPT TYPE="X-SHADER/X-FRAGMENT">
  • 26. THANK YOU! OR HILTCH / CTO @ STREAMRAIL