[vlc-devel] [PATCH] vpx: encoder: use vpx_image_wrap to avoid memcpy

Tristan Matthews tmatth at videolan.org
Fri Apr 13 20:27:44 CEST 2018


---
 modules/codec/vpx.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/modules/codec/vpx.c b/modules/codec/vpx.c
index f92dea2c56..6f7f8e34c4 100644
--- a/modules/codec/vpx.c
+++ b/modules/codec/vpx.c
@@ -456,23 +456,15 @@ static block_t *Encode(encoder_t *p_enc, picture_t *p_pict)
     unsigned i_h = p_enc->fmt_in.video.i_visible_height;
 
     /* Create and initialize the vpx_image */
-    if (!vpx_img_alloc(&img, VPX_IMG_FMT_I420, i_w, i_h, 1)) {
-        VPX_ERR(p_enc, ctx, "Failed to allocate image");
+    if (!vpx_img_wrap(&img, VPX_IMG_FMT_I420, i_w, i_h, 32, p_pict->p[0].p_pixels)) {
+        VPX_ERR(p_enc, ctx, "Failed to wrap image");
         return NULL;
     }
-    for (int plane = 0; plane < p_pict->i_planes; plane++) {
-        uint8_t *src = p_pict->p[plane].p_pixels;
-        uint8_t *dst = img.planes[plane];
-        int src_stride = p_pict->p[plane].i_pitch;
-        int dst_stride = img.stride[plane];
-
-        int size = __MIN(src_stride, dst_stride);
-        for (int line = 0; line < p_pict->p[plane].i_visible_lines; line++)
-        {
-            memcpy(dst, src, size);
-            src += src_stride;
-            dst += dst_stride;
-        }
+
+    /* Correct chroma plane offsets. */
+    for (int plane = 1; plane < p_pict->i_planes; plane++) {
+        img.planes[plane] = p_pict->p[plane].p_pixels;
+        img.stride[plane] = p_pict->p[plane].i_pitch;
     }
 
     int flags = 0;
-- 
2.17.0



More information about the vlc-devel mailing list