[vlc-devel] [PATCH 03/15] Add spu_id property to decoder

Roland Bewick roland.bewick at gmail.com
Tue May 14 11:40:02 CEST 2019


This property will allow control of alignment, margin and synchronization of individual subpictures.
---
 include/vlc_subpicture.h |  1 +
 src/input/decoder.c      | 15 +++++++++++++++
 src/input/decoder.h      |  6 ++++++
 src/input/es_out.c       |  9 +++++++--
 4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/include/vlc_subpicture.h b/include/vlc_subpicture.h
index ea618e8aa1..5dc07d4d3b 100644
--- a/include/vlc_subpicture.h
+++ b/include/vlc_subpicture.h
@@ -192,6 +192,7 @@ struct subpicture_t
      * subtitle type. */
     /**@{*/
     bool         b_subtitle;            /**< the picture is a movie subtitle */
+    unsigned int i_spu_id;                    /**< use spu-specific settings */
     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/input/decoder.c b/src/input/decoder.c
index e5bc84d091..4cf593e2ce 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -140,6 +140,10 @@ struct decoder_owner
         sout_packetizer_input_t *p_sout_input;
     } cc;
 
+    /* The ID of the SPU this decoder is linked to, if any. Used to
+       manipulate the properties of subpictures created by this decoder */
+    int i_spu_id;
+
     /* Mouse event */
     vlc_mutex_t     mouse_lock;
     vlc_mouse_event mouse_event;
@@ -642,6 +646,7 @@ static subpicture_t *spu_new_buffer( decoder_t *p_dec,
         p_subpic->i_channel = p_owner->i_spu_channel;
         p_subpic->i_order = p_owner->i_spu_order++;
         p_subpic->b_subtitle = true;
+        p_subpic->i_spu_id = p_owner->i_spu_id;
     }
 
     return p_subpic;
@@ -1783,6 +1788,7 @@ static decoder_t * CreateDecoder( vlc_object_t *p_parent,
     p_owner->p_sout = p_sout;
     p_owner->p_sout_input = NULL;
     p_owner->p_packetizer = NULL;
+    p_owner->i_spu_id = 0;
 
     atomic_init( &p_owner->b_fmt_description, false );
     p_owner->p_description = NULL;
@@ -2367,6 +2373,15 @@ int input_DecoderGetCcState( decoder_t *p_dec, vlc_fourcc_t codec,
     return VLC_SUCCESS;
 }
 
+int input_DecoderSetSpuId( decoder_t *dec, unsigned int i_spu_id )
+{
+    struct decoder_owner *p_owner = dec_get_owner( dec );
+    assert( dec->fmt_in.i_cat == SPU_ES );
+
+    p_owner->i_spu_id = i_spu_id;
+    return VLC_SUCCESS;
+}
+
 void input_DecoderChangePause( decoder_t *p_dec, bool b_paused, vlc_tick_t i_date )
 {
     struct decoder_owner *p_owner = dec_get_owner( p_dec );
diff --git a/src/input/decoder.h b/src/input/decoder.h
index f9928edb45..ffe61bafb8 100644
--- a/src/input/decoder.h
+++ b/src/input/decoder.h
@@ -109,6 +109,12 @@ bool input_DecoderHasFormatChanged( decoder_t *p_dec, es_format_t *p_fmt, vlc_me
  */
 size_t input_DecoderGetFifoSize( decoder_t *p_dec );
 
+/**
+ * This function assigns the decoder to an SPU so that the correct properties
+ * can be applied (Alignment, margin, delay etc).
+ */
+int input_DecoderSetSpuId( decoder_t *dec, unsigned int i_spu_id );
+
 void input_DecoderSetVoutMouseEvent( decoder_t *, vlc_mouse_event, void * );
 int  input_DecoderAddVoutOverlay( decoder_t *, subpicture_t *, int * );
 int  input_DecoderFlushVoutOverlay( decoder_t *, int );
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 73088c87d4..dc14a970b6 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -2044,10 +2044,10 @@ static void EsOutUnselectEs( es_out_t *out, es_out_id_t *es, bool b_update )
  * \param i_cat the ES category (e.g. SPU_ES)
  * \return count
  */
-static int EsOutCountSelected( es_out_sys_t *p_sys,
+static unsigned int EsOutCountSelected( es_out_sys_t *p_sys,
                                enum es_format_category_e i_cat )
 {
-    int i_selected_count = 0;
+    unsigned int i_selected_count = 0;
     es_out_id_t *other;
     foreach_es_then_es_slaves(other)
         if( other->fmt.i_cat == i_cat && EsIsSelected( other ) )
@@ -2217,6 +2217,11 @@ static void EsOutSelect( es_out_t *out, es_out_id_t *es, bool b_force )
     if( p_esprops && p_sys->i_mode == ES_OUT_MODE_AUTO && EsIsSelected( es ) &&
         !b_select_secondary_subtitle )
         p_esprops->p_main_es = es;
+
+    if (es->fmt.i_cat == SPU_ES && es->p_dec)
+    {
+        input_DecoderSetSpuId( es->p_dec, EsOutCountSelected( p_sys, es->fmt.i_cat ) );
+    }
 }
 
 static void EsOutCreateCCChannels( es_out_t *out, vlc_fourcc_t codec, uint64_t i_bitmap,
-- 
2.11.0



More information about the vlc-devel mailing list