[vlc-devel] [PATCH 06/16] Add spu_id property to decoder

Roland Bewick roland.bewick at gmail.com
Tue May 21 20:08:30 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       | 25 +++++++++++++++++++++++++
 4 files changed, 47 insertions(+)

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..023f487ed7 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 */
+    unsigned 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 933249c39b..5f0deae46d 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -242,6 +242,7 @@ static int LanguageArrayIndex( char **ppsz_langs, const char *psz_lang );
 
 static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm );
 static char *EsInfoCategoryName( es_out_id_t* es );
+static unsigned int EsOutCountSelected( es_out_sys_t *p_sys, enum es_format_category_e i_cat );
 
 static inline int EsOutGetClosedCaptionsChannel( const es_format_t *p_fmt )
 {
@@ -1963,6 +1964,12 @@ static void EsOutSelectEs( es_out_t *out, es_out_id_t *es )
         input_SendEventVbiTransparency( p_input,
                                         var_GetBool( es->p_dec, "vbi-opaque" ) );
     }
+
+    if (es->fmt.i_cat == SPU_ES)
+    {
+        input_DecoderSetSpuId( es->p_dec,
+                               EsOutCountSelected( p_sys, es->fmt.i_cat ) );
+    }
 }
 
 static void EsOutDrainCCChannels( es_out_id_t *parent )
@@ -2039,6 +2046,24 @@ static void EsOutUnselectEs( es_out_t *out, es_out_id_t *es, bool b_update )
 }
 
 /**
+ * Count the number of selected ES of the given category
+ * \param i_cat the ES category (e.g. SPU_ES)
+ * \return count
+ */
+static unsigned int EsOutCountSelected( es_out_sys_t *p_sys,
+                                        enum es_format_category_e i_cat )
+{
+    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 ) )
+        {
+            ++i_selected_count;
+        }
+    return i_selected_count;
+}
+
+/**
  * Select an ES given the current mode
  * XXX: you need to take a the lock before (stream.stream_lock)
  *
-- 
2.11.0



More information about the vlc-devel mailing list