diff --git a/src/mscommon.c b/src/mscommon.c index cf37326..7a1fb7b 100644 --- a/src/mscommon.c +++ b/src/mscommon.c @@ -59,6 +59,10 @@ extern void libmsandroiddisplay_init(void); #include #endif +#if defined(WIN32) && !defined(_WIN32_WCE) +static MSList *ms_plugins_loaded_list; +#endif + MSList *ms_list_new(void *data){ MSList *new_elem=(MSList *)ms_new(MSList,1); new_elem->prev=new_elem->next=NULL; @@ -317,6 +321,8 @@ int ms_load_plugins(const char *dir){ if (initroutine!=NULL){ initroutine(); ms_message("Plugin loaded (%s)", szPluginFile); + // Add this new loaded plugin to the list (useful for FreeLibrary at the end) + ms_plugins_loaded_list=ms_list_append(ms_plugins_loaded_list,os_handle); num++; }else{ ms_warning("Could not locate init routine of plugin %s. Should be %s", @@ -400,6 +406,21 @@ int ms_load_plugins(const char *dir){ return num; } +void ms_unload_plugins(){ + MSList *elem; + +#if defined(WIN32) && !defined(_WIN32_WCE) + + for(elem=ms_plugins_loaded_list;elem!=NULL;elem=elem->next) + { + HINSTANCE handle=(HINSTANCE )elem->data; + FreeLibrary(handle) ; + } + + ms_list_free(ms_plugins_loaded_list); + +#endif +} #ifdef __ALSA_ENABLED__ extern MSSndCardDesc alsa_card_desc; @@ -617,6 +638,7 @@ void ms_exit(){ #ifdef VIDEO_ENABLED ms_web_cam_manager_destroy(); #endif + ms_unload_plugins(); } void ms_sleep(int seconds){ diff --git a/src/msticker.c b/src/msticker.c index 65c7c5d..fb672af 100644 --- a/src/msticker.c +++ b/src/msticker.c @@ -59,7 +59,8 @@ void ms_ticker_stop(MSTicker *s){ ms_mutex_lock(&s->lock); s->run=FALSE; ms_mutex_unlock(&s->lock); - ms_thread_join(s->thread,NULL); + if(s->thread) + ms_thread_join(s->thread,NULL); } void ms_ticker_set_name(MSTicker *s, const char *name){ diff --git a/src/msv4l2.c b/src/msv4l2.c index b888e2b..bccdd2d 100644 --- a/src/msv4l2.c +++ b/src/msv4l2.c @@ -490,10 +490,14 @@ static void msv4l2_postprocess(MSFilter *f){ V4l2State *s=(V4l2State*)f->data; s->thread_run = FALSE; - if(ms_thread_join(s->thread,NULL)) - ms_warning("msv4l2 thread was already stopped"); - else + if(s->thread) { + ms_thread_join(s->thread,NULL); ms_message("msv4l2 thread has joined."); + } + else { + ms_warning("msv4l2 thread was already stopped"); + } + flushq(&s->rq,0); }