Commit 5a65cee9 authored by Sandrine Avakian's avatar Sandrine Avakian

Adding ref_count in structure MSFactory to keep track of users through initializations.

Modifying ms_factory_destroy to destroy it and its contents when no one is using it anymore.
Modifying ms_factory_uninit to destroy the card manager and webcam manager when there is
 no  references to them.
parent 006d694f
......@@ -42,6 +42,7 @@ struct _MSFactory{
int mtu;
bool_t statistics_enabled;
bool_t voip_initd;
int ref_count;
};
typedef struct _MSFactory MSFactory;
......@@ -80,6 +81,12 @@ LINPHONE_DEPRECATED MS2_PUBLIC MSFactory *ms_factory_get_fallback(void);
**/
MS2_PUBLIC void ms_factory_destroy(MSFactory *factory);
/**
* Exits the factory : unset voip and destroys the factory if there is no references to it.
* Ensures it can be destroyed before destroying all objects created by the factory.
**/
MS2_PUBLIC MSFactory* ms_factory_exit(MSFactory* factory);
MS2_PUBLIC void ms_factory_register_filter(MSFactory *factory, MSFilterDesc *desc);
/**
......
......@@ -240,27 +240,39 @@ MSFactory *ms_factory_new(void){
return obj;
}
/**
* Destroy the factory.
* This should be done after destroying all objects created by the factory.
**/
void ms_factory_destroy(MSFactory *factory){
ms_factory_uninit_plugins(factory);
//if (factory->evq) ms_event_queue_destroy(factory->evq, factory);
if (factory->evq) ms_factory_destroy_event_queue(factory);
factory->formats=ms_list_free_with_data(factory->formats,(void(*)(void*))ms_fmt_descriptor_destroy);
factory->desc_list=ms_list_free(factory->desc_list);
ms_list_for_each(factory->stats_list,ms_free);
factory->stats_list=ms_list_free(factory->stats_list);
factory->offer_answer_provider_list = ms_list_free(factory->offer_answer_provider_list);
ms_list_for_each(factory->platform_tags, ms_free);
factory->platform_tags = ms_list_free(factory->platform_tags);
if (factory->plugins_dir) ms_free(factory->plugins_dir);
ms_free(factory);
factory->ref_count--;
if (factory->ref_count == 0){
ms_factory_uninit_plugins(factory);
//if (factory->evq) ms_event_queue_destroy(factory->evq, factory);
if (factory->evq) ms_factory_destroy_event_queue(factory);
factory->formats=ms_list_free_with_data(factory->formats,(void(*)(void*))ms_fmt_descriptor_destroy);
factory->desc_list=ms_list_free(factory->desc_list);
ms_list_for_each(factory->stats_list,ms_free);
factory->stats_list=ms_list_free(factory->stats_list);
factory->offer_answer_provider_list = ms_list_free(factory->offer_answer_provider_list);
ms_list_for_each(factory->platform_tags, ms_free);
factory->platform_tags = ms_list_free(factory->platform_tags);
if (factory->plugins_dir) ms_free(factory->plugins_dir);
ms_free(factory);
}
//if (factory==fallback_factory) fallback_factory=NULL;
}
//
//MSFactory* ms_factory_exit(MSFactory* factory){
// ms_factory_uninit_voip(factory);
//
// ms_factory_destroy(factory);
// return NULL;
// }
// return factory;
//}
void ms_factory_register_filter(MSFactory* factory, MSFilterDesc* desc ) {
if (desc->id==MS_FILTER_NOT_SET_ID){
......
......@@ -265,7 +265,7 @@ void ms_factory_init_voip(MSFactory *obj){
int i;
ms_srtp_init();
obj->ref_count++;
/* 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]);
......@@ -323,19 +323,21 @@ void ms_factory_init_voip(MSFactory *obj){
void ms_factory_uninit_voip(MSFactory *obj){
ms_srtp_shutdown();
if (obj->voip_initd){
managers_ref--;
if (managers_ref==0){
ms_snd_card_manager_destroy();
#ifdef VIDEO_ENABLED
ms_video_presets_manager_destroy(obj->video_presets_manager);
ms_web_cam_manager_destroy();
#endif
managers_ref--;
if (managers_ref==0){
ms_snd_card_manager_destroy();
if (obj->voip_initd){
#ifdef VIDEO_ENABLED
ms_web_cam_manager_destroy();
ms_video_presets_manager_destroy(obj->video_presets_manager);
#endif
}
obj->voip_initd = FALSE;
}
obj->voip_initd = FALSE;
}
void ms_voip_exit(){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment