From cf868c21b139bb1aa39efbea0c008acf47cfd76d Mon Sep 17 00:00:00 2001 From: Martin Pulec <martin.pulec@cesnet.cz> Date: Fri, 28 Aug 2020 09:02:10 +0200 Subject: [PATCH] UltraGrid plugin: opt to use memmove instead of memcpy --- client/ultragrid/ultragrid.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/client/ultragrid/ultragrid.cpp b/client/ultragrid/ultragrid.cpp index dd670d3e..91131a78 100644 --- a/client/ultragrid/ultragrid.cpp +++ b/client/ultragrid/ultragrid.cpp @@ -344,6 +344,12 @@ void cesnet_set_render_buffer_rgba(unsigned char *rgba, int width, int height) bool copy_data(struct cesnet_shm *cesnet_shm, unsigned char *y, unsigned char *u, unsigned char *v, int width, int height) { + void *(*copy_fn)(void *dest, const void *src, size_t n) = memcpy; + + if (getenv("MEMMOVE_INSTEAD_MEMCPY")) { + copy_fn = memmove; + } + # if !defined WITH_CLIENT_CUDA if (cesnet_shm->use_gpu) { fprintf(stderr, "CUDA support not compiled in! Use 'uv -t shm' to use standard SHM.\n"); @@ -386,26 +392,26 @@ bool copy_data(struct cesnet_shm *cesnet_shm, } else { // Y for (int i = 0; i < height; ++i) { - memcpy(out1_y, y, width); + copy_fn(out1_y, y, width); out1_y += width; y += width; - memcpy(out2_y, y, width); + copy_fn(out2_y, y, width); out2_y += width; y += width; } // U V for (int i = 0; i < height / 2; ++i) { - memcpy(out1_u, u, width / 2); + copy_fn(out1_u, u, width / 2); out1_u += width / 2; u += width / 2; - memcpy(out2_u, u, width / 2); + copy_fn(out2_u, u, width / 2); out2_u += width / 2; u += width / 2; - memcpy(out1_v, v, width / 2); + copy_fn(out1_v, v, width / 2); out1_v += width / 2; v += width / 2; - memcpy(out2_v, v, width / 2); + copy_fn(out2_v, v, width / 2); out2_v += width / 2; v += width / 2; } @@ -426,12 +432,12 @@ bool copy_data(struct cesnet_shm *cesnet_shm, # endif } else { int len = width * height; - memcpy(tmp, y, len); + copy_fn(tmp, y, len); tmp += len; len = width * height / 4; - memcpy(tmp, u, len); + copy_fn(tmp, u, len); tmp += len; - memcpy(tmp, v, len); + copy_fn(tmp, v, len); } } return true; -- GitLab