Don't kill the player process (and effectively the decode process) when
completely stopped. Instead, send them SIGSTOP to pause the process until they're needed again. Then send them SIGCONT instead of re-spawning them. git-svn-id: https://svn.musicpd.org/mpd/trunk@6485 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
4734a2e2b4
commit
89eca9eebc
20
src/decode.c
20
src/decode.c
|
@ -75,6 +75,8 @@ static void stopDecode(DecoderControl * dc)
|
||||||
|
|
||||||
static void quitDecode(PlayerControl * pc, DecoderControl * dc)
|
static void quitDecode(PlayerControl * pc, DecoderControl * dc)
|
||||||
{
|
{
|
||||||
|
int pid;
|
||||||
|
|
||||||
stopDecode(dc);
|
stopDecode(dc);
|
||||||
pc->state = PLAYER_STATE_STOP;
|
pc->state = PLAYER_STATE_STOP;
|
||||||
dc->seek = 0;
|
dc->seek = 0;
|
||||||
|
@ -82,6 +84,10 @@ static void quitDecode(PlayerControl * pc, DecoderControl * dc)
|
||||||
pc->stop = 0;
|
pc->stop = 0;
|
||||||
pc->pause = 0;
|
pc->pause = 0;
|
||||||
kill(getppid(), SIGUSR1);
|
kill(getppid(), SIGUSR1);
|
||||||
|
|
||||||
|
pid = decode_pid;
|
||||||
|
if (pid > 0)
|
||||||
|
kill(pid, SIGSTOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af)
|
static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af)
|
||||||
|
@ -396,6 +402,14 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb,
|
||||||
static int decoderInit(PlayerControl * pc, OutputBuffer * cb,
|
static int decoderInit(PlayerControl * pc, OutputBuffer * cb,
|
||||||
DecoderControl * dc)
|
DecoderControl * dc)
|
||||||
{
|
{
|
||||||
|
int pid;
|
||||||
|
|
||||||
|
pid = decode_pid;
|
||||||
|
if (pid > 0) {
|
||||||
|
kill(pid, SIGCONT);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
blockSignals();
|
blockSignals();
|
||||||
getPlayerData()->playerControl.decode_pid = 0;
|
getPlayerData()->playerControl.decode_pid = 0;
|
||||||
decode_pid = fork();
|
decode_pid = fork();
|
||||||
|
@ -691,10 +705,8 @@ void decode(void)
|
||||||
dc->stop = 0;
|
dc->stop = 0;
|
||||||
dc->start = 1;
|
dc->start = 1;
|
||||||
|
|
||||||
if (decode_pid <= 0) {
|
if (decoderInit(pc, cb, dc) < 0)
|
||||||
if (decoderInit(pc, cb, dc) < 0)
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
decodeParent(pc, dc, cb);
|
decodeParent(pc, dc, cb);
|
||||||
}
|
}
|
||||||
|
|
29
src/player.c
29
src/player.c
|
@ -110,6 +110,14 @@ void player_sigChldHandler(int pid, int status)
|
||||||
|
|
||||||
int playerInit(void)
|
int playerInit(void)
|
||||||
{
|
{
|
||||||
|
int pid;
|
||||||
|
|
||||||
|
pid = player_pid;
|
||||||
|
if (pid > 0) {
|
||||||
|
kill(pid, SIGCONT);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
blockSignals();
|
blockSignals();
|
||||||
player_pid = fork();
|
player_pid = fork();
|
||||||
if (player_pid==0)
|
if (player_pid==0)
|
||||||
|
@ -155,9 +163,6 @@ int playerInit(void)
|
||||||
} else if (pc->cycleLogFiles) {
|
} else if (pc->cycleLogFiles) {
|
||||||
cycle_log_files();
|
cycle_log_files();
|
||||||
pc->cycleLogFiles = 0;
|
pc->cycleLogFiles = 0;
|
||||||
} else if (pc->quit) {
|
|
||||||
pc->quit = 0;
|
|
||||||
break;
|
|
||||||
} else
|
} else
|
||||||
my_usleep(10000);
|
my_usleep(10000);
|
||||||
}
|
}
|
||||||
|
@ -177,20 +182,18 @@ int playerInit(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int playerQuit(int fd)
|
int playerWait(int fd)
|
||||||
{
|
{
|
||||||
PlayerControl *pc = &(getPlayerData()->playerControl);
|
int pid;
|
||||||
|
|
||||||
if (playerStop(fd) < 0)
|
if (playerStop(fd) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
playerCloseAudio();
|
playerCloseAudio();
|
||||||
|
|
||||||
if (player_pid > 0) {
|
pid = player_pid;
|
||||||
pc->quit = 1;
|
if (pid > 0)
|
||||||
while (player_pid > 0 && pc->quit)
|
kill(pid, SIGSTOP);
|
||||||
my_usleep(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -212,7 +215,7 @@ int playerPlay(int fd, Song * song)
|
||||||
pathcpy_trunc(pc->utf8url, getSongUrl(song));
|
pathcpy_trunc(pc->utf8url, getSongUrl(song));
|
||||||
|
|
||||||
pc->play = 1;
|
pc->play = 1;
|
||||||
if (player_pid == 0 && playerInit() < 0) {
|
if (playerInit() < 0) {
|
||||||
pc->play = 0;
|
pc->play = 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -245,8 +248,10 @@ void playerKill(void)
|
||||||
int pid;
|
int pid;
|
||||||
|
|
||||||
pid = player_pid;
|
pid = player_pid;
|
||||||
if (pid > 0)
|
if (pid > 0) {
|
||||||
|
kill(pid, SIGCONT);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int playerPause(int fd)
|
int playerPause(int fd)
|
||||||
|
|
|
@ -57,7 +57,6 @@
|
||||||
#define PLAYER_METADATA_STATE_WRITE 2
|
#define PLAYER_METADATA_STATE_WRITE 2
|
||||||
|
|
||||||
typedef struct _PlayerControl {
|
typedef struct _PlayerControl {
|
||||||
volatile mpd_sint8 quit;
|
|
||||||
volatile mpd_sint8 stop;
|
volatile mpd_sint8 stop;
|
||||||
volatile mpd_sint8 play;
|
volatile mpd_sint8 play;
|
||||||
volatile mpd_sint8 pause;
|
volatile mpd_sint8 pause;
|
||||||
|
@ -122,7 +121,7 @@ int getPlayerError(void);
|
||||||
|
|
||||||
int playerInit(void);
|
int playerInit(void);
|
||||||
|
|
||||||
int playerQuit(int fd);
|
int playerWait(int fd);
|
||||||
|
|
||||||
int queueSong(Song * song);
|
int queueSong(Song * song);
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,6 @@ void initPlayerData(void)
|
||||||
buffered_chunks * sizeof(mpd_sint8));
|
buffered_chunks * sizeof(mpd_sint8));
|
||||||
buffer->acceptMetadata = 0;
|
buffer->acceptMetadata = 0;
|
||||||
|
|
||||||
playerData_pd->playerControl.quit = 0;
|
|
||||||
playerData_pd->playerControl.stop = 0;
|
playerData_pd->playerControl.stop = 0;
|
||||||
playerData_pd->playerControl.pause = 0;
|
playerData_pd->playerControl.pause = 0;
|
||||||
playerData_pd->playerControl.play = 0;
|
playerData_pd->playerControl.play = 0;
|
||||||
|
|
|
@ -788,7 +788,7 @@ int deleteFromPlaylist(int fd, int song)
|
||||||
&& playlist.current == songOrder) {
|
&& playlist.current == songOrder) {
|
||||||
/*if(playlist.current>=playlist.length) return playerStop(fd);
|
/*if(playlist.current>=playlist.length) return playerStop(fd);
|
||||||
else return playPlaylistOrderNumber(fd,playlist.current); */
|
else return playPlaylistOrderNumber(fd,playlist.current); */
|
||||||
playerQuit(STDERR_FILENO);
|
playerWait(STDERR_FILENO);
|
||||||
playlist_noGoToNext = 1;
|
playlist_noGoToNext = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -829,7 +829,7 @@ void deleteASongFromPlaylist(Song * song)
|
||||||
int stopPlaylist(int fd)
|
int stopPlaylist(int fd)
|
||||||
{
|
{
|
||||||
DEBUG("playlist: stop\n");
|
DEBUG("playlist: stop\n");
|
||||||
if (playerQuit(fd) < 0)
|
if (playerWait(fd) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
playlist.queued = -1;
|
playlist.queued = -1;
|
||||||
playlist_state = PLAYLIST_STATE_STOP;
|
playlist_state = PLAYLIST_STATE_STOP;
|
||||||
|
|
Loading…
Reference in New Issue