]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/duplicate.c
Remove useless test before free and delete.
[vlc] / modules / stream_out / duplicate.c
index f2d599558b923f26b628bb3f21c57b86359b9dc9..d923f9efa3a1221e68661bf0ef23897820864853 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
- * duplicate.c
+ * duplicate.c: duplicate stream output module
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: duplicate.c,v 1.9 2004/01/18 02:20:28 fenrir Exp $
+ * Copyright (C) 2003-2004 the VideoLAN team
+ * $Id$
  *
  * Author: Laurent Aimar <fenrir@via.ecp.fr>
  *
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>
-#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/sout.h>
+#include <vlc_sout.h>
+#include <vlc_block.h>
 
 /*****************************************************************************
- * Exported prototypes
+ * Module descriptor
  *****************************************************************************/
 static int      Open    ( vlc_object_t * );
 static void     Close   ( vlc_object_t * );
 
-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 *,
-                               sout_buffer_t* );
-
-/*****************************************************************************
- * Module descriptor
- *****************************************************************************/
 vlc_module_begin();
-    set_description( _("Duplicate stream") );
+    set_description( _("Duplicate stream output") );
     set_capability( "sout stream", 50 );
     add_shortcut( "duplicate" );
     add_shortcut( "dup" );
+    set_category( CAT_SOUT );
+    set_subcategory( SUBCAT_SOUT_STREAM );
     set_callbacks( Open, Close );
 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 *,
+                               block_t* );
+
 struct sout_stream_sys_t
 {
     int             i_nb_streams;
@@ -60,8 +65,6 @@ struct sout_stream_sys_t
 
     int             i_nb_select;
     char            **ppsz_select;
-
-    int             i_es;
 };
 
 struct sout_stream_id_t
@@ -70,7 +73,7 @@ struct sout_stream_id_t
     void                **pp_ids;
 };
 
-static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select, int i_es_number );
+static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select );
 
 /*****************************************************************************
  * Open:
@@ -79,7 +82,7 @@ static int Open( vlc_object_t *p_this )
 {
     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
     sout_stream_sys_t *p_sys;
-    sout_cfg_t        *p_cfg;
+    config_chain_t        *p_cfg;
 
     msg_Dbg( p_stream, "creating 'duplicate'" );
 
@@ -89,7 +92,6 @@ static int Open( vlc_object_t *p_this )
     p_sys->pp_streams   = NULL;
     p_sys->i_nb_select  = 0;
     p_sys->ppsz_select  = NULL;
-    p_sys->i_es         = 0;
 
     for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next )
     {
@@ -98,7 +100,7 @@ static int Open( vlc_object_t *p_this )
             sout_stream_t *s;
 
             msg_Dbg( p_stream, " * adding `%s'", p_cfg->psz_value );
-            s = sout_stream_new( p_stream->p_sout, p_cfg->psz_value );
+            s = sout_StreamNew( p_stream->p_sout, p_cfg->psz_value );
 
             if( s )
             {
@@ -137,7 +139,6 @@ static int Open( vlc_object_t *p_this )
 /*****************************************************************************
  * Close:
  *****************************************************************************/
-
 static void Close( vlc_object_t * p_this )
 {
     sout_stream_t     *p_stream = (sout_stream_t*)p_this;
@@ -145,23 +146,14 @@ static void Close( vlc_object_t * p_this )
 
     int i;
 
-    msg_Dbg( p_stream, "closing a duplication");
+    msg_Dbg( p_stream, "closing a duplication" );
     for( i = 0; i < p_sys->i_nb_streams; i++ )
     {
-        sout_stream_delete( p_sys->pp_streams[i] );
-        if( p_sys->ppsz_select[i] )
-        {
-            free( p_sys->ppsz_select[i] );
-        }
-    }
-    if( p_sys->pp_streams )
-    {
-        free( p_sys->pp_streams );
-    }
-    if( p_sys->ppsz_select )
-    {
-        free( p_sys->ppsz_select );
+        sout_StreamDelete( p_sys->pp_streams[i] );
+        free( p_sys->ppsz_select[i] );
     }
+    free( p_sys->pp_streams );
+    free( p_sys->ppsz_select );
 
     free( p_sys );
 }
