diff --git a/CMakeLists.txt b/CMakeLists.txt index 3483d5c505..1a556523cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ if(HIP_FOUND AND Libva_FOUND) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17") target_link_libraries(${PROJECT_NAME} Libva::va Libva::va_drm hip::device) install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) - install(FILES api/rocdecode.h utils/video_demuxer.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) + install(FILES api/rocdecode.h api/rocparser.h utils/video_demuxer.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) else() if (NOT HIP_FOUND) diff --git a/api/rocdecode.h b/api/rocdecode.h index b57374b474..03ae9eb402 100644 --- a/api/rocdecode.h +++ b/api/rocdecode.h @@ -62,7 +62,8 @@ typedef enum rocDecStatus_enum{ ROCDEC_OUTOF_MEMORY = -4, ROCDEC_INVALID_PARAMETER = -5, ROCDEC_NOT_IMPLEMENTED = -6, - ROCDEC_NOT_SUPPORTED = -7, + ROCDEC_NOT_INITIALIZED = -7, + ROCDEC_NOT_SUPPORTED = -8, ROCDEC_SUCCESS = 0, }rocDecStatus; diff --git a/api/rocparser.h b/api/rocparser.h index 1cb51d95b9..1aa8b7f9af 100644 --- a/api/rocparser.h +++ b/api/rocparser.h @@ -216,7 +216,7 @@ typedef struct _RocdecSeiMessageInfo { typedef int (ROCDECAPI *PFNVIDSEQUENCECALLBACK)(void *, RocdecVideoFormat *); typedef int (ROCDECAPI *PFNVIDDECODECALLBACK)(void *, RocdecPicParams *); typedef int (ROCDECAPI *PFNVIDDISPLAYCALLBACK)(void *, RocdecParserDispInfo *); -typedef int (ROCDECAPI *PFNVIDOPPOINTCALLBACK)(void *, RocdecOperatingPointInfo*); // reserved for future (AV1 specific) +//typedef int (ROCDECAPI *PFNVIDOPPOINTCALLBACK)(void *, RocdecOperatingPointInfo*); // reserved for future (AV1 specific) typedef int (ROCDECAPI *PFNVIDSEIMSGCALLBACK) (void *, RocdecSeiMessageInfo *); /** @@ -239,8 +239,8 @@ typedef struct _RocdecParserParams { PFNVIDSEQUENCECALLBACK pfnSequenceCallback; /**< IN: Called before decoding frames and/or whenever there is a fmt change */ PFNVIDDECODECALLBACK pfnDecodePicture; /**< IN: Called when a picture is ready to be decoded (decode order) */ PFNVIDDISPLAYCALLBACK pfnDisplayPicture; /**< IN: Called whenever a picture is ready to be displayed (display order) */ - PFNVIDOPPOINTCALLBACK pfnGetOperatingPoint; /**< IN: Called from AV1 sequence header to get operating point of a AV1 - scalable bitstream */ + //PFNVIDOPPOINTCALLBACK pfnGetOperatingPoint; /**< IN: Called from AV1 sequence header to get operating point of a AV1 + // scalable bitstream */ PFNVIDSEIMSGCALLBACK pfnGetSEIMsg; /**< IN: Called when all SEI messages are parsed for particular frame */ void *pvReserved2[5]; /**< Reserved for future use - set to NULL */ RocdecVideoFormatEx *pExtVideoInfo; /**< IN: [Optional] sequence header data from system layer */ @@ -265,6 +265,13 @@ extern rocDecStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *pHandle /************************************************************************************************/ extern rocDecStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser handle, RocdecSourceDataPacket *pPacket); +/************************************************************************************************/ +//! \ingroup FUNCTS +//! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser handle) +//! Destroy the video parser object +/************************************************************************************************/ +extern rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser handle); + #if defined(__cplusplus) } #endif /* __cplusplus */ diff --git a/src/parser/h264_parser.cpp b/src/parser/h264_parser.cpp new file mode 100644 index 0000000000..be452feb8e --- /dev/null +++ b/src/parser/h264_parser.cpp @@ -0,0 +1,52 @@ +/* +Copyright (c) 2023 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "h264_parser.h" + +/** + * @brief Construct a new HEVCParser object + * + */ +H264VideoParser::H264VideoParser() { + +} + +/** + * @brief Function to initialize any h264 parser related members + * + * @return rocDecStatus + */ +rocDecStatus H264VideoParser::Initialize(RocdecParserParams *pParams) { + RocVideoParser::Initialize(pParams); + //todo:: + return ROCDEC_NOT_IMPLEMENTED; +} + +/** + * @brief Function to Parse video data: Typically called from application when a demuxed picture is ready to be parsed + * + * @param pData: IN: pointer to demuxed data packet + * @return rocDecStatus + */ +rocDecStatus H264VideoParser::ParseVideoData(RocdecSourceDataPacket *pData) { + return ROCDEC_NOT_IMPLEMENTED; +} \ No newline at end of file diff --git a/src/parser/h264_parser.h b/src/parser/h264_parser.h new file mode 100644 index 0000000000..80392926ed --- /dev/null +++ b/src/parser/h264_parser.h @@ -0,0 +1,51 @@ +/* +Copyright (c) 2023 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +#pragma once + +#include "roc_video_parser.h" + +class H264VideoParser : public RocVideoParser { + +public: + /** + * @brief Construct a new HEVCParser object + * + */ + H264VideoParser(); + /** + * @brief Derived Function to Initialize the parser + * + * @return rocDecStatus + */ + virtual rocDecStatus Initialize(RocdecParserParams *pParams); + /** + * @brief Function to Parse video data: Typically called from application when a demuxed picture is ready to be parsed + * @brief Derived from base class + * + * @param pData: Pointer to picture data + * @return rocDecStatus: returns success on completion, else error_code for failure + */ + virtual rocDecStatus ParseVideoData(RocdecSourceDataPacket *pData); + +private: + +}; \ No newline at end of file diff --git a/src/parser/hevc_parser.cpp b/src/parser/hevc_parser.cpp new file mode 100644 index 0000000000..4cc5dabe42 --- /dev/null +++ b/src/parser/hevc_parser.cpp @@ -0,0 +1,52 @@ +/* +Copyright (c) 2023 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include "hevc_parser.h" + +/** + * @brief Constructs a new HEVCParser object + * + */ +HEVCVideoParser::HEVCVideoParser() { + +} + +/** + * @brief Function to initialize any hevc parser related members + * + * @return rocDecStatus + */ +rocDecStatus HEVCVideoParser::Initialize(RocdecParserParams *pParams) { + //todo:: + RocVideoParser::Initialize(pParams); + return ROCDEC_NOT_IMPLEMENTED; +} + +/** + * @brief Function to Parse video data: Typically called from application when a demuxed picture is ready to be parsed + * + * @param pData: IN: pointer to demuxed data packet + * @return rocDecStatus + */ +rocDecStatus HEVCVideoParser::ParseVideoData(RocdecSourceDataPacket *pData) { + return ROCDEC_NOT_IMPLEMENTED; +} \ No newline at end of file diff --git a/src/parser/hevc_parser.h b/src/parser/hevc_parser.h new file mode 100644 index 0000000000..385bd78e37 --- /dev/null +++ b/src/parser/hevc_parser.h @@ -0,0 +1,50 @@ +/* +Copyright (c) 2023 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +#pragma once + +#include "roc_video_parser.h" + +class HEVCVideoParser : public RocVideoParser { + +public: + /** + * @brief Construct a new HEVCParser object + * + */ + HEVCVideoParser(); + /** + * @brief Function to Initialize the parser + * + * @return rocDecStatus + */ + virtual rocDecStatus Initialize(RocdecParserParams *pParams); + /** + * @brief Function to Parse video data: Typically called from application when a demuxed picture is ready to be parsed + * + * @param pData: Pointer to picture data + * @return rocDecStatus: returns success on completion, else error_code for failure + */ + virtual rocDecStatus ParseVideoData(RocdecSourceDataPacket *pData); // pure virtual: implemented by derived class + +private: + +}; \ No newline at end of file diff --git a/src/parser/parser_handle.h b/src/parser/parser_handle.h index f028fa8873..81ecd178ac 100644 --- a/src/parser/parser_handle.h +++ b/src/parser/parser_handle.h @@ -24,38 +24,40 @@ THE SOFTWARE. #include #include #include "rocparser.h" +#include "roc_video_parser.h" +#include "h264_parser.h" +#include "hevc_parser.h" -class RocVideoParser { -public: - RocVideoParser() {}; // default constructor - RocVideoParser(RocdecParserParams *pParams): parser_params_(*pParams) {}; - ~RocVideoParser(); - void SetParserParams(RocdecParserParams *pParams) { parser_params_ = *pParams; }; - RocdecParserParams *GetParserParams() {return &parser_params_;}; - rocDecStatus ParseVideoData(RocdecSourceDataPacket *pData); - -private: - RocdecParserParams parser_params_; -}; - -struct RocParserHandle { +class RocParserHandle { public: - explicit RocParserHandle() {}; // default constructor + explicit RocParserHandle(RocdecParserParams *pParams) { create_parser(pParams); }; // default constructor ~RocParserHandle() { clear_errors(); } - std::shared_ptr roc_parser; // class instantiation 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; } - bool set_parser_params(RocdecParserParams *pParams) { - if(roc_parser) { - roc_parser->SetParserParams(pParams); - return true; - } else { - return false; - } - } + rocDecStatus ParseVideoData(RocdecSourceDataPacket *pPacket) { return roc_parser_->ParseVideoData(pPacket); } private: - void clear_errors() { error = "";} + std::shared_ptr roc_parser_ = nullptr; // class instantiation + void clear_errors() { error = ""; } + void create_parser(RocdecParserParams *pParams) { + switch(pParams->CodecType) { + case rocDecVideoCodec_H264: + roc_parser_ = std::make_shared(); + break; + case rocDecVideoCodec_HEVC: + roc_parser_ = std::make_shared(); + break; + default: + THROW("Unsupported parser type "+ TOSTR(pParams->CodecType)); + break; + } + + if (roc_parser_ ) { + rocDecStatus ret = roc_parser_->Initialize(pParams); + if (ret != ROCDEC_SUCCESS) + THROW("rocParser Initialization failed with error: "+ TOSTR(ret)); + } + } std::string error; }; \ No newline at end of file diff --git a/src/parser/roc_video_parser.cpp b/src/parser/roc_video_parser.cpp index bc81e60b80..ea869935ae 100644 --- a/src/parser/roc_video_parser.cpp +++ b/src/parser/roc_video_parser.cpp @@ -19,18 +19,26 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include "rocparser.h" -#include "parser_handle.h" - +#include "roc_video_parser.h" /** - * @brief + * @brief Initializes any parser related stuff for all parsers * - * @param pData - * @return rocDecodeStatus + * @return rocDecStatus : ROCDEC_SUCCESS on success */ -rocDecStatus RocVideoParser::ParseVideoData(RocdecSourceDataPacket *pData) { - // todo: +rocDecStatus RocVideoParser::Initialize(RocdecParserParams *pParams) { + if(pParams == nullptr) { + ERR(STR("Parser parameters are not set for the parser")); + return ROCDEC_NOT_INITIALIZED; + } + // Initialize callback function pointers + pfn_sequece_cb_ = pParams->pfnSequenceCallback; /**< Called before decoding frames and/or whenever there is a fmt change */ + pfn_decode_picture_cb_ = pParams->pfnDecodePicture; /**< Called when a picture is ready to be decoded (decode order) */ + pfn_display_picture_cb_ = pParams->pfnDisplayPicture; /**< Called whenever a picture is ready to be displayed (display order) */ + pfn_get_sei_message_cb_ = pParams->pfnGetSEIMsg; /**< Called when all SEI messages are parsed for particular frame */ + + parser_params_ = pParams; + return ROCDEC_SUCCESS; } diff --git a/src/parser/roc_video_parser.h b/src/parser/roc_video_parser.h new file mode 100644 index 0000000000..12f2370290 --- /dev/null +++ b/src/parser/roc_video_parser.h @@ -0,0 +1,53 @@ +/* +Copyright (c) 2023 - 2023 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ +#pragma once + +#include +#include +#include "rocparser.h" +#include "../commons.h" + +/** + * @brief Base class for video parsing + * + */ +class RocVideoParser { +public: + RocVideoParser() {}; // default constructor + RocVideoParser(RocdecParserParams *pParams) : parser_params_(pParams) {}; + virtual ~RocVideoParser() = default ; + virtual void SetParserParams(RocdecParserParams *pParams) { parser_params_ = pParams; }; + RocdecParserParams *GetParserParams() {return parser_params_;}; + virtual rocDecStatus Initialize(RocdecParserParams *pParams); + virtual rocDecStatus ParseVideoData(RocdecSourceDataPacket *pData) = 0; // pure virtual: implemented by derived class + +protected: + RocdecParserParams *parser_params_ = nullptr; + /** + * @brief callback function pointers for the parser + * + */ + PFNVIDSEQUENCECALLBACK pfn_sequece_cb_; /**< Called before decoding frames and/or whenever there is a fmt change */ + PFNVIDDECODECALLBACK pfn_decode_picture_cb_; /**< Called when a picture is ready to be decoded (decode order) */ + PFNVIDDISPLAYCALLBACK pfn_display_picture_cb_; /**< Called whenever a picture is ready to be displayed (display order) */ + PFNVIDSEIMSGCALLBACK pfn_get_sei_message_cb_; /**< Called when all SEI messages are parsed for particular frame */ +}; diff --git a/src/parser/rocparser_api.cpp b/src/parser/rocparser_api.cpp index 6535322828..294e7b243e 100644 --- a/src/parser/rocparser_api.cpp +++ b/src/parser/rocparser_api.cpp @@ -32,15 +32,11 @@ rocDecStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *pHandle, RocdecParserParams *pParams) { RocdecVideoParser handle = nullptr; try { - handle = new RocParserHandle(); + handle = new RocParserHandle(pParams); } catch(const std::exception& e) { ERR( STR("Failed to init the rocDecode handle, ") + STR(e.what())) } - //set params for the handle - auto parser_handle = static_cast (handle); - if (!parser_handle->set_parser_params(pParams)) - return ROCDEC_INVALID_PARAMETER; *pHandle = handle; return rocDecStatus::ROCDEC_SUCCESS; } @@ -60,7 +56,7 @@ rocDecParseVideoData(RocdecVideoParser handle, RocdecSourceDataPacket *pPacket) auto parser_hdl = static_cast (handle); rocDecStatus ret; try { - ret = parser_hdl->roc_parser->ParseVideoData(pPacket); + ret = parser_hdl->ParseVideoData(pPacket); } catch(const std::exception& e) { parser_hdl->capture_error(e.what());