aboutsummaryrefslogtreecommitdiffstats
path: root/src/song_update.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/song_update.c')
-rw-r--r--src/song_update.c81
1 files changed, 43 insertions, 38 deletions
diff --git a/src/song_update.c b/src/song_update.c
index b418b600e..37f502a20 100644
--- a/src/song_update.c
+++ b/src/song_update.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -27,6 +27,7 @@
#include "tag_ape.h"
#include "tag_id3.h"
#include "tag.h"
+#include "tag_handler.h"
#include "input_stream.h"
#include <glib.h>
@@ -65,33 +66,12 @@ song_file_load(const char *path, struct directory *parent)
/**
* Attempts to load APE or ID3 tags from the specified file.
*/
-static struct tag *
-tag_load_fallback(const char *path)
+static bool
+tag_scan_fallback(const char *path,
+ const struct tag_handler *handler, void *handler_ctx)
{
- struct tag *tag = tag_ape_load(path);
- if (tag == NULL)
- tag = tag_id3_load(path);
- return tag;
-}
-
-/**
- * The decoder plugin failed to load any tags: fall back to the APE or
- * ID3 tag loader.
- */
-static struct tag *
-tag_fallback(const char *path, struct tag *tag)
-{
- struct tag *fallback = tag_load_fallback(path);
-
- if (fallback != NULL) {
- /* tag was successfully loaded: copy the song
- duration, and destroy the old (empty) tag */
- fallback->time = tag->time;
- tag_free(tag);
- return fallback;
- } else
- /* no APE/ID3 tag found: return the empty tag */
- return tag;
+ return tag_ape_scan2(path, handler, handler_ctx) ||
+ tag_id3_scan(path, handler, handler_ctx);
}
bool
@@ -131,27 +111,47 @@ song_file_update(struct song *song)
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 = decoder_plugin_tag_dup(plugin, path_fs);
- if (song->tag != NULL)
+ 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->stream_tag != NULL) {
+ if (plugin->scan_stream != NULL) {
/* open the input_stream (if not already
open) */
- if (is == NULL)
- is = input_stream_open(path_fs, NULL);
+ 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 = decoder_plugin_stream_tag(plugin,
- is);
- if (song->tag != NULL)
+ song->tag = tag_new();
+ if (decoder_plugin_scan_stream(plugin, is,
+ &full_tag_handler,
+ song->tag))
break;
- input_stream_seek(is, 0, SEEK_SET, NULL);
+ tag_free(song->tag);
+ song->tag = NULL;
+
+ input_stream_lock_seek(is, 0, SEEK_SET, NULL);
}
}
@@ -161,8 +161,13 @@ song_file_update(struct song *song)
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))
- song->tag = tag_fallback(path_fs, song->tag);
+ tag_scan_fallback(path_fs, &full_tag_handler, song->tag);
g_free(path_fs);
return song->tag != NULL;
@@ -190,7 +195,7 @@ song_file_update_inarchive(struct song *song)
tag_free(song->tag);
//accept every file that has music suffix
- //because we dont support tag reading throught
+ //because we don't support tag reading through
//input streams
song->tag = tag_new();