static void * load_lib( mlt_profile profile, mlt_service_type type , void* handle){ int i=0; void (*f0r_get_plugin_info)(f0r_plugin_info_t*), *f0r_construct , *f0r_update , *f0r_destruct, (*f0r_get_param_info)(f0r_param_info_t* info, int param_index), (*f0r_init)(void) , *f0r_deinit , (*f0r_set_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index), (*f0r_get_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index), (*f0r_update2) (f0r_instance_t instance, double time, const uint32_t* inframe1, const uint32_t* inframe2,const uint32_t* inframe3, uint32_t* outframe); if ( ( f0r_construct = dlsym(handle, "f0r_construct") ) && (f0r_update = dlsym(handle,"f0r_update") ) && (f0r_destruct = dlsym(handle,"f0r_destruct") ) && (f0r_get_plugin_info = dlsym(handle,"f0r_get_plugin_info") ) && (f0r_get_param_info = dlsym(handle,"f0r_get_param_info") ) && (f0r_set_param_value= dlsym(handle,"f0r_set_param_value" ) ) && (f0r_get_param_value= dlsym(handle,"f0r_get_param_value" ) ) && (f0r_init= dlsym(handle,"f0r_init" ) ) && (f0r_deinit= dlsym(handle,"f0r_deinit" ) ) ){ f0r_update2=dlsym(handle,"f0r_update2"); f0r_plugin_info_t info; f0r_get_plugin_info(&info); void* ret=NULL; mlt_properties properties=NULL; if (type == producer_type && info.plugin_type == F0R_PLUGIN_TYPE_SOURCE ){ mlt_producer this = mlt_producer_new( ); if ( this != NULL ) { this->get_frame = producer_get_frame; this->close = ( mlt_destructor )producer_close; f0r_init(); properties=MLT_PRODUCER_PROPERTIES ( this ); for (i=0;i<info.num_params;i++){ f0r_param_info_t pinfo; f0r_get_param_info(&pinfo,i); } ret=this; } } else if (type == filter_type && info.plugin_type == F0R_PLUGIN_TYPE_FILTER ){ mlt_filter this = mlt_filter_new( ); if ( this != NULL ) { this->process = filter_process; this->close = filter_close; f0r_init(); properties=MLT_FILTER_PROPERTIES ( this ); for (i=0;i<info.num_params;i++){ f0r_param_info_t pinfo; f0r_get_param_info(&pinfo,i); } ret=this; } }else if (type == transition_type && info.plugin_type == F0R_PLUGIN_TYPE_MIXER2){ mlt_transition transition = mlt_transition_new( ); if ( transition != NULL ) { transition->process = transition_process; transition->close = transition_close; properties=MLT_TRANSITION_PROPERTIES( transition ); mlt_properties_set_int(properties, "_transition_type", 1 ); ret=transition; } } mlt_properties_set_data(properties, "_dlclose_handle", handle , sizeof (void*) , NULL , NULL ); mlt_properties_set_data(properties, "_dlclose", dlclose , sizeof (void*) , NULL , NULL ); mlt_properties_set_data(properties, "f0r_construct", f0r_construct , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_update", f0r_update , sizeof(void*),NULL,NULL); if (f0r_update2) mlt_properties_set_data(properties, "f0r_update2", f0r_update2 , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_destruct", f0r_destruct , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_get_plugin_info", f0r_get_plugin_info , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_get_param_info", f0r_get_param_info , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_set_param_value", f0r_set_param_value , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_get_param_value", f0r_get_param_value , sizeof(void*),NULL,NULL); return ret; }else{ printf("some was wrong\n"); dlerror(); } return NULL; }
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type) { Frei0rContext *frei0r = ctx->priv; f0r_init_f f0r_init; f0r_get_plugin_info_f f0r_get_plugin_info; f0r_plugin_info_t *pi; char *path; /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */ if ((path = av_strdup(getenv("FREI0R_PATH")))) { char *p, *ptr = NULL; for (p = path; p = strtok_r(p, ":", &ptr); p = NULL) if (frei0r->dl_handle = load_path(ctx, p, dl_name)) break; av_free(path); } if (!frei0r->dl_handle && (path = getenv("HOME"))) { char prefix[1024]; snprintf(prefix, sizeof(prefix), "%s/.frei0r-1/lib/", path); frei0r->dl_handle = load_path(ctx, prefix, dl_name); } if (!frei0r->dl_handle) frei0r->dl_handle = load_path(ctx, "/usr/local/lib/frei0r-1/", dl_name); if (!frei0r->dl_handle) frei0r->dl_handle = load_path(ctx, "/usr/lib/frei0r-1/", dl_name); if (!frei0r->dl_handle) { av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'\n", dl_name); return AVERROR(EINVAL); } if (!(f0r_init = load_sym(ctx, "f0r_init" )) || !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) || !(frei0r->get_param_info = load_sym(ctx, "f0r_get_param_info" )) || !(frei0r->get_param_value = load_sym(ctx, "f0r_get_param_value")) || !(frei0r->set_param_value = load_sym(ctx, "f0r_set_param_value")) || !(frei0r->update = load_sym(ctx, "f0r_update" )) || !(frei0r->construct = load_sym(ctx, "f0r_construct" )) || !(frei0r->destruct = load_sym(ctx, "f0r_destruct" )) || !(frei0r->deinit = load_sym(ctx, "f0r_deinit" ))) return AVERROR(EINVAL); if (f0r_init() < 0) { av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module"); return AVERROR(EINVAL); } f0r_get_plugin_info(&frei0r->plugin_info); pi = &frei0r->plugin_info; if (pi->plugin_type != type) { av_log(ctx, AV_LOG_ERROR, "Invalid type '%s' for the plugin\n", pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" : pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" : pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" : pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown"); return AVERROR(EINVAL); } av_log(ctx, AV_LOG_INFO, "name:%s author:'%s' explanation:'%s' color_model:%s " "frei0r_version:%d version:%d.%d num_params:%d\n", pi->name, pi->author, pi->explanation, pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" : pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" : pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown", pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params); return 0; }
bool init(void) { if(!f0r_init)return false; if(!f0r_get_plugin_info)return false; if(!f0r_get_param_info)return false; if(!f0r_construct)return false; if(!f0r_destruct)return false; if(!f0r_set_param_value)return false; if(!f0r_get_param_value)return false; if(!f0r_deinit)return false; int err=0; if(f0r_init) err=f0r_init(); f0r_plugin_info_t info; f0r_get_plugin_info(&info); m_name = info.name; m_author = info.author; m_type = info.plugin_type; switch(m_type) { case (F0R_PLUGIN_TYPE_SOURCE): case (F0R_PLUGIN_TYPE_FILTER): break; default: ::error("[pix_frei0r] only supports sources/filters, no mixers!"); return false; } #ifdef __GNUC__ # warning check color type #endif m_color = info.color_model; #ifdef __GNUC__ # warning check compatibility #endif m_frei0rVersion = info.frei0r_version; m_majorVersion = info.major_version; m_minorVersion = info.minor_version; m_explanation = info.explanation; ::post("%s by %s", info.name, info.author); ::post("%d:: %s", m_type, info.explanation); if(!f0r_update)return false; // if(!f0r_update2)return false; int numparameters = info.num_params; int i=0; m_parameterNames.clear(); m_parameterTypes.clear(); m_parameter.clear(); // dummy parameter (so we start at 1) m_parameterNames.push_back(""); m_parameterTypes.push_back(0); for(i=0; i<numparameters; i++) { f0r_param_info_t pinfo; f0r_get_param_info(&pinfo, i); m_parameterNames.push_back(pinfo.name); m_parameterTypes.push_back(pinfo.type); ::post("parm%02d[%s]: %s", i+1, pinfo.name, pinfo.explanation); } return true; }
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type) { Frei0rContext *s = ctx->priv; f0r_init_f f0r_init; f0r_get_plugin_info_f f0r_get_plugin_info; f0r_plugin_info_t *pi; char *path; if (!dl_name) { av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n"); return AVERROR(EINVAL); } /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */ if (path = getenv("FREI0R_PATH")) { while(*path) { char *ptr = av_get_token((const char **)&path, ":"); if (!ptr) return AVERROR(ENOMEM); s->dl_handle = load_path(ctx, ptr, dl_name); av_freep(&ptr); if (s->dl_handle) break; /* found */ if (*path) path++; /* skip ':' */ } } if (!s->dl_handle && (path = getenv("HOME"))) { char prefix[1024]; snprintf(prefix, sizeof(prefix), "%s/.frei0r-1/lib/", path); s->dl_handle = load_path(ctx, prefix, dl_name); } if (!s->dl_handle) s->dl_handle = load_path(ctx, "/usr/local/lib/frei0r-1/", dl_name); if (!s->dl_handle) s->dl_handle = load_path(ctx, "/usr/lib/frei0r-1/", dl_name); if (!s->dl_handle) { av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'.\n", dl_name); return AVERROR(EINVAL); } if (!(f0r_init = load_sym(ctx, "f0r_init" )) || !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) || !(s->get_param_info = load_sym(ctx, "f0r_get_param_info" )) || !(s->get_param_value = load_sym(ctx, "f0r_get_param_value")) || !(s->set_param_value = load_sym(ctx, "f0r_set_param_value")) || !(s->update = load_sym(ctx, "f0r_update" )) || !(s->construct = load_sym(ctx, "f0r_construct" )) || !(s->destruct = load_sym(ctx, "f0r_destruct" )) || !(s->deinit = load_sym(ctx, "f0r_deinit" ))) return AVERROR(EINVAL); if (f0r_init() < 0) { av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module.\n"); return AVERROR(EINVAL); } f0r_get_plugin_info(&s->plugin_info); pi = &s->plugin_info; if (pi->plugin_type != type) { av_log(ctx, AV_LOG_ERROR, "Invalid type '%s' for this plugin\n", pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" : pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" : pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" : pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown"); return AVERROR(EINVAL); } av_log(ctx, AV_LOG_VERBOSE, "name:%s author:'%s' explanation:'%s' color_model:%s " "frei0r_version:%d version:%d.%d num_params:%d\n", pi->name, pi->author, pi->explanation, pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" : pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" : pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown", pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params); return 0; }
static void * load_lib( mlt_profile profile, mlt_service_type type , void* handle, const char *name ){ int i=0; void (*f0r_get_plugin_info)(f0r_plugin_info_t*), *f0r_construct , *f0r_update , *f0r_destruct, (*f0r_get_param_info)(f0r_param_info_t* info, int param_index), (*f0r_init)(void) , *f0r_deinit , (*f0r_set_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index), (*f0r_get_param_value)(f0r_instance_t instance, f0r_param_t param, int param_index), (*f0r_update2) (f0r_instance_t instance, double time, const uint32_t* inframe1, const uint32_t* inframe2,const uint32_t* inframe3, uint32_t* outframe); if ( ( f0r_construct = dlsym(handle, "f0r_construct") ) && (f0r_destruct = dlsym(handle,"f0r_destruct") ) && (f0r_get_plugin_info = dlsym(handle,"f0r_get_plugin_info") ) && (f0r_get_param_info = dlsym(handle,"f0r_get_param_info") ) && (f0r_set_param_value= dlsym(handle,"f0r_set_param_value" ) ) && (f0r_get_param_value= dlsym(handle,"f0r_get_param_value" ) ) && (f0r_init= dlsym(handle,"f0r_init" ) ) && (f0r_deinit= dlsym(handle,"f0r_deinit" ) ) ){ f0r_update=dlsym(handle,"f0r_update"); f0r_update2=dlsym(handle,"f0r_update2"); f0r_plugin_info_t info; f0r_get_plugin_info(&info); void* ret=NULL; mlt_properties properties=NULL; char minor[12]; if (type == producer_type && info.plugin_type == F0R_PLUGIN_TYPE_SOURCE ){ mlt_producer this = mlt_producer_new( profile ); if ( this != NULL ) { this->get_frame = producer_get_frame; this->close = ( mlt_destructor )producer_close; f0r_init(); properties=MLT_PRODUCER_PROPERTIES ( this ); for (i=0;i<info.num_params;i++){ f0r_param_info_t pinfo; f0r_get_param_info(&pinfo,i); } ret=this; } } else if (type == filter_type && info.plugin_type == F0R_PLUGIN_TYPE_FILTER ){ mlt_filter this = mlt_filter_new( ); if ( this != NULL ) { this->process = filter_process; this->close = filter_close; f0r_init(); properties=MLT_FILTER_PROPERTIES ( this ); for (i=0;i<info.num_params;i++){ f0r_param_info_t pinfo; f0r_get_param_info(&pinfo,i); } ret=this; } }else if (type == transition_type && info.plugin_type == F0R_PLUGIN_TYPE_MIXER2){ mlt_transition transition = mlt_transition_new( ); if ( transition != NULL ) { transition->process = transition_process; transition->close = transition_close; properties=MLT_TRANSITION_PROPERTIES( transition ); mlt_properties_set_int(properties, "_transition_type", 1 ); ret=transition; } } check_thread_safe( properties, name ); mlt_properties_set_data(properties, "_dlclose_handle", handle , sizeof ( handle ) , NULL , NULL ); mlt_properties_set_data(properties, "_dlclose", dlclose , sizeof (void*) , NULL , NULL ); mlt_properties_set_data(properties, "f0r_construct", f0r_construct , sizeof( f0r_construct ),NULL,NULL); mlt_properties_set_data(properties, "f0r_update", f0r_update , sizeof( f0r_update ),NULL,NULL); if (f0r_update2) mlt_properties_set_data(properties, "f0r_update2", f0r_update2 , sizeof( f0r_update2 ),NULL,NULL); mlt_properties_set_data(properties, "f0r_destruct", f0r_destruct , sizeof( f0r_destruct ),NULL,NULL); mlt_properties_set_data(properties, "f0r_get_plugin_info", f0r_get_plugin_info , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_get_param_info", f0r_get_param_info , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_set_param_value", f0r_set_param_value , sizeof(void*),NULL,NULL); mlt_properties_set_data(properties, "f0r_get_param_value", f0r_get_param_value , sizeof(void*),NULL,NULL); // Let frei0r plugin version be serialized using same format as metadata snprintf( minor, sizeof( minor ), "%d", info.minor_version ); mlt_properties_set_double( properties, "version", info.major_version + info.minor_version / pow( 10, strlen( minor ) ) ); // Use the global param name map for backwards compatibility when // param names change and setting frei0r params by name instead of index. mlt_properties param_name_map = mlt_properties_get_data( mlt_global_properties(), "frei0r.param_name_map", NULL ); if ( param_name_map ) { // Lookup my plugin in the map param_name_map = mlt_properties_get_data( param_name_map, name, NULL ); mlt_properties_set_data( properties, "_param_name_map", param_name_map, 0, NULL, NULL ); } return ret; }else{ mlt_log_error( NULL, "frei0r plugin \"%s\" is missing a function\n", name ); dlerror(); } return NULL; }
static av_cold int frei0r_init(AVFilterContext *ctx, const char *dl_name, int type) { Frei0rContext *s = ctx->priv; f0r_init_f f0r_init; f0r_get_plugin_info_f f0r_get_plugin_info; f0r_plugin_info_t *pi; char *path; int ret = 0; int i; static const char* const frei0r_pathlist[] = { "/usr/local/lib/frei0r-1/", "/usr/lib/frei0r-1/", "/usr/local/lib64/frei0r-1/", "/usr/lib64/frei0r-1/" }; if (!dl_name) { av_log(ctx, AV_LOG_ERROR, "No filter name provided.\n"); return AVERROR(EINVAL); } /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */ if ((path = av_strdup(getenv("FREI0R_PATH")))) { #ifdef _WIN32 const char *separator = ";"; #else const char *separator = ":"; #endif char *p, *ptr = NULL; for (p = path; p = av_strtok(p, separator, &ptr); p = NULL) { /* add additional trailing slash in case it is missing */ char *p1 = av_asprintf("%s/", p); if (!p1) { ret = AVERROR(ENOMEM); goto check_path_end; } ret = load_path(ctx, &s->dl_handle, p1, dl_name); av_free(p1); if (ret < 0) goto check_path_end; if (s->dl_handle) break; } check_path_end: av_free(path); if (ret < 0) return ret; } if (!s->dl_handle && (path = getenv("HOME"))) { char *prefix = av_asprintf("%s/.frei0r-1/lib/", path); if (!prefix) return AVERROR(ENOMEM); ret = load_path(ctx, &s->dl_handle, prefix, dl_name); av_free(prefix); if (ret < 0) return ret; } for (i = 0; !s->dl_handle && i < FF_ARRAY_ELEMS(frei0r_pathlist); i++) { ret = load_path(ctx, &s->dl_handle, frei0r_pathlist[i], dl_name); if (ret < 0) return ret; } if (!s->dl_handle) { av_log(ctx, AV_LOG_ERROR, "Could not find module '%s'.\n", dl_name); return AVERROR(EINVAL); } if (!(f0r_init = load_sym(ctx, "f0r_init" )) || !(f0r_get_plugin_info = load_sym(ctx, "f0r_get_plugin_info")) || !(s->get_param_info = load_sym(ctx, "f0r_get_param_info" )) || !(s->get_param_value = load_sym(ctx, "f0r_get_param_value")) || !(s->set_param_value = load_sym(ctx, "f0r_set_param_value")) || !(s->update = load_sym(ctx, "f0r_update" )) || !(s->construct = load_sym(ctx, "f0r_construct" )) || !(s->destruct = load_sym(ctx, "f0r_destruct" )) || !(s->deinit = load_sym(ctx, "f0r_deinit" ))) return AVERROR(EINVAL); if (f0r_init() < 0) { av_log(ctx, AV_LOG_ERROR, "Could not init the frei0r module.\n"); return AVERROR(EINVAL); } f0r_get_plugin_info(&s->plugin_info); pi = &s->plugin_info; if (pi->plugin_type != type) { av_log(ctx, AV_LOG_ERROR, "Invalid type '%s' for this plugin\n", pi->plugin_type == F0R_PLUGIN_TYPE_FILTER ? "filter" : pi->plugin_type == F0R_PLUGIN_TYPE_SOURCE ? "source" : pi->plugin_type == F0R_PLUGIN_TYPE_MIXER2 ? "mixer2" : pi->plugin_type == F0R_PLUGIN_TYPE_MIXER3 ? "mixer3" : "unknown"); return AVERROR(EINVAL); } av_log(ctx, AV_LOG_VERBOSE, "name:%s author:'%s' explanation:'%s' color_model:%s " "frei0r_version:%d version:%d.%d num_params:%d\n", pi->name, pi->author, pi->explanation, pi->color_model == F0R_COLOR_MODEL_BGRA8888 ? "bgra8888" : pi->color_model == F0R_COLOR_MODEL_RGBA8888 ? "rgba8888" : pi->color_model == F0R_COLOR_MODEL_PACKED32 ? "packed32" : "unknown", pi->frei0r_version, pi->major_version, pi->minor_version, pi->num_params); return 0; }