From 29bfe5e3bd39332bcf3f42bda2cddad7c08fefd6 Mon Sep 17 00:00:00 2001 From: Rajy Rawther Date: Wed, 9 Oct 2024 10:29:08 -0700 Subject: [PATCH] Add new API rocDecParserMarkFrameForReuse() for Parser (#430) * added new API to release video frame for decoder and parser * removed ReleseFrame() from low level parser classes * Removed rocDecReleaseFrame() from decoder and added in parser * address review comments * revert un-necessary files * minor fix * remove unused function * minor formatting fix --- CHANGELOG.md | 1 + api/rocparser.h | 7 +++++++ src/parser/parser_handle.h | 1 + src/parser/roc_video_parser.cpp | 9 ++++++++- src/parser/roc_video_parser.h | 8 ++++++++ src/parser/rocparser_api.cpp | 24 ++++++++++++++++++++++++ src/rocdecode/roc_decoder.cpp | 4 ++-- src/rocdecode/roc_decoder.h | 2 +- 8 files changed, 52 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69027e7ce..40876c3e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Documentation for rocDecode is available at ### Additions * Clang - Default CXX compiler +* Parser - Add new API rocDecParserMarkFrameForReuse() ### Optimizations diff --git a/api/rocparser.h b/api/rocparser.h index 8f666376d5..bcb245cf3c 100644 --- a/api/rocparser.h +++ b/api/rocparser.h @@ -275,6 +275,13 @@ extern rocDecStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *parser_ /************************************************************************************************/ extern rocDecStatus ROCDECAPI rocDecParseVideoData(RocdecVideoParser parser_handle, RocdecSourceDataPacket *packet); +/************************************************************************************************/ +//! \ingroup group_rocparser +//! \fn rocDecStatus ROCDECAPI rocDecParserMarkFrameForReuse(RocdecVideoParser parser_handle, int pic_idx) +//! Mark frame with index pic_idx in parser's buffer pool for reuse (means the frame has been consumed) +/************************************************************************************************/ +extern rocDecStatus ROCDECAPI rocDecParserMarkFrameForReuse(RocdecVideoParser parser_handle, int pic_idx); + /************************************************************************************************/ //! \ingroup group_rocparser //! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser parser_handle) diff --git a/src/parser/parser_handle.h b/src/parser/parser_handle.h index c354029a86..d623a71e71 100644 --- a/src/parser/parser_handle.h +++ b/src/parser/parser_handle.h @@ -37,6 +37,7 @@ public: 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 MarkFrameForReuse(int pic_idx) { return roc_parser_->MarkFrameForReuse(pic_idx); } rocDecStatus DestroyParser() { return DestroyParserInternal(); }; private: diff --git a/src/parser/roc_video_parser.cpp b/src/parser/roc_video_parser.cpp index 23e1cd178b..7db24a9870 100644 --- a/src/parser/roc_video_parser.cpp +++ b/src/parser/roc_video_parser.cpp @@ -73,6 +73,14 @@ rocDecStatus RocVideoParser::Initialize(RocdecParserParams *pParams) { return ROCDEC_SUCCESS; } +rocDecStatus RocVideoParser::MarkFrameForReuse(int pic_idx) { + if (pic_idx < 0) { + return ROCDEC_INVALID_PARAMETER; + } + //todo:: + return ROCDEC_NOT_IMPLEMENTED; +} + void RocVideoParser::InitDecBufPool() { for (int i = 0; i < dec_buf_pool_size_; i++) { decode_buffer_pool_[i].use_status = kNotUsed; @@ -106,7 +114,6 @@ ParserResult RocVideoParser::OutputDecodedPictures(bool no_delay) { pfn_display_picture_cb_(parser_params_.user_data, &disp_info); decode_buffer_pool_[output_pic_list_[i]].use_status &= ~kFrameUsedForDisplay; } - num_output_pics_ = disp_delay; // Shift the remaining frames to the top if (num_output_pics_) { diff --git a/src/parser/roc_video_parser.h b/src/parser/roc_video_parser.h index a73519cb08..6be47603f4 100644 --- a/src/parser/roc_video_parser.h +++ b/src/parser/roc_video_parser.h @@ -102,6 +102,14 @@ public: virtual rocDecStatus Initialize(RocdecParserParams *pParams); virtual rocDecStatus ParseVideoData(RocdecSourceDataPacket *pData) = 0; // pure virtual: implemented by derived class virtual rocDecStatus UnInitialize() = 0; // pure virtual: implemented by derived class + /** + * @brief function to to release surface with pic_idx and mark it for reuse, can be called from a different thread than decode thread + * @brief calling thread is responsible for syncronizing + * \param [in] pic_idx surface index for the picture to be released + * + * @return rocDecStatus + */ + virtual rocDecStatus MarkFrameForReuse(int pic_idx); protected: RocdecParserParams parser_params_ = {}; diff --git a/src/parser/rocparser_api.cpp b/src/parser/rocparser_api.cpp index 9f340bdcdf..2fa51f596c 100644 --- a/src/parser/rocparser_api.cpp +++ b/src/parser/rocparser_api.cpp @@ -81,6 +81,30 @@ rocDecParseVideoData(RocdecVideoParser parser_handle, RocdecSourceDataPacket *pa return ret; } +/************************************************************************************************/ +//! \ingroup group_rocparser +//! \fn rocDecStatus ROCDECAPI rocDecParserMarkFrameForReuse(RocdecVideoParser parser_handle, int pic_idx) +//! Release frame with index pic_idx from parser's buffer pool and mark it for reuse +/************************************************************************************************/ +rocDecStatus ROCDECAPI +rocDecParserMarkFrameForReuse(RocdecVideoParser parser_handle, int pic_idx) { + if (parser_handle == nullptr || pic_idx < 0) { + return ROCDEC_INVALID_PARAMETER; + } + auto roc_parser_handle = static_cast(parser_handle); + rocDecStatus ret; + try { + ret = roc_parser_handle->MarkFrameForReuse(pic_idx); + } + catch(const std::exception& e) { + roc_parser_handle->CaptureError(e.what()); + ERR(e.what()) + return ROCDEC_RUNTIME_ERROR; + } + return ret; + +} + /************************************************************************************************/ //! \ingroup FUNCTS //! \fn rocDecStatus ROCDECAPI rocDecDestroyVideoParser(RocdecVideoParser parser_handle) diff --git a/src/rocdecode/roc_decoder.cpp b/src/rocdecode/roc_decoder.cpp index 321105336f..53b5910d62 100644 --- a/src/rocdecode/roc_decoder.cpp +++ b/src/rocdecode/roc_decoder.cpp @@ -93,7 +93,7 @@ rocDecStatus RocDecoder::ReconfigureDecoder(RocdecReconfigureDecoderInfo *reconf } rocDecStatus rocdec_status; for (int pic_idx = 0; pic_idx < hip_interop_.size(); pic_idx++) { - rocdec_status = ReleaseVideoFrame(pic_idx); + rocdec_status = FreeVideoFrame(pic_idx); if (rocdec_status != ROCDEC_SUCCESS) { ERR("Releasing the video frame for picture idx = " + TOSTR(pic_idx) + " failed during reconfiguration."); return rocdec_status; @@ -172,7 +172,7 @@ rocDecStatus RocDecoder::GetVideoFrame(int pic_idx, void *dev_mem_ptr[3], uint32 return rocdec_status; } -rocDecStatus RocDecoder::ReleaseVideoFrame(int pic_idx) { +rocDecStatus RocDecoder::FreeVideoFrame(int pic_idx) { if (pic_idx >= hip_interop_.size()) { return ROCDEC_INVALID_PARAMETER; } diff --git a/src/rocdecode/roc_decoder.h b/src/rocdecode/roc_decoder.h index 3aec889545..f4b1ebc482 100644 --- a/src/rocdecode/roc_decoder.h +++ b/src/rocdecode/roc_decoder.h @@ -64,7 +64,7 @@ public: private: rocDecStatus InitHIP(int device_id); - rocDecStatus ReleaseVideoFrame(int pic_idx); + rocDecStatus FreeVideoFrame(int pic_idx); int num_devices_; RocDecoderCreateInfo decoder_create_info_; VaapiVideoDecoder va_video_decoder_;