SlideShare a Scribd company logo
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
BINARY DATA ADVENTURES  IN BROWSER JAVASCRIPT
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’
BINARY DATA ADVENTURES  IN BROWSER JAVASCRIPT
BINARY DATA ADVENTURES  IN BROWSER JAVASCRIPT
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
Ad

Recommended

Low Latency Networking on IOS and Android over Cloud by Oguz Bastemur
Low Latency Networking on IOS and Android over Cloud by Oguz Bastemur
Codemotion
 
PreBule
PreBule
Reo Yamada
 
Nvvp streams-2
Nvvp streams-2
Josh Wyatt
 
Ether Mining 101
Ether Mining 101
Conor Svensson
 
Ether mining 101 v2
Ether mining 101 v2
Conor Svensson
 
Spesifikasi server
Spesifikasi server
Julio Mukhlishin
 
Palestra - ASPNET 5 no Linux
Palestra - ASPNET 5 no Linux
Henrylle Maia
 
Puppet Camp Dublin - 06/2012
Puppet Camp Dublin - 06/2012
Roland Tritsch
 
Video game console specs 2
Video game console specs 2
gks1996
 
Computer Organisation Part 2
Computer Organisation Part 2
Krishna Kumar Bohra
 
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
DevOpsDays Tel Aviv
 
Nvvp streams-3
Nvvp streams-3
Josh Wyatt
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / July
Constantin Dumitrescu
 
Assembly programming
Assembly programming
Peter Cheung
 
PS5 vs XBOX SERIES X
PS5 vs XBOX SERIES X
GARFGAMER
 
Zsh & fish: better *bash* for hackers
Zsh & fish: better *bash* for hackers
Ruslan Sharipov
 
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
YEONG-CHEON YOU
 
CubiMap_Linkedin
CubiMap_Linkedin
Jesus Albo
 
The Spock Guide to Think Out of The Vagrant Box
The Spock Guide to Think Out of The Vagrant Box
Errazudin Ishak
 
HTML5 Gaming
HTML5 Gaming
David Isbitski
 
VirtualOS-using-Qemu
VirtualOS-using-Qemu
Girish Patoliya
 
Murano docker demo
Murano docker demo
Henar Muñoz Frutos
 
Zsh shell-for-humans
Zsh shell-for-humans
Juan De Bravo
 
Shrink to grow
Shrink to grow
Daniel Bovensiepen
 
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
DefCamp
 
GPU
GPU
Hamid Bluri
 
Cuda
Cuda
Mannu Malhotra
 
James tecnologia
James tecnologia
jameselmejor123
 
Culturas andinas
Culturas andinas
Bebesita Taty
 

More Related Content

What's hot (19)

Video game console specs 2
Video game console specs 2
gks1996
 
Computer Organisation Part 2
Computer Organisation Part 2
Krishna Kumar Bohra
 
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
DevOpsDays Tel Aviv
 
Nvvp streams-3
Nvvp streams-3
Josh Wyatt
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / July
Constantin Dumitrescu
 
Assembly programming
Assembly programming
Peter Cheung
 
PS5 vs XBOX SERIES X
PS5 vs XBOX SERIES X
GARFGAMER
 
Zsh & fish: better *bash* for hackers
Zsh & fish: better *bash* for hackers
Ruslan Sharipov
 
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
YEONG-CHEON YOU
 
CubiMap_Linkedin
CubiMap_Linkedin
Jesus Albo
 
The Spock Guide to Think Out of The Vagrant Box
The Spock Guide to Think Out of The Vagrant Box
Errazudin Ishak
 
HTML5 Gaming
HTML5 Gaming
David Isbitski
 
VirtualOS-using-Qemu
VirtualOS-using-Qemu
Girish Patoliya
 
Murano docker demo
Murano docker demo
Henar Muñoz Frutos
 
Zsh shell-for-humans
Zsh shell-for-humans
Juan De Bravo
 
Shrink to grow
Shrink to grow
Daniel Bovensiepen
 
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
DefCamp
 
GPU
GPU
Hamid Bluri
 
Cuda
Cuda
Mannu Malhotra
 
Video game console specs 2
Video game console specs 2
gks1996
 
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
Data Science in DevOps/SysOps - Boaz Shuster - DevOpsDays Tel Aviv 2018
DevOpsDays Tel Aviv
 
Nvvp streams-3
Nvvp streams-3
Josh Wyatt
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / July
Constantin Dumitrescu
 
Assembly programming
Assembly programming
Peter Cheung
 
PS5 vs XBOX SERIES X
PS5 vs XBOX SERIES X
GARFGAMER
 
Zsh & fish: better *bash* for hackers
Zsh & fish: better *bash* for hackers
Ruslan Sharipov
 
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
CUDA Raytracing을 이용한 Voxel오브젝트 가시성 테스트
YEONG-CHEON YOU
 
