]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/swscale.c
swscale: pass/calculate sar-info, should fix #7437
[vlc] / modules / video_filter / swscale.c
index 9a17c4871e511fdf909dcc20ed9cdf387236d34f..91b3d5809e55638e0e87cea3961b28e39c9c941e 100644 (file)
 #include <vlc_filter.h>
 #include <vlc_cpu.h>
 
-#ifdef HAVE_LIBSWSCALE_SWSCALE_H
-#   include <libswscale/swscale.h>
-#elif defined(HAVE_FFMPEG_SWSCALE_H)
-#   include <ffmpeg/swscale.h>
+#include <libswscale/swscale.h>
+
+#ifdef __APPLE__
+# include <TargetConditionals.h>
 #endif
 
 #include "../codec/avcodec/chroma.h" // Chroma Avutil <-> VLC conversion
@@ -80,8 +80,6 @@ vlc_module_end ()
  * Local prototypes
  ****************************************************************************/
 
-void *( *swscale_fast_memcpy )( void *, const void *, size_t );
-
 /**
  * Internal swscale filter structure.
  */
@@ -160,9 +158,6 @@ static int OpenScaler( vlc_object_t *p_this )
     if( ( p_filter->p_sys = p_sys = malloc(sizeof(filter_sys_t)) ) == NULL )
         return VLC_ENOMEM;
 
-    /* FIXME pointer assignment may not be atomic */
-    swscale_fast_memcpy = vlc_memcpy;
-
     /* Set CPU capabilities */
     p_sys->i_cpu_mask = GetSwsCpuMask();
 
@@ -212,6 +207,9 @@ static int OpenScaler( vlc_object_t *p_this )
              (char *)&p_filter->fmt_out.video.i_chroma,
              ppsz_mode_descriptions[i_sws_mode] );
 
+    p_filter->fmt_out.video.i_sar_num = p_filter->fmt_in.video.i_sar_num;
+    p_filter->fmt_out.video.i_sar_den = p_filter->fmt_in.video.i_sar_den;
+
     return VLC_SUCCESS;
 }
 
@@ -234,20 +232,21 @@ static void CloseScaler( vlc_object_t *p_this )
  *****************************************************************************/
 static int GetSwsCpuMask(void)
 {
-    const unsigned int i_cpu = vlc_CPU();
     int i_sws_cpu = 0;
 
-    if( i_cpu & CPU_CAPABILITY_MMX )
+#if defined(__i386__) || defined(__x86_64__)
+    if( vlc_CPU_MMX() )
         i_sws_cpu |= SWS_CPU_CAPS_MMX;
 #if (LIBSWSCALE_VERSION_INT >= ((0<<16)+(5<<8)+0))
-    if( i_cpu & CPU_CAPABILITY_MMXEXT )
+    if( vlc_CPU_MMXEXT() )
         i_sws_cpu |= SWS_CPU_CAPS_MMX2;
 #endif
-    if( i_cpu & CPU_CAPABILITY_3DNOW )
+    if( vlc_CPU_3dNOW() )
         i_sws_cpu |= SWS_CPU_CAPS_3DNOW;
-
-    if( i_cpu & CPU_CAPABILITY_ALTIVEC )
+#elif defined(__ppc__) || defined(__ppc64__) || defined(__powerpc__)
+    if( vlc_CPU_ALTIVEC() )
         i_sws_cpu |= SWS_CPU_CAPS_ALTIVEC;
+#endif
 
     return i_sws_cpu;
 }
@@ -278,9 +277,6 @@ static void FixParameters( int *pi_fmt, bool *pb_has_a, bool *pb_swap_uv, vlc_fo
         *pi_fmt = PIX_FMT_YUV410P;
         *pb_swap_uv = true;
         break;
-    case VLC_CODEC_RGB16:
-        *pi_fmt = PIX_FMT_RGB565;
-        break;
     default:
         break;
     }
@@ -315,6 +311,7 @@ static int GetParameters( ScalerConfiguration *p_cfg,
     FixParameters( &i_fmti, &b_has_ai, &b_swap_uvi, p_fmti->i_chroma );
     FixParameters( &i_fmto, &b_has_ao, &b_swap_uvo, p_fmto->i_chroma );
 
+#if !defined (__ANDROID__) && !defined(TARGET_OS_IPHONE)
     /* FIXME TODO removed when ffmpeg is fixed
      * Without SWS_ACCURATE_RND the quality is really bad for some conversions */
     switch( i_fmto )
@@ -325,6 +322,7 @@ static int GetParameters( ScalerConfiguration *p_cfg,
         i_sws_flags |= SWS_ACCURATE_RND;
         break;
     }
+#endif
 
     if( p_cfg )
     {
@@ -350,7 +348,7 @@ static int Init( filter_t *p_filter )
 {
     filter_sys_t *p_sys = p_filter->p_sys;
     const video_format_t *p_fmti = &p_filter->fmt_in.video;
-    const video_format_t *p_fmto = &p_filter->fmt_out.video;
+    video_format_t       *p_fmto = &p_filter->fmt_out.video;
 
     if( IsFmtSimilar( p_fmti, &p_sys->fmt_in ) &&
         IsFmtSimilar( p_fmto, &p_sys->fmt_out ) &&
@@ -405,8 +403,10 @@ static int Init( filter_t *p_filter )
         p_sys->p_src_e = picture_New( p_fmti->i_chroma, i_fmti_width, p_fmti->i_height, 0, 1 );
         p_sys->p_dst_e = picture_New( p_fmto->i_chroma, i_fmto_width, p_fmto->i_height, 0, 1 );
 
-        memset( p_sys->p_src_e->p[0].p_pixels, 0, p_sys->p_src_e->p[0].i_pitch * p_sys->p_src_e->p[0].i_lines );
-        memset( p_sys->p_dst_e->p[0].p_pixels, 0, p_sys->p_dst_e->p[0].i_pitch * p_sys->p_dst_e->p[0].i_lines );
+        if( p_sys->p_src_e )
+            memset( p_sys->p_src_e->p[0].p_pixels, 0, p_sys->p_src_e->p[0].i_pitch * p_sys->p_src_e->p[0].i_lines );
+        if( p_sys->p_dst_e )
+            memset( p_sys->p_dst_e->p[0].p_pixels, 0, p_sys->p_dst_e->p[0].i_pitch * p_sys->p_dst_e->p[0].i_lines );
     }
 
     if( !p_sys->ctx ||
@@ -425,6 +425,7 @@ static int Init( filter_t *p_filter )
     p_sys->b_swap_uvi = cfg.b_swap_uvi;
     p_sys->b_swap_uvo = cfg.b_swap_uvo;
 
+    video_format_ScaleCropAr( p_fmto, p_fmti );
 #if 0
     msg_Dbg( p_filter, "%ix%i chroma: %4.4s -> %ix%i chroma: %4.4s extend by %d",
              p_fmti->i_width, p_fmti->i_height, (char *)&p_fmti->i_chroma,