aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/decode.h10
-rw-r--r--src/decoder_control.c82
-rw-r--r--src/player_thread.c67
4 files changed, 110 insertions, 50 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 006ccf214..d31783e4f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -107,6 +107,7 @@ mpd_SOURCES = \
crossfade.c \
dbUtils.c \
decode.c \
+ decoder_control.c \
decoder_api.c \
directory.c \
decoder_list.c \
diff --git a/src/decode.h b/src/decode.h
index 29e25392f..f68507d3f 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -61,4 +61,14 @@ typedef struct _DecoderControl {
void decoderInit(void);
+void dc_command_wait(Notify *notify);
+
+void dc_start(Notify *notify, Song *song);
+
+void dc_start_async(Song *song);
+
+void dc_stop(Notify *notify);
+
+int dc_seek(Notify *notify, double where);
+
#endif
diff --git a/src/decoder_control.c b/src/decoder_control.c
new file mode 100644
index 000000000..1c92ba522
--- /dev/null
+++ b/src/decoder_control.c
@@ -0,0 +1,82 @@
+/* the Music Player Daemon (MPD)
+ * Copyright (C) 2008 Max Kellermann <max@duempel.org>
+ * This project's homepage is: 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "decode.h"
+#include "playerData.h"
+
+void dc_command_wait(Notify *notify)
+{
+ while (dc.command != DECODE_COMMAND_NONE) {
+ notify_signal(&dc.notify);
+ notify_wait(notify);
+ }
+}
+
+static void dc_command(Notify *notify, enum decoder_command cmd)
+{
+ dc.command = cmd;
+ dc_command_wait(notify);
+}
+
+static void dc_command_async(enum decoder_command cmd)
+{
+ dc.command = cmd;
+ notify_signal(&dc.notify);
+}
+
+void dc_start(Notify *notify, Song *song)
+{
+ assert(song != NULL);
+
+ dc.next_song = song;
+ dc.error = DECODE_ERROR_NOERROR;
+ dc_command(notify, DECODE_COMMAND_START);
+}
+
+void dc_start_async(Song *song)
+{
+ assert(song != NULL);
+
+ dc.next_song = song;
+ dc.error = DECODE_ERROR_NOERROR;
+ dc_command_async(DECODE_COMMAND_START);
+}
+
+void dc_stop(Notify *notify)
+{
+ if (dc.command == DECODE_COMMAND_START ||
+ dc.state != DECODE_STATE_STOP)
+ dc_command(notify, DECODE_COMMAND_STOP);
+}
+
+int dc_seek(Notify *notify, double where)
+{
+ assert(where >= 0.0);
+
+ if (dc.state == DECODE_STATE_STOP || !dc.seekable)
+ return -1;
+
+ dc.seekWhere = where;
+ dc.seekError = 0;
+ dc_command(notify, DECODE_COMMAND_SEEK);
+
+ if (dc.seekError)
+ return -1;
+
+ return 0;
+}
diff --git a/src/player_thread.c b/src/player_thread.c
index e2486f2d3..52f0beac0 100644
--- a/src/player_thread.c
+++ b/src/player_thread.c
@@ -31,30 +31,9 @@ enum xfade_state {
XFADE_ENABLED = 1
};
-static void dc_command_wait(void)
-{
- while (dc.command != DECODE_COMMAND_NONE) {
- notify_signal(&dc.notify);
- notify_wait(&pc.notify);
- }
-}
-
-static void dc_command(enum decoder_command cmd)
-{
- dc.command = cmd;
- dc_command_wait();
-}
-
-static void stopDecode(void)
-{
- if (dc.command == DECODE_COMMAND_START ||
- dc.state != DECODE_STATE_STOP)
- dc_command(DECODE_COMMAND_STOP);
-}
-
static void quitDecode(void)
{
- stopDecode();
+ dc_stop(&pc.notify);
pc.state = PLAYER_STATE_STOP;
dc.command = DECODE_COMMAND_NONE;
pc.command = PLAYER_COMMAND_NONE;
@@ -63,10 +42,7 @@ static void quitDecode(void)
static int waitOnDecode(int *decodeWaitedOn)
{
- while (dc.command == DECODE_COMMAND_START) {
- notify_signal(&dc.notify);
- notify_wait(&pc.notify);
- }
+ dc_command_wait(&pc.notify);
if (dc.error != DECODE_ERROR_NOERROR) {
assert(dc.next_song == NULL || dc.next_song->url != NULL);
@@ -88,30 +64,27 @@ static int waitOnDecode(int *decodeWaitedOn)
static int decodeSeek(int *decodeWaitedOn, int *next)
{
int ret = -1;
+ double where;
if (dc.state == DECODE_STATE_STOP ||
dc.error != DECODE_ERROR_NOERROR ||
dc.current_song != pc.next_song) {
- stopDecode();
+ dc_stop(&pc.notify);
*next = -1;
ob_clear();
- dc.next_song = pc.next_song;
- dc.error = DECODE_ERROR_NOERROR;
- dc.command = DECODE_COMMAND_START;
+ dc_start_async(pc.next_song);
waitOnDecode(decodeWaitedOn);
}
- if (dc.state != DECODE_STATE_STOP && dc.seekable) {
- *next = -1;
- dc.seekWhere = pc.seekWhere > pc.totalTime - 0.1 ?
- pc.totalTime - 0.1 : pc.seekWhere;
- dc.seekWhere = 0 > dc.seekWhere ? 0 : dc.seekWhere;
- dc.seekError = 0;
- dc_command(DECODE_COMMAND_SEEK);
- if (!dc.seekError) {
- pc.elapsedTime = dc.seekWhere;
- ret = 0;
- }
- }
+
+ where = pc.seekWhere;
+ if (where > pc.totalTime)
+ where = pc.totalTime - 0.1;
+ if (where < 0.0)
+ where = 0.0;
+
+ ret = dc_seek(&pc.notify, where);
+ if (ret == 0)
+ pc.elapsedTime = where;
player_command_finished();
@@ -291,12 +264,9 @@ static void decodeParent(void)
/* the decoder has finished the current song;
make it decode the next song */
next = ob.end;
- dc.next_song = pc.next_song;
- dc.error = DECODE_ERROR_NOERROR;
- dc.command = DECODE_COMMAND_START;
+ dc_start_async(pc.next_song);
pc.queueState = PLAYER_QUEUE_DECODE;
wakeup_main_task();
- notify_signal(&dc.notify);
}
if (next >= 0 && do_xfade == XFADE_UNKNOWN &&
dc.command != DECODE_COMMAND_START &&
@@ -416,10 +386,7 @@ static void decode(void)
{
ob_clear();
- dc.next_song = pc.next_song;
- dc.error = DECODE_ERROR_NOERROR;
- dc_command(DECODE_COMMAND_START);
-
+ dc_start(&pc.notify, pc.next_song);
decodeParent();
}