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

Steve Lhomme robux4 at ycbcr.xyz
Thu Sep 26 16:00:05 CEST 2019


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

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 3dcfd9831dd..049c6ed8c5b 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -460,13 +460,18 @@ static void FixDisplayFormat(decoder_t *p_dec, video_format_t *fmt)
     video_format_AdjustColorSpace( fmt );
 }
 
-static int CreateDisplay(struct decoder_owner *p_owner, vlc_decoder_device *dec_dev, vout_thread_t *p_vout)
+static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
 {
+    struct decoder_owner *p_owner = dec_get_owner( p_dec );
+
+    vlc_mutex_lock( &p_owner->lock );
+
+    vout_thread_t *p_vout = p_owner->p_vout;
+    vlc_mutex_unlock( &p_owner->lock );
+
     if (!p_vout)
         return -1;
 
-    decoder_t *p_dec = &p_owner->dec;
-
     video_format_t fmt;
     FixDisplayFormat( p_dec, &fmt );
 
@@ -496,10 +501,10 @@ static int CreateDisplay(struct decoder_owner *p_owner, vlc_decoder_device *dec_
         .dpb_size = dpb_size + p_dec->i_extra_picture_buffers + 1,
         .mouse_event = MouseEvent, .mouse_opaque = p_dec,
     };
-    return input_resource_GetDisplay( p_owner->p_resource, dec_dev, &cfg);
+    return input_resource_GetDisplay( p_owner->p_resource, p_owner->p_dec_dev, &cfg);
 }
 
-static int CreateVoutIfNeeded(struct decoder_owner *p_owner)
+static int CreateVoutIfNeeded(struct decoder_owner *p_owner, vlc_decoder_device **pp_dec_dev)
 {
     decoder_t *p_dec = &p_owner->dec;
     bool need_vout = false;
@@ -566,24 +571,30 @@ static int CreateVoutIfNeeded(struct decoder_owner *p_owner)
     p_owner->p_vout = NULL; // the DecoderThread should not use the old vout anymore
     vlc_mutex_unlock( &p_owner->lock );
 
+    if ( pp_dec_dev ) *pp_dec_dev = NULL;
     enum vlc_vout_order order;
     vout_configuration_t cfg = {
         .vout = p_vout, .clock = p_owner->p_clock, .fmt = &fmt,
         .mouse_event = MouseEvent, .mouse_opaque = p_dec
     };
-    vlc_decoder_device *dec_dev = NULL;
     p_vout = input_resource_GetVoutHoldDevice( p_owner->p_resource,
-                                    &cfg, &order, &dec_dev );
-    if (CreateDisplay( p_owner, dec_dev, p_vout ) != 0)
-        p_vout = NULL;
+                                    &cfg, &order, pp_dec_dev );
     if (p_vout)
         decoder_Notify(p_owner, on_vout_added, p_vout, order);
 
     vlc_mutex_lock( &p_owner->lock );
     p_owner->p_vout = p_vout;
-    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 )
+    {
+        if ( p_owner->p_dec_dev != NULL )
+            vlc_decoder_device_Release( p_owner->p_dec_dev );
+        if( p_vout == NULL && *pp_dec_dev != NULL )
+        {
+            vlc_decoder_device_Release( *pp_dec_dev );
+            *pp_dec_dev = NULL;
+        }
+        p_owner->p_dec_dev = *pp_dec_dev;
+    }
 
     DecoderUpdateFormatLocked( p_owner );
     p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
@@ -602,13 +613,13 @@ static int CreateVoutIfNeeded(struct decoder_owner *p_owner)
     return 1; // new vout was created
 }
 
-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 );
 
-    int created_vout = CreateVoutIfNeeded(p_owner);
+    int created_vout = CreateVoutIfNeeded(p_owner, pp_dec_dev);
     if (created_vout != 0)
-        return created_vout == -1 ? -1 : 0; // error or new vout was created
+        return created_vout == -1 ? -1 : 0; // error or new vout was created with a decoder device
 
     bool need_format_update = false;
     if ( memcmp( &p_dec->fmt_out.video.mastering,
@@ -1741,6 +1752,7 @@ static void *DecoderThread( void *p_data )
 static const struct decoder_owner_callbacks dec_video_cbs =
 {
     .video = {
+        .hold_device = ModuleThread_HoldDecoderDevice,
         .format_update = ModuleThread_UpdateVideoFormat,
         .buffer_new = ModuleThread_NewVideoBuffer,
         .queue = ModuleThread_QueueVideo,
-- 
2.17.1



More information about the vlc-devel mailing list