Skip to content
Snippets Groups Projects
Commit b0f9b9a3 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Resolves #274 compression filtering

parent 1a3995aa
No related branches found
No related tags found
No related merge requests found
Showing
with 2283 additions and 36 deletions
......@@ -56,7 +56,7 @@ webserver-deploy:
- mkdir build
- cd build
- echo cmake %CMAKE_ARGS% %CMAKE_ARGS_WINDOWS% -DNANOGUI_DIR="C:/Program Files (x86)/NanoGUI" ..
- cmake %CMAKE_ARGS% %CMAKE_ARGS_WINDOWS% -DREALSENSE_DIR="C:/Program Files (x86)/Intel RealSense SDK 2.0" -DNANOGUI_DIR="C:/Program Files (x86)/NanoGUI" ..
- cmake %CMAKE_ARGS% %CMAKE_ARGS_WINDOWS% -DREALSENSE_DIR="C:/Program Files (x86)/Intel RealSense SDK 2.0" -DNANOGUI_DIR="C:/Program Files (x86)/NanoGUI" -DOPUS_DIR="C:/Program Files (x86)/Opus" ..
- devenv ftl.utu.fi.sln /build Release
- rmdir /q /s "%DEPLOY_DIR%/%CI_COMMIT_REF_SLUG%"
- mkdir "%DEPLOY_DIR%/%CI_COMMIT_REF_SLUG%"
......
......@@ -118,19 +118,25 @@ endif()
if (WITH_OPUS)
find_library( OPUS_LIBRARY NAMES opus PATHS ${OPUS_DIR} PATH_SUFFIXES lib)
find_path( OPUS_INCLUDE NAMES opus/opus.h)
if (OPUS_LIBRARY AND OPUS_INCLUDE)
set(HAVE_OPUS TRUE)
add_library(Opus UNKNOWN IMPORTED)
#set_property(TARGET nanogui PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NANOGUI_EXTRA_INCS})
set_property(TARGET Opus PROPERTY IMPORTED_LOCATION ${OPUS_LIBRARY})
message(STATUS "Found Opus: ${OPUS_LIBRARY}")
if (OPUS_LIBRARY)
find_path( OPUS_INCLUDE NAMES opus/opus.h)
if (WIN32 OR OPUS_INCLUDE)
set(HAVE_OPUS TRUE)
add_library(Opus UNKNOWN IMPORTED)
#set_property(TARGET nanogui PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NANOGUI_EXTRA_INCS})
set_property(TARGET Opus PROPERTY IMPORTED_LOCATION ${OPUS_LIBRARY})
message(STATUS "Found Opus: ${OPUS_LIBRARY}")
else()
message(STATUS "Opus headers not installed")
endif()
if(WIN32)
# Find include
find_path(OPUS_INCLUDE_DIRS
NAMES opus/opus.h
#PATHS "C:/Program Files/OpenVRSDK" "C:/Program Files (x86)/OpenVRSDK" ${OPENVR_DIR}
PATHS "C:/Program Files/Opus" "C:/Program Files (x86)/Opus" ${OPUS_DIR}
PATH_SUFFIXES include
)
set_property(TARGET Opus PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${OPUS_INCLUDE_DIRS})
......@@ -162,6 +168,8 @@ else()
add_library(sgm INTERFACE)
endif()
# ==== Ceres ===================================================================
if (WITH_CERES)
find_package(Ceres REQUIRED)
set(HAVE_CERES true)
......@@ -169,6 +177,8 @@ else()
add_library(ceres INTERFACE)
endif()
# ==============================================================================
if(${CMAKE_VERSION} VERSION_GREATER "3.12.0")
cmake_policy(SET CMP0074 NEW)
endif()
......@@ -187,6 +197,8 @@ else()
endif()
endif()
# ==== Realsense ===============================================================
find_library( REALSENSE_LIBRARY NAMES realsense2 librealsense2 PATHS ${REALSENSE_DIR} PATH_SUFFIXES lib/x64)
if (REALSENSE_LIBRARY)
set(HAVE_REALSENSE TRUE)
......@@ -209,6 +221,8 @@ else()
add_library(realsense INTERFACE)
endif()
# ==============================================================================
if (BUILD_GUI)
set(HAVE_NANOGUI TRUE)
......@@ -225,27 +239,7 @@ if (BUILD_GUI)
set_property(TARGET glfw glfw_objects nanogui PROPERTY FOLDER "dependencies")
endif()
find_library( NVPIPE_LIBRARY NAMES NvPipe libNvPipe PATHS ${NVPIPE_DIR} PATH_SUFFIXES lib)
if (NVPIPE_LIBRARY)
set(HAVE_NVPIPE TRUE)
add_library(nvpipe UNKNOWN IMPORTED)
#set_property(TARGET nanogui PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NANOGUI_EXTRA_INCS})
set_property(TARGET nvpipe PROPERTY IMPORTED_LOCATION ${NVPIPE_LIBRARY})
message(STATUS "Found NvPipe: ${NVPIPE_LIBRARY}")
if(WIN32)
# Find include
find_path(NVPIPE_INCLUDE_DIRS
NAMES NvPipe.h
PATHS "C:/Program Files/NvPipe" "C:/Program Files (x86)/NvPipe" ${NVPIPE_DIR}
PATH_SUFFIXES include
)
set_property(TARGET nvpipe PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NVPIPE_INCLUDE_DIRS})
endif()
else()
set(NVPIPE_LIBRARY "")
add_library(nvpipe INTERFACE)
endif()
# ==== Portaudio v19 ===========================================================
# Portaudio v19 library
find_library( PORTAUDIO_LIBRARY NAMES portaudio PATHS ${PORTAUDIO_DIR} PATH_SUFFIXES lib)
......@@ -271,6 +265,8 @@ else()
message(WARNING "Portaudio not found - sound disabled")
endif()
# ==============================================================================
# Assimp library
#find_library( ASSIMP_LIBRARY NAMES assimp PATHS ${PORTAUDIO_DIR} PATH_SUFFIXES lib)
#if (ASSIMP_LIBRARY)
......@@ -392,7 +388,7 @@ if (WIN32) # TODO(nick) Should do based upon compiler (VS)
set(OS_LIBS "")
else()
add_definitions(-DUNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fPIC -msse3 -Werror -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fPIC -msse3 -Wall")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -pg")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -mfpmath=sse")
set(OS_LIBS "dl")
......@@ -401,6 +397,33 @@ endif()
SET(CMAKE_USE_RELATIVE_PATHS ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# ==== NvPipe ==================================================================
add_subdirectory(lib/nvpipe)
#find_library( NVPIPE_LIBRARY NAMES NvPipe libNvPipe PATHS ${NVPIPE_DIR} PATH_SUFFIXES lib)
#if (NVPIPE_LIBRARY)
set(HAVE_NVPIPE TRUE)
# add_library(nvpipe UNKNOWN IMPORTED)
#set_property(TARGET nanogui PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NANOGUI_EXTRA_INCS})
# set_property(TARGET nvpipe PROPERTY IMPORTED_LOCATION ${NVPIPE_LIBRARY})
# message(STATUS "Found NvPipe: ${NVPIPE_LIBRARY}")
# if(WIN32)
# Find include
# find_path(NVPIPE_INCLUDE_DIRS
# NAMES NvPipe.h
# PATHS "C:/Program Files/NvPipe" "C:/Program Files (x86)/NvPipe" ${NVPIPE_DIR}
# PATH_SUFFIXES include
# )
# set_property(TARGET nvpipe PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NVPIPE_INCLUDE_DIRS})
# endif()
#else()
# set(NVPIPE_LIBRARY "")
# add_library(nvpipe INTERFACE)
#endif()
add_subdirectory(components/common/cpp)
add_subdirectory(applications/calibration)
add_subdirectory(components/codecs)
......
......@@ -10,8 +10,10 @@ add_library(BaseCodec OBJECT
)
target_include_directories(BaseCodec PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src/Video_Codec_SDK_9.1.23/include
${CMAKE_CURRENT_SOURCE_DIR}/src/Video_Codec_SDK_9.1.23/Samples/NvCodec
$<TARGET_PROPERTY:ftlcommon,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:nvpipe,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:NvPipe,INTERFACE_INCLUDE_DIRECTORIES>
)
add_library(OpenCVCodec OBJECT
......@@ -32,24 +34,35 @@ if (HAVE_NVPIPE)
add_library(NvPipeCodec OBJECT
src/nvpipe_encoder.cpp
src/nvpipe_decoder.cpp
src/Video_Codec_SDK_9.1.23/Samples/NvCodec/NvDecoder/NvDecoder.cpp
)
target_include_directories(NvPipeCodec PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src/Video_Codec_SDK_9.1.23/include
${CMAKE_CURRENT_SOURCE_DIR}/src/Video_Codec_SDK_9.1.23/Samples/NvCodec
$<TARGET_PROPERTY:ftlcommon,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:nvpipe,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:NvPipe,INTERFACE_INCLUDE_DIRECTORIES>
)
list(APPEND CODECSRC $<TARGET_OBJECTS:NvPipeCodec>)
endif()
add_library(ftlcodecs ${CODECSRC})
if (WIN32)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
target_link_directories(ftlcodecs PUBLIC src/Video_Codec_SDK_9.1.23/Lib/x64)
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
target_link_directories(ftlcodecs PUBLIC src/Video_Codec_SDK_9.1.23/Lib/Win32)
endif()
endif()
target_include_directories(ftlcodecs PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE src)
#target_include_directories(cv-node PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(ftlcodecs ftlcommon ${OpenCV_LIBS} ${CUDA_LIBRARIES} Eigen3::Eigen nvpipe)
target_link_libraries(ftlcodecs ftlcommon ${OpenCV_LIBS} ${CUDA_LIBRARIES} Eigen3::Eigen NvPipe nvcuvid)
if (BUILD_TESTS)
add_subdirectory(test)
......
......@@ -10,9 +10,16 @@ void depth_to_vuya(const cv::cuda::PtrStepSz<float> &depth, const cv::cuda::PtrS
void vuya_to_depth(const cv::cuda::PtrStepSz<float> &depth, const cv::cuda::PtrStepSz<ushort4> &rgba, float maxdepth, cv::cuda::Stream &stream);
void vuya_to_depth(const cv::cuda::PtrStepSz<float> &depth, const cv::cuda::PtrStepSz<ushort> &luminance, const cv::cuda::PtrStepSz<ushort> &chroma, float maxdepth, cv::cuda::Stream &stream);
void smooth_y(const cv::cuda::PtrStepSz<ushort4> &rgba, cv::cuda::Stream &stream);
void nv12_to_float(const uint8_t* src, uint32_t srcPitch, float* dst, uint32_t dstPitch, uint32_t width, uint32_t height, cudaStream_t s);
}
}
template <class COLOR32>
void Nv12ToColor32(uint8_t *dpNv12, int nNv12Pitch, uint8_t *dpBgra, int nBgraPitch, int nWidth, int nHeight, int iMatrix = 0, cudaStream_t s=0);
#endif // _FTL_CODECS_DEPTH_CONVERT_HPP_
......@@ -4,7 +4,9 @@
#include <ftl/codecs/decoder.hpp>
#include <ftl/threads.hpp>
#include <NvPipe.h>
//#include <NvPipe.h>
class NvDecoder;
namespace ftl {
namespace codecs {
......@@ -19,14 +21,19 @@ class NvPipeDecoder : public ftl::codecs::Decoder {
bool accepts(const ftl::codecs::Packet &pkt);
private:
NvPipe *nv_decoder_;
NvDecoder *nv_decoder_;
bool is_float_channel_;
ftl::codecs::definition_t last_definition_;
ftl::codecs::codec_t last_codec_;
MUTEX mutex_;
bool seen_iframe_;
cv::cuda::GpuMat tmp_;
int width_;
int height_;
int n_;
bool _create(const ftl::codecs::Packet &pkt);
uint8_t* _decode(const uint8_t* src, uint64_t srcSize);
bool _checkIFrame(ftl::codecs::codec_t codec, const unsigned char *data, size_t size);
};
......
File added
File added
File added
File added
File added
File added
File added
File added
File added
This SDK includes portions of FFMPEG, under the following license:
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
NVIDIA Video Codec SDK 9.0 and NVIDIA Video Codec SDK 9.1 Readme and Getting Started Guide
System Requirements
* NVIDIA Kepler/Maxwell/Pascal/Volta/Turing GPU with hardware video accelerators
Refer to the NVIDIA Video SDK developer zone web page
(https://developer.nvidia.com/nvidia-video-codec-sdk) for GPUs which support
video encoding and decoding acceleration.
* Windows: Driver version 436.15 or higher
* Linux: Driver version 435.21 or higher
* CUDA 10.0 Toolkit
* NVIDIA Video Codec SDK is now supported on IBM Power9 class server with
NVIDIA Tesla V100 (SXM2) GPU.
[Windows Configuration Requirements]
- DirectX SDK is needed. You can download the latest SDK from Microsoft's DirectX
website.
- The CUDA 10.0 tool kit is needed to compile the decode samples in SDK 9.0
and above.
- CUDA tool kit is also used for building CUDA kernels that can interop with
NVENC.
In Windows, the following environment variables must be set to build the sample
applications included with the SDK
- DXSDK_DIR: pointing to the DirectX SDK root directory.
- The CUDA 10.0 Toolkit is optional to install if the client has
Video Codec SDK 8.0. However it is mandatory if client has
Video Codec SDK 8.1 or above on his/her machine.
[Linux Configuration Requirements]
- X11 and OpenGL, GLUT, GLEW libraries for video playback and display
- The CUDA 10.0 Toolkit is optional to install if the client has Video Codec
SDK 8.0.
- CUDA 10.0 Toolkit is mandatory if client has Video Codec SDK 8.1 or above
on his/her machine.
- CUDA toolkit is used for building CUDA kernels that can interop with NVENC.
- Libraries and headers from the FFmpeg project which can be downloaded and
installed using the distribution's package manager or compiled from source.
The sample applications have been compiled and tested against the
libraries and headers from FFmpeg- 4.1. The source code of FFmpeg- 4.1
has been included in this SDK package. While configuring FFmpeg on Linux,
it is recommended not to use 'disable-decoders' option. This configuration
is known to have a channel error (XID 31) while executing sample
applications with certain clips and/or result in an unexpected behavior.
- To build/use sample applications that depend on FFmpeg, users may need to
* Add the directory (/usr/local/lib/pkgconfig by default) to the
PKG_CONFIG_PATH environment variable. This is required by the Makefile
to determine the include paths for the FFmpeg headers.
* Add the directory where the FFmpeg libraries are installed, to the
LD_LIBRARY_PATH environment variable. This is required for resolving
runtime dependencies on FFmpeg libraries.
- Stub libraries (libnvcuvid.so and libnvidia-encode.so) have been included
as part of the SDK package, in order to aid development of applications on
systems where the NVIDIA driver has not been installed. The sample
applications in the SDK will link against these stub libraries as part of
the build process. However, users need to ensure that the stub libraries
are not referenced when running the sample applications. A driver
compatible with this SDK needs to be installed in order for the sample
applications to work correctly.
- The Vulkan SDK needs to be installed in order to build and run the
AppMotionEstimationVkCuda sample application. Vulkan SDK can be downloaded
from https://vulkan.lunarg.com/sdk/home. Alternatively, it can be
installed by using the distribution's package manager.
[Common to all OS platforms]
* To download the CUDA 10.0 toolkit, please go to the following web site:
http://developer.nvidia.com/cuda/cuda-toolkit
\ No newline at end of file
What's new in Video Codec SDK 9.1:
----------------------------------
In NVIDIA Video Codec SDK release 9.1, following features have been added:
Encode Features:
1. NVENCODE API for retrieving the last encountered error
2. Support for CUStream
3. Filler NALU insertion
4. Fixes for H.264 MVC
5. Multiple reference frames
Decode Features:
1. Enhancements to decode capability API
2. Memory optimization in sample applications
What's new in Video Codec SDK 9.0:
----------------------------------
In NVIDIA Video Codec SDK release 9.0, following features were added:
Encode Features:
1. Improved encoded quality for Turing GPUs
2. HEVC B-frame support (Turing GPUs only)
3. Encoded output in video memory
4. H.264 ME only mode output in video memory.
5. Non-reference P frames
6. Support for accepting CUArray as input
Decode Features:
1. HEVC YUV 444 decoding (Turing GPUs only)
2. Multiple NVDEC engines(Turing GPUs only)
Please refer to .\doc\NVENC_Application_Note.pdf and
.\doc\NVDEC_Application_Note.pdf to get more details about the available
encoding and decoding functionalities in the SDK.
For system, software and build environment requirements, please refer to the
file ReadMe.txt included in the SDK package.
Package Contents
----------------
This package contains the following:
1) Sample applications demonstrating various encoding/decoding/transcoding
capabilities
- [.\Samples\]
2) NVIDIA video encoder API header
- [.\include\nvEncodeAPI.h]
3) NVIDIA video encoder application note
- [.\doc\NVENC_Application_Note.pdf]
4) NVIDIA video encoder programming guide
- [.\doc\NVENC_VideoEncoder_API_ProgGuide.pdf]
5) NVIDIA video decoder API headers
- [.\include\cuviddec.h]
- [.\include\nvcuvid.h]
6) NVIDIA video decoder application note
- [.\doc\NVDEC_Application_Note.pdf]
7) NVIDIA video decoder programming guide
- [.\doc\NVDEC_VideoDecoder_API_ProgGuide.pdf]
8) Application note on how to use NVIDIA video acceleration in FFmpeg
- [.\doc\Using FFmpeg with NVIDIA GPU Hardware Acceleration.pdf]
9) NVIDIA video decoder and encoder stub libraries
- [.\Lib\linux\stubs\x86_64\libnvcuvid.so]
- [.\Lib\linux\stubs\x86_64\libnvidia-encode.so]
- [.\Lib\linux\stubs\ppc64le\libnvcuvid.so]
- [.\Lib\linux\stubs\ppc64le\libnvidia-encode.so]
- [.\Lib\Win32\nvcuvid.lib]
- [.\Lib\x64\nvcuvid.lib]
The sample applications provided in the package are for demonstration purposes
only and may not be fully tuned for quality and performance. Hence the users
are advised to do their independent evaluation for quality and/or performance.
/*
* Copyright 2017-2018 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
#pragma once
#include <assert.h>
#include <stdint.h>
#include <mutex>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <string.h>
#include "nvcuvid.h"
/**
* @brief Exception class for error reporting from the decode API.
*/
class NVDECException : public std::exception
{
public:
NVDECException(const std::string& errorStr, const CUresult errorCode)
: m_errorString(errorStr), m_errorCode(errorCode) {}
virtual ~NVDECException() throw() {}
virtual const char* what() const throw() { return m_errorString.c_str(); }
CUresult getErrorCode() const { return m_errorCode; }
const std::string& getErrorString() const { return m_errorString; }
static NVDECException makeNVDECException(const std::string& errorStr, const CUresult errorCode,
const std::string& functionName, const std::string& fileName, int lineNo);
private:
std::string m_errorString;
CUresult m_errorCode;
};
inline NVDECException NVDECException::makeNVDECException(const std::string& errorStr, const CUresult errorCode, const std::string& functionName,
const std::string& fileName, int lineNo)
{
std::ostringstream errorLog;
errorLog << functionName << " : " << errorStr << " at " << fileName << ":" << lineNo << std::endl;
NVDECException exception(errorLog.str(), errorCode);
return exception;
}
#define NVDEC_THROW_ERROR( errorStr, errorCode ) \
do \
{ \
throw NVDECException::makeNVDECException(errorStr, errorCode, __FUNCTION__, __FILE__, __LINE__); \
} while (0)
#define NVDEC_API_CALL( cuvidAPI ) \
do \
{ \
CUresult errorCode = cuvidAPI; \
if( errorCode != CUDA_SUCCESS) \
{ \
std::ostringstream errorLog; \
errorLog << #cuvidAPI << " returned error " << errorCode; \
throw NVDECException::makeNVDECException(errorLog.str(), errorCode, __FUNCTION__, __FILE__, __LINE__); \
} \
} while (0)
struct Rect {
int l, t, r, b;
};
struct Dim {
int w, h;
};
/**
* @brief Base class for decoder interface.
*/
class NvDecoder {
public:
/**
* @brief This function is used to initialize the decoder session.
* Application must call this function to initialize the decoder, before
* starting to decode any frames.
*/
NvDecoder(CUcontext cuContext, bool bUseDeviceFrame, cudaVideoCodec eCodec, std::mutex *pMutex = NULL, bool bLowLatency = false,
bool bDeviceFramePitched = false, const Rect *pCropRect = NULL, const Dim *pResizeDim = NULL,
int maxWidth = 0, int maxHeight = 0);
~NvDecoder();
/**
* @brief This function is used to get the current CUDA context.
*/
CUcontext GetContext() { return m_cuContext; }
/**
* @brief This function is used to get the current decode width.
*/
int GetWidth() { assert(m_nWidth); return m_nWidth; }
/**
* @brief This function is used to get the current decode height (Luma height).
*/
int GetHeight() { assert(m_nLumaHeight); return m_nLumaHeight; }
/**
* @brief This function is used to get the current chroma height.
*/
int GetChromaHeight() { assert(m_nChromaHeight); return m_nChromaHeight; }
/**
* @brief This function is used to get the number of chroma planes.
*/
int GetNumChromaPlanes() { assert(m_nNumChromaPlanes); return m_nNumChromaPlanes; }
/**
* @brief This function is used to get the current frame size based on pixel format.
*/
int GetFrameSize() { assert(m_nWidth); return m_nWidth * (m_nLumaHeight + m_nChromaHeight * m_nNumChromaPlanes) * m_nBPP; }
/**
* @brief This function is used to get the pitch of the device buffer holding the decoded frame.
*/
int GetDeviceFramePitch() { assert(m_nWidth); return m_nDeviceFramePitch ? (int)m_nDeviceFramePitch : m_nWidth * m_nBPP; }
/**
* @brief This function is used to get the bit depth associated with the pixel format.
*/
int GetBitDepth() { assert(m_nWidth); return m_nBitDepthMinus8 + 8; }
/**
* @brief This function is used to get the bytes used per pixel.
*/
int GetBPP() { assert(m_nWidth); return m_nBPP; }
/**
* @brief This function is used to get the YUV chroma format
*/
cudaVideoSurfaceFormat GetOutputFormat() { return m_eOutputFormat; }
/**
* @brief This function is used to get information about the video stream (codec, display parameters etc)
*/
CUVIDEOFORMAT GetVideoFormatInfo() { assert(m_nWidth); return m_videoFormat; }
/**
* @brief This function is used to print information about the video stream
*/
std::string GetVideoInfo() const { return m_videoInfo.str(); }
/**
* @brief This function decodes a frame and returns frames that are available for display.
The frames should be used or buffered before making subsequent calls to the Decode function again
* @param pData - pointer to the data buffer that is to be decoded
* @param nSize - size of the data buffer in bytes
* @param pppFrame - CUvideopacketflags for setting decode options
* @param pnFrameReturned - pointer to array of decoded frames that are returned
* @param flags - CUvideopacketflags for setting decode options
* @param ppTimestamp - pointer to array of timestamps for decoded frames that are returned
* @param timestamp - presentation timestamp
* @param stream - CUstream to be used for post-processing operations
*/
bool Decode(const uint8_t *pData, int nSize, uint8_t ***pppFrame, int *pnFrameReturned, uint32_t flags = 0, int64_t **ppTimestamp = NULL, int64_t timestamp = 0, CUstream stream = 0);
/**
* @brief This function decodes a frame and returns the locked frame buffers
* This makes the buffers available for use by the application without the buffers
* getting overwritten, even if subsequent decode calls are made. The frame buffers
* remain locked, until ::UnlockFrame() is called
* @param pData - pointer to the data buffer that is to be decoded
* @param nSize - size of the data buffer in bytes
* @param pppFrame - CUvideopacketflags for setting decode options
* @param pnFrameReturned - pointer to array of decoded frames that are returned
* @param flags - CUvideopacketflags for setting decode options
* @param ppTimestamp - pointer to array of timestamps for decoded frames that are returned
* @param timestamp - presentation timestamp
* @param stream - CUstream to be used for post-processing operations
*/
bool DecodeLockFrame(const uint8_t *pData, int nSize, uint8_t ***pppFrame, int *pnFrameReturned, uint32_t flags = 0, int64_t **ppTimestamp = NULL, int64_t timestamp = 0, CUstream stream = 0);
/**
* @brief This function unlocks the frame buffer and makes the frame buffers available for write again
* @param ppFrame - pointer to array of frames that are to be unlocked
* @param nFrame - number of frames to be unlocked
*/
void UnlockFrame(uint8_t **ppFrame, int nFrame);
/**
* @brief This function allow app to set decoder reconfig params
* @param pCropRect - cropping rectangle coordinates
* @param pResizeDim - width and height of resized output
*/
int setReconfigParams(const Rect * pCropRect, const Dim * pResizeDim);
private:
/**
* @brief Callback function to be registered for getting a callback when decoding of sequence starts
*/
static int CUDAAPI HandleVideoSequenceProc(void *pUserData, CUVIDEOFORMAT *pVideoFormat) { return ((NvDecoder *)pUserData)->HandleVideoSequence(pVideoFormat); }
/**
* @brief Callback function to be registered for getting a callback when a decoded frame is ready to be decoded
*/
static int CUDAAPI HandlePictureDecodeProc(void *pUserData, CUVIDPICPARAMS *pPicParams) { return ((NvDecoder *)pUserData)->HandlePictureDecode(pPicParams); }
/**
* @brief Callback function to be registered for getting a callback when a decoded frame is available for display
*/
static int CUDAAPI HandlePictureDisplayProc(void *pUserData, CUVIDPARSERDISPINFO *pDispInfo) { return ((NvDecoder *)pUserData)->HandlePictureDisplay(pDispInfo); }
/**
* @brief This function gets called when a sequence is ready to be decoded. The function also gets called
when there is format change
*/
int HandleVideoSequence(CUVIDEOFORMAT *pVideoFormat);
/**
* @brief This function gets called when a picture is ready to be decoded. cuvidDecodePicture is called from this function
* to decode the picture
*/
int HandlePictureDecode(CUVIDPICPARAMS *pPicParams);
/**
* @brief This function gets called after a picture is decoded and available for display. Frames are fetched and stored in
internal buffer
*/
int HandlePictureDisplay(CUVIDPARSERDISPINFO *pDispInfo);
/**
* @brief This function reconfigure decoder if there is a change in sequence params.
*/
int ReconfigureDecoder(CUVIDEOFORMAT *pVideoFormat);
private:
CUcontext m_cuContext = NULL;
CUvideoctxlock m_ctxLock;
std::mutex *m_pMutex;
CUvideoparser m_hParser = NULL;
CUvideodecoder m_hDecoder = NULL;
bool m_bUseDeviceFrame;
// dimension of the output
unsigned int m_nWidth = 0, m_nLumaHeight = 0, m_nChromaHeight = 0;
unsigned int m_nNumChromaPlanes = 0;
// height of the mapped surface
int m_nSurfaceHeight = 0;
int m_nSurfaceWidth = 0;
cudaVideoCodec m_eCodec = cudaVideoCodec_NumCodecs;
cudaVideoChromaFormat m_eChromaFormat;
cudaVideoSurfaceFormat m_eOutputFormat;
int m_nBitDepthMinus8 = 0;
int m_nBPP = 1;
CUVIDEOFORMAT m_videoFormat = {};
Rect m_displayRect = {};
// stock of frames
std::vector<uint8_t *> m_vpFrame;
// decoded frames for return
std::vector<uint8_t *> m_vpFrameRet;
// timestamps of decoded frames
std::vector<int64_t> m_vTimestamp;
int m_nDecodedFrame = 0, m_nDecodedFrameReturned = 0;
int m_nDecodePicCnt = 0, m_nPicNumInDecodeOrder[32];
bool m_bEndDecodeDone = false;
std::mutex m_mtxVPFrame;
int m_nFrameAlloc = 0;
CUstream m_cuvidStream = 0;
bool m_bDeviceFramePitched = false;
size_t m_nDeviceFramePitch = 0;
Rect m_cropRect = {};
Dim m_resizeDim = {};
std::ostringstream m_videoInfo;
unsigned int m_nMaxWidth = 0, m_nMaxHeight = 0;
bool m_bReconfigExternal = false;
bool m_bReconfigExtPPChange = false;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment