2
0

Add nullptr parameters check for all decoder/parser APIs and some code clean up (#120)

[ROCm/rocdecode commit: 9257cd6fcf]
Este cometimento está contido em:
Aryan Salmanpour
2023-12-05 13:06:34 -05:00
cometido por GitHub
ascendente 24dc12e75e
cometimento 08c99da4fa
4 ficheiros modificados com 70 adições e 53 eliminações
+17 -17
Ver ficheiro
@@ -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_;
};
+21 -18
Ver ficheiro
@@ -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;
}