rocDecode api defintions added for decoder and parser (#6)

* rocDecode api defintions added for decoder and parser

* addressed review comments and changed struct names to CamelCase

* minot reformatting
Этот коммит содержится в:
Rajy Rawther
2023-09-14 07:33:28 -07:00
коммит произвёл GitHub
родитель 3767aae7a1
Коммит 4ea67e279d
12 изменённых файлов: 927 добавлений и 165 удалений
+61
Просмотреть файл
@@ -0,0 +1,61 @@
/*
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"
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 {
public:
explicit RocParserHandle() {}; // 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;
}
}
private:
void clear_errors() { error = "";}
std::string error;
};
+36
Просмотреть файл
@@ -0,0 +1,36 @@
/*
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 "rocparser.h"
#include "parser_handle.h"
/**
* @brief
*
* @param pData
* @return rocDecodeStatus
*/
rocDecStatus RocVideoParser::ParseVideoData(RocdecSourceDataPacket *pData) {
// todo:
return ROCDEC_SUCCESS;
}
+71
Просмотреть файл
@@ -0,0 +1,71 @@
/*
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 "parser_handle.h"
#include "../commons.h"
/************************************************************************************************/
//! \ingroup FUNCTS
//! \fn rocParserStatus ROCDECAPI rocDecCreateVideoParser(RocdecVideoParser *pHandle, RocdecParserParams *pParams)
//! Create video parser object and initialize
/************************************************************************************************/
rocDecStatus ROCDECAPI
rocDecCreateVideoParser(RocdecVideoParser *pHandle, RocdecParserParams *pParams) {
RocdecVideoParser handle = nullptr;
try {
handle = new RocParserHandle();
}
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;
}
/************************************************************************************************/
//! \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
//! 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) {
auto parser_hdl = static_cast<RocParserHandle *> (handle);
rocDecStatus ret;
try {
ret = parser_hdl->roc_parser->ParseVideoData(pPacket);
}
catch(const std::exception& e) {
parser_hdl->capture_error(e.what());
ERR(e.what())
return ROCDEC_RUNTIME_ERROR;
}
return ret;
}
+4
Просмотреть файл
@@ -26,6 +26,10 @@ THE SOFTWARE.
#include "roc_decoder.h"
/**
* @brief DecHandle structure
*
*/
struct DecHandle {
explicit DecHandle() {}; //constructor
+7 -7
Просмотреть файл
@@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "commons.h"
#include "../commons.h"
#include "roc_decoder.h"
RocDecoder::RocDecoder(int device_id, int num_devices):device_id_ {device_id}, num_devices_{num_devices} {
@@ -32,29 +32,29 @@ RocDecoder::RocDecoder(int device_id, int num_devices):device_id_ {device_id}, n
}
rocDecStatus RocDecoder::getDecoderCaps(ROCDECDECODECAPS *pdc) {
rocDecStatus RocDecoder::getDecoderCaps(RocdecDecodeCaps *pdc) {
// todo:: return appropriate decStatus if fails
//vaQueryConfigProfiles
// fill the ROCDECDECODECAPS struct
// fill the RocdecDecodeCaps struct
// return status
return ROCDEC_NOT_IMPLEMENTED;
}
rocDecStatus RocDecoder::decodeFrame(ROCDECPICPARAMS *pPicParams) {
rocDecStatus RocDecoder::decodeFrame(RocdecPicParams *pPicParams) {
// todo:: return appropriate decStatus if fails
// call funsction to do va-api decoding using the picture parameters structure
// return status
return ROCDEC_NOT_IMPLEMENTED;
}
rocDecStatus RocDecoder::getDecodeStatus(int nPicIdx, ROCDECGETDECODESTATUS* pDecodeStatus) {
rocDecStatus RocDecoder::getDecodeStatus(int nPicIdx, RocdecDecodeStatus* pDecodeStatus) {
// todo:: return appropriate decStatus
// init vaapi decoder to get the decoding status of the picture specified by nPicIndex
// return status
return ROCDEC_NOT_IMPLEMENTED;
}
rocDecStatus RocDecoder::reconfigureDecoder(ROCDECRECONFIGUREDECODERINFO *pDecReconfigParams) {
rocDecStatus RocDecoder::reconfigureDecoder(RocdecReconfigureDecoderInfo *pDecReconfigParams) {
// todo:: return appropriate decStatus
// this will be called when the current configuration is changed during decoding
// release the current va-api decoder instance and create a new one with the new parameters (or reinit if available)
@@ -63,7 +63,7 @@ rocDecStatus RocDecoder::reconfigureDecoder(ROCDECRECONFIGUREDECODERINFO *pDecRe
}
rocDecStatus RocDecoder::mapVideoFrame(int nPicIdx, void *pDevMemPtr[3],
unsigned int *pHorizontalPitch[3], ROCDECPROCPARAMS *pVidPostprocParams) {
unsigned int *pHorizontalPitch[3], RocdecProcParams *pVidPostprocParams) {
// todo:: return appropriate decStatus
// Post-process and map video frame corresponding to nPicIdx 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
+6 -6
Просмотреть файл
@@ -38,11 +38,11 @@ class RocDecoder {
public:
RocDecoder(int device_id, int num_devices);
~RocDecoder();
rocDecStatus getDecoderCaps(ROCDECDECODECAPS *pdc);
rocDecStatus decodeFrame(ROCDECPICPARAMS *pPicParams);
rocDecStatus getDecodeStatus(int nPicIdx, ROCDECGETDECODESTATUS* pDecodeStatus);
rocDecStatus reconfigureDecoder(ROCDECRECONFIGUREDECODERINFO *pDecReconfigParams);
rocDecStatus mapVideoFrame(int nPicIdx, void *pDevMemPtr[3], unsigned int *pHorizontalPitch[3], ROCDECPROCPARAMS *pVidPostprocParams);
rocDecStatus getDecoderCaps(RocdecDecodeCaps *pdc);
rocDecStatus decodeFrame(RocdecPicParams *pPicParams);
rocDecStatus getDecodeStatus(int nPicIdx, RocdecDecodeStatus* pDecodeStatus);
rocDecStatus reconfigureDecoder(RocdecReconfigureDecoderInfo *pDecReconfigParams);
rocDecStatus mapVideoFrame(int nPicIdx, void *pDevMemPtr[3], unsigned int *pHorizontalPitch[3], RocdecProcParams *pVidPostprocParams);
rocDecStatus unMapVideoFrame(void *pMappedDevPtr);
private:
@@ -54,4 +54,4 @@ private:
hipDeviceProp_t hip_dev_prop_;
hipStream_t hip_stream_;
std::vector<std::string> drm_nodes_;
};
};
+15 -15
Просмотреть файл
@@ -21,14 +21,14 @@ THE SOFTWARE.
*/
#include "dec_handle.h"
#include "rocdecode.h"
#include "commons.h"
#include "../commons.h"
/*****************************************************************************************************/
//! \fn rocDecStatus ROCDECAPI rocDecCreateDecoder(rocDecDecoderHandle *phDecoder, ROCDECDECODECREATEINFO *pdci)
//! \fn rocDecStatus ROCDECAPI rocDecCreateDecoder(rocDecDecoderHandle *phDecoder, RocdecDecoderCreateInfo *pdci)
//! Create the decoder object based on pdci. A handle to the created decoder is returned
/*****************************************************************************************************/
rocDecStatus ROCDECAPI
rocDecCreateDecoder(rocDecDecoderHandle *phDecoder, ROCDECDECODECREATEINFO *pdci) {
rocDecCreateDecoder(rocDecDecoderHandle *phDecoder, RocdecDecoderCreateInfo *pdci) {
rocDecDecoderHandle handle = nullptr;
try {
handle = new DecHandle();
@@ -52,14 +52,14 @@ rocDecDestroyDecoder(rocDecDecoderHandle hDecoder) {
}
/**********************************************************************************************************************/
//! \fn rocDecStatus ROCDECAPI rocdecGetDecoderCaps(rocDecDecoderHandle hDecoder, ROCDECDECODECAPS *pdc)
//! \fn rocDecStatus ROCDECAPI rocdecGetDecoderCaps(rocDecDecoderHandle hDecoder, RocdecDecodeCaps *pdc)
//! Queries decode capabilities of AMD's VCN decoder based on CodecType, ChromaFormat and BitDepthMinus8 parameters.
//! 1. Application fills IN parameters CodecType, ChromaFormat and BitDepthMinus8 of ROCDECDECODECAPS structure
//! 1. Application fills IN parameters CodecType, ChromaFormat and BitDepthMinus8 of RocdecDecodeCaps structure
//! 2. On calling rocdecGetDecoderCaps, driver fills OUT parameters if the IN parameters are supported
//! If IN parameters passed to the driver are not supported by AMD-VCN-HW, then all OUT params are set to 0.
/**********************************************************************************************************************/
rocDecStatus ROCDECAPI
rocDecGetDecoderCaps(rocDecDecoderHandle hDecoder, ROCDECDECODECAPS *pdc) {
rocDecGetDecoderCaps(rocDecDecoderHandle hDecoder, RocdecDecodeCaps *pdc) {
auto handle = static_cast<DecHandle *> (hDecoder);
rocDecStatus ret;
try {
@@ -74,12 +74,12 @@ rocDecGetDecoderCaps(rocDecDecoderHandle hDecoder, ROCDECDECODECAPS *pdc) {
}
/*****************************************************************************************************/
//! \fn rocDecStatus ROCDECAPI rocDecDecodeFrame(rocDecDecoderHandle hDecoder, ROCDECPICPARAMS *pPicParams)
//! \fn rocDecStatus ROCDECAPI rocDecDecodeFrame(rocDecDecoderHandle hDecoder, RocdecPicParams *pPicParams)
//! Decodes a single picture
//! Submits the frame for HW decoding
/*****************************************************************************************************/
rocDecStatus ROCDECAPI
rocDecDecodeFrame(rocDecDecoderHandle hDecoder, ROCDECPICPARAMS *pPicParams) {
rocDecDecodeFrame(rocDecDecoderHandle hDecoder, RocdecPicParams *pPicParams) {
auto handle = static_cast<DecHandle *> (hDecoder);
rocDecStatus ret;
try {
@@ -94,13 +94,13 @@ rocDecDecodeFrame(rocDecDecoderHandle hDecoder, ROCDECPICPARAMS *pPicParams) {
}
/************************************************************************************************************/
//! \fn rocDecStatus ROCDECAPI rocDecGetDecodeStatus(rocDecDecoderHandle hDecoder, int nPicIdx, ROCDECGETDECODESTATUS* pDecodeStatus);
//! \fn rocDecStatus ROCDECAPI RocdecGetDecodeStatus(rocDecDecoderHandle hDecoder, int nPicIdx, RocdecDecodeStatus* pDecodeStatus);
//! Get the decode status for frame corresponding to nPicIdx
//! API is currently supported for HEVC, H264 and JPEG codecs.
//! API returns CUDA_ERROR_NOT_SUPPORTED error code for unsupported GPU or codec.
/************************************************************************************************************/
rocDecStatus ROCDECAPI
rocDecGetDecodeStatus(rocDecDecoderHandle hDecoder, int nPicIdx, ROCDECGETDECODESTATUS* pDecodeStatus) {
RocdecGetDecodeStatus(rocDecDecoderHandle hDecoder, int nPicIdx, RocdecDecodeStatus* pDecodeStatus) {
auto handle = static_cast<DecHandle *> (hDecoder);
rocDecStatus ret;
try {
@@ -115,12 +115,12 @@ rocDecGetDecodeStatus(rocDecDecoderHandle hDecoder, int nPicIdx, ROCDECGETDECODE
}
/*********************************************************************************************************/
//! \fn rocDecStatus ROCDECAPI rocDecReconfigureDecoder(rocDecDecoderHandle hDecoder, ROCDECRECONFIGUREDECODERINFO *pDecReconfigParams)
//! \fn rocDecStatus ROCDECAPI rocDecReconfigureDecoder(rocDecDecoderHandle hDecoder, RocdecReconfigureDecoderInfo *pDecReconfigParams)
//! 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
//! params, target area params change for same codec. Must be called during RocdecParserParams::pfnSequenceCallback
/*********************************************************************************************************/
rocDecStatus ROCDECAPI
rocDecReconfigureDecoder(rocDecDecoderHandle hDecoder, ROCDECRECONFIGUREDECODERINFO *pDecReconfigParams) {
rocDecReconfigureDecoder(rocDecDecoderHandle hDecoder, RocdecReconfigureDecoderInfo *pDecReconfigParams) {
auto handle = static_cast<DecHandle *> (hDecoder);
rocDecStatus ret;
try {
@@ -137,13 +137,13 @@ rocDecReconfigureDecoder(rocDecDecoderHandle hDecoder, ROCDECRECONFIGUREDECODERI
/************************************************************************************************************************/
//! \fn extern rocDecStatus ROCDECAPI rocDecMapVideoFrame(rocDecDecoderHandle hDecoder, int nPicIdx,
//! unsigned int *pDevMemPtr, unsigned int *pHorizontalPitch,
//! ROCDECPROCPARAMS *pVidPostprocParams);
//! RocdecProcParams *pVidPostprocParams);
//! Post-process and map video frame corresponding to nPicIdx 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 hDecoder, int nPicIdx,
void *pDevMemPtr[3], unsigned int *pHorizontalPitch[3], ROCDECPROCPARAMS *pVidPostprocParams) {
void *pDevMemPtr[3], unsigned int *pHorizontalPitch[3], RocdecProcParams *pVidPostprocParams) {
auto handle = static_cast<DecHandle *> (hDecoder);
rocDecStatus ret;
try {
+1 -1
Просмотреть файл
@@ -28,5 +28,5 @@ THE SOFTWARE.
#include <sstream>
#include <string.h>
#include "commons.h"
#include "../commons.h"
#include "vaapi_videodecoder.h"
Просмотреть файл