Intro

Warning: The information on this page is not up-to-date, contact Diego or Arno for current info. Up-to-date info on how to use the plugin can be found in P2P-Next's D6.5.3 deliverable. It also explains how to build the plugin from scratch (note: described configure flags wrong, see p2pnext-win32-setup-from-co.sh).

The SwarmPlayer Browser plug-in (SwarmPlugin) is a media player plug-in for Internet Explorer (Firefox and Safari in the next future) based on the VLC plug-in. The SwarmPlugin incorporates P2P technology (from now on P2P Core or Core) developed by TUDelft University, Vrije Universiteit, and others. The advantages of integrating P2P networks and VideoOnDemand (from now on VOD) should be known and are not going to be discussed here. This document presents the architecture from a general and an in depth point of view. Since the current status of the Plug-in is under development, I'll give some attention on how to reproduce a building and installation environment.

The classid in this example is incorrect. It should be clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921

Architecture

Overview

As it's possible to see from the following picture, the general architecture is composed by two main components:

  • The Background Process (from now on BG Process or BG)
  • The Plug-in its-self

The BG Process is intended to provide P2P download and streaming functionalities to the Plug-in while the Plug-in is responsible for handling the playback and the user interaction. It's easy to understand that the architecture has been modeled as a client/server architecture where the Plug-in is the client and the BG is the server.

Plug-in / BG Process interaction

The BG and the Plug-in communicate through two main channels:

  • A TCP channel for commands
  • A HTTP channel for video steaming

The TCP connection is used by the plug-in to send requests to the BG, and by the BG Process to send commands to the Plug-in. The communication protocol is really basic:

Plug-in requests:

BG Process commands:

  • "PLAY stream_source"
    es: "PLAY http://127.0.0.1:1678"
    This command tells to the Plug-in that the requested video is available on the specified stream_source.
  • "PAUSE"
    This command tells to the Plug-in that the connection speed has decreased and the P2P core needs some time for buffering.
  • "RESUME"
    The buffer is full and the connection speed is good enough to start again the playback previously paused.
  • "SHUTDOWN"
    Acknowledge the Plug-in that the shutdown request has been received and performed.
  • "INFO info_string"
    es: "INFO Buffering 10%"
    This commands tells to the Plug-in that there's a string to display in the playback region handled by Vlc.

Here is shown an interaction scheme between Plug-in / BG / P2P Core:

The Background Process

Overview

The BG Process is a Windows executable (.exe) build up from python sources. As already said it's basically a server providing VOD (and P2P) features. The plug-in must be able to launch the BG Process in the case the BG is not up yet. After the BG has been launched by the first plug-in instance, it should keep serving in background until a manual shutdown is performed (through the Systray Icon). The reason to keep the BG alive is of course to guarantee seeding time after service (video streaming) consumption. Through the systray icon it's possible to interact with the BG Process, setting the upload rate limit, monitoring the current download status and speed and requesting the BG to shutdown. An alternative could be to provide interactivity/monitoring features to the BG Process through a web interface.

The Plug-in

Overview

The Plug-in is an ActiveX control based on the VLC Internet Explorer plug-in (vlc-0.9.5). When the browser renders the web page and an <object> tag is found in the html code, the browser loads the plug-in associated to the "classid" parameter of that tag. In our case the "classid" is "E23FE9C6-778E-49D4-B537-38FCDE4887D8". Further studies are needed to understand how to generate and register a new CLASSID to be associated to the SwarmPlugin (since the current one is associated to the VLC plug-in)

As soon as the Plug-in is loaded in the browser, a connection with the BG Process is established and the communication between the two components starts. If the Plug-in can not connect to the BG Process, it tries to launch a new BG instance and to connect again. At this point the connection is established and the session between Plug-in and BG starts.

As already said the communication protocol between the two components consists on requests (from Plug-in to BG) and commands (from BG to Plug-in). This mechanism is asynchronous, this means that after the Plug-in sends a request, commands can be received anytime.

The interaction between the user and the Plug-in is identical to the Vlc plug-in. For details refer to the Vlc documentation:
http://git.videolan.org/?p=vlc.git;a=blob;f=projects/activex/README.TXT
http://wiki.videolan.org/ActiveX

Sources

The starting point of the Plug-in development is vlc-0.9.5. The source code of the VLC package contains a 'projects/activex' directory where the code for building the 'axvlc.dll' is stored. This library is the plug-in its self and is the one that is loaded into the browser.

The ActiveX control is composed by several files implementing different features of an activex control. The 'main' files are plugin.h, plugin.cpp. These are the only 2 files patched to let the plug-in communicate with the BG Process. The patch consist in adding a TriblerControl object to the VLCPlugin class. We are going to see what does this means by giving an overview of the few classes involved:

  • VLCPlugin This class implements the IUnknown interface of the ActiveX control. The VLCPlugin is responsible for handling the region of the web page where the VLC instance is going to draw the video playback. This class has been extended by adding a TriblerControl and some callback functions to provide the plug-in with P2P features.
  • TriblerControl This class handles the communication protocol with the BG. Through this class is possible to add VOD P2P functionality to any software. It's important to introduce two concepts to understand the functionalities of the TriblerControl:
    EventCBMap: this is a multimap containing the association between the command received from the BG and the callback function to perform.
    EventThread: this thread provides an asynchronous mechanism to the communication protocol between Plug-in and BG. As soon as a command is received, the EventThread looks in the EventCBMap and it performs the action associated to the received command (see architecture picture).

