前面几章介绍加载插件时或许你已经注意到了,每个插件其实是由一个module_t结构体管理的,我们看下module_t结构体, 它在modules.h文件中:
struct module_t
{
module_t *next; //说明它是链表的一个节点
module_t *parent;
module_t *submodule;
unsigned submodule_count;
unsigned i_shortcuts;
char **pp_shortcuts;
char *psz_shortname; //名字
char *psz_longname;
char *psz_help;
char *psz_capability;
int i_score;
bool b_loaded;
bool b_unloadable;
void *pf_activate; //指向插件的回调函数
void *pf_deactivate;
module_config_t *p_config; //配置
size_t confsize;
unsigned int i_config_items;
unsigned int i_bool_items;
module_handle_t handle; //dll对应的句柄
char * psz_filename;
char * domain;
};
module_t的成员是在vlc_module_begin ()后面赋值的,我们可以看下filesystem插件对应的module_t赋值后的情况:
struct module_t
{
module_t *submodule = 等会列出;
unsigned submodule_count = 1;
char *psz_shortname = "File";
char *psz_longname = "File input"
char *psz_capability = "access";
int i_score = 50;
void *pf_activate = FileOpen;
void *pf_deactivate = FileClose;
};
它有一个子模块submodule , 它的赋值为
struct module_t
{
module_t *submodule = NULL;
unsigned submodule_count = 0;
char *psz_shortname = "File";
char *psz_longname = "File input"
char *psz_capability = "access";
int i_score = 55;
void *pf_activate = DirOpen;
void *pf_deactivate = DirClose;
};
从中可以看出,父模块的pf_activate 为FileOpen, 子模块的pf_activate 为DirOpen。
插件avcodec对应的module_t字段为:
struct module_t
{
module_t *submodule = 有6个子模块,待会说;
unsigned submodule_count = 6;
char **pp_shortcuts = "avcodec";
char *psz_shortname = "";
char *psz_longname = "FFmpeg audio/video decoder"
char *psz_capability = "decoder";
int i_score = 70;
void *pf_activate = OpenDecoder( vlc_object_t * );
void *pf_deactivate = CloseDecoder( vlc_object_t * );
};
它包含有6个子模块,我画了个图: