Commit d507ff28 authored by Max Kellermann's avatar Max Kellermann

added dc.next_song, renamed pc.current_song

Since pc->current_song denotes the song which the decoder should use next, we should move it to DecoderControl. This removes one internal PlayerControl struct access from the decoder code. Also add pc.next_song, which is manipulated by the playlist code, and gets copied to dc.next_song as soon as the decoder is started.
parent b6909da7
...@@ -105,7 +105,7 @@ static int waitOnDecode(int *decodeWaitedOn) ...@@ -105,7 +105,7 @@ static int waitOnDecode(int *decodeWaitedOn)
player_wakeup_decoder(); player_wakeup_decoder();
if (dc.error != DECODE_ERROR_NOERROR) { if (dc.error != DECODE_ERROR_NOERROR) {
pc.errored_song = pc.current_song; pc.errored_song = dc.next_song;
pc.error = PLAYER_ERROR_FILE; pc.error = PLAYER_ERROR_FILE;
quitDecode(); quitDecode();
return -1; return -1;
...@@ -127,10 +127,11 @@ static int decodeSeek(int *decodeWaitedOn, int *next) ...@@ -127,10 +127,11 @@ static int decodeSeek(int *decodeWaitedOn, int *next)
if (dc.state == DECODE_STATE_STOP || if (dc.state == DECODE_STATE_STOP ||
dc.error != DECODE_ERROR_NOERROR || dc.error != DECODE_ERROR_NOERROR ||
dc.current_song != pc.current_song) { dc.current_song != pc.next_song) {
stopDecode(); stopDecode();
*next = -1; *next = -1;
ob_clear(); ob_clear();
dc.next_song = pc.next_song;
dc.error = DECODE_ERROR_NOERROR; dc.error = DECODE_ERROR_NOERROR;
dc.start = 1; dc.start = 1;
waitOnDecode(decodeWaitedOn); waitOnDecode(decodeWaitedOn);
...@@ -178,11 +179,11 @@ static void processDecodeInput(int *pause_r, unsigned int *bbp_r, ...@@ -178,11 +179,11 @@ static void processDecodeInput(int *pause_r, unsigned int *bbp_r,
pc.state = PLAYER_STATE_PLAY; pc.state = PLAYER_STATE_PLAY;
} else { } else {
char tmp[MPD_PATH_MAX]; char tmp[MPD_PATH_MAX];
pc.errored_song = pc.current_song; pc.errored_song = dc.next_song;
pc.error = PLAYER_ERROR_AUDIO; pc.error = PLAYER_ERROR_AUDIO;
ERROR("problems opening audio device " ERROR("problems opening audio device "
"while playing \"%s\"\n", "while playing \"%s\"\n",
get_song_url(tmp, pc.current_song)); get_song_url(tmp, dc.next_song));
*pause_r = -1; *pause_r = -1;
} }
} }
...@@ -213,7 +214,7 @@ static void decodeStart(void) ...@@ -213,7 +214,7 @@ static void decodeStart(void)
char path_max_fs[MPD_PATH_MAX]; char path_max_fs[MPD_PATH_MAX];
char path_max_utf8[MPD_PATH_MAX]; char path_max_utf8[MPD_PATH_MAX];
if (!get_song_url(path_max_utf8, pc.current_song)) { if (!get_song_url(path_max_utf8, dc.next_song)) {
dc.error = DECODE_ERROR_FILE; dc.error = DECODE_ERROR_FILE;
goto stop_no_close; goto stop_no_close;
} }
...@@ -223,7 +224,7 @@ static void decodeStart(void) ...@@ -223,7 +224,7 @@ static void decodeStart(void)
} else } else
pathcpy_trunc(path_max_fs, path_max_utf8); pathcpy_trunc(path_max_fs, path_max_utf8);
dc.current_song = pc.current_song; /* NEED LOCK */ dc.current_song = dc.next_song; /* NEED LOCK */
if (openInputStream(&inStream, path_max_fs) < 0) { if (openInputStream(&inStream, path_max_fs) < 0) {
dc.error = DECODE_ERROR_FILE; dc.error = DECODE_ERROR_FILE;
goto stop_no_close; goto stop_no_close;
...@@ -306,7 +307,7 @@ static void decodeStart(void) ...@@ -306,7 +307,7 @@ static void decodeStart(void)
} }
if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) { if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) {
pc.errored_song = pc.current_song; pc.errored_song = dc.next_song;
if (ret != DECODE_ERROR_UNKTYPE) if (ret != DECODE_ERROR_UNKTYPE)
dc.error = DECODE_ERROR_FILE; dc.error = DECODE_ERROR_FILE;
else else
...@@ -439,11 +440,11 @@ static void decodeParent(void) ...@@ -439,11 +440,11 @@ static void decodeParent(void)
decodeWaitedOn = 0; decodeWaitedOn = 0;
if(openAudioDevice(&(ob.audioFormat))<0) { if(openAudioDevice(&(ob.audioFormat))<0) {
char tmp[MPD_PATH_MAX]; char tmp[MPD_PATH_MAX];
pc.errored_song = pc.current_song; pc.errored_song = dc.next_song;
pc.error = PLAYER_ERROR_AUDIO; pc.error = PLAYER_ERROR_AUDIO;
ERROR("problems opening audio device " ERROR("problems opening audio device "
"while playing \"%s\"\n", "while playing \"%s\"\n",
get_song_url(tmp, pc.current_song)); get_song_url(tmp, dc.next_song));
break; break;
} else { } else {
player_wakeup_decoder(); player_wakeup_decoder();
...@@ -460,7 +461,7 @@ static void decodeParent(void) ...@@ -460,7 +461,7 @@ static void decodeParent(void)
} }
else if(dc.state!=DECODE_STATE_START) { else if(dc.state!=DECODE_STATE_START) {
/* the decoder failed */ /* the decoder failed */
pc.errored_song = pc.current_song; pc.errored_song = dc.next_song;
pc.error = PLAYER_ERROR_FILE; pc.error = PLAYER_ERROR_FILE;
break; break;
} }
...@@ -478,6 +479,8 @@ static void decodeParent(void) ...@@ -478,6 +479,8 @@ static void decodeParent(void)
/* the decoder has finished the current song; /* the decoder has finished the current song;
make it decode the next song */ make it decode the next song */
next = ob.end; next = ob.end;
dc.next_song = pc.next_song;
dc.error = DECODE_ERROR_NOERROR;
dc.start = 1; dc.start = 1;
pc.queueState = PLAYER_QUEUE_DECODE; pc.queueState = PLAYER_QUEUE_DECODE;
wakeup_main_task(); wakeup_main_task();
...@@ -596,7 +599,7 @@ static void decodeParent(void) ...@@ -596,7 +599,7 @@ static void decodeParent(void)
void decode(void) void decode(void)
{ {
ob_clear(); ob_clear();
dc.next_song = pc.next_song;
dc.error = DECODE_ERROR_NOERROR; dc.error = DECODE_ERROR_NOERROR;
dc.seek = 0; dc.seek = 0;
dc.stop = 0; dc.stop = 0;
......
...@@ -50,6 +50,7 @@ typedef struct _DecoderControl { ...@@ -50,6 +50,7 @@ typedef struct _DecoderControl {
volatile double seekWhere; volatile double seekWhere;
AudioFormat audioFormat; AudioFormat audioFormat;
Song *current_song; Song *current_song;
Song *volatile next_song;
volatile float totalTime; volatile float totalTime;
} DecoderControl; } DecoderControl;
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "player.h" #include "player.h"
#include "path.h" #include "path.h"
#include "decode.h"
#include "command.h" #include "command.h"
#include "log.h" #include "log.h"
#include "playerData.h" #include "playerData.h"
...@@ -101,7 +100,7 @@ int playerWait(int fd) ...@@ -101,7 +100,7 @@ int playerWait(int fd)
static void set_current_song(Song *song) static void set_current_song(Song *song)
{ {
pc.fileTime = song->tag ? song->tag->time : 0; pc.fileTime = song->tag ? song->tag->time : 0;
pc.current_song = song; pc.next_song = song;
} }
int playerPlay(int fd, Song * song) int playerPlay(int fd, Song * song)
...@@ -279,7 +278,7 @@ int playerSeek(int fd, Song * song, float seek_time) ...@@ -279,7 +278,7 @@ int playerSeek(int fd, Song * song, float seek_time)
return -1; return -1;
} }
if (pc.current_song != song) if (pc.next_song != song)
set_current_song(song); set_current_song(song);
if (pc.error == PLAYER_ERROR_NOERROR) { if (pc.error == PLAYER_ERROR_NOERROR) {
......
...@@ -63,7 +63,7 @@ typedef struct _PlayerControl { ...@@ -63,7 +63,7 @@ typedef struct _PlayerControl {
volatile float totalTime; volatile float totalTime;
volatile float elapsedTime; volatile float elapsedTime;
volatile float fileTime; volatile float fileTime;
Song *current_song; Song *volatile next_song;
Song *errored_song; Song *errored_song;
volatile mpd_sint8 queueState; volatile mpd_sint8 queueState;
volatile mpd_sint8 queueLockState; volatile mpd_sint8 queueLockState;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment