]> git.sesse.net Git - vlc/blobdiff - modules/packetizer/copy.c
l10n: Serbian update
[vlc] / modules / packetizer / copy.c
index 8207b609a96b028e44a43147e3613bfbbb064fbb..b5e0973b8e3992ead12e010f8f31e016c613a7b4 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * copy.c
  *****************************************************************************
- * Copyright (C) 2001, 2002, 2006 the VideoLAN team
+ * Copyright (C) 2001, 2002, 2006 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Eric Petit <titer@videolan.org>
  *
- * 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.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -34,6 +34,7 @@
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
 #include <vlc_block.h>
+#include <vlc_bits.h>
 
 /*****************************************************************************
  * Module descriptor
@@ -55,11 +56,14 @@ vlc_module_end ()
 struct decoder_sys_t
 {
     block_t *p_block;
+    void (*pf_parse)( decoder_t *, block_t * );
 };
 
 static block_t *Packetize   ( decoder_t *, block_t ** );
 static block_t *PacketizeSub( decoder_t *, block_t ** );
 
+static void ParseWMV3( decoder_t *, block_t * );
+
 /*****************************************************************************
  * Open: probe the packetizer and return score
  *****************************************************************************
@@ -101,6 +105,15 @@ static int Open( vlc_object_t *p_this )
 
     p_dec->p_sys = p_sys = malloc( sizeof(*p_sys) );
     p_sys->p_block    = NULL;
+    switch( p_dec->fmt_in.i_codec )
+    {
+    case VLC_CODEC_WMV3:
+        p_sys->pf_parse = ParseWMV3;
+        break;
+    default:
+        p_sys->pf_parse = NULL;
+        break;
+    }
 
     return VLC_SUCCESS;
 }
@@ -140,24 +153,27 @@ static block_t *Packetize ( decoder_t *p_dec, block_t **pp_block )
     p_block = *pp_block;
     *pp_block = NULL;
 
-    if( p_block->i_dts <= 0 )
+    if( p_block->i_dts <= VLC_TS_INVALID )
     {
         p_block->i_dts = p_block->i_pts;
     }
 
-    if( p_block->i_dts <= 0 )
+    if( p_block->i_dts <= VLC_TS_INVALID )
     {
-        msg_Dbg( p_dec, "need dts > 0" );
+        msg_Dbg( p_dec, "need valid dts" );
         block_Release( p_block );
         return NULL;
     }
 
     if( p_ret != NULL && p_block->i_pts > p_ret->i_pts )
     {
-        p_ret->i_length = p_block->i_pts - p_ret->i_pts;
+        if (p_dec->fmt_in.i_codec != VLC_CODEC_OPUS)
+            p_ret->i_length = p_block->i_pts - p_ret->i_pts;
     }
     p_dec->p_sys->p_block = p_block;
 
+    if( p_ret && p_dec->p_sys->pf_parse )
+        p_dec->p_sys->pf_parse( p_dec, p_ret );
     return p_ret;
 }
 
@@ -179,17 +195,50 @@ static block_t *PacketizeSub( decoder_t *p_dec, block_t **pp_block )
     p_block = *pp_block;
     *pp_block = NULL;
 
-    if( p_block->i_dts <= 0 )
+    if( p_block->i_dts <= VLC_TS_INVALID )
     {
         p_block->i_dts = p_block->i_pts;
     }
 
-    if( p_block->i_dts <= 0 )
+    if( p_block->i_dts <= VLC_TS_INVALID )
     {
-        msg_Dbg( p_dec, "need dts > 0" );
+        msg_Dbg( p_dec, "need valid dts" );
         block_Release( p_block );
         return NULL;
     }
 
     return p_block;
 }
+
+/* Parse WMV3 packet and extract frame type information */
+static void ParseWMV3( decoder_t *p_dec, block_t *p_block )
+{
+    bs_t s;
+
+    /* Parse Sequence header */
+    bs_init( &s, p_dec->fmt_in.p_extra, p_dec->fmt_in.i_extra );
+    if( bs_read( &s, 2 ) == 3 )
+        return;
+    bs_skip( &s, 22 );
+    const bool b_range_reduction = bs_read( &s, 1 );
+    const bool b_has_frames = bs_read( &s, 3 ) > 0;
+    bs_skip( &s, 2 );
+    const bool b_frame_interpolation = bs_read( &s, 1 );
+    if( bs_eof( &s ) )
+        return;
+
+    /* Parse frame type */
+    bs_init( &s, p_block->p_buffer, p_block->i_buffer );
+    bs_skip( &s, b_frame_interpolation +
+                 2 +
+                 b_range_reduction );
+
+    p_block->i_flags &= ~BLOCK_FLAG_TYPE_MASK;
+    if( bs_read( &s, 1 ) )
+        p_block->i_flags |= BLOCK_FLAG_TYPE_P;
+    else if( !b_has_frames || bs_read( &s, 1 ) )
+        p_block->i_flags |= BLOCK_FLAG_TYPE_I;
+    else
+        p_block->i_flags |= BLOCK_FLAG_TYPE_B;
+}
+