From: Steinar H. Gunderson Date: Sat, 2 Oct 2010 23:01:28 +0000 (+0200) Subject: Send frames from the receiver thread instead of having a Demux(). Seemingly some... X-Git-Url: https://git.sesse.net/?p=vlc;a=commitdiff_plain;h=fbf9467737910cf4fafb3ed32575f889dc731e91 Send frames from the receiver thread instead of having a Demux(). Seemingly some newfangled thing. --- diff --git a/modules/access/decklink.cpp b/modules/access/decklink.cpp index be2b41f6e6..d49605cf90 100644 --- a/modules/access/decklink.cpp +++ b/modules/access/decklink.cpp @@ -119,7 +119,6 @@ vlc_module_begin () set_callbacks( Open, Close ) vlc_module_end () -static int Demux ( demux_t * ); static int Control( demux_t *, int, va_list ); class DeckLinkCaptureDelegate; @@ -132,15 +131,12 @@ struct demux_sys_t es_out_id_t *p_video_es; es_out_id_t *p_audio_es; - int i_last_pts; + + vlc_mutex_t pts_lock; + int i_last_pts; /* protected by */ uint32_t i_dominance_flags; int i_channels; - - vlc_mutex_t frame_lock; - block_t *p_video_frame; /* protected by */ - block_t *p_audio_frame; /* protected by */ - vlc_cond_t has_frame; /* related to */ }; class DeckLinkCaptureDelegate : public IDeckLinkInputCallback @@ -218,6 +214,14 @@ HRESULT DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame->GetStreamTime( &stream_time, &frame_duration, CLOCK_FREQ ); p_video_frame->i_flags = BLOCK_FLAG_TYPE_I | p_sys->i_dominance_flags; p_video_frame->i_pts = p_video_frame->i_dts = VLC_TS_0 + stream_time; + + vlc_mutex_lock( &p_sys->pts_lock ); + if( p_video_frame->i_pts > p_sys->i_last_pts ) + p_sys->i_last_pts = p_video_frame->i_pts; + vlc_mutex_unlock( &p_sys->pts_lock ); + + es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_video_frame->i_pts ); + es_out_Send( p_demux->out, p_sys->p_video_es, p_video_frame ); } if( audioFrame ) @@ -240,25 +244,15 @@ HRESULT DeckLinkCaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame BMDTimeValue packet_time; audioFrame->GetPacketTime( &packet_time, CLOCK_FREQ ); p_audio_frame->i_pts = p_audio_frame->i_dts = VLC_TS_0 + packet_time; - } - - if( p_video_frame || p_audio_frame ) - { - vlc_mutex_lock( &p_sys->frame_lock ); - if( p_video_frame ) - { - if( p_sys->p_video_frame ) - block_Release( p_sys->p_video_frame ); - p_sys->p_video_frame = p_video_frame; - } - if( p_audio_frame ) - { - if( p_sys->p_audio_frame ) - block_Release( p_sys->p_audio_frame ); - p_sys->p_audio_frame = p_audio_frame; - } - vlc_cond_signal( &p_sys->has_frame ); - vlc_mutex_unlock( &p_sys->frame_lock ); + + vlc_mutex_lock( &p_sys->pts_lock ); + if( p_audio_frame->i_pts > p_sys->i_last_pts ) + p_sys->i_last_pts = p_audio_frame->i_pts; + vlc_mutex_unlock( &p_sys->pts_lock ); + if( p_audio_frame->i_pts > p_sys->i_last_pts ) + + es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_audio_frame->i_pts ); + es_out_Send( p_demux->out, p_sys->p_audio_es, p_audio_frame ); } return S_OK; @@ -284,7 +278,7 @@ static int Open( vlc_object_t *p_this ) return VLC_EGENERIC; /* Set up p_demux */ - p_demux->pf_demux = Demux; + p_demux->pf_demux = NULL; p_demux->pf_control = Control; p_demux->info.i_update = 0; p_demux->info.i_title = 0; @@ -653,7 +647,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) case DEMUX_GET_TIME: pi64 = (int64_t*)va_arg( args, int64_t * ); + vlc_mutex_lock( &p_sys->pts_lock ); *pi64 = p_sys->i_last_pts; + vlc_mutex_unlock( &p_sys->pts_lock ); return VLC_SUCCESS; /* TODO implement others */ @@ -663,42 +659,3 @@ static int Control( demux_t *p_demux, int i_query, va_list args ) return VLC_EGENERIC; } - -static int Demux( demux_t *p_demux ) -{ - demux_sys_t *p_sys = p_demux->p_sys; - block_t *p_video_block = NULL; - block_t *p_audio_block = NULL; - - vlc_mutex_lock( &p_sys->frame_lock ); - - while( !p_sys->p_video_frame && !p_sys->p_audio_frame ) - vlc_cond_wait( &p_sys->has_frame, &p_sys->frame_lock ); - - p_video_block = p_sys->p_video_frame; - p_sys->p_video_frame = NULL; - - p_audio_block = p_sys->p_audio_frame; - p_sys->p_audio_frame = NULL; - - vlc_mutex_unlock( &p_sys->frame_lock ); - - if( p_video_block ) - { - if( p_video_block->i_pts > p_sys->i_last_pts ) - p_sys->i_last_pts = p_video_block->i_pts; - es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_video_block->i_pts ); - es_out_Send( p_demux->out, p_sys->p_video_es, p_video_block ); - } - - if( p_audio_block ) - { - if( p_audio_block->i_pts > p_sys->i_last_pts ) - p_sys->i_last_pts = p_audio_block->i_pts; - es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_audio_block->i_pts ); - es_out_Send( p_demux->out, p_sys->p_audio_es, p_audio_block ); - } - - return 1; -} -