From 583e72720a8f41dbfb76e0a7494bc6858dc5cbf6 Mon Sep 17 00:00:00 2001 From: jeffqjiangNew <142832361+jeffqjiangNew@users.noreply.github.com> Date: Tue, 5 Dec 2023 11:40:39 -0500 Subject: [PATCH] Added the command option "-md5_check" to compare the MD5 of the decoded YUV to the reference MD5. This facilitates decoder conformance test automation. (#117) * * rocDecode: Added a command option "-md5_check" to compare the MD5 of the decoded YUV to the reference MD5. This ficilitates decoder conformance test automation. * * rocDecode/HEVC: Changed file and string operation from C code to C++ code. * * rocDecode/HEVC: Updated README.md for videoDecode sample. --- samples/videoDecode/README.md | 2 ++ samples/videoDecode/videodecode.cpp | 44 ++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/samples/videoDecode/README.md b/samples/videoDecode/README.md index 5b11c85c9f..98a553ce06 100644 --- a/samples/videoDecode/README.md +++ b/samples/videoDecode/README.md @@ -33,6 +33,8 @@ make -j -d -z -sei + -md5 + -md5_check MD5_File_Path -crop -m ``` \ No newline at end of file diff --git a/samples/videoDecode/videodecode.cpp b/samples/videoDecode/videodecode.cpp index a0fd6ce23d..65fae40398 100644 --- a/samples/videoDecode/videodecode.cpp +++ b/samples/videoDecode/videodecode.cpp @@ -21,6 +21,9 @@ THE SOFTWARE. */ #include +#include +#include +#include #include #include #include @@ -44,6 +47,7 @@ void ShowHelpAndExit(const char *option = NULL) { << "-z force_zero_latency (force_zero_latency, Decoded frames will be flushed out for display immediately); optional;" << std::endl << "-sei extract SEI messages; optional;" << std::endl << "-md5 generate MD5 message digest on the decoded YUV image sequence; optional;" << std::endl + << "-md5_check MD5 File Path - generate MD5 message digest on the decoded YUV image sequence and compare to the reference MD5 string in a file; optional;" << std::endl << "-crop crop rectangle for output (not used when using interopped decoded frame); optional; default: 0" << std::endl << "-m output_surface_memory_type - decoded surface memory; optional; default - 0" << " [0 : OUT_SURFACE_MEM_DEV_INTERNAL/ 1 : OUT_SURFACE_MEM_DEV_COPIED/ 2 : OUT_SURFACE_MEM_HOST_COPIED]" << std::endl; @@ -52,12 +56,14 @@ void ShowHelpAndExit(const char *option = NULL) { int main(int argc, char **argv) { - std::string input_file_path, output_file_path; + std::string input_file_path, output_file_path, md5_file_path; + std::fstream ref_md5_file; int dump_output_frames = 0; int device_id = 0; bool b_force_zero_latency = false; // false by default: enabling this option might affect decoding performance bool b_extract_sei_messages = false; bool b_generate_md5 = false; + bool b_md5_check = false; Rect crop_rect = {}; Rect *p_crop_rect = nullptr; OutputSurfaceMemoryType mem_type = OUT_SURFACE_MEM_DEV_INTERNAL; // set to internal @@ -112,6 +118,15 @@ int main(int argc, char **argv) { b_generate_md5 = true; continue; } + if (!strcmp(argv[i], "-md5_check")) { + if (++i == argc) { + ShowHelpAndExit("-md5_check"); + } + b_generate_md5 = true; + b_md5_check = true; + md5_file_path = argv[i]; + continue; + } if (!strcmp(argv[i], "-crop")) { if (++i == argc || 4 != sscanf(argv[i], "%d,%d,%d,%d", &crop_rect.l, &crop_rect.t, &crop_rect.r, &crop_rect.b)) { ShowHelpAndExit("-crop"); @@ -160,6 +175,9 @@ int main(int argc, char **argv) { if (b_generate_md5) { viddec.InitMd5(); } + if (b_md5_check) { + ref_md5_file.open(md5_file_path.c_str(), std::ios::in); + } do { auto start_time = std::chrono::high_resolution_clock::now(); @@ -203,6 +221,30 @@ int main(int argc, char **argv) { std::cout << std::hex << static_cast(digest[i]); } std::cout << std::endl; + + if (b_md5_check) { + char ref_md5_string[33], c2[2]; + uint8_t ref_md5[16]; + std::string str; + + for (int i = 0; i < 16; i++) { + int c; + ref_md5_file.get(c2[0]); + ref_md5_file.get(c2[1]); + str = c2; + c = std::stoi(str, nullptr, 16); + ref_md5[i] = c; + } + if (memcmp(digest, ref_md5, 16) == 0) { + std::cout << "MD5 digest matches the reference MD5 digest: "; + } else { + std::cout << "MD5 digest does not matche the reference MD5 digest: "; + } + ref_md5_file.seekg(0, std::ios_base::beg); + ref_md5_file.getline(ref_md5_string, 33); + std::cout << ref_md5_string << std::endl; + ref_md5_file.close(); + } } } catch (const std::exception &ex) { std::cout << ex.what() << std::endl;