diff options
Diffstat (limited to '')
-rw-r--r-- | test/read_tags.cxx | 73 |
1 files changed, 31 insertions, 42 deletions
diff --git a/test/read_tags.cxx b/test/read_tags.cxx index 52b2561b8..91ac9c674 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2014 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,11 +18,11 @@ */ #include "config.h" -#include "IOThread.hxx" -#include "DecoderList.hxx" -#include "DecoderPlugin.hxx" -#include "InputInit.hxx" -#include "InputStream.hxx" +#include "ScopeIOThread.hxx" +#include "decoder/DecoderList.hxx" +#include "decoder/DecoderPlugin.hxx" +#include "input/Init.hxx" +#include "input/InputStream.hxx" #include "AudioFormat.hxx" #include "tag/TagHandler.hxx" #include "tag/TagId3.hxx" @@ -32,11 +32,14 @@ #include "thread/Cond.hxx" #include "Log.hxx" +#ifdef HAVE_GLIB #include <glib.h> +#endif #include <assert.h> #include <unistd.h> #include <stdlib.h> +#include <stdio.h> #ifdef HAVE_LOCALE_H #include <locale.h> @@ -45,22 +48,22 @@ static bool empty = true; static void -print_duration(unsigned seconds, gcc_unused void *ctx) +print_duration(SongTime duration, gcc_unused void *ctx) { - g_print("duration=%d\n", seconds); + printf("duration=%f\n", duration.ToDoubleS()); } static void print_tag(TagType type, const char *value, gcc_unused void *ctx) { - g_print("[%s]=%s\n", tag_item_names[type], value); + printf("[%s]=%s\n", tag_item_names[type], value); empty = false; } static void print_pair(const char *name, const char *value, gcc_unused void *ctx) { - g_print("\"%s\"=%s\n", name, value); + printf("\"%s\"=%s\n", name, value); } static const struct tag_handler print_handler = { @@ -71,7 +74,7 @@ static const struct tag_handler print_handler = { int main(int argc, char **argv) { - const char *decoder_name, *path; + const char *decoder_name; const struct DecoderPlugin *plugin; #ifdef HAVE_LOCALE_H @@ -80,19 +83,20 @@ int main(int argc, char **argv) #endif if (argc != 3) { - g_printerr("Usage: read_tags DECODER FILE\n"); - return 1; + fprintf(stderr, "Usage: read_tags DECODER FILE\n"); + return EXIT_FAILURE; } decoder_name = argv[1]; - path = argv[2]; + const Path path = Path::FromFS(argv[2]); +#ifdef HAVE_GLIB #if !GLIB_CHECK_VERSION(2,32,0) g_thread_init(NULL); #endif +#endif - io_thread_init(); - io_thread_start(); + const ScopeIOThread io_thread; Error error; if (!input_stream_global_init(error)) { @@ -104,8 +108,8 @@ int main(int argc, char **argv) plugin = decoder_plugin_from_name(decoder_name); if (plugin == NULL) { - g_printerr("No such decoder: %s\n", decoder_name); - return 1; + fprintf(stderr, "No such decoder: %s\n", decoder_name); + return EXIT_FAILURE; } bool success = plugin->ScanFile(path, print_handler, nullptr); @@ -113,45 +117,30 @@ int main(int argc, char **argv) Mutex mutex; Cond cond; - InputStream *is = InputStream::Open(path, mutex, cond, - error); + InputStream *is = InputStream::OpenReady(path.c_str(), + mutex, cond, + error); if (is == NULL) { - g_printerr("Failed to open %s: %s\n", - path, error.GetMessage()); - return 1; - } - - mutex.lock(); - - is->WaitReady(); - - if (!is->Check(error)) { - mutex.unlock(); - - g_printerr("Failed to read %s: %s\n", - path, error.GetMessage()); + FormatError(error, "Failed to open %s", path.c_str()); return EXIT_FAILURE; } - mutex.unlock(); - success = plugin->ScanStream(*is, print_handler, nullptr); - is->Close(); + delete is; } decoder_plugin_deinit_all(); input_stream_global_finish(); - io_thread_deinit(); if (!success) { - g_printerr("Failed to read tags\n"); - return 1; + fprintf(stderr, "Failed to read tags\n"); + return EXIT_FAILURE; } if (empty) { - tag_ape_scan2(Path::FromFS(path), &print_handler, NULL); + tag_ape_scan2(path, &print_handler, NULL); if (empty) - tag_id3_scan(Path::FromFS(path), &print_handler, NULL); + tag_id3_scan(path, &print_handler, NULL); } return 0; |