possible race condition?

For help and support with PS3 Media Server in general
Forum rules
Please make sure you follow the Problem Reporting Guidelines before posting if you want a reply.

possible race condition?

Postby jxp » Tue Aug 20, 2013 7:14 am

Hi,

I'm using PMS 1.81.0+mencoder35005-3precise on Linux Mint 13 (Ubuntu 12.04) to stream to a PS3 over a wire.

I'm having mixed success with tsmuxer on mkv files, sometimes it works, other times it doesn't (on the same file). Edit: When it doesn't work, the PS3 displays: "This content cannot be played.". I was looking at the logs and it seems to me there could be a race condition in the way some subprocesses interact. Below is the relevant part of the log. The mkfifo's seem to be executed in subprocesses (?), each of which produces at least 2 log messages: "Starting..." and "Unix process ID...". Looking at the error, the process which creates the file which is found missing is mkfifo-476, but this one doesn't get to log "Unix process ID..." until after the missing file error occurs. This suggests the mkfifo didn't run when another thread tried to use that file.

Is this plausible? It would definitely explain the sporadic success of running tsmuxer. I tried googling for ps3ms race condition but I couldn't find anything relevant.

Thanks!


INFO 2013-08-20 01:28:02.618 [New I/O server worker #4-3] Starting transcode/remux of everything.mkv
DEBUG 2013-08-20 01:28:02.642 [mkfifo-473] Starting mkfifo --mode=777 /tmp/ps3mediaserver/1376976482631tsmuxerout.ts
DEBUG 2013-08-20 01:28:02.732 [mkfifo-474] Starting mkfifo --mode=777 /tmp/ps3mediaserver/1376976482630ffmpegvideo
DEBUG 2013-08-20 01:28:02.739 [mkfifo-475] Starting mkfifo --mode=777 /tmp/ps3mediaserver/1376976482630videoout
DEBUG 2013-08-20 01:28:02.967 [mkfifo-473] Unix process ID (mkfifo): 10173
DEBUG 2013-08-20 01:28:02.967 [mkfifo-474] Unix process ID (mkfifo): 10178
DEBUG 2013-08-20 01:28:03.007 [mencoder-470] Starting /usr/lib/ps3mediaserver/linux/mencoder -ss 0 /mnt/array/data/matei/public/movies/tmp/everything.mkv -quiet -quiet -really-quiet -msglevel statusline=2 -ovc copy -nosound -mc 0 -noskip -of rawvideo -o /tmp/ps3mediaserver/1376976482630ffmpegvideo
DEBUG 2013-08-20 01:28:03.050 [mkfifo-475] Unix process ID (mkfifo): 10179
DEBUG 2013-08-20 01:28:03.060 [mkfifo-476] Starting mkfifo --mode=777 /tmp/ps3mediaserver/1376976482630ffmpegaudio01
DEBUG 2013-08-20 01:28:03.060 [mkfifo-477] Starting mkfifo --mode=777 /tmp/ps3mediaserver/1376976482630audioout
DEBUG 2013-08-20 01:28:03.219 [mencoder-470] Attaching thread: mencoder-470
DEBUG 2013-08-20 01:28:03.220 [mencoder-470] Unix process ID (/usr/lib/ps3mediaserver/linux/mencoder): 10189
DEBUG 2013-08-20 01:28:03.234 [Thread-1371] Error :/tmp/ps3mediaserver/1376976482630ffmpegaudio01 (No such file or directory)
DEBUG 2013-08-20 01:28:03.275 [mkfifo-476] Unix process ID (mkfifo): 10194
DEBUG 2013-08-20 01:28:03.278 [mencoder-471] Starting /usr/lib/ps3mediaserver/linux/mencoder -ss 0 /mnt/array/data/matei/public/movies/tmp/everything.mkv -quiet -quiet -really-quiet -msglevel statusline=2 -channels 2 -ovc copy -of rawaudio -mc 0 -noskip -oac lavc -quiet -quiet -lavcopts acodec=ac3:abitrate=448 -af lavcresample=48000 -srate 48000 -quiet -quiet -o /tmp/ps3mediaserver/1376976482630ffmpegaudio01


Edit: Look at lines 706-717 in src/main/java/net/pms/encoders/TsMuxeRVideo.java in the current git tree (starting at "for (int i = 0; i < ffAudioPipe.length; i++) {"). If I read it correctly(?) this is where the mkfifo process and the consumer (mencoder) process are both started when using tsmuxer, is this right?! First the mkfifo starts on line 709, then the consumer starts on line 716. It seems that the "sleep(50)" on line 711 is the only thing that is supposed to prevent the race condition between the mkfifo process creating the fifo, and the consumer opening it. Can this sleep be replaced by a proper, platform-dependent wait?
jxp
 
Posts: 3
Joined: Tue Aug 20, 2013 6:44 am

Re: possible race condition?

Postby jxp » Wed Aug 21, 2013 5:57 am

I found a relatively easy workaround. I must say, I don't know how processes communicate in non-Linux OSs, so this might not be necessary. Also, I don't know if this breaks anything else. But it seems to make TSMuxeR work consistently for me, for now. The idea is to add a longer delay to the mencoder processes. The java code waits only 50ms before using a mkfifo object, here I increase this 20x to 1s. Don't try this at home.
Code: Select all
$ cd /usr/lib/ps3mediaserver/linux
$ mv mencoder mencoder.orig
$ cat <<EOF >mencoder
#!/bin/bash
sleep 1
exec /usr/lib/ps3mediaserver/linux/mencoder.orig "$@"
EOF
$ chmod a+x mencoder
jxp
 
Posts: 3
Joined: Tue Aug 20, 2013 6:44 am

Re: possible race condition?

Postby Raptor399 » Wed Aug 21, 2013 10:32 pm

Creative! :-)

If I find the time, I'll try to look into a fix on the PMS side.

Thanks for sharing!
Raptor399
Project Member
 
Posts: 1916
Joined: Thu Mar 10, 2011 12:06 am

Re: possible race condition?

Postby Raptor399 » Sat Aug 24, 2013 10:33 am

Fix committed.
Let me know if the snapshot build solves the problem without the scripted MEncoder sleep workaround.
Raptor399
Project Member
 
Posts: 1916
Joined: Thu Mar 10, 2011 12:06 am

Re: possible race condition?

Postby jxp » Thu Sep 26, 2013 5:18 am

Thank you for looking into this. I haven't had the time to look into this any more ('life happened'), so I've been using the workaround. But I wanted to say I appreciate the fact you took care of it for future releases.
jxp
 
Posts: 3
Joined: Tue Aug 20, 2013 6:44 am


Return to General Help and Support

Who is online

Users browsing this forum: Google [Bot] and 11 guests