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

From VideoLAN Wiki
Jump to navigation Jump to search
Line 1: Line 1:
* This guide is being written by a {{VLC}} novice.  Please check all statements below.
+
*Using [http://trac.videolan.org/vlc/browser/trunk/modules/access/dvdread.c dvdread.c] as the template.
* Using [http://trac.videolan.org/vlc/browser/trunk/modules/access/dvdread.c dvdread.c] as the template.
 
  
 +
== How to write a module  ==
  
== Module Descriptor ==
+
VLC is based on many independent modules.
  
A {{VLC}} Module must include a description of itself, and the parameters it accepts.
+
This is a description about how you can write a new module for VLC.  
 +
<pre>How to add a module
 +
-------------------
  
The module descriptor begins with:
+
To add a module to the repository, just add its sources to a Modules.am
<pre>
+
file. If you add a new directory you will need to create a new Modules.am,
vlc_module_begin();
+
inside that directory. Do not forget to add a corresponding
</pre>
+
Makefile line at the end of configure.ac for this new Modules.am file.
  
You should set some category information on your module:
+
To have the module built, you need to add a call to VLC_ADD_PLUGIN or
<pre>
+
VLC_ADD_BUILTINS to configure.ac with your new module name as argument.
    set_shortname( _("DVD without menus") );
+
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 and
 +
configure.
 +
 
 +
VLC keeps a cache of its modules (in ~/.cache/vlc/ on Linux), so you'll have to
 +
delete it (or use vlc --reset-plugins-cache). Then use vlc -vvv --color --list
 +
to check that your plugin is seen by VLC.
 +
 
 +
</pre><pre>
 +
/*****************************************************************************
 +
* Preamble
 +
*****************************************************************************/
 +
 
 +
#ifdef HAVE_CONFIG_H
 +
# include "config.h"
 +
#endif
 +
 
 +
#include &lt;vlc_common.h&gt;
 +
#include &lt;vlc_plugin.h&gt;
 +
 
 +
/*****************************************************************************
 +
* 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 */
 +
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 )
 +
{
 +
   
 +
}</pre>
 +
== Module Descriptor  ==
 +
 
 +
A {{VLC}} Module must include a description of itself, and the parameters it accepts.
 +
 
 +
The module descriptor begins with:
 +
<pre>vlc_module_begin();
 +
</pre>
 +
You should set some category information on your module:  
 +
<pre>   set_shortname( _("DVD without menus") );
 
     set_description( _("DVDRead Input (DVD without menu support)") );
 
     set_description( _("DVDRead Input (DVD without menu support)") );
 
     set_category( CAT_INPUT );
 
     set_category( CAT_INPUT );
</pre>
+
</pre>  
Note the use of _("") to create a string that needs to be translated.
+
Note the use of _("") to create a string that needs to be translated.  
  
Predefined Categories include:
+
Predefined Categories include:  
* CAT_INTERFACE
 
* CAT_AUDIO
 
* CAT_VIDEO
 
* CAT_INPUT
 
* CAT_SOUT
 
* CAT_ADVANCED
 
* CAT_PLAYLIST
 
  
<pre>
+
*CAT_INTERFACE
    set_subcategory( SUBCAT_INPUT_ACCESS );
+
*CAT_AUDIO
</pre>
+
*CAT_VIDEO
See [http://trac.videolan.org/vlc/browser/include/vlc_configuration.h include/vlc_configuration.h]  
+
*CAT_INPUT
for definition of all categories and sub-categories.
+
*CAT_SOUT
 +
*CAT_ADVANCED
 +
*CAT_PLAYLIST
 +
<pre>   set_subcategory( SUBCAT_INPUT_ACCESS );
 +
</pre>  
 +
See [http://trac.videolan.org/vlc/browser/include/vlc_configuration.h include/vlc_configuration.h] for definition of all categories and sub-categories.  
  
=== Adding Parameters ===
+
=== Adding Parameters ===
All macros take the following argument list:
 
<pre> add_integer(name, value, p_callback, text, longtext, advc) </pre>
 
* '''name''' is the string that identifies this parameter in the configuration.  This name may be used at the command prompt to set the configuration value.
 
* '''value''' is the default value for this parameter,
 
* '''p_callback''' is a function pointer that will be called when the value of this parameter is changed.
 
** p_callback is called with the following arguments:  <pre>( p_this, psz_name, oldval, val, p_config->p_callback_data )</pre>
 
*** '''p_this''' is a pointer to a vlc_object_t struct,
 
*** '''psz_name''' is the '''name''' of your parameter that is being changed,
 
*** '''oldval''' is the old value of the parameter,
 
*** '''val''' is the new value of the parameter,
 
*** '''p_call_back_data''' is void* data that you can assign for each parameter.  Usually NULL.
 
* '''text''' A short description of the parameter,
 
* '''longtext''' A complete description of the parameter,
 
* '''advc''' Boolean, ADVanced Configuration.  If TRUE, this parameter will only be displayed when using the --advanced flag. e.g.
 
<pre>vlc -p dvdread --advanced</pre>
 
  
e.g.
+
All macros take the following argument list:
<pre> add_integer("dvdread-angle", 1, NULL, "DVD Angle", "Default DVD Angle", NULL") </pre>
+
<pre> add_integer(name, value, p_callback, text, longtext, advc) </pre>
 +
*'''name''' is the string that identifies this parameter in the configuration. This name may be used at the command prompt to set the configuration value.
 +
*'''value''' is the default value for this parameter,
 +
*'''p_callback''' is a function pointer that will be called when the value of this parameter is changed.
 +
**p_callback is called with the following arguments: <pre>( p_this, psz_name, oldval, val, p_config-&gt;p_callback_data )</pre>
 +
***'''p_this''' is a pointer to a vlc_object_t struct,
 +
***'''psz_name''' is the '''name''' of your parameter that is being changed,
 +
***'''oldval''' is the old value of the parameter,
 +
***'''val''' is the new value of the parameter,
 +
***'''p_call_back_data''' is void* data that you can assign for each parameter. Usually NULL.
 +
*'''text''' A short description of the parameter,
 +
*'''longtext''' A complete description of the parameter,
 +
*'''advc''' Boolean, ADVanced Configuration. If TRUE, this parameter will only be displayed when using the --advanced flag. e.g.
 +
<pre>vlc -p dvdread --advanced</pre>
 +
e.g.  
 +
<pre> add_integer("dvdread-angle", 1, NULL, "DVD Angle", "Default DVD Angle", NULL") </pre>  
 +
You may add the following parameters to your module:
  
You may add the following parameters to your module:
+
*add_integer,  
* add_integer,
+
*add_string,  
* add_string,
+
*add_float,  
* add_float,
+
*add_bool,  
* add_bool,
+
*add_key,  
* add_key,
+
*add_file,  
* add_file,
+
*add_directory,
* add_directory,
 
  
For complete definitions, see [http://trac.videolan.org/vlc/browser/include/vlc_configuration.h include/vlc_configuration.h]
+
For complete definitions, see [http://trac.videolan.org/vlc/browser/include/vlc_configuration.h include/vlc_configuration.h]  
  
== Open(vlc_object_t *) ==
+
== Open(vlc_object_t *) ==
  
== Close(vlc_object_t *) ==
+
== Close(vlc_object_t *) ==
  
 
[[Category:Coding]]
 
[[Category:Coding]]

Revision as of 15:51, 28 August 2009

How to write a module

VLC is based on many independent modules.

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

How to add a module
-------------------

To add a module to the repository, just add its sources to a Modules.am
file. If you add a new directory you will need to create a new Modules.am,
inside that directory. Do not forget to add a corresponding
Makefile line at the end of configure.ac for this new Modules.am file.

To have the module built, you need to add a call to VLC_ADD_PLUGIN or
VLC_ADD_BUILTINS to 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 and 
configure.

VLC keeps a cache of its modules (in ~/.cache/vlc/ on Linux), so you'll have to
delete it (or use vlc --reset-plugins-cache). Then use vlc -vvv --color --list
to check that your plugin is seen by VLC.

/*****************************************************************************

* Preamble
*****************************************************************************/
  1. ifdef HAVE_CONFIG_H
  2. include "config.h"
  3. endif
  1. include <vlc_common.h>
  2. 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 */

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 ) {

}

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 category information on your module:

    set_shortname( _("DVD without menus") );
    set_description( _("DVDRead Input (DVD without menu support)") );
    set_category( CAT_INPUT );

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

Predefined Categories include:

  • CAT_INTERFACE
  • CAT_AUDIO
  • CAT_VIDEO
  • CAT_INPUT
  • CAT_SOUT
  • CAT_ADVANCED
  • CAT_PLAYLIST
    set_subcategory( SUBCAT_INPUT_ACCESS );

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

Adding Parameters

All macros take the following argument list:

 add_integer(name, value, p_callback, text, longtext, advc) 
  • name is the string that identifies this parameter in the configuration. This name may be used at the command prompt to set the configuration value.
  • value is the default value for this parameter,
  • p_callback is a function pointer that will be called when the value of this parameter is changed.
    • p_callback is called with the following arguments:
      ( p_this, psz_name, oldval, val, p_config->p_callback_data )
      • p_this is a pointer to a vlc_object_t struct,
      • psz_name is the name of your parameter that is being changed,
      • oldval is the old value of the parameter,
      • val is the new value of the parameter,
      • p_call_back_data is void* data that you can assign for each parameter. Usually NULL.
  • text A short description of the parameter,
  • longtext A complete description of the parameter,
  • advc Boolean, ADVanced Configuration. If TRUE, this parameter will only be displayed when using the --advanced flag. e.g.
vlc -p dvdread --advanced

e.g.

 add_integer("dvdread-angle", 1, NULL, "DVD Angle", "Default DVD Angle", NULL") 

You may add the following parameters to your module:

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

For complete definitions, see include/vlc_configuration.h

Open(vlc_object_t *)

Close(vlc_object_t *)