示例#1
0
static void * open_module (const char * path)
{
    GModule * handle = g_module_open (path, G_MODULE_BIND_LOCAL);
    if (! handle)
    {
        fprintf (stderr, "ladspa: Failed to open module %s: %s\n", path, g_module_error ());
        return NULL;
    }

    void * sym;
    if (! g_module_symbol (handle, "ladspa_descriptor", & sym))
    {
        fprintf (stderr, "ladspa: Not a valid LADSPA module: %s\n", path);
        g_module_close (handle);
        return NULL;
    }

    LADSPA_Descriptor_Function descfun = (LADSPA_Descriptor_Function) sym;

    const LADSPA_Descriptor * desc;
    for (int i = 0; (desc = descfun (i)); i ++)
    {
        PluginData * plugin = open_plugin (path, desc);
        if (plugin)
            index_append (plugins, plugin);
    }

    return handle;
}
示例#2
0
void init_and_get_number_of_frames(struct filename_list_node *fln, int *do_scan)
{
    struct file_data *fd;

    struct input_ops *ops = NULL;
    struct input_handle *ih = NULL;
    int result;

    fln->d = g_malloc(sizeof(struct file_data));
    memcpy(fln->d, &empty, sizeof empty);
    fd = (struct file_data *) fln->d;

    result = open_plugin(fln->fr->raw, fln->fr->display, &ops, &ih);
    if (result) {
        goto free;
    }

    *do_scan = TRUE;
    fd->number_of_frames = ops->get_total_frames(ih);
    g_mutex_lock(progress_mutex);
    total_frames += fd->number_of_frames;
    g_cond_broadcast(progress_cond);
    g_mutex_unlock(progress_mutex);

  free:
    if (!result) ops->close_file(ih);
    if (ih) ops->handle_destroy(&ih);
}
示例#3
0
int
init_plugin(void **handle)
{
	int ret;
	int (*init)(void **, const char **);

	ret = open_plugin();
	if (ret)
		return ret;

	init = resolve_symbol("cifs_idmap_init_plugin");
	if (!init) {
		plugin_errmsg = "cifs_idmap_init_plugin not implemented";
		return -ENOSYS;
	}
	return (*init)(handle, &plugin_errmsg);
}
示例#4
0
文件: open.c 项目: CCI/cci
/*
 * Open plugins for a given framework
 */
int cci_plugins_open_all(const char *framework,
			 cci_plugins_framework_verify_fn_t verify,
			 struct cci_plugin_handle ** plugins)
{
	int i, j;
	size_t prefix_len;
	char *ptr;
	cci_plugin_t *plugin;
	lt_dlhandle handle;
	char prefix[BUFSIZ];
	char *ctpenv;
	int ctpenv_negate;

	if (CCI_SUCCESS != (i = cci_plugins_init())) {
		return i;
	}

	ctpenv = getenv("CCI_CTP");
	if (ctpenv && ctpenv[0] == '^') {
		ctpenv_negate = 1;
		ctpenv++;
		debug(CCI_DB_INFO, "ignoring CTP list: %s", ctpenv);
	} else {
		ctpenv_negate = 0;
		debug(CCI_DB_INFO, "only keeping CTP list: %s", ctpenv);
	}

	snprintf(prefix, BUFSIZ - 1, "%s%s_", plugin_prefix, framework);
	prefix[BUFSIZ - 1] = '\0';
	prefix_len = strlen(prefix);

	for (i = 0; NULL != cci_plugins_filename_cache &&
	     NULL != cci_plugins_filename_cache[i]; ++i);
	*plugins = calloc(i + 1, sizeof(**plugins));
	if (NULL == *plugins)
		return CCI_ENOMEM;

	for (i = 0, j = 0;
	     NULL != cci_plugins_filename_cache &&
	     NULL != cci_plugins_filename_cache[i]; ++i) {
		/* Find the basename */
		if ((ptr = strrchr(cci_plugins_filename_cache[i], '/')) == NULL) {
			ptr = cci_plugins_filename_cache[i];
		} else {
			++ptr;
		}

		/* Is this a possible plugin? */
		if (strncasecmp(ptr, prefix, prefix_len) == 0) {
			if (open_plugin
			    (cci_plugins_filename_cache[i], &handle, &plugin,
			     verify) == CCI_SUCCESS) {
				if (ctpenv) {
					/* see if the ctp name is in ctpenv */
					int namelen = strlen(ptr + prefix_len);
					char *ctpenv_tmp = ctpenv;
					int found = 0;
					while (1) {
						if (!strncmp(ctpenv_tmp, ptr+prefix_len, namelen)
						    && (ctpenv_tmp[namelen] == ','
							|| ctpenv_tmp[namelen] == '\0')) {
							found = 1;
							break;
						}
						if (ctpenv_tmp[namelen] == '\0')
							break;
						ctpenv_tmp++;
					}
					/* filter */
					if (ctpenv_negate == found) {
						debug(CCI_DB_INFO, "ignoring CTP %s", ptr+prefix_len);
						continue;
					}
				}

				if (NULL != plugin->post_load &&
				    CCI_SUCCESS !=
				    plugin->post_load(plugin)) {
					fprintf(stderr,
						"Post load hook for %s failed -- ignored\n",
						ptr);
					lt_dlclose(handle);
					continue;
				}

				/* Post load was happy; this is a keeper */
				(*plugins)[j].plugin = plugin;
				(*plugins)[j].handle = handle;
				j++;
			}
		}
	}

	qsort(*plugins, j, sizeof(**plugins), cci_plugin_priority_compare);

