Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
8b19235b
Commit
8b19235b
authored
Feb 27, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
parent
ad4246d6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
18 deletions
+43
-18
decode.c
src/decode.c
+22
-17
player.c
src/player.c
+19
-1
player.h
src/player.h
+1
-0
playerData.c
src/playerData.c
+1
-0
No files found.
src/decode.c
View file @
8b19235b
...
@@ -49,31 +49,35 @@
...
@@ -49,31 +49,35 @@
#define FADE_CHUNKS 1024
#define FADE_CHUNKS 1024
int
decode_pid
=
0
;
int
*
decode_pid
=
NULL
;
void
decodeSigHandler
(
int
sig
)
{
void
decodeSigHandler
(
int
sig
)
{
if
(
sig
==
SIGCHLD
)
{
if
(
sig
==
SIGCHLD
)
{
int
status
;
int
status
;
if
(
decode_pid
==
wait3
(
&
status
,
WNOHANG
,
NULL
))
{
if
(
decode_pid
&&
*
decode_pid
==
wait3
(
&
status
,
WNOHANG
,
NULL
))
{
if
(
WIFSIGNALED
(
status
)
&&
WTERMSIG
(
status
)
!=
SIGTERM
)
{
if
(
WIFSIGNALED
(
status
)
&&
WTERMSIG
(
status
)
!=
SIGTERM
)
{
ERROR
(
"decode process died from a "
ERROR
(
"decode process died from a "
"non-TERM signal: %i
\n
"
,
"non-TERM signal: %i
\n
"
,
WTERMSIG
(
status
));
WTERMSIG
(
status
));
}
}
decode_pid
=
0
;
*
decode_pid
=
0
;
}
}
}
}
else
if
(
sig
==
SIGTERM
)
{
else
if
(
sig
==
SIGTERM
)
{
int
pid
=
decode_pid
;
if
(
decode_pid
)
{
if
(
pid
>
0
)
kill
(
pid
,
SIGTERM
);
int
pid
=
*
decode_pid
;
if
(
pid
>
0
)
kill
(
pid
,
SIGTERM
);
}
exit
(
0
);
exit
(
0
);
}
}
}
}
void
stopDecode
(
DecoderControl
*
dc
)
{
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
;
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) {
...
@@ -106,7 +110,7 @@ int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) {
int
waitOnDecode
(
PlayerControl
*
pc
,
AudioFormat
*
af
,
DecoderControl
*
dc
,
int
waitOnDecode
(
PlayerControl
*
pc
,
AudioFormat
*
af
,
DecoderControl
*
dc
,
Buffer
*
cb
)
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
)
{
if
(
dc
->
start
||
dc
->
error
!=
DECODE_ERROR_NOERROR
)
{
strncpy
(
pc
->
erroredFile
,
pc
->
file
,
MAXPATHLEN
);
strncpy
(
pc
->
erroredFile
,
pc
->
file
,
MAXPATHLEN
);
...
@@ -135,7 +139,7 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
...
@@ -135,7 +139,7 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
void
decodeSeek
(
PlayerControl
*
pc
,
AudioFormat
*
af
,
DecoderControl
*
dc
,
void
decodeSeek
(
PlayerControl
*
pc
,
AudioFormat
*
af
,
DecoderControl
*
dc
,
Buffer
*
cb
)
Buffer
*
cb
)
{
{
if
(
decode_pid
>
0
)
{
if
(
decode_pid
&&
*
decode_pid
>
0
)
{
cb
->
next
=
-
1
;
cb
->
next
=
-
1
;
if
(
dc
->
state
!=
DECODE_STATE_DECODE
||
dc
->
error
||
if
(
dc
->
state
!=
DECODE_STATE_DECODE
||
dc
->
error
||
strcmp
(
dc
->
file
,
pc
->
file
)
!=
0
)
strcmp
(
dc
->
file
,
pc
->
file
)
!=
0
)
...
@@ -147,7 +151,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
...
@@ -147,7 +151,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
dc
->
error
=
0
;
dc
->
error
=
0
;
waitOnDecode
(
pc
,
af
,
dc
,
cb
);
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
?
dc
->
seekWhere
=
pc
->
seekWhere
>
pc
->
totalTime
-
1
?
pc
->
totalTime
-
1
:
pc
->
seekWhere
;
pc
->
totalTime
-
1
:
pc
->
seekWhere
;
dc
->
seekWhere
=
1
>
dc
->
seekWhere
?
1
:
dc
->
seekWhere
;
dc
->
seekWhere
=
1
>
dc
->
seekWhere
?
1
:
dc
->
seekWhere
;
...
@@ -155,7 +159,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
...
@@ -155,7 +159,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
dc
->
seek
=
1
;
dc
->
seek
=
1
;
pc
->
elapsedTime
=
dc
->
seekWhere
;
pc
->
elapsedTime
=
dc
->
seekWhere
;
pc
->
bitRate
=
0
;
pc
->
bitRate
=
0
;
while
(
decode_pid
>
0
&&
dc
->
seek
)
usleep
(
10
);
while
(
*
decode_pid
>
0
&&
dc
->
seek
)
usleep
(
10
);
}
}
}
}
pc
->
seek
=
0
;
pc
->
seek
=
0
;
...
@@ -193,9 +197,10 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
...
@@ -193,9 +197,10 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
int
decoderInit
(
PlayerControl
*
pc
,
Buffer
*
cb
,
AudioFormat
*
af
,
int
decoderInit
(
PlayerControl
*
pc
,
Buffer
*
cb
,
AudioFormat
*
af
,
DecoderControl
*
dc
)
{
DecoderControl
*
dc
)
{
decode_pid
=
fork
();
decode_pid
=
&
(
pc
->
decode_pid
);
*
decode_pid
=
fork
();
if
(
decode_pid
==
0
)
{
if
(
*
decode_pid
==
0
)
{
/* CHILD */
/* CHILD */
while
(
1
)
{
while
(
1
)
{
...
@@ -242,7 +247,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
...
@@ -242,7 +247,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
exit
(
0
);
exit
(
0
);
/* END OF CHILD */
/* END OF CHILD */
}
}
else
if
(
decode_pid
<
0
)
{
else
if
(
*
decode_pid
<
0
)
{
strncpy
(
pc
->
erroredFile
,
pc
->
file
,
MAXPATHLEN
);
strncpy
(
pc
->
erroredFile
,
pc
->
file
,
MAXPATHLEN
);
pc
->
error
=
PLAYER_ERROR_SYSTEM
;
pc
->
error
=
PLAYER_ERROR_SYSTEM
;
return
-
1
;
return
-
1
;
...
@@ -274,7 +279,7 @@ void decode() {
...
@@ -274,7 +279,7 @@ void decode() {
dc
->
start
=
1
;
dc
->
start
=
1
;
cb
->
next
=
-
1
;
cb
->
next
=
-
1
;
if
(
decode_pid
<=
0
)
{
if
(
decode_pid
==
NULL
||
*
decode_pid
<=
0
)
{
if
(
decoderInit
(
pc
,
cb
,
af
,
dc
)
<
0
)
return
;
if
(
decoderInit
(
pc
,
cb
,
af
,
dc
)
<
0
)
return
;
}
}
...
@@ -299,7 +304,7 @@ void decode() {
...
@@ -299,7 +304,7 @@ void decode() {
pc
->
beginTime
=
pc
->
elapsedTime
;
pc
->
beginTime
=
pc
->
elapsedTime
;
kill
(
getppid
(),
SIGUSR1
);
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
)
dc
->
state
==
DECODE_STATE_DECODE
)
{
{
processDecodeInput
();
processDecodeInput
();
...
@@ -443,7 +448,7 @@ void decode() {
...
@@ -443,7 +448,7 @@ void decode() {
}
}
pc
->
beginTime
=
cb
->
times
[
cb
->
begin
];
pc
->
beginTime
=
cb
->
times
[
cb
->
begin
];
}
}
else
if
(
decode_pid
<=
0
||
else
if
(
*
decode_pid
<=
0
||
(
dc
->
state
==
DECODE_STATE_STOP
&&
!
dc
->
start
))
(
dc
->
state
==
DECODE_STATE_STOP
&&
!
dc
->
start
))
{
{
quit
=
1
;
quit
=
1
;
...
...
src/player.c
View file @
8b19235b
...
@@ -48,6 +48,8 @@ int player_pid = 0;
...
@@ -48,6 +48,8 @@ int player_pid = 0;
int
player_termSent
=
0
;
int
player_termSent
=
0
;
void
resetPlayer
()
{
void
resetPlayer
()
{
int
pid
;
player_pid
=
0
;
player_pid
=
0
;
player_termSent
=
0
;
player_termSent
=
0
;
getPlayerData
()
->
playerControl
.
stop
=
0
;
getPlayerData
()
->
playerControl
.
stop
=
0
;
...
@@ -58,12 +60,17 @@ void resetPlayer() {
...
@@ -58,12 +60,17 @@ void resetPlayer() {
getPlayerData
()
->
playerControl
.
state
=
PLAYER_STATE_STOP
;
getPlayerData
()
->
playerControl
.
state
=
PLAYER_STATE_STOP
;
getPlayerData
()
->
playerControl
.
queueState
=
PLAYER_QUEUE_UNLOCKED
;
getPlayerData
()
->
playerControl
.
queueState
=
PLAYER_QUEUE_UNLOCKED
;
getPlayerData
()
->
playerControl
.
seek
=
0
;
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
)
{
void
player_sigHandler
(
int
signal
)
{
if
(
signal
==
SIGCHLD
)
{
if
(
signal
==
SIGCHLD
)
{
int
status
;
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
)
{
if
(
WIFSIGNALED
(
status
)
&&
WTERMSIG
(
status
)
!=
SIGTERM
)
{
ERROR
(
"player process died from a "
ERROR
(
"player process died from a "
"non-TERM signal: %i
\n
"
,
"non-TERM signal: %i
\n
"
,
...
@@ -71,6 +78,17 @@ void player_sigHandler(int signal) {
...
@@ -71,6 +78,17 @@ void player_sigHandler(int signal) {
}
}
resetPlayer
();
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
;
}
}
}
}
}
...
...
src/player.h
View file @
8b19235b
...
@@ -74,6 +74,7 @@ typedef struct _PlayerControl {
...
@@ -74,6 +74,7 @@ typedef struct _PlayerControl {
float
crossFade
;
float
crossFade
;
mpd_sint8
softwareVolume
;
mpd_sint8
softwareVolume
;
double
totalPlayTime
;
double
totalPlayTime
;
int
decode_pid
;
}
PlayerControl
;
}
PlayerControl
;
void
player_sigHandler
(
int
signal
);
void
player_sigHandler
(
int
signal
);
...
...
src/playerData.c
View file @
8b19235b
...
@@ -107,6 +107,7 @@ void initPlayerData() {
...
@@ -107,6 +107,7 @@ void initPlayerData() {
playerData_pd
->
playerControl
.
crossFade
=
crossfade
;
playerData_pd
->
playerControl
.
crossFade
=
crossfade
;
playerData_pd
->
playerControl
.
softwareVolume
=
100
;
playerData_pd
->
playerControl
.
softwareVolume
=
100
;
playerData_pd
->
playerControl
.
totalPlayTime
=
0
;
playerData_pd
->
playerControl
.
totalPlayTime
=
0
;
playerData_pd
->
playerControl
.
decode_pid
=
0
;
playerData_pd
->
decoderControl
.
stop
=
0
;
playerData_pd
->
decoderControl
.
stop
=
0
;
playerData_pd
->
decoderControl
.
start
=
0
;
playerData_pd
->
decoderControl
.
start
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment