Difference between revisions of "Hacker Guide/Interfaces"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 37: Line 37:
 
VLC uses GNU getopt to parse command line options. getopt structures are defined in src/extras/getopt.c and command line parsing is done in src/config/cmdline.c
 
VLC uses GNU getopt to parse command line options. getopt structures are defined in src/extras/getopt.c and command line parsing is done in src/config/cmdline.c
  
<!-- Most configuration directives are exchanged via the environment array, using main_Put*Variable and main_Get*Variable. As a result, ./vlc --height 240 is strictly equivalent to : vlc_height=240 ./vlc. That way configuration variables are available everywhere, including plugins.
+
Most configuration directives are exchanged via the environment array, using main_Put*Variable and main_Get*Variable. As a result, ./vlc --height 240 is strictly equivalent to : vlc_height=240 ./vlc. That way configuration variables are available everywhere, including plugins.
  
 
===Warning===
 
===Warning===
  
Please note that for thread-safety issues, you should not use main_Put*Variable once the second thread has been spawned --!>
+
Please note that for thread-safety issues, you should not use main_Put*Variable once the second thread has been spawned
  
 
==Playlist management==
 
==Playlist management==
  
The playlist is created on startup from files given in the command line. An appropriate interface plugin can then add or remove files from it. Functions to be used are described in src/interface/intf_playlist.c. intf_PlaylistAdd and intf_PlaylistDelete are typically the most common used.
+
The playlist is created on startup from files given in the command line. An appropriate interface plugin can then add or remove files from it. Functions to be used are described in src/playlist/control.c.
 
 
The main interface loop intf_Manage is then supposed to start and kill input threads when necessary.
 

Revision as of 23:33, 20 April 2008

VLC Interface

A typical VLC run course

This section describes what happens when you launch the vlc program. After the ELF dynamic loader blah blah blah, the main thread becomes the interface thread. It passes through the following steps :

  1. CPU detection : which CPU are we running on, what are its capabilities (MMX, MMXEXT, 3DNow, AltiVec...) ?
  2. Message interface initialization ;
  3. Command line options parsing ;
  4. Playlist creation ;
  5. Module bank initialization ;
  6. Interface opening ;
  7. Signal handler installation : SIGHUP, SIGINT and SIGQUIT are caught to manage a clean quit (please note that the SDL library also catches SIGSEGV) ;
  8. Audio output thread spawning ;
  9. Video output thread spawning ;
  10. Main loop : events management ;

Following sections describe each of these steps in particular, and many more.

The message interface

It is a know fact that printf() functions are not necessarily thread-safe. As a result, one thread interrupted in a printf() call, followed by another calls to it, will leave the program in an undetermined state. So an API must be set up to print messages without crashing.

This API is implemented in two ways. If INTF_MSG_QUEUE is defined in config.h , every printf-like (see below) call will queue the message into a chained list. This list will be printed and flushed by the interface thread once upon an event loop. If INTF_MSG_QUEUE is undefined, the calling thread will acquire the print lock (which prevents two print operations to occur at the same time) and print the message directly (default behaviour).

Functions available to print messages are :

  • msg_Info ( p_this, ... ) : Print a message to stdout , plain and stupid (for instance "it works!").
  • msg_Err( p_this, ... ) : Print an error message to stderr .
  • msg_Warn( p_this, ... ) : Print a message to stderr if the warning level (determined by -v, -vv and -vvv) is low enough. Please note that the lower the level, the less important the message is.
  • msg_Dbg( p_this, ... ) : This function is designed for optional checkpoint messages, such as "we are now entering function dvd_foo_thingy". It does

nothing in non-trace mode. If the VLC is compiled with --enable-trace, the message is either written to the file vlc-trace.log (if TRACE_LOG is defined in config.h), or printed to stderr (otherwise).

  • msg_Flush(p_this) : Flush the message queue, if it is in use.

Command line options

VLC uses GNU getopt to parse command line options. getopt structures are defined in src/extras/getopt.c and command line parsing is done in src/config/cmdline.c

Most configuration directives are exchanged via the environment array, using main_Put*Variable and main_Get*Variable. As a result, ./vlc --height 240 is strictly equivalent to : vlc_height=240 ./vlc. That way configuration variables are available everywhere, including plugins.

Warning

Please note that for thread-safety issues, you should not use main_Put*Variable once the second thread has been spawned

Playlist management

The playlist is created on startup from files given in the command line. An appropriate interface plugin can then add or remove files from it. Functions to be used are described in src/playlist/control.c.