]> git.sesse.net Git - vlc/blobdiff - src/input/decoder.c
Correctly unpause the vout for reuse.
[vlc] / src / input / decoder.c
index f0663c03204ab9735bd242365db5ce5296dfbec4..a5860a5ab543f8d48b6f4d323fc0ede3d5e012ef 100644 (file)
@@ -312,8 +312,7 @@ decoder_t *input_DecoderNew( input_thread_t *p_input,
         i_priority = VLC_THREAD_PRIORITY_VIDEO;
 
     /* Spawn the decoder thread */
-    if( vlc_thread_create( p_dec, "decoder", DecoderThread,
-                           i_priority, false ) )
+    if( vlc_thread_create( p_dec, "decoder", DecoderThread, i_priority ) )
     {
         msg_Err( p_dec, "cannot spawn decoder thread" );
         module_unneed( p_dec, p_dec->p_module );
@@ -340,6 +339,7 @@ void input_DecoderDelete( decoder_t *p_dec )
 
     /* Make sure we aren't paused/buffering/waiting anymore */
     vlc_mutex_lock( &p_owner->lock );
+    const b_was_paused = p_owner->b_paused;
     p_owner->b_paused = false;
     p_owner->b_buffering = false;
     p_owner->b_flushing = true;
@@ -347,6 +347,8 @@ void input_DecoderDelete( decoder_t *p_dec )
     vlc_mutex_unlock( &p_owner->lock );
 
     vlc_thread_join( p_dec );
+    p_owner->b_paused = b_was_paused;
+
     module_unneed( p_dec, p_dec->p_module );
 
     /* */
@@ -653,7 +655,10 @@ static mtime_t DecoderGetDisplayDate( decoder_t *p_dec, mtime_t i_ts )
     if( !p_owner->p_clock || !i_ts )
         return i_ts;
 
-    return input_clock_GetTS( p_owner->p_clock, NULL, p_owner->p_input->i_pts_delay, i_ts );
+    if( input_clock_ConvertTS( p_owner->p_clock, NULL, &i_ts, NULL, INT64_MAX ) )
+        return 0;
+
+    return i_ts;
 }
 static int DecoderGetDisplayRate( decoder_t *p_dec )
 {
@@ -879,8 +884,6 @@ static void *DecoderThread( vlc_object_t *p_this )
 
             vlc_restorecancel( canc );
         }
-        /* Ensure fast cancellation in case the fifo is not empty */
-        vlc_testcancel();
     }
     return NULL;
 }
@@ -1023,7 +1026,7 @@ static inline void DecoderUpdatePreroll( int64_t *pi_preroll, const block_t *p )
         *pi_preroll = __MIN( *pi_preroll, p->i_dts );
 }
 
-static mtime_t DecoderTeletextFixTs( mtime_t i_ts, mtime_t i_ts_delay )
+static mtime_t DecoderTeletextFixTs( mtime_t i_ts )
 {
     mtime_t current_date = mdate();
 
@@ -1032,41 +1035,42 @@ static mtime_t DecoderTeletextFixTs( mtime_t i_ts, mtime_t i_ts_delay )
     {
         /* ETSI EN 300 472 Annex A : do not take into account the PTS
          * for teletext streams. */
-        return current_date + 400000 + i_ts_delay;
+        return current_date + 400000;
     }
     return i_ts;
 }
 
 static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
-                          mtime_t *pi_duration, int *pi_rate, mtime_t *pi_delay, bool b_telx )
+                          mtime_t *pi_duration, int *pi_rate, mtime_t i_ts_bound, bool b_telx )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
     input_clock_t   *p_clock = p_owner->p_clock;
-    int i_rate = 0;
 
     vlc_assert_locked( &p_owner->lock );
 
