Skip to content

Commit

Permalink
Added 'NVPIPE_WITH_OPENGL' option
Browse files Browse the repository at this point in the history
  • Loading branch information
tbiedert committed Jun 11, 2018
1 parent 30c7bd8 commit c65d567
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -83,9 +84,9 @@ include(GNUInstallDirs)

cuda_add_library(${PROJECT_NAME} SHARED ${NVPIPE_SOURCES})
target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:src/NvCodec ${CUDA_INCLUDE_DIRS}>
$<BUILD_INTERFACE:src/NvCodec ${CUDA_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include>
)
)
target_link_libraries(${PROJECT_NAME} ${NVPIPE_LIBRARIES})

set_target_properties(${PROJECT_NAME} PROPERTIES
Expand Down Expand Up @@ -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()
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions src/NvPipe.cu
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@

#include <cuda.h>
#include <cuda_runtime_api.h>

#ifdef NVPIPE_WITH_OPENGL
#include <cuda_gl_interop.h>
#endif


class Exception
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -313,6 +317,7 @@ private:
};
std::unordered_map<uint32_t, RegisteredPBO> registeredPBOs;
};
#endif


#ifdef NVPIPE_WITH_ENCODER
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -451,6 +458,8 @@ public:
return size;
}

#endif

private:
void recreate(uint32_t width, uint32_t height)
{
Expand Down Expand Up @@ -577,7 +586,9 @@ private:
void* deviceBuffer = nullptr;
uint64_t deviceBufferSize = 0;

#ifdef NVPIPE_WITH_OPENGL
GraphicsResourceRegistry registry;
#endif
};
#endif

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -724,6 +737,8 @@ public:
return size;
}

#endif

private:
void recreate(uint32_t width, uint32_t height)
{
Expand Down Expand Up @@ -802,7 +817,9 @@ private:
void* deviceBuffer = nullptr;
uint64_t deviceBufferSize = 0;

#ifdef NVPIPE_WITH_OPENGL
GraphicsResourceRegistry registry;
#endif
};

#endif
Expand Down Expand Up @@ -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<Instance*>(nvp);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<Instance*>(nvp);
Expand Down Expand Up @@ -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<Instance*>(nvp);
Expand Down
9 changes: 9 additions & 0 deletions src/NvPipe.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#cmakedefine NVPIPE_WITH_ENCODER
#cmakedefine NVPIPE_WITH_DECODER
#cmakedefine NVPIPE_WITH_OPENGL

#ifdef _WIN32
# define NVPIPE_EXPORT __declspec(dllexport)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -130,6 +133,8 @@ NVPIPE_EXPORT uint64_t NvPipe_EncodePBO(NvPipe* nvp, uint32_t pbo, uint8_t* dst,

#endif

#endif

#ifdef NVPIPE_WITH_DECODER

/**
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c65d567

Please sign in to comment.