[vlc-devel] [PATCH] video-chroma: add NV12 to I420 optimization

Victorien Le Couviour--Tuffet victorien.lecouviour.tuffet at gmail.com
Fri May 12 20:56:31 CEST 2017


---
 modules/video_chroma/copy.c | 29 +++++++++++++++++++++++++----
 modules/video_chroma/copy.h |  2 +-
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c
index 98816d4686..718c1fddb7 100644
--- a/modules/video_chroma/copy.c
+++ b/modules/video_chroma/copy.c
@@ -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,
@@ -410,9 +425,6 @@ static void CopyPlane(uint8_t *dst, size_t dst_pitch,
                       const uint8_t *src, size_t src_pitch,
                       unsigned height)
 {
-    if (src_pitch == dst_pitch)
-        memcpy(dst, src, src_pitch * height);
-    else
     for (unsigned y = 0; y < height; y++) {
         memcpy(dst, src, src_pitch);
         src += src_pitch;
@@ -474,8 +486,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,
diff --git a/modules/video_chroma/copy.h b/modules/video_chroma/copy.h
index f5a56cc75c..937773cb84 100644
--- a/modules/video_chroma/copy.h
+++ b/modules/video_chroma/copy.h
@@ -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);
-- 
2.12.0



More information about the vlc-devel mailing list