[vlc-devel] [PATCH] es_out: get the aout or the vout from a vlc_es_id_t

Thomas Guillem thomas at gllm.fr
Fri Oct 19 14:19:25 CEST 2018


Useful when multiple video ESes are selected, in order to do an action on one
specific vout.

This could be used by the future player API.
---
 include/vlc_es.h   | 23 +++++++++++++++++++++++
 src/input/es_out.c | 37 ++++++++++++++++++++++++++++++++++++-
 src/libvlccore.sym |  2 ++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/include/vlc_es.h b/include/vlc_es.h
index c32fddb096..c0f4f85c15 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -717,4 +717,27 @@ vlc_es_id_GetInputId(vlc_es_id_t *id);
 VLC_API enum es_format_category_e
 vlc_es_id_GetCat(vlc_es_id_t *id);
 
+/**
+ * Get the Vout used by this ES
+ *
+ * @param id pointer to the ES track id
+ *
+ * @return a valid Vout (to release with vlc_oject_release()) or NULL (if the
+ * ES is not selected, if it's not a VIDEO_ES or if the vout is not (yet)
+ * created).
+ */
+VLC_API vout_thread_t * vlc_es_id_GetVout(vlc_es_id_t *id);
+
+/**
+ * Get the Aout used by this ES
+ *
+ * @param id pointer to the ES track id
+ *
+ * @return a valid Aout (to release with vlc_oject_release()) or NULL (if the
+ * ES is not selected, if it's not a AUDIO_ES or if the aout is not (yet)
+ * created).
+ */
+VLC_API audio_output_t *
+vlc_es_id_GetAout(vlc_es_id_t *id);
+
 #endif
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 98f71b3ec0..a772934ce2 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -112,6 +112,7 @@ struct es_out_id_t
     char        *psz_title;
     bool        b_terminated;
 
+    vlc_mutex_t dec_lock;
     decoder_t   *p_dec;
     decoder_t   *p_dec_record;
 
@@ -407,6 +408,7 @@ static void EsRelease(es_out_id_t *es)
         free(es->psz_language);
         free(es->psz_language_code);
         es_format_Clean(&es->fmt);
+        vlc_mutex_destroy(&es->dec_lock);
         free(es);
     }
 }
@@ -1689,6 +1691,7 @@ static es_out_id_t *EsOutAddSlaveLocked( es_out_t *out, const es_format_t *fmt,
 
     vlc_list_append(&es->node, es->p_master ? &p_sys->es_slaves : &p_sys->es);
 
+    vlc_mutex_init(&es->dec_lock);
     vlc_atomic_rc_init(&es->rc);
 
     if( es->p_pgrm == p_sys->p_pgrm )
@@ -1761,7 +1764,9 @@ static void EsOutCreateDecoder( es_out_t *out, es_out_id_t *p_es )
             input_DecoderSetVoutMouseEvent( dec, p_es->mouse_event_cb,
                                             p_es->mouse_event_userdata );
     }
+    vlc_mutex_lock(&p_es->dec_lock);
     p_es->p_dec = dec;
+    vlc_mutex_unlock(&p_es->dec_lock);
 
     EsOutDecoderChangeDelay( out, p_es );
 }
@@ -1772,8 +1777,12 @@ static void EsOutDestroyDecoder( es_out_t *out, es_out_id_t *p_es )
     if( !p_es->p_dec )
         return;
 
-    input_DecoderDelete( p_es->p_dec );
+    decoder_t *p_dec = p_es->p_dec;
+    vlc_mutex_lock( &p_es->dec_lock );
     p_es->p_dec = NULL;
+    vlc_mutex_unlock( &p_es->dec_lock );
+
+    input_DecoderDelete( p_dec );
 
     if( p_es->p_dec_record )
     {
@@ -3665,3 +3674,29 @@ vlc_es_id_GetCat(vlc_es_id_t *id)
 {
     return id->i_cat;
 }
+
+vout_thread_t *
+vlc_es_id_GetVout(vlc_es_id_t *id)
+{
+    es_out_id_t *es = vlc_es_id_get_out(id);
+
+    vlc_mutex_lock(&es->dec_lock);
+    vout_thread_t *vout = NULL;
+    if (es->p_dec)
+        input_DecoderGetObjects(es->p_dec, &vout, NULL);
+    vlc_mutex_unlock(&es->dec_lock);
+    return vout;
+}
+
+audio_output_t *
+vlc_es_id_GetAout(vlc_es_id_t *id)
+{
+    es_out_id_t *es = vlc_es_id_get_out(id);
+
+    vlc_mutex_lock(&es->dec_lock);
+    audio_output_t *aout = NULL;
+    if (es->p_dec)
+        input_DecoderGetObjects(es->p_dec, NULL, &aout);
+    vlc_mutex_unlock(&es->dec_lock);
+    return aout;
+}
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index a4ba469b14..bf3d341abe 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -785,3 +785,5 @@ vlc_es_id_Hold
 vlc_es_id_Release
 vlc_es_id_GetInputId
 vlc_es_id_GetCat
+vlc_es_id_GetAout
+vlc_es_id_GetVout
-- 
2.19.1



More information about the vlc-devel mailing list