1
mirror of https://code.videolan.org/videolan/vlc synced 2024-09-04 09:11:33 +02:00

Use polling instead of msleep in v4l2 access_demux.

I'm not sure about the polltimeout. I'd settle for an infinite timeout but then VLC might behavior on exit might be messed up.

This also fixes the last compilation warning in v4l2.c.
This commit is contained in:
Antoine Cellerier 2008-10-27 17:35:55 -07:00
parent aa83566077
commit 711c318b5e

View File

@ -1383,24 +1383,53 @@ static int Demux( demux_t *p_demux )
es_out_id_t *p_es = p_sys->p_es_audio;
block_t *p_block = NULL;
/* Try grabbing audio frames first */
if( p_sys->i_fd_audio < 0 || !( p_block = GrabAudio( p_demux ) ) )
struct pollfd p_fd[2];
int i_fd = 0;
memset( p_fd, 0, 2 * sizeof( struct pollfd ) );
if( p_sys->i_fd_video )
{
/* Try grabbing video frame */
p_es = p_sys->p_es_video;
if( p_sys->i_fd_video > 0 ) p_block = GrabVideo( p_demux );
p_fd[i_fd].fd = p_sys->i_fd_video;
p_fd[i_fd].events = POLLIN|POLLPRI;
i_fd ++;
}
if( p_sys->i_fd_audio )
{
p_fd[i_fd].fd = p_sys->i_fd_audio;
p_fd[i_fd].events = POLLIN|POLLPRI;
i_fd ++;
}
/* Wait for data */
if( poll( p_fd, i_fd, 500 ) ) /* Timeout after 0.5 seconds since I don't know if pf_demux can be blocking. */
{
for( i_fd --; i_fd >= 0; i_fd -- )
{
if( p_fd[i_fd].revents & (POLLIN|POLLPRI) )
{
if( p_fd[i_fd].fd == p_sys->i_fd_video )
{
p_block = GrabVideo( p_demux );
p_es = p_sys->p_es_video;
}
else /* audio */
{
p_block = GrabAudio( p_demux );
p_es = p_sys->p_es_audio;
}
break;
}
}
}
if( !p_block )
{
/* Sleep so we do not consume all the cpu, 10ms seems
* like a good value (100fps) */
/* Yeah, nevermind this was sleeping 10 microseconds! This is
* completely brain damaged anyway. Use poll() or mwait() FIXME. */
msleep(10000);
/* Looks like poll timed out ...
* ... or returned an error on one of the fds.
* TODO: process */
return 1;
}
assert( p_es );
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
es_out_Send( p_demux->out, p_es, p_block );