Difference between revisions of "Hacker Guide/How To Write a Module"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 193: Line 193:
  
 
Depending on the module capability, you will need more information, about the necessary functions to implement.
 
Depending on the module capability, you will need more information, about the necessary functions to implement.
 +
 +
We will detail those here:
 +
* Access
 +
* Demux
 +
* Access_Demux
 +
* Decoder
 +
* Interface
 +
* Video Filter
 +
* Audio Filter
  
 
{{Documentation}}  
 
{{Documentation}}  
  
 
[[Category:Coding]]
 
[[Category:Coding]]

Revision as of 00:46, 2 November 2010

Introduction to modules writer guide

VLC is based on many independent modules, like most multimedia frameworks. Each module introduces a new functionnality.

You MUST read VLC Core and Modules and How VLC loads modules before reading this howto.

This is a description about how you can write a new module for VLC.

Git and Repository integration

Git

If you plan to submit your work to VLC upstream, be sure to look at the git introduction and check the [[Git#Submitting_patches_to_the_vlc-devel_or_x264-devel|send patches part].

Compiling your module

First, find the right place under modules/ to add your new code.

  1. If you are adding a one-file module to the repository, just add its sources to the Modules.am in the same folder.
  2. If you are adding a bigger modules to the repository:
    • create a new directory
    • create a new Modules.am, inside that directory.
    • Add a corresponding Makefile line at the end of configure.ac for this new Modules.am.

To have the module built, you need to use VLC_ADD_PLUGIN or PKG_ENABLE_MODULES_VLC inside the configure.ac with your new module name as argument. Look at other modules for guidelines on how to add build and linkage options.

After changing configure.ac, you will always need to rerun

./bootstrap && ./configure

Loading your module

VLC keeps the cache of its modules (in ~/.cache/vlc/ on Linux), you'll have to delete it (or use vlc --reset-plugins-cache) so that your module gets loaded.

Then use vlc -vvv --color --list to check that your plugin is seen by VLC.

You should also see it in the plugins dialog of the Qt interface (Linux and Windows).

Example of an empty module

We will start with a small example, so you can understand it better.

/*****************************************************************************
 * Preamble
 *****************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <vlc_common.h>
#include <vlc_plugin.h>

/*****************************************************************************
* Local prototypes.
*****************************************************************************/

static int  Open           ( vlc_object_t * );
static void Close          ( vlc_object_t * );

/*****************************************************************************
 * Module descriptor
 *****************************************************************************/

vlc_module_begin()
    set_shortname( _("testmodule") )
    set_description( _("testmodle plug-in") )
    set_capability( "testing", 0 )
    set_callbacks( Open, Close )
    set_category( CAT_INTERFACE ) /* choose relevant category, default categories in vlc/include/vlc_configuration.h */

    add_integer( "test-angle", 1, "DVD Angle", "Default DVD Angle", false)
vlc_module_end ()


/*****************************************************************************
 * Open: initialize interface
 *****************************************************************************/
static int Open( vlc_object_t *p_this )
{
}

/*****************************************************************************
 * Close: destroy interface
 *****************************************************************************/
static void Close( vlc_object_t *p_this )
{
}

How to write the module, aka Explanations about the empty module

Module Descriptor

A VLC media player module must include a description of itself, and the parameters it accepts.

The module descriptor begins with:

vlc_module_begin();

You should set some basic information about your module:

    set_shortname( _("DVD without menus") );
    set_description( _("DVDRead Input") );
    set_category( CAT_INPUT );
    set_subcategory( SUBCAT_INPUT_ACCESS );

Note the use of _("") to create a string that needs to be translated.

Capability

The capability is key to the module loading.

It defines the type of module we are dealing with, whether it is an access, a demux, a decoder or else...

Now is the time to re-read how VLC loads modules.


  • If VLC needs to load a specific name, it will load it by its name and VLC directly opens this module
  • If VLC needs a type of modules ("I need a decoder"), VLC will load all modules matching this capability by decreasing score order until one Open() function (see later) returns VLC_SUCCESS.

See the major types of capabilities of VLC.


Definition Example:

   set_capability( "testing", 10 )

This defines a module of "testing" capability and a score of 10

Configuration Categories and SubCategories

You should use one of the predefined categories for configuration.

The Configuration Categories and Subcategories define where the module will appear in the preferences.

The configuration categories include:

  • CAT_INTERFACE
  • CAT_AUDIO
  • CAT_VIDEO
  • CAT_INPUT
  • CAT_SOUT
  • CAT_ADVANCED
  • CAT_PLAYLIST

You should use one of predefined sub-categories too.

See include/vlc_configuration.h for definition of all configuration categories and sub-categories.

Configuration and Parameters Options

You will need options for your module. Defining new options is easy.

All options definitions take the following argument list:

 add_integer(name, value, text, longtext, advanced) 
  • name is the string that identifies this parameter in the configuration. This name is used at the command prompt to set the configuration value.
  • value is the default value for this parameter,
  • text A short description of the parameter,
  • longtext A complete description of the parameter,
  • advanced Boolean, ADVanced Configuration. If TRUE, this parameter will only be displayed when using the --advanced flag. e.g.


You may add the following options/parameter types to your module:

  • add_integer,
  • add_string,
  • add_float,
  • add_bool,
  • add_key,
  • add_file,
  • add_directory,

For complete definitions, see include/vlc_plugin.h

Callback

The opening and closing static functions, detailed afterwards, need to be defined in the descriptor, so VLC can discuss with the module.

Open(vlc_object_t *)

The most important function of a module, is the opening: the usually-named Open() function.

static int  Open ( vlc_object_t * );

The Open() function is called when the VLC core tries to open the module, and wants to load it.

During Open(), setup of structures, devices or I/O, checks should be done. A working open should return VLC_SUCCESS. In all other cases, it will not be considered as loaded.

If the Opening fails, you need to clean-up your own structures.

Close(vlc_object_t *)

The second most important function of a module, is the closing: the usually-named Close() function.

static int  Close ( vlc_object_t * );

The Close() function is called when the VLC core tries to close or unload an already-loaded module.

If the Open() function failed, Close() will not get called.

During Close(), close devices or I/O and cleaning of structures should be done. Do not leak memory here!


Modules types

Depending on the module capability, you will need more information, about the necessary functions to implement.

We will detail those here:

  • Access
  • Demux
  • Access_Demux
  • Decoder
  • Interface
  • Video Filter
  • Audio Filter
This page is part of official VLC media player Documentation (User GuideStreaming HowToHacker GuideModules)
Please read the Documentation Editing Guidelines before you edit the documentation
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.