put decode_pid in shared mem, so if player process dies, the master
can still kill the decode process. git-svn-id: https://svn.musicpd.org/mpd/trunk@107 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
ad4246d6cb
commit
8b19235b61
37
src/decode.c
37
src/decode.c
|
@ -49,31 +49,35 @@
|
|||
|
||||
#define FADE_CHUNKS 1024
|
||||
|
||||
int decode_pid = 0;
|
||||
int * decode_pid = NULL;
|
||||
|
||||
void decodeSigHandler(int sig) {
|
||||
if(sig==SIGCHLD) {
|
||||
int status;
|
||||
if(decode_pid==wait3(&status,WNOHANG,NULL)) {
|
||||
if(decode_pid && *decode_pid==wait3(&status,WNOHANG,NULL)) {
|
||||
if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
|
||||
ERROR("decode process died from a "
|
||||
"non-TERM signal: %i\n",
|
||||
WTERMSIG(status));
|
||||
}
|
||||
decode_pid = 0;
|
||||
*decode_pid = 0;
|
||||
}
|
||||
}
|
||||
else if(sig==SIGTERM) {
|
||||
int pid = decode_pid;
|
||||
if(decode_pid) {
|
||||
int pid = *decode_pid;
|
||||
if(pid>0) kill(pid,SIGTERM);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void stopDecode(DecoderControl * dc) {
|
||||
if(decode_pid>0 && (dc->start || dc->state==DECODE_STATE_DECODE)) {
|
||||
if(decode_pid && *decode_pid>0 &&
|
||||
(dc->start || dc->state==DECODE_STATE_DECODE))
|
||||
{
|
||||
dc->stop = 1;
|
||||
while(decode_pid>0 && dc->stop) usleep(10);
|
||||
while(decode_pid && *decode_pid>0 && dc->stop) usleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,7 +110,7 @@ int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) {
|
|||
int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
||||
Buffer * cb)
|
||||
{
|
||||
while(decode_pid>0 && dc->start) usleep(10);
|
||||
while(decode_pid && *decode_pid>0 && dc->start) usleep(10);
|
||||
|
||||
if(dc->start || dc->error!=DECODE_ERROR_NOERROR) {
|
||||
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
|
||||
|
@ -135,7 +139,7 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
|||
void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
||||
Buffer * cb)
|
||||
{
|
||||
if(decode_pid>0) {
|
||||
if(decode_pid && *decode_pid>0) {
|
||||
cb->next = -1;
|
||||
if(dc->state!=DECODE_STATE_DECODE || dc->error ||
|
||||
strcmp(dc->file,pc->file)!=0)
|
||||
|
@ -147,7 +151,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
|||
dc->error = 0;
|
||||
waitOnDecode(pc,af,dc,cb);
|
||||
}
|
||||
if(decode_pid>0 && dc->state==DECODE_STATE_DECODE) {
|
||||
if(*decode_pid>0 && dc->state==DECODE_STATE_DECODE) {
|
||||
dc->seekWhere = pc->seekWhere > pc->totalTime-1 ?
|
||||
pc->totalTime-1 : pc->seekWhere;
|
||||
dc->seekWhere = 1 > dc->seekWhere ? 1 : dc->seekWhere;
|
||||
|
@ -155,7 +159,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
|||
dc->seek = 1;
|
||||
pc->elapsedTime = dc->seekWhere;
|
||||
pc->bitRate = 0;
|
||||
while(decode_pid>0 && dc->seek) usleep(10);
|
||||
while(*decode_pid>0 && dc->seek) usleep(10);
|
||||
}
|
||||
}
|
||||
pc->seek = 0;
|
||||
|
@ -193,9 +197,10 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
|
|||
|
||||
int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
|
||||
DecoderControl * dc) {
|
||||
decode_pid = fork();
|
||||
decode_pid = &(pc->decode_pid);
|
||||
*decode_pid = fork();
|
||||
|
||||
if(decode_pid==0) {
|
||||
if(*decode_pid==0) {
|
||||
/* CHILD */
|
||||
|
||||
while(1) {
|
||||
|
@ -242,7 +247,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
|
|||
exit(0);
|
||||
/* END OF CHILD */
|
||||
}
|
||||
else if(decode_pid<0) {
|
||||
else if(*decode_pid<0) {
|
||||
strncpy(pc->erroredFile,pc->file,MAXPATHLEN);
|
||||
pc->error = PLAYER_ERROR_SYSTEM;
|
||||
return -1;
|
||||
|
@ -274,7 +279,7 @@ void decode() {
|
|||
dc->start = 1;
|
||||
cb->next = -1;
|
||||
|
||||
if(decode_pid<=0) {
|
||||
if(decode_pid==NULL || *decode_pid<=0) {
|
||||
if(decoderInit(pc,cb,af,dc)<0) return;
|
||||
}
|
||||
|
||||
|
@ -299,7 +304,7 @@ void decode() {
|
|||
pc->beginTime = pc->elapsedTime;
|
||||
kill(getppid(),SIGUSR1);
|
||||
|
||||
while(decode_pid>0 && !cb->wrap && cb->end-cb->begin<bbp &&
|
||||
while(*decode_pid>0 && !cb->wrap && cb->end-cb->begin<bbp &&
|
||||
dc->state==DECODE_STATE_DECODE)
|
||||
{
|
||||
processDecodeInput();
|
||||
|
@ -443,7 +448,7 @@ void decode() {
|
|||
}
|
||||
pc->beginTime = cb->times[cb->begin];
|
||||
}
|
||||
else if(decode_pid<=0 ||
|
||||
else if(*decode_pid<=0 ||
|
||||
(dc->state==DECODE_STATE_STOP && !dc->start))
|
||||
{
|
||||
quit = 1;
|
||||
|
|
20
src/player.c
20
src/player.c
|
@ -48,6 +48,8 @@ int player_pid = 0;
|
|||
int player_termSent = 0;
|
||||
|
||||
void resetPlayer() {
|
||||
int pid;
|
||||
|
||||
player_pid = 0;
|
||||
player_termSent = 0;
|
||||
getPlayerData()->playerControl.stop = 0;
|
||||
|
@ -58,12 +60,17 @@ void resetPlayer() {
|
|||
getPlayerData()->playerControl.state = PLAYER_STATE_STOP;
|
||||
getPlayerData()->playerControl.queueState = PLAYER_QUEUE_UNLOCKED;
|
||||
getPlayerData()->playerControl.seek = 0;
|
||||
/* kill decode process if it got left running */
|
||||
pid = getPlayerData()->playerControl.decode_pid;
|
||||
if(pid>0) kill(pid,SIGTERM);
|
||||
getPlayerData()->playerControl.decode_pid = 0;
|
||||
}
|
||||
|
||||
void player_sigHandler(int signal) {
|
||||
if(signal==SIGCHLD) {
|
||||
int status;
|
||||
if(player_pid==wait3(&status,WNOHANG,NULL)) {
|
||||
int pid = wait3(&status,WNOHANG,NULL);
|
||||
if(player_pid==pid) {
|
||||
if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
|
||||
ERROR("player process died from a "
|
||||
"non-TERM signal: %i\n",
|
||||
|
@ -71,6 +78,17 @@ void player_sigHandler(int signal) {
|
|||
}
|
||||
resetPlayer();
|
||||
}
|
||||
else if(pid==getPlayerData()->playerControl.decode_pid &&
|
||||
player_pid<=0)
|
||||
{
|
||||
if(WIFSIGNALED(status) && WTERMSIG(status)!=SIGTERM) {
|
||||
ERROR("(caught by master parent) "
|
||||
"decode process died from a "
|
||||
"non-TERM signal: %i\n",
|
||||
WTERMSIG(status));
|
||||
}
|
||||
getPlayerData()->playerControl.decode_pid = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,6 +74,7 @@ typedef struct _PlayerControl {
|
|||
float crossFade;
|
||||
mpd_sint8 softwareVolume;
|
||||
double totalPlayTime;
|
||||
int decode_pid;
|
||||
} PlayerControl;
|
||||
|
||||
void player_sigHandler(int signal);
|
||||
|
|
|
@ -107,6 +107,7 @@ void initPlayerData() {
|
|||
playerData_pd->playerControl.crossFade = crossfade;
|
||||
playerData_pd->playerControl.softwareVolume = 100;
|
||||
playerData_pd->playerControl.totalPlayTime = 0;
|
||||
playerData_pd->playerControl.decode_pid = 0;
|
||||
|
||||
playerData_pd->decoderControl.stop = 0;
|
||||
playerData_pd->decoderControl.start = 0;
|
||||
|
|
Loading…
Reference in New Issue