edid-decode: add support for new CTA-861.6 Audio Coding Types
[edid-decode.git] / parse-cta-block.cpp
blobaafed1b495d50e2392d0ea247716ddf9f7caec5d
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 case 14: return "Auro-Cx";
273 case 15: return "MPEG-D USAC";
274 default: break;
276 fail("Unknown Audio Ext Format 0x%02x.\n", x);
277 return std::string("Unknown Audio Ext Format (") + utohex(x) + ")";
280 static std::string audio_format(unsigned char x)
282 switch (x) {
283 case 1: return "Linear PCM";
284 case 2: return "AC-3";
285 case 3: return "MPEG 1 (Layers 1 & 2)";
286 case 4: return "MPEG 1 Layer 3 (MP3)";
287 case 5: return "MPEG2 (multichannel)";
288 case 6: return "AAC LC";
289 case 7: return "DTS";
290 case 8: return "ATRAC";
291 case 9: return "One Bit Audio";
292 case 10: return "Enhanced AC-3 (DD+)";
293 case 11: return "DTS-HD";
294 case 12: return "MAT (MLP)";
295 case 13: return "DST";
296 case 14: return "WMA Pro";
297 default: break;
299 fail("Unknown Audio Format 0x%02x.\n", x);
300 return std::string("Unknown Audio Format (") + utohex(x) + ")";
303 static std::string mpeg_h_3d_audio_level(unsigned char x)
305 switch (x) {
306 case 0: return "Unspecified";
307 case 1: return "Level 1";
308 case 2: return "Level 2";
309 case 3: return "Level 3";
310 case 4: return "Level 4";
311 case 5: return "Level 5";
312 default: break;
314 fail("Unknown MPEG-H 3D Audio Level 0x%02x.\n", x);
315 return std::string("Unknown MPEG-H 3D Audio Level (") + utohex(x) + ")";
318 static void cta_audio_block(const unsigned char *x, unsigned length)
320 unsigned i, format, ext_format;
322 if (length % 3) {
323 fail("Broken CTA-861 audio block length %d.\n", length);
324 return;
327 for (i = 0; i < length; i += 3) {
328 format = (x[i] & 0x78) >> 3;
329 if (format == 0) {
330 printf(" Reserved (0x00)\n");
331 fail("Audio Format Code 0x00 is reserved.\n");
332 continue;
334 if (format != 15) {
335 ext_format = 0;
336 printf(" %s:\n", audio_format(format).c_str());
337 } else {
338 ext_format = (x[i + 2] & 0xf8) >> 3;
339 printf(" %s:\n", audio_ext_format(ext_format).c_str());
341 if (format != 15)
342 printf(" Max channels: %u\n", (x[i] & 0x07)+1);
343 else if (ext_format == 11)
344 printf(" MPEG-H 3D Audio Level: %s\n",
345 mpeg_h_3d_audio_level(x[i] & 0x07).c_str());
346 else if (ext_format == 13)
347 printf(" Max channels: %u\n",
348 (((x[i + 1] & 0x80) >> 3) | ((x[i] & 0x80) >> 4) |
349 (x[i] & 0x07))+1);
350 else if ((ext_format == 12 || ext_format == 14) && (x[i] & 0x07))
351 fail("Bits F10-F12 must be 0.\n");
352 else
353 printf(" Max channels: %u\n", (x[i] & 0x07)+1);
355 if ((format == 1 || format == 14) && (x[i + 2] & 0xf8))
356 fail("Bits F33-F37 must be 0.\n");
357 if (ext_format != 13 && (x[i+1] & 0x80))
358 fail("Bit F27 must be 0.\n");
360 // Several sample rates are not supported in certain formats
361 if (ext_format == 12 && (x[i+1] & 0x29))
362 fail("Bits F20, F23 and F25 must be 0.\n");
363 if (ext_format >= 4 && ext_format <= 6 && (x[i+1] & 0x60))
364 fail("Bits F25 and F26 must be 0.\n");
365 if ((ext_format == 8 || ext_format == 10 || ext_format == 15) && (x[i+1] & 0x60))
366 fail("Bits F25 and F26 must be 0.\n");
368 printf(" Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
369 (x[i+1] & 0x40) ? " 192" : "",
370 (x[i+1] & 0x20) ? " 176.4" : "",
371 (x[i+1] & 0x10) ? " 96" : "",
372 (x[i+1] & 0x08) ? " 88.2" : "",
373 (x[i+1] & 0x04) ? " 48" : "",
374 (x[i+1] & 0x02) ? " 44.1" : "",
375 (x[i+1] & 0x01) ? " 32" : "");
376 if (format == 1 || ext_format == 13) {
377 printf(" Supported sample sizes (bits):%s%s%s\n",
378 (x[i+2] & 0x04) ? " 24" : "",
379 (x[i+2] & 0x02) ? " 20" : "",
380 (x[i+2] & 0x01) ? " 16" : "");
381 } else if (format <= 8) {
382 printf(" Maximum bit rate: %u kb/s\n", x[i+2] * 8);
383 } else if (format == 10) {
384 // As specified by the "Dolby Audio and Dolby Atmos over HDMI"
385 // specification (v1.0).
386 if (x[i+2] & 1)
387 printf(" Supports Joint Object Coding\n");
388 if (x[i+2] & 2)
389 printf(" Supports Joint Object Coding with ACMOD28\n");
390 } else if (format == 12) {
391 if (x[i+2] & 1) {
392 printf(" Supports Dolby TrueHD, object audio PCM and channel-based PCM\n");
393 printf(" Hash calculation %srequired for object audio PCM or channel-based PCM\n",
394 (x[i+2] & 2) ? "not " : "");
395 } else {
396 printf(" Supports only Dolby TrueHD\n");
398 } else if (format == 14) {
399 printf(" Profile: %u\n", x[i+2] & 7);
400 } else if (format >= 9 && format <= 13) {
401 printf(" Audio Format Code dependent value: 0x%02x\n", x[i+2]);
402 } else if (ext_format == 11 && (x[i+2] & 1)) {
403 printf(" Supports MPEG-H 3D Audio Low Complexity Profile\n");
404 } else if ((ext_format >= 4 && ext_format <= 6) ||
405 ext_format == 8 || ext_format == 10) {
406 printf(" AAC audio frame lengths:%s%s\n",
407 (x[i+2] & 4) ? " 1024_TL" : "",
408 (x[i+2] & 2) ? " 960_TL" : "");
409 if (ext_format >= 8 && (x[i+2] & 1))
410 printf(" Supports %s signaled MPEG Surround data\n",
411 (x[i+2] & 1) ? "implicitly and explicitly" : "only implicitly");
412 if (ext_format == 6 && (x[i+2] & 1))
413 printf(" Supports 22.2ch System H\n");
414 } else if (ext_format == 12 || ext_format == 14) {
415 printf(" Audio Format Code dependent value: %u\n", x[i+2] & 7);
420 void edid_state::cta_svd(const unsigned char *x, unsigned n, bool for_ycbcr420)
422 unsigned i;
424 for (i = 0; i < n; i++) {
425 const struct timings *t = NULL;
426 unsigned char svd = x[i];
427 unsigned char native;
428 unsigned char vic;
430 if ((svd & 0x7f) == 0)
431 continue;
433 if ((svd - 1) & 0x40) {
434 vic = svd;
435 native = 0;
436 } else {
437 vic = svd & 0x7f;
438 native = svd & 0x80;
441 t = find_vic_id(vic);
442 if (t) {
443 switch (vic) {
444 case 95:
445 cta.supported_hdmi_vic_vsb_codes |= 1 << 0;
446 break;
447 case 94:
448 cta.supported_hdmi_vic_vsb_codes |= 1 << 1;
449 break;
450 case 93:
451 cta.supported_hdmi_vic_vsb_codes |= 1 << 2;
452 break;
453 case 98:
454 cta.supported_hdmi_vic_vsb_codes |= 1 << 3;
455 break;
457 bool first_svd = cta.first_svd && !for_ycbcr420;
458 bool override_pref = first_svd && cta.first_svd_might_be_preferred;
460 char type[16];
461 sprintf(type, "VIC %3u", vic);
462 const char *flags = native ? "native" : "";
464 if (for_ycbcr420) {
465 struct timings tmp = *t;
466 tmp.ycbcr420 = true;
467 print_timings(" ", &tmp, type, flags);
468 } else {
469 print_timings(" ", t, type, flags);
471 if (override_pref) {
472 if (!cta.preferred_timings.empty()) {
473 if (match_timings(cta.preferred_timings[0].t, *t))
474 warn("For improved preferred timing interoperability, set 'Native detailed modes' to 1.\n");
475 else
476 warn("VIC %u is the preferred timing, overriding the first detailed timings. Is this intended?\n", vic);
478 cta.preferred_timings.insert(cta.preferred_timings.begin(),
479 timings_ext(*t, type, flags));
480 } else if (first_svd) {
481 cta.preferred_timings.push_back(timings_ext(*t, type, flags));
483 if (first_svd) {
484 cta.first_svd = false;
485 cta.first_svd_might_be_preferred = false;
487 if (native)
488 cta.native_timings.push_back(timings_ext(*t, type, flags));
489 } else {
490 printf(" Unknown (VIC %3u)\n", vic);
491 fail("Unknown VIC %u.\n", vic);
494 if (vic == 1 && !for_ycbcr420)
495 cta.has_vic_1 = 1;
496 if (++cta.vics[vic][for_ycbcr420] == 2)
497 fail("Duplicate %sVIC %u.\n", for_ycbcr420 ? "YCbCr 4:2:0 " : "", vic);
498 if (for_ycbcr420 && cta.preparsed_has_vic[0][vic])
499 fail("YCbCr 4:2:0-only VIC %u is also a regular VIC.\n", vic);
503 void edid_state::print_vic_index(const char *prefix, unsigned idx, const char *suffix, bool ycbcr420)
505 if (!suffix)
506 suffix = "";
507 if (idx < cta.preparsed_svds[0].size()) {
508 unsigned char vic = cta.preparsed_svds[0][idx];
509 const struct timings *t = find_vic_id(vic);
510 char buf[16];
512 sprintf(buf, "VIC %3u", vic);
514 if (t) {
515 struct timings tmp = *t;
516 tmp.ycbcr420 = ycbcr420;
517 print_timings(prefix, &tmp, buf, suffix);
518 } else {
519 printf("%sUnknown (%s%s%s)\n", prefix, buf,
520 *suffix ? ", " : "", suffix);
522 } else {
523 // Should not happen!
524 printf("%sSVD Index %u is out of range", prefix, idx + 1);
525 if (*suffix)
526 printf(" (%s)", suffix);
527 printf("\n");
531 void edid_state::cta_y420cmdb(const unsigned char *x, unsigned length)
533 unsigned max_idx = 0;
534 unsigned i;
536 if (!length) {
537 printf(" All VDB SVDs\n");
538 return;
541 if (memchk(x, length)) {
542 printf(" Empty Capability Map\n");
543 fail("Empty Capability Map.\n");
544 return;
547 for (i = 0; i < length; i++) {
548 unsigned char v = x[i];
549 unsigned j;
551 for (j = 0; j < 8; j++) {
552 if (!(v & (1 << j)))
553 continue;
555 print_vic_index(" ", i * 8 + j, "", true);
556 max_idx = i * 8 + j;
557 if (max_idx < cta.preparsed_svds[0].size()) {
558 unsigned vic = cta.preparsed_svds[0][max_idx];
559 if (cta.preparsed_has_vic[1][vic])
560 fail("VIC %u is also a YCbCr 4:2:0-only VIC.\n", vic);
564 if (max_idx >= cta.preparsed_svds[0].size())
565 fail("Max index %u > %u (#SVDs).\n",
566 max_idx + 1, cta.preparsed_svds[0].size());
569 void edid_state::cta_print_svr(unsigned char svr, vec_timings_ext &vec_tim)
571 char suffix[16];
573 if ((svr > 0 && svr < 128) || (svr > 192 && svr < 254)) {
574 const struct timings *t;
575 unsigned char vic = svr;
577 sprintf(suffix, "VIC %3u", vic);
579 t = find_vic_id(vic);
580 if (t) {
581 print_timings(" ", t, suffix);
582 vec_tim.push_back(timings_ext(*t, suffix, ""));
583 } else {
584 printf(" %s: Unknown\n", suffix);
585 fail("Unknown VIC %u.\n", vic);
588 } else if (svr >= 129 && svr <= 144) {
589 sprintf(suffix, "DTD %3u", svr - 128);
590 if (svr >= cta.preparsed_total_dtds + 129) {
591 printf(" %s: Invalid\n", suffix);
592 fail("Invalid DTD %u.\n", svr - 128);
593 } else {
594 printf(" %s\n", suffix);
595 vec_tim.push_back(timings_ext(svr, suffix));
597 } else if (svr >= 145 && svr <= 160) {
598 sprintf(suffix, "VTDB %3u", svr - 144);
599 if (svr >= cta.preparsed_total_vtdbs + 145) {
600 printf(" %s: Invalid\n", suffix);
601 fail("Invalid VTDB %u.\n", svr - 144);
602 } else {
603 printf(" %s\n", suffix);
604 vec_tim.push_back(timings_ext(svr, suffix));
606 } else if (svr == 254) {
607 sprintf(suffix, "T8VTDB");
608 if (!cta.preparsed_has_t8vtdb) {
609 printf(" %s: Invalid\n", suffix);
610 fail("Invalid T8VTDB.\n");
611 } else {
612 printf(" %s\n", suffix);
613 vec_tim.push_back(timings_ext(svr, suffix));
618 void edid_state::cta_vfpdb(const unsigned char *x, unsigned length)
620 unsigned i;
622 if (length == 0) {
623 fail("Empty Data Block with length %u.\n", length);
624 return;
626 cta.preferred_timings.clear();
627 for (i = 0; i < length; i++)
628 cta_print_svr(x[i], cta.preferred_timings);
631 static std::string hdmi_latency2s(unsigned char l, bool is_video)
633 if (!l)
634 return "Unknown";
635 if (l == 0xff)
636 return is_video ? "Video not supported" : "Audio not supported";
637 return std::to_string(1 + 2 * l) + " ms";
640 void edid_state::hdmi_latency(unsigned char vid_lat, unsigned char aud_lat,
641 bool is_ilaced)
643 const char *vid = is_ilaced ? "Interlaced video" : "Video";
644 const char *aud = is_ilaced ? "Interlaced audio" : "Audio";
646 printf(" %s latency: %s\n", vid, hdmi_latency2s(vid_lat, true).c_str());
647 printf(" %s latency: %s\n", aud, hdmi_latency2s(aud_lat, false).c_str());
649 if (vid_lat > 251 && vid_lat != 0xff)
650 fail("Invalid %s latency value %u.\n", vid, vid_lat);
651 if (aud_lat > 251 && aud_lat != 0xff)
652 fail("Invalid %s latency value %u.\n", aud, aud_lat);
654 if (!vid_lat || vid_lat > 251)
655 return;
656 if (!aud_lat || aud_lat > 251)
657 return;
659 unsigned vid_ms = 1 + 2 * vid_lat;
660 unsigned aud_ms = 1 + 2 * aud_lat;
662 // HDMI 2.0 latency checks for devices without HDMI output
663 if (aud_ms < vid_ms)
664 warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
665 aud, vid, aud_ms, vid_ms);
666 else if (vid_ms + 20 < aud_ms)
667 warn("%s latency + 20 < %s latency (%u + 20 ms < %u ms). This is forbidden for devices without HDMI output.\n",
668 vid, aud, vid_ms, aud_ms);
669 else if (vid_ms < aud_ms)
670 warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
671 vid, aud, vid_ms, aud_ms);
674 void edid_state::cta_hdmi_block(const unsigned char *x, unsigned length)
676 unsigned len_vic, len_3d;
678 if (length < 1) {
679 fail("Empty Data Block with length %u.\n", length);
680 return;
682 printf(" Source physical address: %x.%x.%x.%x\n", x[0] >> 4, x[0] & 0x0f,
683 x[1] >> 4, x[1] & 0x0f);
685 if (length < 3)
686 return;
688 if (x[2] & 0x80)
689 printf(" Supports_AI\n");
690 if (x[2] & 0x40)
691 printf(" DC_48bit\n");
692 if (x[2] & 0x20)
693 printf(" DC_36bit\n");
694 if (x[2] & 0x10)
695 printf(" DC_30bit\n");
696 if (x[2] & 0x08)
697 printf(" DC_Y444\n");
698 /* two reserved bits */
699 if (x[2] & 0x01)
700 printf(" DVI_Dual\n");
702 if (length < 4)
703 return;
705 printf(" Maximum TMDS clock: %u MHz\n", x[3] * 5);
706 if (x[3] * 5 > 340)
707 fail("HDMI VSDB Max TMDS rate is > 340.\n");
709 if (length < 5)
710 return;
712 if (x[4] & 0x0f) {
713 printf(" Supported Content Types:\n");
714 if (x[4] & 0x01)
715 printf(" Graphics\n");
716 if (x[4] & 0x02)
717 printf(" Photo\n");
718 if (x[4] & 0x04)
719 printf(" Cinema\n");
720 if (x[4] & 0x08)
721 printf(" Game\n");
724 unsigned b = 5;
725 if (x[4] & 0x80) {
726 hdmi_latency(x[b], x[b + 1], false);
728 if (x[4] & 0x40) {
729 if (x[b] == x[b + 2] &&
730 x[b + 1] == x[b + 3])
731 warn("Progressive and Interlaced latency values are identical, no need for both.\n");
732 b += 2;
733 hdmi_latency(x[b], x[b + 1], true);
735 b += 2;
738 if (!(x[4] & 0x20))
739 return;
741 bool mask = false;
742 bool formats = false;
744 printf(" Extended HDMI video details:\n");
745 if (x[b] & 0x80)
746 printf(" 3D present\n");
747 if ((x[b] & 0x60) == 0x20) {
748 printf(" All advertised VICs are 3D-capable\n");
749 formats = true;
751 if ((x[b] & 0x60) == 0x40) {
752 printf(" 3D-capable-VIC mask present\n");
753 formats = true;
754 mask = true;
756 switch (x[b] & 0x18) {
757 case 0x00: break;
758 case 0x08:
759 printf(" Base EDID image size is aspect ratio\n");
760 break;
761 case 0x10:
762 printf(" Base EDID image size is in units of 1 cm\n");
763 break;
764 case 0x18:
765 printf(" Base EDID image size is in units of 5 cm\n");
766 base.max_display_width_mm *= 5;
767 base.max_display_height_mm *= 5;
768 printf(" Recalculated image size: %u cm x %u cm\n",
769 base.max_display_width_mm / 10, base.max_display_height_mm / 10);
770 break;
772 b++;
773 len_vic = (x[b] & 0xe0) >> 5;
774 len_3d = (x[b] & 0x1f) >> 0;
775 b++;
777 if (len_vic) {
778 unsigned i;
780 printf(" HDMI VICs:\n");
781 for (i = 0; i < len_vic; i++) {
782 unsigned char vic = x[b + i];
783 const struct timings *t;
785 if (vic && vic <= ARRAY_SIZE(edid_hdmi_mode_map)) {
786 std::string suffix = "HDMI VIC " + std::to_string(vic);
787 cta.supported_hdmi_vic_codes |= 1 << (vic - 1);
788 t = find_vic_id(edid_hdmi_mode_map[vic - 1]);
789 print_timings(" ", t, suffix.c_str());
790 } else {
791 printf(" Unknown (HDMI VIC %u)\n", vic);
792 fail("Unknown HDMI VIC %u.\n", vic);
796 b += len_vic;
799 if (!len_3d)
800 return;
802 if (formats) {
803 /* 3D_Structure_ALL_15..8 */
804 if (x[b] & 0x80)
805 printf(" 3D: Side-by-side (half, quincunx)\n");
806 if (x[b] & 0x01)
807 printf(" 3D: Side-by-side (half, horizontal)\n");
808 /* 3D_Structure_ALL_7..0 */
809 b++;
810 if (x[b] & 0x40)
811 printf(" 3D: Top-and-bottom\n");
812 if (x[b] & 0x20)
813 printf(" 3D: L + depth + gfx + gfx-depth\n");
814 if (x[b] & 0x10)
815 printf(" 3D: L + depth\n");
816 if (x[b] & 0x08)
817 printf(" 3D: Side-by-side (full)\n");
818 if (x[b] & 0x04)
819 printf(" 3D: Line-alternative\n");
820 if (x[b] & 0x02)
821 printf(" 3D: Field-alternative\n");
822 if (x[b] & 0x01)
823 printf(" 3D: Frame-packing\n");
824 b++;
825 len_3d -= 2;
828 if (mask) {
829 int max_idx = -1;
830 unsigned i;
832 printf(" 3D VIC indices that support these capabilities:\n");
833 /* worst bit ordering ever */
834 for (i = 0; i < 8; i++)
835 if (x[b + 1] & (1 << i)) {
836 print_vic_index(" ", i, "");
837 max_idx = i;
839 for (i = 0; i < 8; i++)
840 if (x[b] & (1 << i)) {
841 print_vic_index(" ", i + 8, "");
842 max_idx = i + 8;
844 b += 2;
845 len_3d -= 2;
846 if (max_idx >= (int)cta.preparsed_svds[0].size())
847 fail("HDMI 3D VIC indices max index %d > %u (#SVDs).\n",
848 max_idx + 1, cta.preparsed_svds[0].size());
852 * list of nibbles:
853 * 2D_VIC_Order_X
854 * 3D_Structure_X
855 * (optionally: 3D_Detail_X and reserved)
857 if (!len_3d)
858 return;
860 unsigned end = b + len_3d;
861 int max_idx = -1;
863 printf(" 3D VIC indices with specific capabilities:\n");
864 while (b < end) {
865 unsigned char idx = x[b] >> 4;
866 std::string s;
868 if (idx > max_idx)
869 max_idx = idx;
870 switch (x[b] & 0x0f) {
871 case 0: s = "frame packing"; break;
872 case 1: s = "field alternative"; break;
873 case 2: s = "line alternative"; break;
874 case 3: s = "side-by-side (full)"; break;
875 case 4: s = "L + depth"; break;
876 case 5: s = "L + depth + gfx + gfx-depth"; break;
877 case 6: s = "top-and-bottom"; break;
878 case 8:
879 s = "side-by-side";
880 switch (x[b + 1] >> 4) {
881 case 0x00: s += ", any subsampling"; break;
882 case 0x01: s += ", horizontal"; break;
883 case 0x02: case 0x03: case 0x04: case 0x05:
884 s += ", not in use";
885 fail("not-in-use 3D_Detail_X value 0x%02x.\n",
886 x[b + 1] >> 4);
887 break;
888 case 0x06: s += ", all quincunx combinations"; break;
889 case 0x07: s += ", quincunx odd/left, odd/right"; break;
890 case 0x08: s += ", quincunx odd/left, even/right"; break;
891 case 0x09: s += ", quincunx even/left, odd/right"; break;
892 case 0x0a: s += ", quincunx even/left, even/right"; break;
893 default:
894 s += ", reserved";
895 fail("reserved 3D_Detail_X value 0x%02x.\n",
896 x[b + 1] >> 4);
897 break;
899 break;
900 default:
901 s = "unknown (";
902 s += utohex(x[b] & 0x0f) + ")";
903 fail("Unknown 3D_Structure_X value 0x%02x.\n", x[b] & 0x0f);
904 break;
906 print_vic_index(" ", idx, s.c_str());
907 if ((x[b] & 0x0f) >= 8)
908 b++;
909 b++;
911 if (max_idx >= (int)cta.preparsed_svds[0].size())
912 fail("HDMI 2D VIC indices max index %d > %u (#SVDs).\n",
913 max_idx + 1, cta.preparsed_svds[0].size());
916 static const char *max_frl_rates[] = {
917 "Not Supported",
918 "3 Gbps per lane on 3 lanes",
919 "3 and 6 Gbps per lane on 3 lanes",
920 "3 and 6 Gbps per lane on 3 lanes, 6 Gbps on 4 lanes",
921 "3 and 6 Gbps per lane on 3 lanes, 6 and 8 Gbps on 4 lanes",
922 "3 and 6 Gbps per lane on 3 lanes, 6, 8 and 10 Gbps on 4 lanes",
923 "3 and 6 Gbps per lane on 3 lanes, 6, 8, 10 and 12 Gbps on 4 lanes",
926 static const char *dsc_max_slices[] = {
927 "Not Supported",
928 "up to 1 slice and up to (340 MHz/Ksliceadjust) pixel clock per slice",
929 "up to 2 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
930 "up to 4 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
931 "up to 8 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
932 "up to 8 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
933 "up to 12 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
934 "up to 16 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
937 static void cta_hf_eeodb(const unsigned char *x, unsigned length)
939 printf(" EDID Extension Block Count: %u\n", x[0]);
940 if (length != 1 || x[0] == 0)
941 fail("Block is too long or reports a 0 block count.\n");
944 static void cta_hf_scdb(const unsigned char *x, unsigned length)
946 unsigned rate = x[1] * 5;
947 unsigned v;
949 printf(" Version: %u\n", x[0]);
950 if (rate) {
951 printf(" Maximum TMDS Character Rate: %u MHz\n", rate);
952 if (rate <= 340 || rate > 600)
953 fail("Max TMDS rate is > 0 and <= 340 or > 600.\n");
955 if (x[2] & 0x80)
956 printf(" SCDC Present\n");
957 if (x[2] & 0x40)
958 printf(" SCDC Read Request Capable\n");
959 if (x[2] & 0x20)
960 printf(" Supports Cable Status\n");
961 if (x[2] & 0x10)
962 printf(" Supports Color Content Bits Per Component Indication\n");
963 if (x[2] & 0x08)
964 printf(" Supports scrambling for <= 340 Mcsc\n");
965 if (x[2] & 0x04)
966 printf(" Supports 3D Independent View signaling\n");
967 if (x[2] & 0x02)
968 printf(" Supports 3D Dual View signaling\n");
969 if (x[2] & 0x01)
970 printf(" Supports 3D OSD Disparity signaling\n");
971 if (x[3] & 0xf0) {
972 unsigned max_frl_rate = x[3] >> 4;
974 printf(" Max Fixed Rate Link: ");
975 if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
976 printf("%s\n", max_frl_rates[max_frl_rate]);
977 } else {
978 printf("Unknown (0x%02x)\n", max_frl_rate);
979 fail("Unknown Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
981 if (max_frl_rate == 1 && rate < 300)
982 fail("Max Fixed Rate Link is 1, but Max TMDS rate < 300.\n");
983 else if (max_frl_rate >= 2 && rate < 600)
984 fail("Max Fixed Rate Link is >= 2, but Max TMDS rate < 600.\n");
986 if (x[3] & 0x08)
987 printf(" Supports UHD VIC\n");
988 if (x[3] & 0x04)
989 printf(" Supports 16-bits/component Deep Color 4:2:0 Pixel Encoding\n");
990 if (x[3] & 0x02)
991 printf(" Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding\n");
992 if (x[3] & 0x01)
993 printf(" Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding\n");
995 if (length <= 4)
996 return;
998 if (x[4] & 0x20)
999 printf(" Supports Mdelta\n");
1000 if (x[4] & 0x10)
1001 printf(" Supports media rates below VRRmin (CinemaVRR)\n");
1002 if (x[4] & 0x08)
1003 printf(" Supports negative Mvrr values\n");
1004 if (x[4] & 0x04)
1005 printf(" Supports Fast Vactive\n");
1006 if (x[4] & 0x02)
1007 printf(" Supports Auto Low-Latency Mode\n");
1008 if (x[4] & 0x01)
1009 printf(" Supports a FAPA in blanking after first active video line\n");
1011 if (length <= 5)
1012 return;
1014 v = x[5] & 0x3f;
1015 if (v) {
1016 printf(" VRRmin: %u Hz\n", v);
1017 if (v > 48)
1018 fail("VRRmin > 48.\n");
1020 v = (x[5] & 0xc0) << 2 | x[6];
1021 if (v) {
1022 printf(" VRRmax: %u Hz\n", v);
1023 if (!(x[5] & 0x3f))
1024 fail("VRRmin == 0, but VRRmax isn't.\n");
1025 else if (v < 100)
1026 fail("VRRmax < 100.\n");
1029 if (length <= 7)
1030 return;
1032 if (x[7] & 0x80)
1033 printf(" Supports VESA DSC 1.2a compression\n");
1034 if (x[7] & 0x40)
1035 printf(" Supports Compressed Video Transport for 4:2:0 Pixel Encoding\n");
1036 if (x[7] & 0x08)
1037 printf(" Supports Compressed Video Transport at any valid 1/16th bit bpp\n");
1038 if (x[7] & 0x04)
1039 printf(" Supports 16 bpc Compressed Video Transport\n");
1040 if (x[7] & 0x02)
1041 printf(" Supports 12 bpc Compressed Video Transport\n");
1042 if (x[7] & 0x01)
1043 printf(" Supports 10 bpc Compressed Video Transport\n");
1044 if (x[8] & 0xf) {
1045 unsigned max_slices = x[8] & 0xf;
1047 printf(" DSC Max Slices: ");
1048 if (max_slices < ARRAY_SIZE(dsc_max_slices)) {
1049 printf("%s\n", dsc_max_slices[max_slices]);
1050 } else {
1051 printf("Unknown (0x%02x)\n", max_slices);
1052 fail("Unknown DSC Max Slices (0x%02x).\n", max_slices);
1055 if (x[8] & 0xf0) {
1056 unsigned max_frl_rate = x[8] >> 4;
1058 printf(" DSC Max Fixed Rate Link: ");
1059 if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
1060 printf("%s\n", max_frl_rates[max_frl_rate]);
1061 } else {
1062 printf("Unknown (0x%02x)\n", max_frl_rate);
1063 fail("Unknown DSC Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
1066 if (x[9] & 0x3f)
1067 printf(" Maximum number of bytes in a line of chunks: %u\n",
1068 1024 * (1 + (x[9] & 0x3f)));
1071 static void cta_amd(const unsigned char *x, unsigned length)
1073 // These Freesync values are reversed engineered by looking
1074 // at existing EDIDs.
1075 printf(" Version: %u.%u\n", x[0], x[1]);
1076 printf(" Minimum Refresh Rate: %u Hz\n", x[2]);
1077 printf(" Maximum Refresh Rate: %u Hz\n", x[3]);
1078 // Freesync 1.x flags
1079 // One or more of the 0xe6 bits signal that the VESA MCCS
1080 // protocol is used to switch the Freesync range
1081 printf(" Flags 1.x: 0x%02x%s\n", x[4],
1082 (x[4] & 0xe6) ? " (MCCS)" : "");
1083 if (length >= 10) {
1084 // Freesync 2.x flags
1085 // Bit 2 no doubt indicates if the monitor supports Local Dimming
1086 // There are probably also bits to signal support of the
1087 // FreeSync2_scRGB and FreeSync2_Gamma22 HDR display modes.
1088 // I suspect bits 0 and 1.
1089 printf(" Flags 2.x: 0x%02x\n", x[5]);
1090 // The AMD tone mapping tutorial referred to in the URL below
1091 // mentions that the Freesync HDR info reports max/min
1092 // luminance of the monitor with and without local dimming.
1094 // https://gpuopen.com/learn/using-amd-freesync-premium-pro-hdr-code-samples/
1096 // So I assume that the first two luminance values are
1097 // the max/min luminance of the display and the next two
1098 // luminance values are the max/min luminance values when
1099 // local dimming is disabled. The values I get seem to
1100 // support that.
1101 printf(" Maximum luminance: %u (%.3f cd/m^2)\n",
1102 x[6], 50.0 * pow(2, x[6] / 32.0));
1103 printf(" Minimum luminance: %u (%.3f cd/m^2)\n",
1104 x[7], (50.0 * pow(2, x[6] / 32.0)) * pow(x[7] / 255.0, 2) / 100.0);
1105 if (x[5] & 4) {
1106 // One or both bytes can be 0. The meaning of that
1107 // is unknown.
1108 printf(" Maximum luminance (without local dimming): %u (%.3f cd/m^2)\n",
1109 x[8], 50.0 * pow(2, x[8] / 32.0));
1110 printf(" Minimum luminance (without local dimming): %u (%.3f cd/m^2)\n",
1111 x[9], (50.0 * pow(2, x[8] / 32.0)) * pow(x[9] / 255.0, 2) / 100.0);
1112 } else {
1113 // These bytes are always 0x08 0x2f. If these values
1114 // represent max/min luminance as well, then these
1115 // would map to 59.460 and 0.020 cd/m^2 respectively.
1116 // I wonder if this somehow relates to SDR.
1117 printf(" Unknown: 0x%02x 0x%02x\n", x[8], x[9]);
1122 static std::string display_use_case(unsigned char x)
1124 switch (x) {
1125 case 1: return "Test equipment";
1126 case 2: return "Generic display";
1127 case 3: return "Television display";
1128 case 4: return "Desktop productivity display";
1129 case 5: return "Desktop gaming display";
1130 case 6: return "Presentation display";
1131 case 7: return "Virtual reality headset";
1132 case 8: return "Augmented reality";
1133 case 16: return "Video wall display";
1134 case 17: return "Medical imaging display";
1135 case 18: return "Dedicated gaming display";
1136 case 19: return "Dedicated video monitor display";
1137 case 20: return "Accessory display";
1138 default: break;
1140 fail("Unknown Display product primary use case 0x%02x.\n", x);
1141 return std::string("Unknown display use case (") + utohex(x) + ")";
1144 static void cta_microsoft(const unsigned char *x, unsigned length)
1146 // This VSDB is documented at:
1147 // https://docs.microsoft.com/en-us/windows-hardware/drivers/display/specialized-monitors-edid-extension
1148 printf(" Version: %u\n", x[0]);
1149 if (x[0] > 2) {
1150 // In version 1 and 2 these bits should always be set to 0.
1151 printf(" Desktop Usage: %u\n", (x[1] >> 6) & 1);
1152 printf(" Third-Party Usage: %u\n", (x[1] >> 5) & 1);
1154 printf(" Display Product Primary Use Case: %u (%s)\n", x[1] & 0x1f,
1155 display_use_case(x[1] & 0x1f).c_str());
1156 printf(" Container ID: %s\n", containerid2s(x + 2).c_str());
1159 static void cta_hdr10plus(const unsigned char *x, unsigned length)
1161 if (length == 0) {
1162 fail("Empty Data Block with length %u.\n", length);
1163 return;
1165 printf(" Application Version: %u\n", x[0]);
1166 hex_block(" ", x + 1, length - 1);
1169 // Convert a PQ value (0-1) to cd/m^2 aka nits (0-10000)
1170 static double pq2nits(double pq)
1172 const double m1 = 2610.0 / 16384.0;
1173 const double m2 = 128.0 * (2523.0 / 4096.0);
1174 const double c1 = 3424.0 / 4096.0;
1175 const double c2 = 32.0 * (2413.0 / 4096.0);
1176 const double c3 = 32.0 * (2392.0 / 4096.0);
1177 double e = pow(pq, 1.0 / m2);
1178 double v = e - c1;
1180 if (v < 0)
1181 v = 0;
1182 v /= c2 - c3 * e;
1183 v = pow(v, 1.0 / m1);
1184 return v * 10000.0;
1187 static void cta_dolby_video(const unsigned char *x, unsigned length)
1189 unsigned char version = (x[0] >> 5) & 0x07;
1191 printf(" Version: %u (%u bytes)\n", version, length + 5);
1192 if (x[0] & 0x01)
1193 printf(" Supports YUV422 12 bit\n");
1195 if (version == 0) {
1196 if (x[0] & 0x02)
1197 printf(" Supports 2160p60\n");
1198 if (x[0] & 0x04)
1199 printf(" Supports global dimming\n");
1200 unsigned char dm_version = x[16];
1201 printf(" DM Version: %u.%u\n", dm_version >> 4, dm_version & 0xf);
1202 unsigned pq = (x[14] << 4) | (x[13] >> 4);
1203 printf(" Target Min PQ: %u (%.8f cd/m^2)\n", pq, pq2nits(pq / 4095.0));
1204 pq = (x[15] << 4) | (x[13] & 0xf);
1205 printf(" Target Max PQ: %u (%u cd/m^2)\n", pq, (unsigned)pq2nits(pq / 4095.0));
1206 printf(" Rx, Ry: %.8f, %.8f\n",
1207 ((x[1] >> 4) | (x[2] << 4)) / 4096.0,
1208 ((x[1] & 0xf) | (x[3] << 4)) / 4096.0);
1209 printf(" Gx, Gy: %.8f, %.8f\n",
1210 ((x[4] >> 4) | (x[5] << 4)) / 4096.0,
1211 ((x[4] & 0xf) | (x[6] << 4)) / 4096.0);
1212 printf(" Bx, By: %.8f, %.8f\n",
1213 ((x[7] >> 4) | (x[8] << 4)) / 4096.0,
1214 ((x[7] & 0xf) | (x[9] << 4)) / 4096.0);
1215 printf(" Wx, Wy: %.8f, %.8f\n",
1216 ((x[10] >> 4) | (x[11] << 4)) / 4096.0,
1217 ((x[10] & 0xf) | (x[12] << 4)) / 4096.0);
1218 return;
1221 if (version == 1) {
1222 if (x[0] & 0x02)
1223 printf(" Supports 2160p60\n");
1224 if (x[1] & 0x01)
1225 printf(" Supports global dimming\n");
1226 unsigned char dm_version = (x[0] >> 2) & 0x07;
1227 printf(" DM Version: %u.x\n", dm_version + 2);
1228 printf(" Colorimetry: %s\n", (x[2] & 0x01) ? "P3-D65" : "ITU-R BT.709");
1229 printf(" Low Latency: %s\n", (x[3] & 0x01) ? "Standard + Low Latency" : "Only Standard");
1230 double lm = (x[2] >> 1) / 127.0;
1231 printf(" Target Min Luminance: %.8f cd/m^2\n", lm * lm);
1232 printf(" Target Max Luminance: %u cd/m^2\n", 100 + (x[1] >> 1) * 50);
1233 if (length == 10) {
1234 printf(" Rx, Ry: %.8f, %.8f\n", x[4] / 256.0, x[5] / 256.0);
1235 printf(" Gx, Gy: %.8f, %.8f\n", x[6] / 256.0, x[7] / 256.0);
1236 printf(" Bx, By: %.8f, %.8f\n", x[8] / 256.0, x[9] / 256.0);
1237 } else {
1238 double xmin = 0.625;
1239 double xstep = (0.74609375 - xmin) / 31.0;
1240 double ymin = 0.25;
1241 double ystep = (0.37109375 - ymin) / 31.0;
1243 printf(" Unique Rx, Ry: %.8f, %.8f\n",
1244 xmin + xstep * (x[6] >> 3),
1245 ymin + ystep * (((x[6] & 0x7) << 2) | (x[4] & 0x01) | ((x[5] & 0x01) << 1)));
1246 xstep = 0.49609375 / 127.0;
1247 ymin = 0.5;
1248 ystep = (0.99609375 - ymin) / 127.0;
1249 printf(" Unique Gx, Gy: %.8f, %.8f\n",
1250 xstep * (x[4] >> 1), ymin + ystep * (x[5] >> 1));
1251 xmin = 0.125;
1252 xstep = (0.15234375 - xmin) / 7.0;
1253 ymin = 0.03125;
1254 ystep = (0.05859375 - ymin) / 7.0;
1255 printf(" Unique Bx, By: %.8f, %.8f\n",
1256 xmin + xstep * (x[3] >> 5),
1257 ymin + ystep * ((x[3] >> 2) & 0x07));
1259 return;
1262 if (version == 2) {
1263 if (x[0] & 0x02)
1264 printf(" Supports Backlight Control\n");
1265 if (x[1] & 0x04)
1266 printf(" Supports global dimming\n");
1267 unsigned char dm_version = (x[0] >> 2) & 0x07;
1268 printf(" DM Version: %u.x\n", dm_version + 2);
1269 printf(" Backlt Min Luma: %u cd/m^2\n", 25 + (x[1] & 0x03) * 25);
1270 printf(" Interface: ");
1271 switch (x[2] & 0x03) {
1272 case 0: printf("Low-Latency\n"); break;
1273 case 1: printf("Low-Latency + Low-Latency-HDMI\n"); break;
1274 case 2: printf("Standard + Low-Latency\n"); break;
1275 case 3: printf("Standard + Low-Latency + Low-Latency-HDMI\n"); break;
1277 printf(" Supports 10b 12b 444: ");
1278 switch ((x[3] & 0x01) << 1 | (x[4] & 0x01)) {
1279 case 0: printf("Not supported\n"); break;
1280 case 1: printf("10 bit\n"); break;
1281 case 2: printf("12 bit\n"); break;
1282 case 3: printf("Reserved\n"); break;
1285 // This divider constant is a guess. According to what I read
1286 // when googling for how to interpret these values, the Min PQ
1287 // maps to a range of 0-1 cd/m^2, and the Max PQ maps to a
1288 // range of 100-10000 cd/m^2. Since the maximum value for the Max PQ
1289 // is 2055 + 65 * 31 = 4070, I am guessing that that is the correct
1290 // divider, but it might well be 4095 or 4096 instead.
1292 // I'm also not sure if the divider for Min PQ is the same as for
1293 // Max PQ. To map the max value of 20 * 31 to 1 cd/m^2 you would
1294 // need a divider of 4134 or 4135, but I suspect the same divider
1295 // is used.
1296 const double dv_pq_div = 2055 + 31 * 65;
1298 unsigned pq = 20 * (x[1] >> 3);
1299 printf(" Target Min PQ v2: %u (%.8f cd/m^2)\n", pq, pq2nits(pq / dv_pq_div));
1300 pq = 2055 + 65 * (x[2] >> 3);
1301 printf(" Target Max PQ v2: %u (%u cd/m^2)\n", pq, (unsigned)pq2nits(pq / dv_pq_div));
1303 double xmin = 0.625;
1304 double xstep = (0.74609375 - xmin) / 31.0;
1305 double ymin = 0.25;
1306 double ystep = (0.37109375 - ymin) / 31.0;
1308 printf(" Unique Rx, Ry: %.8f, %.8f\n",
1309 xmin + xstep * (x[5] >> 3),
1310 ymin + ystep * (x[6] >> 3));
1311 xstep = 0.49609375 / 127.0;
1312 ymin = 0.5;
1313 ystep = (0.99609375 - ymin) / 127.0;
1314 printf(" Unique Gx, Gy: %.8f, %.8f\n",
1315 xstep * (x[3] >> 1), ymin + ystep * (x[4] >> 1));
1316 xmin = 0.125;
1317 xstep = (0.15234375 - xmin) / 7.0;
1318 ymin = 0.03125;
1319 ystep = (0.05859375 - ymin) / 7.0;
1320 printf(" Unique Bx, By: %.8f, %.8f\n",
1321 xmin + xstep * (x[5] & 0x07),
1322 ymin + ystep * (x[6] & 0x07));
1326 static void cta_dolby_audio(const unsigned char *x, unsigned length)
1328 unsigned char version = 1 + (x[0] & 0x07);
1330 printf(" Version: %u (%u bytes)\n", version, length + 5);
1331 if (x[0] & 0x80)
1332 printf(" Headphone playback only\n");
1333 if (x[0] & 0x40)
1334 printf(" Height speaker zone present\n");
1335 if (x[0] & 0x20)
1336 printf(" Surround speaker zone present\n");
1337 if (x[0] & 0x10)
1338 printf(" Center speaker zone present\n");
1339 if (x[1] & 0x01)
1340 printf(" Supports Dolby MAT PCM decoding at 48 kHz only, does not support TrueHD\n");
1343 static const char *speaker_map[] = {
1344 "FL/FR - Front Left/Right",
1345 "LFE1 - Low Frequency Effects 1",
1346 "FC - Front Center",
1347 "BL/BR - Back Left/Right",
1348 "BC - Back Center",
1349 "FLc/FRc - Front Left/Right of Center",
1350 "RLC/RRC - Rear Left/Right of Center (Deprecated)",
1351 "FLw/FRw - Front Left/Right Wide",
1352 "TpFL/TpFR - Top Front Left/Right",
1353 "TpC - Top Center",
1354 "TpFC - Top Front Center",
1355 "LS/RS - Left/Right Surround",
1356 "LFE2 - Low Frequency Effects 2",
1357 "TpBC - Top Back Center",
1358 "SiL/SiR - Side Left/Right",
1359 "TpSiL/TpSiR - Top Side Left/Right",
1360 "TpBL/TpBR - Top Back Left/Right",
1361 "BtFC - Bottom Front Center",
1362 "BtFL/BtFR - Bottom Front Left/Right",
1363 "TpLS/TpRS - Top Left/Right Surround (Deprecated for CTA-861)",
1364 "LSd/RSd - Left/Right Surround Direct (HDMI only)",
1367 static void cta_sadb(const unsigned char *x, unsigned length)
1369 unsigned sad;
1370 unsigned i;
1372 if (length < 3) {
1373 fail("Empty Data Block with length %u.\n", length);
1374 return;
1377 sad = ((x[2] << 16) | (x[1] << 8) | x[0]);
1379 for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
1380 if ((sad >> i) & 1)
1381 printf(" %s\n", speaker_map[i]);
1385 static void cta_vesa_dtcdb(const unsigned char *x, unsigned length)
1387 if (length != 7 && length != 15 && length != 31) {
1388 fail("Invalid length %u.\n", length);
1389 return;
1392 switch (x[0] >> 6) {
1393 case 0: printf(" White"); break;
1394 case 1: printf(" Red"); break;
1395 case 2: printf(" Green"); break;
1396 case 3: printf(" Blue"); break;
1398 unsigned v = x[0] & 0x3f;
1399 printf(" transfer characteristics: %u", v);
1400 for (unsigned i = 1; i < length; i++)
1401 printf(" %u", v += x[i]);
1402 printf(" 1023\n");
1405 static void cta_vesa_vdddb(const unsigned char *x, unsigned length)
1407 if (length != 30) {
1408 fail("Invalid length %u.\n", length);
1409 return;
1412 printf(" Interface Type: ");
1413 unsigned char v = x[0];
1414 switch (v >> 4) {
1415 case 0: printf("Analog (");
1416 switch (v & 0xf) {
1417 case 0: printf("15HD/VGA"); break;
1418 case 1: printf("VESA NAVI-V (15HD)"); break;
1419 case 2: printf("VESA NAVI-D"); break;
1420 default: printf("Reserved"); break;
1422 printf(")\n");
1423 break;
1424 case 1: printf("LVDS %u lanes", v & 0xf); break;
1425 case 2: printf("RSDS %u lanes", v & 0xf); break;
1426 case 3: printf("DVI-D %u channels", v & 0xf); break;
1427 case 4: printf("DVI-I analog"); break;
1428 case 5: printf("DVI-I digital %u channels", v & 0xf); break;
1429 case 6: printf("HDMI-A"); break;
1430 case 7: printf("HDMI-B"); break;
1431 case 8: printf("MDDI %u channels", v & 0xf); break;
1432 case 9: printf("DisplayPort %u channels", v & 0xf); break;
1433 case 10: printf("IEEE-1394"); break;
1434 case 11: printf("M1 analog"); break;
1435 case 12: printf("M1 digital %u channels", v & 0xf); break;
1436 default: printf("Reserved"); break;
1438 printf("\n");
1440 printf(" Interface Standard Version: %u.%u\n", x[1] >> 4, x[1] & 0xf);
1441 printf(" Content Protection Support: ");
1442 switch (x[2]) {
1443 case 0: printf("None\n"); break;
1444 case 1: printf("HDCP\n"); break;
1445 case 2: printf("DTCP\n"); break;
1446 case 3: printf("DPCP\n"); break;
1447 default: printf("Reserved\n"); break;
1450 printf(" Minimum Clock Frequency: %u MHz\n", x[3] >> 2);
1451 printf(" Maximum Clock Frequency: %u MHz\n", ((x[3] & 0x03) << 8) | x[4]);
1452 printf(" Device Native Pixel Format: %ux%u\n",
1453 x[5] | (x[6] << 8), x[7] | (x[8] << 8));
1454 printf(" Aspect Ratio: %.2f\n", (100 + x[9]) / 100.0);
1455 v = x[0x0a];
1456 printf(" Default Orientation: ");
1457 switch ((v & 0xc0) >> 6) {
1458 case 0x00: printf("Landscape\n"); break;
1459 case 0x01: printf("Portrait\n"); break;
1460 case 0x02: printf("Not Fixed\n"); break;
1461 case 0x03: printf("Undefined\n"); break;
1463 printf(" Rotation Capability: ");
1464 switch ((v & 0x30) >> 4) {
1465 case 0x00: printf("None\n"); break;
1466 case 0x01: printf("Can rotate 90 degrees clockwise\n"); break;
1467 case 0x02: printf("Can rotate 90 degrees counterclockwise\n"); break;
1468 case 0x03: printf("Can rotate 90 degrees in either direction)\n"); break;
1470 printf(" Zero Pixel Location: ");
1471 switch ((v & 0x0c) >> 2) {
1472 case 0x00: printf("Upper Left\n"); break;
1473 case 0x01: printf("Upper Right\n"); break;
1474 case 0x02: printf("Lower Left\n"); break;
1475 case 0x03: printf("Lower Right\n"); break;
1477 printf(" Scan Direction: ");
1478 switch (v & 0x03) {
1479 case 0x00: printf("Not defined\n"); break;
1480 case 0x01: printf("Fast Scan is on the Major (Long) Axis and Slow Scan is on the Minor Axis\n"); break;
1481 case 0x02: printf("Fast Scan is on the Minor (Short) Axis and Slow Scan is on the Major Axis\n"); break;
1482 case 0x03: printf("Reserved\n");
1483 fail("Scan Direction used the reserved value 0x03.\n");
1484 break;
1486 printf(" Subpixel Information: ");
1487 switch (x[0x0b]) {
1488 case 0x00: printf("Not defined\n"); break;
1489 case 0x01: printf("RGB vertical stripes\n"); break;
1490 case 0x02: printf("RGB horizontal stripes\n"); break;
1491 case 0x03: printf("Vertical stripes using primary order\n"); break;
1492 case 0x04: printf("Horizontal stripes using primary order\n"); break;
1493 case 0x05: printf("Quad sub-pixels, red at top left\n"); break;
1494 case 0x06: printf("Quad sub-pixels, red at bottom left\n"); break;
1495 case 0x07: printf("Delta (triad) RGB sub-pixels\n"); break;
1496 case 0x08: printf("Mosaic\n"); break;
1497 case 0x09: printf("Quad sub-pixels, RGB + 1 additional color\n"); break;
1498 case 0x0a: printf("Five sub-pixels, RGB + 2 additional colors\n"); break;
1499 case 0x0b: printf("Six sub-pixels, RGB + 3 additional colors\n"); break;
1500 case 0x0c: printf("Clairvoyante, Inc. PenTile Matrix (tm) layout\n"); break;
1501 default: printf("Reserved\n"); break;
1503 printf(" Horizontal and vertical dot/pixel pitch: %.2f x %.2f mm\n",
1504 (double)(x[0x0c]) / 100.0, (double)(x[0x0d]) / 100.0);
1505 v = x[0x0e];
1506 printf(" Dithering: ");
1507 switch (v >> 6) {
1508 case 0: printf("None\n"); break;
1509 case 1: printf("Spatial\n"); break;
1510 case 2: printf("Temporal\n"); break;
1511 case 3: printf("Spatial and Temporal\n"); break;
1513 printf(" Direct Drive: %s\n", (v & 0x20) ? "Yes" : "No");
1514 printf(" Overdrive %srecommended\n", (v & 0x10) ? "not " : "");
1515 printf(" Deinterlacing: %s\n", (v & 0x08) ? "Yes" : "No");
1517 v = x[0x0f];
1518 printf(" Audio Support: %s\n", (v & 0x80) ? "Yes" : "No");
1519 printf(" Separate Audio Inputs Provided: %s\n", (v & 0x40) ? "Yes" : "No");
1520 printf(" Audio Input Override: %s\n", (v & 0x20) ? "Yes" : "No");
1521 v = x[0x10];
1522 if (v)
1523 printf(" Audio Delay: %s%u ms\n", (v & 0x80) ? "" : "-", (v & 0x7f) * 2);
1524 else
1525 printf(" Audio Delay: no information provided\n");
1526 v = x[0x11];
1527 printf(" Frame Rate/Mode Conversion: ");
1528 switch (v >> 6) {
1529 case 0: printf("None\n"); break;
1530 case 1: printf("Single Buffering\n"); break;
1531 case 2: printf("Double Buffering\n"); break;
1532 case 3: printf("Advanced Frame Rate Conversion\n"); break;
1534 if (v & 0x3f)
1535 printf(" Frame Rate Range: %u fps +/- %u fps\n",
1536 x[0x12], v & 0x3f);
1537 else
1538 printf(" Nominal Frame Rate: %u fps\n", x[0x12]);
1539 printf(" Color Bit Depth: %u @ interface, %u @ display\n",
1540 (x[0x13] >> 4) + 1, (x[0x13] & 0xf) + 1);
1541 v = x[0x15] & 3;
1542 if (v) {
1543 printf(" Additional Primary Chromaticities:\n");
1544 unsigned col_x = (x[0x16] << 2) | (x[0x14] >> 6);
1545 unsigned col_y = (x[0x17] << 2) | ((x[0x14] >> 4) & 3);
1546 printf(" Primary 4: 0.%04u, 0.%04u\n",
1547 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1548 if (v > 1) {
1549 col_x = (x[0x18] << 2) | ((x[0x14] >> 2) & 3);
1550 col_y = (x[0x19] << 2) | (x[0x14] & 3);
1551 printf(" Primary 5: 0.%04u, 0.%04u\n",
1552 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1553 if (v > 2) {
1554 col_x = (x[0x1a] << 2) | (x[0x15] >> 6);
1555 col_y = (x[0x1b] << 2) | ((x[0x15] >> 4) & 3);
1556 printf(" Primary 6: 0.%04u, 0.%04u\n",
1557 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1562 v = x[0x1c];
1563 printf(" Response Time %s: %u ms\n",
1564 (v & 0x80) ? "White -> Black" : "Black -> White", v & 0x7f);
1565 v = x[0x1d];
1566 printf(" Overscan: %u%% x %u%%\n", v >> 4, v & 0xf);
1569 static double decode_uchar_as_double(unsigned char x)
1571 signed char s = (signed char)x;
1573 return s / 64.0;
1576 void edid_state::cta_rcdb(const unsigned char *x, unsigned length)
1578 unsigned spm = ((x[3] << 16) | (x[2] << 8) | x[1]);
1579 unsigned i;
1581 if (length < 4) {
1582 fail("Empty Data Block with length %u.\n", length);
1583 return;
1586 if ((x[0] & 0x20) && !cta.has_sldb)
1587 fail("'SLD' flag is 1, but no Speaker Location Data Block is found.\n");
1588 else if (!(x[0] & 0x20) && cta.has_sldb)
1589 fail("'SLD' flag is 0, but a Speaker Location Data Block is present.\n");
1591 if (x[0] & 0x40) {
1592 printf(" Speaker count: %u\n", (x[0] & 0x1f) + 1);
1593 } else {
1594 if (x[0] & 0x1f)
1595 fail("'Speaker' flag is 0, but 'Speaker Count' is != 0.\n");
1596 if (x[0] & 0x20)
1597 fail("'SLD' flag is 1, but 'Speaker' is 0.\n");
1600 printf(" Speaker Presence Mask:\n");
1601 for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
1602 if ((spm >> i) & 1)
1603 printf(" %s\n", speaker_map[i]);
1606 if ((x[0] & 0xa0) == 0x80)
1607 fail("'Display' flag set, but not the 'SLD' flag.\n");
1609 bool valid_max = cta.preparsed_sld_has_coord || (x[0] & 0x80);
1611 if (valid_max && length >= 7) {
1612 printf(" Xmax: %u dm\n", x[4]);
1613 printf(" Ymax: %u dm\n", x[5]);
1614 printf(" Zmax: %u dm\n", x[6]);
1615 } else if (!valid_max && length >= 7) {
1616 // The RCDB should have been truncated.
1617 warn("'Display' flag is 0 and 'Coord' is 0 for all SLDs, but the Max coordinates are still present.\n");
1619 if ((x[0] & 0x80) && length >= 10) {
1620 printf(" DisplayX: %.3f * Xmax\n", decode_uchar_as_double(x[7]));
1621 printf(" DisplayY: %.3f * Ymax\n", decode_uchar_as_double(x[8]));
1622 printf(" DisplayZ: %.3f * Zmax\n", decode_uchar_as_double(x[9]));
1623 } else if (!(x[0] & 0x80) && length >= 10) {
1624 // The RCDB should have been truncated.
1625 warn("'Display' flag is 0, but the Display coordinates are still present.\n");
1629 static const char *speaker_location[] = {
1630 "FL - Front Left",
1631 "FR - Front Right",
1632 "FC - Front Center",
1633 "LFE1 - Low Frequency Effects 1",
1634 "BL - Back Left",
1635 "BR - Back Right",
1636 "FLC - Front Left of Center",
1637 "FRC - Front Right of Center",
1638 "BC - Back Center",
1639 "LFE2 - Low Frequency Effects 2",
1640 "SiL - Side Left",
1641 "SiR - Side Right",
1642 "TpFL - Top Front Left",
1643 "TpFR - Top Front Right",
1644 "TpFC - Top Front Center",
1645 "TpC - Top Center",
1646 "TpBL - Top Back Left",
1647 "TpBR - Top Back Right",
1648 "TpSiL - Top Side Left",
1649 "TpSiR - Top Side Right",
1650 "TpBC - Top Back Center",
1651 "BtFC - Bottom Front Center",
1652 "BtFL - Bottom Front Left",
1653 "BtFR - Bottom Front Right",
1654 "FLW - Front Left Wide",
1655 "FRW - Front Right Wide",
1656 "LS - Left Surround",
1657 "RS - Right Surround",
1660 void edid_state::cta_sldb(const unsigned char *x, unsigned length)
1662 if (length < 2) {
1663 fail("Empty Data Block with length %u.\n", length);
1664 return;
1667 unsigned active_cnt = 0;
1668 unsigned channel_is_active = 0;
1670 while (length >= 2) {
1671 printf(" Channel: %u (%sactive)\n", x[0] & 0x1f,
1672 (x[0] & 0x20) ? "" : "not ");
1673 if (x[0] & 0x20) {
1674 if (channel_is_active & (1U << (x[0] & 0x1f)))
1675 fail("Channel Index %u was already marked 'Active'.\n",
1676 x[0] & 0x1f);
1677 channel_is_active |= 1U << (x[0] & 0x1f);
1678 active_cnt++;
1680 if ((x[1] & 0x1f) < ARRAY_SIZE(speaker_location))
1681 printf(" Speaker: %s\n", speaker_location[x[1] & 0x1f]);
1682 if (length >= 5 && (x[0] & 0x40)) {
1683 printf(" X: %.3f * Xmax\n", decode_uchar_as_double(x[2]));
1684 printf(" Y: %.3f * Ymax\n", decode_uchar_as_double(x[3]));
1685 printf(" Z: %.3f * Zmax\n", decode_uchar_as_double(x[4]));
1686 length -= 3;
1687 x += 3;
1690 length -= 2;
1691 x += 2;
1693 if (active_cnt != cta.preparsed_speaker_count)
1694 fail("There are %u active speakers, but 'Speaker Count' is %u.\n",
1695 active_cnt, cta.preparsed_speaker_count);
1698 void edid_state::cta_preparse_sldb(const unsigned char *x, unsigned length)
1700 cta.has_sldb = true;
1701 while (length >= 2) {
1702 if (length >= 5 && (x[0] & 0x40)) {
1703 cta.preparsed_sld_has_coord = true;
1704 return;
1706 length -= 2;
1707 x += 2;
1711 void edid_state::cta_vcdb(const unsigned char *x, unsigned length)
1713 unsigned char d = x[0];
1715 cta.has_vcdb = true;
1716 if (length < 1) {
1717 fail("Empty Data Block with length %u.\n", length);
1718 return;
1720 printf(" YCbCr quantization: %s\n",
1721 (d & 0x80) ? "Selectable (via AVI YQ)" : "No Data");
1722 printf(" RGB quantization: %s\n",
1723 (d & 0x40) ? "Selectable (via AVI Q)" : "No Data");
1725 * If this bit is not set then that will result in interoperability
1726 * problems (specifically with PCs/laptops) that quite often do not
1727 * follow the default rules with respect to RGB Quantization Range
1728 * handling.
1730 * Starting with the CTA-861-H spec this bit is now required to be
1731 * 1 for new designs.
1733 if (!(d & 0x40))
1734 fail("Set Selectable RGB Quantization to avoid interop issues.\n");
1736 * Since most YCbCr formats use limited range, the interop issues are
1737 * less noticable than for RGB formats.
1739 * Starting with the CTA-861-H spec this bit is now required to be
1740 * 1 for new designs, but just warn about it (for now).
1742 if ((cta.byte3 & 0x30) && !(d & 0x80))
1743 warn("Set Selectable YCbCr Quantization to avoid interop issues.\n");
1745 unsigned char s_pt = (d >> 4) & 0x03;
1746 unsigned char s_it = (d >> 2) & 0x03;
1747 unsigned char s_ce = d & 0x03;
1749 printf(" PT scan behavior: ");
1750 switch (s_pt) {
1751 case 0: printf("No Data\n"); break;
1752 case 1: printf("Always Overscanned\n"); break;
1753 case 2: printf("Always Underscanned\n"); break;
1754 case 3: printf("Supports both over- and underscan\n"); break;
1756 printf(" IT scan behavior: ");
1757 switch (s_it) {
1758 case 0: printf("IT video formats not supported\n"); break;
1759 case 1:
1760 printf("Always Overscanned\n");
1761 // See Table 52 of CTA-861-G for a description of Byte 3
1762 if (cta.byte3 & 0x80)
1763 fail("IT video formats are always overscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to underscanned.\n");
1764 break;
1765 case 2:
1766 printf("Always Underscanned\n");
1767 // See Table 52 of CTA-861-G for a description of Byte 3
1768 if (!(cta.byte3 & 0x80))
1769 fail("IT video formats are always underscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to overscanned.\n");
1770 break;
1771 case 3: printf("Supports both over- and underscan\n"); break;
1773 if (s_it < 2)
1774 warn("IT scan behavior is expected to support underscanned.\n");
1775 printf(" CE scan behavior: ");
1776 switch (s_ce) {
1777 case 0: printf("CE video formats not supported\n"); break;
1778 case 1: printf("Always Overscanned\n"); break;
1779 case 2: printf("Always Underscanned\n"); break;
1780 case 3: printf("Supports both over- and underscan\n"); break;
1782 if (s_ce == 0)
1783 warn("'CE video formats not supported' makes no sense.\n");
1784 else if (s_pt == s_it && s_pt == s_ce)
1785 warn("S_PT is equal to S_IT and S_CE, so should be set to 0 instead.\n");
1788 static const char *colorimetry_map[] = {
1789 "xvYCC601",
1790 "xvYCC709",
1791 "sYCC601",
1792 "opYCC601",
1793 "opRGB",
1794 "BT2020cYCC",
1795 "BT2020YCC",
1796 "BT2020RGB",
1799 static void cta_colorimetry_block(const unsigned char *x, unsigned length)
1801 unsigned i;
1803 if (length < 2) {
1804 fail("Empty Data Block with length %u.\n", length);
1805 return;
1807 for (i = 0; i < ARRAY_SIZE(colorimetry_map); i++) {
1808 if (x[0] & (1 << i))
1809 printf(" %s\n", colorimetry_map[i]);
1811 if (x[1] & 0x80)
1812 printf(" DCI-P3\n");
1813 if (x[1] & 0x40)
1814 printf(" ICtCp\n");
1817 static const char *eotf_map[] = {
1818 "Traditional gamma - SDR luminance range",
1819 "Traditional gamma - HDR luminance range",
1820 "SMPTE ST2084",
1821 "Hybrid Log-Gamma",
1824 static void cta_hdr_static_metadata_block(const unsigned char *x, unsigned length)
1826 unsigned i;
1828 if (length < 2) {
1829 fail("Empty Data Block with length %u.\n", length);
1830 return;
1832 printf(" Electro optical transfer functions:\n");
1833 for (i = 0; i < 6; i++) {
1834 if (x[0] & (1 << i)) {
1835 if (i < ARRAY_SIZE(eotf_map)) {
1836 printf(" %s\n", eotf_map[i]);
1837 } else {
1838 printf(" Unknown (%u)\n", i);
1839 fail("Unknown EOTF (%u).\n", i);
1843 printf(" Supported static metadata descriptors:\n");
1844 for (i = 0; i < 8; i++) {
1845 if (x[1] & (1 << i))
1846 printf(" Static metadata type %u\n", i + 1);
1849 if (length >= 3)
1850 printf(" Desired content max luminance: %u (%.3f cd/m^2)\n",
1851 x[2], 50.0 * pow(2, x[2] / 32.0));
1853 if (length >= 4)
1854 printf(" Desired content max frame-average luminance: %u (%.3f cd/m^2)\n",
1855 x[3], 50.0 * pow(2, x[3] / 32.0));
1857 if (length >= 5)
1858 printf(" Desired content min luminance: %u (%.3f cd/m^2)\n",
1859 x[4], (50.0 * pow(2, x[2] / 32.0)) * pow(x[4] / 255.0, 2) / 100.0);
1862 static void cta_hdr_dyn_metadata_block(const unsigned char *x, unsigned length)
1864 if (length < 3) {
1865 fail("Empty Data Block with length %u.\n", length);
1866 return;
1868 while (length >= 3) {
1869 unsigned type_len = x[0];
1870 unsigned type = x[1] | (x[2] << 8);
1872 if (length < type_len + 1)
1873 return;
1874 printf(" HDR Dynamic Metadata Type %u\n", type);
1875 switch (type) {
1876 case 1:
1877 case 4:
1878 if (type_len > 2)
1879 printf(" Version: %u\n", x[3] & 0xf);
1880 break;
1881 case 2:
1882 if (type_len > 2) {
1883 unsigned version = x[3] & 0xf;
1884 printf(" Version: %u\n", version);
1885 if (version >= 1) {
1886 if (x[3] & 0x10) printf(" Supports SL-HDR1 (ETSI TS 103 433-1)\n");
1887 if (x[3] & 0x20) printf(" Supports SL-HDR2 (ETSI TS 103 433-2)\n");
1888 if (x[3] & 0x40) printf(" Supports SL-HDR3 (ETSI TS 103 433-3)\n");
1891 break;
1892 default:
1893 break;
1895 length -= type_len + 1;
1896 x += type_len + 1;
1900 static void cta_ifdb(const unsigned char *x, unsigned length)
1902 unsigned len_hdr = x[0] >> 5;
1904 if (length < 2) {
1905 fail("Empty Data Block with length %u.\n", length);
1906 return;
1908 printf(" VSIFs: %u\n", x[1]);
1909 if (length < len_hdr + 2)
1910 return;
1911 length -= len_hdr + 2;
1912 x += len_hdr + 2;
1913 while (length > 0) {
1914 int payload_len = x[0] >> 5;
1916 if ((x[0] & 0x1f) == 1 && length >= 4) {
1917 unsigned oui = (x[3] << 16) | (x[2] << 8) | x[1];
1919 printf(" InfoFrame Type Code %u, OUI %s\n",
1920 x[0] & 0x1f, ouitohex(oui).c_str());
1921 x += 4;
1922 length -= 4;
1923 } else {
1924 printf(" InfoFrame Type Code %u\n", x[0] & 0x1f);
1925 x++;
1926 length--;
1928 x += payload_len;
1929 length -= payload_len;
1933 void edid_state::cta_displayid_type_7(const unsigned char *x, unsigned length)
1935 check_displayid_datablock_revision(x[0], 0x00, 2);
1937 if (length < 21U + ((x[0] & 0x70) >> 4)) {
1938 fail("Empty Data Block with length %u.\n", length);
1939 return;
1941 parse_displayid_type_1_7_timing(x + 1, true, 2, true);
1944 void edid_state::cta_displayid_type_8(const unsigned char *x, unsigned length)
1946 check_displayid_datablock_revision(x[0], 0xe8, 1);
1947 if (length < ((x[0] & 0x08) ? 3 : 2)) {
1948 fail("Empty Data Block with length %u.\n", length);
1949 return;
1952 unsigned sz = (x[0] & 0x08) ? 2 : 1;
1953 unsigned type = x[0] >> 6;
1955 if (type) {
1956 fail("Only code type 0 is supported.\n");
1957 return;
1960 if (x[0] & 0x20)
1961 printf(" Also supports YCbCr 4:2:0\n");
1963 x++;
1964 length--;
1965 for (unsigned i = 0; i < length / sz; i++) {
1966 unsigned id = x[i * sz];
1968 if (sz == 2)
1969 id |= x[i * sz + 1] << 8;
1970 parse_displayid_type_4_8_timing(type, id, true);
1974 void edid_state::cta_displayid_type_10(const unsigned char *x, unsigned length)
1976 check_displayid_datablock_revision(x[0], 0x70);
1977 if (length < 7U + ((x[0] & 0x70) >> 4)) {
1978 fail("Empty Data Block with length %u.\n", length);
1979 return;
1982 unsigned sz = 6U + ((x[0] & 0x70) >> 4);
1983 x++;
1984 length--;
1985 for (unsigned i = 0; i < length / sz; i++)
1986 parse_displayid_type_10_timing(x + i * sz, sz, true);
1989 static void cta_hdmi_audio_block(const unsigned char *x, unsigned length)
1991 unsigned num_descs;
1993 if (length < 2) {
1994 fail("Empty Data Block with length %u.\n", length);
1995 return;
1997 if (x[0] & 3)
1998 printf(" Max Stream Count: %u\n", (x[0] & 3) + 1);
1999 if (x[0] & 4)
2000 printf(" Supports MS NonMixed\n");
2002 num_descs = x[1] & 7;
2003 if (num_descs == 0)
2004 return;
2005 length -= 2;
2006 x += 2;
2007 while (length >= 4) {
2008 if (length > 4) {
2009 unsigned format = x[0] & 0xf;
2011 printf(" %s, max channels %u\n", audio_format(format).c_str(),
2012 (x[1] & 0x1f)+1);
2013 printf(" Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
2014 (x[2] & 0x40) ? " 192" : "",
2015 (x[2] & 0x20) ? " 176.4" : "",
2016 (x[2] & 0x10) ? " 96" : "",
2017 (x[2] & 0x08) ? " 88.2" : "",
2018 (x[2] & 0x04) ? " 48" : "",
2019 (x[2] & 0x02) ? " 44.1" : "",
2020 (x[2] & 0x01) ? " 32" : "");
2021 if (format == 1)
2022 printf(" Supported sample sizes (bits):%s%s%s\n",
2023 (x[3] & 0x04) ? " 24" : "",
2024 (x[3] & 0x02) ? " 20" : "",
2025 (x[3] & 0x01) ? " 16" : "");
2026 } else {
2027 unsigned sad = ((x[2] << 16) | (x[1] << 8) | x[0]);
2028 unsigned i;
2030 switch (x[3] >> 4) {
2031 case 1:
2032 printf(" Speaker Allocation for 10.2 channels:\n");
2033 break;
2034 case 2:
2035 printf(" Speaker Allocation for 22.2 channels:\n");
2036 break;
2037 case 3:
2038 printf(" Speaker Allocation for 30.2 channels:\n");
2039 break;
2040 default:
2041 printf(" Unknown Speaker Allocation (0x%02x)\n", x[3] >> 4);
2042 return;
2045 for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
2046 if ((sad >> i) & 1)
2047 printf(" %s\n", speaker_map[i]);
2050 length -= 4;
2051 x += 4;
2055 void edid_state::cta_block(const unsigned char *x, std::vector<unsigned> &found_tags)
2057 unsigned length = x[0] & 0x1f;
2058 unsigned tag = (x[0] & 0xe0) >> 5;
2059 unsigned extended = (tag == 0x07) ? 1 : 0;
2061 x++;
2062 if (extended && length) {
2063 tag <<= 8;
2064 tag |= x[0];
2065 length--;
2066 x++;
2069 bool dooutputname = true;
2070 bool audio_block = false;
2071 data_block.clear();
2073 switch (tag) {
2074 case 0x01: data_block = "Audio Data Block"; audio_block = true; break;
2075 case 0x02: data_block = "Video Data Block"; break;
2076 case 0x03: data_block = "Vendor-Specific Data Block"; break;
2077 case 0x04: data_block = "Speaker Allocation Data Block"; audio_block = true; break;
2078 case 0x05: data_block = "VESA Display Transfer Characteristics Data Block"; break;
2080 case 0x07: data_block = "Unknown CTA-861 Data Block (extended tag truncated)"; break;
2082 case 0x700: data_block = "Video Capability Data Block"; break;
2083 case 0x701: data_block = "Vendor-Specific Video Data Block"; break;
2084 case 0x702: data_block = "VESA Video Display Device Data Block"; break;
2085 case 0x703: data_block = "VESA Video Timing Block Extension"; break;
2086 case 0x704: data_block = "Reserved for HDMI Video Data Block"; break;
2087 case 0x705: data_block = "Colorimetry Data Block"; break;
2088 case 0x706: data_block = "HDR Static Metadata Data Block"; break;
2089 case 0x707: data_block = "HDR Dynamic Metadata Data Block"; break;
2091 case 0x70d: data_block = "Video Format Preference Data Block"; break;
2092 case 0x70e: data_block = "YCbCr 4:2:0 Video Data Block"; break;
2093 case 0x70f: data_block = "YCbCr 4:2:0 Capability Map Data Block"; break;
2094 case 0x710: data_block = "Reserved for CTA-861 Miscellaneous Audio Fields"; break;
2095 case 0x711: data_block = "Vendor-Specific Audio Data Block"; audio_block = true; break;
2096 case 0x712: data_block = "HDMI Audio Data Block"; audio_block = true; break;
2097 case 0x713: data_block = "Room Configuration Data Block"; audio_block = true; break;
2098 case 0x714: data_block = "Speaker Location Data Block"; audio_block = true; break;
2100 case 0x720: data_block = "InfoFrame Data Block"; break;
2102 case 0x722: data_block = "DisplayID Type VII Video Timing Data Block"; break;
2103 case 0x723: data_block = "DisplayID Type VIII Video Timing Data Block"; break;
2104 case 0x72a: data_block = "DisplayID Type X Video Timing Data Block"; break;
2106 case 0x778: data_block = "HDMI Forum EDID Extension Override Data Block"; break;
2107 case 0x779: data_block = "HDMI Forum Sink Capability Data Block"; break;
2109 default:
2110 std::string unknown_name;
2111 if (tag < 0x700) unknown_name = "Unknown CTA-861 Data Block";
2112 else if (tag < 0x70d) unknown_name = "Unknown CTA-861 Video-Related Data Block";
2113 else if (tag < 0x720) unknown_name = "Unknown CTA-861 Audio-Related Data Block";
2114 else if (tag < 0x778) unknown_name = "Unknown CTA-861 Data Block";
2115 else if (tag < 0x780) unknown_name = "Unknown CTA-861 HDMI-Related Data Block";
2116 else unknown_name = "Unknown CTA-861 Data Block";
2117 unknown_name += std::string(" (") + (extended ? "extended " : "") + "tag " + utohex(tag & 0xff) + ", length " + std::to_string(length) + ")";
2118 printf(" %s:\n", unknown_name.c_str());
2119 warn("%s.\n", unknown_name.c_str());
2120 break;
2123 switch (tag) {
2124 case 0x03:
2125 case 0x701:
2126 case 0x711: {
2127 unsigned ouinum;
2129 data_block_oui(data_block, x, length, &ouinum);
2130 x += (length < 3) ? length : 3;
2131 length -= (length < 3) ? length : 3;
2132 dooutputname = false;
2133 tag |= ouinum;
2134 break;
2138 if (dooutputname && data_block.length())
2139 printf(" %s:\n", data_block.c_str());
2141 switch (tag) {
2142 case 0x04:
2143 case 0x05:
2144 case 0x700:
2145 case 0x702:
2146 case 0x705:
2147 case 0x706:
2148 case 0x70d:
2149 case 0x70f:
2150 case 0x712:
2151 case 0x713:
2152 case 0x778:
2153 case 0x779:
2154 if (std::find(found_tags.begin(), found_tags.end(), tag) != found_tags.end())
2155 fail("Only one instance of this Data Block is allowed.\n");
2156 break;
2159 // See Table 52 of CTA-861-G for a description of Byte 3
2160 if (audio_block && !(cta.byte3 & 0x40))
2161 fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
2163 switch (tag) {
2164 case 0x01: cta_audio_block(x, length); break;
2165 case 0x02: cta_svd(x, length, false); break;
2166 case 0x03|kOUI_HDMI:
2167 cta_hdmi_block(x, length);
2168 // The HDMI OUI is present, so this EDID represents an HDMI
2169 // interface. And HDMI interfaces must use EDID version 1.3
2170 // according to the HDMI Specification, so check for this.
2171 if (base.edid_minor != 3)
2172 fail("The HDMI Specification requires EDID 1.3 instead of 1.%u.\n",
2173 base.edid_minor);
2174 break;
2175 case 0x03|kOUI_HDMIForum:
2176 if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
2177 fail("HDMI Forum VSDB did not immediately follow the HDMI VSDB.\n");
2178 if (cta.have_hf_scdb || cta.have_hf_vsdb)
2179 fail("Duplicate HDMI Forum VSDB/SCDB.\n");
2180 cta_hf_scdb(x, length);
2181 cta.have_hf_vsdb = true;
2182 break;
2183 case 0x03|kOUI_AMD: cta_amd(x, length); break;
2184 case 0x03|kOUI_Microsoft: if (length != 0x12) goto dodefault; cta_microsoft(x, length); break;
2185 case 0x04: cta_sadb(x, length); break;
2186 case 0x05: cta_vesa_dtcdb(x, length); break;
2187 case 0x07: fail("Extended tag cannot have zero length.\n"); break;
2188 case 0x700: cta_vcdb(x, length); break;
2189 case 0x701|kOUI_HDR10: cta_hdr10plus(x, length); break;
2190 case 0x701|kOUI_Dolby: cta_dolby_video(x, length); break;
2191 // 0x701|kOUI_Apple: this almost certainly contains 'BLC Info/Corrections',
2192 // since the data (spread out over two VSDBs) is very similar to what is seen
2193 // in DisplayID blocks. Since I don't know how to parse this data, we still
2194 // default to a hex dump, but I mention this here in case data on how to
2195 // parse this becomes available.
2196 case 0x702: cta_vesa_vdddb(x, length); break;
2197 case 0x705: cta_colorimetry_block(x, length); break;
2198 case 0x706: cta_hdr_static_metadata_block(x, length); break;
2199 case 0x707: cta_hdr_dyn_metadata_block(x, length); break;
2200 case 0x70d: cta_vfpdb(x, length); break;
2201 case 0x70e: cta_svd(x, length, true); break;
2202 case 0x70f: cta_y420cmdb(x, length); break;
2203 case 0x711|kOUI_Dolby: cta_dolby_audio(x, length); break;
2204 case 0x712: cta_hdmi_audio_block(x, length); break;
2205 case 0x713: cta_rcdb(x, length); break;
2206 case 0x714: cta_sldb(x, length); break;
2207 case 0x720: cta_ifdb(x, length); break;
2208 case 0x722: cta_displayid_type_7(x, length); break;
2209 case 0x723: cta_displayid_type_8(x, length); break;
2210 case 0x72a: cta_displayid_type_10(x, length); break;
2211 case 0x778:
2212 cta_hf_eeodb(x, length);
2213 // This must be the first CTA-861 block
2214 if (cta.block_number > 0)
2215 fail("Block starts at a wrong offset.\n");
2216 break;
2217 case 0x779:
2218 if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
2219 fail("HDMI Forum SCDB did not immediately follow the HDMI VSDB.\n");
2220 if (cta.have_hf_scdb || cta.have_hf_vsdb)
2221 fail("Duplicate HDMI Forum VSDB/SCDB.\n");
2222 if (length < 2) {
2223 data_block = std::string("HDMI Forum SCDB");
2224 fail("Invalid length %u < 2.\n", length);
2225 break;
2227 if (x[0] || x[1])
2228 printf(" Non-zero SCDB reserved fields!\n");
2229 cta_hf_scdb(x + 2, length - 2);
2230 cta.have_hf_scdb = true;
2231 break;
2232 dodefault:
2233 default:
2234 hex_block(" ", x, length);
2235 break;
2238 cta.block_number++;
2239 cta.previous_cta_tag = tag;
2240 found_tags.push_back(tag);
2243 void edid_state::preparse_cta_block(const unsigned char *x)
2245 unsigned version = x[1];
2246 unsigned offset = x[2];
2248 if (offset >= 4) {
2249 const unsigned char *detailed;
2251 for (detailed = x + offset; detailed + 17 < x + 127; detailed += 18) {
2252 if (memchk(detailed, 18))
2253 break;
2254 if (detailed[0] || detailed[1])
2255 cta.preparsed_total_dtds++;
2259 if (version < 3)
2260 return;
2262 for (unsigned i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
2263 bool for_ycbcr420 = false;
2264 unsigned oui;
2266 switch ((x[i] & 0xe0) >> 5) {
2267 case 0x03:
2268 oui = (x[i + 3] << 16) + (x[i + 2] << 8) + x[i + 1];
2269 if (oui == 0x000c03) {
2270 cta.has_hdmi = true;
2271 cta.preparsed_phys_addr = (x[i + 4] << 8) | x[i + 5];
2273 break;
2274 case 0x07:
2275 if (x[i + 1] == 0x0d)
2276 cta.has_vfpdb = true;
2277 if (x[i + 1] == 0x13 && (x[i + 2] & 0x40)) {
2278 cta.preparsed_speaker_count = 1 + (x[i + 2] & 0x1f);
2279 cta.preparsed_sld = x[i + 2] & 0x20;
2281 if (x[i + 1] == 0x14)
2282 cta_preparse_sldb(x + i + 2, (x[i] & 0x1f) - 1);
2283 if (x[i + 1] == 0x22)
2284 cta.preparsed_total_vtdbs++;
2285 if (x[i + 1] == 0x23)
2286 cta.preparsed_has_t8vtdb = true;
2287 if (x[i + 1] == 0x2a)
2288 cta.preparsed_total_vtdbs +=
2289 ((x[i] & 0x1f) - 2) / (6 + ((x[i + 2] & 0x70) >> 4));
2290 if (x[i + 1] != 0x0e)
2291 continue;
2292 for_ycbcr420 = true;
2293 /* fall-through */
2294 case 0x02:
2295 for (unsigned j = 1 + for_ycbcr420; j <= (x[i] & 0x1f); j++) {
2296 unsigned char vic = x[i + j];
2298 if ((vic & 0x7f) <= 64)
2299 vic &= 0x7f;
2300 cta.preparsed_svds[for_ycbcr420].push_back(vic);
2301 cta.preparsed_has_vic[for_ycbcr420][vic] = true;
2303 break;
2308 void edid_state::parse_cta_block(const unsigned char *x)
2310 unsigned version = x[1];
2311 unsigned offset = x[2];
2312 const unsigned char *detailed;
2314 // See Table 52 of CTA-861-G for a description of Byte 3
2316 printf(" Revision: %u\n", version);
2317 if (version == 0)
2318 fail("Invalid CTA-861 Extension revision 0.\n");
2319 if (version == 2)
2320 fail("Deprecated CTA-861 Extension revision 2.\n");
2321 if (cta.has_hdmi && version != 3)
2322 fail("The HDMI Specification requires CTA Extension revision 3.\n");
2323 if (version > 3)
2324 warn("Unknown CTA-861 Extension revision %u.\n", version);
2326 if (version >= 1) do {
2327 if (version == 1 && x[3] != 0)
2328 fail("Non-zero byte 3.\n");
2330 if (offset < 4)
2331 break;
2333 if (version < 3 && ((offset - 4) / 8)) {
2334 printf(" 8-byte timing descriptors: %u\n", (offset - 4) / 8);
2335 fail("8-byte descriptors were never used.\n");
2338 if (version >= 2) {
2339 if (x[3] & 0x80)
2340 printf(" Underscans IT Video Formats by default\n");
2341 else
2342 warn("IT Video Formats are overscanned by default, but normally this should be underscanned.\n");
2343 if (x[3] & 0x40)
2344 printf(" Basic audio support\n");
2345 if (x[3] & 0x20)
2346 printf(" Supports YCbCr 4:4:4\n");
2347 if (x[3] & 0x10)
2348 printf(" Supports YCbCr 4:2:2\n");
2349 // Disable this test: this fails a lot of EDIDs, and there are
2350 // also some corner cases where you only want to receive 4:4:4
2351 // and refuse a fallback to 4:2:2.
2352 // if ((x[3] & 0x30) && (x[3] & 0x30) != 0x30)
2353 // msg(!cta.has_hdmi, "If YCbCr support is indicated, then both 4:2:2 and 4:4:4 %s be supported.\n",
2354 // cta.has_hdmi ? "shall" : "should");
2355 printf(" Native detailed modes: %u\n", x[3] & 0x0f);
2356 if (cta.block_number == 0)
2357 cta.byte3 = x[3];
2358 else if (x[3] != cta.byte3)
2359 fail("Byte 3 must be the same for all CTA-861 Extension Blocks.\n");
2360 if (cta.block_number == 0) {
2361 unsigned native_dtds = x[3] & 0x0f;
2363 cta.native_timings.clear();
2364 if (!native_dtds && !cta.has_vfpdb) {
2365 cta.first_svd_might_be_preferred = true;
2366 } else if (native_dtds > cta.preparsed_total_dtds) {
2367 fail("There are more Native DTDs (%u) than DTDs (%u).\n",
2368 native_dtds, cta.preparsed_total_dtds);
2370 if (native_dtds > cta.preparsed_total_dtds)
2371 native_dtds = cta.preparsed_total_dtds;
2372 for (unsigned i = 0; i < native_dtds; i++) {
2373 char type[16];
2375 sprintf(type, "DTD %3u", i + 1);
2376 cta.native_timings.push_back(timings_ext(i + 129, type));
2378 if (cta.has_hdmi && block_nr != (block_map.saw_block_1 ? 2 : 1))
2379 fail("The HDMI Specification requires that the first Extension Block (that is not a Block Map) is an CTA-861 Extension Block.\n");
2382 if (version >= 3) {
2383 unsigned i;
2385 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
2386 cta_block(x + i, cta.found_tags);
2389 data_block.clear();
2390 if (i != offset)
2391 fail("Offset is %u, but should be %u.\n", offset, i);
2394 data_block = "Detailed Timing Descriptors";
2395 base.seen_non_detailed_descriptor = false;
2396 bool first = true;
2397 for (detailed = x + offset; detailed + 17 < x + 127; detailed += 18) {
2398 if (memchk(detailed, 18))
2399 break;
2400 if (first) {
2401 first = false;
2402 printf(" %s:\n", data_block.c_str());
2404 detailed_block(detailed);
2406 if (!memchk(detailed, x + 127 - detailed)) {
2407 data_block = "Padding";
2408 fail("CTA-861 padding contains non-zero bytes.\n");
2410 } while (0);
2412 data_block.clear();
2413 if (base.has_serial_number && base.has_serial_string)
2414 warn("Display Product Serial Number is set, so the Serial Number in the Base EDID should be 0.\n");
2415 if (!cta.has_vic_1 && !base.has_640x480p60_est_timing)
2416 fail("Required 640x480p60 timings are missing in the established timings"
2417 " and the SVD list (VIC 1).\n");
2418 if ((cta.supported_hdmi_vic_vsb_codes & cta.supported_hdmi_vic_codes) !=
2419 cta.supported_hdmi_vic_codes)
2420 fail("HDMI VIC Codes must have their CTA-861 VIC equivalents in the VSB.\n");
2421 if (!cta.has_vcdb)
2422 fail("Missing VCDB, needed for Set Selectable RGB Quantization to avoid interop issues.\n");
2425 void edid_state::cta_resolve_svr(vec_timings_ext::iterator iter)
2427 if (iter->svr() == 254) {
2428 iter->flags = cta.t8vtdb.flags;
2429 iter->t = cta.t8vtdb.t;
2430 } else if (iter->svr() <= 144) {
2431 iter->flags = cta.vec_dtds[iter->svr() - 129].flags;
2432 iter->t = cta.vec_dtds[iter->svr() - 129].t;
2433 } else {
2434 iter->flags = cta.vec_vtdbs[iter->svr() - 145].flags;
2435 iter->t = cta.vec_vtdbs[iter->svr() - 145].t;
2439 void edid_state::cta_resolve_svrs()
2441 for (vec_timings_ext::iterator iter = cta.preferred_timings.begin();
2442 iter != cta.preferred_timings.end(); ++iter) {
2443 if (iter->has_svr())
2444 cta_resolve_svr(iter);
2447 for (vec_timings_ext::iterator iter = cta.native_timings.begin();
2448 iter != cta.native_timings.end(); ++iter) {
2449 if (iter->has_svr())
2450 cta_resolve_svr(iter);
2454 void edid_state::check_cta_blocks()
2456 unsigned max_pref_prog_hact = 0;
2457 unsigned max_pref_prog_vact = 0;
2458 unsigned max_pref_ilace_hact = 0;
2459 unsigned max_pref_ilace_vact = 0;
2461 data_block = "CTA-861";
2462 for (vec_timings_ext::iterator iter = cta.preferred_timings.begin();
2463 iter != cta.preferred_timings.end(); ++iter) {
2464 if (iter->t.interlaced &&
2465 (iter->t.vact > max_pref_ilace_vact ||
2466 (iter->t.vact == max_pref_ilace_vact && iter->t.hact >= max_pref_ilace_hact))) {
2467 max_pref_ilace_hact = iter->t.hact;
2468 max_pref_ilace_vact = iter->t.vact;
2470 if (!iter->t.interlaced &&
2471 (iter->t.vact > max_pref_prog_vact ||
2472 (iter->t.vact == max_pref_prog_vact && iter->t.hact >= max_pref_prog_hact))) {
2473 max_pref_prog_hact = iter->t.hact;
2474 max_pref_prog_vact = iter->t.vact;
2478 unsigned native_prog = 0;
2479 unsigned native_prog_hact = 0;
2480 unsigned native_prog_vact = 0;
2481 bool native_prog_mixed_resolutions = false;
2482 unsigned native_ilace = 0;
2483 unsigned native_ilace_hact = 0;
2484 unsigned native_ilace_vact = 0;
2485 bool native_ilace_mixed_resolutions = false;
2487 for (vec_timings_ext::iterator iter = cta.native_timings.begin();
2488 iter != cta.native_timings.end(); ++iter) {
2489 if (iter->t.interlaced) {
2490 native_ilace++;
2491 if (!native_ilace_hact) {
2492 native_ilace_hact = iter->t.hact;
2493 native_ilace_vact = iter->t.vact;
2494 } else if (native_ilace_hact != iter->t.hact ||
2495 native_ilace_vact != iter->t.vact) {
2496 native_ilace_mixed_resolutions = true;
2498 } else {
2499 native_prog++;
2500 if (!native_prog_hact) {
2501 native_prog_hact = iter->t.hact;
2502 native_prog_vact = iter->t.vact;
2503 } else if (native_prog_hact != iter->t.hact ||
2504 native_prog_vact != iter->t.vact) {
2505 native_prog_mixed_resolutions = true;
2510 if (native_prog_mixed_resolutions)
2511 fail("Native progressive timings are a mix of several resolutions.\n");
2512 if (native_ilace_mixed_resolutions)
2513 fail("Native interlaced timings are a mix of several resolutions.\n");
2514 if (native_ilace && !native_prog)
2515 fail("A native interlaced timing is present, but not a native progressive timing.\n");
2516 if (!native_prog_mixed_resolutions && native_prog > 1)
2517 warn("Multiple native progressive timings are defined.\n");
2518 if (!native_ilace_mixed_resolutions && native_ilace > 1)
2519 warn("Multiple native interlaced timings are defined.\n");
2521 if (!native_prog_mixed_resolutions && native_prog_vact &&
2522 (max_pref_prog_vact > native_prog_vact ||
2523 (max_pref_prog_vact == native_prog_vact && max_pref_prog_hact > native_prog_hact)))
2524 warn("Native progressive resolution of %ux%u is smaller than the max preferred progressive resolution %ux%u.\n",
2525 native_prog_hact, native_prog_vact,
2526 max_pref_prog_hact, max_pref_prog_vact);
2527 if (!native_ilace_mixed_resolutions && native_ilace_vact &&
2528 (max_pref_ilace_vact > native_ilace_vact ||
2529 (max_pref_ilace_vact == native_ilace_vact && max_pref_ilace_hact > native_ilace_hact)))
2530 warn("Native interlaced resolution of %ux%u is smaller than the max preferred interlaced resolution %ux%u.\n",
2531 native_ilace_hact, native_ilace_vact,
2532 max_pref_ilace_hact, max_pref_ilace_vact);
2534 if (dispid.native_width && native_prog_hact &&
2535 !native_prog_mixed_resolutions) {
2536 if (dispid.native_width != native_prog_hact ||
2537 dispid.native_height != native_prog_vact)
2538 fail("Mismatch between CTA-861 and DisplayID native progressive resolution.\n");