From 22bb5d1fcce7b80d08f0bbcf4970926f35cde2de Mon Sep 17 00:00:00 2001 From: Alexey Ershov Date: Thu, 10 Sep 2015 19:30:19 +0300 Subject: [PATCH] implemented sample build in fallback mode without interop --- cmake/OpenCVFindVA.cmake | 2 +- samples/CMakeLists.txt | 2 +- samples/va_intel/CMakeLists.txt | 2 +- samples/va_intel/display.cpp.inc | 79 ++++++++++++++++++++++++--- samples/va_intel/va_intel_interop.cpp | 14 +++++ 5 files changed, 88 insertions(+), 11 deletions(-) diff --git a/cmake/OpenCVFindVA.cmake b/cmake/OpenCVFindVA.cmake index 03e24a0346..96df665f8c 100644 --- a/cmake/OpenCVFindVA.cmake +++ b/cmake/OpenCVFindVA.cmake @@ -12,7 +12,7 @@ endif() if(VA_INCLUDE_DIR) set(HAVE_VA TRUE) - set(VA_LIBRARIES "-lva") + set(VA_LIBRARIES "-lva" "-lva-x11") else() set(HAVE_VA FALSE) message(WARNING "libva installation is not found.") diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 216b21eda2..2b0e74ccdf 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -22,7 +22,7 @@ if((NOT ANDROID) AND HAVE_OPENGL) add_subdirectory(opengl) endif() -if(UNIX AND NOT ANDROID AND HAVE_VA_INTEL) +if(UNIX AND NOT ANDROID AND (HAVE_VA OR HAVE_VA_INTEL)) add_subdirectory(va_intel) endif() diff --git a/samples/va_intel/CMakeLists.txt b/samples/va_intel/CMakeLists.txt index 13d701d418..ddf63edb43 100644 --- a/samples/va_intel/CMakeLists.txt +++ b/samples/va_intel/CMakeLists.txt @@ -17,7 +17,7 @@ if(BUILD_EXAMPLES AND OCV_DEPENDENCIES_FOUND) set(the_target "example_${project}_${name}") add_executable(${the_target} ${srcs}) - ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS} ${VA_INTEL_LIBRARIES}) + ocv_target_link_libraries(${the_target} ${OPENCV_LINKER_LIBS} ${OPENCV_VA_INTEL_SAMPLES_REQUIRED_DEPS} ${VA_LIBRARIES} ${VA_INTEL_LIBRARIES}) set_target_properties(${the_target} PROPERTIES OUTPUT_NAME "${project}-example-${name}" diff --git a/samples/va_intel/display.cpp.inc b/samples/va_intel/display.cpp.inc index ccf4aac5a7..f8aeb00e7b 100644 --- a/samples/va_intel/display.cpp.inc +++ b/samples/va_intel/display.cpp.inc @@ -7,24 +7,38 @@ #include #include +#include "cvconfig.h" + #include -#include +#if defined(HAVE_VA_INTEL) +# include +#elif defined(HAVE_VA) +# include +# include +#endif //HAVE_VA_INTEL / HAVE_VA + +namespace va { + +#if defined(HAVE_VA_INTEL) || defined(HAVE_VA) + +bool openDisplay(); +void closeDisplay(); + +VADisplay display = NULL; +bool initialized = false; + +#endif //HAVE_VA_INTEL || HAVE_VA + +#if defined(HAVE_VA_INTEL) #define VA_INTEL_PCI_DIR "/sys/bus/pci/devices" #define VA_INTEL_DRI_DIR "/dev/dri/" #define VA_INTEL_PCI_DISPLAY_CONTROLLER_CLASS 0x03 -namespace va { - static unsigned readId(const char* devName, const char* idName); static int findAdapter(unsigned desiredVendorId); -bool openDisplay(); -void closeDisplay(); - int drmfd = -1; -VADisplay display = NULL; -bool initialized = false; class Directory { @@ -205,4 +219,53 @@ void closeDisplay() } } +#elif defined(HAVE_VA) + +static Display* x11Display = 0; + +bool openDisplay() +{ + if (!initialized) + { + display = 0; + + x11Display = XOpenDisplay(""); + if (x11Display != 0) + { + display = vaGetDisplay(x11Display); + if (display) + { + int majorVersion = 0, minorVersion = 0; + if (vaInitialize(display, &majorVersion, &minorVersion) == VA_STATUS_SUCCESS) + { + initialized = true; + return true; + } + display = 0; + } + XCloseDisplay(x11Display); + x11Display = 0; + } + + return false; // Can't initialize X11/VA display + } + return true; +} + +void closeDisplay() +{ + if (initialized) + { + if (display) + vaTerminate(display); + if (x11Display) + XCloseDisplay(x11Display); + display = 0; + x11Display = 0; + initialized = false; + } +} + +#endif // HAVE_VA_INTEL / HAVE_VA + } // namespace va diff --git a/samples/va_intel/va_intel_interop.cpp b/samples/va_intel/va_intel_interop.cpp index 1175a14aab..996ac375eb 100644 --- a/samples/va_intel/va_intel_interop.cpp +++ b/samples/va_intel/va_intel_interop.cpp @@ -42,6 +42,7 @@ #include "opencv2/core.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/core/va_intel.hpp" +#include "cvconfig.h" #define CHECK_VASTATUS(va_status,func) \ if (va_status != VA_STATUS_SUCCESS) { \ @@ -362,14 +363,20 @@ public: { int n = 0; m_files[0] = m_files[1] = 0; +#if defined(HAVE_VA_INTEL) m_interop = true; +#elif defined(HAVE_VA) + m_interop = false; +#endif //HAVE_VA_INTEL / HAVE_VA for (int i = 1; i < m_argc; ++i) { const char *arg = m_argv[i]; if (arg[0] == '-') // option { +#if defined(HAVE_VA_INTEL) if (!strcmp(arg, "-f")) m_interop = false; +#endif //HAVE_VA_INTEL } else // parameter { @@ -400,8 +407,15 @@ int main(int argc, char** argv) if (!cmd.run()) { fprintf(stderr, +#if defined(HAVE_VA_INTEL) "Usage: va_intel_interop [-f] file1 file2\n\n" + "Interop ON/OFF version\n\n" "where: -f option indicates interop is off (fallback mode); interop is on by default\n" +#elif defined(HAVE_VA) + "Usage: va_intel_interop file1 file2\n\n" + "Interop OFF only version\n\n" + "where:\n" +#endif //HAVE_VA_INTEL / HAVE_VA " file1 is to be created, contains original surface data (NV12)\n" " file2 is to be created, contains processed surface data (NV12)\n"); exit(0);