@@ -180,14 +172,13 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     id->pp_ids   = NULL;
 
     msg_Dbg( p_stream, "duplicated a new stream codec=%4.4s (es=%d group=%d)",
-             (char*)&p_fmt->i_codec,
-             p_sys->i_es,
-             p_fmt->i_group );
+             (char*)&p_fmt->i_codec, p_fmt->i_id, p_fmt->i_group );
+
     for( i_stream = 0; i_stream < p_sys->i_nb_streams; i_stream++ )
     {
         void *id_new = NULL;
 
-        if( ESSelected( p_fmt, p_sys->ppsz_select[i_stream], p_sys->i_es ) )
+        if( ESSelected( p_fmt, p_sys->ppsz_select[i_stream] ) )
         {
             sout_stream_t *out = p_sys->pp_streams[i_stream];
 
@@ -212,8 +203,6 @@ static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt )
         TAB_APPEND( id->i_nb_ids, id->pp_ids, id_new );
     }
 
-    p_sys->i_es++;
-
     if( i_valid_streams <= 0 )
     {
         Del( p_stream, id );
@@ -249,7 +238,7 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
  * Send:
  *****************************************************************************/
 static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
-                 sout_buffer_t *p_buffer )
+                 block_t *p_buffer )
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
     sout_stream_t     *p_dup_stream;
