Add 'projects/rocprofiler-sdk/' from commit 'bf0fad1d5406fbc51403ba1aa9621a9d4a9bce2b'
git-subtree-dir: projects/rocprofiler-sdk git-subtree-mainline:50a90550e9git-subtree-split:bf0fad1d54
Этот коммит содержится в:
@@ -0,0 +1,44 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
cmake_minimum_required(VERSION 3.21.0 FATAL_ERROR)
|
||||
|
||||
if(NOT CMAKE_HIP_COMPILER)
|
||||
find_program(
|
||||
amdclangpp_EXECUTABLE
|
||||
NAMES amdclang++
|
||||
HINTS ${ROCM_PATH} ENV ROCM_PATH /opt/rocm
|
||||
PATHS ${ROCM_PATH} ENV ROCM_PATH /opt/rocm
|
||||
PATH_SUFFIXES bin llvm/bin NO_CACHE)
|
||||
mark_as_advanced(amdclangpp_EXECUTABLE)
|
||||
|
||||
if(amdclangpp_EXECUTABLE)
|
||||
set(CMAKE_HIP_COMPILER "${amdclangpp_EXECUTABLE}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
project(rocprofiler-tool-test-app-rocdecode LANGUAGES CXX HIP)
|
||||
|
||||
foreach(_TYPE DEBUG MINSIZEREL RELEASE RELWITHDEBINFO)
|
||||
if("${CMAKE_HIP_FLAGS_${_TYPE}}" STREQUAL "")
|
||||
set(CMAKE_HIP_FLAGS_${_TYPE} "${CMAKE_CXX_FLAGS_${_TYPE}}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_HIP_STANDARD 17)
|
||||
set(CMAKE_HIP_EXTENSIONS OFF)
|
||||
set(CMAKE_HIP_STANDARD_REQUIRED ON)
|
||||
|
||||
set_source_files_properties(rocdecode.cpp PROPERTIES LANGUAGE HIP)
|
||||
add_executable(rocdecode-demo)
|
||||
target_sources(rocdecode-demo PRIVATE rocdecode.cpp)
|
||||
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(rocDecode REQUIRED)
|
||||
target_link_libraries(
|
||||
rocdecode-demo
|
||||
PRIVATE rocprofiler-sdk::tests-build-flags Threads::Threads hsa-runtime64
|
||||
rocprofiler-sdk::tests-common-library rocDecode::rocDecode)
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
Copyright (c) 2024 - 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 <rocdecode/roc_bitstream_reader.h>
|
||||
#include <rocdecode/rocdecode.h>
|
||||
#include <rocdecode/rocparser.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
// Get input file
|
||||
std::string input_file_path{};
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
if(!strcmp(argv[i], "-i"))
|
||||
{
|
||||
if(++i == argc)
|
||||
{
|
||||
std::cerr << "Provide path to input file" << std::endl;
|
||||
}
|
||||
input_file_path = argv[i];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Set up bitstreamreader
|
||||
RocdecBitstreamReader bs_reader = nullptr;
|
||||
rocDecVideoCodec rocdec_codec_id{};
|
||||
int bit_depth{};
|
||||
if(rocDecCreateBitstreamReader(&bs_reader, input_file_path.c_str()) != ROCDEC_SUCCESS)
|
||||
{
|
||||
std::cerr << "Failed to create the bitstream reader." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(rocDecGetBitstreamCodecType(bs_reader, &rocdec_codec_id) != ROCDEC_SUCCESS)
|
||||
{
|
||||
std::cerr << "Failed to get stream codec type." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(rocdec_codec_id >= rocDecVideoCodec_NumCodecs)
|
||||
{
|
||||
std::cerr << "Unsupported stream file type or codec type by the bitstream reader. Exiting."
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(rocDecGetBitstreamBitDepth(bs_reader, &bit_depth) != ROCDEC_SUCCESS)
|
||||
{
|
||||
std::cerr << "Failed to get stream bit depth." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t* pvideo = nullptr;
|
||||
int n_video_bytes = 0;
|
||||
int64_t pts = 0;
|
||||
if(rocDecGetBitstreamPicData(bs_reader, &pvideo, &n_video_bytes, &pts) != ROCDEC_SUCCESS)
|
||||
{
|
||||
std::cerr << "Failed to get picture data." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The following commands were originally used via the RocVideoDecoder from the
|
||||
// roc_video_dec.cpp file from the rocDecode repository. However, this file kept causing
|
||||
// compiler issues, so the file was removed. The following commands will return errors, but they
|
||||
// should should be tracked for testing purposes
|
||||
|
||||
// rocDecCreateVideoParser
|
||||
RocdecVideoParser rocdec_parser_ = nullptr;
|
||||
RocdecParserParams parser_params = {};
|
||||
parser_params.codec_type = rocdec_codec_id;
|
||||
parser_params.max_num_decode_surfaces = 1;
|
||||
parser_params.clock_rate = 0;
|
||||
parser_params.max_display_delay = 1;
|
||||
parser_params.pfn_sequence_callback = nullptr;
|
||||
parser_params.pfn_decode_picture = nullptr;
|
||||
rocDecCreateVideoParser(&rocdec_parser_, &parser_params);
|
||||
|
||||
// rocDecGetDecoderCaps
|
||||
RocdecDecodeCaps decode_caps{};
|
||||
decode_caps.codec_type = rocdec_codec_id;
|
||||
decode_caps.chroma_format = rocDecVideoChromaFormat_420;
|
||||
decode_caps.bit_depth_minus_8 = 0;
|
||||
rocDecGetDecoderCaps(&decode_caps);
|
||||
|
||||
// rocDecCreateDecoder
|
||||
rocDecDecoderHandle roc_decoder_ = nullptr;
|
||||
RocDecoderCreateInfo videoDecodeCreateInfo = {};
|
||||
videoDecodeCreateInfo.device_id = 0;
|
||||
videoDecodeCreateInfo.codec_type = rocdec_codec_id;
|
||||
videoDecodeCreateInfo.chroma_format = rocDecVideoChromaFormat_420;
|
||||
videoDecodeCreateInfo.bit_depth_minus_8 = 0;
|
||||
rocDecCreateDecoder(&roc_decoder_, &videoDecodeCreateInfo);
|
||||
|
||||
// rocDecDecodeFrame
|
||||
RocdecPicParams* pPicParams = nullptr;
|
||||
rocDecDecodeFrame(roc_decoder_, pPicParams);
|
||||
|
||||
// rocDecParseVideoData
|
||||
RocdecSourceDataPacket packet = {};
|
||||
rocDecParseVideoData(rocdec_parser_, &packet);
|
||||
|
||||
// rocDecGetVideoFrame
|
||||
void* src_dev_ptr[3] = {0};
|
||||
uint32_t src_pitch[3] = {0};
|
||||
RocdecProcParams video_proc_params = {};
|
||||
rocDecGetVideoFrame(roc_decoder_, 0, src_dev_ptr, src_pitch, &video_proc_params);
|
||||
|
||||
// rocDecGetDecodeStatus
|
||||
RocdecDecodeStatus dec_status{};
|
||||
rocDecGetDecodeStatus(roc_decoder_, 0, &dec_status);
|
||||
if(bs_reader)
|
||||
{
|
||||
rocDecDestroyBitstreamReader(bs_reader);
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user