[vlc-commits] [Git][videolan/vlc][master] 6 commits: vout_subpictures: rename SpuRenderText parameters

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Nov 21 07:24:44 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
08fdb7c8 by Steve Lhomme at 2023-11-21T07:09:12+00:00
vout_subpictures: rename SpuRenderText parameters

They are not the original sizes but the output size we want.

- - - - -
4df34d78 by Steve Lhomme at 2023-11-21T07:09:12+00:00
vout_subpicture: use a function to rescale a picture region

The scale version is stored in the private area of the region.

- - - - -
12803491 by Steve Lhomme at 2023-11-21T07:09:12+00:00
vout_subpicture: do the last minute text render outside of the picture rendering

We should only to the rendering of picture based region at this point.

- - - - -
c3a04462 by Steve Lhomme at 2023-11-21T07:09:12+00:00
vout_subpicture: handle external scaling on all regions

We transform the text regions so if there's a region to render/place,
it's a picture-based one.

- - - - -
dec4389e by Steve Lhomme at 2023-11-21T07:09:12+00:00
vout_subpictures: pass the region to render/scale as const

- - - - -
1ccff8cc by Steve Lhomme at 2023-11-21T07:09:12+00:00
substext: rename variable to avoid variable shadowing

- - - - -


2 changed files:

- modules/codec/substext.h
- src/video_output/vout_subpictures.c


Changes:

=====================================
modules/codec/substext.h
=====================================
@@ -155,8 +155,8 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
 
     bool b_schedule_blink_update = false;
 
