Cosmetics (create a DecoderWaitDate function).
authorLaurent Aimar <fenrir@videolan.org>
Mon, 27 Jul 2009 20:00:46 +0000 (22:00 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Mon, 27 Jul 2009 20:00:46 +0000 (22:00 +0200)
It also avoid useless mdate() when decoding audio.

src/input/decoder.c

index 34f8831..7069388 100644 (file)
@@ -1078,6 +1078,35 @@ static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
     }
 }
 
     }
 }
 
+/**
+ * If *pb_reject, it does nothing, otherwise it waits for the given
+ * deadline or a flush request (in which case it set *pi_reject to true.
+ */
+static void DecoderWaitDate( decoder_t *p_dec,
+                             bool *pb_reject, mtime_t i_deadline )
+{
+    decoder_owner_sys_t *p_owner = p_dec->p_owner;
+
+    if( *pb_reject || i_deadline < 0 )
+        return;
+
+    for( ;; )
+    {
+        vlc_mutex_lock( &p_owner->lock );
+        if( p_owner->b_flushing || p_dec->b_die )
+        {
+            *pb_reject = true;
+            vlc_mutex_unlock( &p_owner->lock );
+            break;
+        }
+        int i_ret = vlc_cond_timedwait( &p_owner->wait_request, &p_owner->lock,
+                                        i_deadline );
+        vlc_mutex_unlock( &p_owner->lock );
+        if( i_ret )
+            break;
+    }
+}
+
 static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
                               int *pi_played_sum, int *pi_lost_sum )
 {
 static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
                               int *pi_played_sum, int *pi_lost_sum )
 {
@@ -1153,20 +1182,8 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
             i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
             b_reject = true;
 
             i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
             b_reject = true;
 
-        /* Do not wait against unprotected date */
-        const mtime_t i_deadline = p_audio->start_date - AOUT_MAX_PREPARE_TIME;
-        while( !b_reject && i_deadline > mdate() )
-        {
-            vlc_mutex_lock( &p_owner->lock );
-            if( p_owner->b_flushing || p_dec->b_die )
-            {
-                b_reject = true;
-                vlc_mutex_unlock( &p_owner->lock );
-                break;
-            }
-            vlc_cond_timedwait( &p_owner->wait_request, &p_owner->lock, i_deadline );
-            vlc_mutex_unlock( &p_owner->lock );
-        }
+        DecoderWaitDate( p_dec, &b_reject,
+                         p_audio->start_date - AOUT_MAX_PREPARE_TIME );
 
         if( !b_reject )
         {
 
         if( !b_reject )
         {