-    const mtime_t i_ts_delay = p_owner->p_input->i_pts_delay;
     const mtime_t i_es_delay = p_owner->i_ts_delay;
 
     if( p_clock )
     {
         const bool b_ephemere = pi_ts1 && *pi_ts0 == *pi_ts1;
+        int i_rate;
 
         if( *pi_ts0 > 0 )
-            *pi_ts0 = input_clock_GetTS( p_clock, &i_rate, i_ts_delay,
-                                         *pi_ts0 + i_es_delay );
-        if( pi_ts1 && *pi_ts1 > 0 )
-            *pi_ts1 = input_clock_GetTS( p_clock, &i_rate, i_ts_delay,
-                                         *pi_ts1 + i_es_delay );
+        {
+            *pi_ts0 += i_es_delay;
+            if( pi_ts1 && *pi_ts1 > 0 )
+                *pi_ts1 += i_es_delay;
+            input_clock_ConvertTS( p_clock, &i_rate, pi_ts0, pi_ts1, i_ts_bound );
+        }
+        else
+        {
+            i_rate = input_clock_GetRate( p_clock );
+        }
 
         /* Do not create ephemere data because of rounding errors */
         if( !b_ephemere && pi_ts1 && *pi_ts0 == *pi_ts1 )
             *pi_ts1 += 1;
 
-        if( i_rate <= 0 )
-            i_rate = input_clock_GetRate( p_clock ); 
-
         if( pi_duration )
             *pi_duration = ( *pi_duration * i_rate +
                                     INPUT_RATE_DEFAULT-1 ) / INPUT_RATE_DEFAULT;
@@ -1076,16 +1080,11 @@ static void DecoderFixTs( decoder_t *p_dec, mtime_t *pi_ts0, mtime_t *pi_ts1,
 
         if( b_telx )
         {
-            *pi_ts0 = DecoderTeletextFixTs( *pi_ts0, i_ts_delay );
+            *pi_ts0 = DecoderTeletextFixTs( *pi_ts0 );
             if( pi_ts1 && *pi_ts1 <= 0 )
                 *pi_ts1 = *pi_ts0;
         }
     }
-    if( pi_delay )
-    {
-        const int r = i_rate > 0 ? i_rate : INPUT_RATE_DEFAULT;
-        *pi_delay = i_ts_delay + i_es_delay * r / INPUT_RATE_DEFAULT;
-    }
 }
 
 static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
@@ -1149,19 +1148,16 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
         }
 
         /* */
+        const bool b_dated = p_audio->start_date > 0;
         int i_rate = INPUT_RATE_DEFAULT;
-        mtime_t i_delay;
 
         DecoderFixTs( p_dec, &p_audio->start_date, &p_audio->end_date, NULL,
-                      &i_rate, &i_delay, false );
+                      &i_rate, AOUT_MAX_ADVANCE_TIME, false );
 
         vlc_mutex_unlock( &p_owner->lock );
 
-        /* */
-        const mtime_t i_max_date = mdate() + i_delay + AOUT_MAX_ADVANCE_TIME;
-
         if( !p_aout || !p_aout_input ||
-            p_audio->start_date <= 0 || p_audio->start_date > i_max_date ||
+            p_audio->start_date <= 0 ||
             i_rate < INPUT_RATE_DEFAULT/AOUT_MAX_INPUT_RATE ||
             i_rate > INPUT_RATE_DEFAULT*AOUT_MAX_INPUT_RATE )
             b_reject = true;
@@ -1189,15 +1185,11 @@ static void DecoderPlayAudio( decoder_t *p_dec, aout_buffer_t *p_audio,
         }
         else
         {
-            if( p_audio->start_date <= 0 )
-            {
+            if( b_dated )
+                msg_Warn( p_aout, "received buffer in the future" );
+            else
                 msg_Warn( p_dec, "non-dated audio buffer received" );
-            }
-            else if( p_audio->start_date > i_max_date )
-            {
-                msg_Warn( p_aout, "received buffer in the future (%"PRId64")",
-                          p_audio->start_date - mdate() );
-            }
+
             *pi_lost_sum += 1;
             aout_BufferFree( p_audio );
         }
@@ -1384,17 +1376,15 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
             p_picture->b_force = true;
         }
 
+        const bool b_dated = p_picture->date > 0;
         int i_rate = INPUT_RATE_DEFAULT;
