]> git.sesse.net Git - vlc/blobdiff - modules/codec/libmpeg2.c
* modules/video_filter/*: implemented a forwarding vout_vaControl().
[vlc] / modules / codec / libmpeg2.c
index 29469134052c26fa5b12cf149276c7438da7cad9..88c2a642c2f50baebb240d05a738a58438abe6a1 100755 (executable)
@@ -2,7 +2,7 @@
  * libmpeg2.c: mpeg2 video decoder module making use of libmpeg2.
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: libmpeg2.c,v 1.40 2003/12/22 16:40:04 gbazin Exp $
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Christophe Massiot <massiot@via.ecp.fr>
@@ -100,6 +100,7 @@ static int OpenDecoder( vlc_object_t *p_this )
 {
     decoder_t *p_dec = (decoder_t*)p_this;
     decoder_sys_t *p_sys;
+    uint32_t i_accel = 0;
 
     if( p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','v') &&
         p_dec->fmt_in.i_codec != VLC_FOURCC('m','p','g','1') &&
@@ -134,6 +135,37 @@ static int OpenDecoder( vlc_object_t *p_this )
     p_sys->b_slice_i  = 0;
     p_sys->b_skip     = 0;
 
+#if defined( __i386__ )
+    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMX )
+    {
+        i_accel |= MPEG2_ACCEL_X86_MMX;
+    }
+
+    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_3DNOW )
+    {
+        i_accel |= MPEG2_ACCEL_X86_3DNOW;
+    }
+
+    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMXEXT )
+    {
+        i_accel |= MPEG2_ACCEL_X86_MMXEXT;
+    }
+
+#elif defined( __powerpc__ ) || defined( SYS_DARWIN )
+    if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC )
+    {
+        i_accel |= MPEG2_ACCEL_PPC_ALTIVEC;
+    }
+
+#else
+    /* If we do not know this CPU, trust libmpeg2's feature detection */
+    i_accel = MPEG2_ACCEL_DETECT;
+
+#endif
+
+    /* Set CPU acceleration features */
+    mpeg2_accel( i_accel );
+
     /* Initialize decoder */
     p_sys->p_mpeg2dec = mpeg2_init();
     if( p_sys->p_mpeg2dec == NULL)
@@ -178,7 +210,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 return NULL;
             }
 
-            if( p_block->b_discontinuity && p_sys->p_synchro &&
+            if( (p_block->i_flags&BLOCK_FLAG_DISCONTINUITY) &&
+                p_sys->p_synchro &&
                 p_sys->p_info->sequence &&
                 p_sys->p_info->sequence->width != (unsigned)-1 )
             {
@@ -221,7 +254,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
                 p_sys->i_current_pts = p_block->i_pts;
             }
 
-            p_sys->i_current_rate = DEFAULT_RATE;//p_pes->i_rate;
+            p_sys->i_current_rate = p_block->i_rate;
 
             mpeg2_buffer( p_sys->p_mpeg2dec, p_block->p_buffer,
                           p_block->p_buffer + p_block->i_buffer );
@@ -261,11 +294,22 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
             else
             {
                 /* Use the value provided in the MPEG sequence header */
-                p_sys->i_aspect =
-                    ((uint64_t)p_sys->p_info->sequence->display_width) *
-                    p_sys->p_info->sequence->pixel_width * VOUT_ASPECT_FACTOR /
-                    p_sys->p_info->sequence->display_height /
-                    p_sys->p_info->sequence->pixel_height;
+                if( p_sys->p_info->sequence->pixel_height > 0 )
+                {
+                    p_sys->i_aspect =
+                        ((uint64_t)p_sys->p_info->sequence->display_width) *
+                        p_sys->p_info->sequence->pixel_width *
+                        VOUT_ASPECT_FACTOR /
+                        p_sys->p_info->sequence->display_height /
+                        p_sys->p_info->sequence->pixel_height;
+                }
+                else
+                {
+                    /* Invalid aspect, assume 4:3.
+                     * This shouldn't happen and if it does it is a bug
+                     * in libmpeg2 (likely triggered by an invalid stream) */
+                    p_sys->i_aspect = VOUT_ASPECT_FACTOR * 4 / 3;
+                }
             }
 
             msg_Dbg( p_dec, "%dx%d, aspect %d, %u.%03u fps",