copy: add SSE optimization for NV12 to I420 conversion
authorVictorien Le Couviour--Tuffet <victorien.lecouviour.tuffet@gmail.com>
Fri, 12 May 2017 18:55:02 +0000 (20:55 +0200)
committerThomas Guillem <thomas@gllm.fr>
Fri, 19 May 2017 07:39:32 +0000 (09:39 +0200)
Signed-off-by: Thomas Guillem <thomas@gllm.fr>
modules/codec/videotoolbox.m
modules/video_chroma/copy.c
modules/video_chroma/copy.h
modules/video_chroma/cvpx_i420.c

index 965262e..0dccf8c 100644 (file)
@@ -1160,6 +1160,7 @@ static void copy420YpCbCr8Planar(picture_t *p_pic,
 {
     uint8_t *pp_plane[2];
     size_t pi_pitch[2];
+    copy_cache_t cache;
 
     if (!buffer || i_width == 0 || i_height == 0)
         return;
@@ -1171,7 +1172,12 @@ static void copy420YpCbCr8Planar(picture_t *p_pic,
         pi_pitch[i] = CVPixelBufferGetBytesPerRowOfPlane(buffer, i);
     }
 
-    CopyFromNv12ToI420(p_pic, pp_plane, pi_pitch, i_height);
+    if (CopyInitCache(&cache, i_width))
+        return;
+
+    CopyFromNv12ToI420(p_pic, pp_plane, pi_pitch, i_height, &cache);
+
+    CopyCleanCache(&cache);
 
     CVPixelBufferUnlockBaseAddress(buffer, kCVPixelBufferLock_ReadOnly);
 }
index 61e3149..03918fd 100644 (file)
@@ -369,6 +369,21 @@ static void SSE_CopyFromNv12ToNv12(picture_t *dst,
     asm volatile ("emms");
 }
 
+static void
+SSE_CopyFromNv12ToI420(picture_t *dest, uint8_t *src[2],
+                       size_t src_pitch[2], unsigned int height,
+                       copy_cache_t *cache, unsigned int cpu)
+{
+    SSE_CopyPlane(dest->p[0].p_pixels, dest->p[0].i_pitch,
+                  src[0], src_pitch[0], cache->buffer, cache->size,
+                  height, cpu);
+    SSE_SplitPlanes(dest->p[1].p_pixels, dest->p[1].i_pitch,
+                    dest->p[2].p_pixels, dest->p[2].i_pitch,
+                    src[1], src_pitch[1], cache->buffer, cache->size,
+                    height / 2, cpu);
+    asm volatile ("emms");
+}
+
 static void SSE_CopyFromI420ToNv12(picture_t *dst,
                              uint8_t *src[3], size_t src_pitch[3],
                              unsigned height,
@@ -473,8 +488,17 @@ void CopyFromNv12ToNv12(picture_t *dst, uint8_t *src[2], size_t src_pitch[2],
 }
 
 void CopyFromNv12ToI420(picture_t *dst, uint8_t *src[2], size_t src_pitch[2],
-                        unsigned height)
+                        unsigned height, copy_cache_t *cache)
 {
+#ifdef CAN_COMPILE_SSE2
+    unsigned    cpu = vlc_CPU();
+
+    if (vlc_CPU_SSE2())
+        return SSE_CopyFromNv12ToI420(dst, src, src_pitch, height, cache, cpu);
+#else
+    VLC_UNUSED(cache);
+#endif
+
     CopyPlane(dst->p[0].p_pixels, dst->p[0].i_pitch,
               src[0], src_pitch[0], height);
     SplitPlanes(dst->p[1].p_pixels, dst->p[1].i_pitch,
index 02b015c..f32bd24 100644 (file)
@@ -45,7 +45,7 @@ void CopyFromNv12ToNv12(picture_t *dst, uint8_t *src[2], size_t src_pitch[2],
                         unsigned height, copy_cache_t *cache);
 
 void CopyFromNv12ToI420(picture_t *dst, uint8_t *src[2], size_t src_pitch[2],
-                        unsigned height);
+                        unsigned height, copy_cache_t *cache);
 
 void CopyFromI420ToNv12(picture_t *dst, uint8_t *src[3], size_t src_pitch[3],
                         unsigned height, copy_cache_t *cache);
index e5f08cb..5d48992 100644 (file)
@@ -95,7 +95,14 @@ static void CVPX_I420(filter_t *p_filter, picture_t *sourcePicture, picture_t *d
         pi_pitch[i] = CVPixelBufferGetBytesPerRowOfPlane(picsys->pixelBuffer, i);
     }
 
-    CopyFromNv12ToI420(destinationPicture, pp_plane, pi_pitch, height);
+    copy_cache_t cache;
+
+    if (CopyInitCache(&cache, width))
+        return;
+
+    CopyFromNv12ToI420(destinationPicture, pp_plane, pi_pitch, height, &cache);
+
+    CopyCleanCache(&cache);
 
     CVPixelBufferUnlockBaseAddress(picsys->pixelBuffer, kCVPixelBufferLock_ReadOnly);
 }