parser high level class implementation (#10)
* rocDecode api defintions added for decoder and parser
* addressed review comments and changed struct names to CamelCase
* minot reformatting
* parser high level class implementation
[ROCm/rocdecode commit: 0a991c1776]
Tento commit je obsažen v:
@@ -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;
|
||||
}
|
||||
@@ -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:
|
||||
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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:
|
||||
|
||||
};
|
||||
@@ -24,38 +24,40 @@ THE SOFTWARE.
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#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<RocVideoParser> 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<RocVideoParser> 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<H264VideoParser>();
|
||||
break;
|
||||
case rocDecVideoCodec_HEVC:
|
||||
roc_parser_ = std::make_shared<HEVCVideoParser>();
|
||||
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;
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 <memory>
|
||||
#include <string>
|
||||
#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 */
|
||||
};
|
||||
@@ -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<RocParserHandle *> (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<RocParserHandle *> (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());
|
||||
|
||||
Odkázat v novém úkolu
Zablokovat Uživatele