aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/decoder/_flac_common.c2
-rw-r--r--src/decoder/_flac_common.h2
-rw-r--r--src/decoder/_ogg_common.c2
-rw-r--r--src/decoder/_ogg_common.h2
-rw-r--r--src/decoder/audiofile_decoder_plugin.c6
-rw-r--r--src/decoder/dsdiff_decoder_plugin.c485
-rw-r--r--src/decoder/dsdiff_decoder_plugin.h25
-rw-r--r--src/decoder/faad_decoder_plugin.c6
-rw-r--r--src/decoder/ffmpeg_decoder_plugin.c62
-rw-r--r--src/decoder/flac_compat.h2
-rw-r--r--src/decoder/flac_decoder_plugin.c11
-rw-r--r--src/decoder/flac_metadata.c2
-rw-r--r--src/decoder/flac_metadata.h2
-rw-r--r--src/decoder/flac_pcm.c2
-rw-r--r--src/decoder/flac_pcm.h2
-rw-r--r--src/decoder/fluidsynth_decoder_plugin.c4
-rw-r--r--src/decoder/mad_decoder_plugin.c4
-rw-r--r--src/decoder/mikmod_decoder_plugin.c2
-rw-r--r--src/decoder/modplug_decoder_plugin.c4
-rw-r--r--src/decoder/mp4ff_decoder_plugin.c5
-rw-r--r--src/decoder/mpcdec_decoder_plugin.c4
-rw-r--r--src/decoder/mpg123_decoder_plugin.c44
-rw-r--r--src/decoder/oggflac_decoder_plugin.c354
-rw-r--r--src/decoder/pcm_decoder_plugin.c89
-rw-r--r--src/decoder/pcm_decoder_plugin.h33
-rw-r--r--src/decoder/sidplay_decoder_plugin.cxx2
-rw-r--r--src/decoder/sndfile_decoder_plugin.c6
-rw-r--r--src/decoder/vorbis_decoder_plugin.c6
-rw-r--r--src/decoder/wavpack_decoder_plugin.c14
-rw-r--r--src/decoder/wildmidi_decoder_plugin.c2
-rw-r--r--src/decoder_api.c103
-rw-r--r--src/decoder_api.h2
-rw-r--r--src/decoder_buffer.c2
-rw-r--r--src/decoder_buffer.h2
-rw-r--r--src/decoder_command.h2
-rw-r--r--src/decoder_control.c28
-rw-r--r--src/decoder_control.h18
-rw-r--r--src/decoder_internal.c37
-rw-r--r--src/decoder_internal.h4
-rw-r--r--src/decoder_list.c8
-rw-r--r--src/decoder_list.h2
-rw-r--r--src/decoder_plugin.c4
-rw-r--r--src/decoder_plugin.h2
-rw-r--r--src/decoder_print.c2
-rw-r--r--src/decoder_print.h2
-rw-r--r--src/decoder_thread.c65
-rw-r--r--src/decoder_thread.h2
47 files changed, 879 insertions, 592 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c
index 8dd22a253..fc42e5913 100644
--- a/src/decoder/_flac_common.c
+++ b/src/decoder/_flac_common.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
diff --git a/src/decoder/_flac_common.h b/src/decoder/_flac_common.h
index 5c59ee123..1f4cbb273 100644
--- a/src/decoder/_flac_common.h
+++ b/src/decoder/_flac_common.h
@@ -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
diff --git a/src/decoder/_ogg_common.c b/src/decoder/_ogg_common.c
index bd0650ac4..bedd3de61 100644
--- a/src/decoder/_ogg_common.c
+++ b/src/decoder/_ogg_common.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
diff --git a/src/decoder/_ogg_common.h b/src/decoder/_ogg_common.h
index f8446c69c..85e4ebba6 100644
--- a/src/decoder/_ogg_common.h
+++ b/src/decoder/_ogg_common.h
@@ -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
diff --git a/src/decoder/audiofile_decoder_plugin.c b/src/decoder/audiofile_decoder_plugin.c
index a8311a3c9..8d6236a57 100644
--- a/src/decoder/audiofile_decoder_plugin.c
+++ b/src/decoder/audiofile_decoder_plugin.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
@@ -54,7 +54,7 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
GError *error = NULL;
size_t nbytes;
- nbytes = input_stream_read(is, data, length, &error);
+ nbytes = input_stream_lock_read(is, data, length, &error);
if (nbytes == 0 && error != NULL) {
g_warning("%s", error->message);
g_error_free(error);
@@ -91,7 +91,7 @@ audiofile_file_seek(AFvirtualfile *vfile, long offset, int is_relative)
{
struct input_stream *is = (struct input_stream *) vfile->closure;
int whence = (is_relative ? SEEK_CUR : SEEK_SET);
- if (input_stream_seek(is, offset, whence, NULL)) {
+ if (input_stream_lock_seek(is, offset, whence, NULL)) {
return is->offset;
} else {
return -1;
diff --git a/src/decoder/dsdiff_decoder_plugin.c b/src/decoder/dsdiff_decoder_plugin.c
new file mode 100644
index 000000000..d1b12e0a7
--- /dev/null
+++ b/src/decoder/dsdiff_decoder_plugin.c
@@ -0,0 +1,485 @@
+/*
+ * 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
+ * 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 "config.h"
+#include "dsdiff_decoder_plugin.h"
+#include "decoder_api.h"
+#include "audio_check.h"
+#include "dsd2pcm/dsd2pcm.h"
+
+#include <unistd.h>
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "dsdiff"
+
+struct dsdiff_id {
+ char value[4];
+};
+
+struct dsdiff_header {
+ struct dsdiff_id id;
+ uint32_t size_high, size_low;
+ struct dsdiff_id format;
+};
+
+struct dsdiff_chunk_header {
+ struct dsdiff_id id;
+ uint32_t size_high, size_low;
+};
+
+struct dsdiff_metadata {
+ unsigned sample_rate, channels;
+};
+
+static bool
+dsdiff_id_equals(const struct dsdiff_id *id, const char *s)
+{
+ assert(id != NULL);
+ assert(s != NULL);
+ assert(strlen(s) == sizeof(id->value));
+
+ return memcmp(id->value, s, sizeof(id->value)) == 0;
+}
+
+/**
+ * Read the "size" attribute from the specified header, converting it
+ * to the host byte order if needed.
+ */
+G_GNUC_CONST
+static uint64_t
+dsdiff_chunk_size(const struct dsdiff_chunk_header *header)
+{
+ return (((uint64_t)GUINT32_FROM_BE(header->size_high)) << 32) |
+ ((uint64_t)GUINT32_FROM_BE(header->size_low));
+}
+
+static bool
+dsdiff_read(struct decoder *decoder, struct input_stream *is,
+ void *data, size_t length)
+{
+ size_t nbytes = decoder_read(decoder, is, data, length);
+ return nbytes == length;
+}
+
+static bool
+dsdiff_read_id(struct decoder *decoder, struct input_stream *is,
+ struct dsdiff_id *id)
+{
+ return dsdiff_read(decoder, is, id, sizeof(*id));
+}
+
+static bool
+dsdiff_read_chunk_header(struct decoder *decoder, struct input_stream *is,
+ struct dsdiff_chunk_header *header)
+{
+ return dsdiff_read(decoder, is, header, sizeof(*header));
+}
+
+static bool
+dsdiff_read_payload(struct decoder *decoder, struct input_stream *is,
+ const struct dsdiff_chunk_header *header,
+ void *data, size_t length)
+{
+ uint64_t size = dsdiff_chunk_size(header);
+ if (size != (uint64_t)length)
+ return false;
+
+ size_t nbytes = decoder_read(decoder, is, data, length);
+ return nbytes == length;
+}
+
+/**
+ * Skip the #input_stream to the specified offset.
+ */
+static bool
+dsdiff_skip_to(struct decoder *decoder, struct input_stream *is,
+ goffset offset)
+{
+ if (is->seekable)
+ return input_stream_seek(is, offset, SEEK_SET, NULL);
+
+ if (is->offset > offset)
+ return false;
+
+ char buffer[8192];
+ while (is->offset < offset) {
+ size_t length = sizeof(buffer);
+ if (offset - is->offset < (goffset)length)
+ length = offset - is->offset;
+
+ size_t nbytes = decoder_read(decoder, is, buffer, length);
+ if (nbytes == 0)
+ return false;
+ }
+
+ assert(is->offset == offset);
+ return true;
+}
+
+/**
+ * Skip some bytes from the #input_stream.
+ */
+static bool
+dsdiff_skip(struct decoder *decoder, struct input_stream *is,
+ goffset delta)
+{
+ assert(delta >= 0);
+
+ if (delta == 0)
+ return true;
+
+ if (is->seekable)
+ return input_stream_seek(is, delta, SEEK_CUR, NULL);
+
+ char buffer[8192];
+ while (delta > 0) {
+ size_t length = sizeof(buffer);
+ if ((goffset)length > delta)
+ length = delta;
+
+ size_t nbytes = decoder_read(decoder, is, buffer, length);
+ if (nbytes == 0)
+ return false;
+
+ delta -= nbytes;
+ }
+
+ return true;
+}
+
+/**
+ * Read and parse a "SND" chunk inside "PROP".
+ */
+static bool
+dsdiff_read_prop_snd(struct decoder *decoder, struct input_stream *is,
+ struct dsdiff_metadata *metadata,
+ goffset end_offset)
+{
+ struct dsdiff_chunk_header header;
+ while ((goffset)(is->offset + sizeof(header)) <= end_offset) {
+ if (!dsdiff_read_chunk_header(decoder, is, &header))
+ return false;
+
+ goffset chunk_end_offset =
+ is->offset + dsdiff_chunk_size(&header);
+ if (chunk_end_offset > end_offset)
+ return false;
+
+ if (dsdiff_id_equals(&header.id, "FS ")) {
+ uint32_t sample_rate;
+ if (!dsdiff_read_payload(decoder, is, &header,
+ &sample_rate,
+ sizeof(sample_rate)))
+ return false;
+
+ metadata->sample_rate = GUINT32_FROM_BE(sample_rate);
+ } else if (dsdiff_id_equals(&header.id, "CHNL")) {
+ uint16_t channels;
+ if (dsdiff_chunk_size(&header) < sizeof(channels) ||
+ !dsdiff_read(decoder, is,
+ &channels, sizeof(channels)) ||
+ !dsdiff_skip_to(decoder, is, chunk_end_offset))
+ return false;
+
+ metadata->channels = GUINT16_FROM_BE(channels);
+ } else if (dsdiff_id_equals(&header.id, "CMPR")) {
+ struct dsdiff_id type;
+ if (dsdiff_chunk_size(&header) < sizeof(type) ||
+ !dsdiff_read(decoder, is,
+ &type, sizeof(type)) ||
+ !dsdiff_skip_to(decoder, is, chunk_end_offset))
+ return false;
+
+ if (!dsdiff_id_equals(&type, "DSD "))
+ /* only uincompressed DSD audio data
+ is implemented */
+ return false;
+ } else {
+ /* ignore unknown chunk */
+
+ if (!dsdiff_skip_to(decoder, is, chunk_end_offset))
+ return false;
+ }
+ }
+
+ return is->offset == end_offset;
+}
+
+/**
+ * Read and parse a "PROP" chunk.
+ */
+static bool
+dsdiff_read_prop(struct decoder *decoder, struct input_stream *is,
+ struct dsdiff_metadata *metadata,
+ const struct dsdiff_chunk_header *prop_header)
+{
+ uint64_t prop_size = dsdiff_chunk_size(prop_header);
+ goffset end_offset = is->offset + prop_size;
+
+ struct dsdiff_id prop_id;
+ if (prop_size < sizeof(prop_id) ||
+ !dsdiff_read_id(decoder, is, &prop_id))
+ return false;
+
+ if (dsdiff_id_equals(&prop_id, "SND "))
+ return dsdiff_read_prop_snd(decoder, is, metadata, end_offset);
+ else
+ /* ignore unknown PROP chunk */
+ return dsdiff_skip_to(decoder, is, end_offset);
+}
+
+/**
+ * Read and parse all metadata chunks at the beginning. Stop when the
+ * first "DSD" chunk is seen, and return its header in the
+ * "chunk_header" parameter.
+ */
+static bool
+dsdiff_read_metadata(struct decoder *decoder, struct input_stream *is,
+ struct dsdiff_metadata *metadata,
+ struct dsdiff_chunk_header *chunk_header)
+{
+ struct dsdiff_header header;
+ if (!dsdiff_read(decoder, is, &header, sizeof(header)) ||
+ !dsdiff_id_equals(&header.id, "FRM8") ||
+ !dsdiff_id_equals(&header.format, "DSD "))
+ return false;
+
+ while (true) {
+ if (!dsdiff_read_chunk_header(decoder, is, chunk_header))
+ return false;
+
+ if (dsdiff_id_equals(&chunk_header->id, "PROP")) {
+ if (!dsdiff_read_prop(decoder, is, metadata,
+ chunk_header))
+ return false;
+ } else if (dsdiff_id_equals(&chunk_header->id, "DSD ")) {
+ /* done with metadata */
+ return true;
+ } else {
+ /* ignore unknown chunk */
+
+ uint64_t chunk_size = dsdiff_chunk_size(chunk_header);
+ goffset chunk_end_offset = is->offset + chunk_size;
+
+ if (!dsdiff_skip_to(decoder, is, chunk_end_offset))
+ return false;
+ }
+ }
+}
+
+G_GNUC_CONST
+static inline int32_t
+clip(int32_t min, int32_t value, int32_t max)
+{
+ if (G_UNLIKELY(value < min))
+ value = min;
+ else if (G_UNLIKELY(value > max))
+ value = max;
+ return value;
+}
+
+/**
+ * Convert an array of float samples [-1 .. +1] to padded 24 bit
+ * samples.
+ */
+static void
+float_to_uint24(int32_t *dest, const float *src, size_t length)
+{
+ const float *src_end = src + length;
+ while (src < src_end) {
+ float f_sample = *src++ * 8388608;
+ *dest++ = clip(-8388608, (int32_t)f_sample, 8388607);
+ }
+}
+
+/**
+ * Decode one "DSD" chunk.
+ */
+static bool
+dsdiff_decode_chunk(struct decoder *decoder, struct input_stream *is,
+ unsigned channels,
+ dsd2pcm_ctx **dsd2pcm, uint64_t chunk_size)
+{
+ uint8_t buffer[8192];
+ const size_t sample_size = sizeof(buffer[0]);
+ const size_t frame_size = channels * sample_size;
+ const unsigned buffer_frames = sizeof(buffer) / frame_size;
+ const unsigned buffer_samples = buffer_frames * frame_size;
+ const size_t buffer_size = buffer_samples * sample_size;
+ float f_buffer[G_N_ELEMENTS(buffer)];
+ int32_t i_buffer[G_N_ELEMENTS(buffer)];
+
+ while (chunk_size > 0) {
+ /* see how much aligned data from the remaining chunk
+ fits into the local buffer */
+ unsigned now_frames = buffer_frames;
+ size_t now_size = buffer_size;
+ unsigned now_samples = buffer_samples;
+ if (chunk_size < (uint64_t)now_size) {
+ now_frames = (unsigned)chunk_size / frame_size;
+ now_size = now_frames * frame_size;
+ now_samples = now_frames * channels;
+ }
+
+ size_t nbytes = decoder_read(decoder, is, buffer, now_size);
+ if (nbytes != now_size)
+ return false;
+
+ chunk_size -= nbytes;
+
+ /* invoke the dsp2pcm library, once for each
+ channel */
+
+ for (unsigned c = 0; c < channels; ++c)
+ dsd2pcm_translate(dsd2pcm[c], now_frames,
+ buffer + c, channels,
+ true, f_buffer + c, channels);
+
+ /* convert to integer and submit to the decoder API */
+
+ float_to_uint24(i_buffer, f_buffer, now_samples);
+ enum decoder_command cmd =
+ decoder_data(decoder, is, i_buffer,
+ now_samples * sizeof(i_buffer[0]),
+ 0);
+ switch (cmd) {
+ case DECODE_COMMAND_NONE:
+ break;
+
+ case DECODE_COMMAND_START:
+ case DECODE_COMMAND_STOP:
+ return false;
+
+ case DECODE_COMMAND_SEEK:
+ /* not implemented yet */
+ decoder_seek_error(decoder);
+ break;
+ }
+ }
+
+ return dsdiff_skip(decoder, is, chunk_size);
+}
+
+static void
+dsdiff_stream_decode(struct decoder *decoder, struct input_stream *is)
+{
+ struct dsdiff_metadata metadata = {
+ .sample_rate = 0,
+ .channels = 0,
+ };
+
+ struct dsdiff_chunk_header chunk_header;
+ if (!dsdiff_read_metadata(decoder, is, &metadata, &chunk_header))
+ return;
+
+ GError *error = NULL;
+ struct audio_format audio_format;
+ if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
+ SAMPLE_FORMAT_S24_P32,
+ metadata.channels, &error)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ /* initialize the dsd2pcm library */
+
+ dsd2pcm_ctx *dsd2pcm[MAX_CHANNELS];
+ for (unsigned i = 0; i < metadata.channels; ++i) {
+ dsd2pcm[i] = dsd2pcm_init();
+ if (dsd2pcm[i] == NULL) {
+ for (unsigned j = 0; j < i; ++j)
+ dsd2pcm_destroy(dsd2pcm[j]);
+ return;
+ }
+ }
+
+ /* success: file was recognized */
+
+ decoder_initialized(decoder, &audio_format, false, -1);
+
+ /* every iteration of the following loop decodes one "DSD"
+ chunk */
+
+ while (true) {
+ uint64_t chunk_size = dsdiff_chunk_size(&chunk_header);
+
+ if (dsdiff_id_equals(&chunk_header.id, "DSD ")) {
+ if (!dsdiff_decode_chunk(decoder, is,
+ metadata.channels,
+ dsd2pcm, chunk_size))
+ break;
+ } else {
+ /* ignore other chunks */
+
+ if (!dsdiff_skip(decoder, is, chunk_size))
+ break;
+ }
+
+ /* read next chunk header; the first one was read by
+ dsdiff_read_metadata() */
+
+ if (!dsdiff_read_chunk_header(decoder, is, &chunk_header))
+ break;
+ }
+
+ for (unsigned i = 0; i < metadata.channels; ++i)
+ dsd2pcm_destroy(dsd2pcm[i]);
+}
+
+static struct tag *
+dsdiff_stream_tag(struct input_stream *is)
+{
+ struct dsdiff_metadata metadata = {
+ .sample_rate = 0,
+ .channels = 0,
+ };
+
+ struct dsdiff_chunk_header chunk_header;
+ if (!dsdiff_read_metadata(NULL, is, &metadata, &chunk_header))
+ return NULL;
+
+ struct audio_format audio_format;
+ if (!audio_format_init_checked(&audio_format, metadata.sample_rate / 8,
+ SAMPLE_FORMAT_S24_P32,
+ metadata.channels, NULL))
+ /* refuse to parse files which we cannot play anyway */
+ return NULL;
+
+ /* no total time estimate, no tags implemented yet */
+ return tag_new();
+}
+
+static const char *const dsdiff_suffixes[] = {
+ "dff",
+ NULL
+};
+
+static const char *const dsdiff_mime_types[] = {
+ "application/x-dff",
+ NULL
+};
+
+const struct decoder_plugin dsdiff_decoder_plugin = {
+ .name = "dsdiff",
+ .stream_decode = dsdiff_stream_decode,
+ .stream_tag = dsdiff_stream_tag,
+ .suffixes = dsdiff_suffixes,
+ .mime_types = dsdiff_mime_types,
+};
diff --git a/src/decoder/dsdiff_decoder_plugin.h b/src/decoder/dsdiff_decoder_plugin.h
new file mode 100644
index 000000000..34e1438de
--- /dev/null
+++ b/src/decoder/dsdiff_decoder_plugin.h
@@ -0,0 +1,25 @@
+/*
+ * 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
+ * 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.
+ */
+
+#ifndef MPD_DECODER_DSDIFF_H
+#define MPD_DECODER_DSDIFF_H
+
+extern const struct decoder_plugin dsdiff_decoder_plugin;
+
+#endif
diff --git a/src/decoder/faad_decoder_plugin.c b/src/decoder/faad_decoder_plugin.c
index 8f932ad58..91aa5392a 100644
--- a/src/decoder/faad_decoder_plugin.c
+++ b/src/decoder/faad_decoder_plugin.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
@@ -205,7 +205,7 @@ faad_song_duration(struct decoder_buffer *buffer, struct input_stream *is)
/* obtain the duration from the ADTS header */
float song_length = adts_song_duration(buffer);
- input_stream_seek(is, tagsize, SEEK_SET, NULL);
+ input_stream_lock_seek(is, tagsize, SEEK_SET, NULL);
data = decoder_buffer_read(buffer, &length);
if (data != NULL)
@@ -406,7 +406,7 @@ faad_stream_decode(struct decoder *mpd_decoder, struct input_stream *is)
faacDecSetConfiguration(decoder, config);
while (!decoder_buffer_is_full(buffer) &&
- !input_stream_eof(is) &&
+ !input_stream_lock_eof(is) &&
decoder_get_command(mpd_decoder) == DECODE_COMMAND_NONE) {
adts_find_frame(buffer);
decoder_buffer_fill(buffer);
diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c
index ba47b2c2c..2923c1400 100644
--- a/src/decoder/ffmpeg_decoder_plugin.c
+++ b/src/decoder/ffmpeg_decoder_plugin.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
@@ -32,22 +32,14 @@
#include <sys/stat.h>
#include <unistd.h>
-#ifdef OLD_FFMPEG_INCLUDES
-#include <avcodec.h>
-#include <avformat.h>
-#include <avio.h>
-#else
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
#include <libavutil/log.h>
-#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ffmpeg"
-#ifndef OLD_FFMPEG_INCLUDES
-
static GLogLevelFlags
level_ffmpeg_to_glib(int level)
{
@@ -79,7 +71,6 @@ mpd_ffmpeg_log_callback(G_GNUC_UNUSED void *ptr, int level,
}
}
-#endif /* !OLD_FFMPEG_INCLUDES */
#ifndef AV_VERSION_INT
#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
@@ -114,7 +105,7 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
if (whence == AVSEEK_SIZE)
return stream->input->size;
- if (!input_stream_seek(stream->input, pos, whence, NULL))
+ if (!input_stream_lock_seek(stream->input, pos, whence, NULL))
return -1;
return stream->input->offset;
@@ -126,11 +117,19 @@ mpd_ffmpeg_stream_open(struct decoder *decoder, struct input_stream *input)
struct mpd_ffmpeg_stream *stream = g_new(struct mpd_ffmpeg_stream, 1);
stream->decoder = decoder;
stream->input = input;
+#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0)
+ stream->io = avio_alloc_context(stream->buffer, sizeof(stream->buffer),
+ false, stream,
+ mpd_ffmpeg_stream_read, NULL,
+ input->seekable
+ ? mpd_ffmpeg_stream_seek : NULL);
+#else
stream->io = av_alloc_put_byte(stream->buffer, sizeof(stream->buffer),
false, stream,
mpd_ffmpeg_stream_read, NULL,
input->seekable
? mpd_ffmpeg_stream_seek : NULL);
+#endif
if (stream->io == NULL) {
g_free(stream);
return NULL;
@@ -176,9 +175,7 @@ mpd_ffmpeg_stream_close(struct mpd_ffmpeg_stream *stream)
static bool
ffmpeg_init(G_GNUC_UNUSED const struct config_param *param)
{
-#ifndef OLD_FFMPEG_INCLUDES
av_log_set_callback(mpd_ffmpeg_log_callback);
-#endif
av_register_all();
return true;
@@ -299,7 +296,6 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
static enum sample_format
ffmpeg_sample_format(G_GNUC_UNUSED const AVCodecContext *codec_context)
{
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(51, 41, 0)
switch (codec_context->sample_fmt) {
case SAMPLE_FMT_S16:
return SAMPLE_FORMAT_S16;
@@ -312,10 +308,6 @@ ffmpeg_sample_format(G_GNUC_UNUSED const AVCodecContext *codec_context)
codec_context->sample_fmt);
return SAMPLE_FORMAT_UNDEFINED;
}
-#else
- /* XXX fixme 16-bit for older ffmpeg (13 Aug 2007) */
- return SAMPLE_FORMAT_S16;
-#endif
}
static AVInputFormat *
@@ -328,7 +320,8 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
unsigned char *buffer = g_malloc(BUFFER_SIZE);
size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
- if (nbytes <= PADDING || !input_stream_seek(is, 0, SEEK_SET, NULL)) {
+ if (nbytes <= PADDING ||
+ !input_stream_lock_seek(is, 0, SEEK_SET, NULL)) {
g_free(buffer);
return NULL;
}
@@ -471,7 +464,6 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
mpd_ffmpeg_stream_close(stream);
}
-#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
typedef struct ffmpeg_tag_map {
enum tag_type type;
const char *name;
@@ -522,8 +514,6 @@ ffmpeg_copy_metadata(struct tag *tag,
return mt != NULL;
}
-#endif
-
//no tag reading in ffmpeg, check if playable
static struct tag *
ffmpeg_stream_tag(struct input_stream *is)
@@ -555,8 +545,9 @@ ffmpeg_stream_tag(struct input_stream *is)
? f->duration / AV_TIME_BASE
: 0;
-#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52,101,0)
av_metadata_conv(f, NULL, f->iformat->metadata_conv);
+#endif
for (unsigned i = 0; i < sizeof(ffmpeg_tag_maps)/sizeof(ffmpeg_tag_map); i++) {
int idx = ffmpeg_find_audio_stream(f);
@@ -564,31 +555,6 @@ ffmpeg_stream_tag(struct input_stream *is)
if (idx >= 0)
ffmpeg_copy_metadata(tag, f->streams[idx]->metadata, ffmpeg_tag_maps[i]);
}
-#else
- if (f->author[0])
- tag_add_item(tag, TAG_ARTIST, f->author);
- if (f->title[0])
- tag_add_item(tag, TAG_TITLE, f->title);
- if (f->album[0])
- tag_add_item(tag, TAG_ALBUM, f->album);
-
- if (f->track > 0) {
- char buffer[16];
- snprintf(buffer, sizeof(buffer), "%d", f->track);
- tag_add_item(tag, TAG_TRACK, buffer);
- }
-
- if (f->comment[0])
- tag_add_item(tag, TAG_COMMENT, f->comment);
- if (f->genre[0])
- tag_add_item(tag, TAG_GENRE, f->genre);
- if (f->year > 0) {
- char buffer[16];
- snprintf(buffer, sizeof(buffer), "%d", f->year);
- tag_add_item(tag, TAG_DATE, buffer);
- }
-
-#endif
av_close_input_stream(f);
mpd_ffmpeg_stream_close(stream);
diff --git a/src/decoder/flac_compat.h b/src/decoder/flac_compat.h
index d597690a0..9a30acc26 100644
--- a/src/decoder/flac_compat.h
+++ b/src/decoder/flac_compat.h
@@ -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
diff --git a/src/decoder/flac_decoder_plugin.c b/src/decoder/flac_decoder_plugin.c
index 9d980b79d..2a826f862 100644
--- a/src/decoder/flac_decoder_plugin.c
+++ b/src/decoder/flac_decoder_plugin.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
@@ -50,7 +50,7 @@ flac_read_cb(G_GNUC_UNUSED const FLAC__StreamDecoder *fd,
if (r == 0) {
if (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE ||
- input_stream_eof(data->input_stream))
+ input_stream_lock_eof(data->input_stream))
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
@@ -68,7 +68,8 @@ flac_seek_cb(G_GNUC_UNUSED const FLAC__StreamDecoder *fd,
if (!data->input_stream->seekable)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
- if (!input_stream_seek(data->input_stream, offset, SEEK_SET, NULL))
+ if (!input_stream_lock_seek(data->input_stream, offset, SEEK_SET,
+ NULL))
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
@@ -109,7 +110,7 @@ flac_eof_cb(G_GNUC_UNUSED const FLAC__StreamDecoder *fd, void *fdata)
return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE &&
decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) ||
- input_stream_eof(data->input_stream);
+ input_stream_lock_eof(data->input_stream);
}
static void
@@ -449,7 +450,7 @@ oggflac_decode(struct decoder *decoder, struct input_stream *input_stream)
/* rewind the stream, because ogg_stream_type_detect() has
moved it */
- input_stream_seek(input_stream, 0, SEEK_SET, NULL);
+ input_stream_lock_seek(input_stream, 0, SEEK_SET, NULL);
flac_decode_internal(decoder, input_stream, true);
}
diff --git a/src/decoder/flac_metadata.c b/src/decoder/flac_metadata.c
index 5b94fd426..a19220572 100644
--- a/src/decoder/flac_metadata.c
+++ b/src/decoder/flac_metadata.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
diff --git a/src/decoder/flac_metadata.h b/src/decoder/flac_metadata.h
index e52b0fb82..01bc1924a 100644
--- a/src/decoder/flac_metadata.h
+++ b/src/decoder/flac_metadata.h
@@ -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
diff --git a/src/decoder/flac_pcm.c b/src/decoder/flac_pcm.c
index bf6e2612c..3b56d50bd 100644
--- a/src/decoder/flac_pcm.c
+++ b/src/decoder/flac_pcm.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
diff --git a/src/decoder/flac_pcm.h b/src/decoder/flac_pcm.h
index bccfc645c..a931998c1 100644
--- a/src/decoder/flac_pcm.h
+++ b/src/decoder/flac_pcm.h
@@ -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
diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/fluidsynth_decoder_plugin.c
index b9a2d0d99..814a7b554 100644
--- a/src/decoder/fluidsynth_decoder_plugin.c
+++ b/src/decoder/fluidsynth_decoder_plugin.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
@@ -102,7 +102,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs)
fluid_player_t *player;
char *path_dup;
int ret;
- Timer *timer;
+ struct timer *timer;
enum decoder_command cmd;
soundfont_path =
diff --git a/src/decoder/mad_decoder_plugin.c b/src/decoder/mad_decoder_plugin.c
index 2c2906c5c..8bf3f6546 100644
--- a/src/decoder/mad_decoder_plugin.c
+++ b/src/decoder/mad_decoder_plugin.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
@@ -168,7 +168,7 @@ mp3_data_init(struct mp3_data *data, struct decoder *decoder,
static bool mp3_seek(struct mp3_data *data, long offset)
{
- if (!input_stream_seek(data->input_stream, offset, SEEK_SET, NULL))
+ if (!input_stream_lock_seek(data->input_stream, offset, SEEK_SET, NULL))
return false;
mad_stream_buffer(&data->stream, data->input_buffer, 0);
diff --git a/src/decoder/mikmod_decoder_plugin.c b/src/decoder/mikmod_decoder_plugin.c
index 91478e86f..9dd5a79b6 100644
--- a/src/decoder/mikmod_decoder_plugin.c
+++ b/src/decoder/mikmod_decoder_plugin.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
diff --git a/src/decoder/modplug_decoder_plugin.c b/src/decoder/modplug_decoder_plugin.c
index 037c2fd74..9345dd240 100644
--- a/src/decoder/modplug_decoder_plugin.c
+++ b/src/decoder/modplug_decoder_plugin.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
@@ -62,7 +62,7 @@ static GByteArray *mod_loadfile(struct decoder *decoder, struct input_stream *is
while (true) {
ret = decoder_read(decoder, is, data, MODPLUG_READ_BLOCK);
if (ret == 0) {
- if (input_stream_eof(is))
+ if (input_stream_lock_eof(is))
/* end of file */
break;
diff --git a/src/decoder/mp4ff_decoder_plugin.c b/src/decoder/mp4ff_decoder_plugin.c
index 861b08194..6475211a4 100644
--- a/src/decoder/mp4ff_decoder_plugin.c
+++ b/src/decoder/mp4ff_decoder_plugin.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
@@ -102,7 +102,8 @@ mp4_seek(void *user_data, uint64_t position)
{
struct mp4ff_input_stream *mis = user_data;
- return input_stream_seek(mis->input_stream, position, SEEK_SET, NULL)
+ return input_stream_lock_seek(mis->input_stream, position, SEEK_SET,
+ NULL)
? 0 : -1;
}
diff --git a/src/decoder/mpcdec_decoder_plugin.c b/src/decoder/mpcdec_decoder_plugin.c
index eaf470a40..7864c0790 100644
--- a/src/decoder/mpcdec_decoder_plugin.c
+++ b/src/decoder/mpcdec_decoder_plugin.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
@@ -61,7 +61,7 @@ mpc_seek_cb(cb_first_arg, mpc_int32_t offset)
{
struct mpc_decoder_data *data = (struct mpc_decoder_data *) cb_data;
- return input_stream_seek(data->is, offset, SEEK_SET, NULL);
+ return input_stream_lock_seek(data->is, offset, SEEK_SET, NULL);
}
static mpc_int32_t
diff --git a/src/decoder/mpg123_decoder_plugin.c b/src/decoder/mpg123_decoder_plugin.c
index 7b48ebfaf..224f3db2a 100644
--- a/src/decoder/mpg123_decoder_plugin.c
+++ b/src/decoder/mpg123_decoder_plugin.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
@@ -24,6 +24,7 @@
#include <glib.h>
#include <mpg123.h>
+#include <stdio.h>
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "mpg123"
@@ -105,6 +106,7 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
int error;
off_t num_samples;
enum decoder_command cmd;
+ struct mpg123_frameinfo info;
/* open the file */
@@ -124,10 +126,25 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
/* tell MPD core we're ready */
- decoder_initialized(decoder, &audio_format, false,
+ decoder_initialized(decoder, &audio_format, true,
(float)num_samples /
(float)audio_format.sample_rate);
+ if (mpg123_info(handle, &info) != MPG123_OK) {
+ info.vbr = MPG123_CBR;
+ info.bitrate = 0;
+ }
+
+ switch (info.vbr) {
+ case MPG123_ABR:
+ info.bitrate = info.abr_rate;
+ break;
+ case MPG123_CBR:
+ break;
+ default:
+ info.bitrate = 0;
+ }
+
/* the decoder main loop */
do {
@@ -144,11 +161,30 @@ mpd_mpg123_file_decode(struct decoder *decoder, const char *path_fs)
break;
}
+ /* update bitrate for ABR/VBR */
+ if (info.vbr != MPG123_CBR) {
+ /* FIXME: maybe skip, as too expensive? */
+ /* FIXME: maybe, (info.vbr == MPG123_VBR) ? */
+ if (mpg123_info (handle, &info) != MPG123_OK)
+ info.bitrate = 0;
+ }
+
/* send to MPD */
- cmd = decoder_data(decoder, NULL, buffer, nbytes, 0);
+ cmd = decoder_data(decoder, NULL, buffer, nbytes, info.bitrate);
- /* seeking not yet implemented */
+ if (cmd == DECODE_COMMAND_SEEK) {
+ off_t c = decoder_seek_where(decoder)*audio_format.sample_rate;
+ c = mpg123_seek(handle, c, SEEK_SET);
+ if (c < 0)
+ decoder_seek_error(decoder);
+ else {
+ decoder_command_finished(decoder);
+ decoder_timestamp(decoder, c/(double)audio_format.sample_rate);
+ }
+
+ cmd = DECODE_COMMAND_NONE;
+ }
} while (cmd == DECODE_COMMAND_NONE);
/* cleanup */
diff --git a/src/decoder/oggflac_decoder_plugin.c b/src/decoder/oggflac_decoder_plugin.c
deleted file mode 100644
index 7e5f48318..000000000
--- a/src/decoder/oggflac_decoder_plugin.c
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * Copyright (C) 2003-2010 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.
- */
-
-/*
- * OggFLAC support (half-stolen from flac_plugin.c :))
- */
-
-#include "config.h" /* must be first for large file support */
-#include "_flac_common.h"
-#include "_ogg_common.h"
-#include "flac_metadata.h"
-
-#include <glib.h>
-#include <OggFLAC/seekable_stream_decoder.h>
-#include <assert.h>
-#include <unistd.h>
-
-static void oggflac_cleanup(OggFLAC__SeekableStreamDecoder * decoder)
-{
- if (decoder)
- OggFLAC__seekable_stream_decoder_delete(decoder);
-}
-
-static OggFLAC__SeekableStreamDecoderReadStatus of_read_cb(G_GNUC_UNUSED const
- OggFLAC__SeekableStreamDecoder
- * decoder,
- FLAC__byte buf[],
- unsigned *bytes,
- void *fdata)
-{
- struct flac_data *data = (struct flac_data *) fdata;
- size_t r;
-
- r = decoder_read(data->decoder, data->input_stream,
- (void *)buf, *bytes);
- *bytes = r;
-
- if (r == 0 && !input_stream_eof(data->input_stream) &&
- decoder_get_command(data->decoder) == DECODE_COMMAND_NONE)
- return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR;
-
- return OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK;
-}
-
-static OggFLAC__SeekableStreamDecoderSeekStatus of_seek_cb(G_GNUC_UNUSED const
- OggFLAC__SeekableStreamDecoder
- * decoder,
- FLAC__uint64 offset,
- void *fdata)
-{
- struct flac_data *data = (struct flac_data *) fdata;
-
- if (!input_stream_seek(data->input_stream, offset, SEEK_SET, NULL))
- return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR;
-
- return OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK;
-}
-
-static OggFLAC__SeekableStreamDecoderTellStatus of_tell_cb(G_GNUC_UNUSED const
- OggFLAC__SeekableStreamDecoder
- * decoder,
- FLAC__uint64 *
- offset, void *fdata)
-{
- struct flac_data *data = (struct flac_data *) fdata;
-
- *offset = (long)(data->input_stream->offset);
-
- return OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK;
-}
-
-static OggFLAC__SeekableStreamDecoderLengthStatus of_length_cb(G_GNUC_UNUSED const
- OggFLAC__SeekableStreamDecoder
- * decoder,
- FLAC__uint64 *
- length,
- void *fdata)
-{
- struct flac_data *data = (struct flac_data *) fdata;
-
- if (data->input_stream->size < 0)
- return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR;
-
- *length = (size_t) (data->input_stream->size);
-
- return OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK;
-}
-
-static FLAC__bool of_EOF_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder,
- void *fdata)
-{
- struct flac_data *data = (struct flac_data *) fdata;
-
- return (decoder_get_command(data->decoder) != DECODE_COMMAND_NONE &&
- decoder_get_command(data->decoder) != DECODE_COMMAND_SEEK) ||
- input_stream_eof(data->input_stream);
-}
-
-static void of_error_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder,
- FLAC__StreamDecoderErrorStatus status, void *fdata)
-{
- flac_error_common_cb("oggflac", status, (struct flac_data *) fdata);
-}
-
-static void oggflacPrintErroredState(OggFLAC__SeekableStreamDecoderState state)
-{
- switch (state) {
- case OggFLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
- g_warning("oggflac allocation error\n");
- break;
- case OggFLAC__SEEKABLE_STREAM_DECODER_READ_ERROR:
- g_warning("oggflac read error\n");
- break;
- case OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_ERROR:
- g_warning("oggflac seek error\n");
- break;
- case OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR:
- g_warning("oggflac seekable stream error\n");
- break;
- case OggFLAC__SEEKABLE_STREAM_DECODER_ALREADY_INITIALIZED:
- g_warning("oggflac decoder already initialized\n");
- break;
- case OggFLAC__SEEKABLE_STREAM_DECODER_INVALID_CALLBACK:
- g_warning("invalid oggflac callback\n");
- break;
- case OggFLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED:
- g_warning("oggflac decoder uninitialized\n");
- break;
- case OggFLAC__SEEKABLE_STREAM_DECODER_OK:
- case OggFLAC__SEEKABLE_STREAM_DECODER_SEEKING:
- case OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM:
- break;
- }
-}
-
-static FLAC__StreamDecoderWriteStatus
-oggflac_write_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder *decoder,
- const FLAC__Frame *frame, const FLAC__int32 *const buf[],
- void *vdata)
-{
- struct flac_data *data = (struct flac_data *) vdata;
-
- return flac_common_write(data, frame, buf, 0);
-}
-
-/* used by TagDup */
-static void of_metadata_dup_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * decoder,
- const FLAC__StreamMetadata * block, void *vdata)
-{
- struct flac_data *data = (struct flac_data *) vdata;
-
- assert(data->tag != NULL);
-
- flac_tag_apply_metadata(data->tag, NULL, block);
-}
-
-/* used by decode */
-static void of_metadata_decode_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder * dec,
- const FLAC__StreamMetadata * block,
- void *vdata)
-{
- flac_metadata_common_cb(block, (struct flac_data *) vdata);
-}
-
-static OggFLAC__SeekableStreamDecoder *
-full_decoder_init_and_read_metadata(struct flac_data *data,
- unsigned int metadata_only)
-{
- OggFLAC__SeekableStreamDecoder *decoder = NULL;
- unsigned int s = 1;
-
- if (!(decoder = OggFLAC__seekable_stream_decoder_new()))
- return NULL;
-
- if (metadata_only) {
- s &= OggFLAC__seekable_stream_decoder_set_metadata_callback
- (decoder, of_metadata_dup_cb);
- s &= OggFLAC__seekable_stream_decoder_set_metadata_respond
- (decoder, FLAC__METADATA_TYPE_STREAMINFO);
- } else {
- s &= OggFLAC__seekable_stream_decoder_set_metadata_callback
- (decoder, of_metadata_decode_cb);
- }
-
- s &= OggFLAC__seekable_stream_decoder_set_read_callback(decoder,
- of_read_cb);
- s &= OggFLAC__seekable_stream_decoder_set_seek_callback(decoder,
- of_seek_cb);
- s &= OggFLAC__seekable_stream_decoder_set_tell_callback(decoder,
- of_tell_cb);
- s &= OggFLAC__seekable_stream_decoder_set_length_callback(decoder,
- of_length_cb);
- s &= OggFLAC__seekable_stream_decoder_set_eof_callback(decoder,
- of_EOF_cb);
- s &= OggFLAC__seekable_stream_decoder_set_write_callback(decoder,
- oggflac_write_cb);
- s &= OggFLAC__seekable_stream_decoder_set_metadata_respond(decoder,
- FLAC__METADATA_TYPE_VORBIS_COMMENT);
- s &= OggFLAC__seekable_stream_decoder_set_error_callback(decoder,
- of_error_cb);
- s &= OggFLAC__seekable_stream_decoder_set_client_data(decoder,
- (void *)data);
-
- if (!s) {
- g_warning("oggflac problem before init()\n");
- goto fail;
- }
- if (OggFLAC__seekable_stream_decoder_init(decoder) !=
- OggFLAC__SEEKABLE_STREAM_DECODER_OK) {
- g_warning("oggflac problem doing init()\n");
- goto fail;
- }
- if (!OggFLAC__seekable_stream_decoder_process_until_end_of_metadata
- (decoder)) {
- g_warning("oggflac problem reading metadata\n");
- goto fail;
- }
-
- return decoder;
-
-fail:
- oggflacPrintErroredState(OggFLAC__seekable_stream_decoder_get_state
- (decoder));
- OggFLAC__seekable_stream_decoder_delete(decoder);
- return NULL;
-}
-
-/* public functions: */
-static struct tag *
-oggflac_stream_tag(struct input_stream *is)
-{
- OggFLAC__SeekableStreamDecoder *decoder;
- struct flac_data data;
- struct tag *tag;
-
- if (ogg_stream_type_detect(is) != FLAC)
- return NULL;
-
- /* rewind the stream, because ogg_stream_type_detect() has
- moved it */
- input_stream_seek(is, 0, SEEK_SET, NULL);
-
- flac_data_init(&data, NULL, is);
-
- data.tag = tag_new();
-
- /* errors here won't matter,
- * data.tag will be set or unset, that's all we care about */
- decoder = full_decoder_init_and_read_metadata(&data, 1);
-
- oggflac_cleanup(decoder);
-
- if (tag_is_defined(data.tag)) {
- tag = data.tag;
- data.tag = NULL;
- } else
- tag = NULL;
-
- flac_data_deinit(&data);
-
- return tag;
-}
-
-static void
-oggflac_decode(struct decoder * mpd_decoder, struct input_stream *input_stream)
-{
- OggFLAC__SeekableStreamDecoder *decoder = NULL;
- struct flac_data data;
- struct audio_format audio_format;
-
- if (ogg_stream_type_detect(input_stream) != FLAC)
- return;
-
- /* rewind the stream, because ogg_stream_type_detect() has
- moved it */
- input_stream_seek(input_stream, 0, SEEK_SET, NULL);
-
- flac_data_init(&data, mpd_decoder, input_stream);
-
- if (!(decoder = full_decoder_init_and_read_metadata(&data, 0))) {
- goto fail;
- }
-
- if (!data.initialized)
- goto fail;
-
- decoder_initialized(mpd_decoder, &audio_format,
- input_stream->seekable,
- (float)data.total_frames /
- (float)data.audio_format.sample_rate);
-
- while (true) {
- OggFLAC__seekable_stream_decoder_process_single(decoder);
- if (OggFLAC__seekable_stream_decoder_get_state(decoder) !=
- OggFLAC__SEEKABLE_STREAM_DECODER_OK) {
- break;
- }
- if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_SEEK) {
- FLAC__uint64 seek_sample = decoder_seek_where(mpd_decoder) *
- data.audio_format.sample_rate;
- if (OggFLAC__seekable_stream_decoder_seek_absolute
- (decoder, seek_sample)) {
- data.next_frame = seek_sample;
- data.position = 0;
- decoder_command_finished(mpd_decoder);
- } else
- decoder_seek_error(mpd_decoder);
- }
- }
-
- if (decoder_get_command(mpd_decoder) == DECODE_COMMAND_NONE) {
- oggflacPrintErroredState
- (OggFLAC__seekable_stream_decoder_get_state(decoder));
- OggFLAC__seekable_stream_decoder_finish(decoder);
- }
-
-fail:
- oggflac_cleanup(decoder);
- flac_data_deinit(&data);
-}
-
-static const char *const oggflac_suffixes[] = { "ogg", "oga", NULL };
-static const char *const oggflac_mime_types[] = {
- "application/ogg",
- "application/x-ogg",
- "audio/ogg",
- "audio/x-ogg",
- "audio/x-flac+ogg",
- NULL
-};
-
-const struct decoder_plugin oggflac_decoder_plugin = {
- .name = "oggflac",
- .stream_decode = oggflac_decode,
- .stream_tag = oggflac_stream_tag,
- .suffixes = oggflac_suffixes,
- .mime_types = oggflac_mime_types
-};
diff --git a/src/decoder/pcm_decoder_plugin.c b/src/decoder/pcm_decoder_plugin.c
new file mode 100644
index 000000000..24ad93cb6
--- /dev/null
+++ b/src/decoder/pcm_decoder_plugin.c
@@ -0,0 +1,89 @@
+/*
+ * 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
+ * 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 "config.h"
+#include "decoder/pcm_decoder_plugin.h"
+#include "decoder_api.h"
+
+#include <glib.h>
+#include <unistd.h>
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "pcm"
+
+static void
+pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
+{
+ static const struct audio_format audio_format = {
+ .sample_rate = 44100,
+ .format = SAMPLE_FORMAT_S16,
+ .channels = 2,
+ };
+ GError *error = NULL;
+ enum decoder_command cmd;
+
+ double time_to_size = audio_format_time_to_size(&audio_format);
+
+ float total_time = -1;
+ if (is->size >= 0)
+ total_time = is->size / time_to_size;
+
+ decoder_initialized(decoder, &audio_format, is->seekable, total_time);
+
+ do {
+ char buffer[4096];
+
+ size_t nbytes = decoder_read(decoder, is,
+ buffer, sizeof(buffer));
+
+ if (nbytes == 0 && input_stream_lock_eof(is))
+ break;
+
+ cmd = nbytes > 0
+ ? decoder_data(decoder, is,
+ buffer, nbytes, 0)
+ : decoder_get_command(decoder);
+ if (cmd == DECODE_COMMAND_SEEK) {
+ goffset offset = (goffset)(time_to_size *
+ decoder_seek_where(decoder));
+ if (input_stream_lock_seek(is, offset, SEEK_SET,
+ &error)) {
+ decoder_command_finished(decoder);
+ } else {
+ g_warning("seeking failed: %s", error->message);
+ g_error_free(error);
+ decoder_seek_error(decoder);
+ }
+
+ cmd = DECODE_COMMAND_NONE;
+ }
+ } while (cmd == DECODE_COMMAND_NONE);
+}
+
+static const char *const pcm_mime_types[] = {
+ /* for streams obtained by the cdio_paranoia input plugin */
+ "audio/x-mpd-cdda-pcm",
+ NULL
+};
+
+const struct decoder_plugin pcm_decoder_plugin = {
+ .name = "pcm",
+ .stream_decode = pcm_stream_decode,
+ .mime_types = pcm_mime_types,
+};
diff --git a/src/decoder/pcm_decoder_plugin.h b/src/decoder/pcm_decoder_plugin.h
new file mode 100644
index 000000000..11df80155
--- /dev/null
+++ b/src/decoder/pcm_decoder_plugin.h
@@ -0,0 +1,33 @@
+/*
+ * 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
+ * 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.
+ */
+
+/** \file
+ *
+ * Not really a decoder; this plugin forwards its input data "as-is".
+ *
+ * It was written only to support the "cdio_paranoia" input plugin,
+ * which does not need a decoder.
+ */
+
+#ifndef MPD_DECODER_PCM_H
+#define MPD_DECODER_PCM_H
+
+extern const struct decoder_plugin pcm_decoder_plugin;
+
+#endif
diff --git a/src/decoder/sidplay_decoder_plugin.cxx b/src/decoder/sidplay_decoder_plugin.cxx
index 6fceeb30f..9aeec8b51 100644
--- a/src/decoder/sidplay_decoder_plugin.cxx
+++ b/src/decoder/sidplay_decoder_plugin.cxx
@@ -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
diff --git a/src/decoder/sndfile_decoder_plugin.c b/src/decoder/sndfile_decoder_plugin.c
index af68f117d..25952dfd5 100644
--- a/src/decoder/sndfile_decoder_plugin.c
+++ b/src/decoder/sndfile_decoder_plugin.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
@@ -40,7 +40,7 @@ sndfile_vio_seek(sf_count_t offset, int whence, void *user_data)
struct input_stream *is = user_data;
bool success;
- success = input_stream_seek(is, offset, whence, NULL);
+ success = input_stream_lock_seek(is, offset, whence, NULL);
if (!success)
return -1;
@@ -54,7 +54,7 @@ sndfile_vio_read(void *ptr, sf_count_t count, void *user_data)
GError *error = NULL;
size_t nbytes;
- nbytes = input_stream_read(is, ptr, count, &error);
+ nbytes = input_stream_lock_read(is, ptr, count, &error);
if (nbytes == 0 && error != NULL) {
g_warning("%s", error->message);
g_error_free(error);
diff --git a/src/decoder/vorbis_decoder_plugin.c b/src/decoder/vorbis_decoder_plugin.c
index 0a3944ad6..f73a41895 100644
--- a/src/decoder/vorbis_decoder_plugin.c
+++ b/src/decoder/vorbis_decoder_plugin.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
@@ -80,7 +80,7 @@ static int ogg_seek_cb(void *data, ogg_int64_t offset, int whence)
return vis->seekable &&
(!vis->decoder || decoder_get_command(vis->decoder) != DECODE_COMMAND_STOP) &&
- input_stream_seek(vis->input_stream, offset, whence, NULL)
+ input_stream_lock_seek(vis->input_stream, offset, whence, NULL)
? 0 : -1;
}
@@ -290,7 +290,7 @@ vorbis_stream_decode(struct decoder *decoder,
/* rewind the stream, because ogg_stream_type_detect() has
moved it */
- input_stream_seek(input_stream, 0, SEEK_SET, NULL);
+ input_stream_lock_seek(input_stream, 0, SEEK_SET, NULL);
if (!vorbis_is_open(&vis, &vf, decoder, input_stream))
return;
diff --git a/src/decoder/wavpack_decoder_plugin.c b/src/decoder/wavpack_decoder_plugin.c
index 24d0c1703..bfb13b2a4 100644
--- a/src/decoder/wavpack_decoder_plugin.c
+++ b/src/decoder/wavpack_decoder_plugin.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
@@ -390,13 +390,15 @@ wavpack_input_get_pos(void *id)
static int
wavpack_input_set_pos_abs(void *id, uint32_t pos)
{
- return input_stream_seek(wpin(id)->is, pos, SEEK_SET, NULL) ? 0 : -1;
+ return input_stream_lock_seek(wpin(id)->is, pos, SEEK_SET, NULL)
+ ? 0 : -1;
}
static int
wavpack_input_set_pos_rel(void *id, int32_t delta, int mode)
{
- return input_stream_seek(wpin(id)->is, delta, mode, NULL) ? 0 : -1;
+ return input_stream_lock_seek(wpin(id)->is, delta, mode, NULL)
+ ? 0 : -1;
}
static int
@@ -447,6 +449,7 @@ wavpack_input_init(struct wavpack_input *isp, struct decoder *decoder,
static struct input_stream *
wavpack_open_wvc(struct decoder *decoder, const char *uri,
+ GMutex *mutex, GCond *cond,
struct wavpack_input *wpi)
{
struct input_stream *is_wvc;
@@ -462,7 +465,7 @@ wavpack_open_wvc(struct decoder *decoder, const char *uri,
return false;
wvc_url = g_strconcat(uri, "c", NULL);
- is_wvc = input_stream_open(wvc_url, NULL);
+ is_wvc = input_stream_open(wvc_url, mutex, cond, NULL);
g_free(wvc_url);
if (is_wvc == NULL)
@@ -499,7 +502,8 @@ wavpack_streamdecode(struct decoder * decoder, struct input_stream *is)
struct wavpack_input isp, isp_wvc;
bool can_seek = is->seekable;
- is_wvc = wavpack_open_wvc(decoder, is->uri, &isp_wvc);
+ is_wvc = wavpack_open_wvc(decoder, is->uri, is->mutex, is->cond,
+ &isp_wvc);
if (is_wvc != NULL) {
open_flags |= OPEN_WVC;
can_seek &= is_wvc->seekable;
diff --git a/src/decoder/wildmidi_decoder_plugin.c b/src/decoder/wildmidi_decoder_plugin.c
index 66e6c61cf..5bc36b4e3 100644
--- a/src/decoder/wildmidi_decoder_plugin.c
+++ b/src/decoder/wildmidi_decoder_plugin.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
diff --git a/src/decoder_api.c b/src/decoder_api.c
index 6dcca32c2..311f1f31b 100644
--- a/src/decoder_api.c
+++ b/src/decoder_api.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
@@ -21,7 +21,6 @@
#include "decoder_api.h"
#include "decoder_internal.h"
#include "decoder_control.h"
-#include "player_control.h"
#include "audio.h"
#include "song.h"
#include "buffer.h"
@@ -63,10 +62,9 @@ decoder_initialized(struct decoder *decoder,
decoder_lock(dc);
dc->state = DECODE_STATE_DECODE;
+ g_cond_signal(dc->client_cond);
decoder_unlock(dc);
- player_lock_signal();
-
g_debug("audio_format=%s, seekable=%s",
audio_format_to_string(&dc->in_audio_format, &af_string),
seekable ? "true" : "false");
@@ -177,9 +175,8 @@ decoder_command_finished(struct decoder *decoder)
}
dc->command = DECODE_COMMAND_NONE;
+ g_cond_signal(dc->client_cond);
decoder_unlock(dc);
-
- player_lock_signal();
}
double decoder_seek_where(G_GNUC_UNUSED struct decoder * decoder)
@@ -219,50 +216,73 @@ void decoder_seek_error(struct decoder * decoder)
decoder_command_finished(decoder);
}
+/**
+ * Should be read operation be cancelled? That is the case when the
+ * player thread has sent a command such as "STOP".
+ */
+G_GNUC_PURE
+static inline bool
+decoder_check_cancel_read(const struct decoder *decoder)
+{
+ if (decoder == NULL)
+ return false;
+
+ const struct decoder_control *dc = decoder->dc;
+ if (dc->command == DECODE_COMMAND_NONE)
+ return false;
+
+ /* ignore the SEEK command during initialization, the plugin
+ should handle that after it has initialized successfully */
+ if (dc->command == DECODE_COMMAND_SEEK &&
+ (dc->state == DECODE_STATE_START || decoder->seeking))
+ return false;
+
+ return true;
+}
+
size_t decoder_read(struct decoder *decoder,
struct input_stream *is,
void *buffer, size_t length)
{
- const struct decoder_control *dc =
- decoder != NULL ? decoder->dc : NULL;
+ /* XXX don't allow decoder==NULL */
GError *error = NULL;
size_t nbytes;
assert(decoder == NULL ||
- dc->state == DECODE_STATE_START ||
- dc->state == DECODE_STATE_DECODE);
+ decoder->dc->state == DECODE_STATE_START ||
+ decoder->dc->state == DECODE_STATE_DECODE);
assert(is != NULL);
assert(buffer != NULL);
if (length == 0)
return 0;
+ input_stream_lock(is);
+
while (true) {
- /* XXX don't allow decoder==NULL */
- if (decoder != NULL &&
- /* ignore the SEEK command during initialization,
- the plugin should handle that after it has
- initialized successfully */
- (dc->command != DECODE_COMMAND_SEEK ||
- (dc->state != DECODE_STATE_START && !decoder->seeking)) &&
- dc->command != DECODE_COMMAND_NONE)
+ if (decoder_check_cancel_read(decoder)) {
+ input_stream_unlock(is);
return 0;
+ }
- nbytes = input_stream_read(is, buffer, length, &error);
+ if (input_stream_available(is))
+ break;
- if (G_UNLIKELY(nbytes == 0 && error != NULL)) {
- g_warning("%s", error->message);
- g_error_free(error);
- return 0;
- }
+ g_cond_wait(is->cond, is->mutex);
+ }
- if (nbytes > 0 || input_stream_eof(is))
- return nbytes;
+ nbytes = input_stream_read(is, buffer, length, &error);
+ assert(nbytes == 0 || error == NULL);
+ assert(nbytes > 0 || error != NULL || input_stream_eof(is));
- /* sleep for a fraction of a second! */
- /* XXX don't sleep, wait for an event instead */
- g_usleep(10000);
+ if (G_UNLIKELY(nbytes == 0 && error != NULL)) {
+ g_warning("%s", error->message);
+ g_error_free(error);
}
+
+ input_stream_unlock(is);
+
+ return nbytes;
}
void
@@ -279,8 +299,7 @@ decoder_timestamp(struct decoder *decoder, double t)
* (decoder.chunk) if there is one.
*/
static enum decoder_command
-do_send_tag(struct decoder *decoder, struct input_stream *is,
- const struct tag *tag)
+do_send_tag(struct decoder *decoder, const struct tag *tag)
{
struct music_chunk *chunk;
@@ -288,12 +307,12 @@ do_send_tag(struct decoder *decoder, struct input_stream *is,
/* there is a partial chunk - flush it, we want the
tag in a new chunk */
decoder_flush_chunk(decoder);
- player_lock_signal();
+ g_cond_signal(decoder->dc->client_cond);
}
assert(decoder->chunk == NULL);
- chunk = decoder_get_chunk(decoder, is);
+ chunk = decoder_get_chunk(decoder);
if (chunk == NULL) {
assert(decoder->dc->command != DECODE_COMMAND_NONE);
return decoder->dc->command;
@@ -309,7 +328,7 @@ update_stream_tag(struct decoder *decoder, struct input_stream *is)
struct tag *tag;
tag = is != NULL
- ? input_stream_tag(is)
+ ? input_stream_lock_tag(is)
: NULL;
if (tag == NULL) {
tag = decoder->song_tag;
@@ -360,11 +379,11 @@ decoder_data(struct decoder *decoder,
tag = tag_merge(decoder->decoder_tag,
decoder->stream_tag);
- cmd = do_send_tag(decoder, is, tag);
+ cmd = do_send_tag(decoder, tag);
tag_free(tag);
} else
/* send only the stream tag */
- cmd = do_send_tag(decoder, is, decoder->stream_tag);
+ cmd = do_send_tag(decoder, decoder->stream_tag);
if (cmd != DECODE_COMMAND_NONE)
return cmd;
@@ -390,7 +409,7 @@ decoder_data(struct decoder *decoder,
size_t nbytes;
bool full;
- chunk = decoder_get_chunk(decoder, is);
+ chunk = decoder_get_chunk(decoder);
if (chunk == NULL) {
assert(dc->command != DECODE_COMMAND_NONE);
return dc->command;
@@ -403,7 +422,7 @@ decoder_data(struct decoder *decoder,
if (dest == NULL) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
- player_lock_signal();
+ g_cond_signal(dc->client_cond);
continue;
}
@@ -422,7 +441,7 @@ decoder_data(struct decoder *decoder,
if (full) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
- player_lock_signal();
+ g_cond_signal(dc->client_cond);
}
data += nbytes;
@@ -477,11 +496,11 @@ decoder_tag(G_GNUC_UNUSED struct decoder *decoder, struct input_stream *is,
struct tag *merged;
merged = tag_merge(decoder->stream_tag, decoder->decoder_tag);
- cmd = do_send_tag(decoder, is, merged);
+ cmd = do_send_tag(decoder, merged);
tag_free(merged);
} else
/* send only the decoder tag */
- cmd = do_send_tag(decoder, is, tag);
+ cmd = do_send_tag(decoder, tag);
return cmd;
}
@@ -514,7 +533,7 @@ decoder_replay_gain(struct decoder *decoder,
replay gain values affect the following
samples */
decoder_flush_chunk(decoder);
- player_lock_signal();
+ g_cond_signal(decoder->dc->client_cond);
}
} else
decoder->replay_gain_serial = 0;
diff --git a/src/decoder_api.h b/src/decoder_api.h
index 8b5f3d82b..9d032b451 100644
--- a/src/decoder_api.h
+++ b/src/decoder_api.h
@@ -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
diff --git a/src/decoder_buffer.c b/src/decoder_buffer.c
index 8f8eb8545..fcb135976 100644
--- a/src/decoder_buffer.c
+++ b/src/decoder_buffer.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
diff --git a/src/decoder_buffer.h b/src/decoder_buffer.h
index b6051e122..77eff5dd1 100644
--- a/src/decoder_buffer.h
+++ b/src/decoder_buffer.h
@@ -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
diff --git a/src/decoder_command.h b/src/decoder_command.h
index 4a2e49f3e..795e13fb2 100644
--- a/src/decoder_command.h
+++ b/src/decoder_command.h
@@ -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
diff --git a/src/decoder_control.c b/src/decoder_control.c
index 85c2e5ba8..70f34b331 100644
--- a/src/decoder_control.c
+++ b/src/decoder_control.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
@@ -19,7 +19,6 @@
#include "config.h"
#include "decoder_control.h"
-#include "player_control.h"
#include "pipe.h"
#include <assert.h>
@@ -27,13 +26,16 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "decoder_control"
-void
-dc_init(struct decoder_control *dc)
+struct decoder_control *
+dc_new(GCond *client_cond)
{
+ struct decoder_control *dc = g_new(struct decoder_control, 1);
+
dc->thread = NULL;
dc->mutex = g_mutex_new();
dc->cond = g_cond_new();
+ dc->client_cond = client_cond;
dc->state = DECODE_STATE_STOP;
dc->command = DECODE_COMMAND_NONE;
@@ -43,34 +45,26 @@ dc_init(struct decoder_control *dc)
dc->mixramp_start = NULL;
dc->mixramp_end = NULL;
dc->mixramp_prev_end = NULL;
+
+ return dc;
}
void
-dc_deinit(struct decoder_control *dc)
+dc_free(struct decoder_control *dc)
{
g_cond_free(dc->cond);
g_mutex_free(dc->mutex);
g_free(dc->mixramp_start);
g_free(dc->mixramp_end);
g_free(dc->mixramp_prev_end);
- dc->mixramp_start = NULL;
- dc->mixramp_end = NULL;
- dc->mixramp_prev_end = NULL;
+ g_free(dc);
}
static void
dc_command_wait_locked(struct decoder_control *dc)
{
while (dc->command != DECODE_COMMAND_NONE)
- player_wait_decoder(dc);
-}
-
-void
-dc_command_wait(struct decoder_control *dc)
-{
- decoder_lock(dc);
- dc_command_wait_locked(dc);
- decoder_unlock(dc);
+ g_cond_wait(dc->client_cond, dc->mutex);
}
static void
diff --git a/src/decoder_control.h b/src/decoder_control.h
index 64c7c302e..566b153ee 100644
--- a/src/decoder_control.h
+++ b/src/decoder_control.h
@@ -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
@@ -58,6 +58,12 @@ struct decoder_control {
*/
GCond *cond;
+ /**
+ * The trigger of this object's client. It is signalled
+ * whenever an event occurs.
+ */
+ GCond *client_cond;
+
enum decoder_state state;
enum decoder_command command;
@@ -114,11 +120,12 @@ struct decoder_control {
char *mixramp_prev_end;
};
-void
-dc_init(struct decoder_control *dc);
+G_GNUC_MALLOC
+struct decoder_control *
+dc_new(GCond *client_cond);
void
-dc_deinit(struct decoder_control *dc);
+dc_free(struct decoder_control *dc);
/**
* Locks the #decoder_control object.
@@ -234,9 +241,6 @@ decoder_current_song(const struct decoder_control *dc)
return NULL;
}
-void
-dc_command_wait(struct decoder_control *dc);
-
/**
* Start the decoder.
*
diff --git a/src/decoder_internal.c b/src/decoder_internal.c
index 990d728e9..bc349f2ff 100644
--- a/src/decoder_internal.c
+++ b/src/decoder_internal.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
@@ -20,7 +20,6 @@
#include "config.h"
#include "decoder_internal.h"
#include "decoder_control.h"
-#include "player_control.h"
#include "pipe.h"
#include "input_stream.h"
#include "buffer.h"
@@ -29,43 +28,19 @@
#include <assert.h>
/**
- * This is a wrapper for input_stream_buffer(). It assumes that the
- * decoder is currently locked, and temporarily unlocks it while
- * calling input_stream_buffer(). We shouldn't hold the lock during a
- * potentially blocking operation.
- */
-static bool
-decoder_input_buffer(struct decoder_control *dc, struct input_stream *is)
-{
- GError *error = NULL;
- int ret;
-
- decoder_unlock(dc);
- ret = input_stream_buffer(is, &error);
- if (ret < 0) {
- g_warning("%s", error->message);
- g_error_free(error);
- }
-
- decoder_lock(dc);
-
- return ret > 0;
-}
-
-/**
* All chunks are full of decoded data; wait for the player to free
* one.
*/
static enum decoder_command
-need_chunks(struct decoder_control *dc, struct input_stream *is, bool do_wait)
+need_chunks(struct decoder_control *dc, bool do_wait)
{
if (dc->command == DECODE_COMMAND_STOP ||
dc->command == DECODE_COMMAND_SEEK)
return dc->command;
- if ((is == NULL || !decoder_input_buffer(dc, is)) && do_wait) {
+ if (do_wait) {
decoder_wait(dc);
- player_signal();
+ g_cond_signal(dc->client_cond);
return dc->command;
}
@@ -74,7 +49,7 @@ need_chunks(struct decoder_control *dc, struct input_stream *is, bool do_wait)
}
struct music_chunk *
-decoder_get_chunk(struct decoder *decoder, struct input_stream *is)
+decoder_get_chunk(struct decoder *decoder)
{
struct decoder_control *dc = decoder->dc;
enum decoder_command cmd;
@@ -97,7 +72,7 @@ decoder_get_chunk(struct decoder *decoder, struct input_stream *is)
}
decoder_lock(dc);
- cmd = need_chunks(dc, is, true);
+ cmd = need_chunks(dc, true);
decoder_unlock(dc);
} while (cmd == DECODE_COMMAND_NONE);
diff --git a/src/decoder_internal.h b/src/decoder_internal.h
index 5818632e5..d89e68cfc 100644
--- a/src/decoder_internal.h
+++ b/src/decoder_internal.h
@@ -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
@@ -89,7 +89,7 @@ struct decoder {
* @return the chunk, or NULL if we have received a decoder command
*/
struct music_chunk *
-decoder_get_chunk(struct decoder *decoder, struct input_stream *is);
+decoder_get_chunk(struct decoder *decoder);
/**
* Flushes the current chunk.
diff --git a/src/decoder_list.c b/src/decoder_list.c
index d76050023..2029b3e62 100644
--- a/src/decoder_list.c
+++ b/src/decoder_list.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
@@ -23,6 +23,8 @@
#include "utils.h"
#include "conf.h"
#include "mpd_error.h"
+#include "decoder/pcm_decoder_plugin.h"
+#include "decoder/dsdiff_decoder_plugin.h"
#include <glib.h>
@@ -57,7 +59,7 @@ const struct decoder_plugin *const decoder_plugins[] = {
#ifdef ENABLE_VORBIS_DECODER
&vorbis_decoder_plugin,
#endif
-#if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC)
+#if defined(HAVE_FLAC)
&oggflac_decoder_plugin,
#endif
#ifdef HAVE_FLAC
@@ -69,6 +71,7 @@ const struct decoder_plugin *const decoder_plugins[] = {
#ifdef HAVE_AUDIOFILE
&audiofile_decoder_plugin,
#endif
+ &dsdiff_decoder_plugin,
#ifdef HAVE_FAAD
&faad_decoder_plugin,
#endif
@@ -102,6 +105,7 @@ const struct decoder_plugin *const decoder_plugins[] = {
#ifdef HAVE_GME
&gme_decoder_plugin,
#endif
+ &pcm_decoder_plugin,
NULL
};
diff --git a/src/decoder_list.h b/src/decoder_list.h
index 7041db0c9..d259cb195 100644
--- a/src/decoder_list.h
+++ b/src/decoder_list.h
@@ -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
diff --git a/src/decoder_plugin.c b/src/decoder_plugin.c
index 062dad364..d32043f0e 100644
--- a/src/decoder_plugin.c
+++ b/src/decoder_plugin.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
@@ -19,7 +19,7 @@
#include "config.h"
#include "decoder_plugin.h"
-#include "utils.h"
+#include "string_util.h"
#include <assert.h>
diff --git a/src/decoder_plugin.h b/src/decoder_plugin.h
index d8371ddb8..0ce1af53e 100644
--- a/src/decoder_plugin.h
+++ b/src/decoder_plugin.h
@@ -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
diff --git a/src/decoder_print.c b/src/decoder_print.c
index a1c2da2e5..72c40ac75 100644
--- a/src/decoder_print.c
+++ b/src/decoder_print.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
diff --git a/src/decoder_print.h b/src/decoder_print.h
index 520438871..31713d5d8 100644
--- a/src/decoder_print.h
+++ b/src/decoder_print.h
@@ -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
diff --git a/src/decoder_thread.c b/src/decoder_thread.c
index 201cd5acd..c2bb655ea 100644
--- a/src/decoder_thread.c
+++ b/src/decoder_thread.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
@@ -26,7 +26,6 @@
#include "decoder_api.h"
#include "replay_gain_ape.h"
#include "input_stream.h"
-#include "player_control.h"
#include "pipe.h"
#include "song.h"
#include "tag.h"
@@ -42,16 +41,20 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "decoder_thread"
-static enum decoder_command
-decoder_lock_get_command(struct decoder_control *dc)
+/**
+ * Marks the current decoder command as "finished" and notifies the
+ * player thread.
+ *
+ * @param dc the #decoder_control object; must be locked
+ */
+static void
+decoder_command_finished_locked(struct decoder_control *dc)
{
- enum decoder_command command;
+ assert(dc->command != DECODE_COMMAND_NONE);
- decoder_lock(dc);
- command = dc->command;
- decoder_unlock(dc);
+ dc->command = DECODE_COMMAND_NONE;
- return command;
+ g_cond_signal(dc->client_cond);
}
/**
@@ -71,7 +74,7 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri)
GError *error = NULL;
struct input_stream *is;
- is = input_stream_open(uri, &error);
+ is = input_stream_open(uri, dc->mutex, dc->cond, &error);
if (is == NULL) {
if (error != NULL) {
g_warning("%s", error->message);
@@ -84,19 +87,27 @@ decoder_input_stream_open(struct decoder_control *dc, const char *uri)
/* wait for the input stream to become ready; its metadata
will be available then */
+ decoder_lock(dc);
+
+ input_stream_update(is);
while (!is->ready &&
- decoder_lock_get_command(dc) != DECODE_COMMAND_STOP) {
- int ret;
+ dc->command != DECODE_COMMAND_STOP) {
+ decoder_wait(dc);
- ret = input_stream_buffer(is, &error);
- if (ret < 0) {
- input_stream_close(is);
- g_warning("%s", error->message);
- g_error_free(error);
- return NULL;
- }
+ input_stream_update(is);
}
+ if (!input_stream_check(is, &error)) {
+ decoder_unlock(dc);
+
+ g_warning("%s", error->message);
+ g_error_free(error);
+
+ return NULL;
+ }
+
+ decoder_unlock(dc);
+
return is;
}
@@ -117,11 +128,11 @@ decoder_stream_decode(const struct decoder_plugin *plugin,
if (decoder->dc->command == DECODE_COMMAND_STOP)
return true;
- decoder_unlock(decoder->dc);
-
/* rewind the stream, so each plugin gets a fresh start */
input_stream_seek(input_stream, 0, SEEK_SET, NULL);
+ decoder_unlock(decoder->dc);
+
decoder_plugin_stream_decode(plugin, decoder, input_stream);
decoder_lock(decoder->dc);
@@ -383,9 +394,8 @@ decoder_run_song(struct decoder_control *dc,
decoder.chunk = NULL;
dc->state = DECODE_STATE_START;
- dc->command = DECODE_COMMAND_NONE;
- player_signal();
+ decoder_command_finished_locked(dc);
pcm_convert_init(&decoder.conv_state);
@@ -431,6 +441,7 @@ decoder_run(struct decoder_control *dc)
if (uri == NULL) {
dc->state = DECODE_STATE_ERROR;
+ decoder_command_finished_locked(dc);
return;
}
@@ -463,16 +474,10 @@ decoder_task(gpointer arg)
case DECODE_COMMAND_SEEK:
decoder_run(dc);
-
- dc->command = DECODE_COMMAND_NONE;
-
- player_signal();
break;
case DECODE_COMMAND_STOP:
- dc->command = DECODE_COMMAND_NONE;
-
- player_signal();
+ decoder_command_finished_locked(dc);
break;
case DECODE_COMMAND_NONE:
diff --git a/src/decoder_thread.h b/src/decoder_thread.h
index 28042d7f8..78f12a54a 100644
--- a/src/decoder_thread.h
+++ b/src/decoder_thread.h
@@ -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