[MPlayer-dev-eng] Failing to exit on SIGINT/SIGHUP - Cache2.c cache_read

Lee Jackson leej at sowhatresearch.com
Wed Feb 17 22:20:21 CET 2010


Hello,

I originally posted this problem nearly a year ago in the user mailing list and given it still hasnt been fixed I thought I would repost it in the dev list and ask if anyone can suggest a "real" fix rather than the naive fix I ended up implementing.

I have an application that, in order to create multiple real-time versions of a live video capture, uses VLC to capture the video and stream it via http. e,g,

cvlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-adev=\"plughw.UA25\" :v4l2-standard=0 :v4l2-width=720 :v4l2-height=576 :v4l2-fps=25 --sout '#transcode{vcodec=mp2v,vb=8000,hq,deinterlace,acodec=mpga,ab=128,channels=2}:duplicate{dst=std{access=http,mux=ps,url=localhost:8080}}'

I then have several instances of mencoder  encoding this in various formats. e.g.

mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=%s:vbitrate=%s:acodec=ac3:abitrate=192:vstrict=0 -ofps 25 -vf scale=720:576 -lavcopts aspect=4/3 http://127.0.0.1:8080 -o test.mpg

This allows me to generate mpeg2, mp4 and an mp3 and obtain a direct copy of the stream (we are aiming to capture, save and convert everything from a 1080p source, in close to real-time).

The PROBLEM I have is that sending a sigint/sighup/sigterm to the process, @ 50% of the time will end up with the mencoder process caught in an endless loop within the stream/cache2.c cache_read function since s->eof never seems to evaluate as true (exit(0) is called but the cache_read loop doesn't end). Hence the process never exits and it causes all sorts of problems for my framework (and as an aside, if anyone can suggest another/better way to take a single video source and transcode it to multiple formats I would be very interested).

Now to fix this I added additional signal handlers e.g. signal(SIGINT,exit_sighandler) , added a simple flag to the exit_sighandler e.g.

static void exit_sighandler(int x){
  bTerminated_Flag = 1;
}

and changed the lines (112-114 in the current SVN version) to :
  // eof?
  if(s->eof) break;
  if (bTerminated_Flag != 0) break;

And at last, mencoder would reliably exit while transcoding!

Now I know this is a hack but I didnt have the time then to get to grips with the cache handling code and work out why s->eof wasnt being set to true when the app was supposed to exit OR how to set it to true without using the cludge of a seperate flag (I dont really have the time now).

I also have no idea of the consequences of this change so I've been hoping someone else would come along and fix it. 10 months later, it isnt fixed so can anyone help me to put together a patch to fix this or suggest a better fix than this?

Many thanks

Lee




More information about the MPlayer-dev-eng mailing list