Add nullptr parameters check for all decoder/parser APIs and some code clean up (#120)
[ROCm/rocdecode commit: 9257cd6fcf]
Dieser Commit ist enthalten in:
committet von
GitHub
Ursprung
24dc12e75e
Commit
08c99da4fa
@@ -271,14 +271,14 @@ typedef struct _RocdecParserParams {
|
||||
|
||||
/************************************************************************************************/
|
||||
//! \ingroup FUNCTS
|
||||
//! \fn rocDecodeStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *pHandle, RocdecParserParams *pParams)
|
||||
//! \fn rocDecodeStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *parser_handle, RocdecParserParams *params)
|
||||
//! Create video parser object and initialize
|
||||
/************************************************************************************************/
|
||||
extern rocDecStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *pHandle, RocdecParserParams *pParams);
|
||||
extern rocDecStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *parser_handle, RocdecParserParams *params);
|
||||
|
||||
/************************************************************************************************/
|
||||
//! \ingroup FUNCTS
|
||||
//! \fn rocDecodeStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser handle, RocdecSourceDataPacket *pPacket)
|
||||
//! \fn rocDecodeStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser parser_handle, RocdecSourceDataPacket *packet)
|
||||
//! Parse the video data from source data packet in pPacket
|
||||
//! Extracts parameter sets like SPS, PPS, bitstream etc. from pPacket and
|
||||
//! calls back pfnDecodePicture with RocdecPicParams data for kicking of HW decoding
|
||||
@@ -286,14 +286,14 @@ extern rocDecStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *pHandle
|
||||
//! the decoder encounters a video format change
|
||||
//! calls back pfnDisplayPicture with RocdecParserDispInfo data to display a video frame
|
||||
/************************************************************************************************/
|
||||
extern rocDecStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser handle, RocdecSourceDataPacket *pPacket);
|
||||
extern rocDecStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser parser_handle, RocdecSourceDataPacket *packet);
|
||||
|
||||
/************************************************************************************************/
|
||||
//! \ingroup FUNCTS
|
||||
//! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser handle)
|
||||
//! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser parser_handle)
|
||||
//! Destroy the video parser object
|
||||
/************************************************************************************************/
|
||||
extern rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser handle);
|
||||
extern rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser parser_handle);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -29,20 +29,20 @@ THE SOFTWARE.
|
||||
#include "hevc_parser.h"
|
||||
|
||||
class RocParserHandle {
|
||||
public:
|
||||
explicit RocParserHandle(RocdecParserParams *pParams) { create_parser(pParams); }; // default constructor
|
||||
~RocParserHandle() { clear_errors(); }
|
||||
bool no_error() { return error.empty(); }
|
||||
const char* error_msg() { return error.c_str(); }
|
||||
void capture_error(const std::string& err_msg) { error = err_msg; }
|
||||
rocDecStatus ParseVideoData(RocdecSourceDataPacket *pPacket) { return roc_parser_->ParseVideoData(pPacket); }
|
||||
rocDecStatus DestroyParser() { return destroy_parser(); };
|
||||
public:
|
||||
explicit RocParserHandle(RocdecParserParams *params) { CreateParser(params); };
|
||||
~RocParserHandle() { ClearErrors(); }
|
||||
bool NoError() { return error_.empty(); }
|
||||
const char* ErrorMsg() { return error_.c_str(); }
|
||||
void CaptureError(const std::string& err_msg) { error_ = err_msg; }
|
||||
rocDecStatus ParseVideoData(RocdecSourceDataPacket *packet) { return roc_parser_->ParseVideoData(packet); }
|
||||
rocDecStatus DestroyParser() { return DestroyParserInternal(); };
|
||||
|
||||
private:
|
||||
std::shared_ptr<RocVideoParser> roc_parser_ = nullptr; // class instantiation
|
||||
void clear_errors() { error = ""; }
|
||||
void create_parser(RocdecParserParams *pParams) {
|
||||
switch(pParams->CodecType) {
|
||||
std::shared_ptr<RocVideoParser> roc_parser_ = nullptr;
|
||||
void ClearErrors() { error_ = ""; }
|
||||
void CreateParser(RocdecParserParams *params) {
|
||||
switch(params->CodecType) {
|
||||
case rocDecVideoCodec_H264:
|
||||
roc_parser_ = std::make_shared<H264VideoParser>();
|
||||
break;
|
||||
@@ -50,19 +50,19 @@ private:
|
||||
roc_parser_ = std::make_shared<HEVCVideoParser>();
|
||||
break;
|
||||
default:
|
||||
THROW("Unsupported parser type "+ TOSTR(pParams->CodecType));
|
||||
THROW("Unsupported parser type "+ TOSTR(params->CodecType));
|
||||
break;
|
||||
}
|
||||
|
||||
if (roc_parser_ ) {
|
||||
rocDecStatus ret = roc_parser_->Initialize(pParams);
|
||||
rocDecStatus ret = roc_parser_->Initialize(params);
|
||||
if (ret != ROCDEC_SUCCESS)
|
||||
THROW("rocParser Initialization failed with error: "+ TOSTR(ret));
|
||||
}
|
||||
}
|
||||
rocDecStatus destroy_parser() {
|
||||
rocDecStatus DestroyParserInternal() {
|
||||
rocDecStatus ret = ROCDEC_NOT_INITIALIZED;
|
||||
if (roc_parser_ ) {
|
||||
if (roc_parser_) {
|
||||
ret = roc_parser_->UnInitialize();
|
||||
if (ret != ROCDEC_SUCCESS)
|
||||
THROW("rocParser UnInitialization failed with error: "+ TOSTR(ret));
|
||||
@@ -70,5 +70,5 @@ private:
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string error;
|
||||
std::string error_;
|
||||
};
|
||||
@@ -25,45 +25,48 @@ THE SOFTWARE.
|
||||
|
||||
/************************************************************************************************/
|
||||
//! \ingroup FUNCTS
|
||||
//! \fn rocParserStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *pHandle, RocdecParserParams *pParams)
|
||||
//! \fn rocParserStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *parser_handle, RocdecParserParams *parser_params)
|
||||
//! Create video parser object and initialize
|
||||
/************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecCreateVideoParser(RocdecVideoParser *pHandle, RocdecParserParams *pParams) {
|
||||
rocDecCreateVideoParser(RocdecVideoParser *parser_handle, RocdecParserParams *parser_params) {
|
||||
if (parser_handle == nullptr || parser_params == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
RocdecVideoParser handle = nullptr;
|
||||
try {
|
||||
handle = new RocParserHandle(pParams);
|
||||
handle = new RocParserHandle(parser_params);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
ERR( STR("Failed to init the rocDecode handle, ") + STR(e.what()))
|
||||
return ROCDEC_RUNTIME_ERROR;
|
||||
}
|
||||
*pHandle = handle;
|
||||
*parser_handle = handle;
|
||||
return rocDecStatus::ROCDEC_SUCCESS;
|
||||
}
|
||||
|
||||
/************************************************************************************************/
|
||||
//! \ingroup FUNCTS
|
||||
//! \fn rocParserStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser handle, RocdecSourceDataPacket *pPacket)
|
||||
//! Parse the video data from source data packet in pPacket
|
||||
//! Extracts parameter sets like SPS, PPS, bitstream etc. from pPacket and
|
||||
//! \fn rocParserStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser parser_handle, RocdecSourceDataPacket *packet)
|
||||
//! Parse the video data from source data packet in packet
|
||||
//! Extracts parameter sets like SPS, PPS, bitstream etc. from packet and
|
||||
//! calls back pfnDecodePicture with RocdecPicParams data for kicking of HW decoding
|
||||
//! calls back pfnSequenceCallback with RocdecVideoFormat data for initial sequence header or when
|
||||
//! the decoder encounters a video format change
|
||||
//! calls back pfnDisplayPicture with ROCDECPARSERDISPINFO data to display a video frame
|
||||
/************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecParseVideoData(RocdecVideoParser handle, RocdecSourceDataPacket *pPacket) {
|
||||
if (handle == nullptr) {
|
||||
rocDecParseVideoData(RocdecVideoParser parser_handle, RocdecSourceDataPacket *packet) {
|
||||
if (parser_handle == nullptr || packet == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto parser_hdl = static_cast<RocParserHandle *> (handle);
|
||||
auto roc_parser_handle = static_cast<RocParserHandle *>(parser_handle);
|
||||
rocDecStatus ret;
|
||||
try {
|
||||
ret = parser_hdl->ParseVideoData(pPacket);
|
||||
ret = roc_parser_handle->ParseVideoData(packet);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
parser_hdl->capture_error(e.what());
|
||||
roc_parser_handle->CaptureError(e.what());
|
||||
ERR(e.what())
|
||||
return ROCDEC_RUNTIME_ERROR;
|
||||
}
|
||||
@@ -72,21 +75,21 @@ rocDecParseVideoData(RocdecVideoParser handle, RocdecSourceDataPacket *pPacket)
|
||||
|
||||
/************************************************************************************************/
|
||||
//! \ingroup FUNCTS
|
||||
//! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser handle)
|
||||
//! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser parser_handle)
|
||||
//! Destroy the video parser object
|
||||
/************************************************************************************************/
|
||||
extern rocDecStatus ROCDECAPI
|
||||
rocDecDestroyVideoParser(RocdecVideoParser handle) {
|
||||
if (handle == nullptr) {
|
||||
rocDecDestroyVideoParser(RocdecVideoParser parser_handle) {
|
||||
if (parser_handle == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto parser_hdl = static_cast<RocParserHandle *> (handle);
|
||||
auto roc_parser_handle = static_cast<RocParserHandle *>(parser_handle);
|
||||
rocDecStatus ret;
|
||||
try {
|
||||
ret = parser_hdl->DestroyParser();
|
||||
ret = roc_parser_handle->DestroyParser();
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
parser_hdl->capture_error(e.what());
|
||||
roc_parser_handle->CaptureError(e.what());
|
||||
ERR(e.what())
|
||||
return ROCDEC_RUNTIME_ERROR;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,9 @@ THE SOFTWARE.
|
||||
/*****************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecCreateDecoder(rocDecDecoderHandle *decoder_handle, RocDecoderCreateInfo *decoder_create_info) {
|
||||
if (decoder_handle == nullptr || decoder_create_info == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
rocDecDecoderHandle handle = nullptr;
|
||||
try {
|
||||
handle = new DecHandle(*decoder_create_info);
|
||||
@@ -49,7 +52,10 @@ rocDecCreateDecoder(rocDecDecoderHandle *decoder_handle, RocDecoderCreateInfo *d
|
||||
/*****************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecDestroyDecoder(rocDecDecoderHandle decoder_handle) {
|
||||
auto handle = static_cast<DecHandle *> (decoder_handle);
|
||||
if (decoder_handle == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto handle = static_cast<DecHandle *>(decoder_handle);
|
||||
delete handle;
|
||||
return ROCDEC_SUCCESS;
|
||||
}
|
||||
@@ -99,7 +105,10 @@ rocDecGetDecoderCaps(RocdecDecodeCaps *pdc) {
|
||||
/*****************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecDecodeFrame(rocDecDecoderHandle decoder_handle, RocdecPicParams *pic_params) {
|
||||
auto handle = static_cast<DecHandle *> (decoder_handle);
|
||||
if (decoder_handle == nullptr || pic_params == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto handle = static_cast<DecHandle *>(decoder_handle);
|
||||
rocDecStatus ret;
|
||||
try {
|
||||
ret = handle->roc_decoder_->DecodeFrame(pic_params);
|
||||
@@ -115,7 +124,7 @@ rocDecDecodeFrame(rocDecDecoderHandle decoder_handle, RocdecPicParams *pic_param
|
||||
/************************************************************************************************************/
|
||||
//! \fn rocDecStatus ROCDECAPI RocdecGetDecodeStatus(rocDecDecoderHandle decoder_handle, int pic_idx, RocdecDecodeStatus* decode_status);
|
||||
//! Get the decode status for frame corresponding to pic_idx
|
||||
//! API is currently supported for HEVC, H264 and JPEG codecs.
|
||||
//! API is currently supported for HEVC codec.
|
||||
//! API returns CUDA_ERROR_NOT_SUPPORTED error code for unsupported GPU or codec.
|
||||
/************************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
@@ -123,7 +132,7 @@ rocDecGetDecodeStatus(rocDecDecoderHandle decoder_handle, int pic_idx, RocdecDec
|
||||
if (decoder_handle == nullptr || decode_status == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto handle = static_cast<DecHandle *> (decoder_handle);
|
||||
auto handle = static_cast<DecHandle *>(decoder_handle);
|
||||
rocDecStatus ret;
|
||||
try {
|
||||
ret = handle->roc_decoder_->GetDecodeStatus(pic_idx, decode_status);
|
||||
@@ -138,15 +147,15 @@ rocDecGetDecodeStatus(rocDecDecoderHandle decoder_handle, int pic_idx, RocdecDec
|
||||
|
||||
/*********************************************************************************************************/
|
||||
//! \fn rocDecStatus ROCDECAPI rocDecReconfigureDecoder(rocDecDecoderHandle decoder_handle, RocdecReconfigureDecoderInfo *reconfig_params)
|
||||
//! Used to reuse single decoder for multiple clips. Currently supports resolution change, resize params
|
||||
//! params, target area params change for same codec. Must be called during RocdecParserParams::pfnSequenceCallback
|
||||
//! Used to reuse single decoder for multiple clips. Currently supports resolution change, resize params
|
||||
//! params, target area params change for same codec. Must be called during RocdecParserParams::pfnSequenceCallback
|
||||
/*********************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecReconfigureDecoder(rocDecDecoderHandle decoder_handle, RocdecReconfigureDecoderInfo *reconfig_params) {
|
||||
if (decoder_handle == nullptr || reconfig_params == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto handle = static_cast<DecHandle *> (decoder_handle);
|
||||
auto handle = static_cast<DecHandle *>(decoder_handle);
|
||||
rocDecStatus ret;
|
||||
try {
|
||||
ret = handle->roc_decoder_->ReconfigureDecoder(reconfig_params);
|
||||
@@ -160,16 +169,18 @@ rocDecReconfigureDecoder(rocDecDecoderHandle decoder_handle, RocdecReconfigureDe
|
||||
}
|
||||
|
||||
/************************************************************************************************************************/
|
||||
//! \fn extern rocDecStatus ROCDECAPI rocDecMapVideoFrame(rocDecDecoderHandle decoder_handle, int pic_idx,
|
||||
//! unsigned int *dev_mem_ptr, unsigned int *horizontal_pitch,
|
||||
//! RocdecProcParams *vid_postproc_params);
|
||||
//! \fn rocDecStatus ROCDECAPI rocDecMapVideoFrame(rocDecDecoderHandle decoder_handle, int pic_idx, unsigned int *dev_mem_ptr,
|
||||
//! unsigned int *horizontal_pitch, RocdecProcParams *vid_postproc_params);
|
||||
//! Post-process and map video frame corresponding to pic_idx for use in HIP. Returns HIP device pointer and associated
|
||||
//! pitch(horizontal stride) of the video frame. Returns device memory pointers for each plane (Y, U and V) seperately
|
||||
/************************************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecMapVideoFrame(rocDecDecoderHandle decoder_handle, int pic_idx,
|
||||
void *dev_mem_ptr[3], uint32_t (&horizontal_pitch)[3], RocdecProcParams *vid_postproc_params) {
|
||||
auto handle = static_cast<DecHandle *> (decoder_handle);
|
||||
if (decoder_handle == nullptr || dev_mem_ptr == nullptr || horizontal_pitch == nullptr || vid_postproc_params == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto handle = static_cast<DecHandle *>(decoder_handle);
|
||||
rocDecStatus ret;
|
||||
try {
|
||||
ret = handle->roc_decoder_->MapVideoFrame(pic_idx, dev_mem_ptr, horizontal_pitch, vid_postproc_params);
|
||||
@@ -188,7 +199,10 @@ rocDecMapVideoFrame(rocDecDecoderHandle decoder_handle, int pic_idx,
|
||||
/*****************************************************************************************************/
|
||||
rocDecStatus ROCDECAPI
|
||||
rocDecUnMapVideoFrame(rocDecDecoderHandle decoder_handle, int pic_idx) {
|
||||
auto handle = static_cast<DecHandle *> (decoder_handle);
|
||||
if (decoder_handle == nullptr) {
|
||||
return ROCDEC_INVALID_PARAMETER;
|
||||
}
|
||||
auto handle = static_cast<DecHandle *>(decoder_handle);
|
||||
rocDecStatus ret;
|
||||
try {
|
||||
ret = handle->roc_decoder_->UnMapVideoFrame(pic_idx);
|
||||
|
||||
In neuem Issue referenzieren
Einen Benutzer sperren