Tizen WASM Video Decoder Sample
This section describes the Tizen WASM Video Decoder sample application and how to use it.
Related Info
Samples
The Tizen WASM Video Decoder sample application shows how to use Tizen WASM Video Decoder to play media on a Samsung device using a WebAssembly module.
This application is an extension to the Tizen WASM Player Sample Application. It illustrates how to extend an existing WASM Player application to achieve decoding video frames to GL texture functionality.
The emss_sdf_sample.h
and emss_sdf_sample.cc
files have been copied from the wasm_player_sample
application and are used only to manage playback in media player.
Video Decoder logic is located in the video_decoder_sdf_sample.h
and video_decoder_sdf_sample.cc
files.
The sample application's features are:
- Elementary media stream playback using
HTMLMediaElement
with anElementaryMediaStreamSource
data source andkVideoTexture
rendering mode - Implementation of Seeking and Multitasking
Packetized data is hardcoded in the application to maximize data access simplicity.
Building the Sample With Tizen Studio
This section covers how to build the sample widget in Tizen Studio, including prerequisites and a step by step guide to the build process.
Prerequisites
To build the sample application, you need the following:
- Sample WASM Player Application source code which can be cloned from the repository on GitHub.
- Samsung Emscripten SDK and Tizen Studio. Follow the Setting Up Samsung Emscripten SDK guide to learn more about their installation and setup.
Building the Application
To build the sample application:
- Launch Tizen Studio.
- Create a new WebAssembly-enabled project in Tizen Studio:
- Select "File > New > Tizen Project".
- Select "Template" and click "Next".
- Select "TV" and click "Next".
- Select "Web Application," check the "WebAssembly (C/C++)" checkbox, and click "Next".
- Select the "Empty" application template and click "Next".
- Name the project
VideoDecoderSample
and click "Next". - Enter the directory paths to the Samsung Emscripten SDK configuration file and cache directory.NoteFor details on Emscripten configuration in Tizen Studio, see Configuring the Samsung Emscripten SDK.
- Click "Finish".
- Add a new WebAssembly module to the project:
- Right click on the project in "Project Explorer".
- Click "New > WebAssembly Module" in the context menu.
- Select "Empty module" and click "Next".
- Name the module
VideoDecoderSampleModule
(the name is important, as this is the name used to load the module). - Click "Finish".
- Replace the default HTML5 and C++ files generated by Tizen Studio with the files from this sample:
- Remove generated HTML5 and C++ files:
VideoDecoderSample/index.html
VideoDecoderSample/main.js
VideoDecoderSample/css/style.css
VideoDecoderSampleModule/inc/empty.hpp
VideoDecoderSampleModule/src/empty.cpp
- Copy the sample widget's files to the project in Tizen Studio:
elementary_media_stream_source_sample/widget/*
->VideoDecoderSample/
elementary_media_stream_source_sample/src/*
->VideoDecoderSampleModule/
- Remove generated HTML5 and C++ files:
- Add the necessary compiler and linker flags to the WebAssembly module:
- Right-click the
VideoDecoderSampleModule
project in "Project Explorer". - Select "Properties" from the context menu.
- Select "C/C++ Build > Settings".
- On the "Tool Settings" tab:
- Select "Emscripten C++ Compiler > Miscellaneous" and edit the "Other flags" field, changing
-std=gnu++11
to-std=gnu++14
. - Select "EEmscripten C++ Linker > Miscellaneous" and make the following changes to the "Linker flags" field:
- Append the following flags:
-s ENVIRONMENT_MAY_BE_TIZEN -pthread -s USE_PTHREADS=1 -s PTHREAD_POOL_SIZE=1
NoteThese flags are explained below, in the Required Samsung Emscripten SDK Flags section. - Remove
-s EXPORT_NAME=EMSSSampleModule -s MODULARIZE=1
.NoteThis step is required, because code loading for modularized and non-modularized WebAssembly modules differs slightly. The EMSS Sample application is prepared to load modules that do not use theMODULARIZE
option.
- Append the following flags:
- Select "Emscripten C++ Compiler > Miscellaneous" and edit the "Other flags" field, changing
- click "Apply and Close".
- Right-click the
- Build the project:
- Right-click the
VideoDecoderSampleModule
project in "Project Explorer". - Click "Build Project" in the context menu.
- Right-click the
- Create an application package:
- Right-click the
VideoDecoderSampleModule
project in "Project Explorer". - Click "Build Signed Package" in the context menu.
- Right-click the
The application is ready to use!
Required Samsung Emscripten SDK Flags
The table below explains Emscripten-specific build flags required to build this sample:
Flag | Description |
---|---|
-s ENVIRONMENT_MAY_BE_TIZEN |
Enables usage of Samsung Emscripten SDK extensions available on Tizen devices. This flag is required to use Elementary Media Stream Source. |
-pthread -s USE_PTHREADS=1
|
Enables usage of threads in WebAssembly module. |
-s PTHREAD_POOL_SIZE=1
|
Prepares the WebAssembly module to start the indicated number of threads. It is important to set this parameter to the maximum number of threads that an application uses; otherwise starting new threads can fail. For more information, see pthreads in the Emscripten documentation. |
Table 1. Required Samsung Emscripten SDK Flags