[vlc-devel] commit: Removed the need to msleep to handle input pause. (Laurent Aimar )
git version control
git at videolan.org
Sun Sep 7 22:18:47 CEST 2008
vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sun Sep 7 22:19:33 2008 +0200| [253ac451cadf69a9ee788d4f640d294957b877f7] | committer: Laurent Aimar
Removed the need to msleep to handle input pause.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=253ac451cadf69a9ee788d4f640d294957b877f7
---
src/input/input.c | 35 +++++++++++++++++++++--------------
src/input/input_internal.h | 5 +++--
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/src/input/input.c b/src/input/input.c
index 2507b2f..eaff240 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -64,7 +64,7 @@ static void WaitDie ( input_thread_t *p_input );
static void End ( input_thread_t *p_input );
static void MainLoop( input_thread_t *p_input );
-static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t * );
+static inline int ControlPopNoLock( input_thread_t *, int *, vlc_value_t *, mtime_t i_deadline );
static void ControlReduce( input_thread_t * );
static bool Control( input_thread_t *, int, vlc_value_t );
@@ -223,6 +223,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
/* Init control buffer */
vlc_mutex_init( &p_input->p->lock_control );
+ vlc_cond_init( &p_input->p->wait_control );
p_input->p->i_control = 0;
/* Parse input options */
@@ -337,6 +338,7 @@ static void Destructor( input_thread_t * p_input )
vlc_mutex_destroy( &p_input->p->counters.counters_lock );
+ vlc_cond_destroy( &p_input->p->wait_control );
vlc_mutex_destroy( &p_input->p->lock_control );
free( p_input->p );
}
@@ -730,23 +732,22 @@ static void MainLoop( input_thread_t *p_input )
int i_type;
vlc_value_t val;
mtime_t i_current;
+ mtime_t i_deadline;
- /* Do the read */
+ /* Demux data */
+ b_force_update = false;
if( p_input->i_state != PAUSE_S )
- {
MainLoopDemux( p_input, &b_force_update, &i_start_mdate );
- }
- else
- {
- /* Small wait */
- b_force_update = false;
- msleep( 10*1000 );
- }
+
+ /* */
+ i_deadline = 0;
+ if( p_input->i_state == PAUSE_S )
+ i_deadline = __MIN( i_intf_update, i_statistic_update );
/* Handle control */
vlc_mutex_lock( &p_input->p->lock_control );
ControlReduce( p_input );
- while( !ControlPopNoLock( p_input, &i_type, &val ) )
+ while( !ControlPopNoLock( p_input, &i_type, &val, i_deadline ) )
{
msg_Dbg( p_input, "control type=%d", i_type );
if( Control( p_input, i_type, val ) )
@@ -1396,11 +1397,17 @@ static void End( input_thread_t * p_input )
* Control
*****************************************************************************/
static inline int ControlPopNoLock( input_thread_t *p_input,
- int *pi_type, vlc_value_t *p_val )
+ int *pi_type, vlc_value_t *p_val,
+ mtime_t i_deadline )
{
- if( p_input->p->i_control <= 0 )
+
+ while( p_input->p->i_control <= 0 )
{
- return VLC_EGENERIC;
+ if( i_deadline <= 0 )
+ return VLC_EGENERIC;
+
+ if( vlc_cond_timedwait( &p_input->p->wait_control, &p_input->p->lock_control, i_deadline ) )
+ return VLC_EGENERIC;
}
*pi_type = p_input->p->control[0].i_type;
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index f3a6e16..0372f66 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -147,6 +147,7 @@ struct input_thread_private_t
/* Buffer of pending actions */
vlc_mutex_t lock_control;
+ vlc_cond_t wait_control;
int i_control;
struct
{
@@ -211,8 +212,7 @@ static inline void input_ControlPush( input_thread_t *p_input,
p_input->p->control[0].i_type = i_type;
memset( &p_input->p->control[0].val, 0, sizeof( vlc_value_t ) );
}
- else
- if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
+ else if( p_input->p->i_control >= INPUT_CONTROL_FIFO_SIZE )
{
msg_Err( p_input, "input control fifo overflow, trashing type=%d",
i_type );
@@ -228,6 +228,7 @@ static inline void input_ControlPush( input_thread_t *p_input,
p_input->p->i_control++;
}
+ vlc_cond_signal( &p_input->p->wait_control );
vlc_mutex_unlock( &p_input->p->lock_control );
}
More information about the vlc-devel
mailing list