aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/outputBuffer.c45
-rw-r--r--src/outputBuffer.h1
-rw-r--r--src/playlist.c72
3 files changed, 46 insertions, 72 deletions
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 26d31b2cd..aca84d07f 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -207,18 +207,24 @@ static void ob_seq_player_set(unsigned int seq_num)
cond_leave(&ob_seq_cond);
}
+static enum action_status ob_do_reset(void)
+{
+ assert(pthread_equal(pthread_self(), ob.thread));
+ ob.elapsed_time = 0;
+ ob.total_time = 0;
+ reader_reset_buffer();
+ ob.xfade_state = XFADE_DISABLED;
+ ob_seq_player_set((unsigned int)ob.seq_decoder);
+ return ob_finalize_action();
+}
+
static enum action_status ob_do_stop(void)
{
assert(pthread_equal(pthread_self(), ob.thread));
- if (ob.state != OB_STATE_STOP) {
- ob.elapsed_time = 0;
- reader_reset_buffer();
- ob.xfade_state = XFADE_DISABLED;
- close_audio_devices();
- ob.state = OB_STATE_STOP;
- ob_seq_player_set((unsigned int)ob.seq_decoder);
- }
- return AS_INPROGRESS;
+ if (ob.state == OB_STATE_STOP)
+ return AS_INPROGRESS;
+ ob.state = OB_STATE_STOP;
+ return ob_do_reset();
}
/*
@@ -299,6 +305,7 @@ static enum action_status ob_take_action(void)
}
break;
case OB_ACTION_STOP: return ob_do_stop();
+ case OB_ACTION_RESET: return ob_do_reset();
case OB_ACTION_QUIT:
close_audio_devices();
ob.state = OB_STATE_QUIT;
@@ -350,24 +357,6 @@ void ob_drop_audio(enum ob_drop_type type)
/* DEBUG("done dropping %u\n", ob.seq_drop); */
}
-void ob_wait_sync(void)
-{
- assert(!pthread_equal(pthread_self(), dc.thread));
- assert(!pthread_equal(pthread_self(), ob.thread));
-
- /* DEBUG(__FILE__": %s %d\n", __func__, __LINE__); */
- cond_enter(&ob_seq_cond);
- while (ob.seq_player != ob.seq_decoder) {
- /* DEBUG("%s %d seq_player:%u seq_decoder:%u\n", */
- /* __func__, __LINE__, ob.seq_player, ob.seq_decoder); */
- cond_wait(&ob_seq_cond);
- /* DEBUG("%s %d seq_player:%u seq_decoder:%u\n", */
- /* __func__, __LINE__, ob.seq_player, ob.seq_decoder); */
- }
- cond_leave(&ob_seq_cond);
- /* DEBUG(__FILE__": %s %d\n", __func__, __LINE__); */
-}
-
/* call this exactly once before decoding each song */
void ob_advance_sequence(void)
{
@@ -527,7 +516,7 @@ void ob_flush(void)
case OB_STATE_SEEK:
assert(0);
case OB_STATE_PLAY:
- case OB_STATE_PAUSE: /* should we assert if paused? */
+ case OB_STATE_PAUSE:
ringbuf_write_advance(ob.index, 1);
break;
case OB_STATE_STOP:
diff --git a/src/outputBuffer.h b/src/outputBuffer.h
index 187846ef3..15e46da60 100644
--- a/src/outputBuffer.h
+++ b/src/outputBuffer.h
@@ -40,6 +40,7 @@ enum ob_action {
OB_ACTION_PAUSE_SET,
OB_ACTION_PAUSE_UNSET,
OB_ACTION_PAUSE_FLIP,
+ OB_ACTION_RESET,
OB_ACTION_STOP,
OB_ACTION_QUIT
};
diff --git a/src/playlist.c b/src/playlist.c
index abe151488..9839cc346 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -93,7 +93,7 @@ static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER;
int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
static void swapOrder(int a, int b);
-static int playPlaylistOrderNumber(int fd, int orderNum);
+static int play_order_num(int fd, int order_num, float seek_time);
static void randomizeOrder(int start, int end);
static void incrPlaylistVersion(void)
@@ -762,7 +762,7 @@ int deleteFromPlaylist(int fd, int song)
{
int i;
int songOrder;
- int stopped_current = 0;
+ int stop_current = 0;
int prev_queued = playlist.queued;
if (song < 0 || song >= playlist.length) {
@@ -813,25 +813,20 @@ int deleteFromPlaylist(int fd, int song)
/* DEBUG("current: %d, songOrder: %d\n", playlist.current, songOrder); */
/* DEBUG("playlist_state: %d\n", playlist_state); */
if (playlist_state != PLAYLIST_STATE_STOP
- && playlist.current == songOrder) {
- dc_trigger_action(DC_ACTION_STOP, 0);
- /* drop all audio, but don't actually close the device */
- ob_drop_audio(OB_DROP_DECODED);
- ob_drop_audio(OB_DROP_PLAYING);
- stopped_current = 1;
- }
+ && playlist.current == songOrder)
+ stop_current = 1;
if (playlist.current > songOrder) {
playlist.current--;
} else if (playlist.current >= playlist.length) {
incrPlaylistCurrent();
}
- if (stopped_current) {
+ if (stop_current) {
/* DEBUG(__FILE__": %d\n", __LINE__); */
if (playlist.current >= 0)
- playPlaylistOrderNumber(STDERR_FILENO,playlist.current);
+ play_order_num(fd, playlist.current, 0);
else
- playlist_state = PLAYLIST_STATE_STOP;
+ stopPlaylist(fd);
} else {
/* DEBUG(__FILE__": %d\n", __LINE__); */
queueNextSongInPlaylist();
@@ -881,23 +876,26 @@ int stopPlaylist(int fd)
return 0;
}
-static int playPlaylistOrderNumber(int fd, int orderNum)
+static int play_order_num(int fd, int order_num, float seek_time)
{
char path[MPD_PATH_MAX];
+ enum dc_action action = seek_time ? DC_ACTION_SEEK : DC_ACTION_START;
playlist_state = PLAYLIST_STATE_PLAY;
- assert(orderNum >= 0);
+ assert(order_num >= 0);
+ assert(seek_time >= 0);
- DEBUG("playlist: play %i:\"%s\"\n", orderNum,
- get_song_url(path, song_at(orderNum)));
+ DEBUG("playlist: play %i:\"%s\"\n", order_num,
+ get_song_url(path, song_at(order_num)));
dc_trigger_action(DC_ACTION_STOP, 0);
- ob_drop_audio(OB_DROP_DECODED);
- queue_song_locked(orderNum);
- ob_drop_audio(OB_DROP_PLAYING);
- ob_trigger_action(OB_ACTION_PAUSE_UNSET);
- dc_trigger_action(DC_ACTION_START, 0);
- ob_wait_sync(); /* HACK: REMOVE */
- playlist.current = orderNum;
+ queue_song_locked(order_num);
+
+ ob_trigger_action(OB_ACTION_RESET);
+
+ dc_trigger_action(action, seek_time);
+ if (dc.seek_where >= 0)
+ playlist.current = order_num;
+
return 0;
}
@@ -944,7 +942,8 @@ int playPlaylist(int fd, int song, int stopOnError)
playlist_errorCount = 0;
ERROR(__FILE__ ": %d current:%d\n", __LINE__, playlist.current);
- return playPlaylistOrderNumber(fd, i);
+ ob_trigger_action(OB_ACTION_PAUSE_UNSET);
+ return play_order_num(fd, i, 0);
}
int playPlaylistById(int fd, int id, int stopOnError)
@@ -1013,7 +1012,8 @@ int nextSongInPlaylist(int fd)
incrPlaylistCurrent();
return stopPlaylist(fd);
}
- return playPlaylistOrderNumber(fd, next);
+ ob_trigger_action(OB_ACTION_PAUSE_UNSET);
+ return play_order_num(fd, next, 0);
}
int getPlaylistRepeatStatus(void)
@@ -1239,7 +1239,8 @@ int previousSongInPlaylist(int fd)
else
prev_order_num = playlist.current;
}
- return playPlaylistOrderNumber(fd, prev_order_num);
+ ob_trigger_action(OB_ACTION_PAUSE_UNSET);
+ return play_order_num(fd, prev_order_num, 0);
}
int shufflePlaylist(int fd)
@@ -1400,24 +1401,7 @@ int seekSongInPlaylist(int fd, int song, float seek_time)
}
DEBUG("playlist: seek %i:\"%s\"\n", i, get_song_url(path, song_at(i)));
- playlist_state = PLAYLIST_STATE_PLAY;
- DEBUG("%s:%d\n", __func__, __LINE__);
- dc_trigger_action(DC_ACTION_STOP, 0);
- DEBUG("%s:%d\n", __func__, __LINE__);
- ob_drop_audio(OB_DROP_DECODED);
- DEBUG("%s:%d\n", __func__, __LINE__);
- queue_song_locked(i);
- DEBUG("%s:%d\n", __func__, __LINE__);
- ob_drop_audio(OB_DROP_PLAYING);
- DEBUG("%s:%d\n", __func__, __LINE__);
- DEBUG("seek_time: %f\n", seek_time);
- dc_trigger_action(DC_ACTION_SEEK, seek_time);
- DEBUG("%s:%d\n", __func__, __LINE__);
- if (dc.seek_where >= 0) {
- playlist.current = i;
- DEBUG("%s:%d\n", __func__, __LINE__);
- ob_wait_sync();
- }
+ play_order_num(fd, i, seek_time);
return 0;
}