[vlc-devel] [PATCH 11/26] decoder: split the creation of the vout/decoder device and the display module

Steve Lhomme robux4 at ycbcr.xyz
Fri Sep 20 16:28:41 CEST 2019


First handle the resources needed by the get_device() call, then the
format_update() which creates the display.
---
 src/input/decoder.c | 96 ++++++++++++++++++++++++++++++---------------
 1 file changed, 65 insertions(+), 31 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 01705c7a77e..4ddd9fdf41f 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -460,7 +460,7 @@ static void FixDisplayFormat(decoder_t *p_dec, video_format_t *fmt)
     video_format_AdjustColorSpace( fmt );
 }
 
-static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
+static int ModuleThread_HoldDecoderDevice( decoder_t *p_dec, vlc_decoder_device **pp_dec_dev )
 {
     struct decoder_owner *p_owner = dec_get_owner( p_dec );
     bool need_vout = false;
@@ -543,43 +543,13 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
         p_owner->p_vout = NULL; // the DecoderThread should not use the old vout anymore
         vlc_mutex_unlock( &p_owner->lock );
 
-        unsigned dpb_size;
-        switch( p_dec->fmt_in.i_codec )
-        {
-        case VLC_CODEC_HEVC:
-        case VLC_CODEC_H264:
-        case VLC_CODEC_DIRAC: /* FIXME valid ? */
-            dpb_size = 18;
-            break;
-        case VLC_CODEC_AV1:
-            dpb_size = 10;
-            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;
-        }
         enum vlc_vout_order order;
         vlc_decoder_device *dec_dev = NULL;
         vout_configuration_t cfg = {
             .vout = p_vout, .clock = p_owner->p_clock, .fmt = &fmt,
-            .dpb_size = dpb_size + p_dec->i_extra_picture_buffers + 1,
             .mouse_event = MouseEvent, .mouse_opaque = p_dec
         };
         p_vout = input_resource_GetVoutHoldDevice( p_owner->p_resource, &cfg, &order, &dec_dev );
-        if (p_vout)
-        {
-            cfg.vout = p_vout;
-            if (input_resource_GetDisplay( p_owner->p_resource, &cfg) != 0)
-            {
-                p_vout = NULL;
-            }
-        }
 
         if (p_vout)
             decoder_Notify(p_owner, on_vout_added, p_vout, order);
@@ -589,6 +559,8 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
         if ( p_owner->p_dec_dev != NULL )
             vlc_decoder_device_Release( p_owner->p_dec_dev );
         p_owner->p_dec_dev = dec_dev;
+        if ( pp_dec_dev )
+            *pp_dec_dev = dec_dev;
 
         DecoderUpdateFormatLocked( p_owner );
         p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
@@ -597,6 +569,11 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
         if( p_vout == NULL )
         {
             msg_Err( p_dec, "failed to create video output" );
+            if ( dec_dev != NULL )
+            {
+                vlc_decoder_device_Release( dec_dev );
+                p_owner->p_dec_dev = NULL;
+            }
             return -1;
         }
 
@@ -612,9 +589,65 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
         DecoderUpdateFormatLocked( p_owner );
         vlc_mutex_unlock( &p_owner->lock );
     }
+    else if ( pp_dec_dev )
+    {
+        vlc_mutex_lock( &p_owner->lock );
+        *pp_dec_dev = p_owner->p_dec_dev;
+        vlc_mutex_unlock( &p_owner->lock );
+    }
     return 0;
 }
 
+static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
+{
+    struct decoder_owner *p_owner = dec_get_owner( p_dec );
+
+    video_format_t fmt;
+    FixDisplayFormat( p_dec, &fmt );
+
+    vlc_mutex_lock( &p_owner->lock );
+
+    vout_thread_t *p_vout = p_owner->p_vout;
+    vlc_mutex_unlock( &p_owner->lock );
+
+    unsigned dpb_size;
+    switch( p_dec->fmt_in.i_codec )
+    {
+    case VLC_CODEC_HEVC:
+    case VLC_CODEC_H264:
+    case VLC_CODEC_DIRAC: /* FIXME valid ? */
+        dpb_size = 18;
+        break;
+    case VLC_CODEC_AV1:
+        dpb_size = 10;
+        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;
+    }
+    vout_configuration_t cfg = {
+        .vout = p_vout, .clock = p_owner->p_clock, .fmt = &fmt,
+        .dpb_size = dpb_size + p_dec->i_extra_picture_buffers + 1,
+        .mouse_event = MouseEvent, .mouse_opaque = p_dec,
+    };
+    int res = input_resource_GetDisplay( p_owner->p_resource, &cfg);
+
+    vlc_mutex_lock( &p_owner->lock );
+    p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
+    vlc_mutex_unlock( &p_owner->lock );
+
+    vlc_fifo_Lock( p_owner->p_fifo );
+    p_owner->reset_out_state = true;
+    vlc_fifo_Unlock( p_owner->p_fifo );
+    return res;
+}
+
 static picture_t *ModuleThread_NewVideoBuffer( decoder_t *p_dec )
 {
     struct decoder_owner *p_owner = dec_get_owner( p_dec );
@@ -1723,6 +1756,7 @@ static const struct decoder_owner_callbacks dec_video_cbs =
         .buffer_new = ModuleThread_NewVideoBuffer,
         .queue = ModuleThread_QueueVideo,
         .queue_cc = ModuleThread_QueueCc,
+        .hold_device = ModuleThread_HoldDecoderDevice,
         .get_display_date = ModuleThread_GetDisplayDate,
         .get_display_rate = ModuleThread_GetDisplayRate,
     },
-- 
2.17.1



More information about the vlc-devel mailing list