Skip to content

Commit a604d44

Browse files
Merge pull request opencv#19755 from mikhail-nikolskiy:ffmpeg-umat
cv::UMat output/input in VideoCapture/VideoWriter (data stays in GPU memory) * FFMPEG with UMat input/output * OpenCL_D3D* context * fix Linux build * cosmetic changes * fix build if USE_AV_HW_CODECS=0 * simplify how child context pointer stored in parent context * QSV interop with OpenCL on Windows * detect_msdk.cmake via pkg-config * fix av_buffer_ref() usage * revert windows-decode-mfx whitelisting; remove debug msg * address review comments * rename property to HW_ACCELERATION_USE_OPENCL * fix issue with "cl_khr_d3d11_sharing" extension not reported by OpenCL GPU+CPU platform * core(ocl): add OpenCL stubs for configurations without OpenCL * videoio(ffmpeg): update #if guards * Put OpenCL related code under HAVE_OPENCL; simplify reuse of media context from OpenCL context * videoio(test): skip unsupported tests - plugins don't support OpenCL/UMat yet - change handling of *_USE_OPENCL flag * videoio(ffmpeg): OpenCL dependency * videoio(ffmpeg): MediaSDK/oneVPL dependency * cleanup, logging * cmake: fix handling of 3rdparty interface targets Co-authored-by: Alexander Alekhin <[email protected]>
1 parent bb92eb5 commit a604d44

17 files changed

+1314
-750
lines changed

CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,16 @@ if(WITH_LIBREALSENSE OR HAVE_LIBREALSENSE)
14311431
endif()
14321432

14331433
if(WITH_MFX OR HAVE_MFX)
1434-
status(" Intel Media SDK:" HAVE_MFX THEN "YES (${MFX_LIBRARY})" ELSE NO)
1434+
if(HAVE_MFX)
1435+
if(MFX_LIBRARY)
1436+
set(__details " (${MFX_LIBRARY})")
1437+
elseif(MFX_LIBRARIES)
1438+
set(__details " (${MFX_LIBRARIES})")
1439+
else()
1440+
set(__details " (unknown)")
1441+
endif()
1442+
endif()
1443+
status(" Intel Media SDK:" HAVE_MFX THEN "YES${__details}" ELSE NO)
14351444
endif()
14361445

14371446
if(WITH_GPHOTO2 OR HAVE_GPHOTO2)

cmake/OpenCVUtils.cmake

+34-15
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,9 @@ macro(ocv_check_modules define)
866866
foreach(flag ${${define}_LDFLAGS})
867867
if(flag MATCHES "^-L(.*)")
868868
list(APPEND _libs_paths ${CMAKE_MATCH_1})
869-
elseif(IS_ABSOLUTE "${flag}")
869+
elseif(IS_ABSOLUTE "${flag}"
870+
OR flag STREQUAL "-lstdc++"
871+
)
870872
list(APPEND _libs "${flag}")
871873
elseif(flag MATCHES "^-l(.*)")
872874
set(_lib "${CMAKE_MATCH_1}")
@@ -1578,24 +1580,41 @@ endfunction()
15781580

15791581

