From c65d567bcc0b5c91cc3d31fe1276f675a248d036 Mon Sep 17 00:00:00 2001 From: Tim Biedert Date: Mon, 11 Jun 2018 14:45:37 +0200 Subject: [PATCH] Added 'NVPIPE_WITH_OPENGL' option --- CMakeLists.txt | 33 ++++++++++++++++++--------------- README.md | 2 ++ src/NvPipe.cu | 25 +++++++++++++++++++++++++ src/NvPipe.h.in | 9 +++++++++ 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 75338f1..7816712 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,12 +30,12 @@ project(NvPipe VERSION 1.0.0 LANGUAGES CXX) SET(DEFAULT_BUILD_TYPE "Release") if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") - set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE - STRING "Choose the type of build." FORCE) - # Set the possible values of build type for cmake-gui - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") + set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE + STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() find_package(CUDA REQUIRED) @@ -46,6 +46,7 @@ list(APPEND CUDA_NVCC_FLAGS "-std=c++11") # Options option(NVPIPE_WITH_ENCODER "Enables the NvPipe encoding interface." ON) option(NVPIPE_WITH_DECODER "Enables the NvPipe decoding interface." ON) +option(NVPIPE_WITH_OPENGL "Enables the NvPipe OpenGL interface." ON) option(NVPIPE_BUILD_EXAMPLES "Builds the NvPipe example applications (requires both encoder and decoder)." ON) # Header @@ -83,9 +84,9 @@ include(GNUInstallDirs) cuda_add_library(${PROJECT_NAME} SHARED ${NVPIPE_SOURCES}) target_include_directories(${PROJECT_NAME} PUBLIC - $ + $ $ -) + ) target_link_libraries(${PROJECT_NAME} ${NVPIPE_LIBRARIES}) set_target_properties(${PROJECT_NAME} PROPERTIES @@ -118,15 +119,17 @@ if (NVPIPE_BUILD_EXAMPLES) target_link_libraries(nvpExampleLossless PRIVATE ${PROJECT_NAME}) # EGL demo - list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/examples/cmake) + if (NVPIPE_WITH_OPENGL) + list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/examples/cmake) - find_package(EGL) - find_package(GLEW) + find_package(EGL) + find_package(GLEW) - if (EGL_FOUND AND GLEW_FOUND) - add_executable(nvpExampleEGL examples/egl.cpp) - target_include_directories(nvpExampleEGL PRIVATE ${EGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR}) - target_link_libraries(nvpExampleEGL PRIVATE ${PROJECT_NAME} ${EGL_LIBRARIES} ${GLEW_LIBRARIES}) + if (EGL_FOUND AND GLEW_FOUND) + add_executable(nvpExampleEGL examples/egl.cpp) + target_include_directories(nvpExampleEGL PRIVATE ${EGL_INCLUDE_DIR} ${GLEW_INCLUDE_DIR}) + target_link_libraries(nvpExampleEGL PRIVATE ${PROJECT_NAME} ${EGL_LIBRARIES} ${GLEW_LIBRARIES}) + endif() endif() endif() endif() diff --git a/README.md b/README.md index 33a64b5..83b2adf 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,8 @@ make install It is possible to compile the encoding or decoding interface only using the `NVPIPE_WITH_ENCODER` and `NVPIPE_WITH_DECODER` options (default: `ON`). +The OpenGL interface is optional and can be disabled using the `NVPIPE_WITH_OPENGL` option (default: `ON`). + The compilation of the included sample applications can be controlled via the `NVPIPE_BUILD_EXAMPLES` CMake option (default: `ON`). Only shared libraries are supported. diff --git a/src/NvPipe.cu b/src/NvPipe.cu index dcbb83c..12619cb 100644 --- a/src/NvPipe.cu +++ b/src/NvPipe.cu @@ -45,7 +45,10 @@ #include #include + +#ifdef NVPIPE_WITH_OPENGL #include +#endif class Exception @@ -230,6 +233,7 @@ void nv12_to_uint16(const uint8_t* src, uint32_t srcPitch, uint8_t* dst, uint32_ +#ifdef NVPIPE_WITH_OPENGL /** * @brief Utility class for managing CUDA-GL interop graphics resources. */ @@ -313,6 +317,7 @@ private: }; std::unordered_map registeredPBOs; }; +#endif #ifdef NVPIPE_WITH_ENCODER @@ -399,6 +404,8 @@ public: return this->encode(dst, dstSize); } +#ifdef NVPIPE_WITH_OPENGL + uint64_t encodeTexture(uint32_t texture, uint32_t target, uint8_t* dst, uint64_t dstSize, uint32_t width, uint32_t height) { if (this->format != NVPIPE_RGBA32) @@ -451,6 +458,8 @@ public: return size; } +#endif + private: void recreate(uint32_t width, uint32_t height) { @@ -577,7 +586,9 @@ private: void* deviceBuffer = nullptr; uint64_t deviceBufferSize = 0; +#ifdef NVPIPE_WITH_OPENGL GraphicsResourceRegistry registry; +#endif }; #endif @@ -665,6 +676,8 @@ public: return 0; } +#ifdef NVPIPE_WITH_OPENGL + uint64_t decodeTexture(const uint8_t* src, uint64_t srcSize, uint32_t texture, uint32_t target, uint32_t width, uint32_t height) { if (this->format != NVPIPE_RGBA32) @@ -724,6 +737,8 @@ public: return size; } +#endif + private: void recreate(uint32_t width, uint32_t height) { @@ -802,7 +817,9 @@ private: void* deviceBuffer = nullptr; uint64_t deviceBufferSize = 0; +#ifdef NVPIPE_WITH_OPENGL GraphicsResourceRegistry registry; +#endif }; #endif @@ -871,6 +888,8 @@ NVPIPE_EXPORT uint64_t NvPipe_Encode(NvPipe* nvp, const void* src, uint8_t* dst, } } +#ifdef NVPIPE_WITH_OPENGL + NVPIPE_EXPORT uint64_t NvPipe_EncodeTexture(NvPipe* nvp, uint32_t texture, uint32_t target, uint8_t* dst, uint64_t dstSize, uint32_t width, uint32_t height) { Instance* instance = static_cast(nvp); @@ -913,6 +932,8 @@ NVPIPE_EXPORT uint64_t NvPipe_EncodePBO(NvPipe* nvp, uint32_t pbo, uint8_t* dst, #endif +#endif + #ifdef NVPIPE_WITH_DECODER NVPIPE_EXPORT NvPipe* NvPipe_CreateDecoder(NvPipe_Format format, NvPipe_Codec codec) @@ -953,6 +974,8 @@ NVPIPE_EXPORT uint64_t NvPipe_Decode(NvPipe* nvp, const uint8_t* src, uint64_t s } } +#ifdef NVPIPE_WITH_OPENGL + NVPIPE_EXPORT uint64_t NvPipe_DecodeTexture(NvPipe* nvp, const uint8_t* src, uint64_t srcSize, uint32_t texture, uint32_t target, uint32_t width, uint32_t height) { Instance* instance = static_cast(nvp); @@ -995,6 +1018,8 @@ NVPIPE_EXPORT uint64_t NvPipe_DecodePBO(NvPipe* nvp, const uint8_t* src, uint64_ #endif +#endif + NVPIPE_EXPORT void NvPipe_Destroy(NvPipe* nvp) { Instance* instance = static_cast(nvp); diff --git a/src/NvPipe.h.in b/src/NvPipe.h.in index 4cc462e..25ccf49 100644 --- a/src/NvPipe.h.in +++ b/src/NvPipe.h.in @@ -33,6 +33,7 @@ #cmakedefine NVPIPE_WITH_ENCODER #cmakedefine NVPIPE_WITH_DECODER +#cmakedefine NVPIPE_WITH_OPENGL #ifdef _WIN32 # define NVPIPE_EXPORT __declspec(dllexport) @@ -102,6 +103,8 @@ NVPIPE_EXPORT NvPipe* NvPipe_CreateEncoder(NvPipe_Format format, NvPipe_Codec co NVPIPE_EXPORT uint64_t NvPipe_Encode(NvPipe* nvp, const void* src, uint8_t* dst, uint64_t dstSize, uint32_t width, uint32_t height); +#ifdef NVPIPE_WITH_OPENGL + /** * @brief encodeTexture Encodes a single frame from an OpenGL texture. * @param nvp Encoder instance. @@ -130,6 +133,8 @@ NVPIPE_EXPORT uint64_t NvPipe_EncodePBO(NvPipe* nvp, uint32_t pbo, uint8_t* dst, #endif +#endif + #ifdef NVPIPE_WITH_DECODER /** @@ -154,6 +159,8 @@ NVPIPE_EXPORT NvPipe* NvPipe_CreateDecoder(NvPipe_Format format, NvPipe_Codec co NVPIPE_EXPORT uint64_t NvPipe_Decode(NvPipe* nvp, const uint8_t* src, uint64_t srcSize, void* dst, uint32_t width, uint32_t height); +#ifdef NVPIPE_WITH_OPENGL + /** * @brief Decodes a single frame to an OpenGL texture. * @param nvp Decoder instance. @@ -182,6 +189,8 @@ NVPIPE_EXPORT uint64_t NvPipe_DecodePBO(NvPipe* nvp, const uint8_t* src, uint64_ #endif +#endif + /** * @brief Cleans up an encoder or decoder instance.