aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audio_format.c44
-rw-r--r--src/audio_format.h19
-rw-r--r--src/command.c9
-rw-r--r--src/decoder_api.c14
-rw-r--r--src/output_thread.c16
5 files changed, 80 insertions, 22 deletions
diff --git a/src/audio_format.c b/src/audio_format.c
new file mode 100644
index 000000000..f88735c73
--- /dev/null
+++ b/src/audio_format.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2003-2009 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "audio_format.h"
+
+#include <assert.h>
+#include <stdio.h>
+
+#if G_BYTE_ORDER == G_BIG_ENDIAN
+#define REVERSE_ENDIAN_SUFFIX "_le"
+#else
+#define REVERSE_ENDIAN_SUFFIX "_be"
+#endif
+
+const char *
+audio_format_to_string(const struct audio_format *af,
+ struct audio_format_string *s)
+{
+ assert(af != NULL);
+ assert(s != NULL);
+
+ snprintf(s->buffer, sizeof(s->buffer), "%u:%u%s:%u",
+ af->sample_rate, af->bits,
+ af->reverse_endian ? REVERSE_ENDIAN_SUFFIX : "",
+ af->channels);
+
+ return s->buffer;
+}
diff --git a/src/audio_format.h b/src/audio_format.h
index a4f5ba2e0..0c1e425a9 100644
--- a/src/audio_format.h
+++ b/src/audio_format.h
@@ -56,6 +56,13 @@ struct audio_format {
};
/**
+ * Buffer for audio_format_string().
+ */
+struct audio_format_string {
+ char buffer[24];
+};
+
+/**
* Clears the #audio_format object, i.e. sets all attributes to an
* undefined (invalid) value.
*/
@@ -219,4 +226,16 @@ static inline double audio_format_time_to_size(const struct audio_format *af)
return af->sample_rate * audio_format_frame_size(af);
}
+/**
+ * Renders the #audio_format object into a string, e.g. for printing
+ * it in a log file.
+ *
+ * @param af the #audio_format object
+ * @param s a buffer to print into
+ * @return the string, or NULL if the #audio_format object is invalid
+ */
+const char *
+audio_format_to_string(const struct audio_format *af,
+ struct audio_format_string *s);
+
#endif
diff --git a/src/command.c b/src/command.c
index 3466da4d1..db0bafa31 100644
--- a/src/command.c
+++ b/src/command.c
@@ -515,18 +515,19 @@ handle_status(struct client *client,
}
if (player_status.state != PLAYER_STATE_STOP) {
+ struct audio_format_string af_string;
+
client_printf(client,
COMMAND_STATUS_TIME ": %i:%i\n"
"elapsed: %1.3f\n"
COMMAND_STATUS_BITRATE ": %u\n"
- COMMAND_STATUS_AUDIO ": %u:%u:%u\n",
+ COMMAND_STATUS_AUDIO ": %s\n",
(int)(player_status.elapsed_time + 0.5),
(int)(player_status.total_time + 0.5),
player_status.elapsed_time,
player_status.bit_rate,
- player_status.audio_format.sample_rate,
- player_status.audio_format.bits,
- player_status.audio_format.channels);
+ audio_format_to_string(&player_status.audio_format,
+ &af_string));
}
if ((updateJobId = isUpdatingDB())) {
diff --git a/src/decoder_api.c b/src/decoder_api.c
index c6c23182e..eb316bc49 100644
--- a/src/decoder_api.c
+++ b/src/decoder_api.c
@@ -44,6 +44,7 @@ decoder_initialized(struct decoder *decoder,
bool seekable, float total_time)
{
struct decoder_control *dc = decoder->dc;
+ struct audio_format_string af_string;
assert(dc->state == DECODE_STATE_START);
assert(dc->pipe != NULL);
@@ -67,18 +68,15 @@ decoder_initialized(struct decoder *decoder,
player_lock_signal();
- g_debug("audio_format=%u:%u:%u, seekable=%s",
- dc->in_audio_format.sample_rate,
- dc->in_audio_format.bits,
- dc->in_audio_format.channels,
+ g_debug("audio_format=%s, seekable=%s",
+ audio_format_to_string(&dc->in_audio_format, &af_string),
seekable ? "true" : "false");
if (!audio_format_equals(&dc->in_audio_format,
&dc->out_audio_format))
- g_debug("converting to %u:%u:%u",
- dc->out_audio_format.sample_rate,
- dc->out_audio_format.bits,
- dc->out_audio_format.channels);
+ g_debug("converting to %s",
+ audio_format_to_string(&dc->out_audio_format,
+ &af_string));
}
char *decoder_get_uri(G_GNUC_UNUSED struct decoder *decoder)
diff --git a/src/output_thread.c b/src/output_thread.c
index 0b61ab171..fccbad5eb 100644
--- a/src/output_thread.c
+++ b/src/output_thread.c
@@ -93,6 +93,7 @@ ao_open(struct audio_output *ao)
bool success;
GError *error = NULL;
const struct audio_format *filter_audio_format;
+ struct audio_format_string af_string;
assert(!ao->open);
assert(ao->fail_timer == NULL);
@@ -145,20 +146,15 @@ ao_open(struct audio_output *ao)
ao->open = true;
g_debug("opened plugin=%s name=\"%s\" "
- "audio_format=%u:%u:%u:%u",
+ "audio_format=%s",
ao->plugin->name, ao->name,
- ao->out_audio_format.sample_rate,
- ao->out_audio_format.bits,
- ao->out_audio_format.channels,
- ao->out_audio_format.reverse_endian);
+ audio_format_to_string(&ao->out_audio_format, &af_string));
if (!audio_format_equals(&ao->in_audio_format,
&ao->out_audio_format))
- g_debug("converting from %u:%u:%u:%u",
- ao->in_audio_format.sample_rate,
- ao->in_audio_format.bits,
- ao->in_audio_format.channels,
- ao->in_audio_format.reverse_endian);
+ g_debug("converting from %s",
+ audio_format_to_string(&ao->in_audio_format,
+ &af_string));
}
static void