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

Steve Lhomme robux4 at ycbcr.xyz
Mon Sep 23 17:01:18 CEST 2019


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

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 3d7f6c1bbe1..455a12a9007 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;
@@ -550,36 +550,6 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
             .mouse_event = MouseEvent, .mouse_opaque = p_dec
         };
         p_vout = input_resource_GetVoutHoldDevice( p_owner->p_resource, &cfg, &order, &dec_dev );
-        if (p_vout)
-        {
-            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;
-            }
-            cfg.dpb_size = dpb_size + p_dec->i_extra_picture_buffers + 1,
-            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);
@@ -615,6 +585,56 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
     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 +1743,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