Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12899167
  • 博文数量: 1293
  • 博客积分: 13501
  • 博客等级: 上将
  • 技术积分: 17974
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 18:11
文章分类

全部博文(1293)

文章存档

2019年(1)

2018年(1)

2016年(118)

2015年(257)

2014年(128)

2013年(222)

2012年(229)

2011年(337)

分类: C/C++

2011-04-09 23:24:30

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 and starts up in src/interface/main.c . It passes through the following steps :

1. CPU detection : which CPU are we running on, what are its capabilitieswps_clip_image1 (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 ; wps_clip_image2

9. Video output thread spawning ;

10. Main loop : events management ;

Following sections describe each of these steps in particularwps_clip_image3, 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 undeterminedwps_clip_image4 statewps_clip_image5. So an API must be set up to print messages without crashing. wps_clip_image6

This API is implementedwps_clip_image7 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 flushedwps_clip_image8 by the interface thread once upon an event loop. If INTF_MSG_QUEUE is undefined, the calling thread will acquirewps_clip_image9 the print lock (which prevents two print operations to occur at the same time) and print the message directly (default behaviourwps_clip_image10).

Functions availablewps_clip_image11 to print messages are :

· intf_Msg ( char * psz_format, ... ) : Print a message to stdout , plain and stupid (for instance "vlc 0.2.72 (Apr 16 2001)").

· intf_ErrMsg ( char * psz_format, ... ) : Print an error message to stderr .

· intf_WarnMsg ( int i_level, char * psz_format, ... ) : Print a message to stderr if the warning level (determinedwps_clip_image12 by -v, -vv and -vvv) is low enough.

Note

Please note that the lower the level, the less important the message is (dayou spikwps_clip_image13 ingliche ?).

· intf_DbgMsg ( char * psz_format, ... ) : 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用别的方法).

· intf_MsgImm, intf_ErrMsgImm, intf_WarnMsgImm, intf_DbgMsgImm : Same as above, except that the message queue, in case INTF_MSG_QUEUE is defined, will be flushed before the function returns.

· intf_WarnHexDump ( int i_level, void * p_data, int i_size ) : Dumpswps_clip_image14 i_size bytes from p_data in hexadecimalwps_clip_image15. i_level works like intf_WarnMsg . This is useful for debugging purposeswps_clip_image16.

· intf_FlushMsg () : 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/interface/main.c in the "Command line options constantswps_clip_image17" section. To add a new option This section needs to be changed, along with GetConfiguration and Usage.

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

Warning

Please note that for thread-safety issueswps_clip_image21, 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 appropriatewps_clip_image22 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 main interface loop intf_Manage is then supposed to start and kill input threads when necessary.

Module bank

On startupwps_clip_image23, VLC creates a bank of all available .so files (plugins) in ., ./lib, /usr/local/lib/videolan/vlc (PLUGIN_PATH), and built-in plugins. Every plugin is checked with its capabilities, which are :

· MODULE_CAPABILITY_INTF : An interface plugin ;

· MODULE_CAPABILITY_ACCESS : A sam-ism, unused  wps_clip_image24at present ;

· MODULE_CAPABILITY_INPUT : An input plugin, for instance PS or DVD ;

· MODULE_CAPABILITY_DECAPS : A sam-ism, unused at present ;

· MODULE_CAPABILITY_ADEC : An audio decoder ;

· MODULE_CAPABILITY_VDEC : A video decoder ;

· MODULE_CAPABILITY_MOTION : A motion wps_clip_image25compensation wps_clip_image26module (for the video decoder) ;

· MODULE_CAPABILITY_IDCT : An IDCT module (for the video decoder) ;

· MODULE_CAPABILITY_AOUT : An audio output module ;

· MODULE_CAPABILITY_VOUT : A video output module ;

· MODULE_CAPABILITY_YUV : A YUV module (for the video output) ;

· MODULE_CAPABILITY_AFX : An audio effect s plugin (for the audio output ; unimplemented) ;

