Sample & Test - Add rocdecDecode to the ctest and decouple the rocdecode-host from it (#685)
* Add rocdecDecode to the ctest and decouple the rocdecode-host from it
* clean up
[ROCm/rocdecode commit: 158f7fd2ba]
This commit is contained in:
@@ -67,25 +67,36 @@ find_package(FFmpeg QUIET)
|
||||
find_package(rocdecode QUIET)
|
||||
find_package(rocdecode-host 1.0.0 QUIET)
|
||||
|
||||
if(HIP_FOUND AND FFMPEG_FOUND AND rocdecode_FOUND AND rocdecode-host_FOUND)
|
||||
if(HIP_FOUND AND rocdecode_FOUND)
|
||||
# HIP
|
||||
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} hip::host)
|
||||
# FFMPEG
|
||||
include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR}
|
||||
${AVFORMAT_INCLUDE_DIR})
|
||||
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES})
|
||||
|
||||
if(FFMPEG_FOUND)
|
||||
# FFMPEG
|
||||
include_directories(${AVUTIL_INCLUDE_DIR} ${AVCODEC_INCLUDE_DIR}
|
||||
${AVFORMAT_INCLUDE_DIR})
|
||||
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} ${FFMPEG_LIBRARIES})
|
||||
endif()
|
||||
if(rocdecode-host_FOUND)
|
||||
# rocdecode-host
|
||||
include_directories(${rocdecode-host_INCLUDE_DIR})
|
||||
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocdecode::rocdecode-host)
|
||||
endif()
|
||||
|
||||
# rocdecode and utils
|
||||
include_directories(${rocdecode_INCLUDE_DIR} ${ROCM_PATH}/lib)
|
||||
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocdecode::rocdecode)
|
||||
# rocdecode-host
|
||||
include_directories(${rocdecode-host_INCLUDE_DIR})
|
||||
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocdecode::rocdecode-host)
|
||||
|
||||
# rocdecode
|
||||
# sample app exe
|
||||
list(APPEND SOURCES ${PROJECT_SOURCE_DIR} rocdecdecode.cpp)
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17")
|
||||
if(FFMPEG_FOUND AND rocdecode-host_FOUND)
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_HOST_DECODE=1)
|
||||
else()
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_HOST_DECODE=0)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST})
|
||||
else()
|
||||
message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!")
|
||||
|
||||
@@ -28,7 +28,10 @@ THE SOFTWARE.
|
||||
#include <filesystem>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <rocdecode/rocdecode.h>
|
||||
#include <rocdecode/rocdecode_host.h>
|
||||
#include <rocdecode/rocparser.h>
|
||||
#if ENABLE_HOST_DECODE
|
||||
#include <rocdecode/rocdecode_host.h>
|
||||
#endif
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -364,6 +367,7 @@ void create_decoder(DecoderInfo& dec_info) {
|
||||
CHECK(rocDecCreateDecoder(&dec_info.decoder, &create_info));
|
||||
}
|
||||
|
||||
#if ENABLE_HOST_DECODE
|
||||
int ROCDECAPI handle_video_sequence_host(void* user_data, RocdecVideoFormatHost* format_host) {
|
||||
DecoderInfo *p_dec_info = static_cast<DecoderInfo *>(user_data);
|
||||
RocdecVideoFormat *format = &format_host->video_format;
|
||||
@@ -451,6 +455,7 @@ void create_decoder_host(DecoderInfo& dec_info) {
|
||||
CHECK(rocDecCreateDecoderHost(&dec_info.decoder, &create_info));
|
||||
dec_info.backend = DECODER_BACKEND_HOST;
|
||||
}
|
||||
#endif
|
||||
|
||||
int ROCDECAPI handle_video_sequence(void* user_data, RocdecVideoFormat* format) {
|
||||
DecoderInfo *p_dec_info = static_cast<DecoderInfo *>(user_data);
|
||||
@@ -551,7 +556,9 @@ void decode_frames(DecoderInfo& dec_info, const std::vector<std::vector<uint8_t>
|
||||
}
|
||||
CHECK(rocDecParseVideoData(dec_info.parser, &packet));
|
||||
}
|
||||
} else if (dec_info.backend == DECODER_BACKEND_HOST) {
|
||||
}
|
||||
#if ENABLE_HOST_DECODE
|
||||
else if (dec_info.backend == DECODER_BACKEND_HOST) {
|
||||
for (int i=0; i < static_cast<int>(frames.size()); ++i) {
|
||||
RocdecPicParamsHost pic_params = {};
|
||||
pic_params.bitstream_data_len = frames[i].size();
|
||||
@@ -562,14 +569,18 @@ void decode_frames(DecoderInfo& dec_info, const std::vector<std::vector<uint8_t>
|
||||
CHECK(rocDecDecodeFrameHost(dec_info.decoder, &pic_params));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void destroy_decoder(DecoderInfo& dec_info) {
|
||||
if (dec_info.backend == DECODER_BACKEND_DEVICE)
|
||||
if (dec_info.backend == DECODER_BACKEND_DEVICE) {
|
||||
CHECK(rocDecDestroyDecoder(dec_info.decoder));
|
||||
}
|
||||
#if ENABLE_HOST_DECODE
|
||||
else if (dec_info.backend == DECODER_BACKEND_HOST) {
|
||||
CHECK(rocDecDestroyDecoderHost(dec_info.decoder));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void destroy_parser(DecoderInfo& dec_info) {
|
||||
@@ -582,7 +593,11 @@ void ShowHelpAndExit(const char *option = NULL) {
|
||||
<< "-i Input File Path - required" << std::endl
|
||||
<< "-o Output File Path - dumps output if requested; optional" << std::endl
|
||||
<< "-d GPU device ID (0 for the first device, 1 for the second, etc.); optional; default: 0" << std::endl
|
||||
#if ENABLE_HOST_DECODE
|
||||
<< "-b backend (0 for GPU, 1 CPU-FFMpeg); optional; default: 0" << std::endl
|
||||
#else
|
||||
<< "-b backend (0 for GPU); optional; default: 0" << std::endl
|
||||
#endif
|
||||
<< "-c codec (0 : HEVC, 1 : H264, 2: AV1, 4: VP9, 5: VP8 ); optional; default: 0" << std::endl
|
||||
<< "-n Number of iteration - specify the number of iterations for performance evaluation; optional; default: 1" << std::endl
|
||||
<< "-m output_surface_memory_type - decoded surface memory; optional; default - 0"
|
||||
@@ -725,9 +740,12 @@ int main(int argc, char** argv) {
|
||||
if (backend == DECODER_BACKEND_DEVICE) {
|
||||
create_parser(dec_info);
|
||||
create_decoder(dec_info);
|
||||
} else {
|
||||
}
|
||||
#if ENABLE_HOST_DECODE
|
||||
else {
|
||||
create_decoder_host(dec_info);
|
||||
}
|
||||
#endif
|
||||
dec_info.dump_decoded_frames = dump_output_frames;
|
||||
auto input_frames = read_frames(input_file_names);
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
Reference in New Issue
Block a user