xref: /aosp_15_r20/external/deqp/external/vulkancts/data/vulkan/video/frame_checksums.py (revision 35238bce31c2a825756842865a792f8cf7f89930)
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4#
5# Copyright (C) 2023 The Khronos Group Inc
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11#      http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19#-------------------------------------------------------------------------
20#
21# Generate checksums from a sequence of YV12 YUV frames as produced by
22# the Fraunhofer reference decoders.
23#
24#  The reference checksums were generated using the Fluster testing
25#  framework ([email protected]:fluendo/fluster.git @
26#  fd2a3aec596ba5437b4c3364111938531a4b5f92) to build the Fraunhofer
27#  reference decoders,
28#
29#  ~/src/fluster $ make h26[45]_reference_decoder
30#
31#  Then, to generate references for H.264 test content,
32#
33#  $ cd ~/src/vk-gl-cts/external/vulkancts/data/vulkan/video/
34#  $ ~/src/fluster/contrib/JM/bin/umake/gcc-12.2/x86_64/release/ldecod -s -i clip-a.h264 -o clip-a.out
35#  $ python frame_checksums.py  clip-a.out  176 144 ; rm clip-a.out
36#
37#  To generate the H.265 YUV files, change the reference decoder line above to,
38#
39#  $ ~/src/fluster/contrib/HM/bin/umake/gcc-12.2/x86_64/release/TAppDecoder -b jellyfish-250-mbps-4k-uhd-GOB-IPB13.h265 -o jellyfish265.out
40#
41#  The h264_resolution_change example was specially handled, since
42#  it's actually a non-conformant bitstream according to the reference
43#  decoders. There are two streams of different resolution
44#  concatenated together in the test vector. They were manually cut
45#  out and each independent stream was passed through the above
46#  process to generate the checksums.
47#
48
49import os
50import sys
51import hashlib
52
53if len(sys.argv) != 4:
54    print("Usage: yuv2rgb-cv.py yuvFile width height")
55    sys.exit(1)
56
57yuv_filename = sys.argv[1]
58width = int(sys.argv[2])
59height = int(sys.argv[3])
60
61def checksum(bs: bytes) -> str:
62    md5 = hashlib.md5()
63    md5.update(bs)
64    return md5.hexdigest()
65
66file_size = os.path.getsize(yuv_filename)
67
68# This assumes the YCrCb format is YV12, as produced by the Fraunhofer
69# reference decoders.
70frame_size = int(width * height * 1.5)
71n_frames = file_size // frame_size
72
73with open(yuv_filename, 'rb') as f:
74    print("Computing checksums for ", n_frames, " frames")
75    for frame in range(n_frames):
76        print(checksum(f.read(frame_size)))
77