	if (NULL == (*plugins)[0].plugin) {
		fprintf(stderr, "Unable to find suitable CCI plugin\n");
		free(*plugins);
		return CCI_ERROR;
	}

	return CCI_SUCCESS;
}
示例#5
0
void init_state_and_scan_work_item(struct filename_list_node *fln, struct scan_opts *opts)
{
    struct file_data *fd = (struct file_data *) fln->d;

    struct input_ops* ops = NULL;
    struct input_handle* ih = NULL;
    int r128_mode = EBUR128_MODE_I;
    unsigned int i;
    int *channel_map;

    int result;
    float *buffer = NULL;
    size_t nr_frames_read;

#ifdef USE_SNDFILE
    SNDFILE *outfile = NULL;
#endif

    result = open_plugin(fln->fr->raw, fln->fr->display, &ops, &ih);
    if (result) {
        g_mutex_lock(progress_mutex);
        elapsed_frames += fd->number_of_frames;
        g_cond_broadcast(progress_cond);
        g_mutex_unlock(progress_mutex);
        goto free;
    }

    if (opts->lra)
        r128_mode |= EBUR128_MODE_LRA;
    if (opts->peak) {
        if (!strcmp(opts->peak, "sample") || !strcmp(opts->peak, "all"))
            r128_mode |= EBUR128_MODE_SAMPLE_PEAK;
#ifdef USE_SPEEX_RESAMPLER
        if (!strcmp(opts->peak, "true") || !strcmp(opts->peak, "dbtp") ||
            !strcmp(opts->peak, "all"))
            r128_mode |= EBUR128_MODE_TRUE_PEAK;
#endif
    }
    if (opts->histogram)
        r128_mode |= EBUR128_MODE_HISTOGRAM;

    fd->st = ebur128_init(ops->get_channels(ih),
                          ops->get_samplerate(ih),
                          r128_mode);

    channel_map = g_malloc(fd->st->channels * sizeof(int));
    if (!ops->set_channel_map(ih, channel_map)) {
        for (i = 0; i < fd->st->channels; ++i) {
            ebur128_set_channel(fd->st, i, channel_map[i]);
        }
    }
    free(channel_map);

    if (fd->st->channels == 1 && opts->force_dual_mono) {
        ebur128_set_channel(fd->st, 0, EBUR128_DUAL_MONO);
    }

    result = ops->allocate_buffer(ih);
    if (result) abort();
    buffer = ops->get_buffer(ih);

#ifdef USE_SNDFILE
    if (opts->decode_file) {
        SF_INFO sf_info;
        memset(&sf_info, '\0', sizeof sf_info);
        sf_info.samplerate = (int) fd->st->samplerate;
        sf_info.channels = (int) fd->st->channels;
        sf_info.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
        outfile = sf_open(opts->decode_file, SFM_WRITE, &sf_info);
        if (!outfile) {
            fprintf(stderr, "output file could not be opened\n");
            exit(EXIT_FAILURE);
        }
    }
#endif

    while ((nr_frames_read = ops->read_frames(ih))) {
        g_mutex_lock(progress_mutex);
        elapsed_frames += nr_frames_read;
        g_cond_broadcast(progress_cond);
        g_mutex_unlock(progress_mutex);
        fd->number_of_elapsed_frames += nr_frames_read;
        result = ebur128_add_frames_float(fd->st, buffer, nr_frames_read);
#ifdef USE_SNDFILE
        if (opts->decode_file) {
            if (sf_writef_float(outfile, buffer, (sf_count_t) nr_frames_read) != (sf_count_t) nr_frames_read)
                sf_perror(outfile);
        }
#endif
        if (result) abort();
    }

#ifdef USE_SNDFILE
    if (opts->decode_file) {
        sf_close(outfile);
    }
#endif

    if (fd->number_of_elapsed_frames != fd->number_of_frames) {
        if (verbose) {
            fprintf(stderr, "Warning: Could not read full file"
                            " or determine right length: "
                            "Expected: %lu Got: %lu",
                            fd->number_of_frames, fd->number_of_elapsed_frames);
        }
        g_mutex_lock(progress_mutex);
        total_frames = total_frames + fd->number_of_elapsed_frames - fd->number_of_frames;
        g_cond_broadcast(progress_cond);
        g_mutex_unlock(progress_mutex);
    }
    ebur128_loudness_global(fd->st, &fd->loudness);
    if (opts->lra) {
        result = ebur128_loudness_range(fd->st, &fd->lra);
        if (result) abort();
    }

    if ((fd->st->mode & EBUR128_MODE_SAMPLE_PEAK) == EBUR128_MODE_SAMPLE_PEAK) {
        for (i = 0; i < fd->st->channels; ++i) {
            double sp;
            ebur128_sample_peak(fd->st, i, &sp);
            if (sp > fd->peak) {
                fd->peak = sp;
            }
        }
    }
#ifdef USE_SPEEX_RESAMPLER
    if ((fd->st->mode & EBUR128_MODE_TRUE_PEAK) == EBUR128_MODE_TRUE_PEAK) {
        for (i = 0; i < fd->st->channels; ++i) {
            double tp;
            ebur128_true_peak(fd->st, i, &tp);
            if (tp > fd->true_peak) {
                fd->true_peak = tp;
            }
        }
    }
#endif
    fd->scanned = TRUE;

    if (ih) ops->free_buffer(ih);
  free:
    if (!result) ops->close_file(ih);
    if (ih) ops->handle_destroy(&ih);
}