aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-02-11 19:12:02 +0100
committerMax Kellermann <max@duempel.org>2012-02-11 17:04:29 +0100
commit5d73215a8dad922c8e383f3837f3ec9e26503389 (patch)
tree8fc4b96d93a907054a05d3250f97bf4f68c6df85 /test
parentb7356bc526dbbd6fa00d40caff2addec10ae7c7e (diff)
downloadmpd-5d73215a8dad922c8e383f3837f3ec9e26503389.tar.gz
mpd-5d73215a8dad922c8e383f3837f3ec9e26503389.tar.xz
mpd-5d73215a8dad922c8e383f3837f3ec9e26503389.zip
decoder_plugin: scan tags with callback table
Pass a callback table to scan_file() and scan_stream(), instead of returning a tag object.
Diffstat (limited to 'test')
-rw-r--r--test/read_tags.c55
1 files changed, 25 insertions, 30 deletions
diff --git a/test/read_tags.c b/test/read_tags.c
index 86d508a5c..9fcf1acfe 100644
--- a/test/read_tags.c
+++ b/test/read_tags.c
@@ -25,9 +25,9 @@
#include "input_stream.h"
#include "audio_format.h"
#include "pcm_volume.h"
-#include "tag_pool.h"
#include "tag_ape.h"
#include "tag_id3.h"
+#include "tag_handler.h"
#include "idle.h"
#include <glib.h>
@@ -134,25 +134,31 @@ decoder_mixramp(G_GNUC_UNUSED struct decoder *decoder,
g_free(mixramp_end);
}
+static bool empty = true;
+
static void
-print_tag(const struct tag *tag)
+print_duration(unsigned seconds, G_GNUC_UNUSED void *ctx)
{
- if (tag->time >= 0)
- g_print("time=%d\n", tag->time);
+ g_print("duration=%d\n", seconds);
+}
- for (unsigned i = 0; i < tag->num_items; ++i)
- g_print("%s=%s\n",
- tag_item_names[tag->items[i]->type],
- tag->items[i]->value);
+static void
+print_tag(enum tag_type type, const char *value, G_GNUC_UNUSED void *ctx)
+{
+ g_print("%s=%s\n", tag_item_names[type], value);
+ empty = false;
}
+static const struct tag_handler print_handler = {
+ .duration = print_duration,
+ .tag = print_tag,
+};
+
int main(int argc, char **argv)
{
GError *error = NULL;
const char *decoder_name, *path;
const struct decoder_plugin *plugin;
- struct tag *tag;
- bool empty;
#ifdef HAVE_LOCALE_H
/* initialize locale */
@@ -175,8 +181,6 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
- tag_pool_init();
-
if (!input_stream_global_init(&error)) {
g_warning("%s", error->message);
g_error_free(error);
@@ -191,8 +195,9 @@ int main(int argc, char **argv)
return 1;
}
- tag = decoder_plugin_tag_dup(plugin, path);
- if (tag == NULL && plugin->stream_tag != NULL) {
+ bool success = decoder_plugin_scan_file(plugin, path,
+ &print_handler, NULL);
+ if (!success && plugin->scan_stream != NULL) {
GMutex *mutex = g_mutex_new();
GCond *cond = g_cond_new();
@@ -206,7 +211,8 @@ int main(int argc, char **argv)
return 1;
}
- tag = decoder_plugin_stream_tag(plugin, is);
+ success = decoder_plugin_scan_stream(plugin, is,
+ &print_handler, NULL);
input_stream_close(is);
g_cond_free(cond);
@@ -217,27 +223,16 @@ int main(int argc, char **argv)
input_stream_global_finish();
io_thread_deinit();
- if (tag == NULL) {
+ if (!success) {
g_printerr("Failed to read tags\n");
return 1;
}
- print_tag(tag);
-
- empty = tag_is_empty(tag);
- tag_free(tag);
-
if (empty) {
- tag = tag_ape_load(path);
- if (tag == NULL)
- tag = tag_id3_load(path);
- if (tag != NULL) {
- print_tag(tag);
- tag_free(tag);
- }
+ tag_ape_scan2(path, &print_handler, NULL);
+ if (empty)
+ tag_id3_scan(path, &print_handler, NULL);
}
- tag_pool_deinit();
-
return 0;
}