[vlc-devel] [PATCH 5/5] RFC: vout: spu: check module and filter chains at creation

Thomas Guillem thomas at gllm.fr
Mon Jun 3 15:41:36 CEST 2019


RFC: not sure if we should disable spu if there is no scaler or scaler_yuvp.

This also fixes a possible null-deref with source_chain and filter_chain.
---
 src/video_output/vout_subpictures.c | 42 +++++++++++++++++------------
 1 file changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 38785e4bfa..4896fa7425 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -216,6 +216,11 @@ static filter_t *SpuRenderCreateAndLoadText(spu_t *spu)
     text->pf_get_attachments = spu_get_attachments;
 
     text->p_module = module_need_var(text, "text renderer", "text-renderer");
+    if (!text->p_module)
+    {
+        vlc_object_delete(text);
+        return NULL;
+    }
 
     /* Create a few variables used for enhanced text rendering */
     var_Create(text, "spu-elapsed",   VLC_VAR_INTEGER);
@@ -254,6 +259,11 @@ static filter_t *SpuRenderCreateAndLoadScale(vlc_object_t *object,
     scale->owner.video = &spu_scaler_cbs;
 
     scale->p_module = module_need(scale, "video converter", NULL, false);
+    if (!scale->p_module)
+    {
+        vlc_object_delete(scale);
+        return NULL;
+    }
 
     return scale;
 }
@@ -267,9 +277,6 @@ static void SpuRenderText(spu_t *spu, bool *rerender_text,
 
     assert(region->fmt.i_chroma == VLC_CODEC_TEXT);
 
-    if (!text || !text->p_module)
-        return;
-
     /* Setup 3 variables which can be used to render
      * time-dependent text (and effects). The first indicates
      * the total amount of time the text will be on screen,
@@ -872,10 +879,8 @@ static void SpuRenderRegion(spu_t *spu,
     }
 
     /* Scale from rendered size to destination size */
-    if (sys->scale && sys->scale->p_module &&
-        (!using_palette || (sys->scale_yuvp && sys->scale_yuvp->p_module)) &&
-        (scale_size.w != SCALE_UNIT || scale_size.h != SCALE_UNIT ||
-        using_palette || convert_chroma)) {
+    if (scale_size.w != SCALE_UNIT || scale_size.h != SCALE_UNIT || convert_chroma)
+    {
         const unsigned dst_width  = spu_scale_w(region->fmt.i_visible_width,  scale_size);
         const unsigned dst_height = spu_scale_h(region->fmt.i_visible_height, scale_size);
 
@@ -1138,14 +1143,12 @@ static subpicture_t *SpuRenderSubpictures(spu_t *spu,
             subpic->i_original_picture_height = fmt_src->i_visible_height;
         }
 
-        if (sys->text) {
-            /* FIXME aspect ratio ? */
-            sys->text->fmt_out.video.i_width          =
-            sys->text->fmt_out.video.i_visible_width  = subpic->i_original_picture_width;
+        /* FIXME aspect ratio ? */
+        sys->text->fmt_out.video.i_width          =
+        sys->text->fmt_out.video.i_visible_width  = subpic->i_original_picture_width;
 
-            sys->text->fmt_out.video.i_height         =
-            sys->text->fmt_out.video.i_visible_height = subpic->i_original_picture_height;
-        }
+        sys->text->fmt_out.video.i_height         =
+        sys->text->fmt_out.video.i_visible_height = subpic->i_original_picture_height;
 
         /* Render all regions
          * We always transform non absolute subtitle into absolute one on the
@@ -1379,9 +1382,6 @@ spu_t *spu_Create(vlc_object_t *object, vout_thread_t *vout)
     SpuHeapInit(&sys->heap);
 
     sys->clock = NULL;
-    sys->text = NULL;
-    sys->scale = NULL;
-    sys->scale_yuvp = NULL;
 
     atomic_init(&sys->margin, var_InheritInteger(spu, "sub-margin"));
 
@@ -1407,6 +1407,14 @@ spu_t *spu_Create(vlc_object_t *object, vout_thread_t *vout)
     sys->scale_yuvp = SpuRenderCreateAndLoadScale(VLC_OBJECT(spu),
                                                   VLC_CODEC_YUVP, VLC_CODEC_YUVA, false);
 
+
+    if (!sys->source_chain || !sys->filter_chain || !sys->text || !sys->scale
+     || !sys->scale_yuvp)
+    {
+        sys->vout = NULL;
+        spu_Destroy(spu);
+        return NULL;
+    }
     /* */
     sys->last_sort_date = -1;
     sys->vout = vout;
-- 
2.20.1



More information about the vlc-devel mailing list