CubiMap_Linkedin
CubiMap_Linkedin
Jesus Albo
 
The Spock Guide to Think Out of The Vagrant Box
The Spock Guide to Think Out of The Vagrant Box
Errazudin Ishak
 
Zsh shell-for-humans
Zsh shell-for-humans
Juan De Bravo
 
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
NVidia CUDA for Bruteforce Attacks - DefCamp 2012
DefCamp
 

Viewers also liked (20)

James tecnologia
James tecnologia
jameselmejor123
 
Culturas andinas
Culturas andinas
Bebesita Taty
 
Eco school
Eco school
walled ashwah
 
Trabajo final de empresarismo
Trabajo final de empresarismo
maryars182
 
Queenty tugas ipa
Queenty tugas ipa
Agustinus Wiyarno
 
Sistema oseo por Maria Fernanda Segovia
Sistema oseo por Maria Fernanda Segovia
MariaFernandaSegovia
 
Presentation 3 - Installation and use
Presentation 3 - Installation and use
Mauricio Parra Quijano
 
Opening session - CAPFITOGEN Programme introduction
Opening session - CAPFITOGEN Programme introduction
Mauricio Parra Quijano
 
Grão de Trigo
Grão de Trigo
Escola de Sabedoria Hilarion de Monte Nebo
 
Presentation 4 - SelecVar, ELCmapas and ECOGEO tools
Presentation 4 - SelecVar, ELCmapas and ECOGEO tools
Mauricio Parra Quijano
 
Presentation 5 representa di_vmapas
Presentation 5 representa di_vmapas
Mauricio Parra Quijano
 
Presentation1 ecogeographic basis
Presentation1 ecogeographic basis
Mauricio Parra Quijano
 
Crônicas no saresp profª
Crônicas no saresp profª
Escola Estadual Joaquim Abarca -
 
第三回R勉強会
第三回R勉強会
Paweł Rusin
 
Struktur dan fugsi tumbuhan
Struktur dan fugsi tumbuhan
Agustinus Wiyarno
 
Surveying CRIS and IR across Europe
Surveying CRIS and IR across Europe
Lígia Maria Ribeiro
 
SharePoint Development Services
SharePoint Development Services
Sergei Rabotai
 
Colegio técnico nacional de encarnación
Colegio técnico nacional de encarnación
lucianokroug
 
Trabajo final de empresarismo
Trabajo final de empresarismo
maryars182
 
Sistema oseo por Maria Fernanda Segovia
Sistema oseo por Maria Fernanda Segovia
MariaFernandaSegovia
 
Opening session - CAPFITOGEN Programme introduction
Opening session - CAPFITOGEN Programme introduction
Mauricio Parra Quijano
 
Presentation 4 - SelecVar, ELCmapas and ECOGEO tools
Presentation 4 - SelecVar, ELCmapas and ECOGEO tools
Mauricio Parra Quijano
 
第三回R勉強会
第三回R勉強会
Paweł Rusin
 
Surveying CRIS and IR across Europe
Surveying CRIS and IR across Europe
Lígia Maria Ribeiro
 
SharePoint Development Services
SharePoint Development Services
Sergei Rabotai
 
Colegio técnico nacional de encarnación
Colegio técnico nacional de encarnación
lucianokroug
 
Ad

Similar to BINARY DATA ADVENTURES IN BROWSER JAVASCRIPT (20)

44 con slides
44 con slides
geeksec80
 
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)
repii
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
Server Density
 
XRobots
XRobots
Dr. Jan Köhnlein
 
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)
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 ...
Daosheng Mu
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
midnite_runr
 
Java Memory Model
Java Memory Model
Łukasz Koniecki
 
Java gpu computing
Java gpu computing
Arjan Lamers
 
HTML5: New UI Library for Games - Chad Austin
HTML5: New UI Library for Games - Chad Austin
Chad Austin
 
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 Zaidi
Databricks
 
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
MITSUNARI Shigeo
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
Serge Stinckwich
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
20131212
20131212
Jocelyn
 
Programar para GPUs
Programar para GPUs
Alcides Fonseca
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
Patrick Chanezon
 
44 con slides
44 con slides
geeksec80
 
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)
repii
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
Server 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
 
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 ...
Daosheng Mu
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
midnite_runr
 
Java gpu computing
Java gpu computing
Arjan Lamers
 
HTML5: New UI Library for Games - Chad Austin
HTML5: New UI Library for Games - Chad Austin
Chad Austin
 
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 Zaidi
Databricks
 
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
深層学習フレームワークにおけるIntel CPU/富岳向け最適化法
MITSUNARI Shigeo
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
Serge Stinckwich
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
Patrick Chanezon
 
Ad

Recently uploaded (20)

cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Creating Inclusive Digital Learning with AI: A Smarter, Fairer Future
Impelsys Inc.
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 

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
  • 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’
  • 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