]> git.sesse.net Git - vlc/blobdiff - src/input/decoder.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / input / decoder.c
index 2dc6404a359524b1874f33f2925861fb4ce683bb..f7ec650a5875ccb3acbb4864f4ad14e27280ab2c 100644 (file)
 #include <vlc_aout.h>
 #include <vlc_sout.h>
 #include <vlc_codec.h>
-#include <vlc_osd.h>
+#include <vlc_spu.h>
 #include <vlc_meta.h>
 #include <vlc_dialog.h>
+#include <vlc_modules.h>
 
 #include "audio_output/aout_internal.h"
 #include "stream_output/stream_output.h"
@@ -75,7 +76,7 @@ static void vout_del_buffer( decoder_t *, picture_t * );
 static void vout_link_picture( decoder_t *, picture_t * );
 static void vout_unlink_picture( decoder_t *, picture_t * );
 
-static subpicture_t *spu_new_buffer( decoder_t * );
+static subpicture_t *spu_new_buffer( decoder_t *, const subpicture_updater_t * );
 static void spu_del_buffer( decoder_t *, subpicture_t * );
 
 struct decoder_owner_sys_t
@@ -213,13 +214,15 @@ void decoder_DeleteAudioBuffer( decoder_t *p_decoder, aout_buffer_t *p_buffer )
     p_decoder->pf_aout_buffer_del( p_decoder, p_buffer );
 }
 
-subpicture_t *decoder_NewSubpicture( decoder_t *p_decoder )
+subpicture_t *decoder_NewSubpicture( decoder_t *p_decoder,
+                                     const subpicture_updater_t *p_dyn )
 {
-    subpicture_t *p_subpicture = p_decoder->pf_spu_buffer_new( p_decoder );
+    subpicture_t *p_subpicture = p_decoder->pf_spu_buffer_new( p_decoder, p_dyn );
     if( !p_subpicture )
         msg_Warn( p_decoder, "can't get output subpicture" );
     return p_subpicture;
 }
+
 void decoder_DeleteSubpicture( decoder_t *p_decoder, subpicture_t *p_subpicture )
 {
     p_decoder->pf_spu_buffer_del( p_decoder, p_subpicture );
@@ -386,10 +389,19 @@ void input_DecoderDecode( decoder_t *p_dec, block_t *p_block, bool b_do_pace )
 
 bool input_DecoderIsEmpty( decoder_t * p_dec )
 {
-    assert( !p_dec->p_owner->b_buffering );
+    decoder_owner_sys_t *p_owner = p_dec->p_owner;
+    assert( !p_owner->b_buffering );
 
-    /* FIXME that's not really true */
-    return block_FifoCount( p_dec->p_owner->p_fifo ) <= 0;
+    bool b_empty = block_FifoCount( p_dec->p_owner->p_fifo ) <= 0;
+    if( b_empty )
+    {
+        vlc_mutex_lock( &p_owner->lock );
+        /* TODO audio support */
+        if( p_dec->fmt_out.i_cat == VIDEO_ES && p_owner->p_vout )
+            b_empty = vout_IsEmpty( p_owner->p_vout );
+        vlc_mutex_unlock( &p_owner->lock );
+    }
+    return b_empty;
 }
 
 void input_DecoderIsCcPresent( decoder_t *p_dec, bool pb_present[4] )
@@ -1339,10 +1351,9 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
     {
         msg_Warn( p_vout, "non-dated video buffer received" );
         *pi_lost_sum += 1;
-        vout_DropPicture( p_vout, p_picture );
+        vout_ReleasePicture( p_vout, p_picture );
         return;
     }
-    vout_LinkPicture( p_vout, p_picture );
 
     /* */
     vlc_mutex_lock( &p_owner->lock );
@@ -1421,8 +1432,7 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
                 vout_Flush( p_vout, p_picture->date );
                 p_owner->i_last_rate = i_rate;
             }
