aboutsummaryrefslogtreecommitdiffstats
path: root/test/run_output.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/run_output.c')
-rw-r--r--test/run_output.c132
1 files changed, 78 insertions, 54 deletions
diff --git a/test/run_output.c b/test/run_output.c
index 5028068ff..c1d7a8120 100644
--- a/test/run_output.c
+++ b/test/run_output.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,6 +18,7 @@
*/
#include "config.h"
+#include "io_thread.h"
#include "output_plugin.h"
#include "output_internal.h"
#include "output_control.h"
@@ -28,6 +29,7 @@
#include "event_pipe.h"
#include "idle.h"
#include "playlist.h"
+#include "player_control.h"
#include "stdbin.h"
#include <glib.h>
@@ -35,6 +37,7 @@
#include <assert.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
struct playlist g_playlist;
@@ -104,7 +107,9 @@ load_audio_output(struct audio_output *ao, const char *name)
return false;
}
- success = audio_output_init(ao, param, &error);
+ static struct player_control dummy_player_control;
+
+ success = audio_output_init(ao, param, &dummy_player_control, &error);
if (!success) {
g_printerr("%s\n", error->message);
g_error_free(error);
@@ -113,16 +118,70 @@ load_audio_output(struct audio_output *ao, const char *name)
return success;
}
+static bool
+run_output(struct audio_output *ao, struct audio_format *audio_format)
+{
+ /* open the audio output */
+
+ GError *error = NULL;
+ if (!ao_plugin_open(ao->plugin, ao->data, audio_format, &error)) {
+ g_printerr("Failed to open audio output: %s\n",
+ error->message);
+ g_error_free(error);
+ return false;
+ }
+
+ struct audio_format_string af_string;
+ g_printerr("audio_format=%s\n",
+ audio_format_to_string(audio_format, &af_string));
+
+ size_t frame_size = audio_format_frame_size(audio_format);
+
+ /* play */
+
+ size_t length = 0;
+ char buffer[4096];
+ while (true) {
+ if (length < sizeof(buffer)) {
+ ssize_t nbytes = read(0, buffer + length,
+ sizeof(buffer) - length);
+ if (nbytes <= 0)
+ break;
+
+ length += (size_t)nbytes;
+ }
+
+ size_t play_length = (length / frame_size) * frame_size;
+ if (play_length > 0) {
+ size_t consumed = ao_plugin_play(ao->plugin, ao->data,
+ buffer, play_length,
+ &error);
+ if (consumed == 0) {
+ ao_plugin_close(ao->plugin, ao->data);
+ g_printerr("Failed to play: %s\n",
+ error->message);
+ g_error_free(error);
+ return false;
+ }
+
+ assert(consumed <= length);
+ assert(consumed % frame_size == 0);
+
+ length -= consumed;
+ memmove(buffer, buffer + consumed, length);
+ }
+ }
+
+ ao_plugin_close(ao->plugin, ao->data);
+ return true;
+}
+
int main(int argc, char **argv)
{
struct audio_output ao;
struct audio_format audio_format;
- struct audio_format_string af_string;
bool success;
GError *error = NULL;
- char buffer[4096];
- ssize_t nbytes;
- size_t frame_size, length = 0, play_length, consumed;
if (argc < 3 || argc > 4) {
g_printerr("Usage: run_output CONFIG NAME [FORMAT] <IN\n");
@@ -143,6 +202,13 @@ int main(int argc, char **argv)
return 1;
}
+ io_thread_init();
+ if (!io_thread_start(&error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return EXIT_FAILURE;
+ }
+
/* initialize the audio output */
if (!load_audio_output(&ao, argv[2]))
@@ -161,59 +227,17 @@ int main(int argc, char **argv)
}
}
- /* open the audio output */
-
- success = ao_plugin_open(ao.plugin, ao.data, &audio_format, &error);
- if (!success) {
- g_printerr("Failed to open audio output: %s\n",
- error->message);
- g_error_free(error);
- return 1;
- }
-
- g_printerr("audio_format=%s\n",
- audio_format_to_string(&audio_format, &af_string));
-
- frame_size = audio_format_frame_size(&audio_format);
-
- /* play */
-
- while (true) {
- if (length < sizeof(buffer)) {
- nbytes = read(0, buffer + length, sizeof(buffer) - length);
- if (nbytes <= 0)
- break;
-
- length += (size_t)nbytes;
- }
+ /* do it */
- play_length = (length / frame_size) * frame_size;
- if (play_length > 0) {
- consumed = ao_plugin_play(ao.plugin, ao.data,
- buffer, play_length,
- &error);
- if (consumed == 0) {
- g_printerr("Failed to play: %s\n",
- error->message);
- g_error_free(error);
- return 1;
- }
-
- assert(consumed <= length);
- assert(consumed % frame_size == 0);
-
- length -= consumed;
- memmove(buffer, buffer + consumed, length);
- }
- }
+ success = run_output(&ao, &audio_format);
/* cleanup and exit */
- ao_plugin_close(ao.plugin, ao.data);
- ao_plugin_finish(ao.plugin, ao.data);
- g_mutex_free(ao.mutex);
+ audio_output_destruct(&ao);
+
+ io_thread_deinit();
config_global_finish();
- return 0;
+ return success ? EXIT_SUCCESS : EXIT_FAILURE;
}