aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-06-01 18:10:13 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-06-01 18:10:13 +0000
commit6d7e0eb1664d14ae3d1d229acfcccf46abf947db (patch)
treea382eb8e90af2b2cc1de8b74d85118249ab93eaf
parent88638f4821842f76062397559614f36b717ffdbb (diff)
downloadmpd-6d7e0eb1664d14ae3d1d229acfcccf46abf947db.tar.gz
mpd-6d7e0eb1664d14ae3d1d229acfcccf46abf947db.tar.xz
mpd-6d7e0eb1664d14ae3d1d229acfcccf46abf947db.zip
Tell the player process (and thus also the decode process) to quit when
playback is stopped completely. This means the player process will no longer have to wake up 100 times per second to see if it's been told to start playing (the main process will just spawn a new player process when it needs to). On the downside, this means an extra pair of forks() and the re-initializing of the player and decode processes each time playback is restarted. git-svn-id: https://svn.musicpd.org/mpd/trunk@6446 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/player.c23
-rw-r--r--src/player.h3
-rw-r--r--src/playerData.c1
-rw-r--r--src/playlist.c5
4 files changed, 29 insertions, 3 deletions
diff --git a/src/player.c b/src/player.c
index 4870dc739..e2dc21064 100644
--- a/src/player.c
+++ b/src/player.c
@@ -155,6 +155,9 @@ int playerInit(void)
} else if (pc->cycleLogFiles) {
cycle_log_files();
pc->cycleLogFiles = 0;
+ } else if (pc->quit) {
+ pc->quit = 0;
+ break;
} else
my_usleep(10000);
}
@@ -174,6 +177,24 @@ int playerInit(void)
return 0;
}
+int playerQuit(int fd)
+{
+ PlayerControl *pc = &(getPlayerData()->playerControl);
+
+ if (playerStop(fd) < 0)
+ return -1;
+
+ playerCloseAudio();
+
+ if (player_pid > 0) {
+ pc->quit = 1;
+ while (player_pid > 0 && pc->quit)
+ my_usleep(1000);
+ }
+
+ return 0;
+}
+
int playerPlay(int fd, Song * song)
{
PlayerControl *pc = &(getPlayerData()->playerControl);
@@ -341,6 +362,8 @@ void playerCloseAudio(void)
if (playerStop(STDERR_FILENO) < 0)
return;
pc->closeAudio = 1;
+ while (player_pid > 0 && pc->closeAudio)
+ my_usleep(1000);
}
}
diff --git a/src/player.h b/src/player.h
index b62fab2ea..ce7eebc9b 100644
--- a/src/player.h
+++ b/src/player.h
@@ -57,6 +57,7 @@
#define PLAYER_METADATA_STATE_WRITE 2
typedef struct _PlayerControl {
+ volatile mpd_sint8 quit;
volatile mpd_sint8 stop;
volatile mpd_sint8 play;
volatile mpd_sint8 pause;
@@ -121,6 +122,8 @@ int getPlayerError(void);
int playerInit(void);
+int playerQuit(int fd);
+
int queueSong(Song * song);
int getPlayerQueueState(void);
diff --git a/src/playerData.c b/src/playerData.c
index 30ff6d6d6..e4506c1e7 100644
--- a/src/playerData.c
+++ b/src/playerData.c
@@ -118,6 +118,7 @@ void initPlayerData(void)
buffered_chunks * sizeof(mpd_sint8));
buffer->acceptMetadata = 0;
+ playerData_pd->playerControl.quit = 0;
playerData_pd->playerControl.stop = 0;
playerData_pd->playerControl.pause = 0;
playerData_pd->playerControl.play = 0;
diff --git a/src/playlist.c b/src/playlist.c
index de5a2a3d5..d68033e1b 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -786,7 +786,7 @@ int deleteFromPlaylist(int fd, int song)
&& playlist.current == songOrder) {
/*if(playlist.current>=playlist.length) return playerStop(fd);
else return playPlaylistOrderNumber(fd,playlist.current); */
- playerStop(STDERR_FILENO);
+ playerQuit(STDERR_FILENO);
playlist_noGoToNext = 1;
}
@@ -827,9 +827,8 @@ void deleteASongFromPlaylist(Song * song)
int stopPlaylist(int fd)
{
DEBUG("playlist: stop\n");
- if (playerStop(fd) < 0)
+ if (playerQuit(fd) < 0)
return -1;
- playerCloseAudio();
playlist.queued = -1;
playlist_state = PLAYLIST_STATE_STOP;
playlist_noGoToNext = 0;