-        mtime_t i_delay;
         DecoderFixTs( p_dec, &p_picture->date, NULL, NULL,
-                      &i_rate, &i_delay, false );
+                      &i_rate, DECODER_BOGUS_VIDEO_DELAY, false );
 
         vlc_mutex_unlock( &p_owner->lock );
 
         /* */
-        const mtime_t i_max_date = mdate() + i_delay + DECODER_BOGUS_VIDEO_DELAY;
-
-        if( !p_picture->b_force && ( p_picture->date <= 0 || p_picture->date >= i_max_date ) )
+        if( !p_picture->b_force && p_picture->date <= 0 )
             b_reject = true;
 
         if( !b_reject )
@@ -1409,15 +1399,11 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
         }
         else
         {
-            if( p_picture->date <= 0 )
-            {
-                msg_Warn( p_vout, "non-dated video buffer received" );
-            }
+            if( b_dated )
+                msg_Warn( p_vout, "early picture skipped" );
             else
-            {
-                msg_Warn( p_vout, "early picture skipped (%"PRId64")",
-                          p_picture->date - mdate() );
-            }
+                msg_Warn( p_vout, "non-dated video buffer received" );
+
             *pi_lost_sum += 1;
             vout_DropPicture( p_vout, p_picture );
         }
@@ -1560,7 +1546,7 @@ static void DecoderPlaySpu( decoder_t *p_dec, subpicture_t *p_subpic,
 
         /* */
         DecoderFixTs( p_dec, &p_subpic->i_start, &p_subpic->i_stop, NULL,
-                      NULL, NULL, b_telx );
+                      NULL, INT64_MAX, b_telx );
 
         vlc_mutex_unlock( &p_owner->lock );
 
@@ -1631,7 +1617,7 @@ static void DecoderPlaySout( decoder_t *p_dec, block_t *p_sout_block,
 
         DecoderFixTs( p_dec, &p_sout_block->i_dts, &p_sout_block->i_pts,
                       &p_sout_block->i_length,
-                      &p_sout_block->i_rate, NULL, b_telx );
+                      &p_sout_block->i_rate, INT64_MAX, b_telx );
 
         vlc_mutex_unlock( &p_owner->lock );
 
@@ -1943,7 +1929,7 @@ static void DecoderProcess( decoder_t *p_dec, block_t *p_block )
     }
 
 #ifdef ENABLE_SOUT
-    if( p_dec->i_object_type == VLC_OBJECT_PACKETIZER )
+    if( vlc_internals( p_dec )->i_object_type == VLC_OBJECT_PACKETIZER )
     {
         if( p_block )
             p_block->i_flags &= ~BLOCK_FLAG_CORE_PRIVATE_MASK;
@@ -2032,14 +2018,18 @@ static void DeleteDecoder( decoder_t * p_dec )
     {
         input_ressource_RequestAout( p_owner->p_input->p->p_ressource,
                                      p_owner->p_aout );
+        input_SendEventAout( p_owner->p_input );
         p_owner->p_aout = NULL;
     }
     if( p_owner->p_vout )
     {
-        /* Hack to make sure all the the pictures are freed by the decoder */
+        /* Hack to make sure all the the pictures are freed by the decoder
+         * and that the vout is not paused anymore */
         vout_FixLeaks( p_owner->p_vout, true );
+        if( p_owner->b_paused )
+            vout_ChangePause( p_owner->p_vout, false, mdate() );
 
-        /* We are about to die. Reattach video output to p_vlc. */
+        /* */
         input_ressource_RequestVout( p_owner->p_input->p->p_ressource, p_owner->p_vout, NULL );
         input_SendEventVout( p_owner->p_input );
     }
@@ -2195,6 +2185,8 @@ static aout_buffer_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
 
         vlc_mutex_unlock( &p_owner->lock );
 
+        input_SendEventAout( p_owner->p_input );
+
         if( p_owner->p_aout_input == NULL )
         {
             msg_Err( p_dec, "failed to create audio output" );