对于Android端客户端,主要是有三个c层的结构体持有数据,是LibVLC.java对应的libvlc_instance_t。Media.java对应的libvlc_media_t,以及播放器对应的libvlc_media_player_t。
三个层次分别对应播放器的配置参数,多媒体信息以及播放器状态
下面简要介绍一下三部分关系,
libvlc_instance_t * libvlc_new( int argc, const char *const *argv )
{
libvlc_int_t *p_libvlc_int = libvlc_InternalCreate();
libvlc_InternalInit( p_libvlc_int, argc + 1, my_argv )
return p_new;
}
/**
* Initialize a libvlc instance
* This function initializes a previously allocated libvlc instance:
* - CPU detection
* - gettext initialization
* - message queue, module bank and playlist initialization
* - configuration and commandline parsing
*/
int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
const char *ppsz_argv[] )
{
libvlc_priv_t *priv = libvlc_priv (p_libvlc);
char *psz_val;
int i_ret = VLC_EGENERIC;
/*
* Initialize the module bank and load the core config only.
* 加载core这个模块,
*/
module_InitBank ();
/*
* Load plugin data into the module bank.
* We need to do this here such that option sets from plugins are added to
* the config system in order that full commandline argument parsing and
* saved settings handling can function properly.
* 对于Android 这是通过shell脚本把需要的modue写完,最终注册打需要的二叉树上的,
*/
module_LoadPlugins (p_libvlc);
/*
* Fully process command line settings.
* Results are stored as runtime state within `p_libvlc` object variables.
*/
int vlc_optind;
if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) )
goto error;
//根据平台加载Log日志
vlc_LogInit(p_libvlc);
return VLC_SUCCESS;
}
/**
* Init bank
*
* Creates a module bank structure which will be filled later
* on with all the modules found.
*/
void module_InitBank (void)
{
/* Fills the module bank structure with the core module infos.
* This is very useful as it will allow us to consider the core
* library just as another module, and for instance the configuration
* options of core will be available in the module bank structure just
* as for every other module.
*VLC_MODULE_ENTRY(core) =========> vlc_entry__core 这是libvlc-module.c中vlc_module_begin预处理出来的方法。方法体就是声明的内容
*/
vlc_plugin_t *plugin = module_InitStatic(VLC_MODULE_ENTRY(core));
if (likely(plugin != NULL))
vlc_plugin_store(plugin);
config_SortConfig ();
/* We do retain the module bank lock until the plugins are loaded as well.
* This is ugly, this staged loading approach is needed: LibVLC gets
* some configuration parameters relevant to loading the plugins from
* the core (builtin) module. The module bank becomes shared read-only data
* once it is ready, so we need to fully serialize initialization.
* DO NOT UNCOMMENT the following line unless you managed to squeeze
* module_LoadPlugins() before you unlock the mutex. */
/*vlc_mutex_unlock (&modules.lock);*/
}
/**
* Registers a statically-linked plug-in.
*/
static vlc_plugin_t *module_InitStatic(vlc_plugin_cb entry)
{
/* Initializes the statically-linked library */
vlc_plugin_t *lib = vlc_plugin_describe (entry);
return lib;
}
vlc_plugin_t *vlc_plugin_describe(vlc_plugin_cb entry)
{
vlc_plugin_t *plugin = vlc_plugin_create();
//调用vlc_module_begin中的方法体中的内容
entry(vlc_plugin_desc_cb, plugin)
return plugin;
}
主要的core初始化大概就这些,下面分析一下media的初始化。主要是通过
void
Java_org_videolan_libvlc_Media_nativeNewFromPath(JNIEnv *env, jobject thiz,
jobject libVlc, jstring jpath)
{
Media_nativeNewFromCb(env, thiz, libVlc, jpath, libvlc_media_new_path);
}
最关键的是通过libvlc_media_new_path,拿到libvlc_media_t
// Create a media for a certain file path
libvlc_media_t *libvlc_media_new_path(const char *path)
{
char *mrl = vlc_path2uri( path, NULL );
if( unlikely(mrl == NULL) )
{
libvlc_printerr( "%s", vlc_strerror_c(errno) );
return NULL;
}
libvlc_media_t *m = libvlc_media_new_location(mrl);
free( mrl );
return m;
}
// Create a media with a certain given media resource location
libvlc_media_t *libvlc_media_new_location(const char * psz_mrl)
{
input_item_t * p_input_item;
libvlc_media_t * p_md;
p_input_item = input_item_New( psz_mrl, NULL );
if (!p_input_item)
{
libvlc_printerr( "Not enough memory" );
return NULL;
}
p_md = libvlc_media_new_from_input_item( p_input_item );
/* The p_input_item is retained in libvlc_media_new_from_input_item */
input_item_Release( p_input_item );
return p_md;
}
具体不详细介绍。播放器流程这里就不再详细介绍,下一篇介绍。