]> git.sesse.net Git - vlc/blobdiff - src/input/decoder.c
Moved out a few defines from vlc_config.h
[vlc] / src / input / decoder.c
index 5b5fbbe3e111063efa4931dabaa1585e5e7ad217..1f825fcf8ade7a2908094caeab692cad9ed6b684 100644 (file)
@@ -158,9 +158,37 @@ struct decoder_owner_sys_t
 #define DECODER_MAX_BUFFERING_AUDIO_DURATION (AOUT_MAX_PREPARE_TIME)
 #define DECODER_MAX_BUFFERING_VIDEO_DURATION (1*CLOCK_FREQ)
 
+/* Pictures which are DECODER_BOGUS_VIDEO_DELAY or more in advance probably have
+ * a bogus PTS and won't be displayed */
+#define DECODER_BOGUS_VIDEO_DELAY                ((mtime_t)(DEFAULT_PTS_DELAY * 30))
+
+/* */
+#define DECODER_SPU_VOUT_WAIT_DURATION ((int)(0.200*CLOCK_FREQ))
+
+
 /*****************************************************************************
  * Public functions
  *****************************************************************************/
+picture_t *decoder_NewPicture( decoder_t *p_decoder )
+{
+    picture_t *p_picture = p_decoder->pf_vout_buffer_new( p_decoder );
+    if( !p_picture )
+        msg_Warn( p_decoder, "can't get output picture" );
+    return p_picture;
+}
+void decoder_DeletePicture( decoder_t *p_decoder, picture_t *p_picture )
+{
+    p_decoder->pf_vout_buffer_del( p_decoder, p_picture );
+}
+void decoder_LinkPicture( decoder_t *p_decoder, picture_t *p_picture )
+{
+    p_decoder->pf_picture_link( p_decoder, p_picture );
+}
+void decoder_UnlinkPicture( decoder_t *p_decoder, picture_t *p_picture )
+{
+    p_decoder->pf_picture_unlink( p_decoder, p_picture );
+}
+
 aout_buffer_t *decoder_NewAudioBuffer( decoder_t *p_decoder, int i_size )
 {
     if( !p_decoder->pf_aout_buffer_new )
@@ -169,8 +197,6 @@ aout_buffer_t *decoder_NewAudioBuffer( decoder_t *p_decoder, int i_size )
 }
 void decoder_DeleteAudioBuffer( decoder_t *p_decoder, aout_buffer_t *p_buffer )
 {
-    if( !p_decoder->pf_aout_buffer_del )
-        return;
     p_decoder->pf_aout_buffer_del( p_decoder, p_buffer );
 }
 
@@ -310,13 +336,8 @@ void input_DecoderDelete( decoder_t *p_dec )
     }
     vlc_mutex_unlock( &p_owner->lock );
 
-    /* Make sure the thread leaves the function */
-    block_FifoWake( p_owner->p_fifo );
-
     vlc_thread_join( p_dec );
-
-    /* Don't module_unneed() here because of the dll loader that wants
-     * close() in the same thread than decode() */
+    module_unneed( p_dec, p_dec->p_module );
 
     /* */
     if( p_dec->p_owner->cc.b_supported )
@@ -782,13 +803,12 @@ static void *DecoderThread( vlc_object_t *p_this )
     decoder_t *p_dec = (decoder_t *)p_this;
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
 
-    int canc = vlc_savecancel();
-
     /* The decoder's main loop */
-    while( vlc_object_alive( p_dec ) )
+    for( ;; )
     {
         block_t *p_block = block_FifoGet( p_owner->p_fifo );
-
+        /* Make sure there is no cancellation point other than this one^^.
+         * If you need one, be sure to push cleanup of p_block. */
         DecoderSignalBuffering( p_dec, p_block == NULL );
 
         if( p_block )
@@ -805,11 +825,6 @@ static void *DecoderThread( vlc_object_t *p_this )
     }
 
     DecoderSignalBuffering( p_dec, true );
-
-    /* We do it here because of the dll loader that wants close() in the
-     * same thread than decode() */
-    module_unneed( p_dec, p_dec->p_module );
-    vlc_restorecancel( canc );
     return NULL;
 }
 
@@ -1314,7 +1329,7 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
         vlc_mutex_unlock( &p_owner->lock );
 
         /* */
-        const mtime_t i_max_date = mdate() + i_delay + VOUT_BOGUS_DELAY;
+        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 ) )
             b_reject = true;
@@ -1794,6 +1809,7 @@ static int DecoderProcess( decoder_t *p_dec, block_t *p_block )
         return VLC_SUCCESS;
     }
 
+    int canc = vlc_savecancel();
 #ifdef ENABLE_SOUT
     if( p_dec->i_object_type == VLC_OBJECT_PACKETIZER )
     {
@@ -1845,6 +1861,7 @@ static int DecoderProcess( decoder_t *p_dec, block_t *p_block )
 
         DecoderSignalFlushed( p_dec );
     }
+    vlc_restorecancel( canc );
 
     return p_dec->b_error ? VLC_EGENERIC : VLC_SUCCESS;
 }
@@ -1971,10 +1988,11 @@ static aout_buffer_t *aout_new_buffer( decoder_t *p_dec, int i_samples )
         p_owner->audio = p_dec->fmt_out.audio;
 
         memcpy( &format, &p_owner->audio, sizeof( audio_sample_format_t ) );
-        if ( i_force_dolby && (format.i_original_channels&AOUT_CHAN_PHYSMASK)
-                                    == (AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT) )
+        if( i_force_dolby &&
+            (format.i_original_channels&AOUT_CHAN_PHYSMASK) ==
+                (AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT) )
         {
-            if ( i_force_dolby == 1 )
+            if( i_force_dolby == 1 )
             {
                 format.i_original_channels = format.i_original_channels |
                                              AOUT_CHAN_DOLBYSTEREO;
@@ -2183,7 +2201,7 @@ static subpicture_t *spu_new_buffer( decoder_t *p_dec )
         if( p_vout )
             break;
 
-        msleep( VOUT_DISPLAY_DELAY );
+        msleep( DECODER_SPU_VOUT_WAIT_DURATION );
     }
 
     if( !p_vout )