DiamondLovesYou / vlc-nacl

Port of VLC to PNaCl/NaCl. Mirror of
https://code.videolan.org/videolan/vlc-nacl
4 stars 3 forks source link

(P)NaCl

This project provides additional modules needed to use VLC from within a NaCl or PNaCl module. With this project, built for PNaCl, VLC is able to play media within arbitrary websites (ie doesn't require use of a Chrome Store app).

The Build

Building on Windows will likely be impossible without use of MSYS. The author uses Linux, and while an effort by the author was taken to ensure the most platform independent instructions, the reader's mileage my vary if their platform is not Linux. Fortunately, Linux is free and so is VirtualBox (and PNaCl is platform/arch independent by design).

Prerequisites

Before we can get started, we need to procure a few things from the Internet:

Build!

$ ./configure && ./compile --arch $ARCH --pepper-root $NACL_SDK_ROOT --webports-root $WEBPORTS_ROOT

Where $ARCH is one of le32, i686, x86_64, or arm, $NACL_SDK_ROOT points to your Pepper SDK root, and $WEBPORTS_ROOT points to the root of your webports checkout. compile will fetch and build the needed webports packages for you.

If you're developing this port, please also pass --enable-tests to ./compile (one has to be on Linux for this currently).

Embedding VLC

<script async>
    var getVlc = null;
    var restartVlc = null;
    (function() {
        "use strict";

        var embed = null;
        var parent = document.getElementById('video');

        restartVlc = function() {
            if(embed != null) {
                parent.removeChild(embed);
            }

            embed = document.createElement('embed');
            embed.setAttribute('id', 'vlc');
            embed.setAttribute('src', 'vlc-debug.nmf');
            embed.setAttribute('type', 'application/x-nacl');
            // Comment out the following two lines if debugging VLC
            embed.setAttribute('src', 'vlc-release.nmf');
            embed.setAttribute('type', 'application/x-pnacl');
            embed.setAttribute('width', '100%');
            embed.setAttribute('height', '100%');

            embed.addEventListener('load', function() {
                var instance = new VlcInstance(embed);
                getVlc = function() {
                    return instance;
                };
            });
            parent.appendChild(embed);
       };
       restartVlc();
   })();
</script>

Place the above after the #video element. It will create a single VLC instance. Call restartVlc() to restart the instance. getVlc() will return the instance object. Info on the API present is documented below.

Additionally, extra/ppapi-control.js should be included in the <head> of the HTML document. ppapi-control.js is internally versioned (ie all messages sent to VLC specify which API version to use), so it is safe to copy where ever needed.

Consult the nmf documentation for info on how to create vlc-debug.nmf and vlc-release.nmf.

Using the Javascript API

Using getVlc() from above (all of these are static, in the C++ class sense):

Note: getVlc().this_is_a_method() && getVlc().this_is_a_property. All methods accept a callback parameter as the last argument. The callback will be called asynchronously with the results. Status codes mimic HTTP status codes, ie a return_code with a value of 200 indicates success. If no callback is provided, any and all errors will be ignored with a warning printed to the devtools console.

There is a limited selection of event one can listen for on the playlist and input objects. Add a callback listener by calling addEventListener(loc, callback) and remove it with removeEventCallback(loc, callback) on the object.

playlist events (new values are in the new_value key, old in old_value):

input events (new values are in the value key):

Example: getVlc().input.addEventListener('position', function(event) { console.log(event); }

This JS API is fully versioned, so the included ppapi-control.js can be copied into your projects source control and updated only when desired.

Take a look at ppapi-control.js in extras/ppapi-control.js for more info.

Issues