-    for( substext_updater_region_t *p_updtregion = &sys->region;
-                                          p_updtregion; p_updtregion = p_updtregion->p_next )
+    for( substext_updater_region_t *update_region = &sys->region;
+                                    update_region; update_region = update_region->p_next )
     {
         subpicture_region_t *r = subpicture_region_NewText();
         if (!r)
@@ -165,16 +165,16 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
         r->fmt.i_sar_num = sar.num;
         r->fmt.i_sar_den = sar.den;
 
-        r->p_text = text_segment_Copy( p_updtregion->p_segments );
-        r->i_align = p_updtregion->align;
-        r->text_flags |= p_updtregion->inner_align & SUBPICTURE_ALIGN_MASK;
-        if (p_updtregion->flags & UPDT_REGION_IGNORE_BACKGROUND)
+        r->p_text = text_segment_Copy( update_region->p_segments );
+        r->i_align = update_region->align;
+        r->text_flags |= update_region->inner_align & SUBPICTURE_ALIGN_MASK;
+        if (update_region->flags & UPDT_REGION_IGNORE_BACKGROUND)
             r->text_flags |= VLC_SUBPIC_TEXT_FLAG_NO_REGION_BG;
-        bool b_gridmode = (p_updtregion->flags & UPDT_REGION_USES_GRID_COORDINATES) != 0;
+        bool b_gridmode = (update_region->flags & UPDT_REGION_USES_GRID_COORDINATES) != 0;
         if (b_gridmode)
             r->text_flags |= VLC_SUBPIC_TEXT_FLAG_GRID_MODE;
 
-        if (!(p_updtregion->flags & UPDT_REGION_FIXED_DONE))
+        if (!(update_region->flags & UPDT_REGION_FIXED_DONE))
         {
             const float margin_ratio = sys->margin_ratio;
             const int   margin_h     = margin_ratio * ( b_gridmode ? subpic->i_original_picture_width
@@ -198,30 +198,30 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
             else if (r->i_align & SUBPICTURE_ALIGN_BOTTOM )
                 r->i_y = margin_v + outerbottom_v;
 
-            if( p_updtregion->flags & UPDT_REGION_ORIGIN_X_IS_RATIO )
-                r->i_x += p_updtregion->origin.x * inner_w;
+            if( update_region->flags & UPDT_REGION_ORIGIN_X_IS_RATIO )
+                r->i_x += update_region->origin.x * inner_w;
             else
-                r->i_x += p_updtregion->origin.x;
+                r->i_x += update_region->origin.x;
 
-            if( p_updtregion->flags & UPDT_REGION_ORIGIN_Y_IS_RATIO )
-                r->i_y += p_updtregion->origin.y * inner_h;
+            if( update_region->flags & UPDT_REGION_ORIGIN_Y_IS_RATIO )
+                r->i_y += update_region->origin.y * inner_h;
             else
-                r->i_y += p_updtregion->origin.y;
+                r->i_y += update_region->origin.y;
 
-            if( p_updtregion->flags & UPDT_REGION_EXTENT_X_IS_RATIO )
-                r->i_max_width += p_updtregion->extent.x * inner_w;
+            if( update_region->flags & UPDT_REGION_EXTENT_X_IS_RATIO )
+                r->i_max_width += update_region->extent.x * inner_w;
             else
-                r->i_max_width += p_updtregion->extent.x;
+                r->i_max_width += update_region->extent.x;
 
-            if( p_updtregion->flags & UPDT_REGION_EXTENT_Y_IS_RATIO )
-                r->i_max_height += p_updtregion->extent.y * inner_h;
+            if( update_region->flags & UPDT_REGION_EXTENT_Y_IS_RATIO )
+                r->i_max_height += update_region->extent.y * inner_h;
             else
-                r->i_max_height += p_updtregion->extent.y;
+                r->i_max_height += update_region->extent.y;
 
         } else {
             /* FIXME it doesn't adapt on crop settings changes */
-            r->i_x = p_updtregion->origin.x * fmt_dst->i_width  / p_updtregion->extent.x;
-            r->i_y = p_updtregion->origin.y * fmt_dst->i_height / p_updtregion->extent.y;
+            r->i_x = update_region->origin.x * fmt_dst->i_width  / update_region->extent.x;
+            r->i_y = update_region->origin.y * fmt_dst->i_height / update_region->extent.y;
         }
 
         /* Add missing default style, if any, to all segments */


=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -329,8 +329,8 @@ static void region_FixFmt(subpicture_region_t *region)
 
 static subpicture_region_t *SpuRenderText(spu_t *spu,
                           const subpicture_region_t *region,
-                          unsigned i_original_width,
-                          unsigned i_original_height,
+                          unsigned output_width,
+                          unsigned output_height,
                           const vlc_fourcc_t *chroma_list)
 {
     spu_private_t *sys = spu->p;
@@ -348,10 +348,10 @@ static subpicture_region_t *SpuRenderText(spu_t *spu,
 
     /* FIXME aspect ratio ? */
     text->fmt_out.video.i_width =
-    text->fmt_out.video.i_visible_width  = i_original_width;
+    text->fmt_out.video.i_visible_width  = output_width;
 
     text->fmt_out.video.i_height =
-    text->fmt_out.video.i_visible_height = i_original_height;
+    text->fmt_out.video.i_visible_height = output_height;
 
     subpicture_region_t *rendered_region = text->ops->render(text, region, chroma_list);
     assert(rendered_region == NULL || !subpicture_region_IsText(rendered_region));
@@ -802,7 +802,120 @@ spu_SelectSubpictures(spu_t *spu, vlc_tick_t system_now,
     return subpicture_array;
 }
 
+static void SpuRescaleRegion(spu_t *spu,
+                             const subpicture_region_t *region,
+                             picture_t **scaled_pic,
+                             const spu_scale_t scale_size,
+                             bool changed_palette, bool using_palette,
+                             const vlc_fourcc_t *chroma_list)
+{
+    spu_private_t *sys = spu->p;
+
+    bool convert_chroma = true;
+    for (int i = 0; chroma_list[i] && convert_chroma; i++) {
+        if (region->fmt.i_chroma == chroma_list[i])
+            convert_chroma = false;
+    }
+
+    /* Scale from rendered size to destination size */
+    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);
+
+        /* Destroy the cache if unusable */
+        if (*scaled_pic) {
+            picture_t *private = *scaled_pic;
+            bool is_changed = false;
+
+            /* Check resize changes */
+            if (dst_width  != private->format.i_visible_width ||
+                dst_height != private->format.i_visible_height)
+                is_changed = true;
+
+            /* Check forced palette changes */
+            if (changed_palette)
+                is_changed = true;
+
+            if (convert_chroma && private->format.i_chroma != chroma_list[0])
+                is_changed = true;
+
+            if (is_changed) {
+                picture_Release(*scaled_pic);
+                *scaled_pic = NULL;
+            }
+        }
+
+        /* Scale if needed into cache */
+        if (!*scaled_pic && dst_width > 0 && dst_height > 0) {
+            filter_t *scale = sys->scale;
+
+            picture_t *picture = region->p_picture;
+            picture_Hold(picture);
+
+            /* Convert YUVP to YUVA/RGBA first for better scaling quality */
+            if (using_palette) {
+                filter_t *scale_yuvp = sys->scale_yuvp;
+
+                scale_yuvp->fmt_in.video = region->fmt;
 
+                scale_yuvp->fmt_out.video = region->fmt;
+                scale_yuvp->fmt_out.video.i_chroma = chroma_list[0];
+                scale_yuvp->fmt_out.video.p_palette = NULL;
+
+                picture = scale_yuvp->ops->filter_video(scale_yuvp, picture);
+
+                scale_yuvp->fmt_in.video.p_palette = NULL;
+                assert(picture == NULL || !picture_HasChainedPics(picture)); // no chaining
+                if (!picture) {
+                    /* Well we will try conversion+scaling */
+                    msg_Warn(spu, "%4.4s to %4.4s conversion failed",
+                             (const char*)&scale_yuvp->fmt_in.video.i_chroma,
+                             (const char*)&scale_yuvp->fmt_out.video.i_chroma);
+                }
+            }
+
+            /* Conversion(except from YUVP)/Scaling */
+            if (picture &&
+                (picture->format.i_visible_width  != dst_width ||
+                 picture->format.i_visible_height != dst_height ||
+                 (convert_chroma && !using_palette)))
+            {
+                scale->fmt_in.video  = picture->format;
+                scale->fmt_out.video = picture->format;
+                if (using_palette)
+                {
+                    scale->fmt_in.video.i_chroma = chroma_list[0];
+                }
+                if (convert_chroma)
+                {
+                    scale->fmt_out.i_codec        =
+                    scale->fmt_out.video.i_chroma = chroma_list[0];
+                }
+
+                scale->fmt_out.video.i_width  = dst_width;
+                scale->fmt_out.video.i_height = dst_height;
+
+                scale->fmt_out.video.i_visible_width =
+                    spu_scale_w(region->fmt.i_visible_width, scale_size);
+                scale->fmt_out.video.i_visible_height =
+                    spu_scale_h(region->fmt.i_visible_height, scale_size);
+
+                picture = scale->ops->filter_video(scale, picture);
+                assert(picture == NULL || !picture_HasChainedPics(picture)); // no chaining
+                if (!picture)
+                    msg_Err(spu, "scaling failed");
+            }
+
+            /* */
+            if (picture) {
+                if (*scaled_pic)
+                    picture_Release(picture);
+                *scaled_pic = picture;
+            }
+        }
+    }
+}
 
 /**
  * It will transform the provided region into another region suitable for rendering.
@@ -810,15 +923,15 @@ spu_SelectSubpictures(spu_t *spu, vlc_tick_t system_now,
 static subpicture_region_t *SpuRenderRegion(spu_t *spu,
                             spu_area_t *dst_area,
                             const spu_render_entry_t *entry,
-                            subpicture_region_t *region,
+                            const subpicture_region_t *region,
                             picture_t **scaled_pic,
                             const spu_scale_t scale_size,
                             const vlc_fourcc_t *chroma_list,
                             const video_format_t *fmt,
-                            int i_original_width, int i_original_height,
                             const spu_area_t *subtitle_area, size_t subtitle_area_count,
                             vlc_tick_t render_date)
 {
+    assert(!subpicture_region_IsText( region ));
     subpicture_t *subpic = entry->subpic;
     spu_private_t *sys = spu->p;
 
@@ -831,23 +944,6 @@ static subpicture_region_t *SpuRenderRegion(spu_t *spu,
     /* Invalidate area by default */
     *dst_area = spu_area_create(0,0, 0,0, scale_size);
 
-    /* Render text region */
-    if (unlikely(subpicture_region_IsText( region )))
-    {
-        subpicture_region_t *rendered_text =
-            SpuRenderText(spu, region,
-                      i_original_width, i_original_height,
-                      chroma_list);
-        if ( rendered_text  == NULL)
-            // not a rendering error for Text-To-Speech
-            return NULL;
-        // replace the text region with the rendered region
-        vlc_list_replace(&region->node, &rendered_text->node);
-        subpicture_region_Delete(region);
-        region = rendered_text;
-        region_FixFmt(rendered_text);
-    }
-
     /* Force palette if requested
      * FIXME b_force_palette and force_crop are applied to all subpictures using palette
      * instead of only the right one (being the dvd spu).
@@ -972,118 +1068,19 @@ static subpicture_region_t *SpuRenderRegion(spu_t *spu,
     }
 
     /* */
-    region_fmt = region->fmt;
-    region_picture = region->p_picture;
+    SpuRescaleRegion( spu, region, scaled_pic, scale_size,
+                      changed_palette, using_palette,
+                      chroma_list );
 
-    bool convert_chroma = true;
-    for (int i = 0; chroma_list[i] && convert_chroma; i++) {
-        if (region_fmt.i_chroma == chroma_list[i])
-            convert_chroma = false;
+    if (*scaled_pic == NULL)
+    {
+        region_fmt = region->fmt;
+        region_picture = region->p_picture;
     }
-
-    /* Scale from rendered size to destination size */
-    if (scale_size.w != SCALE_UNIT || scale_size.h != SCALE_UNIT || convert_chroma)
+    else
     {
-        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);
-
-        /* Destroy the cache if unusable */
-        if (*scaled_pic) {
-            picture_t *private = *scaled_pic;
-            bool is_changed = false;
-
-            /* Check resize changes */
-            if (dst_width  != private->format.i_visible_width ||
-                dst_height != private->format.i_visible_height)
-                is_changed = true;
-
-            /* Check forced palette changes */
-            if (changed_palette)
-                is_changed = true;
-
-            if (convert_chroma && private->format.i_chroma != chroma_list[0])
-                is_changed = true;
-
-            if (is_changed) {
-                picture_Release(*scaled_pic);
-                *scaled_pic = NULL;
-            }
-        }
-
-        /* Scale if needed into cache */
-        if (!*scaled_pic && dst_width > 0 && dst_height > 0) {
-            filter_t *scale = sys->scale;
-
-            picture_t *picture = region->p_picture;
-            picture_Hold(picture);
-
-            /* Convert YUVP to YUVA/RGBA first for better scaling quality */
-            if (using_palette) {
-                filter_t *scale_yuvp = sys->scale_yuvp;
-
-                scale_yuvp->fmt_in.video = region->fmt;
-
-                scale_yuvp->fmt_out.video = region->fmt;
-                scale_yuvp->fmt_out.video.i_chroma = chroma_list[0];
-                scale_yuvp->fmt_out.video.p_palette = NULL;
-
-                picture = scale_yuvp->ops->filter_video(scale_yuvp, picture);
-
-                scale_yuvp->fmt_in.video.p_palette = NULL;
-                assert(picture == NULL || !picture_HasChainedPics(picture)); // no chaining
-                if (!picture) {
-                    /* Well we will try conversion+scaling */
-                    msg_Warn(spu, "%4.4s to %4.4s conversion failed",
-                             (const char*)&scale_yuvp->fmt_in.video.i_chroma,
-                             (const char*)&scale_yuvp->fmt_out.video.i_chroma);
-                }
-            }
-
-            /* Conversion(except from YUVP)/Scaling */
-            if (picture &&
-                (picture->format.i_visible_width  != dst_width ||
-                 picture->format.i_visible_height != dst_height ||
-                 (convert_chroma && !using_palette)))
-            {
-                scale->fmt_in.video  = picture->format;
-                scale->fmt_out.video = picture->format;
-                if (using_palette)
-                {
-                    scale->fmt_in.video.i_chroma = chroma_list[0];
-                }
-                if (convert_chroma)
-                {
-                    scale->fmt_out.i_codec        =
-                    scale->fmt_out.video.i_chroma = chroma_list[0];
-                }
-
-                scale->fmt_out.video.i_width  = dst_width;
-                scale->fmt_out.video.i_height = dst_height;
-
-                scale->fmt_out.video.i_visible_width =
-                    spu_scale_w(region->fmt.i_visible_width, scale_size);
-                scale->fmt_out.video.i_visible_height =
-                    spu_scale_h(region->fmt.i_visible_height, scale_size);
-
-                picture = scale->ops->filter_video(scale, picture);
-                assert(picture == NULL || !picture_HasChainedPics(picture)); // no chaining
-                if (!picture)
-                    msg_Err(spu, "scaling failed");
-            }
-
-            /* */
-            if (picture) {
-                if (*scaled_pic)
-                    picture_Release(picture);
-                *scaled_pic = picture;
-            }
-        }
-
-        /* And use the scaled picture */
-        if (*scaled_pic) {
-            region_fmt     = (*scaled_pic)->format;
-            region_picture = *scaled_pic;
-        }
+        region_picture = *scaled_pic;
+        region_fmt = region_picture->format;
     }
 
     /* Force cropping if requested */
@@ -1283,20 +1280,35 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
             /* Check scale validity */
             assert(scale.w != 0 && scale.h != 0);
 
-            const bool do_external_scale = external_scale && !subpicture_region_IsText( region );
+            /* last minute text rendering */
+            subpicture_region_t *rendered_region = region;
+            if (unlikely(subpicture_region_IsText( region )))
+            {
+                subpicture_region_t *rendered_text =
+                    SpuRenderText(spu, region,
+                            i_original_width, i_original_height,
+                            chroma_list);
+                if ( rendered_text  == NULL)
+                    // not a rendering error for Text-To-Speech
+                    continue;
+                rendered_region = rendered_text;
+                region_FixFmt(rendered_text);
+            }
+
             spu_scale_t virtual_scale = external_scale ? (spu_scale_t){ SCALE_UNIT, SCALE_UNIT } : scale;
 
             /* */
             output_last_ptr = SpuRenderRegion(spu, &area,
-                            entry, region, scaled_region_pic, virtual_scale,
+                            entry, rendered_region, scaled_region_pic, virtual_scale,
                             chroma_list, fmt_dst,
-                            i_original_width, i_original_height,
                             subtitle_area, subtitle_area_count,
                             subpic->b_subtitle ? render_subtitle_date : system_now);
+            if (rendered_region != region)
+                subpicture_region_Delete( rendered_region );
             if (unlikely(output_last_ptr == NULL))
                 continue;
 
-            if (do_external_scale)
+            if (external_scale)
             {
                 if (scale.h != SCALE_UNIT)
                 {



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e2d84f180ded9cd464aea130d5de4026794aa0e1...1ccff8cc090dd803ea849181ac725e7691f4dd5f

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/e2d84f180ded9cd464aea130d5de4026794aa0e1...1ccff8cc090dd803ea849181ac725e7691f4dd5f
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list