[vlc-commits] decoder: split the creation of the vout/decoder device and the display module

Steve Lhomme git at videolan.org
Wed Oct 9 10:16:07 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Wed Sep 25 16:42:29 2019 +0200| [4833d01cccb17237f4f6f1a72b3833e477fd9ed6] | committer: Steve Lhomme

decoder: split the creation of the vout/decoder device and the display module

First handle the resources needed by the get_device() call, then the
format_update() which creates the display.

The on_vout_started is only notified when the vout is really started.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4833d01cccb17237f4f6f1a72b3833e477fd9ed6
---

 src/input/decoder.c | 61 ++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 42 insertions(+), 19 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 27183a9a78..a9d50c7b63 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -457,13 +457,19 @@ 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;
+    enum vlc_vout_order vout_order = p_owner->vout_order;
+    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 );
 
@@ -493,10 +499,13 @@ 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_ReconfigureVout( p_owner->p_resource, dec_dev, &cfg);
+    int res = input_resource_ReconfigureVout( p_owner->p_resource, p_owner->p_dec_dev, &cfg);
+    if (res == 0)
+        decoder_Notify(p_owner, on_vout_started, p_vout, vout_order);
+    return res;
 }
 
-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;
@@ -563,25 +572,29 @@ 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_GetVoutDecoderDevice( p_owner->p_resource,
-                                    &cfg, &order, &dec_dev );
-    if (CreateDisplay( p_owner, dec_dev, p_vout ) != 0)
-        p_vout = NULL;
-    if (p_vout)
-        decoder_Notify(p_owner, on_vout_started, p_vout, order);
+                                    &cfg, &order, pp_dec_dev );
 
     vlc_mutex_lock( &p_owner->lock );
     p_owner->p_vout = p_vout;
     p_owner->vout_order = order;
-    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 ? vlc_decoder_device_Hold(*pp_dec_dev) : NULL;
+    }
 
     DecoderUpdateFormatLocked( p_owner );
     p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
@@ -600,13 +613,22 @@ static int CreateVoutIfNeeded(struct decoder_owner *p_owner)
     return 1; // new vout was created
 }
 
-static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
+static vlc_decoder_device * ModuleThread_GetDecoderDevice( decoder_t *p_dec )
 {
     struct decoder_owner *p_owner = dec_get_owner( p_dec );
 
-    int created_vout = CreateVoutIfNeeded(p_owner);
-    if (created_vout != 0)
-        return created_vout == -1 ? -1 : 0; // error or new vout was created
+    vlc_decoder_device *dec_device = NULL;
+    int created_vout = CreateVoutIfNeeded(p_owner, &dec_device);
+    if (created_vout == -1)
+    {
+        if ( dec_device )
+            vlc_decoder_device_Release( dec_device );
+        return NULL;  // error
+    }
+    if (created_vout == 1)
+    {
+        return dec_device; // new vout was created with a decoder device
+    }
 
     bool need_format_update = false;
     if ( memcmp( &p_dec->fmt_out.video.mastering,
@@ -632,7 +654,7 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec )
         DecoderUpdateFormatLocked( p_owner );
         vlc_mutex_unlock( &p_owner->lock );
     }
-    return 0;
+    return dec_device;
 }
 
 static picture_t *ModuleThread_NewVideoBuffer( decoder_t *p_dec )
@@ -1740,6 +1762,7 @@ static void *DecoderThread( void *p_data )
 static const struct decoder_owner_callbacks dec_video_cbs =
 {
     .video = {
+        .get_device = ModuleThread_GetDecoderDevice,
         .format_update = ModuleThread_UpdateVideoFormat,
         .buffer_new = ModuleThread_NewVideoBuffer,
         .abort_pictures = DecoderThread_AbortPictures,



More information about the vlc-commits mailing list