[MPlayer-dev-eng] mplayer playing to fast ot /me to stupid ?, problem with decoding dvb stream

Alexander Neundorf neundorf at dellingsoft.de
Tue Apr 23 08:31:29 CEST 2002


Hi,

I try to use mplayer to decode the stream coming from my budget dvbs card. It 
works fine for approx. 10 minutes and then it starts to get jerky.
I do the following:

I start  dvbstream:

fork()
int dvbstreamStdout=dup(...);
exec ("dvbstream","-f"...,"-ps","-o");

i.e. I tell dvbstream to generate a PS stream and write this to stdout.

then I start mplayer:
fork();
int mplayerStdin=dup(...);
exec("mplayer","-vo","xv","-ao","oss","-framedrop","-",0);

Additionally I have a buffer handler, which contains a number of buffers of a 
fixed size, I use 40 x 8kb. More buffers didn't make my problem go away. When 
starting I wait until my buffer handler contains 20 buffers. Then as soon as 
I can read something from dvbstream I read it and put it into the buffer 
handler. As soon as I am able to write data to mplayer I get the next buffer 
from my buffer handler and write it. After some minutes the number of filled 
buffers in my buffer handler goes down until it reaches 0 and I have nothing 
to write to mplayer :-(
Without "-framedrop" the picture doesn't start to jump, but after some 
minutes it loses AV sync and finally the sound is away.
It's mplayer from cvs yesterday on a Athlon 1.3 GHz.

My thread main loop does the following:

while (1)
{
   struct timeval tv;
   tv.tv_sec=1;     tv.tv_usec=0;
// create the fd set for reading from dvbstream
   fd_set rfds;  
   FD_ZERO (&rfds);
   FD_SET (dvbstreamStdout, &rfds);
   int maxFd=dvbstreamStdout;

//create the fd set for writing to mplayer
   fd_set wfds;
   FD_ZERO (&wfds);
//only add the mplayer stdin if the buffer handler contains at least one 
//filled buffer or we just started and have more than 20 filled buffers

if (((bufferhandler->fullBuffers()>0)&&(bufferHandler->justStarted()==false))
|| ((bufferHandler->fullBuffers()>20)&&(bufferHandler->justStarted()==true)))
   {
      FD_SET (mplayerStdin,&wfds);
      if (mplayerStdin>maxFd)
         maxFd=mplayerStdin;
   };
   maxFd++;

   int result=select(maxFd,&rfds,&wfds,0,&tv);
   if (result>0)
   {
      if (FD_ISSET(mplayerStdin,&wfds))
      {
//if I can write to mplayer, get the next full buffer from the buffer handler
//and write the data to mplayer
           MySimpleBuffer *nextBuffer=bufferHandler->getFullBuffer();
           write(mplayerStdin,nextBuffer->buffer,nextBuffer->bytes);
//tell the buffer handler that this buffer has been used and can be released
           bufferHandler->releaseFullBuffer();
           fprintf(stderr," M %d ",bufferHandler->fullBuffers());
      };
      if (FD_ISSET(dvbstreamStdout,&rfds))
      {
//if there is data from dvbstream, get a free buffer from the buffer handler 
//and read the data into it
         MySimpleBuffer *nextBuffer=bufferHandler->getFreeBuffer();
         if (nextBuffer!=0)
         {
nextBuffer->bytes=read(dvbstreamStdout,nextBuffer->buffer,bufferHandler->bufferSize());
//tell the buffer handler that this buffer is filled now
               bufferHandler->putFreeBuffer();
               fprintf(stderr," F %d ",bufferHandler->fullBuffers());
         };
      };
   };
};

I don't see what could be wrong here. I have the impression that mplayer is 
playing slightly to fast, or it drops frame when it shouldn't.  
I also tried the option "-fps 24" or another rate, but mplayer always 
autodetects 25 fps.
I also tried to use the option "-cache 512" but this had similar problems. 
After some time it happened that the mplayer cache was completely full, and 
in the next loop it was suddenly empty 8-}, i.e. it seems that mplayer 
dropped this data.

Any ideas what could be wrong and what I could do ?

Bye
Alex



More information about the MPlayer-dev-eng mailing list