]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/bridge.c
sout: voidify sout_stream_t.pf_del
[vlc] / modules / stream_out / bridge.c
index 21fde166e70c9e6b0bac5cb9084ccb534a6a5ea7..3999bae94a60c13262e0e2f12cc241554b2bf4dc 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * bridge.c: bridge stream output module
  *****************************************************************************
- * Copyright (C) 2005-2008 the VideoLAN team
+ * Copyright (C) 2005-2008 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *          Antoine Cellerier <dionoea at videolan dot org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -73,7 +73,7 @@
 #define PLACEHOLDER_DELAY_LONGTEXT N_( \
     "Delay (in ms) before the placeholder kicks in." )
 
-#define PLACEHOLDER_IFRAME_TEXT N_( "Wait for I frame before toggling placholder" )
+#define PLACEHOLDER_IFRAME_TEXT N_( "Wait for I frame before toggling placeholder" )
 #define PLACEHOLDER_IFRAME_LONGTEXT N_( \
     "If enabled, switching between the placeholder and the normal stream " \
     "will only occur on I frames. This will remove artifacts on stream " \
@@ -98,7 +98,7 @@ vlc_module_begin ()
     /* Only usable with VLM. No category so not in gui preferences
     set_category( CAT_SOUT )
     set_subcategory( SUBCAT_SOUT_STREAM )*/