· MODULE_CAPABILITY_VFX : A video effects plugin (for the video output ; unimplemented) ;

How to write a plugin is described in the latter sections. Other threads can request请求, 要求 a plugin descriptorwps_clip_image27 with module_Need ( module_bank_t * p_bank, int i_capabilities, void * p_data ). p_data is an optional parameterwps_clip_image28 (reserved wps_clip_image29for future use) for the pf_probe() function. The returned module_t structure contains pointers to the functions of the plug-in. See include/modules.h for more information.

The interface main loop

The interface thread will first look for a suitable interface plugin. Then it enters the main interface loop, with the plugin's pf_run function. This function will do what's appropriatewps_clip_image30, and every 100 ms will call (typically via a GUI timer callback) intf_Manage.

intf_Manage cleans up the module bank by unloading unnecessary wps_clip_image31modules, manages the playlist, and flushes waiting messages (if the message queue is in use).

How to write an interface plugin API for the Module

Have a look the files in directories modules/misc/control, modules/misc/dummy仿制器, modules/misc/access, or modules/gui. However然而 the GUI interfaces are not very easy to understand, since they are quite big. I suggest to start diggingwps_clip_image32 into a non-graphical interface modules first. For example modules/control/hotkeys.c.

An interface module is made of 3 entry functions and a module description:

· The module description is made of macros wps_clip_image33that declareswps_clip_image34 the capabilities of the module (interface, in this case既然这样) with their priority, the module description as it will appear in the preferenceswps_clip_image35 of GUI modules that implementwps_clip_image36 them, some configuration variables specific to the module, shortcutswps_clip_image37, sub-modules, etc.

· Open ( vlc_object_t* p_object ): This is called by VLC to initialize the module.

· Run ( vlc_object_t* p_object ): really does the job of the interface module (waiting for user input and displaying info). It should check periodicallywps_clip_image38 that p_intf->b_die is not VLC_TRUE.

· Close ( vcl_object_t * p_object ) function is called by VLC to uninitialize the module (basically, this consists in destroying whatever have been allocated by Open)

The above functions take a vlc_object_t* as argument, but that may need to be cast into a intf_thread_t* depending on your needs. This structure is often needed as a parameter wps_clip_image39for exported VLC functions, such as msg_Err(), msg_Warn(), ...

Define intf_sys_t to contain any variable you need (don't use static variables, they suck in a multi-threaded application :-).

If additional capabilities (such as Open button, playlist, menus, etc.) are needed, consultwps_clip_image40 one of the GUI modules. One of the simpler GUI modules to consult might be modules/gui/ncurses/ncurses.c. It is a quite simple complete interface module with playlist interactionwps_clip_image41, and progress bar, among other things.

Arranging for your Module to get Compiled

If you create a new directory for your module, add a Modules.am file in it. In this file, put something like : SOURCES_yourmodule = myfile1.c myfile2.c

Then go to the main configure.ac file, and add in the AC_CONFIG_FILES section (towards the end of the file) a line similar to the others.

If you don't create a directory for your plugin (but instead just put it in an existingwps_clip_image42 directory), you only have to add the two SOURCES_... lines to the existing Modules.am file

This declares your module; it does not arrangewps_clip_image43 for it to be automatically compiled; automatic compilatoin is described further below.

You do not write a Makefile for your module. Instead this is done via the bootstrapwps_clip_image44 and configuration process. So now run:

./bootstrap

./configure configure-options

make

To build the module manually, go to the directory it resides and type make libyourmodule_plugin.so (or .dll, or whatever the file type for a shared library is on your Operating System.)

To automaticallywps_clip_image45 have your module get built, you also set this in the configure.ac file; add your module name to the default modules section in one of the AX_ADD_PLUGINS directives.wps_clip_image46

Prev

Next

Chapter 1.  VLC Overview 

Home

Chapter 3.  The complex multi-layer input

阅读(1884) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~