Skip to content

Commit d321a34

Browse files
committed
Merge pull request opencv#17527 from tomoaki0705:detectCuvidHeader
2 parents fb1a58a + d4af897 commit d321a34

File tree

7 files changed

+32
-11
lines changed

7 files changed

+32
-11
lines changed

cmake/OpenCVDetectCUDA.cmake

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,30 @@ if(CUDA_FOUND)
3838
endif()
3939

4040
if(WITH_NVCUVID)
41+
macro(SEARCH_NVCUVID_HEADER _filename _result)
42+
# place header file under CUDA_TOOLKIT_TARGET_DIR or CUDA_TOOLKIT_ROOT_DIR
43+
find_path(_header_result
44+
${_filename}
45+
PATHS "${CUDA_TOOLKIT_TARGET_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}"
46+
ENV CUDA_PATH
47+
ENV CUDA_INC_PATH
48+
PATH_SUFFIXES include
49+
NO_DEFAULT_PATH
50+
)
51+
if("x${_header_result}" STREQUAL "x_header_result-NOTFOUND")
52+
set(${_result} 0)
53+
else()
54+
set(${_result} 1)
55+
endif()
56+
endmacro()
57+
SEARCH_NVCUVID_HEADER("nvcuvid.h" HAVE_NVCUVID_HEADER)
58+
SEARCH_NVCUVID_HEADER("dynlink_nvcuvid.h" HAVE_DYNLINK_NVCUVID_HEADER)
4159
find_cuda_helper_libs(nvcuvid)
4260
if(WIN32)
4361
find_cuda_helper_libs(nvcuvenc)
4462
endif()
45-
if(CUDA_nvcuvid_LIBRARY)
63+
if(CUDA_nvcuvid_LIBRARY AND (${HAVE_NVCUVID_HEADER} OR ${HAVE_DYNLINK_NVCUVID_HEADER}))
64+
# make sure to have both header and library before enabling
4665
set(HAVE_NVCUVID 1)
4766
endif()
4867
if(CUDA_nvcuvenc_LIBRARY)

cmake/templates/cvconfig.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@
127127

128128
/* NVIDIA Video Decoding API*/
129129
#cmakedefine HAVE_NVCUVID
130+
#cmakedefine HAVE_NVCUVID_HEADER
131+
#cmakedefine HAVE_DYNLINK_NVCUVID_HEADER
130132

131133
/* NVIDIA Video Encoding API*/
132134
#cmakedefine HAVE_NVCUVENC

modules/cudacodec/src/cuvid_video_source.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
#ifndef __CUVID_VIDEO_SOURCE_HPP__
4545
#define __CUVID_VIDEO_SOURCE_HPP__
4646

47-
#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
47+
#if defined(HAVE_DYNLINK_NVCUVID_HEADER)
4848
#include <dynlink_nvcuvid.h>
49-
#else
49+
#elif defined(HAVE_NVCUVID_HEADER)
5050
#include <nvcuvid.h>
5151
#endif
5252
#include "opencv2/core/private.cuda.hpp"

modules/cudacodec/src/frame_queue.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
#include "opencv2/core/utility.hpp"
4848
#include "opencv2/core/private.cuda.hpp"
4949

50-
#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
50+
#if defined(HAVE_DYNLINK_NVCUVID_HEADER)
5151
#include <dynlink_nvcuvid.h>
52-
#else
52+
#elif defined(HAVE_NVCUVID_HEADER)
5353
#include <nvcuvid.h>
5454
#endif
5555

modules/cudacodec/src/precomp.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
#include "opencv2/core/private.cuda.hpp"
5757

5858
#ifdef HAVE_NVCUVID
59-
#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
59+
#if defined(HAVE_DYNLINK_NVCUVID_HEADER)
6060
#include <dynlink_nvcuvid.h>
61-
#else
61+
#elif defined(HAVE_NVCUVID_HEADER)
6262
#include <nvcuvid.h>
6363
#endif
6464

modules/cudacodec/src/video_decoder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
#ifndef __VIDEO_DECODER_HPP__
4545
#define __VIDEO_DECODER_HPP__
4646

47-
#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
47+
#if defined(HAVE_DYNLINK_NVCUVID_HEADER)
4848
#include <dynlink_nvcuvid.h>
49-
#else
49+
#elif defined(HAVE_NVCUVID_HEADER)
5050
#include <nvcuvid.h>
5151
#endif
5252

modules/cudacodec/src/video_parser.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@
4444
#ifndef __VIDEO_PARSER_HPP__
4545
#define __VIDEO_PARSER_HPP__
4646

47-
#if CUDA_VERSION >= 9000 && CUDA_VERSION < 10000
47+
#if defined(HAVE_DYNLINK_NVCUVID_HEADER)
4848
#include <dynlink_nvcuvid.h>
49-
#else
49+
#elif defined(HAVE_NVCUVID_HEADER)
5050
#include <nvcuvid.h>
5151
#endif
5252

0 commit comments

Comments
 (0)