Exemplo n.º 1
0
Arquivo: song.c Projeto: azuwis/mpd
bool
song_file_update(struct song *song)
{
	const char *suffix;
	char *path_fs;
	const struct decoder_plugin *plugin;
	struct stat st;

	assert(song_is_file(song));

	/* check if there's a suffix and a plugin */

	suffix = uri_get_suffix(song->url);
	if (suffix == NULL)
		return false;

	plugin = decoder_plugin_from_suffix(suffix, false);
	if (plugin == NULL)
		return false;

	path_fs = map_song_fs(song);
	if (path_fs == NULL)
		return false;

	if (song->tag != NULL) {
		tag_free(song->tag);
		song->tag = NULL;
	}

	if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) {
		g_free(path_fs);
		return false;
	}

	song->mtime = st.st_mtime;

	do {
		song->tag = plugin->tag_dup(path_fs);
		if (song->tag != NULL)
			break;

		plugin = decoder_plugin_from_suffix(suffix, true);
	} while (plugin != NULL);

	if (song->tag != NULL && tag_is_empty(song->tag))
		song->tag = tag_fallback(path_fs, song->tag);

	g_free(path_fs);
	return song->tag != NULL;
}
Exemplo n.º 2
0
/**
 * Try decoding a stream, using plugins matching the stream's URI
 * suffix.
 *
 * @param tried_r a list of plugins which were tried
 */
static bool
decoder_run_stream_suffix(struct decoder *decoder, struct input_stream *is,
			  const char *uri, GSList **tried_r)
{
	assert(tried_r != NULL);

	const char *suffix = uri_get_suffix(uri);
	const struct decoder_plugin *plugin = NULL;

	if (suffix == NULL)
		return false;

	while ((plugin = decoder_plugin_from_suffix(suffix, plugin)) != NULL) {
		if (plugin->stream_decode == NULL)
			continue;

		if (g_slist_find(*tried_r, plugin) != NULL)
			/* don't try a plugin twice */
			continue;

		if (decoder_stream_decode(plugin, decoder, is))
			return true;

		*tried_r = g_slist_prepend(*tried_r, deconst_plugin(plugin));
	}

	return false;
}
Exemplo n.º 3
0
bool
song_file_update_inarchive(struct song *song)
{
	const char *suffix;
	const struct decoder_plugin *plugin;

	assert(song_is_file(song));

	/* check if there's a suffix and a plugin */

	suffix = uri_get_suffix(song->uri);
	if (suffix == NULL)
		return false;

	plugin = decoder_plugin_from_suffix(suffix, false);
	if (plugin == NULL)
		return false;

	if (song->tag != NULL)
		tag_free(song->tag);

	//accept every file that has music suffix
	//because we don't support tag reading through
	//input streams
	song->tag = tag_new();

	return true;
}
Exemplo n.º 4
0
static void
update_regular_file(struct directory *directory,
		    const char *name, const struct stat *st)
{
	const char *suffix = uri_get_suffix(name);
	const struct decoder_plugin* plugin;
#ifdef ENABLE_ARCHIVE
	const struct archive_plugin *archive;
#endif
	if (suffix == NULL)
		return;

	if ((plugin = decoder_plugin_from_suffix(suffix, false)) != NULL)
	{
		struct song* song = songvec_find(&directory->songs, name);

		if (!(song != NULL && st->st_mtime == song->mtime &&
		      !walk_discard) &&
			plugin->container_scan != NULL)
		{
			if (update_container_file(directory, name, st, plugin))
			{
				if (song != NULL)
					delete_song(directory, song);

				return;
			}
		}

		if (song == NULL) {
			song = song_file_load(name, directory);
			if (song == NULL) {
				g_debug("ignoring unrecognized file %s/%s",
					directory_get_path(directory), name);
				return;
			}

			songvec_add(&directory->songs, song);
			modified = true;
			g_message("added %s/%s",
				  directory_get_path(directory), name);
		} else if (st->st_mtime != song->mtime || walk_discard) {
			g_message("updating %s/%s",
				  directory_get_path(directory), name);
			if (!song_file_update(song)) {
				g_debug("deleting unrecognized file %s/%s",
					directory_get_path(directory), name);
				delete_song(directory, song);
			}

			modified = true;
		}
#ifdef ENABLE_ARCHIVE
	} else if ((archive = archive_plugin_from_suffix(suffix))) {
		update_archive_file(directory, name, st, archive);
#endif
	}
}
Exemplo n.º 5
0
bool
update_song_file(struct directory *directory,
		 const char *name, const char *suffix,
		 const struct stat *st)
{
	const struct decoder_plugin *plugin =
		decoder_plugin_from_suffix(suffix, NULL);
	if (plugin == NULL)
		return false;

	update_song_file2(directory, name, st, plugin);
	return true;
}
Exemplo n.º 6
0
/**
 * Try decoding a file.
 */
