edid-decode: rework the -n option
[edid-decode.git] / parse-cta-block.cpp
blob7b3f0c33fbd65040b06bca09bd87f2a79aff169b
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2006-2012 Red Hat, Inc.
4 * Copyright 2018-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 * Author: Adam Jackson <ajax@nwnk.net>
7 * Maintainer: Hans Verkuil <hverkuil-cisco@xs4all.nl>
8 */
10 #include <algorithm>
11 #include <stdio.h>
12 #include <math.h>
14 #include "edid-decode.h"
16 static const struct timings edid_cta_modes1[] = {
17 /* VIC 1 */
18 { 640, 480, 4, 3, 25175, 0, false, 16, 96, 48, false, 10, 2, 33, false },
19 { 720, 480, 4, 3, 27000, 0, false, 16, 62, 60, false, 9, 6, 30, false },
20 { 720, 480, 16, 9, 27000, 0, false, 16, 62, 60, false, 9, 6, 30, false },
21 { 1280, 720, 16, 9, 74250, 0, false, 110, 40, 220, true, 5, 5, 20, true },
22 { 1920, 1080, 16, 9, 74250, 0, true, 88, 44, 148, true, 2, 5, 15, true },
23 { 1440, 480, 4, 3, 27000, 0, true, 38, 124, 114, false, 4, 3, 15, false },
24 { 1440, 480, 16, 9, 27000, 0, true, 38, 124, 114, false, 4, 3, 15, false },
25 { 1440, 240, 4, 3, 27000, 0, false, 38, 124, 114, false, 4, 3, 15, false },
26 { 1440, 240, 16, 9, 27000, 0, false, 38, 124, 114, false, 4, 3, 15, false },
27 { 2880, 480, 4, 3, 54000, 0, true, 76, 248, 228, false, 4, 3, 15, false },
28 /* VIC 11 */
29 { 2880, 480, 16, 9, 54000, 0, true, 76, 248, 228, false, 4, 3, 15, false },
30 { 2880, 240, 4, 3, 54000, 0, false, 76, 248, 228, false, 4, 3, 15, false },
31 { 2880, 240, 16, 9, 54000, 0, false, 76, 248, 228, false, 4, 3, 15, false },
32 { 1440, 480, 4, 3, 54000, 0, false, 32, 124, 120, false, 9, 6, 30, false },
33 { 1440, 480, 16, 9, 54000, 0, false, 32, 124, 120, false, 9, 6, 30, false },
34 { 1920, 1080, 16, 9, 148500, 0, false, 88, 44, 148, true, 4, 5, 36, true },
35 { 720, 576, 4, 3, 27000, 0, false, 12, 64, 68, false, 5, 5, 39, false },
36 { 720, 576, 16, 9, 27000, 0, false, 12, 64, 68, false, 5, 5, 39, false },
37 { 1280, 720, 16, 9, 74250, 0, false, 440, 40, 220, true, 5, 5, 20, true },
38 { 1920, 1080, 16, 9, 74250, 0, true, 528, 44, 148, true, 2, 5, 15, true },
39 /* VIC 21 */
40 { 1440, 576, 4, 3, 27000, 0, true, 24, 126, 138, false, 2, 3, 19, false },
41 { 1440, 576, 16, 9, 27000, 0, true, 24, 126, 138, false, 2, 3, 19, false },
42 { 1440, 288, 4, 3, 27000, 0, false, 24, 126, 138, false, 2, 3, 19, false },
43 { 1440, 288, 16, 9, 27000, 0, false, 24, 126, 138, false, 2, 3, 19, false },
44 { 2880, 576, 4, 3, 54000, 0, true, 48, 252, 276, false, 2, 3, 19, false },
45 { 2880, 576, 16, 9, 54000, 0, true, 48, 252, 276, false, 2, 3, 19, false },
46 { 2880, 288, 4, 3, 54000, 0, false, 48, 252, 276, false, 2, 3, 19, false },
47 { 2880, 288, 16, 9, 54000, 0, false, 48, 252, 276, false, 2, 3, 19, false },
48 { 1440, 576, 4, 3, 54000, 0, false, 24, 128, 136, false, 5, 5, 39, false },
49 { 1440, 576, 16, 9, 54000, 0, false, 24, 128, 136, false, 5, 5, 39, false },
50 /* VIC 31 */
51 { 1920, 1080, 16, 9, 148500, 0, false, 528, 44, 148, true, 4, 5, 36, true },
52 { 1920, 1080, 16, 9, 74250, 0, false, 638, 44, 148, true, 4, 5, 36, true },
53 { 1920, 1080, 16, 9, 74250, 0, false, 528, 44, 148, true, 4, 5, 36, true },
54 { 1920, 1080, 16, 9, 74250, 0, false, 88, 44, 148, true, 4, 5, 36, true },
55 { 2880, 480, 4, 3, 108000, 0, false, 64, 248, 240, false, 9, 6, 30, false },
56 { 2880, 480, 16, 9, 108000, 0, false, 64, 248, 240, false, 9, 6, 30, false },
57 { 2880, 576, 4, 3, 108000, 0, false, 48, 256, 272, false, 5, 5, 39, false },
58 { 2880, 576, 16, 9, 108000, 0, false, 48, 256, 272, false, 5, 5, 39, false },
59 { 1920, 1080, 16, 9, 72000, 0, true, 32, 168, 184, true, 23, 5, 57, false, 0, 0, true },
60 { 1920, 1080, 16, 9, 148500, 0, true, 528, 44, 148, true, 2, 5, 15, true },
61 /* VIC 41 */
62 { 1280, 720, 16, 9, 148500, 0, false, 440, 40, 220, true, 5, 5, 20, true },
63 { 720, 576, 4, 3, 54000, 0, false, 12, 64, 68, false, 5, 5, 39, false },
64 { 720, 576, 16, 9, 54000, 0, false, 12, 64, 68, false, 5, 5, 39, false },
65 { 1440, 576, 4, 3, 54000, 0, true, 24, 126, 138, false, 2, 3, 19, false },
66 { 1440, 576, 16, 9, 54000, 0, true, 24, 126, 138, false, 2, 3, 19, false },
67 { 1920, 1080, 16, 9, 148500, 0, true, 88, 44, 148, true, 2, 5, 15, true },
68 { 1280, 720, 16, 9, 148500, 0, false, 110, 40, 220, true, 5, 5, 20, true },
69 { 720, 480, 4, 3, 54000, 0, false, 16, 62, 60, false, 9, 6, 30, false },
70 { 720, 480, 16, 9, 54000, 0, false, 16, 62, 60, false, 9, 6, 30, false },
71 { 1440, 480, 4, 3, 54000, 0, true, 38, 124, 114, false, 4, 3, 15, false },
72 /* VIC 51 */
73 { 1440, 480, 16, 9, 54000, 0, true, 38, 124, 114, false, 4, 3, 15, false },
74 { 720, 576, 4, 3, 108000, 0, false, 12, 64, 68, false, 5, 5, 39, false },
75 { 720, 576, 16, 9, 108000, 0, false, 12, 64, 68, false, 5, 5, 39, false },
76 { 1440, 576, 4, 3, 108000, 0, true, 24, 126, 138, false, 2, 3, 19, false },
77 { 1440, 576, 16, 9, 108000, 0, true, 24, 126, 138, false, 2, 3, 19, false },
78 { 720, 480, 4, 3, 108000, 0, false, 16, 62, 60, false, 9, 6, 30, false },
79 { 720, 480, 16, 9, 108000, 0, false, 16, 62, 60, false, 9, 6, 30, false },
80 { 1440, 480, 4, 3, 108000, 0, true, 38, 124, 114, false, 4, 3, 15, false },
81 { 1440, 480, 16, 9, 108000, 0, true, 38, 124, 114, false, 4, 3, 15, false },
82 { 1280, 720, 16, 9, 59400, 0, false, 1760, 40, 220, true, 5, 5, 20, true },
83 /* VIC 61 */
84 { 1280, 720, 16, 9, 74250, 0, false, 2420, 40, 220, true, 5, 5, 20, true },
85 { 1280, 720, 16, 9, 74250, 0, false, 1760, 40, 220, true, 5, 5, 20, true },
86 { 1920, 1080, 16, 9, 297000, 0, false, 88, 44, 148, true, 4, 5, 36, true },
87 { 1920, 1080, 16, 9, 297000, 0, false, 528, 44, 148, true, 4, 5, 36, true },
88 { 1280, 720, 64, 27, 59400, 0, false, 1760, 40, 220, true, 5, 5, 20, true },
89 { 1280, 720, 64, 27, 74250, 0, false, 2420, 40, 220, true, 5, 5, 20, true },
90 { 1280, 720, 64, 27, 74250, 0, false, 1760, 40, 220, true, 5, 5, 20, true },
91 { 1280, 720, 64, 27, 74250, 0, false, 440, 40, 220, true, 5, 5, 20, true },
92 { 1280, 720, 64, 27, 74250, 0, false, 110, 40, 220, true, 5, 5, 20, true },
93 { 1280, 720, 64, 27, 148500, 0, false, 440, 40, 220, true, 5, 5, 20, true },
94 /* VIC 71 */
95 { 1280, 720, 64, 27, 148500, 0, false, 110, 40, 220, true, 5, 5, 20, true },
96 { 1920, 1080, 64, 27, 74250, 0, false, 638, 44, 148, true, 4, 5, 36, true },
97 { 1920, 1080, 64, 27, 74250, 0, false, 528, 44, 148, true, 4, 5, 36, true },
98 { 1920, 1080, 64, 27, 74250, 0, false, 88, 44, 148, true, 4, 5, 36, true },
99 { 1920, 1080, 64, 27, 148500, 0, false, 528, 44, 148, true, 4, 5, 36, true },
100 { 1920, 1080, 64, 27, 148500, 0, false, 88, 44, 148, true, 4, 5, 36, true },
101 { 1920, 1080, 64, 27, 297000, 0, false, 528, 44, 148, true, 4, 5, 36, true },
102 { 1920, 1080, 64, 27, 297000, 0, false, 88, 44, 148, true, 4, 5, 36, true },
103 { 1680, 720, 64, 27, 59400, 0, false, 1360, 40, 220, true, 5, 5, 20, true },
104 { 1680, 720, 64, 27, 59400, 0, false, 1228, 40, 220, true, 5, 5, 20, true },
105 /* VIC 81 */
106 { 1680, 720, 64, 27, 59400, 0, false, 700, 40, 220, true, 5, 5, 20, true },
107 { 1680, 720, 64, 27, 82500, 0, false, 260, 40, 220, true, 5, 5, 20, true },
108 { 1680, 720, 64, 27, 99000, 0, false, 260, 40, 220, true, 5, 5, 20, true },
109 { 1680, 720, 64, 27, 165000, 0, false, 60, 40, 220, true, 5, 5, 95, true },
110 { 1680, 720, 64, 27, 198000, 0, false, 60, 40, 220, true, 5, 5, 95, true },
111 { 2560, 1080, 64, 27, 99000, 0, false, 998, 44, 148, true, 4, 5, 11, true },
112 { 2560, 1080, 64, 27, 90000, 0, false, 448, 44, 148, true, 4, 5, 36, true },
113 { 2560, 1080, 64, 27, 118800, 0, false, 768, 44, 148, true, 4, 5, 36, true },
114 { 2560, 1080, 64, 27, 185625, 0, false, 548, 44, 148, true, 4, 5, 36, true },
115 { 2560, 1080, 64, 27, 198000, 0, false, 248, 44, 148, true, 4, 5, 11, true },
116 /* VIC 91 */
117 { 2560, 1080, 64, 27, 371250, 0, false, 218, 44, 148, true, 4, 5, 161, true },
118 { 2560, 1080, 64, 27, 495000, 0, false, 548, 44, 148, true, 4, 5, 161, true },
119 { 3840, 2160, 16, 9, 297000, 0, false, 1276, 88, 296, true, 8, 10, 72, true },
120 { 3840, 2160, 16, 9, 297000, 0, false, 1056, 88, 296, true, 8, 10, 72, true },
121 { 3840, 2160, 16, 9, 297000, 0, false, 176, 88, 296, true, 8, 10, 72, true },
122 { 3840, 2160, 16, 9, 594000, 0, false, 1056, 88, 296, true, 8, 10, 72, true },
123 { 3840, 2160, 16, 9, 594000, 0, false, 176, 88, 296, true, 8, 10, 72, true },
124 { 4096, 2160, 256, 135, 297000, 0, false, 1020, 88, 296, true, 8, 10, 72, true },
125 { 4096, 2160, 256, 135, 297000, 0, false, 968, 88, 128, true, 8, 10, 72, true },
126 { 4096, 2160, 256, 135, 297000, 0, false, 88, 88, 128, true, 8, 10, 72, true },
127 /* VIC 101 */
128 { 4096, 2160, 256, 135, 594000, 0, false, 968, 88, 128, true, 8, 10, 72, true },
129 { 4096, 2160, 256, 135, 594000, 0, false, 88, 88, 128, true, 8, 10, 72, true },
130 { 3840, 2160, 64, 27, 297000, 0, false, 1276, 88, 296, true, 8, 10, 72, true },
131 { 3840, 2160, 64, 27, 297000, 0, false, 1056, 88, 296, true, 8, 10, 72, true },
132 { 3840, 2160, 64, 27, 297000, 0, false, 176, 88, 296, true, 8, 10, 72, true },
133 { 3840, 2160, 64, 27, 594000, 0, false, 1056, 88, 296, true, 8, 10, 72, true },
134 { 3840, 2160, 64, 27, 594000, 0, false, 176, 88, 296, true, 8, 10, 72, true },
135 { 1280, 720, 16, 9, 90000, 0, false, 960, 40, 220, true, 5, 5, 20, true },
136 { 1280, 720, 64, 27, 90000, 0, false, 960, 40, 220, true, 5, 5, 20, true },
137 { 1680, 720, 64, 27, 99000, 0, false, 810, 40, 220, true, 5, 5, 20, true },
138 /* VIC 111 */
139 { 1920, 1080, 16, 9, 148500, 0, false, 638, 44, 148, true, 4, 5, 36, true },
140 { 1920, 1080, 64, 27, 148500, 0, false, 638, 44, 148, true, 4, 5, 36, true },
141 { 2560, 1080, 64, 27, 198000, 0, false, 998, 44, 148, true, 4, 5, 11, true },
142 { 3840, 2160, 16, 9, 594000, 0, false, 1276, 88, 296, true, 8, 10, 72, true },
143 { 4096, 2160, 256, 135, 594000, 0, false, 1020, 88, 296, true, 8, 10, 72, true },
144 { 3840, 2160, 64, 27, 594000, 0, false, 1276, 88, 296, true, 8, 10, 72, true },
145 { 3840, 2160, 16, 9, 1188000, 0, false, 1056, 88, 296, true, 8, 10, 72, true },
146 { 3840, 2160, 16, 9, 1188000, 0, false, 176, 88, 296, true, 8, 10, 72, true },
147 { 3840, 2160, 64, 27, 1188000, 0, false, 1056, 88, 296, true, 8, 10, 72, true },
148 { 3840, 2160, 64, 27, 1188000, 0, false, 176, 88, 296, true, 8, 10, 72, true },
149 /* VIC 121 */
150 { 5120, 2160, 64, 27, 396000, 0, false, 1996, 88, 296, true, 8, 10, 22, true },
151 { 5120, 2160, 64, 27, 396000, 0, false, 1696, 88, 296, true, 8, 10, 22, true },
152 { 5120, 2160, 64, 27, 396000, 0, false, 664, 88, 128, true, 8, 10, 22, true },
153 { 5120, 2160, 64, 27, 742500, 0, false, 746, 88, 296, true, 8, 10, 297, true },
154 { 5120, 2160, 64, 27, 742500, 0, false, 1096, 88, 296, true, 8, 10, 72, true },
155 { 5120, 2160, 64, 27, 742500, 0, false, 164, 88, 128, true, 8, 10, 72, true },
156 { 5120, 2160, 64, 27, 1485000, 0, false, 1096, 88, 296, true, 8, 10, 72, true },
159 static const struct timings edid_cta_modes2[] = {
160 /* VIC 193 */
161 { 5120, 2160, 64, 27, 1485000, 0, false, 164, 88, 128, true, 8, 10, 72, true },
162 { 7680, 4320, 16, 9, 1188000, 0, false, 2552, 176, 592, true, 16, 20, 144, true },
163 { 7680, 4320, 16, 9, 1188000, 0, false, 2352, 176, 592, true, 16, 20, 44, true },
164 { 7680, 4320, 16, 9, 1188000, 0, false, 552, 176, 592, true, 16, 20, 44, true },
165 { 7680, 4320, 16, 9, 2376000, 0, false, 2552, 176, 592, true, 16, 20, 144, true },
166 { 7680, 4320, 16, 9, 2376000, 0, false, 2352, 176, 592, true, 16, 20, 44, true },
167 { 7680, 4320, 16, 9, 2376000, 0, false, 552, 176, 592, true, 16, 20, 44, true },
168 { 7680, 4320, 16, 9, 4752000, 0, false, 2112, 176, 592, true, 16, 20, 144, true },
169 /* VIC 201 */
170 { 7680, 4320, 16, 9, 4752000, 0, false, 352, 176, 592, true, 16, 20, 144, true },
171 { 7680, 4320, 64, 27, 1188000, 0, false, 2552, 176, 592, true, 16, 20, 144, true },
172 { 7680, 4320, 64, 27, 1188000, 0, false, 2352, 176, 592, true, 16, 20, 44, true },
173 { 7680, 4320, 64, 27, 1188000, 0, false, 552, 176, 592, true, 16, 20, 44, true },
174 { 7680, 4320, 64, 27, 2376000, 0, false, 2552, 176, 592, true, 16, 20, 144, true },
175 { 7680, 4320, 64, 27, 2376000, 0, false, 2352, 176, 592, true, 16, 20, 44, true },
176 { 7680, 4320, 64, 27, 2376000, 0, false, 552, 176, 592, true, 16, 20, 44, true },
177 { 7680, 4320, 64, 27, 4752000, 0, false, 2112, 176, 592, true, 16, 20, 144, true },
178 { 7680, 4320, 64, 27, 4752000, 0, false, 352, 176, 592, true, 16, 20, 144, true },
179 { 10240, 4320, 64, 27, 1485000, 0, false, 1492, 176, 592, true, 16, 20, 594, true },
180 /* VIC 211 */
181 { 10240, 4320, 64, 27, 1485000, 0, false, 2492, 176, 592, true, 16, 20, 44, true },
182 { 10240, 4320, 64, 27, 1485000, 0, false, 288, 176, 296, true, 16, 20, 144, true },
183 { 10240, 4320, 64, 27, 2970000, 0, false, 1492, 176, 592, true, 16, 20, 594, true },
184 { 10240, 4320, 64, 27, 2970000, 0, false, 2492, 176, 592, true, 16, 20, 44, true },
185 { 10240, 4320, 64, 27, 2970000, 0, false, 288, 176, 296, true, 16, 20, 144, true },
186 { 10240, 4320, 64, 27, 5940000, 0, false, 2192, 176, 592, true, 16, 20, 144, true },
187 { 10240, 4320, 64, 27, 5940000, 0, false, 288, 176, 296, true, 16, 20, 144, true },
188 { 4096, 2160, 256, 135, 1188000, 0, false, 800, 88, 296, true, 8, 10, 72, true },
189 { 4096, 2160, 256, 135, 1188000, 0, false, 88, 88, 128, true, 8, 10, 72, true },
192 static const unsigned char edid_hdmi_mode_map[] = { 95, 94, 93, 98 };
194 unsigned char hdmi_vic_to_vic(unsigned char hdmi_vic)
196 if (hdmi_vic > 0 && hdmi_vic <= ARRAY_SIZE(edid_hdmi_mode_map))
197 return edid_hdmi_mode_map[hdmi_vic - 1];
198 return 0;
201 const struct timings *find_vic_id(unsigned char vic)
203 if (vic > 0 && vic <= ARRAY_SIZE(edid_cta_modes1))
204 return edid_cta_modes1 + vic - 1;
205 if (vic >= 193 && vic < ARRAY_SIZE(edid_cta_modes2) + 193)
206 return edid_cta_modes2 + vic - 193;
207 return NULL;
210 const struct timings *find_hdmi_vic_id(unsigned char hdmi_vic)
212 if (hdmi_vic > 0 && hdmi_vic <= ARRAY_SIZE(edid_hdmi_mode_map))
213 return find_vic_id(edid_hdmi_mode_map[hdmi_vic - 1]);
214 return NULL;
217 const struct timings *cta_close_match_to_vic(const timings &t, unsigned &vic)
219 for (vic = 1; vic <= ARRAY_SIZE(edid_cta_modes1); vic++) {
220 if (timings_close_match(t, edid_cta_modes1[vic - 1]))
221 return &edid_cta_modes1[vic - 1];
223 for (vic = 193; vic < ARRAY_SIZE(edid_cta_modes2) + 193; vic++) {
224 if (timings_close_match(t, edid_cta_modes1[vic - 193]))
225 return &edid_cta_modes1[vic - 193];
227 vic = 0;
228 return NULL;
231 void edid_state::cta_list_vics()
233 char type[16];
234 for (unsigned vic = 1; vic <= ARRAY_SIZE(edid_cta_modes1); vic++) {
235 sprintf(type, "VIC %3u", vic);
236 print_timings("", &edid_cta_modes1[vic - 1], type, "", false, false);
238 for (unsigned vic = 193; vic < ARRAY_SIZE(edid_cta_modes2) + 193; vic++) {
239 sprintf(type, "VIC %3u", vic);
240 print_timings("", &edid_cta_modes2[vic - 193], type, "", false, false);
244 void edid_state::cta_list_hdmi_vics()
246 for (unsigned i = 0; i < ARRAY_SIZE(edid_hdmi_mode_map); i++) {
247 unsigned vic = edid_hdmi_mode_map[i];
248 char type[16];
250 sprintf(type, "HDMI VIC %u", i + 1);
251 print_timings("", find_vic_id(vic), type, "", false, false);
255 static std::string audio_ext_format(unsigned char x)
257 if (x >= 1 && x <= 3)
258 fail("Obsolete Audio Ext Format 0x%02x.\n", x);
259 switch (x) {
260 case 1: return "HE AAC (Obsolete)";
261 case 2: return "HE AAC v2 (Obsolete)";
262 case 3: return "MPEG Surround (Obsolete)";
263 case 4: return "MPEG-4 HE AAC";
264 case 5: return "MPEG-4 HE AAC v2";
265 case 6: return "MPEG-4 AAC LC";
266 case 7: return "DRA";
267 case 8: return "MPEG-4 HE AAC + MPEG Surround";
268 case 10: return "MPEG-4 AAC LC + MPEG Surround";
269 case 11: return "MPEG-H 3D Audio";
270 case 12: return "AC-4";
271 case 13: return "L-PCM 3D Audio";
272 default: break;
274 fail("Unknown Audio Ext Format 0x%02x.\n", x);
275 return std::string("Unknown Audio Ext Format (") + utohex(x) + ")";
278 static std::string audio_format(unsigned char x)
280 switch (x) {
281 case 1: return "Linear PCM";
282 case 2: return "AC-3";
283 case 3: return "MPEG 1 (Layers 1 & 2)";
284 case 4: return "MPEG 1 Layer 3 (MP3)";
285 case 5: return "MPEG2 (multichannel)";
286 case 6: return "AAC LC";
287 case 7: return "DTS";
288 case 8: return "ATRAC";
289 case 9: return "One Bit Audio";
290 case 10: return "Enhanced AC-3 (DD+)";
291 case 11: return "DTS-HD";
292 case 12: return "MAT (MLP)";
293 case 13: return "DST";
294 case 14: return "WMA Pro";
295 default: break;
297 fail("Unknown Audio Format 0x%02x.\n", x);
298 return std::string("Unknown Audio Format (") + utohex(x) + ")";
301 static std::string mpeg_h_3d_audio_level(unsigned char x)
303 switch (x) {
304 case 0: return "Unspecified";
305 case 1: return "Level 1";
306 case 2: return "Level 2";
307 case 3: return "Level 3";
308 case 4: return "Level 4";
309 case 5: return "Level 5";
310 default: break;
312 fail("Unknown MPEG-H 3D Audio Level 0x%02x.\n", x);
313 return std::string("Unknown MPEG-H 3D Audio Level (") + utohex(x) + ")";
316 static void cta_audio_block(const unsigned char *x, unsigned length)
318 unsigned i, format, ext_format;
320 if (length % 3) {
321 fail("Broken CTA-861 audio block length %d.\n", length);
322 return;
325 for (i = 0; i < length; i += 3) {
326 format = (x[i] & 0x78) >> 3;
327 if (format == 0) {
328 printf(" Reserved (0x00)\n");
329 fail("Audio Format Code 0x00 is reserved.\n");
330 continue;
332 if (format != 15) {
333 ext_format = 0;
334 printf(" %s:\n", audio_format(format).c_str());
335 } else {
336 ext_format = (x[i + 2] & 0xf8) >> 3;
337 printf(" %s:\n", audio_ext_format(ext_format).c_str());
339 if (format != 15)
340 printf(" Max channels: %u\n", (x[i] & 0x07)+1);
341 else if (ext_format == 11)
342 printf(" MPEG-H 3D Audio Level: %s\n",
343 mpeg_h_3d_audio_level(x[i] & 0x07).c_str());
344 else if (ext_format == 13)
345 printf(" Max channels: %u\n",
346 (((x[i + 1] & 0x80) >> 3) | ((x[i] & 0x80) >> 4) |
347 (x[i] & 0x07))+1);
348 else
349 printf(" Max channels: %u\n", (x[i] & 0x07)+1);
351 printf(" Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
352 (x[i+1] & 0x40) ? " 192" : "",
353 (x[i+1] & 0x20) ? " 176.4" : "",
354 (x[i+1] & 0x10) ? " 96" : "",
355 (x[i+1] & 0x08) ? " 88.2" : "",
356 (x[i+1] & 0x04) ? " 48" : "",
357 (x[i+1] & 0x02) ? " 44.1" : "",
358 (x[i+1] & 0x01) ? " 32" : "");
359 if (format == 1 || ext_format == 13) {
360 printf(" Supported sample sizes (bits):%s%s%s\n",
361 (x[i+2] & 0x04) ? " 24" : "",
362 (x[i+2] & 0x02) ? " 20" : "",
363 (x[i+2] & 0x01) ? " 16" : "");
364 } else if (format <= 8) {
365 printf(" Maximum bit rate: %u kb/s\n", x[i+2] * 8);
366 } else if (format == 10) {
367 // As specified by the "Dolby Audio and Dolby Atmos over HDMI"
368 // specification (v1.0).
369 if (x[i+2] & 1)
370 printf(" Supports Joint Object Coding\n");
371 if (x[i+2] & 2)
372 printf(" Supports Joint Object Coding with ACMOD28\n");
373 } else if (format == 12) {
374 if (x[i+2] & 1) {
375 printf(" Supports Dolby TrueHD, object audio PCM and channel-based PCM\n");
376 printf(" Hash calculation %srequired for object audio PCM or channel-based PCM\n",
377 (x[i+2] & 2) ? "not " : "");
378 } else {
379 printf(" Supports only Dolby TrueHD\n");
381 } else if (format == 14) {
382 printf(" Profile: %u\n", x[i+2] & 7);
383 } else if (format >= 9 && format <= 13) {
384 printf(" Audio Format Code dependent value: 0x%02x\n", x[i+2]);
385 } else if (ext_format == 11 && (x[i+2] & 1)) {
386 printf(" Supports MPEG-H 3D Audio Low Complexity Profile\n");
387 } else if ((ext_format >= 4 && ext_format <= 6) ||
388 ext_format == 8 || ext_format == 10) {
389 printf(" AAC audio frame lengths:%s%s\n",
390 (x[i+2] & 4) ? " 1024_TL" : "",
391 (x[i+2] & 2) ? " 960_TL" : "");
392 if (ext_format >= 8 && (x[i+2] & 1))
393 printf(" Supports %s signaled MPEG Surround data\n",
394 (x[i+2] & 1) ? "implicitly and explicitly" : "only implicitly");
395 if (ext_format == 6 && (x[i+2] & 1))
396 printf(" Supports 22.2ch System H\n");
401 void edid_state::cta_svd(const unsigned char *x, unsigned n, bool for_ycbcr420)
403 unsigned i;
405 for (i = 0; i < n; i++) {
406 const struct timings *t = NULL;
407 unsigned char svd = x[i];
408 unsigned char native;
409 unsigned char vic;
411 if ((svd & 0x7f) == 0)
412 continue;
414 if ((svd - 1) & 0x40) {
415 vic = svd;
416 native = 0;
417 } else {
418 vic = svd & 0x7f;
419 native = svd & 0x80;
422 t = find_vic_id(vic);
423 if (t) {
424 switch (vic) {
425 case 95:
426 cta.supported_hdmi_vic_vsb_codes |= 1 << 0;
427 break;
428 case 94:
429 cta.supported_hdmi_vic_vsb_codes |= 1 << 1;
430 break;
431 case 93:
432 cta.supported_hdmi_vic_vsb_codes |= 1 << 2;
433 break;
434 case 98:
435 cta.supported_hdmi_vic_vsb_codes |= 1 << 3;
436 break;
438 bool first_svd = cta.first_svd && !for_ycbcr420;
439 bool override_pref = first_svd && cta.first_svd_might_be_preferred;
441 char type[16];
442 sprintf(type, "VIC %3u", vic);
443 const char *flags = native ? "native" : "";
445 if (for_ycbcr420) {
446 struct timings tmp = *t;
447 tmp.ycbcr420 = true;
448 print_timings(" ", &tmp, type, flags);
449 } else {
450 print_timings(" ", t, type, flags);
452 if (override_pref) {
453 if (!cta.preferred_timings.empty()) {
454 if (match_timings(cta.preferred_timings[0].t, *t))
455 warn("For improved preferred timing interoperability, set 'Native detailed modes' to 1.\n");
456 else
457 warn("VIC %u is the preferred timing, overriding the first detailed timings. Is this intended?\n", vic);
459 cta.preferred_timings.insert(cta.preferred_timings.begin(),
460 timings_ext(*t, type, flags));
461 } else if (first_svd) {
462 cta.preferred_timings.push_back(timings_ext(*t, type, flags));
464 if (first_svd) {
465 cta.first_svd = false;
466 cta.first_svd_might_be_preferred = false;
468 if (native)
469 cta.native_timings.push_back(timings_ext(*t, type, flags));
470 } else {
471 printf(" Unknown (VIC %3u)\n", vic);
472 fail("Unknown VIC %u.\n", vic);
475 if (vic == 1 && !for_ycbcr420)
476 cta.has_vic_1 = 1;
477 if (++cta.vics[vic][for_ycbcr420] == 2)
478 fail("Duplicate %sVIC %u.\n", for_ycbcr420 ? "YCbCr 4:2:0 " : "", vic);
479 if (for_ycbcr420 && cta.preparsed_has_vic[0][vic])
480 fail("YCbCr 4:2:0-only VIC %u is also a regular VIC.\n", vic);
484 void edid_state::print_vic_index(const char *prefix, unsigned idx, const char *suffix, bool ycbcr420)
486 if (!suffix)
487 suffix = "";
488 if (idx < cta.preparsed_svds[0].size()) {
489 unsigned char vic = cta.preparsed_svds[0][idx];
490 const struct timings *t = find_vic_id(vic);
491 char buf[16];
493 sprintf(buf, "VIC %3u", vic);
495 if (t) {
496 struct timings tmp = *t;
497 tmp.ycbcr420 = ycbcr420;
498 print_timings(prefix, &tmp, buf, suffix);
499 } else {
500 printf("%sUnknown (%s%s%s)\n", prefix, buf,
501 *suffix ? ", " : "", suffix);
503 } else {
504 // Should not happen!
505 printf("%sSVD Index %u is out of range", prefix, idx + 1);
506 if (*suffix)
507 printf(" (%s)", suffix);
508 printf("\n");
512 void edid_state::cta_y420cmdb(const unsigned char *x, unsigned length)
514 unsigned max_idx = 0;
515 unsigned i;
517 if (!length) {
518 printf(" All VDB SVDs\n");
519 return;
522 if (memchk(x, length)) {
523 printf(" Empty Capability Map\n");
524 fail("Empty Capability Map.\n");
525 return;
528 for (i = 0; i < length; i++) {
529 unsigned char v = x[i];
530 unsigned j;
532 for (j = 0; j < 8; j++) {
533 if (!(v & (1 << j)))
534 continue;
536 print_vic_index(" ", i * 8 + j, "", true);
537 max_idx = i * 8 + j;
538 if (max_idx < cta.preparsed_svds[0].size()) {
539 unsigned vic = cta.preparsed_svds[0][max_idx];
540 if (cta.preparsed_has_vic[1][vic])
541 fail("VIC %u is also a YCbCr 4:2:0-only VIC.\n", vic);
545 if (max_idx >= cta.preparsed_svds[0].size())
546 fail("Max index %u > %u (#SVDs).\n",
547 max_idx + 1, cta.preparsed_svds[0].size());
550 void edid_state::cta_print_svr(unsigned char svr, vec_timings_ext &vec_tim)
552 char suffix[16];
554 if ((svr > 0 && svr < 128) || (svr > 192 && svr < 254)) {
555 const struct timings *t;
556 unsigned char vic = svr;
558 sprintf(suffix, "VIC %3u", vic);
560 t = find_vic_id(vic);
561 if (t) {
562 print_timings(" ", t, suffix);
563 vec_tim.push_back(timings_ext(*t, suffix, ""));
564 } else {
565 printf(" %s: Unknown\n", suffix);
566 fail("Unknown VIC %u.\n", vic);
569 } else if (svr >= 129 && svr <= 144) {
570 sprintf(suffix, "DTD %3u", svr - 128);
571 if (svr >= cta.preparsed_total_dtds + 129) {
572 printf(" %s: Invalid\n", suffix);
573 fail("Invalid DTD %u.\n", svr - 128);
574 } else {
575 printf(" %s\n", suffix);
576 vec_tim.push_back(timings_ext(svr, suffix));
578 } else if (svr >= 145 && svr <= 160) {
579 sprintf(suffix, "VTDB %3u", svr - 144);
580 if (svr >= cta.preparsed_total_vtdbs + 145) {
581 printf(" %s: Invalid\n", suffix);
582 fail("Invalid VTDB %u.\n", svr - 144);
583 } else {
584 printf(" %s\n", suffix);
585 vec_tim.push_back(timings_ext(svr, suffix));
587 } else if (svr == 254) {
588 sprintf(suffix, "T8VTDB");
589 if (!cta.preparsed_has_t8vtdb) {
590 printf(" %s: Invalid\n", suffix);
591 fail("Invalid T8VTDB.\n");
592 } else {
593 printf(" %s\n", suffix);
594 vec_tim.push_back(timings_ext(svr, suffix));
599 void edid_state::cta_vfpdb(const unsigned char *x, unsigned length)
601 unsigned i;
603 if (length == 0) {
604 fail("Empty Data Block with length %u.\n", length);
605 return;
607 cta.preferred_timings.clear();
608 for (i = 0; i < length; i++)
609 cta_print_svr(x[i], cta.preferred_timings);
612 static std::string hdmi_latency2s(unsigned char l, bool is_video)
614 if (!l)
615 return "Unknown";
616 if (l == 0xff)
617 return is_video ? "Video not supported" : "Audio not supported";
618 return std::to_string(1 + 2 * l) + " ms";
621 void edid_state::hdmi_latency(unsigned char vid_lat, unsigned char aud_lat,
622 bool is_ilaced)
624 const char *vid = is_ilaced ? "Interlaced video" : "Video";
625 const char *aud = is_ilaced ? "Interlaced audio" : "Audio";
627 printf(" %s latency: %s\n", vid, hdmi_latency2s(vid_lat, true).c_str());
628 printf(" %s latency: %s\n", aud, hdmi_latency2s(aud_lat, false).c_str());
630 if (vid_lat > 251 && vid_lat != 0xff)
631 fail("Invalid %s latency value %u.\n", vid, vid_lat);
632 if (aud_lat > 251 && aud_lat != 0xff)
633 fail("Invalid %s latency value %u.\n", aud, aud_lat);
635 if (!vid_lat || vid_lat > 251)
636 return;
637 if (!aud_lat || aud_lat > 251)
638 return;
640 unsigned vid_ms = 1 + 2 * vid_lat;
641 unsigned aud_ms = 1 + 2 * aud_lat;
643 // HDMI 2.0 latency checks for devices without HDMI output
644 if (aud_ms < vid_ms)
645 warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
646 aud, vid, aud_ms, vid_ms);
647 else if (vid_ms + 20 < aud_ms)
648 warn("%s latency + 20 < %s latency (%u + 20 ms < %u ms). This is forbidden for devices without HDMI output.\n",
649 vid, aud, vid_ms, aud_ms);
650 else if (vid_ms < aud_ms)
651 warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
652 vid, aud, vid_ms, aud_ms);
655 void edid_state::cta_hdmi_block(const unsigned char *x, unsigned length)
657 unsigned len_vic, len_3d;
659 if (length < 1) {
660 fail("Empty Data Block with length %u.\n", length);
661 return;
663 printf(" Source physical address: %x.%x.%x.%x\n", x[0] >> 4, x[0] & 0x0f,
664 x[1] >> 4, x[1] & 0x0f);
666 if (length < 3)
667 return;
669 if (x[2] & 0x80)
670 printf(" Supports_AI\n");
671 if (x[2] & 0x40)
672 printf(" DC_48bit\n");
673 if (x[2] & 0x20)
674 printf(" DC_36bit\n");
675 if (x[2] & 0x10)
676 printf(" DC_30bit\n");
677 if (x[2] & 0x08)
678 printf(" DC_Y444\n");
679 /* two reserved bits */
680 if (x[2] & 0x01)
681 printf(" DVI_Dual\n");
683 if (length < 4)
684 return;
686 printf(" Maximum TMDS clock: %u MHz\n", x[3] * 5);
687 if (x[3] * 5 > 340)
688 fail("HDMI VSDB Max TMDS rate is > 340.\n");
690 if (length < 5)
691 return;
693 if (x[4] & 0x0f) {
694 printf(" Supported Content Types:\n");
695 if (x[4] & 0x01)
696 printf(" Graphics\n");
697 if (x[4] & 0x02)
698 printf(" Photo\n");
699 if (x[4] & 0x04)
700 printf(" Cinema\n");
701 if (x[4] & 0x08)
702 printf(" Game\n");
705 unsigned b = 5;
706 if (x[4] & 0x80) {
707 hdmi_latency(x[b], x[b + 1], false);
709 if (x[4] & 0x40) {
710 if (x[b] == x[b + 2] &&
711 x[b + 1] == x[b + 3])
712 warn("Progressive and Interlaced latency values are identical, no need for both.\n");
713 b += 2;
714 hdmi_latency(x[b], x[b + 1], true);
716 b += 2;
719 if (!(x[4] & 0x20))
720 return;
722 bool mask = false;
723 bool formats = false;
725 printf(" Extended HDMI video details:\n");
726 if (x[b] & 0x80)
727 printf(" 3D present\n");
728 if ((x[b] & 0x60) == 0x20) {
729 printf(" All advertised VICs are 3D-capable\n");
730 formats = true;
732 if ((x[b] & 0x60) == 0x40) {
733 printf(" 3D-capable-VIC mask present\n");
734 formats = true;
735 mask = true;
737 switch (x[b] & 0x18) {
738 case 0x00: break;
739 case 0x08:
740 printf(" Base EDID image size is aspect ratio\n");
741 break;
742 case 0x10:
743 printf(" Base EDID image size is in units of 1 cm\n");
744 break;
745 case 0x18:
746 printf(" Base EDID image size is in units of 5 cm\n");
747 base.max_display_width_mm *= 5;
748 base.max_display_height_mm *= 5;
749 printf(" Recalculated image size: %u cm x %u cm\n",
750 base.max_display_width_mm / 10, base.max_display_height_mm / 10);
751 break;
753 b++;
754 len_vic = (x[b] & 0xe0) >> 5;
755 len_3d = (x[b] & 0x1f) >> 0;
756 b++;
758 if (len_vic) {
759 unsigned i;
761 printf(" HDMI VICs:\n");
762 for (i = 0; i < len_vic; i++) {
763 unsigned char vic = x[b + i];
764 const struct timings *t;
766 if (vic && vic <= ARRAY_SIZE(edid_hdmi_mode_map)) {
767 std::string suffix = "HDMI VIC " + std::to_string(vic);
768 cta.supported_hdmi_vic_codes |= 1 << (vic - 1);
769 t = find_vic_id(edid_hdmi_mode_map[vic - 1]);
770 print_timings(" ", t, suffix.c_str());
771 } else {
772 printf(" Unknown (HDMI VIC %u)\n", vic);
773 fail("Unknown HDMI VIC %u.\n", vic);
777 b += len_vic;
780 if (!len_3d)
781 return;
783 if (formats) {
784 /* 3D_Structure_ALL_15..8 */
785 if (x[b] & 0x80)
786 printf(" 3D: Side-by-side (half, quincunx)\n");
787 if (x[b] & 0x01)
788 printf(" 3D: Side-by-side (half, horizontal)\n");
789 /* 3D_Structure_ALL_7..0 */
790 b++;
791 if (x[b] & 0x40)
792 printf(" 3D: Top-and-bottom\n");
793 if (x[b] & 0x20)
794 printf(" 3D: L + depth + gfx + gfx-depth\n");
795 if (x[b] & 0x10)
796 printf(" 3D: L + depth\n");
797 if (x[b] & 0x08)
798 printf(" 3D: Side-by-side (full)\n");
799 if (x[b] & 0x04)
800 printf(" 3D: Line-alternative\n");
801 if (x[b] & 0x02)
802 printf(" 3D: Field-alternative\n");
803 if (x[b] & 0x01)
804 printf(" 3D: Frame-packing\n");
805 b++;
806 len_3d -= 2;
809 if (mask) {
810 int max_idx = -1;
811 unsigned i;
813 printf(" 3D VIC indices that support these capabilities:\n");
814 /* worst bit ordering ever */
815 for (i = 0; i < 8; i++)
816 if (x[b + 1] & (1 << i)) {
817 print_vic_index(" ", i, "");
818 max_idx = i;
820 for (i = 0; i < 8; i++)
821 if (x[b] & (1 << i)) {
822 print_vic_index(" ", i + 8, "");
823 max_idx = i + 8;
825 b += 2;
826 len_3d -= 2;
827 if (max_idx >= (int)cta.preparsed_svds[0].size())
828 fail("HDMI 3D VIC indices max index %d > %u (#SVDs).\n",
829 max_idx + 1, cta.preparsed_svds[0].size());
833 * list of nibbles:
834 * 2D_VIC_Order_X
835 * 3D_Structure_X
836 * (optionally: 3D_Detail_X and reserved)
838 if (!len_3d)
839 return;
841 unsigned end = b + len_3d;
842 int max_idx = -1;
844 printf(" 3D VIC indices with specific capabilities:\n");
845 while (b < end) {
846 unsigned char idx = x[b] >> 4;
847 std::string s;
849 if (idx > max_idx)
850 max_idx = idx;
851 switch (x[b] & 0x0f) {
852 case 0: s = "frame packing"; break;
853 case 1: s = "field alternative"; break;
854 case 2: s = "line alternative"; break;
855 case 3: s = "side-by-side (full)"; break;
856 case 4: s = "L + depth"; break;
857 case 5: s = "L + depth + gfx + gfx-depth"; break;
858 case 6: s = "top-and-bottom"; break;
859 case 8:
860 s = "side-by-side";
861 switch (x[b + 1] >> 4) {
862 case 0x00: s += ", any subsampling"; break;
863 case 0x01: s += ", horizontal"; break;
864 case 0x02: case 0x03: case 0x04: case 0x05:
865 s += ", not in use";
866 fail("not-in-use 3D_Detail_X value 0x%02x.\n",
867 x[b + 1] >> 4);
868 break;
869 case 0x06: s += ", all quincunx combinations"; break;
870 case 0x07: s += ", quincunx odd/left, odd/right"; break;
871 case 0x08: s += ", quincunx odd/left, even/right"; break;
872 case 0x09: s += ", quincunx even/left, odd/right"; break;
873 case 0x0a: s += ", quincunx even/left, even/right"; break;
874 default:
875 s += ", reserved";
876 fail("reserved 3D_Detail_X value 0x%02x.\n",
877 x[b + 1] >> 4);
878 break;
880 break;
881 default:
882 s = "unknown (";
883 s += utohex(x[b] & 0x0f) + ")";
884 fail("Unknown 3D_Structure_X value 0x%02x.\n", x[b] & 0x0f);
885 break;
887 print_vic_index(" ", idx, s.c_str());
888 if ((x[b] & 0x0f) >= 8)
889 b++;
890 b++;
892 if (max_idx >= (int)cta.preparsed_svds[0].size())
893 fail("HDMI 2D VIC indices max index %d > %u (#SVDs).\n",
894 max_idx + 1, cta.preparsed_svds[0].size());
897 static const char *max_frl_rates[] = {
898 "Not Supported",
899 "3 Gbps per lane on 3 lanes",
900 "3 and 6 Gbps per lane on 3 lanes",
901 "3 and 6 Gbps per lane on 3 lanes, 6 Gbps on 4 lanes",
902 "3 and 6 Gbps per lane on 3 lanes, 6 and 8 Gbps on 4 lanes",
903 "3 and 6 Gbps per lane on 3 lanes, 6, 8 and 10 Gbps on 4 lanes",
904 "3 and 6 Gbps per lane on 3 lanes, 6, 8, 10 and 12 Gbps on 4 lanes",
907 static const char *dsc_max_slices[] = {
908 "Not Supported",
909 "up to 1 slice and up to (340 MHz/Ksliceadjust) pixel clock per slice",
910 "up to 2 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
911 "up to 4 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
912 "up to 8 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
913 "up to 8 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
914 "up to 12 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
915 "up to 16 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
918 static void cta_hf_eeodb(const unsigned char *x, unsigned length)
920 printf(" EDID Extension Block Count: %u\n", x[0]);
921 if (length != 1 || x[0] == 0)
922 fail("Block is too long or reports a 0 block count.\n");
925 static void cta_hf_scdb(const unsigned char *x, unsigned length)
927 unsigned rate = x[1] * 5;
928 unsigned v;
930 printf(" Version: %u\n", x[0]);
931 if (rate) {
932 printf(" Maximum TMDS Character Rate: %u MHz\n", rate);
933 if (rate <= 340 || rate > 600)
934 fail("Max TMDS rate is > 0 and <= 340 or > 600.\n");
936 if (x[2] & 0x80)
937 printf(" SCDC Present\n");
938 if (x[2] & 0x40)
939 printf(" SCDC Read Request Capable\n");
940 if (x[2] & 0x10)
941 printf(" Supports Color Content Bits Per Component Indication\n");
942 if (x[2] & 0x08)
943 printf(" Supports scrambling for <= 340 Mcsc\n");
944 if (x[2] & 0x04)
945 printf(" Supports 3D Independent View signaling\n");
946 if (x[2] & 0x02)
947 printf(" Supports 3D Dual View signaling\n");
948 if (x[2] & 0x01)
949 printf(" Supports 3D OSD Disparity signaling\n");
950 if (x[3] & 0xf0) {
951 unsigned max_frl_rate = x[3] >> 4;
953 printf(" Max Fixed Rate Link: ");
954 if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
955 printf("%s\n", max_frl_rates[max_frl_rate]);
956 } else {
957 printf("Unknown (0x%02x)\n", max_frl_rate);
958 fail("Unknown Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
960 if (max_frl_rate == 1 && rate < 300)
961 fail("Max Fixed Rate Link is 1, but Max TMDS rate < 300.\n");
962 else if (max_frl_rate >= 2 && rate < 600)
963 fail("Max Fixed Rate Link is >= 2, but Max TMDS rate < 600.\n");
965 if (x[3] & 0x08)
966 printf(" Supports UHD VIC\n");
967 if (x[3] & 0x04)
968 printf(" Supports 16-bits/component Deep Color 4:2:0 Pixel Encoding\n");
969 if (x[3] & 0x02)
970 printf(" Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding\n");
971 if (x[3] & 0x01)
972 printf(" Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding\n");
974 if (length <= 4)
975 return;
977 if (x[4] & 0x20)
978 printf(" Supports Mdelta\n");
979 if (x[4] & 0x10)
980 printf(" Supports media rates below VRRmin (CinemaVRR)\n");
981 if (x[4] & 0x08)
982 printf(" Supports negative Mvrr values\n");
983 if (x[4] & 0x04)
984 printf(" Supports Fast Vactive\n");
985 if (x[4] & 0x02)
986 printf(" Supports Auto Low-Latency Mode\n");
987 if (x[4] & 0x01)
988 printf(" Supports a FAPA in blanking after first active video line\n");
990 if (length <= 5)
991 return;
993 v = x[5] & 0x3f;
994 if (v) {
995 printf(" VRRmin: %u Hz\n", v);
996 if (v > 48)
997 fail("VRRmin > 48.\n");
999 v = (x[5] & 0xc0) << 2 | x[6];
1000 if (v) {
1001 printf(" VRRmax: %u Hz\n", v);
1002 if (!(x[5] & 0x3f))
1003 fail("VRRmin == 0, but VRRmax isn't.\n");
1004 else if (v < 100)
1005 fail("VRRmax < 100.\n");
1008 if (length <= 7)
1009 return;
1011 if (x[7] & 0x80)
1012 printf(" Supports VESA DSC 1.2a compression\n");
1013 if (x[7] & 0x40)
1014 printf(" Supports Compressed Video Transport for 4:2:0 Pixel Encoding\n");
1015 if (x[7] & 0x08)
1016 printf(" Supports Compressed Video Transport at any valid 1/16th bit bpp\n");
1017 if (x[7] & 0x04)
1018 printf(" Supports 16 bpc Compressed Video Transport\n");
1019 if (x[7] & 0x02)
1020 printf(" Supports 12 bpc Compressed Video Transport\n");
1021 if (x[7] & 0x01)
1022 printf(" Supports 10 bpc Compressed Video Transport\n");
1023 if (x[8] & 0xf) {
1024 unsigned max_slices = x[8] & 0xf;
1026 printf(" DSC Max Slices: ");
1027 if (max_slices < ARRAY_SIZE(dsc_max_slices)) {
1028 printf("%s\n", dsc_max_slices[max_slices]);
1029 } else {
1030 printf("Unknown (0x%02x)\n", max_slices);
1031 fail("Unknown DSC Max Slices (0x%02x).\n", max_slices);
1034 if (x[8] & 0xf0) {
1035 unsigned max_frl_rate = x[8] >> 4;
1037 printf(" DSC Max Fixed Rate Link: ");
1038 if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
1039 printf("%s\n", max_frl_rates[max_frl_rate]);
1040 } else {
1041 printf("Unknown (0x%02x)\n", max_frl_rate);
1042 fail("Unknown DSC Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
1045 if (x[9] & 0x3f)
1046 printf(" Maximum number of bytes in a line of chunks: %u\n",
1047 1024 * (1 + (x[9] & 0x3f)));
1050 static void cta_amd(const unsigned char *x, unsigned length)
1052 // These Freesync values are reversed engineered by looking
1053 // at existing EDIDs.
1054 printf(" Version: %u.%u\n", x[0], x[1]);
1055 printf(" Minimum Refresh Rate: %u Hz\n", x[2]);
1056 printf(" Maximum Refresh Rate: %u Hz\n", x[3]);
1057 // Freesync 1.x flags
1058 // One or more of the 0xe6 bits signal that the VESA MCCS
1059 // protocol is used to switch the Freesync range
1060 printf(" Flags 1.x: 0x%02x%s\n", x[4],
1061 (x[4] & 0xe6) ? " (MCCS)" : "");
1062 if (length >= 10) {
1063 // Freesync 2.x flags
1064 // Bit 2 no doubt indicates if the monitor supports Local Dimming
1065 // There are probably also bits to signal support of the
1066 // FreeSync2_scRGB and FreeSync2_Gamma22 HDR display modes.
1067 // I suspect bits 0 and 1.
1068 printf(" Flags 2.x: 0x%02x\n", x[5]);
1069 // The AMD tone mapping tutorial referred to in the URL below
1070 // mentions that the Freesync HDR info reports max/min
1071 // luminance of the monitor with and without local dimming.
1073 // https://gpuopen.com/learn/using-amd-freesync-premium-pro-hdr-code-samples/
1075 // So I assume that the first two luminance values are
1076 // the max/min luminance of the display and the next two
1077 // luminance values are the max/min luminance values when
1078 // local dimming is disabled. The values I get seem to
1079 // support that.
1080 printf(" Maximum luminance: %u (%.3f cd/m^2)\n",
1081 x[6], 50.0 * pow(2, x[6] / 32.0));
1082 printf(" Minimum luminance: %u (%.3f cd/m^2)\n",
1083 x[7], (50.0 * pow(2, x[6] / 32.0)) * pow(x[7] / 255.0, 2) / 100.0);
1084 if (x[5] & 4) {
1085 // One or both bytes can be 0. The meaning of that
1086 // is unknown.
1087 printf(" Maximum luminance (without local dimming): %u (%.3f cd/m^2)\n",
1088 x[8], 50.0 * pow(2, x[8] / 32.0));
1089 printf(" Minimum luminance (without local dimming): %u (%.3f cd/m^2)\n",
1090 x[9], (50.0 * pow(2, x[8] / 32.0)) * pow(x[9] / 255.0, 2) / 100.0);
1091 } else {
1092 // These bytes are always 0x08 0x2f. If these values
1093 // represent max/min luminance as well, then these
1094 // would map to 59.460 and 0.020 cd/m^2 respectively.
1095 // I wonder if this somehow relates to SDR.
1096 printf(" Unknown: 0x%02x 0x%02x\n", x[8], x[9]);
1101 static std::string display_use_case(unsigned char x)
1103 switch (x) {
1104 case 1: return "Test equipment";
1105 case 2: return "Generic display";
1106 case 3: return "Television display";
1107 case 4: return "Desktop productivity display";
1108 case 5: return "Desktop gaming display";
1109 case 6: return "Presentation display";
1110 case 7: return "Virtual reality headset";
1111 case 8: return "Augmented reality";
1112 case 16: return "Video wall display";
1113 case 17: return "Medical imaging display";
1114 case 18: return "Dedicated gaming display";
1115 case 19: return "Dedicated video monitor display";
1116 case 20: return "Accessory display";
1117 default: break;
1119 fail("Unknown Display product primary use case 0x%02x.\n", x);
1120 return std::string("Unknown display use case (") + utohex(x) + ")";
1123 static void cta_microsoft(const unsigned char *x, unsigned length)
1125 // This VSDB is documented at:
1126 // https://docs.microsoft.com/en-us/windows-hardware/drivers/display/specialized-monitors-edid-extension
1127 printf(" Version: %u\n", x[0]);
1128 if (x[0] > 2) {
1129 // In version 1 and 2 these bits should always be set to 0.
1130 printf(" Desktop Usage: %u\n", (x[1] >> 6) & 1);
1131 printf(" Third-Party Usage: %u\n", (x[1] >> 5) & 1);
1133 printf(" Display Product Primary Use Case: %u (%s)\n", x[1] & 0x1f,
1134 display_use_case(x[1] & 0x1f).c_str());
1135 printf(" Container ID: %s\n", containerid2s(x + 2).c_str());
1138 static void cta_hdr10plus(const unsigned char *x, unsigned length)
1140 if (length == 0) {
1141 fail("Empty Data Block with length %u.\n", length);
1142 return;
1144 printf(" Application Version: %u\n", x[0]);
1145 hex_block(" ", x + 1, length - 1);
1148 // Convert a PQ value (0-1) to cd/m^2 aka nits (0-10000)
1149 static double pq2nits(double pq)
1151 const double m1 = 2610.0 / 16384.0;
1152 const double m2 = 128.0 * (2523.0 / 4096.0);
1153 const double c1 = 3424.0 / 4096.0;
1154 const double c2 = 32.0 * (2413.0 / 4096.0);
1155 const double c3 = 32.0 * (2392.0 / 4096.0);
1156 double e = pow(pq, 1.0 / m2);
1157 double v = e - c1;
1159 if (v < 0)
1160 v = 0;
1161 v /= c2 - c3 * e;
1162 v = pow(v, 1.0 / m1);
1163 return v * 10000.0;
1166 static void cta_dolby_video(const unsigned char *x, unsigned length)
1168 unsigned char version = (x[0] >> 5) & 0x07;
1170 printf(" Version: %u (%u bytes)\n", version, length + 5);
1171 if (x[0] & 0x01)
1172 printf(" Supports YUV422 12 bit\n");
1174 if (version == 0) {
1175 if (x[0] & 0x02)
1176 printf(" Supports 2160p60\n");
1177 if (x[0] & 0x04)
1178 printf(" Supports global dimming\n");
1179 unsigned char dm_version = x[16];
1180 printf(" DM Version: %u.%u\n", dm_version >> 4, dm_version & 0xf);
1181 unsigned pq = (x[14] << 4) | (x[13] >> 4);
1182 printf(" Target Min PQ: %u (%.8f cd/m^2)\n", pq, pq2nits(pq / 4095.0));
1183 pq = (x[15] << 4) | (x[13] & 0xf);
1184 printf(" Target Max PQ: %u (%u cd/m^2)\n", pq, (unsigned)pq2nits(pq / 4095.0));
1185 printf(" Rx, Ry: %.8f, %.8f\n",
1186 ((x[1] >> 4) | (x[2] << 4)) / 4096.0,
1187 ((x[1] & 0xf) | (x[3] << 4)) / 4096.0);
1188 printf(" Gx, Gy: %.8f, %.8f\n",
1189 ((x[4] >> 4) | (x[5] << 4)) / 4096.0,
1190 ((x[4] & 0xf) | (x[6] << 4)) / 4096.0);
1191 printf(" Bx, By: %.8f, %.8f\n",
1192 ((x[7] >> 4) | (x[8] << 4)) / 4096.0,
1193 ((x[7] & 0xf) | (x[9] << 4)) / 4096.0);
1194 printf(" Wx, Wy: %.8f, %.8f\n",
1195 ((x[10] >> 4) | (x[11] << 4)) / 4096.0,
1196 ((x[10] & 0xf) | (x[12] << 4)) / 4096.0);
1197 return;
1200 if (version == 1) {
1201 if (x[0] & 0x02)
1202 printf(" Supports 2160p60\n");
1203 if (x[1] & 0x01)
1204 printf(" Supports global dimming\n");
1205 unsigned char dm_version = (x[0] >> 2) & 0x07;
1206 printf(" DM Version: %u.x\n", dm_version + 2);
1207 printf(" Colorimetry: %s\n", (x[2] & 0x01) ? "P3-D65" : "ITU-R BT.709");
1208 printf(" Low Latency: %s\n", (x[3] & 0x01) ? "Standard + Low Latency" : "Only Standard");
1209 double lm = (x[2] >> 1) / 127.0;
1210 printf(" Target Min Luminance: %.8f cd/m^2\n", lm * lm);
1211 printf(" Target Max Luminance: %u cd/m^2\n", 100 + (x[1] >> 1) * 50);
1212 if (length == 10) {
1213 printf(" Rx, Ry: %.8f, %.8f\n", x[4] / 256.0, x[5] / 256.0);
1214 printf(" Gx, Gy: %.8f, %.8f\n", x[6] / 256.0, x[7] / 256.0);
1215 printf(" Bx, By: %.8f, %.8f\n", x[8] / 256.0, x[9] / 256.0);
1216 } else {
1217 double xmin = 0.625;
1218 double xstep = (0.74609375 - xmin) / 31.0;
1219 double ymin = 0.25;
1220 double ystep = (0.37109375 - ymin) / 31.0;
1222 printf(" Unique Rx, Ry: %.8f, %.8f\n",
1223 xmin + xstep * (x[6] >> 3),
1224 ymin + ystep * (((x[6] & 0x7) << 2) | (x[4] & 0x01) | ((x[5] & 0x01) << 1)));
1225 xstep = 0.49609375 / 127.0;
1226 ymin = 0.5;
1227 ystep = (0.99609375 - ymin) / 127.0;
1228 printf(" Unique Gx, Gy: %.8f, %.8f\n",
1229 xstep * (x[4] >> 1), ymin + ystep * (x[5] >> 1));
1230 xmin = 0.125;
1231 xstep = (0.15234375 - xmin) / 7.0;
1232 ymin = 0.03125;
1233 ystep = (0.05859375 - ymin) / 7.0;
1234 printf(" Unique Bx, By: %.8f, %.8f\n",
1235 xmin + xstep * (x[3] >> 5),
1236 ymin + ystep * ((x[3] >> 2) & 0x07));
1238 return;
1241 if (version == 2) {
1242 if (x[0] & 0x02)
1243 printf(" Supports Backlight Control\n");
1244 if (x[1] & 0x04)
1245 printf(" Supports global dimming\n");
1246 unsigned char dm_version = (x[0] >> 2) & 0x07;
1247 printf(" DM Version: %u.x\n", dm_version + 2);
1248 printf(" Backlt Min Luma: %u cd/m^2\n", 25 + (x[1] & 0x03) * 25);
1249 printf(" Interface: ");
1250 switch (x[2] & 0x03) {
1251 case 0: printf("Low-Latency\n"); break;
1252 case 1: printf("Low-Latency + Low-Latency-HDMI\n"); break;
1253 case 2: printf("Standard + Low-Latency\n"); break;
1254 case 3: printf("Standard + Low-Latency + Low-Latency-HDMI\n"); break;
1256 printf(" Supports 10b 12b 444: ");
1257 switch ((x[3] & 0x01) << 1 | (x[4] & 0x01)) {
1258 case 0: printf("Not supported\n"); break;
1259 case 1: printf("10 bit\n"); break;
1260 case 2: printf("12 bit\n"); break;
1261 case 3: printf("Reserved\n"); break;
1264 // This divider constant is a guess. According to what I read
1265 // when googling for how to interpret these values, the Min PQ
1266 // maps to a range of 0-1 cd/m^2, and the Max PQ maps to a
1267 // range of 100-10000 cd/m^2. Since the maximum value for the Max PQ
1268 // is 2055 + 65 * 31 = 4070, I am guessing that that is the correct
1269 // divider, but it might well be 4095 or 4096 instead.
1271 // I'm also not sure if the divider for Min PQ is the same as for
1272 // Max PQ. To map the max value of 20 * 31 to 1 cd/m^2 you would
1273 // need a divider of 4134 or 4135, but I suspect the same divider
1274 // is used.
1275 const double dv_pq_div = 2055 + 31 * 65;
1277 unsigned pq = 20 * (x[1] >> 3);
1278 printf(" Target Min PQ v2: %u (%.8f cd/m^2)\n", pq, pq2nits(pq / dv_pq_div));
1279 pq = 2055 + 65 * (x[2] >> 3);
1280 printf(" Target Max PQ v2: %u (%u cd/m^2)\n", pq, (unsigned)pq2nits(pq / dv_pq_div));
1282 double xmin = 0.625;
1283 double xstep = (0.74609375 - xmin) / 31.0;
1284 double ymin = 0.25;
1285 double ystep = (0.37109375 - ymin) / 31.0;
1287 printf(" Unique Rx, Ry: %.8f, %.8f\n",
1288 xmin + xstep * (x[5] >> 3),
1289 ymin + ystep * (x[6] >> 3));
1290 xstep = 0.49609375 / 127.0;
1291 ymin = 0.5;
1292 ystep = (0.99609375 - ymin) / 127.0;
1293 printf(" Unique Gx, Gy: %.8f, %.8f\n",
1294 xstep * (x[3] >> 1), ymin + ystep * (x[4] >> 1));
1295 xmin = 0.125;
1296 xstep = (0.15234375 - xmin) / 7.0;
1297 ymin = 0.03125;
1298 ystep = (0.05859375 - ymin) / 7.0;
1299 printf(" Unique Bx, By: %.8f, %.8f\n",
1300 xmin + xstep * (x[5] & 0x07),
1301 ymin + ystep * (x[6] & 0x07));
1305 static void cta_dolby_audio(const unsigned char *x, unsigned length)
1307 unsigned char version = 1 + (x[0] & 0x07);
1309 printf(" Version: %u (%u bytes)\n", version, length + 5);
1310 if (x[0] & 0x80)
1311 printf(" Headphone playback only\n");
1312 if (x[0] & 0x40)
1313 printf(" Height speaker zone present\n");
1314 if (x[0] & 0x20)
1315 printf(" Surround speaker zone present\n");
1316 if (x[0] & 0x10)
1317 printf(" Center speaker zone present\n");
1318 if (x[1] & 0x01)
1319 printf(" Supports Dolby MAT PCM decoding at 48 kHz only, does not support TrueHD\n");
1322 static const char *speaker_map[] = {
1323 "FL/FR - Front Left/Right",
1324 "LFE1 - Low Frequency Effects 1",
1325 "FC - Front Center",
1326 "BL/BR - Back Left/Right",
1327 "BC - Back Center",
1328 "FLc/FRc - Front Left/Right of Center",
1329 "RLC/RRC - Rear Left/Right of Center (Deprecated)",
1330 "FLw/FRw - Front Left/Right Wide",
1331 "TpFL/TpFR - Top Front Left/Right",
1332 "TpC - Top Center",
1333 "TpFC - Top Front Center",
1334 "LS/RS - Left/Right Surround",
1335 "LFE2 - Low Frequency Effects 2",
1336 "TpBC - Top Back Center",
1337 "SiL/SiR - Side Left/Right",
1338 "TpSiL/TpSiR - Top Side Left/Right",
1339 "TpBL/TpBR - Top Back Left/Right",
1340 "BtFC - Bottom Front Center",
1341 "BtFL/BtFR - Bottom Front Left/Right",
1342 "TpLS/TpRS - Top Left/Right Surround (Deprecated for CTA-861)",
1343 "LSd/RSd - Left/Right Surround Direct (HDMI only)",
1346 static void cta_sadb(const unsigned char *x, unsigned length)
1348 unsigned sad;
1349 unsigned i;
1351 if (length < 3) {
1352 fail("Empty Data Block with length %u.\n", length);
1353 return;
1356 sad = ((x[2] << 16) | (x[1] << 8) | x[0]);
1358 for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
1359 if ((sad >> i) & 1)
1360 printf(" %s\n", speaker_map[i]);
1364 static void cta_vesa_dtcdb(const unsigned char *x, unsigned length)
1366 if (length != 7 && length != 15 && length != 31) {
1367 fail("Invalid length %u.\n", length);
1368 return;
1371 switch (x[0] >> 6) {
1372 case 0: printf(" White"); break;
1373 case 1: printf(" Red"); break;
1374 case 2: printf(" Green"); break;
1375 case 3: printf(" Blue"); break;
1377 unsigned v = x[0] & 0x3f;
1378 printf(" transfer characteristics: %u", v);
1379 for (unsigned i = 1; i < length; i++)
1380 printf(" %u", v += x[i]);
1381 printf(" 1023\n");
1384 static void cta_vesa_vdddb(const unsigned char *x, unsigned length)
1386 if (length != 30) {
1387 fail("Invalid length %u.\n", length);
1388 return;
1391 printf(" Interface Type: ");
1392 unsigned char v = x[0];
1393 switch (v >> 4) {
1394 case 0: printf("Analog (");
1395 switch (v & 0xf) {
1396 case 0: printf("15HD/VGA"); break;
1397 case 1: printf("VESA NAVI-V (15HD)"); break;
1398 case 2: printf("VESA NAVI-D"); break;
1399 default: printf("Reserved"); break;
1401 printf(")\n");
1402 break;
1403 case 1: printf("LVDS %u lanes", v & 0xf); break;
1404 case 2: printf("RSDS %u lanes", v & 0xf); break;
1405 case 3: printf("DVI-D %u channels", v & 0xf); break;
1406 case 4: printf("DVI-I analog"); break;
1407 case 5: printf("DVI-I digital %u channels", v & 0xf); break;
1408 case 6: printf("HDMI-A"); break;
1409 case 7: printf("HDMI-B"); break;
1410 case 8: printf("MDDI %u channels", v & 0xf); break;
1411 case 9: printf("DisplayPort %u channels", v & 0xf); break;
1412 case 10: printf("IEEE-1394"); break;
1413 case 11: printf("M1 analog"); break;
1414 case 12: printf("M1 digital %u channels", v & 0xf); break;
1415 default: printf("Reserved"); break;
1417 printf("\n");
1419 printf(" Interface Standard Version: %u.%u\n", x[1] >> 4, x[1] & 0xf);
1420 printf(" Content Protection Support: ");
1421 switch (x[2]) {
1422 case 0: printf("None\n"); break;
1423 case 1: printf("HDCP\n"); break;
1424 case 2: printf("DTCP\n"); break;
1425 case 3: printf("DPCP\n"); break;
1426 default: printf("Reserved\n"); break;
1429 printf(" Minimum Clock Frequency: %u MHz\n", x[3] >> 2);
1430 printf(" Maximum Clock Frequency: %u MHz\n", ((x[3] & 0x03) << 8) | x[4]);
1431 printf(" Device Native Pixel Format: %ux%u\n",
1432 x[5] | (x[6] << 8), x[7] | (x[8] << 8));
1433 printf(" Aspect Ratio: %.2f\n", (100 + x[9]) / 100.0);
1434 v = x[0x0a];
1435 printf(" Default Orientation: ");
1436 switch ((v & 0xc0) >> 6) {
1437 case 0x00: printf("Landscape\n"); break;
1438 case 0x01: printf("Portrait\n"); break;
1439 case 0x02: printf("Not Fixed\n"); break;
1440 case 0x03: printf("Undefined\n"); break;
1442 printf(" Rotation Capability: ");
1443 switch ((v & 0x30) >> 4) {
1444 case 0x00: printf("None\n"); break;
1445 case 0x01: printf("Can rotate 90 degrees clockwise\n"); break;
1446 case 0x02: printf("Can rotate 90 degrees counterclockwise\n"); break;
1447 case 0x03: printf("Can rotate 90 degrees in either direction)\n"); break;
1449 printf(" Zero Pixel Location: ");
1450 switch ((v & 0x0c) >> 2) {
1451 case 0x00: printf("Upper Left\n"); break;
1452 case 0x01: printf("Upper Right\n"); break;
1453 case 0x02: printf("Lower Left\n"); break;
1454 case 0x03: printf("Lower Right\n"); break;
1456 printf(" Scan Direction: ");
1457 switch (v & 0x03) {
1458 case 0x00: printf("Not defined\n"); break;
1459 case 0x01: printf("Fast Scan is on the Major (Long) Axis and Slow Scan is on the Minor Axis\n"); break;
1460 case 0x02: printf("Fast Scan is on the Minor (Short) Axis and Slow Scan is on the Major Axis\n"); break;
1461 case 0x03: printf("Reserved\n");
1462 fail("Scan Direction used the reserved value 0x03.\n");
1463 break;
1465 printf(" Subpixel Information: ");
1466 switch (x[0x0b]) {
1467 case 0x00: printf("Not defined\n"); break;
1468 case 0x01: printf("RGB vertical stripes\n"); break;
1469 case 0x02: printf("RGB horizontal stripes\n"); break;
1470 case 0x03: printf("Vertical stripes using primary order\n"); break;
1471 case 0x04: printf("Horizontal stripes using primary order\n"); break;
1472 case 0x05: printf("Quad sub-pixels, red at top left\n"); break;
1473 case 0x06: printf("Quad sub-pixels, red at bottom left\n"); break;
1474 case 0x07: printf("Delta (triad) RGB sub-pixels\n"); break;
1475 case 0x08: printf("Mosaic\n"); break;
1476 case 0x09: printf("Quad sub-pixels, RGB + 1 additional color\n"); break;
1477 case 0x0a: printf("Five sub-pixels, RGB + 2 additional colors\n"); break;
1478 case 0x0b: printf("Six sub-pixels, RGB + 3 additional colors\n"); break;
1479 case 0x0c: printf("Clairvoyante, Inc. PenTile Matrix (tm) layout\n"); break;
1480 default: printf("Reserved\n"); break;
1482 printf(" Horizontal and vertical dot/pixel pitch: %.2f x %.2f mm\n",
1483 (double)(x[0x0c]) / 100.0, (double)(x[0x0d]) / 100.0);
1484 v = x[0x0e];
1485 printf(" Dithering: ");
1486 switch (v >> 6) {
1487 case 0: printf("None\n"); break;
1488 case 1: printf("Spatial\n"); break;
1489 case 2: printf("Temporal\n"); break;
1490 case 3: printf("Spatial and Temporal\n"); break;
1492 printf(" Direct Drive: %s\n", (v & 0x20) ? "Yes" : "No");
1493 printf(" Overdrive %srecommended\n", (v & 0x10) ? "not " : "");
1494 printf(" Deinterlacing: %s\n", (v & 0x08) ? "Yes" : "No");
1496 v = x[0x0f];
1497 printf(" Audio Support: %s\n", (v & 0x80) ? "Yes" : "No");
1498 printf(" Separate Audio Inputs Provided: %s\n", (v & 0x40) ? "Yes" : "No");
1499 printf(" Audio Input Override: %s\n", (v & 0x20) ? "Yes" : "No");
1500 v = x[0x10];
1501 if (v)
1502 printf(" Audio Delay: %s%u ms\n", (v & 0x80) ? "" : "-", (v & 0x7f) * 2);
1503 else
1504 printf(" Audio Delay: no information provided\n");
1505 v = x[0x11];
1506 printf(" Frame Rate/Mode Conversion: ");
1507 switch (v >> 6) {
1508 case 0: printf("None\n"); break;
1509 case 1: printf("Single Buffering\n"); break;
1510 case 2: printf("Double Buffering\n"); break;
1511 case 3: printf("Advanced Frame Rate Conversion\n"); break;
1513 if (v & 0x3f)
1514 printf(" Frame Rate Range: %u fps +/- %u fps\n",
1515 x[0x12], v & 0x3f);
1516 else
1517 printf(" Nominal Frame Rate: %u fps\n", x[0x12]);
1518 printf(" Color Bit Depth: %u @ interface, %u @ display\n",
1519 (x[0x13] >> 4) + 1, (x[0x13] & 0xf) + 1);
1520 v = x[0x15] & 3;
1521 if (v) {
1522 printf(" Additional Primary Chromaticities:\n");
1523 unsigned col_x = (x[0x16] << 2) | (x[0x14] >> 6);
1524 unsigned col_y = (x[0x17] << 2) | ((x[0x14] >> 4) & 3);
1525 printf(" Primary 4: 0.%04u, 0.%04u\n",
1526 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1527 if (v > 1) {
1528 col_x = (x[0x18] << 2) | ((x[0x14] >> 2) & 3);
1529 col_y = (x[0x19] << 2) | (x[0x14] & 3);
1530 printf(" Primary 5: 0.%04u, 0.%04u\n",
1531 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1532 if (v > 2) {
1533 col_x = (x[0x1a] << 2) | (x[0x15] >> 6);
1534 col_y = (x[0x1b] << 2) | ((x[0x15] >> 4) & 3);
1535 printf(" Primary 6: 0.%04u, 0.%04u\n",
1536 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1541 v = x[0x1c];
1542 printf(" Response Time %s: %u ms\n",
1543 (v & 0x80) ? "White -> Black" : "Black -> White", v & 0x7f);
1544 v = x[0x1d];
1545 printf(" Overscan: %u%% x %u%%\n", v >> 4, v & 0xf);
1548 static double decode_uchar_as_double(unsigned char x)
1550 signed char s = (signed char)x;
1552 return s / 64.0;
1555 void edid_state::cta_rcdb(const unsigned char *x, unsigned length)
1557 unsigned spm = ((x[3] << 16) | (x[2] << 8) | x[1]);
1558 unsigned i;
1560 if (length < 4) {
1561 fail("Empty Data Block with length %u.\n", length);
1562 return;
1565 if ((x[0] & 0x20) && !cta.has_sldb)
1566 fail("'SLD' flag is 1, but no Speaker Location Data Block is found.\n");
1567 else if (!(x[0] & 0x20) && cta.has_sldb)
1568 fail("'SLD' flag is 0, but a Speaker Location Data Block is present.\n");
1570 if (x[0] & 0x40) {
1571 printf(" Speaker count: %u\n", (x[0] & 0x1f) + 1);
1572 } else {
1573 if (x[0] & 0x1f)
1574 fail("'Speaker' flag is 0, but 'Speaker Count' is != 0.\n");
1575 if (x[0] & 0x20)
1576 fail("'SLD' flag is 1, but 'Speaker' is 0.\n");
1579 printf(" Speaker Presence Mask:\n");
1580 for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
1581 if ((spm >> i) & 1)
1582 printf(" %s\n", speaker_map[i]);
1585 if ((x[0] & 0xa0) == 0x80)
1586 fail("'Display' flag set, but not the 'SLD' flag.\n");
1588 bool valid_max = cta.preparsed_sld_has_coord || (x[0] & 0x80);
1590 if (valid_max && length >= 7) {
1591 printf(" Xmax: %u dm\n", x[4]);
1592 printf(" Ymax: %u dm\n", x[5]);
1593 printf(" Zmax: %u dm\n", x[6]);
1594 } else if (!valid_max && length >= 7) {
1595 // The RCDB should have been truncated.
1596 warn("'Display' flag is 0 and 'Coord' is 0 for all SLDs, but the Max coordinates are still present.\n");
1598 if ((x[0] & 0x80) && length >= 10) {
1599 printf(" DisplayX: %.3f * Xmax\n", decode_uchar_as_double(x[7]));
1600 printf(" DisplayY: %.3f * Ymax\n", decode_uchar_as_double(x[8]));
1601 printf(" DisplayZ: %.3f * Zmax\n", decode_uchar_as_double(x[9]));
1602 } else if (!(x[0] & 0x80) && length >= 10) {
1603 // The RCDB should have been truncated.
1604 warn("'Display' flag is 0, but the Display coordinates are still present.\n");
1608 static const char *speaker_location[] = {
1609 "FL - Front Left",
1610 "FR - Front Right",
1611 "FC - Front Center",
1612 "LFE1 - Low Frequency Effects 1",
1613 "BL - Back Left",
1614 "BR - Back Right",
1615 "FLC - Front Left of Center",
1616 "FRC - Front Right of Center",
1617 "BC - Back Center",
1618 "LFE2 - Low Frequency Effects 2",
1619 "SiL - Side Left",
1620 "SiR - Side Right",
1621 "TpFL - Top Front Left",
1622 "TpFR - Top Front Right",
1623 "TpFC - Top Front Center",
1624 "TpC - Top Center",
1625 "TpBL - Top Back Left",
1626 "TpBR - Top Back Right",
1627 "TpSiL - Top Side Left",
1628 "TpSiR - Top Side Right",
1629 "TpBC - Top Back Center",
1630 "BtFC - Bottom Front Center",
1631 "BtFL - Bottom Front Left",
1632 "BtFR - Bottom Front Right",
1633 "FLW - Front Left Wide",
1634 "FRW - Front Right Wide",
1635 "LS - Left Surround",
1636 "RS - Right Surround",
1639 void edid_state::cta_sldb(const unsigned char *x, unsigned length)
1641 if (length < 2) {
1642 fail("Empty Data Block with length %u.\n", length);
1643 return;
1646 unsigned active_cnt = 0;
1647 unsigned channel_is_active = 0;
1649 while (length >= 2) {
1650 printf(" Channel: %u (%sactive)\n", x[0] & 0x1f,
1651 (x[0] & 0x20) ? "" : "not ");
1652 if (x[0] & 0x20) {
1653 if (channel_is_active & (1U << (x[0] & 0x1f)))
1654 fail("Channel Index %u was already marked 'Active'.\n",
1655 x[0] & 0x1f);
1656 channel_is_active |= 1U << (x[0] & 0x1f);
1657 active_cnt++;
1659 if ((x[1] & 0x1f) < ARRAY_SIZE(speaker_location))
1660 printf(" Speaker: %s\n", speaker_location[x[1] & 0x1f]);
1661 if (length >= 5 && (x[0] & 0x40)) {
1662 printf(" X: %.3f * Xmax\n", decode_uchar_as_double(x[2]));
1663 printf(" Y: %.3f * Ymax\n", decode_uchar_as_double(x[3]));
1664 printf(" Z: %.3f * Zmax\n", decode_uchar_as_double(x[4]));
1665 length -= 3;
1666 x += 3;
1669 length -= 2;
1670 x += 2;
1672 if (active_cnt != cta.preparsed_speaker_count)
1673 fail("There are %u active speakers, but 'Speaker Count' is %u.\n",
1674 active_cnt, cta.preparsed_speaker_count);
1677 void edid_state::cta_preparse_sldb(const unsigned char *x, unsigned length)
1679 cta.has_sldb = true;
1680 while (length >= 2) {
1681 if (length >= 5 && (x[0] & 0x40)) {
1682 cta.preparsed_sld_has_coord = true;
1683 return;
1685 length -= 2;
1686 x += 2;
1690 void edid_state::cta_vcdb(const unsigned char *x, unsigned length)
1692 unsigned char d = x[0];
1694 cta.has_vcdb = true;
1695 if (length < 1) {
1696 fail("Empty Data Block with length %u.\n", length);
1697 return;
1699 printf(" YCbCr quantization: %s\n",
1700 (d & 0x80) ? "Selectable (via AVI YQ)" : "No Data");
1701 printf(" RGB quantization: %s\n",
1702 (d & 0x40) ? "Selectable (via AVI Q)" : "No Data");
1704 * If this bit is not set then that will result in interoperability
1705 * problems (specifically with PCs/laptops) that quite often do not
1706 * follow the default rules with respect to RGB Quantization Range
1707 * handling.
1709 * Starting with the CTA-861-H spec this bit is now required to be
1710 * 1 for new designs.
1712 if (!(d & 0x40))
1713 fail("Set Selectable RGB Quantization to avoid interop issues.\n");
1715 * Since most YCbCr formats use limited range, the interop issues are
1716 * less noticable than for RGB formats.
1718 * Starting with the CTA-861-H spec this bit is now required to be
1719 * 1 for new designs, but just warn about it (for now).
1721 if ((cta.byte3 & 0x30) && !(d & 0x80))
1722 warn("Set Selectable YCbCr Quantization to avoid interop issues.\n");
1724 unsigned char s_pt = (d >> 4) & 0x03;
1725 unsigned char s_it = (d >> 2) & 0x03;
1726 unsigned char s_ce = d & 0x03;
1728 printf(" PT scan behavior: ");
1729 switch (s_pt) {
1730 case 0: printf("No Data\n"); break;
1731 case 1: printf("Always Overscanned\n"); break;
1732 case 2: printf("Always Underscanned\n"); break;
1733 case 3: printf("Supports both over- and underscan\n"); break;
1735 printf(" IT scan behavior: ");
1736 switch (s_it) {
1737 case 0: printf("IT video formats not supported\n"); break;
1738 case 1:
1739 printf("Always Overscanned\n");
1740 // See Table 52 of CTA-861-G for a description of Byte 3
1741 if (cta.byte3 & 0x80)
1742 fail("IT video formats are always overscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to underscanned.\n");
1743 break;
1744 case 2:
1745 printf("Always Underscanned\n");
1746 // See Table 52 of CTA-861-G for a description of Byte 3
1747 if (!(cta.byte3 & 0x80))
1748 fail("IT video formats are always underscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to overscanned.\n");
1749 break;
1750 case 3: printf("Supports both over- and underscan\n"); break;
1752 if (s_it < 2)
1753 warn("IT scan behavior is expected to support underscanned.\n");
1754 printf(" CE scan behavior: ");
1755 switch (s_ce) {
1756 case 0: printf("CE video formats not supported\n"); break;
1757 case 1: printf("Always Overscanned\n"); break;
1758 case 2: printf("Always Underscanned\n"); break;
1759 case 3: printf("Supports both over- and underscan\n"); break;
1761 if (s_ce == 0)
1762 warn("'CE video formats not supported' makes no sense.\n");
1763 else if (s_pt == s_it && s_pt == s_ce)
1764 warn("S_PT is equal to S_IT and S_CE, so should be set to 0 instead.\n");
1767 static const char *colorimetry_map[] = {
1768 "xvYCC601",
1769 "xvYCC709",
1770 "sYCC601",
1771 "opYCC601",
1772 "opRGB",
1773 "BT2020cYCC",
1774 "BT2020YCC",
1775 "BT2020RGB",
1778 static void cta_colorimetry_block(const unsigned char *x, unsigned length)
1780 unsigned i;
1782 if (length < 2) {
1783 fail("Empty Data Block with length %u.\n", length);
1784 return;
1786 for (i = 0; i < ARRAY_SIZE(colorimetry_map); i++) {
1787 if (x[0] & (1 << i))
1788 printf(" %s\n", colorimetry_map[i]);
1790 if (x[1] & 0x80)
1791 printf(" DCI-P3\n");
1792 if (x[1] & 0x40)
1793 printf(" ICtCp\n");
1796 static const char *eotf_map[] = {
1797 "Traditional gamma - SDR luminance range",
1798 "Traditional gamma - HDR luminance range",
1799 "SMPTE ST2084",
1800 "Hybrid Log-Gamma",
1803 static void cta_hdr_static_metadata_block(const unsigned char *x, unsigned length)
1805 unsigned i;
1807 if (length < 2) {
1808 fail("Empty Data Block with length %u.\n", length);
1809 return;
1811 printf(" Electro optical transfer functions:\n");
1812 for (i = 0; i < 6; i++) {
1813 if (x[0] & (1 << i)) {
1814 if (i < ARRAY_SIZE(eotf_map)) {
1815 printf(" %s\n", eotf_map[i]);
1816 } else {
1817 printf(" Unknown (%u)\n", i);
1818 fail("Unknown EOTF (%u).\n", i);
1822 printf(" Supported static metadata descriptors:\n");
1823 for (i = 0; i < 8; i++) {
1824 if (x[1] & (1 << i))
1825 printf(" Static metadata type %u\n", i + 1);
1828 if (length >= 3)
1829 printf(" Desired content max luminance: %u (%.3f cd/m^2)\n",
1830 x[2], 50.0 * pow(2, x[2] / 32.0));
1832 if (length >= 4)
1833 printf(" Desired content max frame-average luminance: %u (%.3f cd/m^2)\n",
1834 x[3], 50.0 * pow(2, x[3] / 32.0));
1836 if (length >= 5)
1837 printf(" Desired content min luminance: %u (%.3f cd/m^2)\n",
1838 x[4], (50.0 * pow(2, x[2] / 32.0)) * pow(x[4] / 255.0, 2) / 100.0);
1841 static void cta_hdr_dyn_metadata_block(const unsigned char *x, unsigned length)
1843 if (length < 3) {
1844 fail("Empty Data Block with length %u.\n", length);
1845 return;
1847 while (length >= 3) {
1848 unsigned type_len = x[0];
1849 unsigned type = x[1] | (x[2] << 8);
1851 if (length < type_len + 1)
1852 return;
1853 printf(" HDR Dynamic Metadata Type %u\n", type);
1854 switch (type) {
1855 case 1:
1856 case 4:
1857 if (type_len > 2)
1858 printf(" Version: %u\n", x[3] & 0xf);
1859 break;
1860 case 2:
1861 if (type_len > 2) {
1862 unsigned version = x[3] & 0xf;
1863 printf(" Version: %u\n", version);
1864 if (version >= 1) {
1865 if (x[3] & 0x10) printf(" Supports SL-HDR1 (ETSI TS 103 433-1)\n");
1866 if (x[3] & 0x20) printf(" Supports SL-HDR2 (ETSI TS 103 433-2)\n");
1867 if (x[3] & 0x40) printf(" Supports SL-HDR3 (ETSI TS 103 433-3)\n");
1870 break;
1871 default:
1872 break;
1874 length -= type_len + 1;
1875 x += type_len + 1;
1879 static void cta_ifdb(const unsigned char *x, unsigned length)
1881 unsigned len_hdr = x[0] >> 5;
1883 if (length < 2) {
1884 fail("Empty Data Block with length %u.\n", length);
1885 return;
1887 printf(" VSIFs: %u\n", x[1]);
1888 if (length < len_hdr + 2)
1889 return;
1890 length -= len_hdr + 2;
1891 x += len_hdr + 2;
1892 while (length > 0) {
1893 int payload_len = x[0] >> 5;
1895 if ((x[0] & 0x1f) == 1 && length >= 4) {
1896 unsigned oui = (x[3] << 16) | (x[2] << 8) | x[1];
1898 printf(" InfoFrame Type Code %u, OUI %s\n",
1899 x[0] & 0x1f, ouitohex(oui).c_str());
1900 x += 4;
1901 length -= 4;
1902 } else {
1903 printf(" InfoFrame Type Code %u\n", x[0] & 0x1f);
1904 x++;
1905 length--;
1907 x += payload_len;
1908 length -= payload_len;
1912 void edid_state::cta_displayid_type_7(const unsigned char *x, unsigned length)
1914 check_displayid_datablock_revision(x[0], 0x00, 2);
1916 if (length < 21U + ((x[0] & 0x70) >> 4)) {
1917 fail("Empty Data Block with length %u.\n", length);
1918 return;
1920 parse_displayid_type_1_7_timing(x + 1, true, 2, true);
1923 void edid_state::cta_displayid_type_8(const unsigned char *x, unsigned length)
1925 check_displayid_datablock_revision(x[0], 0xe8, 1);
1926 if (length < ((x[0] & 0x08) ? 3 : 2)) {
1927 fail("Empty Data Block with length %u.\n", length);
1928 return;
1931 unsigned sz = (x[0] & 0x08) ? 2 : 1;
1932 unsigned type = x[0] >> 6;
1934 if (type) {
1935 fail("Only code type 0 is supported.\n");
1936 return;
1939 if (x[0] & 0x20)
1940 printf(" Also supports YCbCr 4:2:0\n");
1942 x++;
1943 length--;
1944 for (unsigned i = 0; i < length / sz; i++) {
1945 unsigned id = x[i * sz];
1947 if (sz == 2)
1948 id |= x[i * sz + 1] << 8;
1949 parse_displayid_type_4_8_timing(type, id, true);
1953 void edid_state::cta_displayid_type_10(const unsigned char *x, unsigned length)
1955 check_displayid_datablock_revision(x[0], 0x70);
1956 if (length < 7U + ((x[0] & 0x70) >> 4)) {
1957 fail("Empty Data Block with length %u.\n", length);
1958 return;
1961 unsigned sz = 6U + ((x[0] & 0x70) >> 4);
1962 x++;
1963 length--;
1964 for (unsigned i = 0; i < length / sz; i++)
1965 parse_displayid_type_10_timing(x + i * sz, sz, true);
1968 static void cta_hdmi_audio_block(const unsigned char *x, unsigned length)
1970 unsigned num_descs;
1972 if (length < 2) {
1973 fail("Empty Data Block with length %u.\n", length);
1974 return;
1976 if (x[0] & 3)
1977 printf(" Max Stream Count: %u\n", (x[0] & 3) + 1);
1978 if (x[0] & 4)
1979 printf(" Supports MS NonMixed\n");
1981 num_descs = x[1] & 7;
1982 if (num_descs == 0)
1983 return;
1984 length -= 2;
1985 x += 2;
1986 while (length >= 4) {
1987 if (length > 4) {
1988 unsigned format = x[0] & 0xf;
1990 printf(" %s, max channels %u\n", audio_format(format).c_str(),
1991 (x[1] & 0x1f)+1);
1992 printf(" Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
1993 (x[2] & 0x40) ? " 192" : "",
1994 (x[2] & 0x20) ? " 176.4" : "",
1995 (x[2] & 0x10) ? " 96" : "",
1996 (x[2] & 0x08) ? " 88.2" : "",
1997 (x[2] & 0x04) ? " 48" : "",
1998 (x[2] & 0x02) ? " 44.1" : "",
1999 (x[2] & 0x01) ? " 32" : "");
2000 if (format == 1)
2001 printf(" Supported sample sizes (bits):%s%s%s\n",
2002 (x[3] & 0x04) ? " 24" : "",
2003 (x[3] & 0x02) ? " 20" : "",
2004 (x[3] & 0x01) ? " 16" : "");
2005 } else {
2006 unsigned sad = ((x[2] << 16) | (x[1] << 8) | x[0]);
2007 unsigned i;
2009 switch (x[3] >> 4) {
2010 case 1:
2011 printf(" Speaker Allocation for 10.2 channels:\n");
2012 break;
2013 case 2:
2014 printf(" Speaker Allocation for 22.2 channels:\n");
2015 break;
2016 case 3:
2017 printf(" Speaker Allocation for 30.2 channels:\n");
2018 break;
2019 default:
2020 printf(" Unknown Speaker Allocation (0x%02x)\n", x[3] >> 4);
2021 return;
2024 for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
2025 if ((sad >> i) & 1)
2026 printf(" %s\n", speaker_map[i]);
2029 length -= 4;
2030 x += 4;
2034 void edid_state::cta_block(const unsigned char *x, std::vector<unsigned> &found_tags)
2036 unsigned length = x[0] & 0x1f;
2037 unsigned tag = (x[0] & 0xe0) >> 5;
2038 unsigned extended = (tag == 0x07) ? 1 : 0;
2040 x++;
2041 if (extended && length) {
2042 tag <<= 8;
2043 tag |= x[0];
2044 length--;
2045 x++;
2048 bool dooutputname = true;
2049 bool audio_block = false;
2050 data_block.clear();
2052 switch (tag) {
2053 case 0x01: data_block = "Audio Data Block"; audio_block = true; break;
2054 case 0x02: data_block = "Video Data Block"; break;
2055 case 0x03: data_block = "Vendor-Specific Data Block"; break;
2056 case 0x04: data_block = "Speaker Allocation Data Block"; audio_block = true; break;
2057 case 0x05: data_block = "VESA Display Transfer Characteristics Data Block"; break;
2059 case 0x07: data_block = "Unknown CTA-861 Data Block (extended tag truncated)"; break;
2061 case 0x700: data_block = "Video Capability Data Block"; break;
2062 case 0x701: data_block = "Vendor-Specific Video Data Block"; break;
2063 case 0x702: data_block = "VESA Video Display Device Data Block"; break;
2064 case 0x703: data_block = "VESA Video Timing Block Extension"; break;
2065 case 0x704: data_block = "Reserved for HDMI Video Data Block"; break;
2066 case 0x705: data_block = "Colorimetry Data Block"; break;
2067 case 0x706: data_block = "HDR Static Metadata Data Block"; break;
2068 case 0x707: data_block = "HDR Dynamic Metadata Data Block"; break;
2070 case 0x70d: data_block = "Video Format Preference Data Block"; break;
2071 case 0x70e: data_block = "YCbCr 4:2:0 Video Data Block"; break;
2072 case 0x70f: data_block = "YCbCr 4:2:0 Capability Map Data Block"; break;
2073 case 0x710: data_block = "Reserved for CTA-861 Miscellaneous Audio Fields"; break;
2074 case 0x711: data_block = "Vendor-Specific Audio Data Block"; audio_block = true; break;
2075 case 0x712: data_block = "HDMI Audio Data Block"; audio_block = true; break;
2076 case 0x713: data_block = "Room Configuration Data Block"; audio_block = true; break;
2077 case 0x714: data_block = "Speaker Location Data Block"; audio_block = true; break;
2079 case 0x720: data_block = "InfoFrame Data Block"; break;
2081 case 0x734: data_block = "DisplayID Type VII Video Timing Data Block"; break;
2082 case 0x735: data_block = "DisplayID Type VIII Video Timing Data Block"; break;
2083 case 0x742: data_block = "DisplayID Type X Video Timing Data Block"; break;
2085 case 0x778: data_block = "HDMI Forum EDID Extension Override Data Block"; break;
2086 case 0x779: data_block = "HDMI Forum Sink Capability Data Block"; break;
2088 default:
2089 std::string unknown_name;
2090 if (tag < 0x700) unknown_name = "Unknown CTA-861 Data Block";
2091 else if (tag < 0x70d) unknown_name = "Unknown CTA-861 Video-Related Data Block";
2092 else if (tag < 0x720) unknown_name = "Unknown CTA-861 Audio-Related Data Block";
2093 else if (tag < 0x778) unknown_name = "Unknown CTA-861 Data Block";
2094 else if (tag < 0x780) unknown_name = "Unknown CTA-861 HDMI-Related Data Block";
2095 else unknown_name = "Unknown CTA-861 Data Block";
2096 unknown_name += std::string(" (") + (extended ? "extended " : "") + "tag " + utohex(tag & 0xff) + ", length " + std::to_string(length) + ")";
2097 printf(" %s:\n", unknown_name.c_str());
2098 warn("%s.\n", unknown_name.c_str());
2099 break;
2102 switch (tag) {
2103 case 0x03:
2104 case 0x701:
2105 case 0x711: {
2106 unsigned ouinum;
2108 data_block_oui(data_block, x, length, &ouinum);
2109 x += (length < 3) ? length : 3;
2110 length -= (length < 3) ? length : 3;
2111 dooutputname = false;
2112 tag |= ouinum;
2113 break;
2117 if (dooutputname && data_block.length())
2118 printf(" %s:\n", data_block.c_str());
2120 switch (tag) {
2121 case 0x04:
2122 case 0x05:
2123 case 0x700:
2124 case 0x702:
2125 case 0x705:
2126 case 0x706:
2127 case 0x70d:
2128 case 0x70f:
2129 case 0x712:
2130 case 0x713:
2131 case 0x778:
2132 case 0x779:
2133 if (std::find(found_tags.begin(), found_tags.end(), tag) != found_tags.end())
2134 fail("Only one instance of this Data Block is allowed.\n");
2135 break;
2138 // See Table 52 of CTA-861-G for a description of Byte 3
2139 if (audio_block && !(cta.byte3 & 0x40))
2140 fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
2142 switch (tag) {
2143 case 0x01: cta_audio_block(x, length); break;
2144 case 0x02: cta_svd(x, length, false); break;
2145 case 0x03|kOUI_HDMI:
2146 cta_hdmi_block(x, length);
2147 // The HDMI OUI is present, so this EDID represents an HDMI
2148 // interface. And HDMI interfaces must use EDID version 1.3
2149 // according to the HDMI Specification, so check for this.
2150 if (base.edid_minor != 3)
2151 fail("The HDMI Specification requires EDID 1.3 instead of 1.%u.\n",
2152 base.edid_minor);
2153 break;
2154 case 0x03|kOUI_HDMIForum:
2155 if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
2156 fail("HDMI Forum VSDB did not immediately follow the HDMI VSDB.\n");
2157 if (cta.have_hf_scdb || cta.have_hf_vsdb)
2158 fail("Duplicate HDMI Forum VSDB/SCDB.\n");
2159 cta_hf_scdb(x, length);
2160 cta.have_hf_vsdb = true;
2161 break;
2162 case 0x03|kOUI_AMD: cta_amd(x, length); break;
2163 case 0x03|kOUI_Microsoft: if (length != 0x12) goto dodefault; cta_microsoft(x, length); break;
2164 case 0x04: cta_sadb(x, length); break;
2165 case 0x05: cta_vesa_dtcdb(x, length); break;
2166 case 0x07: fail("Extended tag cannot have zero length.\n"); break;
2167 case 0x700: cta_vcdb(x, length); break;
2168 case 0x701|kOUI_HDR10: cta_hdr10plus(x, length); break;
2169 case 0x701|kOUI_Dolby: cta_dolby_video(x, length); break;
2170 case 0x702: cta_vesa_vdddb(x, length); break;
2171 case 0x705: cta_colorimetry_block(x, length); break;
2172 case 0x706: cta_hdr_static_metadata_block(x, length); break;
2173 case 0x707: cta_hdr_dyn_metadata_block(x, length); break;
2174 case 0x70d: cta_vfpdb(x, length); break;
2175 case 0x70e: cta_svd(x, length, true); break;
2176 case 0x70f: cta_y420cmdb(x, length); break;
2177 case 0x711|kOUI_Dolby: cta_dolby_audio(x, length); break;
2178 case 0x712: cta_hdmi_audio_block(x, length); break;
2179 case 0x713: cta_rcdb(x, length); break;
2180 case 0x714: cta_sldb(x, length); break;
2181 case 0x720: cta_ifdb(x, length); break;
2182 case 0x734: cta_displayid_type_7(x, length); break;
2183 case 0x735: cta_displayid_type_8(x, length); break;
2184 case 0x742: cta_displayid_type_10(x, length); break;
2185 case 0x778:
2186 cta_hf_eeodb(x, length);
2187 // This must be the first CTA-861 block
2188 if (cta.block_number > 0)
2189 fail("Block starts at a wrong offset.\n");
2190 break;
2191 case 0x779:
2192 if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
2193 fail("HDMI Forum SCDB did not immediately follow the HDMI VSDB.\n");
2194 if (cta.have_hf_scdb || cta.have_hf_vsdb)
2195 fail("Duplicate HDMI Forum VSDB/SCDB.\n");
2196 if (length < 2) {
2197 data_block = std::string("HDMI Forum SCDB");
2198 fail("Invalid length %u < 2.\n", length);
2199 break;
2201 if (x[0] || x[1])
2202 printf(" Non-zero SCDB reserved fields!\n");
2203 cta_hf_scdb(x + 2, length - 2);
2204 cta.have_hf_scdb = true;
2205 break;
2206 dodefault:
2207 default:
2208 hex_block(" ", x, length);
2209 break;
2212 cta.block_number++;
2213 cta.previous_cta_tag = tag;
2214 found_tags.push_back(tag);
2217 void edid_state::preparse_cta_block(const unsigned char *x)
2219 unsigned version = x[1];
2220 unsigned offset = x[2];
2222 if (offset >= 4) {
2223 const unsigned char *detailed;
2225 for (detailed = x + offset; detailed + 17 < x + 127; detailed += 18) {
2226 if (memchk(detailed, 18))
2227 break;
2228 if (detailed[0] || detailed[1])
2229 cta.preparsed_total_dtds++;
2233 if (version < 3)
2234 return;
2236 for (unsigned i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
2237 bool for_ycbcr420 = false;
2238 unsigned oui;
2240 switch ((x[i] & 0xe0) >> 5) {
2241 case 0x03:
2242 oui = (x[i + 3] << 16) + (x[i + 2] << 8) + x[i + 1];
2243 if (oui == 0x000c03) {
2244 cta.has_hdmi = true;
2245 cta.preparsed_phys_addr = (x[i + 4] << 8) | x[i + 5];
2247 break;
2248 case 0x07:
2249 if (x[i + 1] == 0x0d)
2250 cta.has_vfpdb = true;
2251 if (x[i + 1] == 0x13 && (x[i + 2] & 0x40)) {
2252 cta.preparsed_speaker_count = 1 + (x[i + 2] & 0x1f);
2253 cta.preparsed_sld = x[i + 2] & 0x20;
2255 if (x[i + 1] == 0x14)
2256 cta_preparse_sldb(x + i + 2, (x[i] & 0x1f) - 1);
2257 if (x[i + 1] == 0x22)
2258 cta.preparsed_total_vtdbs++;
2259 if (x[i + 1] == 0x23)
2260 cta.preparsed_has_t8vtdb = true;
2261 if (x[i + 1] == 0x32)
2262 cta.preparsed_total_vtdbs +=
2263 ((x[i] & 0x1f) - 2) / (6 + ((x[i + 2] & 0x70) >> 4));
2264 if (x[i + 1] != 0x0e)
2265 continue;
2266 for_ycbcr420 = true;
2267 /* fall-through */
2268 case 0x02:
2269 for (unsigned j = 1 + for_ycbcr420; j <= (x[i] & 0x1f); j++) {
2270 unsigned char vic = x[i + j];
2272 if ((vic & 0x7f) <= 64)
2273 vic &= 0x7f;
2274 cta.preparsed_svds[for_ycbcr420].push_back(vic);
2275 cta.preparsed_has_vic[for_ycbcr420][vic] = true;
2277 break;
2282 void edid_state::parse_cta_block(const unsigned char *x)
2284 unsigned version = x[1];
2285 unsigned offset = x[2];
2286 const unsigned char *detailed;
2288 // See Table 52 of CTA-861-G for a description of Byte 3
2290 printf(" Revision: %u\n", version);
2291 if (version == 0)
2292 fail("Invalid CTA-861 Extension revision 0.\n");
2293 if (version == 2)
2294 fail("Deprecated CTA-861 Extension revision 2.\n");
2295 if (cta.has_hdmi && version != 3)
2296 fail("The HDMI Specification requires CTA Extension revision 3.\n");
2297 if (version > 3)
2298 warn("Unknown CTA-861 Extension revision %u.\n", version);
2300 if (version >= 1) do {
2301 if (version == 1 && x[3] != 0)
2302 fail("Non-zero byte 3.\n");
2304 if (offset < 4)
2305 break;
2307 if (version < 3 && ((offset - 4) / 8)) {
2308 printf(" 8-byte timing descriptors: %u\n", (offset - 4) / 8);
2309 fail("8-byte descriptors were never used.\n");
2312 if (version >= 2) {
2313 if (x[3] & 0x80)
2314 printf(" Underscans IT Video Formats by default\n");
2315 else
2316 warn("IT Video Formats are overscanned by default, but normally this should be underscanned.\n");
2317 if (x[3] & 0x40)
2318 printf(" Basic audio support\n");
2319 if (x[3] & 0x20)
2320 printf(" Supports YCbCr 4:4:4\n");
2321 if (x[3] & 0x10)
2322 printf(" Supports YCbCr 4:2:2\n");
2323 // Disable this test: this fails a lot of EDIDs, and there are
2324 // also some corner cases where you only want to receive 4:4:4
2325 // and refuse a fallback to 4:2:2.
2326 // if ((x[3] & 0x30) && (x[3] & 0x30) != 0x30)
2327 // msg(!cta.has_hdmi, "If YCbCr support is indicated, then both 4:2:2 and 4:4:4 %s be supported.\n",
2328 // cta.has_hdmi ? "shall" : "should");
2329 printf(" Native detailed modes: %u\n", x[3] & 0x0f);
2330 if (cta.block_number == 0)
2331 cta.byte3 = x[3];
2332 else if (x[3] != cta.byte3)
2333 fail("Byte 3 must be the same for all CTA-861 Extension Blocks.\n");
2334 if (cta.block_number == 0) {
2335 unsigned native_dtds = x[3] & 0x0f;
2337 cta.native_timings.clear();
2338 if (!native_dtds && !cta.has_vfpdb) {
2339 cta.first_svd_might_be_preferred = true;
2340 } else if (native_dtds > cta.preparsed_total_dtds) {
2341 fail("There are more Native DTDs (%u) than DTDs (%u).\n",
2342 native_dtds, cta.preparsed_total_dtds);
2344 if (native_dtds > cta.preparsed_total_dtds)
2345 native_dtds = cta.preparsed_total_dtds;
2346 for (unsigned i = 0; i < native_dtds; i++) {
2347 char type[16];
2349 sprintf(type, "DTD %3u", i + 1);
2350 cta.native_timings.push_back(timings_ext(i + 129, type));
2352 if (cta.has_hdmi && block_nr != (block_map.saw_block_1 ? 2 : 1))
2353 fail("The HDMI Specification requires that the first Extension Block (that is not a Block Map) is an CTA-861 Extension Block.\n");
2356 if (version >= 3) {
2357 unsigned i;
2359 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
2360 cta_block(x + i, cta.found_tags);
2363 data_block.clear();
2364 if (i != offset)
2365 fail("Offset is %u, but should be %u.\n", offset, i);
2368 data_block = "Detailed Timing Descriptors";
2369 base.seen_non_detailed_descriptor = false;
2370 bool first = true;
2371 for (detailed = x + offset; detailed + 17 < x + 127; detailed += 18) {
2372 if (memchk(detailed, 18))
2373 break;
2374 if (first) {
2375 first = false;
2376 printf(" %s:\n", data_block.c_str());
2378 detailed_block(detailed);
2380 if (!memchk(detailed, x + 127 - detailed)) {
2381 data_block = "Padding";
2382 fail("CTA-861 padding contains non-zero bytes.\n");
2384 } while (0);
2386 data_block.clear();
2387 if (base.has_serial_number && base.has_serial_string)
2388 warn("Display Product Serial Number is set, so the Serial Number in the Base EDID should be 0.\n");
2389 if (!cta.has_vic_1 && !base.has_640x480p60_est_timing)
2390 fail("Required 640x480p60 timings are missing in the established timings"
2391 " and the SVD list (VIC 1).\n");
2392 if ((cta.supported_hdmi_vic_vsb_codes & cta.supported_hdmi_vic_codes) !=
2393 cta.supported_hdmi_vic_codes)
2394 fail("HDMI VIC Codes must have their CTA-861 VIC equivalents in the VSB.\n");
2395 if (!cta.has_vcdb)
2396 fail("Missing VCDB, needed for Set Selectable RGB Quantization to avoid interop issues.\n");
2399 void edid_state::cta_resolve_svr(vec_timings_ext::iterator iter)
2401 if (iter->svr() == 254) {
2402 iter->flags = cta.t8vtdb.flags;
2403 iter->t = cta.t8vtdb.t;
2404 } else if (iter->svr() <= 144) {
2405 iter->flags = cta.vec_dtds[iter->svr() - 129].flags;
2406 iter->t = cta.vec_dtds[iter->svr() - 129].t;
2407 } else {
2408 iter->flags = cta.vec_vtdbs[iter->svr() - 145].flags;
2409 iter->t = cta.vec_vtdbs[iter->svr() - 145].t;
2413 void edid_state::cta_resolve_svrs()
2415 for (vec_timings_ext::iterator iter = cta.preferred_timings.begin();
2416 iter != cta.preferred_timings.end(); ++iter) {
2417 if (iter->has_svr())
2418 cta_resolve_svr(iter);
2421 for (vec_timings_ext::iterator iter = cta.native_timings.begin();
2422 iter != cta.native_timings.end(); ++iter) {
2423 if (iter->has_svr())
2424 cta_resolve_svr(iter);
2428 void edid_state::check_cta_blocks()
2430 unsigned max_pref_prog_hact = 0;
2431 unsigned max_pref_prog_vact = 0;
2432 unsigned max_pref_ilace_hact = 0;
2433 unsigned max_pref_ilace_vact = 0;
2435 data_block = "CTA-861";
2436 for (vec_timings_ext::iterator iter = cta.preferred_timings.begin();
2437 iter != cta.preferred_timings.end(); ++iter) {
2438 if (iter->t.interlaced &&
2439 (iter->t.vact > max_pref_ilace_vact ||
2440 (iter->t.vact == max_pref_ilace_vact && iter->t.hact >= max_pref_ilace_hact))) {
2441 max_pref_ilace_hact = iter->t.hact;
2442 max_pref_ilace_vact = iter->t.vact;
2444 if (!iter->t.interlaced &&
2445 (iter->t.vact > max_pref_prog_vact ||
2446 (iter->t.vact == max_pref_prog_vact && iter->t.hact >= max_pref_prog_hact))) {
2447 max_pref_prog_hact = iter->t.hact;
2448 max_pref_prog_vact = iter->t.vact;
2452 unsigned native_prog = 0;
2453 unsigned native_prog_hact = 0;
2454 unsigned native_prog_vact = 0;
2455 bool native_prog_mixed_resolutions = false;
2456 unsigned native_ilace = 0;
2457 unsigned native_ilace_hact = 0;
2458 unsigned native_ilace_vact = 0;
2459 bool native_ilace_mixed_resolutions = false;
2461 for (vec_timings_ext::iterator iter = cta.native_timings.begin();
2462 iter != cta.native_timings.end(); ++iter) {
2463 if (iter->t.interlaced) {
2464 native_ilace++;
2465 if (!native_ilace_hact) {
2466 native_ilace_hact = iter->t.hact;
2467 native_ilace_vact = iter->t.vact;
2468 } else if (native_ilace_hact != iter->t.hact ||
2469 native_ilace_vact != iter->t.vact) {
2470 native_ilace_mixed_resolutions = true;
2472 } else {
2473 native_prog++;
2474 if (!native_prog_hact) {
2475 native_prog_hact = iter->t.hact;
2476 native_prog_vact = iter->t.vact;
2477 } else if (native_prog_hact != iter->t.hact ||
2478 native_prog_vact != iter->t.vact) {
2479 native_prog_mixed_resolutions = true;
2484 if (native_prog_mixed_resolutions)
2485 fail("Native progressive timings are a mix of several resolutions.\n");
2486 if (native_ilace_mixed_resolutions)
2487 fail("Native interlaced timings are a mix of several resolutions.\n");
2488 if (native_ilace && !native_prog)
2489 fail("A native interlaced timing is present, but not a native progressive timing.\n");
2490 if (!native_prog_mixed_resolutions && native_prog > 1)
2491 warn("Multiple native progressive timings are defined.\n");
2492 if (!native_ilace_mixed_resolutions && native_ilace > 1)
2493 warn("Multiple native interlaced timings are defined.\n");
2495 if (!native_prog_mixed_resolutions && native_prog_vact &&
2496 (max_pref_prog_vact > native_prog_vact ||
2497 (max_pref_prog_vact == native_prog_vact && max_pref_prog_hact > native_prog_hact)))
2498 warn("Native progressive resolution of %ux%u is smaller than the max preferred progressive resolution %ux%u.\n",
2499 native_prog_hact, native_prog_vact,
2500 max_pref_prog_hact, max_pref_prog_vact);
2501 if (!native_ilace_mixed_resolutions && native_ilace_vact &&
2502 (max_pref_ilace_vact > native_ilace_vact ||
2503 (max_pref_ilace_vact == native_ilace_vact && max_pref_ilace_hact > native_ilace_hact)))
2504 warn("Native interlaced resolution of %ux%u is smaller than the max preferred interlaced resolution %ux%u.\n",
2505 native_ilace_hact, native_ilace_vact,
2506 max_pref_ilace_hact, max_pref_ilace_vact);
2508 if (dispid.native_width && native_prog_hact &&
2509 !native_prog_mixed_resolutions) {
2510 if (dispid.native_width != native_prog_hact ||
2511 dispid.native_height != native_prog_vact)
2512 fail("Mismatch between CTA-861 and DisplayID native progressive resolution.\n");