[vlc-devel] [PATCH 09/10] Dynamic secondary sub margin workaround

Roland Bewick roland.bewick at gmail.com
Sun May 5 12:01:49 CEST 2019


Margin from hotkeys was only applied when the subtitle is first rendered (non-absolute position).

This change will alter the absolute position by the difference in margin since the subtitle was first rendered.
---
 include/vlc_subpicture.h            |  1 +
 src/misc/subpicture.c               |  1 +
 src/video_output/vout_subpictures.c | 19 +++++++++++++++----
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/include/vlc_subpicture.h b/include/vlc_subpicture.h
index d36ed2c055..639a015f0b 100644
--- a/include/vlc_subpicture.h
+++ b/include/vlc_subpicture.h
@@ -193,6 +193,7 @@ struct subpicture_t
     /**@{*/
     bool         b_subtitle;            /**< the picture is a movie subtitle */
     bool         b_secondary;           /**< use secondary subtrack settings */
+    int          i_secondary_margin;      /* margin recorded on first render */
     bool         b_absolute;                       /**< position is absolute */
     int          i_original_picture_width;  /**< original width of the movie */
     int          i_original_picture_height;/**< original height of the movie */
diff --git a/src/misc/subpicture.c b/src/misc/subpicture.c
index 3e2535492a..eca5663d6c 100644
--- a/src/misc/subpicture.c
+++ b/src/misc/subpicture.c
@@ -52,6 +52,7 @@ subpicture_t *subpicture_New( const subpicture_updater_t *p_upd )
     p_subpic->b_subtitle = false;
     p_subpic->i_alpha    = 0xFF;
     p_subpic->p_region   = NULL;
+    p_subpic->i_secondary_margin = 0;
 
     if( p_upd )
     {
diff --git a/src/video_output/vout_subpictures.c b/src/video_output/vout_subpictures.c
index 7349a22482..a91b585bbc 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -809,11 +809,22 @@ static void SpuRenderRegion(spu_t *spu,
     SpuRegionPlace(&x_offset, &y_offset,
                    subpic, region, sys->secondary_sub_alignment);
 
-    if (subpic->b_secondary && !subpic->b_absolute)
+    if (subpic->b_secondary)
     {
-        /* Move the secondary subtitles by the secondary margin before overlap detection.
-           This way, overlaps will be resolved if they still exist. */
-        y_offset -= spu_invscale_h(atomic_load(&sys->secondary_sub_margin), scale_size);
+        int secondary_margin = spu_invscale_h(atomic_load(&sys->secondary_sub_margin), scale_size);
+        if (!subpic->b_absolute)
+        {
+            /* Move the secondary subtitles by the secondary margin before overlap detection.
+            This way, overlaps will be resolved if they still exist. */
+            y_offset -= secondary_margin;
+            subpic->i_secondary_margin = secondary_margin;
+        }
+        else
+        {
+            /* Use an absolute margin for secondary subpictures that
+               have already been placed but have been moved by the user */
+            y_margin += secondary_margin - subpic->i_secondary_margin;
+        }
     }
 
     /* Save this position for subtitle overlap support
-- 
2.17.1



More information about the vlc-devel mailing list