-            vout_DisplayPicture( p_vout, p_picture );
-            vout_UnlinkPicture( p_vout, p_picture );
+            vout_PutPicture( p_vout, p_picture );
         }
         else
         {
@@ -1432,8 +1442,7 @@ static void DecoderPlayVideo( decoder_t *p_dec, picture_t *p_picture,
                 msg_Warn( p_vout, "non-dated video buffer received" );
 
             *pi_lost_sum += 1;
-            vout_UnlinkPicture( p_vout, p_picture );
-            vout_DropPicture( p_vout, p_picture );
+            vout_ReleasePicture( p_vout, p_picture );
         }
         int i_tmp_display;
         int i_tmp_lost;
@@ -1469,7 +1478,7 @@ static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block )
         if( p_dec->b_die )
         {
             /* It prevent freezing VLC in case of broken decoder */
-            vout_DropPicture( p_vout, p_pic );
+            vout_ReleasePicture( p_vout, p_pic );
             if( p_block )
                 block_Release( p_block );
             break;
@@ -1479,7 +1488,7 @@ static void DecoderDecodeVideo( decoder_t *p_dec, block_t *p_block )
 
         if( p_owner->i_preroll_end > VLC_TS_INVALID && p_pic->date < p_owner->i_preroll_end )
         {
-            vout_DropPicture( p_vout, p_pic );
+            vout_ReleasePicture( p_vout, p_pic );
             continue;
         }
 
@@ -1585,7 +1594,7 @@ static void DecoderPlaySpu( decoder_t *p_dec, subpicture_t *p_subpic,
                          p_subpic->i_start - SPU_MAX_PREPARE_TIME );
 
         if( !b_reject )
-            spu_DisplaySubpicture( vout_GetSpu( p_vout ), p_subpic );
+            vout_PutSubpicture( p_vout, p_subpic );
         else
             subpicture_Delete( p_subpic );
 
@@ -1687,8 +1696,7 @@ static void DecoderFlushBuffering( decoder_t *p_dec )
 
         if( p_owner->p_vout )
         {
-            vout_UnlinkPicture( p_owner->p_vout, p_picture );
-            vout_DropPicture( p_owner->p_vout, p_picture );
+            vout_ReleasePicture( p_owner->p_vout, p_picture );
         }
 
         if( !p_owner->buffer.p_picture )
@@ -1928,8 +1936,7 @@ static void DecoderProcessSpu( decoder_t *p_dec, block_t *p_block, bool b_flush
         p_vout = input_resource_HoldVout( p_input->p->p_resource );
 
         if( p_vout && p_owner->p_spu_vout == p_vout )
-            spu_Control( vout_GetSpu( p_vout ), SPU_CHANNEL_CLEAR,
-                         p_owner->i_spu_channel );
+            vout_FlushSubpictureChannel( p_vout, p_owner->i_spu_channel );
 
         if( p_vout )
             vlc_object_release( p_vout );
@@ -2068,12 +2075,10 @@ static void DeleteDecoder( decoder_t * p_dec )
     {
         /* 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() );
+        vout_Reset( p_owner->p_vout );
 
         /* */
-        input_resource_RequestVout( p_owner->p_input->p->p_resource, p_owner->p_vout, NULL, true );
+        input_resource_RequestVout( p_owner->p_input->p->p_resource, p_owner->p_vout, NULL, 0, true );
         input_SendEventVout( p_owner->p_input );
     }
 
@@ -2093,7 +2098,7 @@ static void DeleteDecoder( decoder_t * p_dec )
         if( p_vout )
         {
             if( p_owner->p_spu_vout == p_vout )
-                spu_Control( vout_GetSpu( p_vout ), SPU_CHANNEL_CLEAR, p_owner->i_spu_channel );
+                vout_FlushSubpictureChannel( p_vout, p_owner->i_spu_channel );
             vlc_object_release( p_vout );
         }
     }
@@ -2153,7 +2158,7 @@ static vout_thread_t *aout_request_vout( void *p_private,
     decoder_t *p_dec = p_private;
     input_thread_t *p_input = p_dec->p_owner->p_input;
 
-    p_vout = input_resource_RequestVout( p_input->p->p_resource, p_vout, p_fmt, b_recyle );
+    p_vout = input_resource_RequestVout( p_input->p->p_resource, p_vout, p_fmt, 1, b_recyle );
     input_SendEventVout( p_input );
 
     return p_vout;
@@ -2254,9 +2259,6 @@ static void aout_del_buffer( decoder_t *p_dec, aout_buffer_t *p_buffer )
                           p_owner->p_aout_input, p_buffer );
 }
 
-
-int vout_CountPictureAvailable( vout_thread_t *p_vout );
-
 static picture_t *vout_new_buffer( decoder_t *p_dec )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
