ImportantDue to NaCl deprecation by the Chromium project, Tizen TV will continue its support for NaCl only until 2021-year products. Meanwhile, Tizen TV will start focusing on high-performance, cross-browser WebAssembly from 2020-year products.
This topic introduces the Native Client technology, which allows you to run native C and C++ code on Samsung Smart TVs.
Native Client (NaCl) is a technology developed by Google that allows you to load and safely execute native binaries, written in C or C++, as if they were Web browser plug-ins. NaCl is supported on the Google Chrome™ browser, but Samsung has customized the NaCl technology and has supported it on Smart TVs since 2013. Since most Smart TV applications are essentially Web pages, it means NaCl binaries can also be run on Smart TVs.
The following figure shows Futuracer, a game that uses NaCl to take advantage of OpenGL® ES graphics features.
The following topics introduce you to creating NaCl applications for Smart TVs:
Getting Started
Learn about the tools you need to develop NaCl applications and the structure of a NaCl application.
When you use NaCl, you can take advantage of the following features:
Greater execution speed
NaCl code runs up to 24 times faster than JavaScript (benchmark based on an encryption algorithm).
Near-native code performance
In Web applications, you can use compiled code run natively on the host CPU. On the ARM platform, NaCl applications can achieve about 85% of native perfo
Multithreading
You can use the multithreading features introduced in C++ 11 and take advantage of the multi-core architecture of mos.
Input event handling
The NaCl plugin can register mouse and keyboard events.
Access to local and remote resources using special interfaces, such as TCP/UDP sockets, WebSockets, and file I/O.
Support for C++ 11 and C++ 14
Access to libraries ported from C/C++, including:
OpenGL® ES 2.0: 3D graphics
OpenSSL: secure data encryption
OpenCV: image/video recognition and analysis
Boost: general-purpose tools
Security
The NaCl plugin is sandboxed inside the Web browser engine to ensure that malicious code is detected and terminated. To ensure the safety of executed code, C/C++ native code compiled using the NaCl toolchain has some restrictions:
System resources cannot be opened directly using functions, such as the fopen() function.
The main() function is replaced by a set of functions and classes that represent the NaCl plugin logic.
System-dependent libraries, such as "uinstd.h" and "windows.h", are not available.
Code obfuscation
After compiling the application, the native code cannot be retrieved from the application package.
Portability across systems and architectures
NaCl applications can be easily ported between various runtime environments. The NaCl build system allows you to target the 3 major system architectures: x86-32 (i686), x86-64, and ARM. When support for new platforms is added, you can simply translate the application to the new architecture without extensive code modification, recompiling, or worrying about compatibility.
Intercompatibility and interoperability with the Google Chrome™ Web browser
Excluding TV-specific features, NaCl applications can run on Samsung Smart TVs and on the Google Chrome™ Web browser.
NaCl Use Cases
NaCl can be used in many ways. It can be used to easily port existing C++ applications to the Web, to support heavy computational tasks and extend Web page functionality, and to create standalone, CPU-intensive Web applications, such as 3D games. You can enhance the Smart TV experience by using NaCl to implement fast, responsive applications with great connectivity possibilities.
The following Smart TV use cases are made possible using NaCl:
Creating 3D games using the OpenGL® library and the audio interface.
Creating and displaying graphics models on a Web page using OpenGL® ES 2.0.
Harnessing the computational power of the device to create embedded emulators.
Performing sound mixing using the audio interface to access sample-level audio control.
Creating a set-top box (STB) experience on the TV itself.
Creating custom media streaming applications using advanced video, audio, and networking features.
Implementing multicast data streaming using UDP sockets.
Using the OpenCV face recognition features with video captured from the Smart TV webcam.
Creating interactive simulations using 3D graphics and input event handling.
Technical Overview
Samsung Smart TVs use a Web engine to render Web pages in the browser and to run TV applications.
The NaCl technology uses the Pepper Plugin API (or PPAPI), which replaces the Netscape Plugin API and enables running Web browser plugins on the Webkit and Blink Web engines. A NaCl module is essentially a Pepper plugin embedded on a Web page, loaded from the host, and executed inside the Web engine sandbox. The PPAPI allows you to exchange information with JavaScript in the Web page, enabling features, such as messaging, event handling, and viewport drawing. The JavaScript component and NaCl module communicate using input events or through a messaging system.
Native code must be compiled before it can be run as a NaCl module. The NaCl toolchain includes compilation tools, such as GCC, Clang, ar, and make, adapted for working with NaCl code.
You can compile a NaCl module in 2 ways:
Compile directly to a ".nexe" file using GCC
This process is similar to compiling normal C or C++ code.
Compile using Clang, a LLVM compiler
Clang compiles the source code to a ".pexe" file, an intermediate bytecode format called Portable Native Client (PNaCl). Google Chrome™ can load the ".pexe" file directly because it supports just-in-time translation, but for Samsung TVs, you must create a ".nexe" file for each architecture you want the module to support.
Using the Clang compiler, you can compile once and simply translate for multiple architectures, including future architectures. You can also use advanced Clang features, such as address, memory, and thread sanitizers.
To load a compiled NaCl module in an application:
The "index.html" file is loaded and parsed.
The Web page is displayed.
For each embed element with the type "application/x-nacl":
The corresponding manifest file is loaded and parsed.
The ".nexe" file coresponding to the system architecture is loaded from the path specified in the manifest file.
The ".nexe" file is statically analyzed for security violations. If no security violations are found, the module is executed in the browser sandbox.
When the NaCl instance is successfully created, the module loaded event is sent to the JavaScript component.
The NaCl plugin is displayed on the Web page in the embed element.
Manage Your Cookies
We use cookies to improve your experience on our website and to show you relevant
advertising. Manage you settings for our cookies below.
Essential Cookies
These cookies are essential as they enable you to move around the website. This
category cannot be disabled.
Company
Domain
Samsung Electronics
.samsungdeveloperconference.com
Analytical/Performance Cookies
These cookies collect information about how you use our website. for example which
pages you visit most often. All information these cookies collect is used to improve
how the website works.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Functionality Cookies
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and
tailor the website to provide enhanced features and content for you.
Company
Domain
LinkedIn
.ads.linkedin.com, .linkedin.com
Advertising Cookies
These cookies gather information about your browser habits. They remember that
you've visited our website and share this information with other organizations such
as advertisers.
Company
Domain
LinkedIn
.linkedin.com
Meta (formerly Facebook)
.samsungdeveloperconference.com
Google Inc.
.samsungdeveloperconference.com
Preferences Submitted
You have successfully updated your cookie preferences.