Fix framework test: do not recreate factory if it was destroyed (due to invalid initialization)

parent e72c8b0c
......@@ -41,6 +41,11 @@ typedef struct _MSFactory MSFactory;
**/
MS2_PUBLIC MSFactory *ms_factory_new(void);
/**
* Create the factory default callback.
**/
MS2_PUBLIC MSFactory *ms_factory_create_fallback(void);
/**
* Used by the legacy functions before MSFactory was added.
* Do not use in an application.
......
......@@ -284,16 +284,18 @@ static int ms_base_ref=0;
static int ms_plugins_ref=0;
void ms_base_init(){
if (ms_base_ref++ >0 ) {
ms_base_ref++;
if ( ms_base_ref>1 ) {
ms_message ("Skiping ms_base_init, because [%i] ref",ms_base_ref);
return;
}
ms_factory_create_fallback();
ms_factory_get_fallback();
}
void ms_base_exit(){
if (--ms_base_ref >0 ) {
--ms_base_ref;
if ( ms_base_ref>0 ) {
ms_message ("Skiping ms_base_exit, still [%i] ref",ms_base_ref);
return;
}
......@@ -301,7 +303,8 @@ void ms_base_exit(){
}
void ms_plugins_init(void) {
if (ms_plugins_ref++ >0 ) {
ms_plugins_ref++;
if ( ms_plugins_ref>1 ) {
ms_message ("Skiping ms_plugins_init, because [%i] ref",ms_plugins_ref);
return;
}
......@@ -309,7 +312,8 @@ void ms_plugins_init(void) {
}
void ms_plugins_exit(void) {
if (--ms_plugins_ref >0 ) {
--ms_plugins_ref;
if ( ms_plugins_ref>0 ) {
ms_message ("Skiping ms_plugins_exit, still [%i] ref",ms_plugins_ref);
return;
}
......
......@@ -124,9 +124,6 @@ static MSFilterStats *find_or_create_stats(MSFactory *factory, MSFilterDesc *des
* Do not use in an application.
**/
MSFactory *ms_factory_get_fallback(void){
if (fallback_factory==NULL){
fallback_factory=ms_factory_new();
}
return fallback_factory;
}
......@@ -167,6 +164,12 @@ void ms_factory_init(MSFactory *obj){
ms_message("ms_factory_init() done");
}
MSFactory *ms_factory_create_fallback(void){
if (fallback_factory==NULL){
fallback_factory=ms_factory_new();
}
return fallback_factory;
}
MSFactory *ms_factory_new(void){
MSFactory *obj=ms_new0(MSFactory,1);
......@@ -336,7 +339,7 @@ MSFilterDesc *ms_factory_lookup_filter_by_name(MSFactory* factory, const char *f
MSFilterDesc* ms_factory_lookup_filter_by_id( MSFactory* factory, MSFilterId id){
MSList *elem;
for (elem=factory->desc_list;elem!=NULL;elem=ms_list_next(elem)){
MSFilterDesc *desc=(MSFilterDesc*)elem->data;
if (desc->id==id){
......@@ -429,7 +432,7 @@ int ms_factory_load_plugins(MSFactory *factory, const char *dir){
BOOL fFinished = FALSE;
const char *tmp=getenv("DEBUG");
BOOL debug=(tmp!=NULL && atoi(tmp)==1);
snprintf(szDirPath, sizeof(szDirPath), "%s", dir);
// Start searching for .dll files in the current directory.
......
......@@ -63,9 +63,7 @@ static void filter_register_tester(void) {
ms_filter_destroy(filter);
ms_exit();
CU_ASSERT_PTR_NULL(ms_filter_lookup_by_name("MSVoidSource"));
filter= ms_filter_create_decoder("pcma");
CU_ASSERT_PTR_NULL(filter);
CU_ASSERT_PTR_NULL(ms_factory_get_fallback());
}
static test_t tests[] = {
......
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