-    add_integer( SOUT_CFG_PREFIX_OUT "id", 0, NULL, ID_TEXT, ID_LONGTEXT,
+    add_integer( SOUT_CFG_PREFIX_OUT "id", 0, ID_TEXT, ID_LONGTEXT,
                  false )
     add_string( SOUT_CFG_PREFIX_OUT "in-name", "default",
                 DEST_TEXT, DEST_LONGTEXT, false )
@@ -110,17 +110,17 @@ vlc_module_begin ()
     add_shortcut( "bridge-in" )
     /*set_category( CAT_SOUT )
     set_subcategory( SUBCAT_SOUT_STREAM )*/
-    add_integer( SOUT_CFG_PREFIX_IN "delay", 0, NULL, DELAY_TEXT,
+    add_integer( SOUT_CFG_PREFIX_IN "delay", 0, DELAY_TEXT,
                  DELAY_LONGTEXT, false )
-    add_integer( SOUT_CFG_PREFIX_IN "id-offset", 8192, NULL, ID_OFFSET_TEXT,
+    add_integer( SOUT_CFG_PREFIX_IN "id-offset", 8192, ID_OFFSET_TEXT,
                  ID_OFFSET_LONGTEXT, false )
     add_string( SOUT_CFG_PREFIX_IN "name", "default",
                 NAME_TEXT, NAME_LONGTEXT, false )
-    add_bool( SOUT_CFG_PREFIX_IN "placeholder", false, NULL,
+    add_bool( SOUT_CFG_PREFIX_IN "placeholder", false,
               PLACEHOLDER_TEXT, PLACEHOLDER_LONGTEXT, false )
-    add_integer( SOUT_CFG_PREFIX_IN "placeholder-delay", 200, NULL,
+    add_integer( SOUT_CFG_PREFIX_IN "placeholder-delay", 200,
                  PLACEHOLDER_DELAY_TEXT, PLACEHOLDER_DELAY_LONGTEXT, false )
-    add_bool( SOUT_CFG_PREFIX_IN "placeholder-switch-on-iframe", true, NULL,
+    add_bool( SOUT_CFG_PREFIX_IN "placeholder-switch-on-iframe", true,
               PLACEHOLDER_IFRAME_TEXT, PLACEHOLDER_IFRAME_LONGTEXT, false )
     set_callbacks( OpenIn, CloseIn )
 
@@ -140,13 +140,13 @@ static const char *const ppsz_sout_options_in[] = {
     NULL
 };
 
-static sout_stream_id_t *AddOut ( sout_stream_t *, es_format_t * );
-static int               DelOut ( sout_stream_t *, sout_stream_id_t * );
-static int               SendOut( sout_stream_t *, sout_stream_id_t *, block_t * );
+static sout_stream_id_sys_t *AddOut ( sout_stream_t *, es_format_t * );
+static void              DelOut ( sout_stream_t *, sout_stream_id_sys_t * );
+static int               SendOut( sout_stream_t *, sout_stream_id_sys_t *, block_t * );
 
-static sout_stream_id_t *AddIn ( sout_stream_t *, es_format_t * );
-static int               DelIn ( sout_stream_t *, sout_stream_id_t * );
-static int               SendIn( sout_stream_t *, sout_stream_id_t *, block_t * );
+static sout_stream_id_sys_t *AddIn ( sout_stream_t *, es_format_t * );
+static void              DelIn ( sout_stream_t *, sout_stream_id_sys_t * );
+static int               SendIn( sout_stream_t *, sout_stream_id_sys_t *, block_t * );
 
 typedef struct bridged_es_t
 {
@@ -156,7 +156,7 @@ typedef struct bridged_es_t
     bool b_empty;
 
     /* bridge in part */
-    sout_stream_id_t *id;
+    sout_stream_id_sys_t *id;
     mtime_t i_last;
     bool b_changed;
 } bridged_es_t;
@@ -167,6 +167,7 @@ typedef struct bridge_t
     int i_es_num;
 } bridge_t;
 
+static vlc_mutex_t lock = VLC_STATIC_MUTEX;
 
 /*
  * Bridge out
@@ -174,7 +175,6 @@ typedef struct bridge_t
 
 typedef struct out_sout_stream_sys_t
 {
-    vlc_mutex_t *p_lock;
     bridged_es_t *p_es;
     int i_id;
     bool b_inited;
@@ -199,10 +199,6 @@ static int OpenOut( vlc_object_t *p_this )
         return VLC_ENOMEM;
     p_sys->b_inited = false;
 
-    var_Create( p_this->p_libvlc, "bridge-lock", VLC_VAR_MUTEX );
-    var_Get( p_this->p_libvlc, "bridge-lock", &val );
-    p_sys->p_lock = val.p_address;
-
     var_Get( p_stream, SOUT_CFG_PREFIX_OUT "id", &val );
     p_sys->i_id = val.i_int;
 
@@ -220,8 +216,7 @@ static int OpenOut( vlc_object_t *p_this )
     p_stream->pf_send   = SendOut;
 
     p_stream->p_sys     = (sout_stream_sys_t *)p_sys;
-
-    p_stream->p_sout->i_out_pace_nocontrol++;
+    p_stream->pace_nocontrol = true;
 
     return VLC_SUCCESS;
 }
@@ -234,13 +229,11 @@ static void CloseOut( vlc_object_t * p_this )
     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
 
-    p_stream->p_sout->i_out_pace_nocontrol--;
-
     free( p_sys->psz_name );
     free( p_sys );
 }
 
-static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt )
+static sout_stream_id_sys_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt )
 {
     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
     bridge_t *p_bridge;
@@ -254,7 +247,7 @@ static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt )
     }
     p_sys->b_inited = true;
 
-    vlc_mutex_lock( p_sys->p_lock );
+    vlc_mutex_lock( &lock );
 
     p_bridge = var_GetAddress( p_stream->p_libvlc, p_sys->psz_name );
     if ( p_bridge == NULL )
@@ -297,23 +290,21 @@ static sout_stream_id_t * AddOut( sout_stream_t *p_stream, es_format_t *p_fmt )
     msg_Dbg( p_stream, "bridging out input codec=%4.4s id=%d pos=%d",
              (char*)&p_es->fmt.i_codec, p_es->fmt.i_id, i );
 
-    vlc_mutex_unlock( p_sys->p_lock );
+    vlc_mutex_unlock( &lock );
 
-    return (sout_stream_id_t *)p_sys;
+    return (sout_stream_id_sys_t *)p_sys;
 }
 
-static int DelOut( sout_stream_t *p_stream, sout_stream_id_t *id )
+static void DelOut( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     VLC_UNUSED(id);
     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
     bridged_es_t *p_es;
 
     if ( !p_sys->b_inited )
-    {
-        return VLC_SUCCESS;
-    }
+        return;
 
-    vlc_mutex_lock( p_sys->p_lock );
+    vlc_mutex_lock( &lock );
 
     p_es = p_sys->p_es;
 
@@ -322,14 +313,12 @@ static int DelOut( sout_stream_t *p_stream, sout_stream_id_t *id )
     p_es->p_block = false;
 
     p_es->b_changed = true;
-    vlc_mutex_unlock( p_sys->p_lock );
+    vlc_mutex_unlock( &lock );
 
     p_sys->b_inited = false;
-
-    return VLC_SUCCESS;
 }
 
-static int SendOut( sout_stream_t *p_stream, sout_stream_id_t *id,
+static int SendOut( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
                     block_t *p_buffer )
 {
     out_sout_stream_sys_t *p_sys = (out_sout_stream_sys_t *)p_stream->p_sys;
@@ -341,7 +330,7 @@ static int SendOut( sout_stream_t *p_stream, sout_stream_id_t *id,
         return VLC_SUCCESS;
     }
 
-    vlc_mutex_lock( p_sys->p_lock );
+    vlc_mutex_lock( &lock );
 
     p_es = p_sys->p_es;
     *p_es->pp_last = p_buffer;
@@ -351,7 +340,7 @@ static int SendOut( sout_stream_t *p_stream, sout_stream_id_t *id,
         p_buffer = p_buffer->p_next;
     }
 
-    vlc_mutex_unlock( p_sys->p_lock );
+    vlc_mutex_unlock( &lock );
 
     return VLC_SUCCESS;
 }
@@ -363,7 +352,6 @@ static int SendOut( sout_stream_t *p_stream, sout_stream_id_t *id,
 
 typedef struct in_sout_stream_sys_t
 {
-    vlc_mutex_t *p_lock;
     int i_id_offset;
     mtime_t i_delay;
 
@@ -373,9 +361,9 @@ typedef struct in_sout_stream_sys_t
     bool b_switch_on_iframe;
     int i_state;
     mtime_t i_placeholder_delay;
-    sout_stream_id_t *id_video;
+    sout_stream_id_sys_t *id_video;
     mtime_t i_last_video;
-    sout_stream_id_t *id_audio;
+    sout_stream_id_sys_t *id_audio;
     mtime_t i_last_audio;
 } in_sout_stream_sys_t;
 
@@ -404,10 +392,6 @@ static int OpenIn( vlc_object_t *p_this )
     config_ChainParse( p_stream, SOUT_CFG_PREFIX_IN, ppsz_sout_options_in,
                    p_stream->p_cfg );
 
-    var_Create( p_this->p_libvlc, "bridge-lock", VLC_VAR_MUTEX );
-    var_Get( p_this->p_libvlc, "bridge-lock", &val );
-    p_sys->p_lock = val.p_address;
-
     var_Get( p_stream, SOUT_CFG_PREFIX_IN "id-offset", &val );
     p_sys->i_id_offset = val.i_int;
 
@@ -444,9 +428,7 @@ static int OpenIn( vlc_object_t *p_this )
     p_stream->pf_send   = SendIn;
 
     p_stream->p_sys     = (sout_stream_sys_t *)p_sys;
-
-    /* update p_sout->i_out_pace_nocontrol */
-    p_stream->p_sout->i_out_pace_nocontrol++;
+    p_stream->pace_nocontrol = true;
 
     return VLC_SUCCESS;
 }
@@ -459,23 +441,21 @@ static void CloseIn( vlc_object_t * p_this )
     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
 
-    p_stream->p_sout->i_out_pace_nocontrol--;
-
     free( p_sys->psz_name );
     free( p_sys );
 }
 
-struct sout_stream_id_t
+struct sout_stream_id_sys_t
 {
-    sout_stream_id_t *id;
+    sout_stream_id_sys_t *id;
     int i_cat; /* es category. Used for placeholder option */
 };
 
-static sout_stream_id_t * AddIn( sout_stream_t *p_stream, es_format_t *p_fmt )
+static sout_stream_id_sys_t * AddIn( sout_stream_t *p_stream, es_format_t *p_fmt )
 {
     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
 
-    sout_stream_id_t *id = malloc( sizeof( sout_stream_id_t ) );
+    sout_stream_id_sys_t *id = malloc( sizeof( sout_stream_id_sys_t ) );
     if( !id ) return NULL;
 
     id->id = p_stream->p_next->pf_add( p_stream->p_next, p_fmt );
@@ -506,20 +486,18 @@ static sout_stream_id_t * AddIn( sout_stream_t *p_stream, es_format_t *p_fmt )
     return id;
 }
 
-static int DelIn( sout_stream_t *p_stream, sout_stream_id_t *id )
+static void DelIn( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
 
     if( id == p_sys->id_video ) p_sys->id_video = NULL;
     if( id == p_sys->id_audio ) p_sys->id_audio = NULL;
 
-    int ret = p_stream->p_next->pf_del( p_stream->p_next, id->id );
-
+    p_stream->p_next->pf_del( p_stream->p_next, id->id );
     free( id );
-    return ret;
 }
 
-static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
+static int SendIn( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
                    block_t *p_buffer )
 {
     in_sout_stream_sys_t *p_sys = (in_sout_stream_sys_t *)p_stream->p_sys;
@@ -533,7 +511,7 @@ static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
         p_stream->p_next->pf_send( p_stream->p_next, id->id, p_buffer );
 
     /* Then check all bridged streams */
-    vlc_mutex_lock( p_sys->p_lock );
+    vlc_mutex_lock( &lock );
 
     p_bridge = var_GetAddress( p_stream->p_libvlc, p_sys->psz_name );
 
@@ -624,7 +602,7 @@ static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
                 p_block->i_dts += p_sys->i_delay;
                 p_block = p_block->p_next;
             }
-            sout_stream_id_t *newid = NULL;
+            sout_stream_id_sys_t *newid = NULL;
             if( p_sys->b_placeholder )
             {
                 switch( p_bridge->pp_es[i]->fmt.i_cat )
@@ -711,7 +689,7 @@ static int SendIn( sout_stream_t *p_stream, sout_stream_id_t *id,
         }
     }
 
-    vlc_mutex_unlock( p_sys->p_lock );
+    vlc_mutex_unlock( &lock );
 
     return VLC_SUCCESS;
 }