@@ -2264,7 +2266,11 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
     if( p_owner->p_vout == NULL ||
         p_dec->fmt_out.video.i_width != p_owner->video.i_width ||
         p_dec->fmt_out.video.i_height != p_owner->video.i_height ||
-        p_dec->fmt_out.video.i_chroma != p_owner->video.i_chroma ||
+        p_dec->fmt_out.video.i_visible_width != p_owner->video.i_visible_width ||
+        p_dec->fmt_out.video.i_visible_height != p_owner->video.i_visible_height ||
+        p_dec->fmt_out.video.i_x_offset != p_owner->video.i_x_offset  ||
+        p_dec->fmt_out.video.i_y_offset != p_owner->video.i_y_offset  ||
+        p_dec->fmt_out.i_codec != p_owner->video.i_chroma ||
         (int64_t)p_dec->fmt_out.video.i_sar_num * p_owner->video.i_sar_den !=
         (int64_t)p_dec->fmt_out.video.i_sar_den * p_owner->video.i_sar_num )
     {
@@ -2277,52 +2283,45 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
             return NULL;
         }
 
-        if( !p_dec->fmt_out.video.i_visible_width ||
-            !p_dec->fmt_out.video.i_visible_height )
+        video_format_t fmt = p_dec->fmt_out.video;
+        fmt.i_chroma = p_dec->fmt_out.i_codec;
+        p_owner->video = fmt;
+
+        if( !fmt.i_visible_width || !fmt.i_visible_height )
         {
             if( p_dec->fmt_in.video.i_visible_width &&
                 p_dec->fmt_in.video.i_visible_height )
             {
-                p_dec->fmt_out.video.i_visible_width =
-                    p_dec->fmt_in.video.i_visible_width;
-                p_dec->fmt_out.video.i_visible_height =
-                    p_dec->fmt_in.video.i_visible_height;
+                fmt.i_visible_width  = p_dec->fmt_in.video.i_visible_width;
+                fmt.i_visible_height = p_dec->fmt_in.video.i_visible_height;
             }
             else
             {
-                p_dec->fmt_out.video.i_visible_width =
-                    p_dec->fmt_out.video.i_width;
-                p_dec->fmt_out.video.i_visible_height =
-                    p_dec->fmt_out.video.i_height;
+                fmt.i_visible_width  = fmt.i_width;
+                fmt.i_visible_height = fmt.i_height;
             }
         }
 
-        if( p_dec->fmt_out.video.i_visible_height == 1088 &&
+        if( fmt.i_visible_height == 1088 &&
             var_CreateGetBool( p_dec, "hdtv-fix" ) )
         {
-            p_dec->fmt_out.video.i_visible_height = 1080;
-            if( !(p_dec->fmt_out.video.i_sar_num % 136))
+            fmt.i_visible_height = 1080;
+            if( !(fmt.i_sar_num % 136))
             {
-                p_dec->fmt_out.video.i_sar_num *= 135;
-                p_dec->fmt_out.video.i_sar_den *= 136;
+                fmt.i_sar_num *= 135;
+                fmt.i_sar_den *= 136;
             }
             msg_Warn( p_dec, "Fixing broken HDTV stream (display_height=1088)");
         }
 
-        if( !p_dec->fmt_out.video.i_sar_num ||
-            !p_dec->fmt_out.video.i_sar_den )
+        if( !fmt.i_sar_num || !fmt.i_sar_den )
         {
-            p_dec->fmt_out.video.i_sar_num = 1;
-            p_dec->fmt_out.video.i_sar_den = 1;
+            fmt.i_sar_num = 1;
+            fmt.i_sar_den = 1;
         }
 
-        vlc_ureduce( &p_dec->fmt_out.video.i_sar_num,
-                     &p_dec->fmt_out.video.i_sar_den,
-                     p_dec->fmt_out.video.i_sar_num,
-                     p_dec->fmt_out.video.i_sar_den, 50000 );
-
-        p_dec->fmt_out.video.i_chroma = p_dec->fmt_out.i_codec;
-        p_owner->video = p_dec->fmt_out.video;
+        vlc_ureduce( &fmt.i_sar_num, &fmt.i_sar_den,
+                     fmt.i_sar_num, fmt.i_sar_den, 50000 );
 
         vlc_mutex_lock( &p_owner->lock );
 
@@ -2332,9 +2331,27 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
         p_owner->p_vout = NULL;
         vlc_mutex_unlock( &p_owner->lock );
 
+        unsigned dpb_size;
+        switch( p_dec->fmt_in.i_codec )
+        {
+        case VLC_CODEC_H264:
+        case VLC_CODEC_DIRAC: /* FIXME valid ? */
+            dpb_size = 18;
+            break;
+        case VLC_CODEC_VP5:
+        case VLC_CODEC_VP6:
+        case VLC_CODEC_VP6F:
+        case VLC_CODEC_VP8:
+            dpb_size = 3;
+            break;
+        default:
+            dpb_size = 2;
+            break;
+        }
         p_vout = input_resource_RequestVout( p_owner->p_input->p->p_resource,
-                                              p_vout, &p_dec->fmt_out.video, true );
-
+                                             p_vout, &fmt,
+                                             dpb_size + 1 + DECODER_MAX_BUFFERING_COUNT,
+                                             true );
         vlc_mutex_lock( &p_owner->lock );
         p_owner->p_vout = p_vout;
 