15801582
function(ocv_add_external_target name inc link def)
1581-
if(BUILD_SHARED_LIBS)
1583+
if(BUILD_SHARED_LIBS AND link)
15821584
set(imp IMPORTED)
15831585
endif()
15841586
add_library(ocv.3rdparty.${name} INTERFACE ${imp})
1585-
set_target_properties(ocv.3rdparty.${name} PROPERTIES
1586-
INTERFACE_INCLUDE_DIRECTORIES "${inc}"
1587-
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${inc}"
1588-
INTERFACE_COMPILE_DEFINITIONS "${def}")
1589-
# When cmake version is greater than or equal to 3.11, INTERFACE_LINK_LIBRARIES no longer applies to interface library
1590-
# See https://github.com/opencv/opencv/pull/18658
1591-
if (CMAKE_VERSION VERSION_LESS 3.11)
1592-
set_target_properties(ocv.3rdparty.${name} PROPERTIES
1593-
INTERFACE_LINK_LIBRARIES "${link}")
1594-
else()
1595-
target_link_libraries(ocv.3rdparty.${name} INTERFACE ${link})
1587+
if(def)
1588+
if(NOT (CMAKE_VERSION VERSION_LESS "3.11.0")) # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1264 : eliminates "Cannot specify compile definitions for imported target" error message
1589+
target_compile_definitions(ocv.3rdparty.${name} INTERFACE "${def}")
1590+
else()
1591+
set_target_properties(ocv.3rdparty.${name} PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${def}")
1592+
endif()
1593+
endif()
1594+
if(inc)
1595+
if(NOT (CMAKE_VERSION VERSION_LESS "3.11.0")) # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/1264 : eliminates "Cannot specify compile definitions for imported target" error message
1596+
target_include_directories(ocv.3rdparty.${name} SYSTEM INTERFACE "$<BUILD_INTERFACE:${inc}>")
1597+
else()
1598+
set_target_properties(ocv.3rdparty.${name} PROPERTIES
1599+
INTERFACE_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${inc}>"
1600+
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<BUILD_INTERFACE:${inc}>"
1601+
)
1602+
endif()
1603+
endif()
1604+
if(link)
1605+
# When cmake version is greater than or equal to 3.11, INTERFACE_LINK_LIBRARIES no longer applies to interface library
1606+
# See https://github.com/opencv/opencv/pull/18658
1607+
if(CMAKE_VERSION VERSION_LESS 3.11)
1608+
set_target_properties(ocv.3rdparty.${name} PROPERTIES
1609+
INTERFACE_LINK_LIBRARIES "${link}")
1610+
else()
1611+
target_link_libraries(ocv.3rdparty.${name} INTERFACE ${link})
1612+
endif()
15961613
endif()
1597-
#
1598-
if(NOT BUILD_SHARED_LIBS)
1614+
# to install used target only upgrade CMake
1615+
if(NOT BUILD_SHARED_LIBS
1616+
AND CMAKE_VERSION VERSION_LESS "3.13.0" # https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
1617+
)
15991618
install(TARGETS ocv.3rdparty.${name} EXPORT OpenCVModules)
16001619
endif()
16011620
endfunction()

modules/core/include/opencv2/core/ocl.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#define OPENCV_OPENCL_HPP
4444

4545
#include "opencv2/core.hpp"
46+
#include <typeinfo>
47+
#include <typeindex>
4648

4749
namespace cv { namespace ocl {
4850

@@ -277,6 +279,12 @@ class CV_EXPORTS Context
277279
/** @returns cl_context value */
278280
void* ptr() const;
279281

282+
/**
283+
* @brief Get OpenCL context property specified on context creation
284+
* @param propertyId Property id (CL_CONTEXT_* as defined in cl_context_properties type)
285+
* @returns Property value if property was specified on clCreateContext, or NULL if context created without the property
286+
*/
287+
void* getOpenCLContextProperty(int propertyId) const;
280288

281289
bool useSVM() const;
282290
void setUseSVM(bool enabled);
@@ -290,6 +298,21 @@ class CV_EXPORTS Context
290298

291299
void release();
292300

301+
class CV_EXPORTS UserContext {
302+
public:
303+
virtual ~UserContext();
304+
};
305+
template <typename T>
306+
inline void setUserContext(const std::shared_ptr<T>& userContext) {
307+
setUserContext(typeid(T), userContext);
308+
}
309+
template <typename T>
310+
inline std::shared_ptr<T> getUserContext() {
311+
return std::dynamic_pointer_cast<T>(getUserContext(typeid(T)));
312+
}
313+
void setUserContext(std::type_index typeId, const std::shared_ptr<UserContext>& userContext);
314+
std::shared_ptr<UserContext> getUserContext(std::type_index typeId);
315+
293316
struct Impl;
294317
inline Impl* getImpl() const { return (Impl*)p; }
295318
inline bool empty() const { return !p; }

0 commit comments

Comments
 (0)