vlc特有的模块(plugin)管理方式

来源:互联网 发布:淘宝客数据采集工具 编辑:程序博客网 时间:2024/06/05 02:56

    vlc中所有的模块均以动态库(插件)方式来管理,就连main模块也不例外。可以在windows下查看vlc安装目录下plugin目录,里面包含了所有的动态库。当vlc启动的时候,主模块采用动态加入的方式.

具体实现如下:

     If you have a look at include/modules_inner.h, you can see on line 97 that it declares a new function. This function's name is defined by __VLC_SYMBOL(vlc_entry). __VLC_SYMBOL is defined a few lines above as the concatenation of "vlc_entry" with MODULE_NAME (the CONCATENATE macro inserts the double underscore). MODULE_NAME is defined by the compiler at compile time using a -D command line flag except in the case of the main libvlc module (which is the one you're looking at) where it defines the name at line 31 of src/libvlc.c. This file then includes src/libvlc.h which calls the vlc_module_begin() macro on line 1177. So we now have a valid function called vlc_entry__main. When the main plugin is initialized in the __module_LoadMain() in src/misc/modules.c, it gives that function as the second argument to the AllocateBuiltinModule() on line 327 which will then call the function on line 1212.

    上面一段是老外解释的,还是说的比较清楚了,后来我仔细看了下,自己也做了相关的试验。其实他的核心就是采用宏定义将该模块的入口函数导出,以让其他函数调用。同时入口函数里面初始化了于该模块相关的所有函数指针。

    主模块的库是libvlc。在modules_in.h中,通过宏定义,导出了vlc_entry__MODULE_NAME函数,MODULE_NAME的宏定义在libvlc.c的31行,(#define MODULE_NAME main)这样也就说明了该模块的入口函数是vlc_entry__main。在modules.c中存在函数__module_InitBank,该函数最后调用module_LoadMain,在module_LoadMain中,调用了AllocateBuiltinModule函数(AllocateBuiltinModule( p_this, vlc_entry__main );),此处明确指出了需要调用主模块的入口函数vlc_entry__main,哈哈,看到了吧,此处说明了main模块要载入了,果然在AllocateBuiltinModule函数中存在调用pf_entry( p_module )1212行,该调用实质是vlc_entry__main的调用,现在一切真像大白了。

     除了主模块的载入外,其他模块的载入和主模块有点不同。他们不是通过这样直接指定模块名字调用相应的函数指针的方式,而是采用在动态库中直接找到_vlc_entry*函数的地址,并调用该函数完成具体模块的初始化工作。具体的函数调用流程如下:

     1。通过__module_Need(modules.h)找到需要载入的模块;

     2。在上面函数中通过AllocatePlugin(Modules.h)函数来完成载入;

     3.在AllocatePlugin函数中,CallEntry实现具体的模块入口的调用,其实现原理就是通过在动态库文件中查找_vlc_entry*函数的地址(C语言风格的动态库)。

     4。回到最上层的__module_Need函数中,调用模块初始化的pf_activate来激活,最后当需要卸载时,调用pf_deactivate函数即可。

     以上就是vlc独特的管理模块的方式,只是一个大概的原理,具体里面还有很多数据结构还未仔细研究,不过可以看的出vlc这样做的好处能比较灵活的管理各种模块,并动态改变。虽然代码都有C写的,但是实现后的灵活度还是很高的。

http://blog.sina.com.cn/s/blog_53eb5a2401009kwj.html