[vlc-devel] [PATCH 1/3] chromecast: use a local sout_stream_id_sys_t containing the es_format_t

Steve Lhomme robux4 at videolabs.io
Tue Apr 26 10:56:26 CEST 2016


--
replaces https://patches.videolan.org/patch/13077/ with no lock
---
 modules/stream_out/chromecast/cast.cpp | 59 ++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/modules/stream_out/chromecast/cast.cpp b/modules/stream_out/chromecast/cast.cpp
index d05ca1c..4a244f8 100644
--- a/modules/stream_out/chromecast/cast.cpp
+++ b/modules/stream_out/chromecast/cast.cpp
@@ -54,6 +54,10 @@ struct sout_stream_sys_t
     sout_stream_t * const p_out;
     intf_sys_t * const p_intf;
     const bool b_has_video;
+
+    sout_stream_id_sys_t *GetSubId( sout_stream_t*, sout_stream_id_sys_t* );
+
+    std::vector<sout_stream_id_sys_t*> streams;
 };
 
 #define SOUT_CFG_PREFIX "sout-chromecast-"
@@ -100,6 +104,12 @@ vlc_module_begin ()
 vlc_module_end ()
 
 
+struct sout_stream_id_sys_t
+{
+    es_format_t           fmt;
+    sout_stream_id_sys_t  *p_sub_id;
+};
+
 /*****************************************************************************
  * Sout callbacks
  *****************************************************************************/
@@ -112,7 +122,16 @@ static sout_stream_id_sys_t *Add(sout_stream_t *p_stream, const es_format_t *p_f
         if (p_fmt->i_cat != AUDIO_ES)
             return NULL;
     }
-    return sout_StreamIdAdd(p_sys->p_out, p_fmt);
+
+    sout_stream_id_sys_t *p_sys_id = (sout_stream_id_sys_t *)malloc( sizeof(sout_stream_id_sys_t) );
+    if (p_sys_id != NULL)
+    {
+        es_format_Copy( &p_sys_id->fmt, p_fmt );
+        p_sys_id->p_sub_id = NULL;
+
+        p_sys->streams.push_back( p_sys_id );
+    }
+    return p_sys_id;
 }
 
 
@@ -120,15 +139,47 @@ static void Del(sout_stream_t *p_stream, sout_stream_id_sys_t *id)
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
 
-    sout_StreamIdDel(p_sys->p_out, id);
+    for (size_t i=0; i<p_sys->streams.size(); i++)
+    {
+        if ( p_sys->streams[i] == id )
+        {
+            if ( p_sys->streams[i]->p_sub_id != NULL )
+                sout_StreamIdDel( p_sys->p_out, p_sys->streams[i]->p_sub_id );
+
+            es_format_Clean( &p_sys->streams[i]->fmt );
+            free( p_sys->streams[i] );
+            p_sys->streams.erase( p_sys->streams.begin() +  i );
+            break;
+        }
+    }
 }
 
+sout_stream_id_sys_t *sout_stream_sys_t::GetSubId( sout_stream_t *p_stream,
+                                                   sout_stream_id_sys_t *id )
+{
+    size_t i;
+
+    assert( p_stream->p_sys == this );
+
+    for (i = 0; i < streams.size(); ++i)
+    {
+        if ( id == (sout_stream_id_sys_t*) streams[i] )
+            return streams[i]->p_sub_id;
+    }
+
+    msg_Err( p_stream, "unknown stream ID" );
+    return NULL;
+}
 
 static int Send(sout_stream_t *p_stream, sout_stream_id_sys_t *id,
                 block_t *p_buffer)
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
 
+    id = p_sys->GetSubId( p_stream, id );
+    if ( id == NULL )
+        return VLC_EGENERIC;
+
     return sout_StreamIdSend(p_sys->p_out, id, p_buffer);
 }
 
@@ -136,6 +187,10 @@ static void Flush( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
 
+    id = p_sys->GetSubId( p_stream, id );
+    if ( id == NULL )
+        return;
+
     sout_StreamFlush( p_sys->p_out, id );
 }
 
-- 
2.7.0



More information about the vlc-devel mailing list