]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/duplicate.c
vpx: fix leak
[vlc] / modules / stream_out / duplicate.c
index 852327a0817a1dcb6e2af97bf11d5e51af40c440..e51d9c169313e9f4f14e4f1cd17586f7d5115156 100644 (file)
@@ -6,19 +6,19 @@
  *
  * Author: Laurent Aimar <fenrir@via.ecp.fr>
  *
- * 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -43,8 +43,7 @@ static void     Close   ( vlc_object_t * );
 vlc_module_begin ()
     set_description( N_("Duplicate stream output") )
     set_capability( "sout stream", 50 )
-    add_shortcut( "duplicate" )
-    add_shortcut( "dup" )
+    add_shortcut( "duplicate", "dup" )
     set_category( CAT_SOUT )
     set_subcategory( SUBCAT_SOUT_STREAM )
     set_callbacks( Open, Close )
@@ -54,9 +53,9 @@ vlc_module_end ()
 /*****************************************************************************
  * Exported prototypes
  *****************************************************************************/
-static sout_stream_id_t *Add ( sout_stream_t *, es_format_t * );
-static int               Del ( sout_stream_t *, sout_stream_id_t * );
-static int               Send( sout_stream_t *, sout_stream_id_t *,
+static sout_stream_id_sys_t *Add( sout_stream_t *, const es_format_t * );
+static void              Del ( sout_stream_t *, sout_stream_id_sys_t * );
+static int               Send( sout_stream_t *, sout_stream_id_sys_t *,
                                block_t* );
 
 struct sout_stream_sys_t
@@ -64,17 +63,20 @@ struct sout_stream_sys_t
     int             i_nb_streams;
     sout_stream_t   **pp_streams;
 
+    int             i_nb_last_streams;
+    sout_stream_t   **pp_last_streams;
+
     int             i_nb_select;
     char            **ppsz_select;
 };
 
-struct sout_stream_id_t
+struct sout_stream_id_sys_t
 {
     int                 i_nb_ids;
     void                **pp_ids;
 };
 
-static bool ESSelected( es_format_t *fmt, char *psz_select );
+static bool ESSelected( const es_format_t *fmt, char *psz_select );
 
 /*****************************************************************************
  * Open:
@@ -92,20 +94,24 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
 
     TAB_INIT( p_sys->i_nb_streams, p_sys->pp_streams );
+    TAB_INIT( p_sys->i_nb_last_streams, p_sys->pp_last_streams );
     TAB_INIT( p_sys->i_nb_select, p_sys->ppsz_select );
 
     for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
     {
         if( !strncmp( p_cfg->psz_name, "dst", strlen( "dst" ) ) )
         {
-            sout_stream_t *s;
+            sout_stream_t *s, *p_last;
 
             msg_Dbg( p_stream, " * adding `%s'", p_cfg->psz_value );
-            s = sout_StreamNew( p_stream->p_sout, p_cfg->psz_value );
+            s = sout_StreamChainNew( p_stream->p_sout, p_cfg->psz_value,
+                p_stream->p_next, &p_last );
 
             if( s )
             {
                 TAB_APPEND( p_sys->i_nb_streams, p_sys->pp_streams, s );
+                TAB_APPEND( p_sys->i_nb_last_streams, p_sys->pp_last_streams,
+                    p_last );
                 TAB_APPEND( p_sys->i_nb_select,  p_sys->ppsz_select, NULL );
             }
         }
@@ -164,10 +170,11 @@ static void Close( vlc_object_t * p_this )
     msg_Dbg( p_stream, "closing a duplication" );
     for( i = 0; i < p_sys->i_nb_streams; i++ )
     {
-        sout_StreamDelete( p_sys->pp_streams[i] );
+        sout_StreamChainDelete(p_sys->pp_streams[i], p_sys->pp_last_streams[i]);
         free( p_sys->ppsz_select[i] );
     }
     free( p_sys->pp_streams );
+    free( p_sys->pp_last_streams );
     free( p_sys->ppsz_select );
 
     free( p_sys );
@@ -176,13 +183,13 @@ static void Close( vlc_object_t * p_this )
 /*****************************************************************************
  * Add:
  *****************************************************************************/
-static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
+static sout_stream_id_sys_t * Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
-    sout_stream_id_t  *id;
+    sout_stream_id_sys_t  *id;
     int i_stream, i_valid_streams = 0;
 
-    id = malloc( sizeof( sout_stream_id_t ) );
+    id = malloc( sizeof( sout_stream_id_sys_t ) );
     if( !id )
         return NULL;
 
@@ -232,7 +239,7 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
 /*****************************************************************************
  * Del:
  *****************************************************************************/
-static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
+static void Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     int               i_stream;
@@ -248,13 +255,12 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
 
     free( id->pp_ids );
     free( id );
-    return VLC_SUCCESS;
 }
 
 /*****************************************************************************
  * Send:
  *****************************************************************************/
-static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
+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;
@@ -301,28 +307,17 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
  *****************************************************************************/
 static bool NumInRange( const char *psz_range, int i_num )
 {
-    const char *psz = strchr( psz_range, '-' );
-    char *end;
-    int  i_start, i_stop;
-
-    i_start = strtol( psz_range, &end, 0 );
-    if( end == psz_range )
-        i_start = i_num;
-
-    if( psz )
-    {
-        psz++;
-        i_stop = strtol( psz, &end, 0 );
-        if( end == psz )
-            i_stop = i_num;
-    }
-    else
-        i_stop = i_start;
-
-    return i_start <= i_num && i_num <= i_stop;
+    int beginRange, endRange;
+    int res = sscanf(psz_range, "%d-%d", &beginRange, &endRange);
+    if (res == 0)
+        return false;
+    else if (res == 1)
+        return beginRange == i_num;
+    return (i_num >= beginRange && i_num <= endRange)
+        || (beginRange > endRange && (i_num <= beginRange && i_num >= endRange));
 }
 
-static bool ESSelected( es_format_t *fmt, char *psz_select )
+static bool ESSelected( const es_format_t *fmt, char *psz_select )
 {
     char  *psz_dup;
     char  *psz;