Files
rocm-systems/projects/rocdecode/src/rocdecode-host/roc_decoder_host.cpp
T
Rajy Rawther 40e072f394 FFMpeg decoder rocdecode integration (#583)
* initial commit

* initial implementation for host based decoder

* minor change

* cmake changes and added new sample

* rocdecDecode sample implementation

* rocdecode sample changes working

* working version of avcodec decoder and sample

* Add end of stream handling for repeated decoding with reconfigure

* reorg files and added changelog

* update readme

* revert file

* remove unused class members

* addressed reviw comment for changelog

* fix sample to work on more video files

* resolved review comments

* bumped version to 0.14.0

* fixed build warnings

* addressed review comments

* addressed review comments

* addressed review comments

* fixed readme to match .cpp file options for parameters

* updated review comments, readme, and added test data for the sample

* fixed bug for saving frame for 10 bit videos

* addressed review comments

* addressed all the new review comments

[ROCm/rocdecode commit: 3ddb12f075]
2025-06-07 13:12:57 -04:00

85 строки
3.4 KiB
C++

/*
Copyright (c) 2023 - 2025 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 "../commons.h"
#include "roc_decoder_host.h"
RocDecoderHost::RocDecoderHost(RocDecoderHostCreateInfo& decoder_create_info): avcodec_video_decoder_{decoder_create_info}, decoder_create_info_{decoder_create_info} {}
RocDecoderHost::~RocDecoderHost() {}
rocDecStatus RocDecoderHost::InitializeDecoder() {
rocDecStatus rocdec_status = ROCDEC_SUCCESS;
if (!decoder_create_info_.user_data) {
ERR("Invalid function callback pointer passed");
return ROCDEC_NOT_INITIALIZED;
}
rocdec_status = avcodec_video_decoder_.InitializeDecoder();
if (rocdec_status != ROCDEC_SUCCESS) {
ERR("Failed to initialize the FFMpeg Video decoder.");
return rocdec_status;
}
return rocdec_status;
}
rocDecStatus RocDecoderHost::DecodeFrame(RocdecPicParamsHost *pic_params) {
rocDecStatus rocdec_status = ROCDEC_SUCCESS;
rocdec_status = avcodec_video_decoder_.SubmitDecode(pic_params);
if (rocdec_status != ROCDEC_SUCCESS) {
ERR("Decode submission is not successful.");
}
return rocdec_status;
}
rocDecStatus RocDecoderHost::GetDecodeStatus(int pic_idx, RocdecDecodeStatus* decode_status) {
rocDecStatus rocdec_status = ROCDEC_SUCCESS;
rocdec_status = avcodec_video_decoder_.GetDecodeStatus(pic_idx, decode_status);
if (rocdec_status != ROCDEC_SUCCESS) {
ERR("Failed to query the decode status.");
}
return rocdec_status;
}
rocDecStatus RocDecoderHost::ReconfigureDecoder(RocdecReconfigureDecoderInfo *reconfig_params) {
if (reconfig_params == nullptr) {
return ROCDEC_INVALID_PARAMETER;
}
rocDecStatus rocdec_status = avcodec_video_decoder_.ReconfigureDecoder(reconfig_params);
if (rocdec_status != ROCDEC_SUCCESS) {
ERR("Reconfiguration of the decoder failed.");
return rocdec_status;
}
return rocdec_status;
}
rocDecStatus RocDecoderHost::GetVideoFrame(int pic_idx, void **frame_ptr, uint32_t *line_size, RocdecProcParams *vid_postproc_params) {
if (vid_postproc_params == nullptr || frame_ptr == nullptr) {
return ROCDEC_INVALID_PARAMETER;
}
rocDecStatus rocdec_status = avcodec_video_decoder_.GetVideoFrame(pic_idx, frame_ptr, line_size, vid_postproc_params);
if (rocdec_status != ROCDEC_SUCCESS) {
ERR("GetVideoFrame failed.");
return rocdec_status;
}
return rocdec_status;
}