The Environment

SVN repository

SwarmPlugin
The source code of the VLC patched version can be found here. You can find:

  • vlc-0.9.5/ : patched version of VLC (the plug-in sources are under vlc-0.9.5/projects/activex)
  • vlc-0.9.5_swarm_plugin.patch : patch file to build the SwarmPlugin out of the original VLC plug-in
  • vlc_win32_setup.sh : script to create the building environment for compiling the SwarmPlugin (not completely stable)

The precompiled binaries can be found in here.

Background Process
The source file of the BG Process is this one.

Runtime environment

The runtime environment is not completely defined yet. It's reasonable to think that the installation path will be something like C:Program FilesSwarmPlugin

it will contain the BGProcess executable and libraries, the Plug-in (axvlc.dll) and the Vlc libraries. One registry entry will be needed:
HKEY_LOCAL_MACHINESoftwareSwarmPlugin
BGProcessPath=C:Path oBG

this item will contain the path through which the Plug-in can find the BGProcess and run it.

How to build

Background Process

To build the BG Process you have to check out the svn repository:
svn co http://svn.tribler.org/abc/branches/mainbranch/

go in the mainbranch directory just created and run on the console:
python TriblerPluginBuildWin32setupBGexe.py py2exe

this requires you to have python and the py2exe extension installed. Once done, you can find the dist directory containing the BG Process executable and libraries.

Plug-in

As already mentioned, the Plug-in is a patched version of the VLC (0.9.5) plug-in. VLC is software native for Linux, so to build up a Windows version you'll have to cross-compile from Linux to Windows with the Mingw compiler (for example) or alternatively use a Cygwin environment.

To compile the SwarmPlugin you have to compile the whole VLC source tree.
svn co http://svn.tribler.org/vlc/branches/vlc-0.9.5-win32-swarmplugin-diego-feb2009/
You can find the sources under vlc-0.9.5-win32-swarmplugin-diego-feb2009/vlc-0.9.5. Compile it as you would compile VLC. For details on how to build VLC please refer to the VLC documentation on How to build VLC for Windows.

Since this task may be tricky we provide a script for creating a building environment, patching VLC and compile the SwarmPlugin. As already stated the script is vlc_win32_setup.sh and the patch file is vlc-0.9.5_swarm_plugin.patch. Create a new directory, place these files in it, run the vlc_win32_setup.sh and follow the instructions.

Important: this procedure hasn't been tested on a clean environment, you may find problems during the configuration phase.

How to install

We provide you with a binary package. This package contains a vlc.win32.nsi NSIS script to build an autoinstaller. Create your autoinstaller and run it. Remember to check the activex plugin as component to install and change the destination directory to C:Program FilesSwarmPlugin (preferably). Place the BG Process you built with the "dist" directory (read "How to build" section) preferably under C:Program FilesSwarmPluginBGProcess . Then create a Windows registry (with regedit) under HKEY_LOCAL_MACHINESoftwareSwarmPlugin with BGProcessPath as key and the path where you copied the BG Process as value. Example:
[HKEY_LOCAL_MACHINESoftwareSwarmPlugin] BGProcessPath="C:Program FilesSwarmPluginBGProcessBackgroundProcess.exe" .

Now you can try to open this page with Internet Explorer.

An Interesting Framework

As it's possible to understand from the architecture description of the Plug-in, the TriblerControl combined with the BG offers a simple interface to the P2P core. Such framework would allow developers to implement their own VOD software based on torrent/P2P technology in a really simple way. Apart from the SwarmPlugin, other possible uses could be:

  • A stand alone swarmplayer
  • A Windows sidebar VOD widget
  • P2P LIMO widgets
  • ...

To implement such a feature you just have to include the TriblerControl in your software in this way:

/* Initialize TriblerControl */

TriblerControl * triblerControl = new TriblerControl();

triblerControl->startup();

/* Register callback functions */

triblerControl->regEventCB< MyClass >( EV_PLAY, &myClassObj, &MyClass::onPlayCmd );

triblerControl->regEventCB( EV_PAUSE,  &myStaticFunction );

register your callbacks for every event you want to handle:

  • EV_PLAY
  • EV_PAUSE
  • EV_RESUME
  • EV_STOP
  • EV_INFO

Todo and open issues (current status)

  • Perform building environment and building procedure.
  • Create an installation script.
  • Extend Systray icon interface and functionality.

Web content download accelerator

The idea is to merge normal HTTP downloading with P2P. The first time a user completes a normal HTTP download, he creates a torrent out of it and notifies the tracker. When the second user downloads the same resource through HTTP, a P2P plug-in integrated in the web browser starts to look for other peers sharing the same content. At this point the resource is going to be downloaded both through HTTP and BitTorrent. A service gives the root-hash of the torrent providing a security hash-checking mechanism (see MerkleHashes for more details).

Attachments