![Page 1: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/1.jpg)
AMT use case: Upipe + Chrome
Christophe Massiot (EBU multicast 2014)
![Page 2: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/2.jpg)
Goal • Display a multicast stream in a web
browser, using AMT if needed • Without AMT support from the OS,
or from a local network equipment
AMT
use
case
: Upi
pe +
Chr
ome
2
![Page 3: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/3.jpg)
Case 1: Direct access to multicast AM
T us
e ca
se: U
pipe
+ C
hrom
e
3
![Page 4: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/4.jpg)
Case 2: Use AMT relay AM
T us
e ca
se: U
pipe
+ C
hrom
e
4
![Page 5: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/5.jpg)
How? AM
T us
e ca
se: U
pipe
+ C
hrom
e
5
![Page 6: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/6.jpg)
Open source AMT libraries • Only one: Cisco’s – Written in C – Simple API: open, poll, recv
AMT
use
case
: Upi
pe +
Chr
ome
6
![Page 7: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/7.jpg)
Display video in a web browser • The old-fashioned way: NPAPI
“Netscape plug-ins” – Blatant security hole (no sandbox) – Requires user installation – Mozilla & Google have announced
end of support in 2014
AMT
use
case
: Upi
pe +
Chr
ome
7
![Page 8: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/8.jpg)
Display video in a web browser • Media Source Extensions – Designed for HLS/HDS/DASH etc. – Would have to implement AMT in JS – Would need UDP socket support from
browser (only supported by Chrome, and for packaged applications)
– Not as open as “native” extensions
AMT
use
case
: Upi
pe +
Chr
ome
8
![Page 9: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/9.jpg)
Display video in a web browser • Microsoft ActiveX – Example: VLC plug-in – No support for Mac OS X, Linux or
embedded devices – Security issues
AMT
use
case
: Upi
pe +
Chr
ome
9
![Page 10: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/10.jpg)
Display video in a web browser • Google’s “PPAPI” and “native client” – Open source – Supports downloadable native code (C
and C++) and dynamic linking – Plug-in isolated in a “sandbox” – Supported in recent Chrome versions on
all operating systems, and plans to port to Android devices
– Also has support for “portable” bitcode
AMT
use
case
: Upi
pe +
Chr
ome
10
![Page 11: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/11.jpg)
Knitting the pieces together • Need a C or C++ framework with
demux/decode capabilities • Must be very flexible: PPAPI has
constraints on threading and API calls AMT
use
case
: Upi
pe +
Chr
ome
11
![Page 12: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/12.jpg)
• Handles flows of data in a « pipeline » • Processes them using filters called
« pipes » • Defines APIs:
– To configure and feed data into pipes – To get out-of-band events from pipes – To store data in an efficient manner with
attributes – To interact with an event loop/threads
• Provides a set of basic pipes
AMT
use
case
: Upi
pe +
Chr
ome
12
Introducing Upipe
![Page 13: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/13.jpg)
Upipe vs. other frameworks • Flexibility – Lower-level: application decides
where to put queues and threads – Keep modules as simple and
autonomous as possible (UNIX philosophy)
– Arbitrary attributes on buffers è better clock management
– Dynamic pipeline construction
AMT
use
case
: Upi
pe +
Chr
ome
13
![Page 14: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/14.jpg)
Upipe vs. other frameworks • Event-driven architecture (upump) – Pipes install watchers called back
when events occur: • File descriptors readable or writable • Timers • Idlers
– Non-blocking – Unified API for sources/filters/sinks
AMT
use
case
: Upi
pe +
Chr
ome
14
![Page 15: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/15.jpg)
Upipe vs. other frameworks • Performance – Lock-less or wait-less data structures – Systematic reference counts on
structures – Zerocopy, copy-on-write buffer
management • Younger project: fewer modules,
fewer users
AMT
use
case
: Upi
pe +
Chr
ome
15
![Page 16: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/16.jpg)
Which steps? AM
T us
e ca
se: U
pipe
+ C
hrom
e
16
![Page 17: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/17.jpg)
Implementing AMT support • Source file:
lib/upipe-amt/upipe_amt_source.c • Caveats: libamt not compatible with
event-driven architectures, so requires its own thread
AMT
use
case
: Upi
pe +
Chr
ome
17
![Page 18: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/18.jpg)
A simple AMT-enabled player • Upipe’s example uplay requires a 2-line
change to use AMT source
AMT
use
case
: Upi
pe +
Chr
ome
18
![Page 19: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/19.jpg)
Implementing NaCl support • BSD sockets are supported with
compatibility layer libnacl_io • Need specific modules for display
and sound (lib/upipe-nacl) • Need a “player” plug-in building the
pipeline, based on uplay (examples/chrome/player_chrome)
• Messaging between JS and plug-in
AMT
use
case
: Upi
pe +
Chr
ome
19
![Page 20: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/20.jpg)
NaCl configuration • NaCl and pNaCl enabled by default
in recent Chrome versions • Sockets blocked by default – chrome://flags only works for
“packaged apps” – Need to pass command-line option
--allow-nacl-socket-api=localhost
AMT
use
case
: Upi
pe +
Chr
ome
20
![Page 21: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/21.jpg)
NaCl socket support • Only a subset of BSD sockets API – Missing setsockopt options: • IP_ADD_MEMBERSHIP / DROP • IP_ADD_SOURCE_MEMBERSHIP / DROP • IP_PKTINFO • …
– Cannot bind to a multicast address • AMT provides a work-around
AMT
use
case
: Upi
pe +
Chr
ome
21
![Page 22: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/22.jpg)
NaCl performance • “Nearly as fast as native compiled
code” but in reality: – No assembly allowed (no decoder
optimizations) – No easy YUV support
• Portable Native Client adds 10 to 25% overhead
• However, support for OpenGL and hardware decoders under way
AMT
use
case
: Upi
pe +
Chr
ome
22
![Page 23: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/23.jpg)
Hands on! AM
T us
e ca
se: U
pipe
+ C
hrom
e
23
![Page 24: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/24.jpg)
Installing NaCl SDK and NaCl ports • https://developer.chrome.com/
native-client/sdk/download • http://code.google.com/p/
naclports/ • Need build environment and 32
bits version of standard libraries, in particular lib32z1-dev
AMT
use
case
: Upi
pe +
Chr
ome
24
![Page 25: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/25.jpg)
Building NaCl ports • Apply
http://upipe.org/downloads/naclports.patch • export NACL_SDK_ROOT=<path>/nacl_sdk/
pepper_35 • NACL_ARCH=x86_64 TOOLCHAIN=glibc ./bin/
naclports install upipe • NACL_ARCH=i686 TOOLCHAIN=glibc ./bin/
naclports install upipe
AMT
use
case
: Upi
pe +
Chr
ome
25
![Page 26: AMT use case: Upipe + Chromeupipe.org/blog/wp-content/uploads/2014/09/ebu-multicast2014.pdf · – Systematic reference counts on structures – Zerocopy, copy-on-write buffer](https://reader034.vdocument.in/reader034/viewer/2022042404/5f189d68f5e19a2f1b195bb6/html5/thumbnails/26.jpg)
Building and running plug-in • cd out/build/upipe/upipe-master/examples/
chrome/player_chrome • make • export CHROME_ARGS="--allow-nacl-socket-
api=192.168.0.100,localhost” • make run
AMT
use
case
: Upi
pe +
Chr
ome
26