]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/copy.c
Used VLC_CODEC_* and vlc_fourcc_GetCodec when suitable.
[vlc] / modules / packetizer / copy.c
index 24b8465681cbc34487eee80cdd500567a80b5b2b..11461d5d36e2292e02fcfec7dabcdd4c4e1a1d0c 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * copy.c
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
+ * Copyright (C) 2001, 2002, 2006 the VideoLAN team
  * $Id$
  *
  * Authors: 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>                                      /* malloc(), free() */
 
-#include <vlc/vlc.h>
-#include <vlc/decoder.h>
-#include <vlc/input.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_codec.h>
+#include <vlc_block.h>
 
 /*****************************************************************************
  * Module descriptor
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-vlc_module_begin();
-    set_description( _("Copy packetizer") );
-    set_capability( "packetizer", 1 );
-    set_callbacks( Open, Close );
-vlc_module_end();
+vlc_module_begin ()
+    set_category( CAT_SOUT )
+    set_subcategory( SUBCAT_SOUT_PACKETIZER )
+    set_description( N_("Copy packetizer") )
+    set_capability( "packetizer", 1 )
+    set_callbacks( Open, Close )
+vlc_module_end ()
 
 /*****************************************************************************
  * Local prototypes
@@ -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,7 +79,10 @@ 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 */
     es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
@@ -93,26 +103,26 @@ static int Open( vlc_object_t *p_this )
         case VLC_FOURCC( 'D', 'X', '5', '0'):
         case VLC_FOURCC( 0x04, 0,   0,   0):
         case VLC_FOURCC( '3', 'I', 'V', '2'):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', '4', 'v');
+            p_dec->fmt_out.i_codec = VLC_CODEC_MP4V;
             break;
 
         case VLC_FOURCC( 'm', 'p', 'g', '1' ):
         case VLC_FOURCC( 'm', 'p', 'g', '2' ):
-        case VLC_FOURCC( 'm', 'p', '1', 'v' ):
-        case VLC_FOURCC( 'm', 'p', '2', 'v' ):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 'm', 'p', 'g', 'v' );
+        case VLC_CODEC_MP1V:
+        case VLC_CODEC_MP2V:
+            p_dec->fmt_out.i_codec = VLC_CODEC_MPGV;
             break;
 
         case VLC_FOURCC( 'd', 'i', 'v', '1' ):
         case VLC_FOURCC( 'M', 'P', 'G', '4' ):
         case VLC_FOURCC( 'm', 'p', 'g', '4' ):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '1' );
+            p_dec->fmt_out.i_codec = VLC_CODEC_DIV1;
             break;
 
         case VLC_FOURCC( 'd', 'i', 'v', '2' ):
         case VLC_FOURCC( 'M', 'P', '4', '2' ):
         case VLC_FOURCC( 'm', 'p', '4', '2' ):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '2' );
+            p_dec->fmt_out.i_codec = VLC_CODEC_DIV2;
             break;
 
         case VLC_FOURCC( 'd', 'i', 'v', '3' ):
@@ -127,25 +137,25 @@ static int Open( vlc_object_t *p_this )
         case VLC_FOURCC( 'm', 'p', 'g', '3' ):
         case VLC_FOURCC( 'M', 'P', 'G', '3' ):
         case VLC_FOURCC( 'A', 'P', '4', '1' ):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 'D', 'I', 'V', '3' );
+            p_dec->fmt_out.i_codec = VLC_CODEC_DIV3;
             break;
 
-        case VLC_FOURCC( 'h', '2', '6', '3' ):
+        case VLC_CODEC_H263:
         case VLC_FOURCC( 'U', '2', '6', '3' ):
         case VLC_FOURCC( 'u', '2', '6', '3' ):
             p_dec->fmt_out.i_codec = VLC_FOURCC( 'H', '2', '6', '3' );
             break;
 
         case VLC_FOURCC( 'i', '2', '6', '3' ):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 'I', '2', '6', '3' );
+            p_dec->fmt_out.i_codec = VLC_CODEC_H263I;
             break;
 
         case VLC_FOURCC( 'm', 'j', 'p', 'g' ):
         case VLC_FOURCC( 'm', 'j', 'p', 'a' ):
-        case VLC_FOURCC( 'j', 'p', 'e', 'g' ):
+        case VLC_CODEC_JPEG:
         case VLC_FOURCC( 'J', 'P', 'E', 'G' ):
         case VLC_FOURCC( 'J', 'F', 'I', 'F' ):
-            p_dec->fmt_out.i_codec = VLC_FOURCC( 'M', 'J', 'P', 'G' );
+            p_dec->fmt_out.i_codec = VLC_CODEC_MJPG;
             break;
 
         case VLC_FOURCC( 'd', 'v', 's', 'd' ):
@@ -159,16 +169,16 @@ static int Open( vlc_object_t *p_this )
             switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
             {
                 case 1:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('u','8',' ',' ');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_U8;
                     break;
                 case 2:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
                     break;
                 case 3:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
                     break;
                 case 4:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
                     break;
                 default:
                     msg_Err( p_dec, "unknown raw audio sample size" );
@@ -180,16 +190,16 @@ static int Open( vlc_object_t *p_this )
             switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
             {
                 case 1:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S8;
                     break;
                 case 2:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S16B;
                     break;
                 case 3:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S24B;
                     break;
                 case 4:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S32B;
                     break;
                 default:
                     msg_Err( p_dec, "unknown raw audio sample size" );
@@ -201,16 +211,16 @@ static int Open( vlc_object_t *p_this )
             switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
             {
                 case 1:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S8;
                     break;
                 case 2:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S16L;
                     break;
                 case 3:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S24L;
                     break;
                 case 4:
-                    p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
+                    p_dec->fmt_out.i_codec = VLC_CODEC_S32L;
                     break;
                 default:
                     msg_Err( p_dec, "unknown raw audio sample size" );
@@ -237,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 )
 {
@@ -249,9 +260,13 @@ 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;
 
@@ -275,3 +290,36 @@ 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;
+}