Skip to content
Snippets Groups Projects
Commit a2960fa1 authored by Martin Pulec's avatar Martin Pulec
Browse files

UltraGrid plugin: refactor data copying

parent 6d63d7c1
No related branches found
No related tags found
No related merge requests found
......@@ -338,6 +338,49 @@ void cesnet_set_render_buffer_rgba(unsigned char *rgba, int width, int height)
fprintf(stderr, "%s: %s\n", #cmd, cudaGetErrorString(err)); \
} \
} while (0)
bool copy_data(struct cesnet_shm *cesnet_shm,
unsigned char *y, unsigned char *u, unsigned char *v, int width, int height)
{
# 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");
return false;
}
# endif // !defined WITH_CLIENT_CUDA
if (cesnet_shm->use_gpu) {
# ifdef WITH_CLIENT_CUDA
char *d_data;
CUDA_CHECK(cudaIpcOpenMemHandle(
(void **)&d_data,
(cudaIpcMemHandle_t &)cesnet_shm->frames[cesnet_shm->write_head].cuda_ipc_mem_handle,
cudaIpcMemLazyEnablePeerAccess));
char *tmp = d_data;
int len = width * height;
CUDA_CHECK(cudaMemcpy(tmp, y, len, cudaMemcpyHostToDevice));
tmp += len;
len = width * height / 4;
CUDA_CHECK(cudaMemcpy(tmp, u, len, cudaMemcpyHostToDevice));
tmp += len;
CUDA_CHECK(cudaMemcpy(tmp, v, len, cudaMemcpyHostToDevice));
CUDA_CHECK(cudaIpcCloseMemHandle(d_data));
# endif
}
else {
char *tmp = cesnet_shm->frames[cesnet_shm->write_head].data;
int len = width * height;
memcpy(tmp, y, len);
tmp += len;
len = width * height / 4;
memcpy(tmp, u, len);
tmp += len;
memcpy(tmp, v, len);
}
return true;
}
// rendering buffer - results in YUV I420 format
void cesnet_set_render_buffer_yuv_i420(
unsigned char *y, unsigned char *u, unsigned char *v, int width, int height)
......@@ -430,38 +473,8 @@ void cesnet_set_render_buffer_yuv_i420(
cesnet_shm->frames[cesnet_shm->write_head].width = width;
cesnet_shm->frames[cesnet_shm->write_head].height = height;
if (cesnet_shm->use_gpu) {
# ifdef WITH_CLIENT_CUDA
char *d_data;
CUDA_CHECK(cudaIpcOpenMemHandle(
(void **)&d_data,
(cudaIpcMemHandle_t &)cesnet_shm->frames[cesnet_shm->write_head].cuda_ipc_mem_handle,
cudaIpcMemLazyEnablePeerAccess));
char *tmp = d_data;
int len = width * height;
CUDA_CHECK(cudaMemcpy(tmp, y, len, cudaMemcpyHostToDevice));
tmp += len;
len = width * height / 4;
CUDA_CHECK(cudaMemcpy(tmp, u, len, cudaMemcpyHostToDevice));
tmp += len;
CUDA_CHECK(cudaMemcpy(tmp, v, len, cudaMemcpyHostToDevice));
CUDA_CHECK(cudaIpcCloseMemHandle(d_data));
# else
fprintf(stderr, "CUDA support not compiled in! Use 'uv -t shm' to use standard SHM.\n");
goto done;
# endif
}
else {
char *tmp = cesnet_shm->frames[cesnet_shm->write_head].data;
int len = width * height;
memcpy(tmp, y, len);
tmp += len;
len = width * height / 4;
memcpy(tmp, u, len);
tmp += len;
memcpy(tmp, v, len);
if (!copy_data(cesnet_shm, y, u, v, width, height)) {
goto done;
}
if (cesnet_shm->pkt.frame != (unsigned)-1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment