初始化入口:
linphone_core_init() ——linphonecore.c 1793
static void linphone_core_init(LinphoneCore * lc, const LinphoneCoreVTable *vtable, LpConfig *config, void * userdata){
const char *remote_provisioning_uri = NULL;
linphone_task_list_init(&lc->hooks);
_linphone_core_add_listener(lc, internal_vtable, TRUE, TRUE);
memcpy(local_vtable,vtable,sizeof(LinphoneCoreVTable));
_linphone_core_add_listener(lc, local_vtable, TRUE, FALSE);
lc->factory = ms_factory_new_with_voip();
linphone_core_register_default_codecs(lc);
linphone_core_register_offer_answer_providers(lc);
/* Get the mediastreamer2 event queue */
/* This allows to run event's callback in linphone_core_iterate() */
lc->msevq=ms_factory_create_event_queue(lc->factory);
lc->sal=sal_init(lc->factory);
}
媒体库初始化在ms_factory_new_with_voip() —— msvoip.c 354
MSFactory *ms_factory_new_with_voip(void){
ms_message("ms_factory_new_with_voip");
MSFactory *f = ms_factory_new();
ms_factory_init_voip(f);
ms_factory_init_plugins(f);
return f;
}
第一步、ms_factory_new()新建一个MSFactory对象
第二步、ms_factory_init_voip(),初始化voip;
第三步、ms_factory_init_plugins();初始化插件;
先分析第一步,ms_factory_new()只是实例化一个MSFactory结构体 位于msfactory.c line223
MSFactory *ms_factory_new(void){
MSFactory *obj=ms_new0(MSFactory,1);
ms_factory_init(obj);
return obj;
}
ms_factory_init(); ——msfactory.c 144
void ms_factory_init(MSFactory *obj){
int i;
long num_cpu=1;
char *debug_log_enabled = NULL;
char *tags;
...
ms_message("Mediastreamer2 factory " MEDIASTREAMER_VERSION " (git: " GIT_VERSION ") initialized.");
/* register builtin MSFilter's */
for (i=0;ms_base_filter_descs[i]!=NULL;i++){
ms_factory_register_filter(obj,ms_base_filter_descs[i]);
}
ms_factory_set_cpu_count(obj,num_cpu);
ms_factory_set_mtu(obj,MS_MTU_DEFAULT);
#ifdef ANDROID
ms_factory_add_platform_tag(obj, "android");
#endif
#ifdef TARGET_OS_IPHONE
ms_factory_add_platform_tag(obj, "ios");
#endif
...
tags = ms_factory_get_platform_tags_as_string(obj);
ms_message("ms_factory_init() done: platform_tags=%s", tags);
ms_free(tags);
}
主要是设置MSFactory*的一些属性,重点在中间的for循环。
其中的ms_base_filter_descs[]定义在basedesc.h中,
extern MSFilterDesc ms_tee_desc;
extern MSFilterDesc ms_join_desc;
extern MSFilterDesc ms_void_source_desc;
extern MSFilterDesc ms_void_sink_desc;
MSFilterDesc * ms_base_filter_descs[]={
&ms_tee_desc,
&ms_join_desc,
&ms_void_source_desc,
&ms_void_sink_desc,
NULL
};
而ms_factory_register_filter()在msfactory.c line 230
void ms_factory_register_filter(MSFactory* factory, MSFilterDesc* desc ) {
if (desc->id==MS_FILTER_NOT_SET_ID){
ms_fatal("MSFilterId for %s not set !",desc->name);
}
desc->flags|=MS_FILTER_IS_ENABLED; /*by default a registered filter is enabled*/
/*lastly registered encoder/decoders may replace older ones*/
factory->desc_list=bctbx_list_prepend(factory->desc_list,desc);
}
将整个数组中定义的desc设置到factory->desc_list;
再看第二步ms_factory_init_voip(MSFactory *) 在msvoip.c line260
void ms_factory_init_voip(MSFactory *obj){
MSSndCardManager *cm;
int i;
if (obj->voip_initd) return;
ms_srtp_init();
obj->devices_info = ms_devices_info_new();
......
#if defined(ANDROID) && defined(VIDEO_ENABLED)
if (AMediaImage_isAvailable()) {
ms_factory_register_filter(obj, &ms_mediacodec_h264_dec_desc);
ms_factory_register_filter(obj, &ms_mediacodec_h264_enc_desc);
}
#endif
/* register builtin VoIP MSFilter's */
for (i=0;ms_voip_filter_descs[i]!=NULL;i++){
ms_factory_register_filter(obj,ms_voip_filter_descs[i]);
}
cm=ms_snd_card_manager_new();
ms_message("Registering all soundcard handlers");
cm->factory=obj;
obj->sndcardmanager = cm;
for (i=0;ms_snd_card_descs[i]!=NULL;i++){
ms_snd_card_manager_register_desc(cm,ms_snd_card_descs[i]);
}
...
#if defined(ANDROID) && defined (VIDEO_ENABLED)
{
MSDevicesInfo *devices = ms_factory_get_devices_info(obj);
SoundDeviceDescription *description = ms_devices_info_get_sound_device_description(devices);
if (description && description->flags & DEVICE_HAS_CRAPPY_OPENGL) {
if (!libmsandroiddisplay_init(obj)) {
libmsandroiddisplaybad_init(obj);
}
} else {
libmsandroidopengldisplay_init(obj);
}
}
#endif
obj->voip_initd=TRUE;
obj->voip_uninit_func = ms_factory_uninit_voip;
ms_message("ms_factory_init_voip() done");
}
初始化有个重要的操作,构建一个MSSndCardManager对象,然后将系统允许的集中声卡注册进去;
其中ms_snd_card_manager_new() ,在mssndcard.c line27
MSSndCardManager * ms_snd_card_manager_new(void){
MSSndCardManager *obj=(MSSndCardManager *)ms_new0(MSSndCardManager,1);
obj->factory = NULL;
obj->cards=NULL;
obj->descs=NULL;
return obj;
}
只是初始化一个MSSndCardManager结构体,并与外部传入的MSFactory互相关联属性;
ms_snd_card_descs[]是预先定义好的
static MSSndCardDesc * ms_snd_card_descs[]={
#ifdef MS2_FILTERS
...
#ifdef __ALSA_ENABLED__
&alsa_card_desc,
#endif
...
#ifdef ANDROID
&android_native_snd_card_desc,
&android_native_snd_opensles_card_desc,
&msandroid_sound_card_desc,
#endif
#endif /* MS2_FILTERS */
NULL
};
对于Android 平台 一共定义了3中声卡模型,
其中的android_native_snd_card_desc定义在 androidsound.cpp