aboutsummaryrefslogtreecommitdiffstats
path: root/test/read_tags.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/read_tags.c')
-rw-r--r--test/read_tags.c88
1 files changed, 54 insertions, 34 deletions
diff --git a/test/read_tags.c b/test/read_tags.c
index 8906e1c8a..faf9a45c0 100644
--- a/test/read_tags.c
+++ b/test/read_tags.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
@@ -18,21 +18,23 @@
*/
#include "config.h"
+#include "io_thread.h"
#include "decoder_list.h"
#include "decoder_api.h"
#include "input_init.h"
#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>
#include <assert.h>
#include <unistd.h>
+#include <stdlib.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
@@ -50,8 +52,8 @@ idle_add(G_GNUC_UNUSED unsigned flags)
* No-op dummy.
*/
bool
-pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED int length,
- G_GNUC_UNUSED const struct audio_format *format,
+pcm_volume(G_GNUC_UNUSED void *buffer, G_GNUC_UNUSED size_t length,
+ G_GNUC_UNUSED enum sample_format format,
G_GNUC_UNUSED int volume)
{
return true;
@@ -89,7 +91,7 @@ decoder_read(G_GNUC_UNUSED struct decoder *decoder,
struct input_stream *is,
void *buffer, size_t length)
{
- return input_stream_read(is, buffer, length, NULL);
+ return input_stream_lock_read(is, buffer, length, NULL);
}
void
@@ -132,25 +134,38 @@ decoder_mixramp(G_GNUC_UNUSED struct decoder *decoder,
g_free(mixramp_end);
}
+static bool empty = true;
+
+static void
+print_duration(unsigned seconds, G_GNUC_UNUSED void *ctx)
+{
+ g_print("duration=%d\n", seconds);
+}
+
static void
-print_tag(const struct tag *tag)
+print_tag(enum tag_type type, const char *value, G_GNUC_UNUSED void *ctx)
{
- if (tag->time >= 0)
- g_print("time=%d\n", tag->time);
+ g_print("[%s]=%s\n", tag_item_names[type], value);
+ empty = false;
+}
- 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_pair(const char *name, const char *value, G_GNUC_UNUSED void *ctx)
+{
+ g_print("\"%s\"=%s\n", name, value);
}
+static const struct tag_handler print_handler = {
+ .duration = print_duration,
+ .tag = print_tag,
+ .pair = print_pair,
+};
+
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 */
@@ -166,7 +181,12 @@ int main(int argc, char **argv)
path = argv[2];
g_thread_init(NULL);
- tag_pool_init();
+ io_thread_init();
+ if (!io_thread_start(&error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
if (!input_stream_global_init(&error)) {
g_warning("%s", error->message);
@@ -182,9 +202,14 @@ int main(int argc, char **argv)
return 1;
}
- tag = decoder_plugin_tag_dup(plugin, path);
- if (tag == NULL && plugin->stream_tag != NULL) {
- struct input_stream *is = input_stream_open(path, &error);
+ 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();
+
+ struct input_stream *is =
+ input_stream_open(path, mutex, cond, &error);
if (is == NULL) {
g_printerr("Failed to open %s: %s\n",
@@ -193,33 +218,28 @@ 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);
+ g_mutex_free(mutex);
}
decoder_plugin_deinit_all();
input_stream_global_finish();
- if (tag == NULL) {
+ io_thread_deinit();
+
+ 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;
}