From 8b86f61514a2c181ed2b8633a61d6a72f426b107 Mon Sep 17 00:00:00 2001 From: Jeff Jiang <142832361+jeffqjiangNew@users.noreply.github.com> Date: Tue, 4 Nov 2025 21:12:56 -0500 Subject: [PATCH] * rocDecode: Added several fixes to samples. (#668) - Fixed the build error with videodecodepicfiles sample. - Added error handling of sample app command option combination of memory type OUT_SURFACE_MEM_NOT_MAPPED and MD5 generation. [ROCm/rocdecode commit: c388518965171daccf760a15857603203c6a2794] --- projects/rocdecode/CHANGELOG.md | 5 +++++ .../rocdecode/samples/videoDecode/videodecode.cpp | 2 +- .../samples/videoDecodeMem/videodecodemem.cpp | 2 +- .../samples/videoDecodePicFiles/CMakeLists.txt | 11 ++++++++++- .../videoDecodePicFiles/videodecodepicfiles.cpp | 2 +- projects/rocdecode/utils/md5.h | 5 +++++ .../rocdecode/utils/rocvideodecode/roc_video_dec.cpp | 6 +++++- 7 files changed, 28 insertions(+), 5 deletions(-) diff --git a/projects/rocdecode/CHANGELOG.md b/projects/rocdecode/CHANGELOG.md index 620de6fb96..02a9da8068 100644 --- a/projects/rocdecode/CHANGELOG.md +++ b/projects/rocdecode/CHANGELOG.md @@ -10,6 +10,11 @@ Full documentation for rocDecode is available at [https://rocm.docs.amd.com/proj ### Added * Logging control. Message output from the core components is now controlled by the logging level threshold, which can be set by an environment variable or other methods. +### Resolved issues + +* Fixed the build error with videodecodepicfiles sample. +* Added error handling of sample app command option combination of memory type OUT_SURFACE_MEM_NOT_MAPPED and MD5 generation. + ## rocDecode 1.4.0 for ROCm 7.1.0 ### Added diff --git a/projects/rocdecode/samples/videoDecode/videodecode.cpp b/projects/rocdecode/samples/videoDecode/videodecode.cpp index dc3277219a..9cfff7f7fe 100644 --- a/projects/rocdecode/samples/videoDecode/videodecode.cpp +++ b/projects/rocdecode/samples/videoDecode/videodecode.cpp @@ -364,7 +364,7 @@ int main(int argc, char **argv) { } for (int i = 0; i < n_frame_returned; i++) { pframe = viddec->GetFrame(&pts); - if (b_generate_md5) { + if (b_generate_md5 && pframe) { md5_generator->UpdateMd5ForFrame(pframe, surf_info); } if (dump_output_frames && mem_type != OUT_SURFACE_MEM_NOT_MAPPED) { diff --git a/projects/rocdecode/samples/videoDecodeMem/videodecodemem.cpp b/projects/rocdecode/samples/videoDecodeMem/videodecodemem.cpp index 9145a508ce..fd10784e65 100644 --- a/projects/rocdecode/samples/videoDecodeMem/videodecodemem.cpp +++ b/projects/rocdecode/samples/videoDecodeMem/videodecodemem.cpp @@ -235,7 +235,7 @@ int main(int argc, char **argv) { } for (int i = 0; i < n_frame_returned; i++) { pframe = viddec.GetFrame(&pts); - if (b_generate_md5) { + if (b_generate_md5 && pframe) { md5_generator->UpdateMd5ForFrame(pframe, surf_info); } if (dump_output_frames && mem_type != OUT_SURFACE_MEM_NOT_MAPPED) { diff --git a/projects/rocdecode/samples/videoDecodePicFiles/CMakeLists.txt b/projects/rocdecode/samples/videoDecodePicFiles/CMakeLists.txt index 508408115a..b8d4987281 100644 --- a/projects/rocdecode/samples/videoDecodePicFiles/CMakeLists.txt +++ b/projects/rocdecode/samples/videoDecodePicFiles/CMakeLists.txt @@ -63,6 +63,7 @@ endif() find_package(HIP QUIET) find_package(rocdecode QUIET) +find_package(rocdecode-host 1.0.0 QUIET) find_package(rocprofiler-register QUIET) find_package(FFmpeg QUIET) find_package(Threads REQUIRED) @@ -85,13 +86,21 @@ if(HIP_FOUND AND FFMPEG_FOUND AND rocdecode_FOUND AND Threads_FOUND AND rocprofi # sample app exe list(APPEND SOURCES ${PROJECT_SOURCE_DIR} videodecodepicfiles.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/rocvideodecode/roc_video_dec.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../utils/ffmpegvideodecode/ffmpeg_video_dec.cpp) add_executable(${PROJECT_NAME} ${SOURCES}) - target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) + if(rocdecode-host_FOUND) + # rocdecode-host + include_directories(${rocdecode-host_INCLUDE_DIR}) + set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} rocdecode::rocdecode-host) + target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_HOST_DECODE=1) + else() + target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_HOST_DECODE=0) + endif() # FFMPEG multi-version support if(_FFMPEG_AVCODEC_VERSION VERSION_LESS_EQUAL 58.134.100) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=0) else() target_compile_definitions(${PROJECT_NAME} PUBLIC USE_AVCODEC_GREATER_THAN_58_134=1) endif() + target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARY_LIST}) else() message("-- ERROR!: ${PROJECT_NAME} excluded! please install all the dependencies and try again!") if (NOT HIP_FOUND) diff --git a/projects/rocdecode/samples/videoDecodePicFiles/videodecodepicfiles.cpp b/projects/rocdecode/samples/videoDecodePicFiles/videodecodepicfiles.cpp index 09efbe0934..53db80c91c 100644 --- a/projects/rocdecode/samples/videoDecodePicFiles/videodecodepicfiles.cpp +++ b/projects/rocdecode/samples/videoDecodePicFiles/videodecodepicfiles.cpp @@ -316,7 +316,7 @@ int main(int argc, char **argv) { } for (int i = 0; i < n_frame_returned; i++) { pframe = viddec->GetFrame(&pts); - if (b_generate_md5) { + if (b_generate_md5 && pframe) { md5_generator->UpdateMd5ForFrame(pframe, surf_info); } if (dump_output_frames && mem_type != OUT_SURFACE_MEM_NOT_MAPPED) { diff --git a/projects/rocdecode/utils/md5.h b/projects/rocdecode/utils/md5.h index 0be8a43d40..86e8a712c8 100644 --- a/projects/rocdecode/utils/md5.h +++ b/projects/rocdecode/utils/md5.h @@ -87,6 +87,11 @@ public: } else hst_ptr = static_cast (surf_mem); + if (hst_ptr == nullptr) { + ROCDEC_ERR("Null surface pointer."); + return; + } + // Need to covert interleaved planar to stacked planar, assuming 4:2:0 chroma sampling. uint8_t *stacked_ptr = new uint8_t [output_image_size]; uint8_t *tmp_hst_ptr = hst_ptr; diff --git a/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp b/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp index 0c4ffc39e5..03f739c860 100644 --- a/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp +++ b/projects/rocdecode/utils/rocvideodecode/roc_video_dec.cpp @@ -956,7 +956,11 @@ void RocVideoDecoder::SaveFrameToFile(std::string output_file_name, void *surf_m } else hst_ptr = static_cast (surf_mem); - + if (hst_ptr == nullptr) { + ROCDEC_ERR("Null surface pointer."); + return; + } + if (current_output_filename.empty()) { current_output_filename = output_file_name; }