00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include <config.h>
00024 #endif
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <math.h>
00032 #include <cpl.h>
00033
00034 #include "muse_processing.h"
00035
00036 #include "muse_utils.h"
00037
00038
00042
00043
00046
00047
00048
00049
00053
00054 typedef struct muse_processinginfo_s {
00055 struct muse_processinginfo_s *prev;
00056 struct muse_processinginfo_s *next;
00057 cpl_recipe *plugin;
00058 cpl_recipeconfig *recipeconfig;
00060 muse_processing_prepare_header_func *prepare_header;
00062 muse_processing_get_frame_level_func *get_frame_level;
00064 muse_processing_get_frame_mode_func *get_frame_mode;
00065 } muse_processinginfo_t;
00066
00067
00071
00072 static muse_processinginfo_t *muse_processinginfo = NULL;
00073
00074
00078
00079
00080 static muse_processinginfo_t *
00081 muse_processinginfo_get(const cpl_recipe *aRecipe) {
00082 if (muse_processinginfo != NULL) {
00083 muse_processinginfo_t *m;
00084 for (m = muse_processinginfo; m != NULL; m = m->next) {
00085 if (m->plugin == aRecipe) {
00086 return m;
00087 }
00088 }
00089 }
00090 return NULL;
00091 }
00092
00093
00105
00106 void
00107 muse_processinginfo_register
00108 ( cpl_recipe *plugin,
00109 cpl_recipeconfig *recipeconfig,
00110 muse_processing_prepare_header_func *prepare_header,
00111 muse_processing_get_frame_level_func *get_frame_level,
00112 muse_processing_get_frame_mode_func *get_frame_mode) {
00113
00114 muse_processinginfo_t *m = muse_processinginfo;
00115 if (muse_processinginfo == NULL) {
00116 muse_processinginfo = cpl_calloc(1, sizeof(muse_processinginfo_t));
00117 m = muse_processinginfo;
00118 } else {
00119 while (m->next != NULL) {
00120 m = m->next;
00121 }
00122 m->next = cpl_calloc(1, sizeof(muse_processinginfo_t));
00123 m->next->prev = m;
00124 m = m->next;
00125 }
00126 m->plugin = plugin;
00127 m->recipeconfig = recipeconfig;
00128 m->prepare_header = prepare_header;
00129 m->get_frame_level = get_frame_level;
00130 m->get_frame_mode = get_frame_mode;
00131 }
00132
00133
00141
00142 void
00143 muse_processinginfo_delete(cpl_recipe *aRecipe) {
00144 muse_processinginfo_t *m = muse_processinginfo_get(aRecipe);
00145 if (m == NULL) {
00146 return;
00147 }
00148 if (m == muse_processinginfo) {
00149 muse_processinginfo = m->next;
00150 if (muse_processinginfo != NULL) {
00151 muse_processinginfo->prev = NULL;
00152 }
00153 } else {
00154 m->prev->next = m->next;
00155 if (m->next != NULL) {
00156 m->next->prev = m->prev;
00157 }
00158 }
00159 cpl_recipeconfig_delete(m->recipeconfig);
00160 cpl_free(m);
00161 }
00162
00163
00171
00172 cpl_error_code muse_processing_prepare_header(const cpl_recipe *aRecipe,
00173 const char *aFrametag,
00174 cpl_propertylist *aHeader) {
00175 muse_processinginfo_t *m = muse_processinginfo_get(aRecipe);
00176 return (m != NULL)? (* m->prepare_header)(aFrametag, aHeader): CPL_ERROR_NONE;
00177 }
00178
00179
00186
00187 cpl_frame_level
00188 muse_processing_get_frame_level(const cpl_recipe *aRecipe,
00189 const char *aFrametag) {
00190 muse_processinginfo_t *m = muse_processinginfo_get(aRecipe);
00191 return (m != NULL)? (* m->get_frame_level)(aFrametag): CPL_FRAME_LEVEL_NONE;
00192 }
00193
00194
00201
00202 int
00203 muse_processing_get_frame_mode(const cpl_recipe *aRecipe,
00204 const char *aFrametag) {
00205 muse_processinginfo_t *m = muse_processinginfo_get(aRecipe);
00206 return (m != NULL)?(* m->get_frame_mode)(aFrametag): MUSE_FRAME_MODE_ALL;
00207 }
00208
00209
00215
00216 cpl_recipeconfig *
00217 muse_processing_get_recipeconfig(cpl_recipe *aRecipe) {
00218 muse_processinginfo_t *m = muse_processinginfo_get(aRecipe);
00219 return (m != NULL)?m->recipeconfig: NULL;
00220 }
00221
00222
00238
00239 cpl_error_code
00240 muse_processing_prepare_property(cpl_propertylist *aHeader, const char *aName,
00241 cpl_type aType, const char *aDescription)
00242 {
00243 cpl_ensure_code(aHeader, CPL_ERROR_NULL_INPUT);
00244 cpl_ensure_code(aName, CPL_ERROR_NULL_INPUT);
00245
00246 cpl_error_code rc = CPL_ERROR_NONE;
00247
00248 cpl_propertylist *list = cpl_propertylist_new();
00249 cpl_propertylist_copy_property_regexp(list, aHeader, aName, 0);
00250 if (cpl_propertylist_is_empty(list)) {
00251 cpl_propertylist_delete(list);
00252
00253
00254
00255
00256
00257 if (!cpl_propertylist_has(aHeader, "MUSE PRIVATE DOCUMENTATION")) {
00258 cpl_msg_warning(__func__, "Property %s (%s) not used", aName,
00259 aDescription);
00260 return CPL_ERROR_DATA_NOT_FOUND;
00261 }
00262
00263
00264
00265 switch(aType) {
00266 case CPL_TYPE_FLOAT:
00267 cpl_propertylist_append_float(aHeader, aName, NAN);
00268 break;
00269 case CPL_TYPE_DOUBLE:
00270 cpl_propertylist_append_double(aHeader, aName, NAN);
00271 break;
00272 case CPL_TYPE_STRING:
00273 cpl_propertylist_append_string(aHeader, aName, "");
00274 break;
00275 case CPL_TYPE_INT:
00276 cpl_propertylist_append_int(aHeader, aName, INT_MAX);
00277 break;
00278 case CPL_TYPE_LONG:
00279 cpl_propertylist_append_long(aHeader, aName, LONG_MAX);
00280 break;
00281 case CPL_TYPE_BOOL:
00282 cpl_propertylist_append_bool(aHeader, aName, FALSE);
00283 break;
00284 default:
00285 return CPL_ERROR_INVALID_TYPE;
00286 }
00287
00288
00289
00290 cpl_property *property = cpl_propertylist_get_property(aHeader, aName);
00291 if (aDescription != NULL && strlen(aDescription)>0) {
00292 rc = cpl_property_set_comment(property, aDescription);
00293 }
00294 cpl_type type = cpl_property_get_type(property);
00295 if (type != aType) {
00296 cpl_msg_warning(__func__, "Type of property %s is %s but should be %s",
00297 aName, cpl_type_get_name(type), cpl_type_get_name(aType));
00298 return CPL_ERROR_TYPE_MISMATCH;
00299 }
00300 return CPL_ERROR_NONE;
00301 }
00302
00303
00304 int i;
00305 for (i = 0; i < cpl_propertylist_get_size(list); i++) {
00306 cpl_property *prop = cpl_propertylist_get(list, i);
00307 cpl_property *property =
00308 cpl_propertylist_get_property(aHeader, cpl_property_get_name(prop));
00309 if (aDescription != NULL && strlen(aDescription)>0) {
00310 rc = cpl_property_set_comment(property, aDescription);
00311 }
00312 cpl_type type = cpl_property_get_type(property);
00313 if (type != aType) {
00314 cpl_msg_warning(__func__, "Type of property %s is %s but should be %s",
00315 aName, cpl_type_get_name(type), cpl_type_get_name(aType));
00316 cpl_propertylist_delete(list);
00317 return CPL_ERROR_TYPE_MISMATCH;
00318 }
00319 }
00320 cpl_propertylist_delete(list);
00321 return rc;
00322 }
00323
00324
00336
00337 void
00338 muse_processing_recipeinfo(cpl_plugin *aPlugin)
00339 {
00340 cpl_msg_set_threadid_off();
00341 cpl_msg_info(__func__, "%s v%s", PACKAGE_NAME, PACKAGE_VERSION);
00342 if (!aPlugin) {
00343 return;
00344 }
00345 if (cpl_msg_get_level() != CPL_MSG_DEBUG &&
00346 cpl_msg_get_log_level() != CPL_MSG_DEBUG) {
00347 return;
00348 }
00349 cpl_recipe *recipe = (cpl_recipe *)aPlugin;
00350 cpl_size nframes = cpl_frameset_get_size(recipe->frames);
00351 cpl_msg_debug(__func__, "%"CPL_SIZE_FORMAT" input frames:", nframes);
00352
00353 cpl_msg_indent_more();
00354 cpl_size iframe;
00355 for (iframe = 0; iframe < nframes; iframe++) {
00356 cpl_frame *frame = cpl_frameset_get_position(recipe->frames, iframe);
00357 cpl_msg_debug(__func__, "%s\t%s", cpl_frame_get_filename(frame),
00358 cpl_frame_get_tag(frame));
00359 }
00360 cpl_msg_indent_less();
00361
00362
00363 cpl_msg_debug(__func__, "non-default parameters:");
00364 cpl_msg_indent_more();
00365 int n = 0;
00366 const cpl_parameter *p = cpl_parameterlist_get_first(recipe->parameters);
00367 for ( ; p; p = cpl_parameterlist_get_next(recipe->parameters)) {
00368
00369
00370 const char *name = cpl_parameter_get_alias(p, CPL_PARAMETER_MODE_CLI);
00371 cpl_type type = cpl_parameter_get_type(p);
00372
00373 switch (type) {
00374 case CPL_TYPE_BOOL: {
00375 cpl_boolean value = cpl_parameter_get_bool(p),
00376 dval = cpl_parameter_get_default_bool(p);
00377 if (value != dval) {
00378 cpl_msg_debug(__func__, "--%s=%s [%s]", name,
00379 value ? "true" : "false", dval ? "true" : "false");
00380 n++;
00381 }
00382 break;
00383 }
00384 case CPL_TYPE_INT: {
00385 int value = cpl_parameter_get_int(p),
00386 dval = cpl_parameter_get_default_int(p);
00387 if (value != dval) {
00388 cpl_msg_debug(__func__, "--%s=%d [%d]", name, value, dval);
00389 n++;
00390 }
00391 break;
00392 }
00393 case CPL_TYPE_DOUBLE: {
00394 double value = cpl_parameter_get_double(p),
00395 dval = cpl_parameter_get_default_double(p);
00396 if (value != dval) {
00397 cpl_msg_debug(__func__, "--%s=%g [%g]", name, value, dval);
00398 n++;
00399 }
00400 break;
00401 }
00402 case CPL_TYPE_STRING: {
00403 const char *value = cpl_parameter_get_string(p),
00404 *dval = cpl_parameter_get_default_string(p);
00405 if (value && dval && strncmp(value, dval, strlen(dval) + 1)) {
00406 cpl_msg_debug(__func__, "--%s=\"%s\" [\"%s\"]", name, value, dval);
00407 n++;
00408 }
00409 break;
00410 }
00411 default:
00412 cpl_msg_debug(__func__, "--%s: parameter of unknown type!", name);
00413 break;
00414 }
00415 }
00416 if (!n) {
00417 cpl_msg_debug(__func__, "none");
00418 }
00419 cpl_msg_indent_less();
00420
00421 cpl_msg_debug(__func__, "relevant environment variables:");
00422 cpl_msg_indent_more();
00423
00424
00425 char *expuser = getenv("MUSE_EXPERT_USER");
00426 if (expuser) {
00427 cpl_msg_debug(__func__, "MUSE_EXPERT_USER=%s", expuser);
00428 }
00429
00430 char *omp_num_threads = getenv("OMP_NUM_THREADS");
00431 if (omp_num_threads) {
00432 cpl_msg_debug(__func__, "OMP_NUM_THREADS=%s", omp_num_threads);
00433 }
00434 cpl_msg_indent_less();
00435 }
00436