This section provides an extension to WASM Player Usage Guide article with RenderingMode::kVideoTexture of ElementaryMediaStreamSource. It presents how to extend existing WASM Player application with Video Decoder functionalities using Tizen WASM Video Decoder Sample.
The aim of this article is to present how to modify existing WASM Player application to use RenderingMode::kVideoTexture functionality of ElementaryMediaStreamSource.
This mode allows the application to fill requested GL texture with decoded frame, instead of rendering it on a HTMLMediaElement.
WASM Player -> WASM Video Decoder steps
Setting Video Texture rendering mode for WASM Player
To change ElementaryMediaStreamSource rendering mode from Media Element to Video Texture RenderingMode::kMediaElement should be replaced by RenderingMode::kVideoTexture:
using LatencyMode = samsung::wasm::ElementaryMediaStreamSource::LatencyMode;
using RenderingMode = samsung::wasm::ElementaryMediaStreamSource::RenderingMode;
auto elementary_media_stream_source = std::make_unique<samsung::wasm::ElementaryMediaStreamSource>(LatencyMode::kNormal, RenderingMode::kVideoTexture);
GL context in Emscripten
Make canvas accessible from Emscripten
GL context in WASM is associated with a canvas HTML element. To make it possible for WASM to use it, the following steps need to be applied:
Create a canvas element in the application's HTML file that runs WASM module:
Please note that EGL provided by emscripten does not support setting GL major version, so it is not possible to use GLES 3.0 using EGL wrapper.
Registering GL context for WASM Video Decoder
Inform ElementaryMediaTrack about current graphics context:
video_track_.RegisterCurrentGraphicsContext();
Video Decoder rendering loop
Requesting video texture fill
The decoding loop that fills the texture with a decoded video frame can be started after OnTrackOpen event is received or when HTMLMediaElement::Play callback is called.
When the texture is filled with the video frame, drawing should be performed:
void VideoDecoderTrackDataPump::RequestNewVideoTexture() {
video_track_.FillTextureWithNextFrame(
texture_, [this](samsung::wasm::OperationResult result) {
if (result != samsung::wasm::OperationResult::kSuccess) {
std::cout << "Filling texture with next frame failed" << std::endl;
return;
}
Draw();
});
}
Drawing
Like in any C++ application, we need to provide a rendering loop.
In WASM Video Decoder application, we achieve it by providing the following cycle:
Define a global callback function for emscripten_request_animation_frame:
int CAPIOnDrawTextureCompleted(double /* time */, void* thiz) {
if (thiz)
static_cast<VideoDecoderTrackDataPump*>(thiz)->OnDrawCompleted();
return 0;
}
Recycling video picture
It is important to always recycle video picture after it has been drawn.
To do so, we need to call RecycleTexture method in emscripten_request_animation_frame callback:
To properly end a rendering loop when rendering should be stopped, the application should always handle ElementaryMediaTrack::FillTextureWithNextFrame errors - eg. OperationResult::kAlreadyDestroyed when a track
was stopped before calling this method or OperationResult::kAborted when a track was stopped after calling this method.
Before invalidating the pointer that has already been provided to the emscripten_request_animation_frame callback, you should abort that callback with the emscripten_cancel_animation_frame by providing a callback id returned by the emscripten_request_animation_frame method.
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.