From 7b91ebb5d450d48d8d3d2915e09ee579c02e97cf Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 3 Sep 2024 14:03:59 +0200 Subject: [PATCH] vcomp/cmpto_j2k: move CUDA buf alloc to set_pool The allocation was before set_pool, which can, however, now set cuda_convert_func to nullptr, therefore the malloc would be unneeded. --- src/video_compress/cmpto_j2k.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/video_compress/cmpto_j2k.cpp b/src/video_compress/cmpto_j2k.cpp index d537ec298..076d4611c 100644 --- a/src/video_compress/cmpto_j2k.cpp +++ b/src/video_compress/cmpto_j2k.cpp @@ -189,11 +189,21 @@ static struct { }; static void -set_pool(struct state_video_compress_j2k *s) +set_pool(struct state_video_compress_j2k *s, struct video_desc desc) { s->pool_in_device_memory = false; #ifdef HAVE_CUDA if (cuda_devices_count == 1) { + cuda_wrapper_set_device((int) cuda_devices[0]); + + if (s->cuda_convert_func != nullptr) { + cuda_wrapper_free(s->cuda_conv_tmp_buf); + cuda_wrapper_malloc( + (void **) &s->cuda_conv_tmp_buf, + vc_get_datalen(desc.width, desc.height, desc.color_spec) + + MAX_PADDING); + } + s->pool_in_device_memory = true; s->pool = video_frame_pool( s->max_in_frames, @@ -226,17 +236,6 @@ static bool configure_with(struct state_video_compress_j2k *s, struct video_desc } } -#ifdef HAVE_CUDA - cuda_wrapper_set_device((int) cuda_devices[0]); - if (s->cuda_convert_func != nullptr) { - cuda_wrapper_free(s->cuda_conv_tmp_buf); - cuda_wrapper_malloc( - (void **) &s->cuda_conv_tmp_buf, - vc_get_datalen(desc.width, desc.height, desc.color_spec) + - MAX_PADDING); - } -#endif - if(!found){ log_msg(LOG_LEVEL_ERROR, "[J2K] Failed to find suitable pixel format\n"); return false; @@ -262,7 +261,7 @@ static bool configure_with(struct state_video_compress_j2k *s, struct video_desc "Setting MCT", NOOP); - set_pool(s); + set_pool(s, desc); s->compressed_desc = desc; s->compressed_desc.color_spec = codec_is_a_rgb(desc.color_spec) ? J2KR : J2K;