12#include <boost/shared_ptr.hpp>
13#include "CommonDefs.h"
14#include "CudaCommon.h"
31 const std::string& functionName,
const std::string& fileName,
int lineNo);
38 const std::string& fileName,
int lineNo)
40 std::ostringstream errorLog;
41 errorLog << functionName <<
" : " << errorStr <<
" at " << fileName <<
":" << lineNo << std::endl;
46#define NVDEC_THROW_ERROR( errorStr, errorCode ) \
49 throw NVDECException::makeNVDECException(errorStr, errorCode, __FUNCTION__, __FILE__, __LINE__); \
53#define NVDEC_API_CALL( cuvidAPI ) \
56 CUresult errorCode = cuvidAPI; \
57 if( errorCode != CUDA_SUCCESS) \
59 std::ostringstream errorLog; \
60 errorLog << #cuvidAPI << " returned error " << errorCode; \
61 throw NVDECException::makeNVDECException(errorLog.str(), errorCode, __FUNCTION__, __FILE__, __LINE__); \
84 NvDecoder(CUcontext cuContext,
int nWidth,
int nHeight,
bool bUseDeviceFrame, cudaVideoCodec eCodec, std::mutex* pMutex = NULL,
85 bool bLowLatency =
false,
bool bDeviceFramePitched =
false,
const Rect* pCropRect = NULL,
const Dim* pResizeDim = NULL,
int maxWidth = 0,
int maxHeight = 0);
133 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);
141 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);
204 cudaVideoCodec
m_eCodec = cudaVideoCodec_NumCodecs;
239 bool init(std::function<
void(frame_sp&)>
send, std::function<frame_sp()>
makeFrame);
240 void ConvertToPlanar(uint8_t* pHostFrame,
int nWidth,
int nHeight,
int nBitDepth);
241 void process(
void* inputFrameBuffer,
size_t inputFrameSize, uint64_t inputFrameTS);
242 std::function<void( frame_sp&)>
send;
void process(void *inputFrameBuffer, size_t inputFrameSize, uint64_t inputFrameTS)
Definition H264DecoderNvCodecHelper.cpp:733
H264DecoderNvCodecHelper()
Definition H264DecoderNvCodecHelper.h:236
boost::shared_ptr< NvDecoder > helper
Definition H264DecoderNvCodecHelper.h:245
H264DecoderNvCodecHelper(int mWidth, int mHieght)
Definition H264DecoderNvCodecHelper.cpp:685
bool init(std::function< void(frame_sp &)> send, std::function< frame_sp()> makeFrame)
Definition H264DecoderNvCodecHelper.cpp:709
std::function< void(frame_sp &)> send
Definition H264DecoderNvCodecHelper.h:242
std::function< frame_sp()> makeFrame
Definition H264DecoderNvCodecHelper.h:243
void ConvertToPlanar(uint8_t *pHostFrame, int nWidth, int nHeight, int nBitDepth)
Definition H264DecoderNvCodecHelper.cpp:716
~H264DecoderNvCodecHelper()
Definition H264DecoderNvCodecHelper.h:237
std::queue< uint64_t > framesTimestampEntry
Definition H264DecoderNvCodecHelper.h:246
Exception class for error reporting from the decode API.
Definition H264DecoderNvCodecHelper.h:21
CUresult m_errorCode
Definition H264DecoderNvCodecHelper.h:34
NVDECException(const std::string &errorStr, const CUresult errorCode)
Definition H264DecoderNvCodecHelper.h:23
virtual const char * what() const
Definition H264DecoderNvCodecHelper.h:27
virtual ~NVDECException()
Definition H264DecoderNvCodecHelper.h:26
std::string m_errorString
Definition H264DecoderNvCodecHelper.h:33
CUresult getErrorCode() const
Definition H264DecoderNvCodecHelper.h:28
const std::string & getErrorString() const
Definition H264DecoderNvCodecHelper.h:29
static NVDECException makeNVDECException(const std::string &errorStr, const CUresult errorCode, const std::string &functionName, const std::string &fileName, int lineNo)
Definition H264DecoderNvCodecHelper.h:37
CUcontext m_cuContext
Definition H264DecoderNvCodecHelper.h:193
int m_nBitDepthMinus8
Definition H264DecoderNvCodecHelper.h:206
std::vector< uint8_t * > m_vpFrame
Definition H264DecoderNvCodecHelper.h:210
bool m_bReconfigExtPPChange
Definition H264DecoderNvCodecHelper.h:229
int m_nPicNumInDecodeOrder[32]
Definition H264DecoderNvCodecHelper.h:216
int m_nDecodedFrame
Definition H264DecoderNvCodecHelper.h:215
int HandleVideoSequence(CUVIDEOFORMAT *pVideoFormat)
This function gets called when a sequence is ready to be decoded. The function also gets called when ...
Definition H264DecoderNvCodecHelper.cpp:117
Dim m_resizeDim
Definition H264DecoderNvCodecHelper.h:224
CUvideoparser m_hParser
Definition H264DecoderNvCodecHelper.h:196
int GetFrameSize()
This function is used to get the current frame size based on pixel format.
Definition H264DecoderNvCodecHelper.h:107
cudaVideoChromaFormat m_eChromaFormat
Definition H264DecoderNvCodecHelper.h:205
Rect m_cropRect
Definition H264DecoderNvCodecHelper.h:223
unsigned int m_nMaxHeight
Definition H264DecoderNvCodecHelper.h:227
int m_nSurfaceWidth
Definition H264DecoderNvCodecHelper.h:203
int GetDeviceFramePitch()
This function is used to get the pitch of the device buffer holding the decoded frame.
Definition H264DecoderNvCodecHelper.h:112
int HandlePictureDisplay(CUVIDPARSERDISPINFO *pDispInfo)
This function gets called after a picture is decoded and available for display. Frames are fetched an...
Definition H264DecoderNvCodecHelper.cpp:430
int ReconfigureDecoder(CUVIDEOFORMAT *pVideoFormat)
This function reconfigure decoder if there is a change in sequence params.
Definition H264DecoderNvCodecHelper.cpp:262
CUvideodecoder m_hDecoder
Definition H264DecoderNvCodecHelper.h:197
~NvDecoder()
Definition H264DecoderNvCodecHelper.cpp:530
int HandlePictureDecode(CUVIDPICPARAMS *pPicParams)
This function gets called when a picture is ready to be decoded. cuvidDecodePicture is called from th...
Definition H264DecoderNvCodecHelper.cpp:416
bool m_bDeviceFramePitched
Definition H264DecoderNvCodecHelper.h:221
std::string GetVideoInfo() const
This function is used to print information about the video stream.
Definition H264DecoderNvCodecHelper.h:127
CUstream m_cuvidStream
Definition H264DecoderNvCodecHelper.h:220
Rect m_displayRect
Definition H264DecoderNvCodecHelper.h:208
int setReconfigParams(const Rect *pCropRect, const Dim *pResizeDim)
This function allow app to set decoder reconfig params.
Definition H264DecoderNvCodecHelper.cpp:369
std::vector< uint8_t * > m_vpFrameRet
Definition H264DecoderNvCodecHelper.h:212
int GetHeight()
This function is used to get the current decode height.
Definition H264DecoderNvCodecHelper.h:102
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)
This function decodes a frame and returns the locked frame buffers This makes the buffers available f...
Definition H264DecoderNvCodecHelper.cpp:613
unsigned int m_nMaxWidth
Definition H264DecoderNvCodecHelper.h:227
std::ostringstream m_videoInfo
Definition H264DecoderNvCodecHelper.h:226
int GetWidth()
This function is used to get the current decode width.
Definition H264DecoderNvCodecHelper.h:97
unsigned int m_nWidth
Definition H264DecoderNvCodecHelper.h:200
NvDecoder()
Definition H264DecoderNvCodecHelper.h:86
CUvideoctxlock m_ctxLock
Definition H264DecoderNvCodecHelper.h:194
int GetBitDepth()
This function is used to get the bit depth associated with the pixel format.
Definition H264DecoderNvCodecHelper.h:117
CUVIDEOFORMAT GetVideoFormatInfo()
This function is used to get information about the video stream (codec, display parameters etc)
Definition H264DecoderNvCodecHelper.h:122
static int CUDAAPI HandleVideoSequenceProc(void *pUserData, CUVIDEOFORMAT *pVideoFormat)
Callback function to be registered for getting a callback when decoding of sequence starts.
Definition H264DecoderNvCodecHelper.h:157
cudaVideoCodec m_eCodec
Definition H264DecoderNvCodecHelper.h:204
void UnlockFrame(uint8_t **ppFrame, int nFrame)
This function unlocks the frame buffer and makes the frame buffers available for write again.
Definition H264DecoderNvCodecHelper.cpp:621
NvDecoder(CUcontext cuContext, int nWidth, int nHeight, 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)
This function is used to initialize the decoder session. Application must call this function to initi...
Definition H264DecoderNvCodecHelper.cpp:507
std::mutex m_mtxVPFrame
Definition H264DecoderNvCodecHelper.h:218
CUVIDEOFORMAT m_videoFormat
Definition H264DecoderNvCodecHelper.h:207
int m_nFrameAlloc
Definition H264DecoderNvCodecHelper.h:219
int m_nSurfaceHeight
Definition H264DecoderNvCodecHelper.h:202
int m_nDecodedFrameReturned
Definition H264DecoderNvCodecHelper.h:215
static int CUDAAPI HandlePictureDisplayProc(void *pUserData, CUVIDPARSERDISPINFO *pDispInfo)
Callback function to be registered for getting a callback when a decoded frame is available for displ...
Definition H264DecoderNvCodecHelper.h:167
static int CUDAAPI HandlePictureDecodeProc(void *pUserData, CUVIDPICPARAMS *pPicParams)
Callback function to be registered for getting a callback when a decoded frame is ready to be decoded...
Definition H264DecoderNvCodecHelper.h:162
std::mutex * m_pMutex
Definition H264DecoderNvCodecHelper.h:195
bool m_bUseDeviceFrame
Definition H264DecoderNvCodecHelper.h:198
CUcontext GetContext()
This function is used to get the current CUDA context.
Definition H264DecoderNvCodecHelper.h:92
std::vector< int64_t > m_vTimestamp
Definition H264DecoderNvCodecHelper.h:214
bool m_bEndDecodeDone
Definition H264DecoderNvCodecHelper.h:217
size_t m_nDeviceFramePitch
Definition H264DecoderNvCodecHelper.h:222
int m_nDecodePicCnt
Definition H264DecoderNvCodecHelper.h:216
unsigned int m_nHeight
Definition H264DecoderNvCodecHelper.h:200
bool m_bReconfigExternal
Definition H264DecoderNvCodecHelper.h:228
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)
This function decodes a frame and returns frames that are available for display. The frames should be...
Definition H264DecoderNvCodecHelper.cpp:569
Definition H264DecoderNvCodecHelper.h:69
int w
Definition H264DecoderNvCodecHelper.h:70
int h
Definition H264DecoderNvCodecHelper.h:70
Definition H264DecoderNvCodecHelper.h:65
int t
Definition H264DecoderNvCodecHelper.h:66
int b
Definition H264DecoderNvCodecHelper.h:66
int r
Definition H264DecoderNvCodecHelper.h:66
int l
Definition H264DecoderNvCodecHelper.h:66