@@ -258,18 +247,18 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
     /* Loop through the linked list of buffers */
     while( p_buffer )
     {
-        sout_buffer_t *p_next = p_buffer->p_next;
+        block_t *p_next = p_buffer->p_next;
 
         p_buffer->p_next = NULL;
 
         for( i_stream = 0; i_stream < p_sys->i_nb_streams - 1; i_stream++ )
         {
-            sout_buffer_t *p_dup;
+            block_t *p_dup;
             p_dup_stream = p_sys->pp_streams[i_stream];
 
             if( id->pp_ids[i_stream] )
             {
-                p_dup = sout_BufferDuplicate( p_stream->p_sout, p_buffer );
+                p_dup = block_Duplicate( p_buffer );
 
                 p_dup_stream->pf_send( p_dup_stream, id->pp_ids[i_stream],
                                        p_dup );
@@ -284,7 +273,7 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_t *id,
         }
         else
         {
-            sout_BufferDelete( p_stream->p_sout, p_buffer );
+            block_Release( p_buffer );
         }
 
         p_buffer = p_next;
@@ -317,12 +306,12 @@ static vlc_bool_t NumInRange( char *psz_range, int i_num )
     return i_start <= i_num && i_num <= i_stop ? VLC_TRUE : VLC_FALSE;
 }
 
-static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select, int i_es_number )
+static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select )
 {
     char  *psz_dup;
     char  *psz;
 
-    /* We have tree state variable : no tested (-1), failed(0), succeed(1) */
+    /* We have tri-state variable : no tested (-1), failed(0), succeed(1) */
     int i_cat = -1;
     int i_es  = -1;
     int i_prgm= -1;
@@ -367,47 +356,44 @@ static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select, int i_es_numbe
         if( !strncmp( psz, "no-audio", strlen( "no-audio" ) ) ||
             !strncmp( psz, "noaudio", strlen( "noaudio" ) ) )
         {
-            if( fmt->i_cat == AUDIO_ES )
+            if( i_cat == -1 )
             {
-                i_cat = 0;
-                break;
+                i_cat = fmt->i_cat != AUDIO_ES ? 1 : 0;
             }
         }
         else if( !strncmp( psz, "no-video", strlen( "no-video" ) ) ||
                  !strncmp( psz, "novideo", strlen( "novideo" ) ) )
         {
-            if( fmt->i_cat == VIDEO_ES )
+            if( i_cat == -1 )
             {
-                i_cat = 0;
-                break;
+                i_cat = fmt->i_cat != VIDEO_ES ? 1 : 0;
             }
         }
         else if( !strncmp( psz, "no-spu", strlen( "no-spu" ) ) ||
                  !strncmp( psz, "nospu", strlen( "nospu" ) ) )
         {
-            if( fmt->i_cat == SPU_ES )
+            if( i_cat == -1 )
             {
-                i_cat = 0;
-                break;
+                i_cat = fmt->i_cat != SPU_ES ? 1 : 0;
             }
         }
         else if( !strncmp( psz, "audio", strlen( "audio" ) ) )
         {
-            if( i_cat != 1 )
+            if( i_cat == -1 )
             {
                 i_cat = fmt->i_cat == AUDIO_ES ? 1 : 0;
             }
         }
         else if( !strncmp( psz, "video", strlen( "video" ) ) )
         {
-            if( i_cat != 1 )
+            if( i_cat == -1 )
             {
                 i_cat = fmt->i_cat == VIDEO_ES ? 1 : 0;
             }
         }
         else if( !strncmp( psz, "spu", strlen( "spu" ) ) )
         {
-            if( i_cat != 1 )
+            if( i_cat == -1 )
             {
                 i_cat = fmt->i_cat == SPU_ES ? 1 : 0;
             }
@@ -417,35 +403,33 @@ static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select, int i_es_numbe
             char *psz_arg = strchr( psz, '=' );
             *psz_arg++ = '\0';
 
-            if( !strcmp( psz, "no-es" ) || !strcmp( psz, "es" ) )
+            if( !strcmp( psz, "no-es" ) || !strcmp( psz, "noes" ) )
             {
-                if( !NumInRange( psz_arg, i_es_number ) )
+                if( i_es == -1 )
                 {
-                    i_es = 0;
-                    break;
+                    i_es = NumInRange( psz_arg, fmt->i_id ) ? 0 : -1;
                 }
             }
             else if( !strcmp( psz, "es" ) )
             {
-                if( i_es != 1 )
+                if( i_es == -1 )
                 {
-                    i_es = NumInRange( psz_arg, i_es_number ) ? 1 : 0;
+                    i_es = NumInRange( psz_arg, fmt->i_id) ? 1 : -1;
                 }
             }
             else if( !strcmp( psz, "no-prgm" ) || !strcmp( psz, "noprgm" ) ||
                       !strcmp( psz, "no-program" ) || !strcmp( psz, "noprogram" ) )
             {
-                if( fmt->i_group >= 0 && !NumInRange( psz_arg, fmt->i_group ) )
+                if( fmt->i_group >= 0 && i_prgm == -1 )
                 {
-                    i_prgm = 0;
-                    break;
+                    i_prgm = NumInRange( psz_arg, fmt->i_group ) ? 0 : -1;
                 }
             }
-            else if( !strcmp( psz, "program" ) || !strcmp( psz, "program" ) )
+            else if( !strcmp( psz, "prgm" ) || !strcmp( psz, "program" ) )
             {
-                if( fmt->i_group >= 0 && i_prgm != 1 )
+                if( fmt->i_group >= 0 && i_prgm == -1 )
                 {
-                    i_prgm = NumInRange( psz_arg, fmt->i_group ) ? 1 : 0;
+                    i_prgm = NumInRange( psz_arg, fmt->i_group ) ? 1 : -1;
                 }
             }
         }
@@ -459,12 +443,9 @@ static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select, int i_es_numbe
 
     free( psz_dup );
 
-    if( i_cat == 0 || i_es == 0 || i_prgm == 0 )
+    if( i_cat == 1 || i_es == 1 || i_prgm == 1 )
     {
-        /* One test failed */
-        return VLC_FALSE;
+        return VLC_TRUE;
     }
-    return VLC_TRUE;
+    return VLC_FALSE;
 }
-
-