[vlc-devel] [PATCH 13/15] Add dynamic secondary sub margin workaround

Roland Bewick roland.bewick at gmail.com
Tue May 14 11:40:12 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               | 15 ++++++++-------
 src/video_output/vout_subpictures.c | 17 +++++++++++++++++
 3 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/include/vlc_subpicture.h b/include/vlc_subpicture.h
index 4a646dc936..060ce8de12 100644
--- a/include/vlc_subpicture.h
+++ b/include/vlc_subpicture.h
@@ -198,6 +198,7 @@ struct subpicture_t
     int          i_original_picture_width;  /**< original width of the movie */
     int          i_original_picture_height;/**< original height of the movie */
     int          i_alpha;                                  /**< transparency */
+    int          i_secondary_margin;      /* margin recorded on first render */
      /**@}*/
 
     subpicture_updater_t updater;
diff --git a/src/misc/subpicture.c b/src/misc/subpicture.c
index 8c1ae51797..69ad2df459 100644
--- a/src/misc/subpicture.c
+++ b/src/misc/subpicture.c
@@ -46,13 +46,14 @@ subpicture_t *subpicture_New( const subpicture_updater_t *p_upd )
     if( !p_subpic )
         return NULL;
 
-    p_subpic->i_order    = 0;
-    p_subpic->b_absolute = true;
-    p_subpic->b_fade     = false;
-    p_subpic->b_subtitle = false;
-    p_subpic->i_alpha    = 0xFF;
-    p_subpic->p_region   = NULL;
-    p_subpic->p_clock    = NULL;
+    p_subpic->i_order            = 0;
+    p_subpic->b_absolute         = true;
+    p_subpic->b_fade             = false;
+    p_subpic->b_subtitle         = false;
+    p_subpic->i_alpha            = 0xFF;
+    p_subpic->p_region           = NULL;
+    p_subpic->p_clock            = 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 7a29c2d365..33989a9392 100644
--- a/src/video_output/vout_subpictures.c
+++ b/src/video_output/vout_subpictures.c
@@ -832,6 +832,23 @@ static void SpuRenderRegion(spu_t *spu,
     int i_align = region->i_align;
     if (subpic->i_spu_id > SPU_ID_PRIMARY)
     {
+        int secondary_margin =
+            spu_invscale_h(atomic_load(&sys->secondary_sub_margin[subpic->i_spu_id - SPU_ID_SECONDARY_START]),
+                                       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;
+        }
+
         int i_align_override = sys->secondary_sub_alignment[subpic->i_spu_id - SPU_ID_SECONDARY_START];
         i_align = i_align_override >= 0 ? i_align_override : i_align;
     }
-- 
2.11.0



More information about the vlc-devel mailing list