]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/copy.c
Include vlc_plugin.h as needed
[vlc] / modules / packetizer / copy.c
index 3727c21650bc4eb05d8d7bae85afa48f4a596374..8f7cb2f35cadaf93f9dc8a3c98bbe4b049ba60f4 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * copy.c
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: copy.c,v 1.19 2003/11/20 18:27:44 fenrir 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 );
@@ -48,14 +54,11 @@ vlc_module_end();
  *****************************************************************************/
 struct decoder_sys_t
 {
-    int i_spu_size;
-    int i_spu;
-
     block_t *p_block;
 };
 
-static block_t *PacketizeAV ( decoder_t *, block_t ** );
-static block_t *PacketizeSPU( 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
@@ -68,36 +71,21 @@ static int Open( vlc_object_t *p_this )
     decoder_t     *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys;
 
-    if( p_dec->fmt_in.i_cat == AUDIO_ES || p_dec->fmt_in.i_cat == VIDEO_ES )
-    {
-        p_dec->pf_packetize = PacketizeAV;
-    }
-    else if( p_dec->fmt_in.i_cat == SPU_ES )
-    {
-        if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', 'p', 'u', ' ' ) ||
-            p_dec->fmt_in.i_codec == VLC_FOURCC( 's', 'p', 'u', 'b' ) )
-        {
-            p_dec->pf_packetize = PacketizeSPU;
-        }
-        else
-        {
-            p_dec->pf_packetize = PacketizeAV;
-        }
-    }
-    else
+    if( p_dec->fmt_in.i_cat != AUDIO_ES &&
+        p_dec->fmt_in.i_cat != VIDEO_ES &&
+        p_dec->fmt_in.i_cat != SPU_ES )
     {
         msg_Err( p_dec, "invalid ES type" );
         return VLC_EGENERIC;
     }
 
+    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 )
@@ -193,7 +181,7 @@ static int Open( vlc_object_t *p_this )
                     p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
                     break;
                 default:
-                    msg_Err( p_dec, "unknown raw audio sample size !!" );
+                    msg_Err( p_dec, "unknown raw audio sample size" );
                     return VLC_EGENERIC;
             }
             break;
@@ -214,7 +202,7 @@ static int Open( vlc_object_t *p_this )
                     p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b');
                     break;
                 default:
-                    msg_Err( p_dec, "unknown raw audio sample size !!" );
+                    msg_Err( p_dec, "unknown raw audio sample size" );
                     return VLC_EGENERIC;
             }
             break;
@@ -235,20 +223,13 @@ static int Open( vlc_object_t *p_this )
                     p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
                     break;
                 default:
-                    msg_Err( p_dec, "unknown raw audio sample size !!" );
+                    msg_Err( p_dec, "unknown raw audio sample size" );
                     return VLC_EGENERIC;
             }
             break;
-
-        /* subtitles */
-        case VLC_FOURCC( 's', 'p', 'u', 'b' ):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 's', 'p', 'u', ' ' );
-            break;
     }
 
     p_dec->p_sys = p_sys = malloc( sizeof( block_t ) );
-    p_sys->i_spu_size = 0;
-    p_sys->i_spu      = 0;
     p_sys->p_block    = NULL;
 
     return VLC_SUCCESS;
@@ -266,27 +247,37 @@ 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 *PacketizeAV ( decoder_t *p_dec, block_t **pp_block )
+static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
 {
     block_t *p_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 )
+    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 pts > 0" );
+        msg_Dbg( p_dec, "need dts > 0" );
         block_Release( p_block );
         return NULL;
     }
@@ -301,63 +292,34 @@ static block_t *PacketizeAV ( decoder_t *p_dec, block_t **pp_block )
 }
 
 /*****************************************************************************
- * PacketizeSPU: packetize an SPU unit (so gather all PES of one subtitle)
+ * PacketizeSub: packetize an unit (here copy a complete block )
  *****************************************************************************/
-static block_t *PacketizeSPU( decoder_t *p_dec, block_t **pp_block )
+static block_t *PacketizeSub( decoder_t *p_dec, block_t **pp_block )
 {
-    decoder_sys_t *p_sys = p_dec->p_sys;
     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_sys->i_spu_size <= 0 &&
-        ( p_block->i_pts <= 0 || p_block->i_buffer < 4 ) )
+    if( p_block->i_dts <= 0 )
     {
-        msg_Dbg( p_dec, "invalid starting packet (size < 4 or pts <=0)" );
-        block_Release( p_block );
-        return NULL;
+        p_block->i_dts = p_block->i_pts;
     }
 
-    block_ChainAppend( &p_sys->p_block, p_block );
-    p_sys->i_spu += p_block->i_buffer;
-
-    if( p_sys->i_spu_size <= 0 )
+    if( p_block->i_dts <= 0 )
     {
-        int i_rle = ( ( p_block->p_buffer[2] << 8 )| p_block->p_buffer[3] ) - 4;
-
-        p_sys->i_spu_size = ( p_block->p_buffer[0] << 8 )| p_block->p_buffer[1];
-
-        msg_Dbg( p_dec, "i_spu_size=%d i_rle=%d", p_sys->i_spu_size, i_rle );
-
-        if( p_sys->i_spu_size <= 0 || i_rle >= p_sys->i_spu_size )
-        {
-            p_sys->i_spu_size = 0;
-            p_sys->i_spu      = 0;
-            p_sys->p_block    = NULL;
-
-            block_Release( p_block );
-            return NULL;
-        }
+        msg_Dbg( p_dec, "need dts > 0" );
+        block_Release( p_block );
+        return NULL;
     }
 
-    if( p_sys->i_spu >= p_sys->i_spu_size )
-    {
-        /* We have a complete sub */
-        block_t *p_ret = p_sys->p_block;
-
-        msg_Dbg( p_dec, "SPU packets size=%d should be %d",
-                 p_sys->i_spu, p_sys->i_spu_size );
-
-        p_sys->i_spu_size = 0;
-        p_sys->i_spu      = 0;
-        p_sys->p_block    = NULL;
-        return p_ret;
-    }
-    return NULL;
+    return p_block;
 }
-