-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
15 changed files
with
252 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
|
||
project(pynvbufsurfacegenerator VERSION "0.0.1" LANGUAGES CXX CUDA) | ||
|
||
set(python_module_name pynvbufsurfacegenerator) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" ) | ||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" ) | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
set(CMAKE_BUILD_TYPE Release) | ||
endif() | ||
|
||
set(CMAKE_CXX_FLAGS "-O3") | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O3") | ||
|
||
find_package(PkgConfig REQUIRED) | ||
find_package(CUDA REQUIRED) | ||
find_package(Python3 COMPONENTS Interpreter Development REQUIRED) | ||
find_package(pybind11 CONFIG REQUIRED) | ||
|
||
if(NOT DEFINED DeepStream_DIR) | ||
set(DeepStream_DIR /opt/nvidia/deepstream/deepstream) | ||
endif() | ||
|
||
pkg_check_modules(GLIB REQUIRED glib-2.0) | ||
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0) | ||
|
||
include_directories( | ||
${Python3_INCLUDE_DIRS} | ||
${GLIB_INCLUDE_DIRS} | ||
${GSTREAMER_INCLUDE_DIRS} | ||
${CUDA_INCLUDE_DIRS} | ||
${DeepStream_DIR}/sources/includes | ||
${CMAKE_SOURCE_DIR}/nvbufsurfacegenerator/include | ||
${CMAKE_SOURCE_DIR}/pynvbufsurfacegenerator | ||
) | ||
|
||
link_directories( | ||
${Python3_LIBRARY_DIRS} | ||
${GLIB_LIBRARY_DIRS} | ||
${GSTREAMER_LIBRARY_DIRS} | ||
${CUDA_LIBRARY_DIRS} | ||
${DeepStream_DIR}/lib | ||
) | ||
|
||
add_subdirectory(nvbufsurfacegenerator ../build/nvbufsurfacegenerator) | ||
|
||
set(SOURCE_FILES | ||
"nvbufsurfacegenerator/src/nvbufsurface_generator.cpp" | ||
) | ||
set(HEADER_FILES | ||
"nvbufsurfacegenerator/include/nvbufsurface_generator.h" | ||
) | ||
|
||
file (GLOB PYTHON_FILES "pynvbufsurfacegenerator/*.cpp" "pynvbufsurfacegenerator/*.h") | ||
|
||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES} ${HEADER_FILES} ${PYTHON_FILES} ) | ||
|
||
pybind11_add_module(${python_module_name} SHARED | ||
${SOURCE_FILES} | ||
${HEADER_FILES} | ||
${PYTHON_FILES} | ||
) | ||
|
||
target_link_libraries(${python_module_name} PRIVATE | ||
${Python3_LIBRARIES} | ||
${GLIB_LIBRARIES} | ||
${GSTREAMER_LIBRARIES} | ||
${CUDA_LIBRARIES} | ||
nvdsbufferpool | ||
nvbufsurfacegenerator | ||
pybind11::module | ||
pybind11::lto | ||
) | ||
|
||
pybind11_extension(${python_module_name}) | ||
pybind11_strip(${python_module_name}) | ||
|
||
install(TARGETS ${python_module_name} DESTINATION .) |
57 changes: 57 additions & 0 deletions
57
libs/nvbufsurfacegenerator/nvbufsurfacegenerator/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
|
||
project(nvbufsurfacegenerator VERSION "0.0.1" LANGUAGES CXX CUDA) | ||
|
||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" ) | ||
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" ) | ||
|
||
find_package(PkgConfig REQUIRED) | ||
find_package(CUDA REQUIRED) | ||
find_package(Python3 COMPONENTS Interpreter Development REQUIRED) | ||
|
||
if (NOT DEFINED DeepStream_DIR) | ||
set(DeepStream_DIR /opt/nvidia/deepstream/deepstream) | ||
endif() | ||
|
||
pkg_check_modules(GLIB REQUIRED glib-2.0) | ||
pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0) | ||
|
||
include_directories( | ||
${GLIB_INCLUDE_DIRS} | ||
${GSTREAMER_INCLUDE_DIRS} | ||
${CUDA_INCLUDE_DIRS} | ||
${DeepStream_DIR}/sources/includes | ||
) | ||
|
||
link_directories( | ||
${GLIB_LIBRARY_DIRS} | ||
${GSTREAMER_LIBRARY_DIRS} | ||
${CUDA_LIBRARY_DIRS} | ||
${DeepStream_DIR}/lib | ||
) | ||
|
||
AUX_SOURCE_DIRECTORY(src SRC_FILES) | ||
|
||
set(PROJECT_SOURCE_DIR "src") | ||
set(PROJECT_INCLUDE_DIR "include") | ||
|
||
set(SOURCE_FILES | ||
${PROJECT_INCLUDE_DIR}/nvbufsurface_generator.h | ||
${PROJECT_SOURCE_DIR}/nvbufsurface_generator.cpp | ||
) | ||
|
||
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES}) | ||
|
||
add_library(nvbufsurfacegenerator SHARED ${SOURCE_FILES}) | ||
target_link_libraries( | ||
nvbufsurfacegenerator | ||
${GLIB_LIBRARIES} | ||
${GSTREAMER_LIBRARIES} | ||
${CUDA_LIBRARIES} | ||
nvdsbufferpool | ||
) | ||
|
||
target_include_directories(nvbufsurfacegenerator PUBLIC include) | ||
|
||
install(TARGETS nvbufsurfacegenerator LIBRARY PUBLIC_HEADER) |
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions
27
libs/nvbufsurfacegenerator/pynvbufsurfacegenerator/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import gi | ||
|
||
from . import pynvbufsurfacegenerator | ||
|
||
gi.require_version('Gst', '1.0') | ||
from gi.repository import Gst | ||
|
||
|
||
class NvBufSurfaceGenerator: | ||
"""Generates GStreamer buffers with NvBufSurface memory allocated. | ||
:param caps: Caps for the generated buffers. | ||
:param gpu_id: ID of the GPU to allocate NvBufSurface. | ||
:param mem_type: Memory type for the NvBufSurface. | ||
""" | ||
|
||
def __init__(self, caps: Gst.Caps, gpu_id: int, mem_type: int): | ||
self._nested = pynvbufsurfacegenerator.NvBufSurfaceGenerator( | ||
hash(caps), gpu_id, mem_type | ||
) | ||
|
||
def create_surface(self, buffer: Gst.Buffer): | ||
"""Create a new NvBufSurface and attach it to the given buffer. | ||
:param buffer: Buffer to attach the NvBufSurface to. | ||
""" | ||
return self._nested.create_surface(hash(buffer)) |
Oops, something went wrong.