<h2>jsmpeg SDL Video Driver</h2>

An experimental SDL video driver named <b>jsmpeg</b> is provided since Valentine's Day 2019. It uses the technique described in <a and <a in combination with HTML5 and WebGL in a modern browser to provide display, mouse, and keyboard to a normal [undroidwish].

This means, that the rendering is performed into a memory buffer, which is encoded into a modified MPEG-1 transport stream, sent over a Websocket to a web browser, which performs MPEG-1 decoding and rendering into a HTML5 canvas optionally using WebGL. Likewise, mouse and keyboard events are sent on the same Websocket from the browser back to the <b>jsmpeg</b> driver, transformed to SDL mouse and keyboard events and further processed by the [undroidwish] application.

Frame rate and required bandwidth are moderate. Currently, 25 frames per seconds are sent at most, which require some few hundred kilobits per second. Since April 2019 limited support for OpenGL is available for the Canvas3D and tkZinc widgets. It requires a working EGL/OpenGL infrastructure (Linux etc.) or Windows OpenGL. On Linux this normally requires an X11 display connection except for very recent versions of Mesa and GPU drivers, i.e. on Debian 10 and Fedora 30 the environment variable <b>EGL_DISPLAY</b> can be set to <b>surfaceless</b> in order to turn on headless GPU mode.

For the adventurous, there is a test version for <a x86_64</a> (Debian 9, Fedora 30, CentOS 7), <a 32 bit</a> (XP or newer), <a 64 bit</a> (XP or newer), and <a (tested on High Sierra). All can be run using the <b>jsmpeg</b> video driver when the environment variable <b>SDL_VIDEODRIVER</b> has the value <b>jsmpeg</b> and the required <a DLLs/shared libraries are available on the system, e.g.

<verbatim>
    # POSIX
    export SDL_VIDEODRIVER=jsmpeg
    ./undroidwish-x86_64-deb9 builtin:widget -sdlwidth 800 -sdlheight 600
</verbatim>

<verbatim>
    REM Windows
    SET SDL_VIDEODRIVER=jsmpeg
    undroidwish-win32.exe builtin:widget -sdlwidth 800 -sdlheight 600
</verbatim>


<verbatim>
    # Mac OSX
    export SDL_VIDEODRIVER=jsmpeg
    builtin:widget -sdlwidth 800 -sdlheight 600
</verbatim>


For Windows, the required DLLs are <b>avutil-56.dll</b>, <b>avcodec-58.dll</b>, <b>swresample-3.dll</b>, and <b>swscale-5.dll</b> which are available from <a and preferably loaded from For Linux, the shared libraries are available per installing the distribution's ffmpeg package(s). For MacOSX, the homebrew ffmpeg package provides the necessary shared libraries.

By default, the HTTP/Websockets port is 8080 which can be overridden with the environment variable <b>SDL_VIDEO_JSMPEG_PORT</b>. Thus, the URL

<verbatim>

</verbatim>

connects the browser with the <b>jsmpeg</b> enabled [undroidwish]. If the browser's WebGL implementation isn't suitable for proper displaying the [undroidwish] root window, the alternate URL

<verbatim>

</verbatim>

turns off WebGL usage.

Note that all local TCP/IP addresses are bound, not just localhost.  Thus, if your local TCP/IP address is then will work, and provides access to your app via non-localhost devices.

<h3>HTTP AUTH</h3>

You can optionally password-protect the http port serving your app, by defining the <b>SDL_VIDEO_JSMPEG_AUTH</b> variable like so:

<verbatim>export SDL_VIDEO_JSMPEG_AUTH=$(echo -n user:pass | base64)</verbatim>

This will cause your web browser to require a username/password combination in order to display the page.  For more info about HTTP AUTH see the Wikipedia article <a

<h3>Screen recording</h3>

You can optionally save your entire Tk app's running to a MPEG1 file, by defining the <b>SDL_VIDEO_JSMPEG_OUTFILE</b> like so:

<verbatim>export SDL_VIDEO_JSMPEG_OUTFILE=data.mpg</verbatim>

<h3>HTML Page Title</h3>

The HTML generated to support the jsmpeg driver will automatically use the Tk window manager title to define your web page's web title. Thus, this command in your Tcl/Tk program:

<verbatim>wm title . "Hello World \U1F601"</verbatim>

will result in your web browser titling this page tab as "Hello World &#128513;". Only the application's toplevel window (the "." in Tk parlance) will set the browser
title.

<h3>A note about colors</h3>

Due to RGB->YCbCr->RGB  color conversions taking place when using the <b>jsmpeg</b> driver, the output colors of your app (when viewed in a web browser) are never exactly what they would be in Tk.

For example, white #FFFFFF will render as #FEFEFE.  This difference is very slight.

<nowiki>
<center>
<br><br>
<img
alt="Screenshot widget demo">
<br>Screenshot taken in a GNOME Wayland session<br><br>
</center>
</nowiki>