]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/copy.c
Include vlc_plugin.h as needed
[vlc] / modules / packetizer / copy.c
index 7e7108de3e5829d22db58a9e6f0f8b6c51964f23..8f7cb2f35cadaf93f9dc8a3c98bbe4b049ba60f4 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * copy.c
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: copy.c,v 1.23 2004/01/25 17:58:30 murray Exp $
+ * Copyright (C) 2001, 2002, 2006 the VideoLAN team
+ * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Eric Petit <titer@videolan.org>
  *
  * 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>                                      /* malloc(), free() */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include <vlc/input.h>
+#include <vlc_plugin.h>
+#include <vlc_codec.h>
+#include <vlc_block.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -38,6 +42,8 @@ static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
 vlc_module_begin();
+    set_category( CAT_SOUT );
+    set_subcategory( SUBCAT_SOUT_PACKETIZER );
     set_description( _("Copy packetizer") );
     set_capability( "packetizer", 1 );
     set_callbacks( Open, Close );
@@ -51,7 +57,8 @@ struct decoder_sys_t
     block_t *p_block;
 };
 
-static block_t *Packetize ( decoder_t *, block_t ** );
+static block_t *Packetize   ( decoder_t *, block_t ** );
+static block_t *PacketizeSub( decoder_t *, block_t ** );
 
 /*****************************************************************************
  * Open: probe the packetizer and return score
@@ -72,16 +79,13 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    p_dec->pf_packetize = Packetize;
+    if( p_dec->fmt_in.i_cat == SPU_ES )
+        p_dec->pf_packetize = PacketizeSub;
+    else
+        p_dec->pf_packetize = Packetize;
 
     /* Create the output format */
-    memcpy( &p_dec->fmt_out, &p_dec->fmt_in, sizeof( es_format_t ) );
-    if( p_dec->fmt_in.i_extra > 0 )
-    {
-        p_dec->fmt_out.p_extra = malloc( p_dec->fmt_in.i_extra );
-        memcpy( p_dec->fmt_out.p_extra, p_dec->fmt_in.p_extra,
-                p_dec->fmt_in.i_extra );
-    }
+    es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
 
     /* Fix the value of the fourcc */
     switch( p_dec->fmt_in.i_codec )
@@ -243,11 +247,12 @@ static void Close( vlc_object_t *p_this )
         block_ChainRelease( p_dec->p_sys->p_block );
     }
 
+    es_format_Clean( &p_dec->fmt_out );
     free( p_dec->p_sys );
 }
 
 /*****************************************************************************
- * PacketizeStd: packetize an unit (here copy a complete block )
+ * Packetize: packetize an unit (here copy a complete block )
  *****************************************************************************/
 static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
 {
@@ -255,24 +260,24 @@ static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
     block_t *p_ret = p_dec->p_sys->p_block;
 
     if( pp_block == NULL || *pp_block == NULL )
+        return NULL;
+    if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
     {
+        block_Release( *pp_block );
         return NULL;
     }
+
     p_block = *pp_block;
     *pp_block = NULL;
 
-    if( p_block->i_pts <= 0 )
-    {
-        p_block->i_pts = p_block->i_dts;
-    }
-    else if( p_block->i_dts <= 0 )
+    if( p_block->i_dts <= 0 )
     {
         p_block->i_dts = p_block->i_pts;
     }
 
-    if( p_block->i_pts <= 0 )
+    if( p_block->i_dts <= 0 )
     {
-        msg_Dbg( p_dec, "need pts > 0" );
+        msg_Dbg( p_dec, "need dts > 0" );
         block_Release( p_block );
         return NULL;
     }
@@ -286,3 +291,35 @@ static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
     return p_ret;
 }
 
+/*****************************************************************************
+ * PacketizeSub: packetize an unit (here copy a complete block )
+ *****************************************************************************/
+static block_t *PacketizeSub( decoder_t *p_dec, block_t **pp_block )
+{
+    block_t *p_block;
+
+    if( pp_block == NULL || *pp_block == NULL )
+        return NULL;
+    if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
+    {
+        block_Release( *pp_block );
+        return NULL;
+    }
+
+    p_block = *pp_block;
+    *pp_block = NULL;
+
+    if( p_block->i_dts <= 0 )
+    {
+        p_block->i_dts = p_block->i_pts;
+    }
+
+    if( p_block->i_dts <= 0 )
+    {
+        msg_Dbg( p_dec, "need dts > 0" );
+        block_Release( p_block );
+        return NULL;
+    }
+
+    return p_block;
+}