Skip to content

Commit 44f8670

Browse files
committed
Merge pull request opencv#5171 from avershov:opencl-vaapi-interop
2 parents 1f7fc68 + a8656ea commit 44f8670

File tree

11 files changed

+1002
-0
lines changed

11 files changed

+1002
-0
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ OCV_OPTION(WITH_OPENCLAMDBLAS "Include AMD OpenCL BLAS library support" ON
205205
OCV_OPTION(WITH_DIRECTX "Include DirectX support" ON IF (WIN32 AND NOT WINRT) )
206206
OCV_OPTION(WITH_INTELPERC "Include Intel Perceptual Computing support" OFF IF (WIN32 AND NOT WINRT) )
207207
OCV_OPTION(WITH_IPP_A "Include Intel IPP_A support" OFF IF (MSVC OR X86 OR X86_64) )
208+
OCV_OPTION(WITH_VAAPI "Include VA-API support" OFF IF (UNIX AND NOT ANDROID) )
208209
OCV_OPTION(WITH_GDAL "Include GDAL Support" OFF IF (NOT ANDROID AND NOT IOS AND NOT WINRT) )
209210
OCV_OPTION(WITH_GPHOTO2 "Include gPhoto2 library support" ON IF (UNIX AND NOT ANDROID) )
210211

@@ -1065,6 +1066,10 @@ if(DEFINED WITH_IPP_A)
10651066
status(" Use IPP Async:" HAVE_IPP_A THEN "YES" ELSE NO)
10661067
endif(DEFINED WITH_IPP_A)
10671068

1069+
if(DEFINED WITH_VAAPI)
1070+
status(" Use Intel VA-API:" HAVE_VAAPI THEN "YES (MSDK: ${VAAPI_MSDK_ROOT} OpenCL: ${VAAPI_IOCL_ROOT})" ELSE NO)
1071+
endif(DEFINED WITH_VAAPI)
1072+
10681073
status(" Use Eigen:" HAVE_EIGEN THEN "YES (ver ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION})" ELSE NO)
10691074
status(" Use Cuda:" HAVE_CUDA THEN "YES (ver ${CUDA_VERSION_STRING})" ELSE NO)
10701075
status(" Use OpenCL:" HAVE_OPENCL THEN YES ELSE NO)

cmake/OpenCVFindLibsVideo.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,11 @@ ocv_clear_vars(HAVE_GPHOTO2)
317317
if(WITH_GPHOTO2)
318318
CHECK_MODULE(libgphoto2 HAVE_GPHOTO2)
319319
endif(WITH_GPHOTO2)
320+
321+
# --- VA-API ---
322+
if(WITH_VAAPI)
323+
include("${OpenCV_SOURCE_DIR}/cmake/OpenCVFindVAAPI.cmake")
324+
if(VAAPI_IOCL_INCLUDE_DIR)
325+
ocv_include_directories(${VAAPI_IOCL_INCLUDE_DIR})
326+
endif()
327+
endif(WITH_VAAPI)

cmake/OpenCVFindVAAPI.cmake

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Main variables:
2+
# VAAPI_MSDK_INCLUDE_DIR and VAAPI_IOCL_INCLUDE_DIR to use VAAPI
3+
# HAVE_VAAPI for conditional compilation OpenCV with/without VAAPI
4+
5+
# VAAPI_MSDK_ROOT - root of Intel MSDK installation
6+
# VAAPI_IOCL_ROOT - root of Intel OCL installation
7+
8+
if(UNIX AND NOT ANDROID)
9+
if($ENV{VAAPI_MSDK_ROOT})
10+
set(VAAPI_MSDK_ROOT $ENV{VAAPI_MSDK_ROOT})
11+
else()
12+
set(VAAPI_MSDK_ROOT "/opt/intel/mediasdk")
13+
endif()
14+
15+
if($ENV{VAAPI_IOCL_ROOT})
16+
set(VAAPI_IOCL_ROOT $ENV{VAAPI_IOCL_ROOT})
17+
else()
18+
set(VAAPI_IOCL_ROOT "/opt/intel/opencl")
19+
endif()
20+
21+
find_path(
22+
VAAPI_MSDK_INCLUDE_DIR
23+
NAMES mfxdefs.h
24+
PATHS ${VAAPI_MSDK_ROOT}
25+
PATH_SUFFIXES include
26+
DOC "Path to Intel MSDK headers")
27+
28+
find_path(
29+
VAAPI_IOCL_INCLUDE_DIR
30+
NAMES CL/va_ext.h
31+
PATHS ${VAAPI_IOCL_ROOT}
32+
PATH_SUFFIXES include
33+
DOC "Path to Intel OpenCL headers")
34+
endif()
35+
36+
if(VAAPI_MSDK_INCLUDE_DIR AND VAAPI_IOCL_INCLUDE_DIR)
37+
set(HAVE_VAAPI TRUE)
38+
set(VAAPI_EXTRA_LIBS "-lva" "-lva-drm")
39+
else()
40+
set(HAVE_VAAPI FALSE)
41+
message(WARNING "Intel MSDK & OpenCL installation is not found.")
42+
endif()
43+
44+
mark_as_advanced(FORCE VAAPI_MSDK_INCLUDE_DIR VAAPI_IOCL_INCLUDE_DIR)

cmake/templates/cvconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,6 @@
188188

189189
/* gPhoto2 library */
190190
#cmakedefine HAVE_GPHOTO2
191+
192+
/* Intel VA-API */
193+
#cmakedefine HAVE_VAAPI
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
// Copyright (C) 2015, Itseez, Inc., all rights reserved.
6+
// Third party copyrights are property of their respective owners.
7+
8+
#ifndef __OPENCV_CORE_VAAPI_HPP__
9+
#define __OPENCV_CORE_VAAPI_HPP__
10+
11+
#ifndef __cplusplus
12+
# error vaapi.hpp header must be compiled as C++
13+
#endif
14+
15+
#include "opencv2/core.hpp"
16+
#include "ocl.hpp"
17+
18+
#if defined(HAVE_VAAPI)
19+
# include "va/va.h"
20+
#else // HAVE_VAAPI
21+
# if !defined(_VA_H_)
22+
typedef void* VADisplay;
23+
typedef unsigned int VASurfaceID;
24+
# endif // !_VA_H_
25+
#endif // HAVE_VAAPI
26+
27+
namespace cv { namespace vaapi {
28+
29+
/** @addtogroup core_vaapi
30+
This section describes CL-VA (VA-API) interoperability.
31+
32+
To enable CL-VA interoperability support, configure OpenCV using CMake with WITH_VAAPI=ON . Currently VA-API is
33+
supported on Linux only. You should also install Intel Media Server Studio (MSS) to use this feature. You may
34+
have to specify the path(s) to MSS components for cmake in environment variables: VAAPI_MSDK_ROOT for Media SDK
35+
(default is "/opt/intel/mediasdk"), and VAAPI_IOCL_ROOT for Intel OpenCL (default is "/opt/intel/opencl").
36+
37+
To use VA-API interoperability you should first create VADisplay (libva), and then call initializeContextFromVA()
38+
function to create OpenCL context and set up interoperability.
39+
*/
40+
//! @{
41+
42+
/////////////////// CL-VA Interoperability Functions ///////////////////
43+
44+
namespace ocl {
45+
using namespace cv::ocl;
46+
47+
// TODO static functions in the Context class
48+
/** @brief Creates OpenCL context from VA.
49+
@param display - VADisplay for which CL interop should be established.
50+
@return Returns reference to OpenCL Context
51+
*/
52+
CV_EXPORTS Context& initializeContextFromVA(VADisplay display);
53+
54+
} // namespace cv::vaapi::ocl
55+
56+
/** @brief Converts InputArray to VASurfaceID object.
57+
@param src - source InputArray.
58+
@param surface - destination VASurfaceID object.
59+
@param size - size of image represented by VASurfaceID object.
60+
*/
61+
CV_EXPORTS void convertToVASurface(InputArray src, VASurfaceID surface, Size size);
62+
63+
/** @brief Converts VASurfaceID object to OutputArray.
64+
@param surface - source VASurfaceID object.
65+
@param size - size of image represented by VASurfaceID object.
66+
@param dst - destination OutputArray.
67+
*/
68+
CV_EXPORTS void convertFromVASurface(VASurfaceID surface, Size size, OutputArray dst);
69+
70+
//! @}
71+
72+
}} // namespace cv::vaapi
73+
74+
#endif /* __OPENCV_CORE_VAAPI_HPP__ */

modules/core/src/precomp.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "opencv2/core/core_c.h"
5151
#include "opencv2/core/cuda.hpp"
5252
#include "opencv2/core/opengl.hpp"
53+
#include "opencv2/core/vaapi.hpp"
5354

5455
#include "opencv2/core/private.hpp"
5556
#include "opencv2/core/private.cuda.hpp"

0 commit comments

Comments
 (0)