static bool
decoder_run_file(struct decoder *decoder, const char *path_fs)
{
	struct decoder_control *dc = decoder->dc;
	const char *suffix = uri_get_suffix(path_fs);
	const struct decoder_plugin *plugin = NULL;

	if (suffix == NULL)
		return false;

	decoder_unlock(dc);

	decoder_load_replay_gain(decoder, path_fs);

	while ((plugin = decoder_plugin_from_suffix(suffix, plugin)) != NULL) {
		if (plugin->file_decode != NULL) {
			decoder_lock(dc);

			if (decoder_file_decode(plugin, decoder, path_fs))
				return true;

			decoder_unlock(dc);
		} else if (plugin->stream_decode != NULL) {
			struct input_stream *input_stream;
			bool success;

			input_stream = decoder_input_stream_open(dc, path_fs);
			if (input_stream == NULL)
				continue;

			decoder_lock(dc);

			success = decoder_stream_decode(plugin, decoder,
							input_stream);

			decoder_unlock(dc);

			input_stream_close(input_stream);

			if (success) {
				decoder_lock(dc);
				return true;
			}
		}
	}

	decoder_lock(dc);
	return false;
}
Exemplo n.º 7
0
bool
song_file_update(struct song *song)
{
	const char *suffix;
	char *path_fs;
	const struct decoder_plugin *plugin;
	struct stat st;
	struct input_stream *is = NULL;

	assert(song_is_file(song));

	/* check if there's a suffix and a plugin */

	suffix = uri_get_suffix(song->uri);
	if (suffix == NULL)
		return false;

	plugin = decoder_plugin_from_suffix(suffix, NULL);
	if (plugin == NULL)
		return false;

	path_fs = map_song_fs(song);
	if (path_fs == NULL)
		return false;

	if (song->tag != NULL) {
		tag_free(song->tag);
		song->tag = NULL;
	}

	if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) {
		g_free(path_fs);
		return false;
	}

	song->mtime = st.st_mtime;

	do {
		/* load file tag */
		song->tag = decoder_plugin_tag_dup(plugin, path_fs);
		if (song->tag != NULL)
			break;

		/* fall back to stream tag */
		if (plugin->stream_tag != NULL) {
			/* open the input_stream (if not already
			   open) */
			if (is == NULL)
				is = input_stream_open(path_fs, NULL);

			/* now try the stream_tag() method */
			if (is != NULL) {
				song->tag = decoder_plugin_stream_tag(plugin,
								      is);
				if (song->tag != NULL)
					break;

				input_stream_seek(is, 0, SEEK_SET, NULL);
			}
		}

		plugin = decoder_plugin_from_suffix(suffix, plugin);
	} while (plugin != NULL);

	if (is != NULL)
		input_stream_close(is);

	if (song->tag != NULL && tag_is_empty(song->tag))
		song->tag = tag_fallback(path_fs, song->tag);

	g_free(path_fs);
	return song->tag != NULL;
}
Exemplo n.º 8
0
bool
song_file_update(struct song *song)
{
    const char *suffix;
    char *path_fs;
    const struct decoder_plugin *plugin;
    struct stat st;
    struct input_stream *is = NULL;

    assert(song_is_file(song));

    /* check if there's a suffix and a plugin */

    suffix = uri_get_suffix(song->uri);
    if (suffix == NULL)
        return false;

    plugin = decoder_plugin_from_suffix(suffix, NULL);
    if (plugin == NULL)
        return false;

    path_fs = map_song_fs(song);
    if (path_fs == NULL)
        return false;

    if (song->tag != NULL) {
        tag_free(song->tag);
        song->tag = NULL;
    }

    if (stat(path_fs, &st) < 0 || !S_ISREG(st.st_mode)) {
        g_free(path_fs);
        return false;
    }

    song->mtime = st.st_mtime;

    GMutex *mutex = NULL;
    GCond *cond;
#if !GCC_CHECK_VERSION(4, 2)
    /* work around "may be used uninitialized in this function"
       false positive */
    cond = NULL;
#endif

    do {
        /* load file tag */
        song->tag = tag_new();
        if (decoder_plugin_scan_file(plugin, path_fs,
                                     &full_tag_handler, song->tag))
            break;

        tag_free(song->tag);
        song->tag = NULL;

        /* fall back to stream tag */
        if (plugin->scan_stream != NULL) {
            /* open the input_stream (if not already
               open) */
            if (is == NULL) {
                mutex = g_mutex_new();
                cond = g_cond_new();
                is = input_stream_open(path_fs, mutex, cond,
                                       NULL);
            }

            /* now try the stream_tag() method */
            if (is != NULL) {
                song->tag = tag_new();
                if (decoder_plugin_scan_stream(plugin, is,
                                               &full_tag_handler,
                                               song->tag))
                    break;

                tag_free(song->tag);
                song->tag = NULL;

                input_stream_lock_seek(is, 0, SEEK_SET, NULL);
            }
        }

        plugin = decoder_plugin_from_suffix(suffix, plugin);
    } while (plugin != NULL);

    if (is != NULL)
        input_stream_close(is);

    if (mutex != NULL) {
        g_cond_free(cond);
        g_mutex_free(mutex);
    }

    if (song->tag != NULL && tag_is_empty(song->tag))
        tag_scan_fallback(path_fs, &full_tag_handler, song->tag);

    g_free(path_fs);
    return song->tag != NULL;
}