@@ -2349,35 +2366,18 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
             p_dec->b_error = true;
             return NULL;
         }
-
-        if( p_owner->video.i_rmask )
-            p_owner->p_vout->render.i_rmask = p_owner->video.i_rmask;
-        if( p_owner->video.i_gmask )
-            p_owner->p_vout->render.i_gmask = p_owner->video.i_gmask;
-        if( p_owner->video.i_bmask )
-            p_owner->p_vout->render.i_bmask = p_owner->video.i_bmask;
     }
 
     /* Get a new picture
      */
     for( ;; )
     {
-        picture_t *p_picture;
-
         if( p_dec->b_die || p_dec->b_error )
             return NULL;
 
-        /* The video filter chain required that there is always 1 free buffer
-         * that it will use as temporary one. It will release the temporary
-         * buffer once its work is done, so this check is safe even if we don't
-         * lock around both count() and create().
-         */
-        if( vout_CountPictureAvailable( p_owner->p_vout ) >= 2 )
-        {
-            p_picture = vout_CreatePicture( p_owner->p_vout, 0, 0, 0 );
-            if( p_picture )
-                return p_picture;
-        }
+        picture_t *p_picture = vout_GetPicture( p_owner->p_vout );
+        if( p_picture )
+            return p_picture;
 
         if( DecoderIsFlushing( p_dec ) )
             return NULL;
@@ -2386,7 +2386,7 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
         DecoderSignalBuffering( p_dec, true );
 
         /* Check the decoder doesn't leak pictures */
-        vout_FixLeaks( p_owner->p_vout, false );
+        vout_FixLeaks( p_owner->p_vout );
 
         /* FIXME add a vout_WaitPictureAvailable (timedwait) */
         msleep( VOUT_OUTMEM_SLEEP );
@@ -2395,20 +2395,21 @@ static picture_t *vout_new_buffer( decoder_t *p_dec )
 
 static void vout_del_buffer( decoder_t *p_dec, picture_t *p_pic )
 {
-    vout_DropPicture( p_dec->p_owner->p_vout, p_pic );
+    vout_ReleasePicture( p_dec->p_owner->p_vout, p_pic );
 }
 
 static void vout_link_picture( decoder_t *p_dec, picture_t *p_pic )
 {
-    vout_LinkPicture( p_dec->p_owner->p_vout, p_pic );
+    vout_HoldPicture( p_dec->p_owner->p_vout, p_pic );
 }
 
 static void vout_unlink_picture( decoder_t *p_dec, picture_t *p_pic )
 {
-    vout_UnlinkPicture( p_dec->p_owner->p_vout, p_pic );
+    vout_ReleasePicture( p_dec->p_owner->p_vout, p_pic );
 }
 
-static subpicture_t *spu_new_buffer( decoder_t *p_dec )
+static subpicture_t *spu_new_buffer( decoder_t *p_dec,
+                                     const subpicture_updater_t *p_updater )
 {
     decoder_owner_sys_t *p_owner = p_dec->p_owner;
     vout_thread_t *p_vout = NULL;
@@ -2441,13 +2442,12 @@ static subpicture_t *spu_new_buffer( decoder_t *p_dec )
 
         vlc_mutex_unlock( &p_owner->lock );
 
-        spu_Control( vout_GetSpu( p_vout ), SPU_CHANNEL_REGISTER,
-                     &p_owner->i_spu_channel );
+        p_owner->i_spu_channel = vout_RegisterSubpictureChannel( p_vout );
         p_owner->i_spu_order = 0;
         p_owner->p_spu_vout = p_vout;
     }
 
-    p_subpic = subpicture_New();
+    p_subpic = subpicture_New( p_updater );
     if( p_subpic )
     {
         p_subpic->i_channel = p_owner->i_spu_channel;