Debian Codegraph @

utils/edid-decode/parse-cta-block.cpp

raw
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.
5 *
6 * Author: Adam Jackson <[email protected]>
7 * Maintainer: Hans Verkuil <[email protected]>
8 */
9
10 #include <algorithm>
11 #include <stdio.h>
12 #include <math.h>
13
14 #include "edid-decode.h"
15
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 },
157 };
158
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 },
190 };
191
192 static const cta_rid rids[] = {
193 /* RID 0-9 */
194 { 0, 0, 0, 0 },
195 { 1280, 720, 16, 9 },
196 { 1280, 720, 64, 27 },
197 { 1680, 720, 64, 27 },
198 { 1920, 1080, 16, 9 },
199 { 1920, 1080, 64, 27 },
200 { 2560, 1080, 64, 27 },
201 { 3840, 1080, 32, 9 },
202 { 2560, 1440, 16, 9 },
203 { 3440, 1440, 64, 27 },
204 /* RID 10-19 */
205 { 5120, 1440, 32, 9 },
206 { 3840, 2160, 16, 9 },
207 { 3840, 2160, 64, 27 },
208 { 5120, 2160, 64, 27 },
209 { 7680, 2160, 32, 9 },
210 { 5120, 2880, 16, 9 },
211 { 5120, 2880, 64, 27 },
212 { 6880, 2880, 64, 27 },
213 { 10240, 2880, 32, 9 },
214 { 7680, 4320, 16, 9 },
215 /* RID 20-28 */
216 { 7680, 4320, 64, 27 },
217 { 10240, 4320, 64, 27 },
218 { 15360, 4320, 32, 9 },
219 { 11520, 6480, 16, 9 },
220 { 11520, 6480, 64, 27 },
221 { 15360, 6480, 64, 27 },
222 { 15360, 8640, 16, 9 },
223 { 15360, 8640, 64, 27 },
224 { 20480, 8640, 64, 27 },
225 };
226
227 static const unsigned char rid2vic[ARRAY_SIZE(rids)][8] = {
228 /* RID 0-9 */
229 {},
230 { 60, 61, 62, 108, 19, 4, 41, 47 },
231 { 65, 66, 67, 109, 68, 69, 70, 71 },
232 { 79, 80, 81, 110, 82, 83, 84, 85 },
233 { 32, 33, 34, 111, 31, 16, 64, 63 },
234 { 72, 73, 74, 112, 75, 76, 77, 78 },
235 { 86, 87, 88, 113, 89, 90, 91, 92 },
236 {},
237 {},
238 {},
239 /* RID 10-19 */
240 {},
241 { 93, 94, 95, 114, 96, 97, 117, 118 },
242 { 103, 104, 105, 116, 106, 107, 119, 120 },
243 { 121, 122, 123, 124, 125, 126, 127, 193 },
244 {},
245 {},
246 {},
247 {},
248 {},
249 { 194, 195, 196, 197, 198, 199, 200, 201 },
250 /* RID 20-28 */
251 { 202, 203, 204, 205, 206, 207, 208, 209 },
252 { 210, 211, 212, 213, 214, 215, 216, 217 },
253 {},
254 {},
255 {},
256 {},
257 {},
258 {},
259 {},
260 };
261
262 static const unsigned vf_rate_values[] = {
263 /* Rate Index 0-7 */
264 0, 24, 25, 30, 48, 50, 60, 100,
265 /* Rate Index 8-15 */
266 120, 144, 200, 240, 300, 360, 400, 480,
267 };
268
269 static const unsigned char edid_hdmi_mode_map[] = { 95, 94, 93, 98 };
270
271 unsigned char hdmi_vic_to_vic(unsigned char hdmi_vic)
272 {
273 if (hdmi_vic > 0 && hdmi_vic <= ARRAY_SIZE(edid_hdmi_mode_map))
274 return edid_hdmi_mode_map[hdmi_vic - 1];
275 return 0;
276 }
277
278 const struct timings *find_vic_id(unsigned char vic)
279 {
280 if (vic > 0 && vic <= ARRAY_SIZE(edid_cta_modes1))
281 return edid_cta_modes1 + vic - 1;
282 if (vic >= 193 && vic < ARRAY_SIZE(edid_cta_modes2) + 193)
283 return edid_cta_modes2 + vic - 193;
284 return NULL;
285 }
286
287 const struct timings *find_hdmi_vic_id(unsigned char hdmi_vic)
288 {
289 if (hdmi_vic > 0 && hdmi_vic <= ARRAY_SIZE(edid_hdmi_mode_map))
290 return find_vic_id(edid_hdmi_mode_map[hdmi_vic - 1]);
291 return NULL;
292 }
293
294 const struct cta_rid *find_rid(unsigned char rid)
295 {
296 if (rid > 0 && rid < ARRAY_SIZE(rids))
297 return &rids[rid];
298 return NULL;
299 }
300
301 static unsigned char rid_to_vic(unsigned char rid, unsigned char rate_index)
302 {
303 if (vf_rate_values[rate_index] > 120)
304 return 0;
305 return rid2vic[rid][rate_index - 1];
306 }
307
308 unsigned char rid_fps_to_vic(unsigned char rid, unsigned fps)
309 {
310 for (unsigned i = 1; i < ARRAY_SIZE(vf_rate_values); i++) {
311 if (vf_rate_values[i] == fps)
312 return rid2vic[rid][i - 1];
313 }
314 return 0;
315 }
316
317 const struct timings *cta_close_match_to_vic(const timings &t, unsigned &vic)
318 {
319 for (vic = 1; vic <= ARRAY_SIZE(edid_cta_modes1); vic++) {
320 if (timings_close_match(t, edid_cta_modes1[vic - 1]))
321 return &edid_cta_modes1[vic - 1];
322 }
323 for (vic = 193; vic < ARRAY_SIZE(edid_cta_modes2) + 193; vic++) {
324 if (timings_close_match(t, edid_cta_modes1[vic - 193]))
325 return &edid_cta_modes1[vic - 193];
326 }
327 vic = 0;
328 return NULL;
329 }
330
331 bool cta_matches_vic(const timings &t, unsigned &vic)
332 {
333 for (vic = 1; vic <= ARRAY_SIZE(edid_cta_modes1); vic++) {
334 if (match_timings(t, edid_cta_modes1[vic - 1]))
335 return true;
336 }
337 for (vic = 193; vic < ARRAY_SIZE(edid_cta_modes2) + 193; vic++) {
338 if (match_timings(t, edid_cta_modes1[vic - 193]))
339 return true;
340 }
341 vic = 0;
342 return false;
343 }
344
345 void edid_state::cta_list_vics()
346 {
347 char type[16];
348 for (unsigned vic = 1; vic <= ARRAY_SIZE(edid_cta_modes1); vic++) {
349 sprintf(type, "VIC %3u", vic);
350 print_timings("", &edid_cta_modes1[vic - 1], type, "", false, false);
351 }
352 for (unsigned vic = 193; vic < ARRAY_SIZE(edid_cta_modes2) + 193; vic++) {
353 sprintf(type, "VIC %3u", vic);
354 print_timings("", &edid_cta_modes2[vic - 193], type, "", false, false);
355 }
356 }
357
358 void edid_state::cta_list_hdmi_vics()
359 {
360 for (unsigned i = 0; i < ARRAY_SIZE(edid_hdmi_mode_map); i++) {
361 unsigned vic = edid_hdmi_mode_map[i];
362 char type[16];
363
364 sprintf(type, "HDMI VIC %u", i + 1);
365 print_timings("", find_vic_id(vic), type, "", false, false);
366 }
367 }
368
369 void edid_state::cta_list_rids()
370 {
371 for (unsigned i = 1; i < ARRAY_SIZE(rids); i++) {
372 printf("RID %2u: %5ux%-4u %2u:%-2u\n", i,
373 rids[i].hact, rids[i].vact,
374 rids[i].hratio, rids[i].vratio);
375 }
376 }
377
378 void edid_state::cta_list_rid_timings(unsigned list_rid)
379 {
380 for (unsigned rid = 1; rid < ARRAY_SIZE(rids); rid++) {
381 char type[16];
382
383 if (list_rid && rid != list_rid)
384 continue;
385
386 sprintf(type, "RID %u", rid);
387 for (unsigned i = 1; i < ARRAY_SIZE(vf_rate_values); i++) {
388 unsigned fps = vf_rate_values[i];
389
390 if (rid_to_vic(rid, i)) {
391 printf("%s: %5ux%-4u %7.3f Hz %3u:%-2u maps to VIC %u\n", type,
392 rids[rid].hact, rids[rid].vact, (double)fps,
393 rids[rid].hratio, rids[rid].vratio,
394 rid_to_vic(rid, i));
395 continue;
396 }
397 timings t = calc_ovt_mode(rids[rid].hact, rids[rid].vact,
398 rids[rid].hratio, rids[rid].vratio, fps);
399 print_timings("", &t, type, "", false, false);
400 }
401 }
402 }
403
404 static std::string audio_ext_format(unsigned char x)
405 {
406 if (x >= 1 && x <= 3)
407 fail("Obsolete Audio Ext Format 0x%02x.\n", x);
408 switch (x) {
409 case 1: return "HE AAC (Obsolete)";
410 case 2: return "HE AAC v2 (Obsolete)";
411 case 3: return "MPEG Surround (Obsolete)";
412 case 4: return "MPEG-4 HE AAC";
413 case 5: return "MPEG-4 HE AAC v2";
414 case 6: return "MPEG-4 AAC LC";
415 case 7: return "DRA";
416 case 8: return "MPEG-4 HE AAC + MPEG Surround";
417 case 10: return "MPEG-4 AAC LC + MPEG Surround";
418 case 11: return "MPEG-H 3D Audio";
419 case 12: return "AC-4";
420 case 13: return "L-PCM 3D Audio";
421 case 14: return "Auro-Cx";
422 case 15: return "MPEG-D USAC";
423 default: break;
424 }
425 fail("Unknown Audio Ext Format 0x%02x.\n", x);
426 return std::string("Unknown Audio Ext Format (") + utohex(x) + ")";
427 }
428
429 static std::string audio_format(unsigned char x)
430 {
431 switch (x) {
432 case 1: return "Linear PCM";
433 case 2: return "AC-3";
434 case 3: return "MPEG 1 (Layers 1 & 2)";
435 case 4: return "MPEG 1 Layer 3 (MP3)";
436 case 5: return "MPEG2 (multichannel)";
437 case 6: return "AAC LC";
438 case 7: return "DTS";
439 case 8: return "ATRAC";
440 case 9: return "One Bit Audio";
441 case 10: return "Enhanced AC-3 (DD+)";
442 case 11: return "DTS-HD";
443 case 12: return "MAT (MLP)";
444 case 13: return "DST";
445 case 14: return "WMA Pro";
446 default: break;
447 }
448 fail("Unknown Audio Format 0x%02x.\n", x);
449 return std::string("Unknown Audio Format (") + utohex(x) + ")";
450 }
451
452 static std::string mpeg_h_3d_audio_level(unsigned char x)
453 {
454 switch (x) {
455 case 0: return "Unspecified";
456 case 1: return "Level 1";
457 case 2: return "Level 2";
458 case 3: return "Level 3";
459 case 4: return "Level 4";
460 case 5: return "Level 5";
461 default: break;
462 }
463 fail("Unknown MPEG-H 3D Audio Level 0x%02x.\n", x);
464 return std::string("Unknown MPEG-H 3D Audio Level (") + utohex(x) + ")";
465 }
466
467 void edid_state::cta_audio_block(const unsigned char *x, unsigned length)
468 {
469 unsigned i, format, ext_format;
470
471 if (length % 3) {
472 fail("Broken CTA-861 audio block length %d.\n", length);
473 return;
474 }
475
476 for (i = 0; i < length; i += 3) {
477 format = (x[i] & 0x78) >> 3;
478 if (format == 0) {
479 printf(" Reserved (0x00)\n");
480 fail("Audio Format Code 0x00 is reserved.\n");
481 continue;
482 }
483 if (format != 15) {
484 ext_format = 0;
485 printf(" %s:\n", audio_format(format).c_str());
486 } else {
487 ext_format = (x[i + 2] & 0xf8) >> 3;
488 printf(" %s:\n", audio_ext_format(ext_format).c_str());
489 }
490 if (format != 15)
491 printf(" Max channels: %u\n", (x[i] & 0x07)+1);
492 else if (ext_format == 11)
493 printf(" MPEG-H 3D Audio Level: %s\n",
494 mpeg_h_3d_audio_level(x[i] & 0x07).c_str());
495 else if (ext_format == 13)
496 printf(" Max channels: %u\n",
497 (((x[i + 1] & 0x80) >> 3) | ((x[i] & 0x80) >> 4) |
498 (x[i] & 0x07))+1);
499 else if ((ext_format == 12 || ext_format == 14) && (x[i] & 0x07))
500 fail("Bits F10-F12 must be 0.\n");
501 else
502 printf(" Max channels: %u\n", (x[i] & 0x07)+1);
503
504 if ((format == 1 || format == 14) && (x[i + 2] & 0xf8))
505 fail("Bits F33-F37 must be 0.\n");
506 if (ext_format != 13 && (x[i+1] & 0x80))
507 fail("Bit F27 must be 0.\n");
508
509 // Several sample rates are not supported in certain formats
510 if (ext_format == 12 && (x[i+1] & 0x29))
511 fail("Bits F20, F23 and F25 must be 0.\n");
512 if (ext_format >= 4 && ext_format <= 6 && (x[i+1] & 0x60))
513 fail("Bits F25 and F26 must be 0.\n");
514 if ((ext_format == 8 || ext_format == 10 || ext_format == 15) && (x[i+1] & 0x60))
515 fail("Bits F25 and F26 must be 0.\n");
516
517 printf(" Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
518 (x[i+1] & 0x40) ? " 192" : "",
519 (x[i+1] & 0x20) ? " 176.4" : "",
520 (x[i+1] & 0x10) ? " 96" : "",
521 (x[i+1] & 0x08) ? " 88.2" : "",
522 (x[i+1] & 0x04) ? " 48" : "",
523 (x[i+1] & 0x02) ? " 44.1" : "",
524 (x[i+1] & 0x01) ? " 32" : "");
525 if (format == 1 || ext_format == 13) {
526 printf(" Supported sample sizes (bits):%s%s%s\n",
527 (x[i+2] & 0x04) ? " 24" : "",
528 (x[i+2] & 0x02) ? " 20" : "",
529 (x[i+2] & 0x01) ? " 16" : "");
530 } else if (format <= 8) {
531 printf(" Maximum bit rate: %u kb/s\n", x[i+2] * 8);
532 } else if (format == 10) {
533 // As specified by the "Dolby Audio and Dolby Atmos over HDMI"
534 // specification (v1.0).
535 if (x[i+2] & 1)
536 printf(" Supports Joint Object Coding\n");
537 if (x[i+2] & 2)
538 printf(" Supports Joint Object Coding with ACMOD28\n");
539 } else if (format == 11) {
540 // Reverse engineering, see:
541 // https://www.avsforum.com/threads/lg-c9-earc-info-thread.3072900/post-61795538
542 if (x[i+2] & 2)
543 printf(" Supports DTS:X\n");
544 // Note: I strongly suspect that bit 0 indicates DTS-HD MA support.
545 printf(" Audio Format Code dependent value: 0x%02x\n", x[i+2]);
546 } else if (format == 12) {
547 if (x[i+2] & 1) {
548 printf(" Supports Dolby TrueHD, object audio PCM and channel-based PCM\n");
549 printf(" Hash calculation %srequired for object audio PCM or channel-based PCM\n",
550 (x[i+2] & 2) ? "not " : "");
551 } else {
552 printf(" Supports only Dolby TrueHD\n");
553 }
554 } else if (format == 14) {
555 printf(" Profile: %u\n", x[i+2] & 7);
556 } else if (format >= 9 && format <= 13) {
557 printf(" Audio Format Code dependent value: 0x%02x\n", x[i+2]);
558 } else if (ext_format == 11 && (x[i+2] & 1)) {
559 printf(" Supports MPEG-H 3D Audio Low Complexity Profile\n");
560 } else if ((ext_format >= 4 && ext_format <= 6) ||
561 ext_format == 8 || ext_format == 10) {
562 printf(" AAC audio frame lengths:%s%s\n",
563 (x[i+2] & 4) ? " 1024_TL" : "",
564 (x[i+2] & 2) ? " 960_TL" : "");
565 if (ext_format >= 8 && (x[i+2] & 1))
566 printf(" Supports %s signaled MPEG Surround data\n",
567 (x[i+2] & 1) ? "implicitly and explicitly" : "only implicitly");
568 if (ext_format == 6 && (x[i+2] & 1))
569 printf(" Supports 22.2ch System H\n");
570 } else if (ext_format == 12 || ext_format == 14) {
571 printf(" Audio Format Code dependent value: %u\n", x[i+2] & 7);
572 }
573 }
574 }
575
576 void edid_state::cta_svd(const unsigned char *x, unsigned n, bool for_ycbcr420)
577 {
578 bool ascending = !for_ycbcr420;
579 unsigned char last_vic = 0;
580 bool first_vic_is_1_to_4 = false;
581 bool have_vics_5_and_up = false;
582 unsigned i;
583
584 if (!n)
585 fail("This Data Block is empty.\n");
586 for (i = 0; i < n; i++) {
587 const struct timings *t = NULL;
588 unsigned char svd = x[i];
589 unsigned char native;
590 unsigned char vic;
591
592 if ((svd & 0x7f) == 0)
593 continue;
594
595 if ((svd - 1) & 0x40) {
596 vic = svd;
597 native = 0;
598 if (cta.avi_version == 2)
599 cta.avi_version = 3;
600 } else {
601 vic = svd & 0x7f;
602 native = svd & 0x80;
603 }
604
605 if (i == 0)
606 first_vic_is_1_to_4 = vic <= 4;
607 if (vic > 4)
608 have_vics_5_and_up = true;
609 if (vic < last_vic)
610 ascending = false;
611 last_vic = vic;
612
613 t = find_vic_id(vic);
614 if (t) {
615 switch (vic) {
616 case 95:
617 cta.supported_hdmi_vic_vsb_codes |= 1 << 0;
618 break;
619 case 94:
620 cta.supported_hdmi_vic_vsb_codes |= 1 << 1;
621 break;
622 case 93:
623 cta.supported_hdmi_vic_vsb_codes |= 1 << 2;
624 break;
625 case 98:
626 cta.supported_hdmi_vic_vsb_codes |= 1 << 3;
627 break;
628 }
629 bool first_svd = cta.first_svd && !for_ycbcr420;
630
631 char type[16];
632 sprintf(type, "VIC %3u", vic);
633 const char *flags = native ? "native" : "";
634
635 if (for_ycbcr420) {
636 struct timings tmp = *t;
637 tmp.ycbcr420 = true;
638 print_timings(" ", &tmp, type, flags);
639 cta.has_ycbcr420 = true;
640 } else {
641 print_timings(" ", t, type, flags);
642 }
643 if (first_svd && !cta.preferred_timings.empty()) {
644 if (!match_timings(cta.preferred_timings[0].t, *t)) {
645 // The DTD can't handle width or height >= 4096. If the first
646 // VIC has a width or height >= 4096, then adding VFPDB and
647 // NVRDB data blocks is strongly recommended.
648 if (t->vact < 4096 && t->hact < 4096)
649 warn("VIC %u and the first DTD are not identical. Is this intended?\n", vic);
650 else if (!cta.has_vfpdb)
651 warn("The first VIC %u has width or height >= 4096, adding a VFPDB and NVRDB is strongly recommended.\n", vic);
652 } else if (cta.first_svd_might_be_preferred) {
653 warn("For improved preferred timing interoperability, set 'Native detailed modes' to 1.\n");
654 }
655 }
656 if (first_svd) {
657 if (cta.first_svd_might_be_preferred)
658 cta.preferred_timings.insert(cta.preferred_timings.begin(),
659 timings_ext(*t, type, flags));
660 else
661 cta.preferred_timings.push_back(timings_ext(*t, type, flags));
662 }
663 if (first_svd) {
664 cta.first_svd = false;
665 cta.first_svd_might_be_preferred = false;
666 }
667 if (native)
668 cta.native_timings.push_back(timings_ext(*t, type, flags));
669 } else {
670 printf(" Unknown (VIC %3u)\n", vic);
671 fail("Unknown VIC %u.\n", vic);
672 }
673
674 if (vic == 1 && !for_ycbcr420)
675 cta.has_vic_1 = 1;
676 if (++cta.vics[vic][for_ycbcr420] == 2)
677 fail("Duplicate %sVIC %u.\n", for_ycbcr420 ? "YCbCr 4:2:0 " : "", vic);
678 if (for_ycbcr420 && cta.preparsed_has_vic[0][vic])
679 fail("YCbCr 4:2:0-only VIC %u is also a regular VIC.\n", vic);
680 }
681 if (n > 1 && ascending && first_vic_is_1_to_4 && have_vics_5_and_up)
682 warn("All VICs are in ascending order, and the first (preferred) VIC <= 4, is that intended?\n");
683 }
684
685 cta_vfd edid_state::cta_parse_vfd(const unsigned char *x, unsigned lvfd)
686 {
687 cta_vfd vfd = {};
688
689 cta.avi_version = 4;
690 if (cta.avi_v4_length < 15)
691 cta.avi_v4_length = 15;
692 vfd.rid = x[0] & 0x3f;
693 if (vfd.rid >= ARRAY_SIZE(rids)) {
694 vfd.rid = 0;
695 return vfd;
696 }
697 vfd.bfr50 = !!(x[0] & 0x80);
698 vfd.fr24 = !!(x[0] & 0x40);
699 vfd.bfr60 = lvfd > 1 ? !!(x[1] & 0x80) : 1;
700 vfd.fr144 = lvfd > 1 ? !!(x[1] & 0x40) : 0;
701 vfd.fr_factor = lvfd > 1 ? (x[1] & 0x3f) : 3;
702 vfd.fr48 = lvfd > 2 ? !!(x[2] & 0x01) : 0;
703 return vfd;
704 }
705
706 static bool vfd_has_rate(cta_vfd &vfd, unsigned rate_index)
707 {
708 static const unsigned factors[6] = {
709 1, 2, 4, 8, 12, 16
710 };
711 unsigned rate = vf_rate_values[rate_index];
712 unsigned factor = 0;
713
714 if (!vfd.rid)
715 return false;
716 if (rate == 24)
717 return vfd.fr24;
718 if (rate == 48)
719 return vfd.fr48;
720 if (rate == 144)
721 return vfd.fr144;
722
723 if (!(rate % 30)) {
724 if (!vfd.bfr60)
725 return false;
726 factor = rate / 30;
727 }
728 if (!(rate % 25)) {
729 if (!vfd.bfr50)
730 return false;
731 factor = rate / 25;
732 }
733
734 for (unsigned i = 0; i < ARRAY_SIZE(factors); i++)
735 if (factors[i] == factor && (vfd.fr_factor & (1 << i)))
736 return true;
737 return false;
738 }
739
740 void edid_state::cta_vfdb(const unsigned char *x, unsigned n)
741 {
742 if (n-- == 0) {
743 fail("Length is 0.\n");
744 return;
745 }
746 unsigned char flags = *x++;
747 unsigned lvfd = (flags & 3) + 1;
748
749 if (n % lvfd) {
750 fail("Length - 1 is not a multiple of Lvfd (%u).\n", lvfd);
751 return;
752 }
753 if (flags & 0x80)
754 printf(" Supports YCbCr 4:2:0\n");
755 if (flags & 0x40)
756 printf(" NTSC fractional frame rates are preferred\n");
757 for (unsigned i = 0; i < n; i += lvfd, x += lvfd) {
758 unsigned char rid = x[0] & 0x3f;
759 cta_vfd vfd = cta_parse_vfd(x, lvfd);
760
761 if (lvfd > 2 && (x[2] & 0xfe))
762 fail("Bits F31-F37 must be 0.\n");
763 if (lvfd > 3 && x[3])
764 fail("Bits F40-F47 must be 0.\n");
765 if (rid == 0 || rid >= ARRAY_SIZE(rids)) {
766 fail("Unknown RID %u.\n", rid);
767 continue;
768 }
769 for (unsigned rate_index = 1; rate_index < ARRAY_SIZE(vf_rate_values); rate_index++) {
770 if (!vfd_has_rate(vfd, rate_index))
771 continue;
772 struct timings t = calc_ovt_mode(rids[vfd.rid].hact,
773 rids[vfd.rid].vact,
774 rids[vfd.rid].hratio,
775 rids[vfd.rid].vratio,
776 vf_rate_values[rate_index]);
777 char type[16];
778 sprintf(type, "RID %u@%up", rid, vf_rate_values[rate_index]);
779 print_timings(" ", &t, type);
780 if (rid_to_vic(vfd.rid, rate_index))
781 fail("%s not allowed since it maps to VIC %u.\n",
782 type, rid_to_vic(vfd.rid, rate_index));
783 }
784 }
785 }
786
787 void edid_state::print_vic_index(const char *prefix, unsigned idx, const char *suffix, bool ycbcr420)
788 {
789 if (!suffix)
790 suffix = "";
791 if (idx < cta.preparsed_svds[0].size()) {
792 unsigned char vic = cta.preparsed_svds[0][idx];
793 const struct timings *t = find_vic_id(vic);
794 char buf[16];
795
796 sprintf(buf, "VIC %3u", vic);
797
798 if (t) {
799 struct timings tmp = *t;
800 tmp.ycbcr420 = ycbcr420;
801 print_timings(prefix, &tmp, buf, suffix);
802 } else {
803 printf("%sUnknown (%s%s%s)\n", prefix, buf,
804 *suffix ? ", " : "", suffix);
805 }
806 } else {
807 // Should not happen!
808 printf("%sSVD Index %u is out of range", prefix, idx + 1);
809 if (*suffix)
810 printf(" (%s)", suffix);
811 printf("\n");
812 }
813 }
814
815 void edid_state::cta_y420cmdb(const unsigned char *x, unsigned length)
816 {
817 unsigned max_idx = 0;
818 unsigned i;
819
820 if (!length) {
821 printf(" All VDB SVDs\n");
822 return;
823 }
824
825 if (memchk(x, length)) {
826 printf(" Empty Capability Map\n");
827 fail("Empty Capability Map.\n");
828 return;
829 }
830
831 for (i = 0; i < length; i++) {
832 unsigned char v = x[i];
833 unsigned j;
834
835 for (j = 0; j < 8; j++) {
836 if (!(v & (1 << j)))
837 continue;
838
839 print_vic_index(" ", i * 8 + j, "", true);
840 max_idx = i * 8 + j;
841 if (max_idx < cta.preparsed_svds[0].size()) {
842 unsigned vic = cta.preparsed_svds[0][max_idx];
843 if (cta.preparsed_has_vic[1][vic])
844 fail("VIC %u is also a YCbCr 4:2:0-only VIC.\n", vic);
845 }
846 cta.has_ycbcr420 = true;
847 }
848 }
849 if (max_idx >= cta.preparsed_svds[0].size())
850 fail("Max index %u > %u (#SVDs).\n",
851 max_idx + 1, cta.preparsed_svds[0].size());
852 }
853
854 void edid_state::cta_print_svr(unsigned char svr, vec_timings_ext &vec_tim)
855 {
856 char suffix[24];
857
858 if ((svr > 0 && svr < 128) || (svr > 192 && svr < 254)) {
859 const struct timings *t;
860 unsigned char vic = svr;
861
862 sprintf(suffix, "VIC %3u", vic);
863
864 t = find_vic_id(vic);
865 if (t) {
866 print_timings(" ", t, suffix);
867 vec_tim.push_back(timings_ext(*t, suffix, ""));
868 } else {
869 printf(" %s: Unknown\n", suffix);
870 fail("Unknown VIC %u.\n", vic);
871 }
872
873 } else if (svr >= 129 && svr <= 144) {
874 sprintf(suffix, "DTD %3u", svr - 128);
875 if (svr >= cta.preparsed_total_dtds + 129) {
876 printf(" %s: Invalid\n", suffix);
877 fail("Invalid DTD %u.\n", svr - 128);
878 } else {
879 printf(" %s\n", suffix);
880 vec_tim.push_back(timings_ext(svr, suffix));
881 cta.has_svrs = true;
882 }
883 } else if (svr >= 145 && svr <= 160) {
884 sprintf(suffix, "VTDB %3u", svr - 144);
885 if (svr >= cta.preparsed_total_vtdbs + 145) {
886 printf(" %s: Invalid\n", suffix);
887 fail("Invalid VTDB %u.\n", svr - 144);
888 } else {
889 printf(" %s\n", suffix);
890 vec_tim.push_back(timings_ext(svr, suffix));
891 cta.has_svrs = true;
892 }
893 } else if (svr >= 161 && svr <= 175) {
894 sprintf(suffix, "RID %u@%up",
895 cta.preparsed_first_vfd.rid, vf_rate_values[svr - 160]);
896 if (!vfd_has_rate(cta.preparsed_first_vfd, svr - 160)) {
897 printf(" %s: Invalid\n", suffix);
898 fail("Invalid %s.\n", suffix);
899 } else {
900 printf(" %s\n", suffix);
901 vec_tim.push_back(timings_ext(svr, suffix));
902 cta.has_svrs = true;
903 }
904 } else if (svr == 254) {
905 sprintf(suffix, "T8VTDB");
906 if (!cta.preparsed_has_t8vtdb) {
907 printf(" %s: Invalid\n", suffix);
908 fail("Invalid T8VTDB.\n");
909 } else {
910 sprintf(suffix, "DMT 0x%02x", cta.preparsed_t8vtdb_dmt);
911 printf(" %s\n", suffix);
912 vec_tim.push_back(timings_ext(svr, suffix));
913 cta.has_svrs = true;
914 }
915 }
916 }
917
918 void edid_state::cta_vfpdb(const unsigned char *x, unsigned length)
919 {
920 unsigned i;
921
922 if (length == 0) {
923 fail("Empty Data Block with length %u.\n", length);
924 return;
925 }
926 cta.preferred_timings_vfpdb.clear();
927 for (i = 0; i < length; i++)
928 cta_print_svr(x[i], cta.preferred_timings_vfpdb);
929 if (cta.has_nvrdb)
930 return;
931
932 for (const auto &n : cta.preferred_timings_vfpdb) {
933 if (n.t.vact >= 4096 || n.t.hact >= 4096) {
934 warn("One of the VFPDB timings has width or height >= 4096, adding an NVRDB is strongly recommended.\n");
935 break;
936 }
937 }
938 }
939
940 void edid_state::cta_nvrdb(const unsigned char *x, unsigned length)
941 {
942 if (length == 0) {
943 fail("Empty Data Block with length %u.\n", length);
944 return;
945 }
946
947 unsigned char flags = length == 1 ? 0 : x[1];
948
949 cta.native_timing_nvrdb.clear();
950 cta_print_svr(x[0], cta.native_timing_nvrdb);
951 if ((flags & 1) && length < 6) {
952 fail("Data Block too short for Image Size (length = %u).\n", length);
953 return;
954 }
955 if (flags & 0x7e)
956 fail("Bits F41-F46 must be 0.\n");
957 if (!(flags & 1))
958 return;
959
960 unsigned w = (x[3] << 8) | x[2];
961 unsigned h = (x[5] << 8) | x[4];
962
963 if (!w || !h) {
964 fail("Image Size has a zero width and/or height.\n");
965 return;
966 }
967
968 if (flags & 0x80) {
969 w *= 10;
970 h *= 10;
971 }
972 printf(" Image Size: %.1fx%.1f mm\n", w / 10.0, h / 10.0);
973 image_width = w;
974 image_height = h;
975 if (w <= 25500 && h <= 25500)
976 warn("Image Size should only be used for large displays with width and/or height > 255 cm\n");
977 cta.nvrdb_has_size = true;
978 }
979
980 static std::string hdmi_latency2s(unsigned char l, bool is_video)
981 {
982 if (!l)
983 return "Unknown";
984 if (l == 0xff)
985 return is_video ? "Video not supported" : "Audio not supported";
986 return std::to_string(2 * (l - 1)) + " ms";
987 }
988
989 void edid_state::hdmi_latency(unsigned char vid_lat, unsigned char aud_lat,
990 bool is_ilaced)
991 {
992 const char *vid = is_ilaced ? "Interlaced video" : "Video";
993 const char *aud = is_ilaced ? "Interlaced audio" : "Audio";
994
995 printf(" %s latency: %s\n", vid, hdmi_latency2s(vid_lat, true).c_str());
996 printf(" %s latency: %s\n", aud, hdmi_latency2s(aud_lat, false).c_str());
997
998 if (vid_lat > 251 && vid_lat != 0xff)
999 fail("Invalid %s latency value %u.\n", vid, vid_lat);
1000 if (aud_lat > 251 && aud_lat != 0xff)
1001 fail("Invalid %s latency value %u.\n", aud, aud_lat);
1002
1003 if (!vid_lat || vid_lat > 251)
1004 return;
1005 if (!aud_lat || aud_lat > 251)
1006 return;
1007
1008 unsigned vid_ms = 2 * (vid_lat - 1);
1009 unsigned aud_ms = 2 * (aud_lat - 1);
1010
1011 // HDMI 2.0 latency checks for devices without HDMI output
1012 if (aud_ms < vid_ms)
1013 warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
1014 aud, vid, aud_ms, vid_ms);
1015 else if (vid_ms + 20 < aud_ms)
1016 warn("%s latency + 20 < %s latency (%u + 20 ms < %u ms). This is forbidden for devices without HDMI output.\n",
1017 vid, aud, vid_ms, aud_ms);
1018 else if (vid_ms < aud_ms)
1019 warn("%s latency < %s latency (%u ms < %u ms). This is discouraged for devices without HDMI output.\n",
1020 vid, aud, vid_ms, aud_ms);
1021 }
1022
1023 void edid_state::cta_hdmi_block(const unsigned char *x, unsigned length)
1024 {
1025 unsigned len_vic, len_3d;
1026
1027 if (length < 1) {
1028 fail("Empty Data Block with length %u.\n", length);
1029 return;
1030 }
1031 printf(" Source physical address: %x.%x.%x.%x\n", x[0] >> 4, x[0] & 0x0f,
1032 x[1] >> 4, x[1] & 0x0f);
1033
1034 if (length < 3)
1035 return;
1036
1037 if (x[2] & 0x80)
1038 printf(" Supports_AI\n");
1039 if (x[2] & 0x40)
1040 printf(" DC_48bit\n");
1041 if (x[2] & 0x20)
1042 printf(" DC_36bit\n");
1043 if (x[2] & 0x10)
1044 printf(" DC_30bit\n");
1045 if (x[2] & 0x08)
1046 printf(" DC_Y444\n");
1047 /* two reserved bits */
1048 if (x[2] & 0x01)
1049 printf(" DVI_Dual\n");
1050
1051 if (length < 4)
1052 return;
1053
1054 unsigned rate = x[3] * 5;
1055 printf(" Maximum TMDS clock: %u MHz\n", rate);
1056 cta.hdmi_max_rate = rate;
1057 if (rate > 340)
1058 fail("HDMI VSDB Max TMDS rate is > 340.\n");
1059
1060 if (length < 5)
1061 return;
1062
1063 if (x[4] & 0x0f) {
1064 printf(" Supported Content Types:\n");
1065 if (x[4] & 0x01)
1066 printf(" Graphics\n");
1067 if (x[4] & 0x02)
1068 printf(" Photo\n");
1069 if (x[4] & 0x04)
1070 printf(" Cinema\n");
1071 if (x[4] & 0x08)
1072 printf(" Game\n");
1073 }
1074
1075 unsigned b = 5;
1076 if (x[4] & 0x80) {
1077 hdmi_latency(x[b], x[b + 1], false);
1078
1079 if (x[4] & 0x40) {
1080 if (x[b] == x[b + 2] &&
1081 x[b + 1] == x[b + 3])
1082 warn("Progressive and Interlaced latency values are identical, no need for both.\n");
1083 b += 2;
1084 hdmi_latency(x[b], x[b + 1], true);
1085 }
1086 b += 2;
1087 }
1088
1089 if (!(x[4] & 0x20))
1090 return;
1091
1092 bool mask = false;
1093 bool formats = false;
1094
1095 printf(" Extended HDMI video details:\n");
1096 if (x[b] & 0x80)
1097 printf(" 3D present\n");
1098 if ((x[b] & 0x60) == 0x20) {
1099 printf(" All advertised VICs are 3D-capable\n");
1100 formats = true;
1101 }
1102 if ((x[b] & 0x60) == 0x40) {
1103 printf(" 3D-capable-VIC mask present\n");
1104 formats = true;
1105 mask = true;
1106 }
1107 switch (x[b] & 0x18) {
1108 case 0x00: break;
1109 case 0x08:
1110 printf(" Base EDID image size is aspect ratio\n");
1111 break;
1112 case 0x10:
1113 printf(" Base EDID image size is in units of 1 cm\n");
1114 break;
1115 case 0x18:
1116 printf(" Base EDID image size is in units of 5 cm\n");
1117 if (base.max_display_width_mm < 2550 &&
1118 base.max_display_height_mm < 2550)
1119 fail("5 cm units should not be used for displays smaller than 255x255 cm\n");
1120 break;
1121 }
1122 b++;
1123 len_vic = (x[b] & 0xe0) >> 5;
1124 len_3d = (x[b] & 0x1f) >> 0;
1125 b++;
1126
1127 if (len_vic) {
1128 unsigned i;
1129
1130 printf(" HDMI VICs:\n");
1131 for (i = 0; i < len_vic; i++) {
1132 unsigned char vic = x[b + i];
1133 const struct timings *t;
1134
1135 if (vic && vic <= ARRAY_SIZE(edid_hdmi_mode_map)) {
1136 std::string suffix = "HDMI VIC " + std::to_string(vic);
1137 cta.supported_hdmi_vic_codes |= 1 << (vic - 1);
1138 t = find_vic_id(edid_hdmi_mode_map[vic - 1]);
1139 print_timings(" ", t, suffix.c_str());
1140 } else {
1141 printf(" Unknown (HDMI VIC %u)\n", vic);
1142 fail("Unknown HDMI VIC %u.\n", vic);
1143 }
1144 }
1145
1146 b += len_vic;
1147 }
1148
1149 if (!len_3d)
1150 return;
1151
1152 if (formats) {
1153 /* 3D_Structure_ALL_15..8 */
1154 if (x[b] & 0x80)
1155 printf(" 3D: Side-by-side (half, quincunx)\n");
1156 if (x[b] & 0x01)
1157 printf(" 3D: Side-by-side (half, horizontal)\n");
1158 /* 3D_Structure_ALL_7..0 */
1159 b++;
1160 if (x[b] & 0x40)
1161 printf(" 3D: Top-and-bottom\n");
1162 if (x[b] & 0x20)
1163 printf(" 3D: L + depth + gfx + gfx-depth\n");
1164 if (x[b] & 0x10)
1165 printf(" 3D: L + depth\n");
1166 if (x[b] & 0x08)
1167 printf(" 3D: Side-by-side (full)\n");
1168 if (x[b] & 0x04)
1169 printf(" 3D: Line-alternative\n");
1170 if (x[b] & 0x02)
1171 printf(" 3D: Field-alternative\n");
1172 if (x[b] & 0x01)
1173 printf(" 3D: Frame-packing\n");
1174 b++;
1175 len_3d -= 2;
1176 }
1177
1178 if (mask) {
1179 int max_idx = -1;
1180 unsigned i;
1181
1182 printf(" 3D VIC indices that support these capabilities:\n");
1183 /* worst bit ordering ever */
1184 for (i = 0; i < 8; i++)
1185 if (x[b + 1] & (1 << i)) {
1186 print_vic_index(" ", i, "");
1187 max_idx = i;
1188 }
1189 for (i = 0; i < 8; i++)
1190 if (x[b] & (1 << i)) {
1191 print_vic_index(" ", i + 8, "");
1192 max_idx = i + 8;
1193 }
1194 b += 2;
1195 len_3d -= 2;
1196 if (max_idx >= (int)cta.preparsed_svds[0].size())
1197 fail("HDMI 3D VIC indices max index %d > %u (#SVDs).\n",
1198 max_idx + 1, cta.preparsed_svds[0].size());
1199 }
1200
1201 /*
1202 * list of nibbles:
1203 * 2D_VIC_Order_X
1204 * 3D_Structure_X
1205 * (optionally: 3D_Detail_X and reserved)
1206 */
1207 if (!len_3d)
1208 return;
1209
1210 unsigned end = b + len_3d;
1211 int max_idx = -1;
1212
1213 printf(" 3D VIC indices with specific capabilities:\n");
1214 while (b < end) {
1215 unsigned char idx = x[b] >> 4;
1216 std::string s;
1217
1218 if (idx > max_idx)
1219 max_idx = idx;
1220 switch (x[b] & 0x0f) {
1221 case 0: s = "frame packing"; break;
1222 case 1: s = "field alternative"; break;
1223 case 2: s = "line alternative"; break;
1224 case 3: s = "side-by-side (full)"; break;
1225 case 4: s = "L + depth"; break;
1226 case 5: s = "L + depth + gfx + gfx-depth"; break;
1227 case 6: s = "top-and-bottom"; break;
1228 case 8:
1229 s = "side-by-side";
1230 switch (x[b + 1] >> 4) {
1231 case 0x00: s += ", any subsampling"; break;
1232 case 0x01: s += ", horizontal"; break;
1233 case 0x02: case 0x03: case 0x04: case 0x05:
1234 s += ", not in use";
1235 fail("not-in-use 3D_Detail_X value 0x%02x.\n",
1236 x[b + 1] >> 4);
1237 break;
1238 case 0x06: s += ", all quincunx combinations"; break;
1239 case 0x07: s += ", quincunx odd/left, odd/right"; break;
1240 case 0x08: s += ", quincunx odd/left, even/right"; break;
1241 case 0x09: s += ", quincunx even/left, odd/right"; break;
1242 case 0x0a: s += ", quincunx even/left, even/right"; break;
1243 default:
1244 s += ", reserved";
1245 fail("reserved 3D_Detail_X value 0x%02x.\n",
1246 x[b + 1] >> 4);
1247 break;
1248 }
1249 break;
1250 default:
1251 s = "unknown (";
1252 s += utohex(x[b] & 0x0f) + ")";
1253 fail("Unknown 3D_Structure_X value 0x%02x.\n", x[b] & 0x0f);
1254 break;
1255 }
1256 print_vic_index(" ", idx, s.c_str());
1257 if ((x[b] & 0x0f) >= 8)
1258 b++;
1259 b++;
1260 }
1261 if (max_idx >= (int)cta.preparsed_svds[0].size())
1262 fail("HDMI 2D VIC indices max index %d > %u (#SVDs).\n",
1263 max_idx + 1, cta.preparsed_svds[0].size());
1264 }
1265
1266 static const char *max_frl_rates[] = {
1267 "Not Supported",
1268 "3 Gbps per lane on 3 lanes",
1269 "3 and 6 Gbps per lane on 3 lanes",
1270 "3 and 6 Gbps per lane on 3 lanes, 6 Gbps on 4 lanes",
1271 "3 and 6 Gbps per lane on 3 lanes, 6 and 8 Gbps on 4 lanes",
1272 "3 and 6 Gbps per lane on 3 lanes, 6, 8 and 10 Gbps on 4 lanes",
1273 "3 and 6 Gbps per lane on 3 lanes, 6, 8, 10 and 12 Gbps on 4 lanes",
1274 };
1275
1276 static const char *dsc_max_slices[] = {
1277 "Not Supported",
1278 "up to 1 slice and up to (340 MHz/Ksliceadjust) pixel clock per slice",
1279 "up to 2 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
1280 "up to 4 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
1281 "up to 8 slices and up to (340 MHz/Ksliceadjust) pixel clock per slice",
1282 "up to 8 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
1283 "up to 12 slices and up to (400 MHz/Ksliceadjust) pixel clock per slice",
1284 "up to 12 slices and up to (600 MHz/Ksliceadjust) pixel clock per slice",
1285 };
1286
1287 static void cta_hf_eeodb(const unsigned char *x, unsigned length)
1288 {
1289 printf(" EDID Extension Block Count: %u\n", x[0]);
1290 if (length != 1)
1291 fail("Block is too long.\n");
1292 if (x[0] <= 1)
1293 fail("Extension Block Count == %u.\n", x[0]);
1294 }
1295
1296 void edid_state::cta_hf_scdb(const unsigned char *x, unsigned length)
1297 {
1298 unsigned rate = x[1] * 5;
1299 unsigned v;
1300
1301 printf(" Version: %u\n", x[0]);
1302 if (rate) {
1303 printf(" Maximum TMDS Character Rate: %u MHz\n", rate);
1304 if (rate <= 340 || rate > 600)
1305 fail("Max TMDS rate is > 0 and <= 340 or > 600.\n");
1306 if (rate < cta.hdmi_max_rate)
1307 fail("HDMI Forum VSDB rate < HDMI VSDB rate.\n");
1308 else
1309 cta.hdmi_max_rate = rate;
1310 }
1311 if (x[2] & 0x80)
1312 printf(" SCDC Present\n");
1313 if (x[2] & 0x40)
1314 printf(" SCDC Read Request Capable\n");
1315 if (x[2] & 0x20)
1316 printf(" Supports Cable Status\n");
1317 if (x[2] & 0x10)
1318 printf(" Supports Color Content Bits Per Component Indication\n");
1319 if (x[2] & 0x08)
1320 printf(" Supports scrambling for <= 340 Mcsc\n");
1321 if (x[2] & 0x04)
1322 printf(" Supports 3D Independent View signaling\n");
1323 if (x[2] & 0x02)
1324 printf(" Supports 3D Dual View signaling\n");
1325 if (x[2] & 0x01)
1326 printf(" Supports 3D OSD Disparity signaling\n");
1327 if (x[3] & 0xf0) {
1328 unsigned max_frl_rate = x[3] >> 4;
1329
1330 printf(" Max Fixed Rate Link: ");
1331 if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
1332 printf("%s\n", max_frl_rates[max_frl_rate]);
1333 } else {
1334 printf("Unknown (0x%02x)\n", max_frl_rate);
1335 fail("Unknown Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
1336 }
1337 if (max_frl_rate == 1 && rate < 300)
1338 fail("Max Fixed Rate Link is 1, but Max TMDS rate < 300.\n");
1339 else if (max_frl_rate >= 2 && rate < 600)
1340 fail("Max Fixed Rate Link is >= 2, but Max TMDS rate < 600.\n");
1341
1342 // FIXME:
1343 // Currently I do not really know how to translate the
1344 // Max FRL value to an equivalent max clock frequency.
1345 // So reset this field to 0 to skip any clock rate checks.
1346 cta.hdmi_max_rate = 0;
1347 }
1348 if (x[3] & 0x08)
1349 printf(" Supports UHD VIC\n");
1350 if (x[3] & 0x04)
1351 printf(" Supports 16-bits/component Deep Color 4:2:0 Pixel Encoding\n");
1352 if (x[3] & 0x02)
1353 printf(" Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding\n");
1354 if (x[3] & 0x01)
1355 printf(" Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding\n");
1356
1357 if (length <= 4)
1358 return;
1359
1360 if (x[4] & 0x80)
1361 printf(" Supports FAPA End Extended\n");
1362 if (x[4] & 0x40)
1363 printf(" Supports QMS\n");
1364 if (x[4] & 0x20)
1365 printf(" Supports Mdelta\n");
1366 if (x[4] & 0x10) {
1367 printf(" Supports media rates below VRRmin (CinemaVRR, deprecated)\n");
1368 warn("CinemaVRR is deprecated and must be cleared.\n");
1369 }
1370 if (x[4] & 0x08)
1371 printf(" Supports negative Mvrr values\n");
1372 if (x[4] & 0x04)
1373 printf(" Supports Fast Vactive\n");
1374 if (x[4] & 0x02)
1375 printf(" Supports Auto Low-Latency Mode\n");
1376 if (x[4] & 0x01)
1377 printf(" Supports a FAPA in blanking after first active video line\n");
1378
1379 if (length <= 5)
1380 return;
1381
1382 v = x[5] & 0x3f;
1383 if (v) {
1384 printf(" VRRmin: %u Hz\n", v);
1385 if (v > 48)
1386 fail("VRRmin > 48.\n");
1387 }
1388 v = (x[5] & 0xc0) << 2 | x[6];
1389 if (v) {
1390 printf(" VRRmax: %u Hz\n", v);
1391 if (!(x[5] & 0x3f))
1392 fail("VRRmin == 0, but VRRmax isn't.\n");
1393 else if (v < 100)
1394 fail("VRRmax < 100.\n");
1395 }
1396
1397 if (length <= 7)
1398 return;
1399
1400 if (x[7] & 0x80)
1401 printf(" Supports VESA DSC 1.2a compression\n");
1402 if (x[7] & 0x40)
1403 printf(" Supports Compressed Video Transport for 4:2:0 Pixel Encoding\n");
1404 if (x[7] & 0x20)
1405 printf(" Supports QMS TFRmax\n");
1406 if (x[7] & 0x10)
1407 printf(" Supports QMS TFRmin\n");
1408 if (x[7] & 0x08)
1409 printf(" Supports Compressed Video Transport at any valid 1/16th bit bpp\n");
1410 if (x[7] & 0x04)
1411 printf(" Supports 16 bpc Compressed Video Transport\n");
1412 if (x[7] & 0x02)
1413 printf(" Supports 12 bpc Compressed Video Transport\n");
1414 if (x[7] & 0x01)
1415 printf(" Supports 10 bpc Compressed Video Transport\n");
1416 if (x[8] & 0xf) {
1417 unsigned max_slices = x[8] & 0xf;
1418
1419 printf(" DSC Max Slices: ");
1420 if (max_slices < ARRAY_SIZE(dsc_max_slices)) {
1421 printf("%s\n", dsc_max_slices[max_slices]);
1422 } else {
1423 printf("Unknown (%u), interpreted as: %s\n", max_slices,
1424 dsc_max_slices[7]);
1425 warn("Unknown DSC Max Slices (%u).\n", max_slices);
1426 }
1427 }
1428 if (x[8] & 0xf0) {
1429 unsigned max_frl_rate = x[8] >> 4;
1430
1431 printf(" DSC Max Fixed Rate Link: ");
1432 if (max_frl_rate < ARRAY_SIZE(max_frl_rates)) {
1433 printf("%s\n", max_frl_rates[max_frl_rate]);
1434 } else {
1435 printf("Unknown (0x%02x)\n", max_frl_rate);
1436 fail("Unknown DSC Max Fixed Rate Link (0x%02x).\n", max_frl_rate);
1437 }
1438 }
1439 if (x[9] & 0x3f)
1440 printf(" Maximum number of bytes in a line of chunks: %u\n",
1441 1024 * (1 + (x[9] & 0x3f)));
1442 }
1443
1444 // Convert a PQ value (0-1) to cd/m^2 aka nits (0-10000)
1445 static double pq2nits(double pq)
1446 {
1447 const double m1 = 2610.0 / 16384.0;
1448 const double m2 = 128.0 * (2523.0 / 4096.0);
1449 const double c1 = 3424.0 / 4096.0;
1450 const double c2 = 32.0 * (2413.0 / 4096.0);
1451 const double c3 = 32.0 * (2392.0 / 4096.0);
1452 double e = pow(pq, 1.0 / m2);
1453 double v = e - c1;
1454
1455 if (v < 0)
1456 v = 0;
1457 v /= c2 - c3 * e;
1458 v = pow(v, 1.0 / m1);
1459 return v * 10000.0;
1460 }
1461
1462 static double perc2d(unsigned char x)
1463 {
1464 double m = x >> 2;
1465 double e = x & 3;
1466
1467 return 100.0 * (m / 64.0) * pow(10, -e);
1468 }
1469
1470 static void cta_hf_sbtmdb(const unsigned char *x, unsigned length)
1471 {
1472 int len = length;
1473
1474 if (!length)
1475 fail("Block is too short.\n");
1476 printf(" Version: %d\n", x[0] & 0xf);
1477 switch ((x[0] >> 5) & 3) {
1478 case 0:
1479 printf(" Does not support a General RDM format\n");
1480 break;
1481 case 1:
1482 printf(" Supports an SDR-range General RDM format\n");
1483 break;
1484 case 2:
1485 printf(" Supports an HDR-range General RDM format\n");
1486 break;
1487 default:
1488 fail("Invalid GRDM Support value.\n");
1489 break;
1490 }
1491 if (!(x[0] & 0x80))
1492 return;
1493
1494 bool uses_hgig_drdm = true;
1495
1496 printf(" Supports a D-RDM format\n");
1497 if (x[1] & 0x10)
1498 printf(" Use HGIG D-RDM\n");
1499 switch (x[1] & 7) {
1500 case 0:
1501 printf(" HGIG D-RDM is not used\n");
1502 uses_hgig_drdm = false;
1503 break;
1504 case 1:
1505 printf(" PBnits[0] = 600 cd/m^2\n");
1506 break;
1507 case 2:
1508 printf(" PBnits[0] = 1000 cd/m^2\n");
1509 break;
1510 case 3:
1511 printf(" PBnits[0] = 4000 cd/m^2\n");
1512 break;
1513 case 4:
1514 printf(" PBnits[0] = 10000 cd/m^2\n");
1515 break;
1516 default:
1517 fail("Invalid HGIG D-DRM value.\n");
1518 break;
1519 }
1520
1521 bool has_chromaticities = false;
1522
1523 if (x[1] & 0x20)
1524 printf(" MaxRGB\n");
1525 switch (x[1] >> 6) {
1526 case 0:
1527 printf(" Gamut is explicit\n");
1528 has_chromaticities = true;
1529 break;
1530 case 1:
1531 printf(" Gamut is Rec. ITU-R BT.709\n");
1532 break;
1533 case 2:
1534 printf(" Gamut is SMPTE ST 2113\n");
1535 break;
1536 default:
1537 printf(" Gamut is Rec. ITU-R BT.2020\n");
1538 break;
1539 }
1540 x += 2;
1541 len -= 2;
1542 if (has_chromaticities) {
1543 printf(" Red: (%.5f, %.5f)\n", chrom2d(x), chrom2d(x + 2));
1544 printf(" Green: (%.5f, %.5f)\n", chrom2d(x + 4), chrom2d(x + 6));
1545 printf(" Blue: (%.5f, %.5f)\n", chrom2d(x + 8), chrom2d(x + 10));
1546 printf(" White: (%.5f, %.5f)\n", chrom2d(x + 12), chrom2d(x + 14));
1547 x += 16;
1548 len -= 16;
1549 }
1550 if (uses_hgig_drdm)
1551 return;
1552 printf(" Min Brightness 10: %.8f cd/m^2\n", pq2nits((x[0] << 1) / 4095.0));
1553 printf(" Peak Brightness 100: %u cd/m^2\n", (unsigned)pq2nits((x[1] << 4) / 4095.0));
1554 x += 2;
1555 len -= 2;
1556 if (len <= 0)
1557 return;
1558 printf(" Percentage of Peak Brightness P0: %.2f%%\n", perc2d(x[0]));
1559 printf(" Peak Brightness P0: %.8f cd/m^2\n", pq2nits((x[1] << 1) / 4095.0));
1560 x += 2;
1561 len -= 2;
1562 if (len <= 0)
1563 return;
1564 printf(" Percentage of Peak Brightness P1: %.2f%%\n", perc2d(x[0]));
1565 printf(" Peak Brightness P1: %.8f cd/m^2\n", pq2nits((x[1] << 1) / 4095.0));
1566 x += 2;
1567 len -= 2;
1568 if (len <= 0)
1569 return;
1570 printf(" Percentage of Peak Brightness P2: %.2f%%\n", perc2d(x[0]));
1571 printf(" Peak Brightness P2: %.8f cd/m^2\n", pq2nits((x[1] << 1) / 4095.0));
1572 x += 2;
1573 len -= 2;
1574 if (len <= 0)
1575 return;
1576 printf(" Percentage of Peak Brightness P3: %.2f%%\n", perc2d(x[0]));
1577 printf(" Peak Brightness P3: %.8f cd/m^2\n", pq2nits((x[1] << 1) / 4095.0));
1578 }
1579
1580 static void cta_amd(const unsigned char *x, unsigned length)
1581 {
1582 // These Freesync values are reversed engineered by looking
1583 // at existing EDIDs.
1584 printf(" Version: %u\n", x[0]);
1585
1586 // Obtained from:
1587 // https://github.com/torvalds/linux/commit/ec8e59cb4e0c1a52d5a541fff9dcec398b48f7b4
1588 printf(" Feature Caps: 0x%02x\n", x[1]);
1589 if (x[1] & 0x40)
1590 printf(" Replay Supported\n");
1591
1592 printf(" Minimum Refresh Rate: %u Hz\n", x[2]);
1593 printf(" Maximum Refresh Rate: %u Hz\n", x[3]);
1594 // Freesync 1.x flags
1595 // One or more of the 0xe6 bits signal that the VESA MCCS
1596 // protocol is used to switch the Freesync range
1597 printf(" Flags 1.x: 0x%02x%s\n", x[4],
1598 (x[4] & 0xe6) ? " (MCCS)" : "");
1599 if (length >= 10) {
1600 // Freesync 2.x flags
1601 // Bit 2 no doubt indicates if the monitor supports Local Dimming
1602 // There are probably also bits to signal support of the
1603 // FreeSync2_scRGB and FreeSync2_Gamma22 HDR display modes.
1604 // I suspect bits 0 and 1.
1605 printf(" Flags 2.x: 0x%02x\n", x[5]);
1606 // The AMD tone mapping tutorial referred to in the URL below
1607 // mentions that the Freesync HDR info reports max/min
1608 // luminance of the monitor with and without local dimming.
1609 //
1610 // https://gpuopen.com/learn/using-amd-freesync-premium-pro-hdr-code-samples/
1611 //
1612 // So I assume that the first two luminance values are
1613 // the max/min luminance of the display and the next two
1614 // luminance values are the max/min luminance values when
1615 // local dimming is disabled. The values I get seem to
1616 // support that.
1617 printf(" Maximum luminance: %u (%.3f cd/m^2)\n",
1618 x[6], 50.0 * pow(2, x[6] / 32.0));
1619 printf(" Minimum luminance: %u (%.3f cd/m^2)\n",
1620 x[7], (50.0 * pow(2, x[6] / 32.0)) * pow(x[7] / 255.0, 2) / 100.0);
1621 if (x[5] & 4) {
1622 // One or both bytes can be 0. The meaning of that
1623 // is unknown.
1624 printf(" Maximum luminance (without local dimming): %u (%.3f cd/m^2)\n",
1625 x[8], 50.0 * pow(2, x[8] / 32.0));
1626 printf(" Minimum luminance (without local dimming): %u (%.3f cd/m^2)\n",
1627 x[9], (50.0 * pow(2, x[8] / 32.0)) * pow(x[9] / 255.0, 2) / 100.0);
1628 } else {
1629 // These bytes are always 0x08 0x2f. If these values
1630 // represent max/min luminance as well, then these
1631 // would map to 59.460 and 0.020 cd/m^2 respectively.
1632 // I wonder if this somehow relates to SDR.
1633 printf(" Unknown: 0x%02x 0x%02x\n", x[8], x[9]);
1634 }
1635 }
1636 }
1637
1638 static std::string display_use_case(unsigned char x)
1639 {
1640 switch (x) {
1641 case 1: return "Test equipment";
1642 case 2: return "Generic display";
1643 case 3: return "Television display";
1644 case 4: return "Desktop productivity display";
1645 case 5: return "Desktop gaming display";
1646 case 6: return "Presentation display";
1647 case 7: return "Virtual reality headset";
1648 case 8: return "Augmented reality";
1649 case 16: return "Video wall display";
1650 case 17: return "Medical imaging display";
1651 case 18: return "Dedicated gaming display";
1652 case 19: return "Dedicated video monitor display";
1653 case 20: return "Accessory display";
1654 default: break;
1655 }
1656 fail("Unknown Display product primary use case 0x%02x.\n", x);
1657 return "Unknown";
1658 }
1659
1660 static void cta_microsoft(const unsigned char *x, unsigned length)
1661 {
1662 // This VSDB is documented at:
1663 // https://docs.microsoft.com/en-us/windows-hardware/drivers/display/specialized-monitors-edid-extension
1664 printf(" Version: %u\n", x[0]);
1665 if (x[0] > 2) {
1666 // In version 1 and 2 these bits should always be set to 0.
1667 printf(" Desktop Usage: %u\n", (x[1] >> 6) & 1);
1668 printf(" Third-Party Usage: %u\n", (x[1] >> 5) & 1);
1669 }
1670 printf(" Display Product Primary Use Case: %s\n",
1671 display_use_case(x[1] & 0x1f).c_str());
1672 printf(" Container ID: %s\n", containerid2s(x + 2).c_str());
1673 }
1674
1675 static void cta_hdr10plus(const unsigned char *x, unsigned length)
1676 {
1677 if (length == 0) {
1678 fail("Empty Data Block with length %u.\n", length);
1679 return;
1680 }
1681 printf(" Application Version: %u\n", x[0] & 3);
1682 printf(" Full Frame Peak Luminance Index: %u\n", (x[0] >> 2) & 3);
1683 printf(" Peak Luminance Index: %u\n", x[0] >> 4);
1684 hex_block(" ", x + 1, length - 1);
1685 }
1686
1687 static void cta_dolby_video(const unsigned char *x, unsigned length)
1688 {
1689 unsigned char version = (x[0] >> 5) & 0x07;
1690
1691 printf(" Version: %u (%u bytes)\n", version, length + 5);
1692 if (x[0] & 0x01)
1693 printf(" Supports YUV422 12 bit\n");
1694
1695 if (version == 0) {
1696 if (x[0] & 0x02)
1697 printf(" Supports 2160p60\n");
1698 if (x[0] & 0x04)
1699 printf(" Supports global dimming\n");
1700 unsigned char dm_version = x[16];
1701 printf(" DM Version: %u.%u\n", dm_version >> 4, dm_version & 0xf);
1702 unsigned pq = (x[14] << 4) | (x[13] >> 4);
1703 printf(" Target Min PQ: %u (%.8f cd/m^2)\n", pq, pq2nits(pq / 4095.0));
1704 pq = (x[15] << 4) | (x[13] & 0xf);
1705 printf(" Target Max PQ: %u (%u cd/m^2)\n", pq, (unsigned)pq2nits(pq / 4095.0));
1706 printf(" Rx, Ry: %.8f, %.8f\n",
1707 ((x[1] >> 4) | (x[2] << 4)) / 4096.0,
1708 ((x[1] & 0xf) | (x[3] << 4)) / 4096.0);
1709 printf(" Gx, Gy: %.8f, %.8f\n",
1710 ((x[4] >> 4) | (x[5] << 4)) / 4096.0,
1711 ((x[4] & 0xf) | (x[6] << 4)) / 4096.0);
1712 printf(" Bx, By: %.8f, %.8f\n",
1713 ((x[7] >> 4) | (x[8] << 4)) / 4096.0,
1714 ((x[7] & 0xf) | (x[9] << 4)) / 4096.0);
1715 printf(" Wx, Wy: %.8f, %.8f\n",
1716 ((x[10] >> 4) | (x[11] << 4)) / 4096.0,
1717 ((x[10] & 0xf) | (x[12] << 4)) / 4096.0);
1718 return;
1719 }
1720
1721 if (version == 1) {
1722 if (x[0] & 0x02)
1723 printf(" Supports 2160p60\n");
1724 if (x[1] & 0x01)
1725 printf(" Supports global dimming\n");
1726 unsigned char dm_version = (x[0] >> 2) & 0x07;
1727 printf(" DM Version: %u.x\n", dm_version + 2);
1728 printf(" Colorimetry: %s\n", (x[2] & 0x01) ? "P3-D65" : "ITU-R BT.709");
1729 printf(" Low Latency: %s\n", (x[3] & 0x01) ? "Standard + Low Latency" : "Only Standard");
1730 double lm = (x[2] >> 1) / 127.0;
1731 printf(" Target Min Luminance: %.8f cd/m^2\n", lm * lm);
1732 printf(" Target Max Luminance: %u cd/m^2\n", 100 + (x[1] >> 1) * 50);
1733 if (length == 10) {
1734 printf(" Rx, Ry: %.8f, %.8f\n", x[4] / 256.0, x[5] / 256.0);
1735 printf(" Gx, Gy: %.8f, %.8f\n", x[6] / 256.0, x[7] / 256.0);
1736 printf(" Bx, By: %.8f, %.8f\n", x[8] / 256.0, x[9] / 256.0);
1737 } else {
1738 double xmin = 0.625;
1739 double xstep = (0.74609375 - xmin) / 31.0;
1740 double ymin = 0.25;
1741 double ystep = (0.37109375 - ymin) / 31.0;
1742
1743 printf(" Unique Rx, Ry: %.8f, %.8f\n",
1744 xmin + xstep * (x[6] >> 3),
1745 ymin + ystep * (((x[6] & 0x7) << 2) | (x[4] & 0x01) | ((x[5] & 0x01) << 1)));
1746 xstep = 0.49609375 / 127.0;
1747 ymin = 0.5;
1748 ystep = (0.99609375 - ymin) / 127.0;
1749 printf(" Unique Gx, Gy: %.8f, %.8f\n",
1750 xstep * (x[4] >> 1), ymin + ystep * (x[5] >> 1));
1751 xmin = 0.125;
1752 xstep = (0.15234375 - xmin) / 7.0;
1753 ymin = 0.03125;
1754 ystep = (0.05859375 - ymin) / 7.0;
1755 printf(" Unique Bx, By: %.8f, %.8f\n",
1756 xmin + xstep * (x[3] >> 5),
1757 ymin + ystep * ((x[3] >> 2) & 0x07));
1758 }
1759 return;
1760 }
1761
1762 if (version == 2) {
1763 if (x[0] & 0x02)
1764 printf(" Supports Backlight Control\n");
1765 if (x[1] & 0x04)
1766 printf(" Supports global dimming\n");
1767 unsigned char dm_version = (x[0] >> 2) & 0x07;
1768 printf(" DM Version: %u.x\n", dm_version + 2);
1769 printf(" Backlt Min Luma: %u cd/m^2\n", 25 + (x[1] & 0x03) * 25);
1770 printf(" Interface: ");
1771 switch (x[2] & 0x03) {
1772 case 0: printf("Low-Latency\n"); break;
1773 case 1: printf("Low-Latency + Low-Latency-HDMI\n"); break;
1774 case 2: printf("Standard + Low-Latency\n"); break;
1775 case 3: printf("Standard + Low-Latency + Low-Latency-HDMI\n"); break;
1776 }
1777 printf(" Supports 10b 12b 444: ");
1778 switch ((x[3] & 0x01) << 1 | (x[4] & 0x01)) {
1779 case 0: printf("Not supported\n"); break;
1780 case 1: printf("10 bit\n"); break;
1781 case 2: printf("12 bit\n"); break;
1782 case 3: printf("Reserved\n"); break;
1783 }
1784
1785 unsigned pq = 20 * (x[1] >> 3);
1786 printf(" Target Min PQ v2: %u (%.8f cd/m^2)\n", pq, pq2nits(pq / 4095.0));
1787 pq = 2055 + 65 * (x[2] >> 3);
1788 printf(" Target Max PQ v2: %u (%u cd/m^2)\n", pq, (unsigned)pq2nits(pq / 4095.0));
1789
1790 printf(" Unique Rx, Ry: %.8f, %.8f\n",
1791 0.625 + (x[5] >> 3) / 256.0,
1792 0.25 + (x[6] >> 3) / 256.0);
1793 printf(" Unique Gx, Gy: %.8f, %.8f\n",
1794 (x[3] >> 1) / 256.0,
1795 0.5 + (x[4] >> 1) / 256.0);
1796 printf(" Unique Bx, By: %.8f, %.8f\n",
1797 0.125 + (x[5] & 0x07) / 256.0,
1798 0.03125 + (x[6] & 0x07) / 256.0);
1799 }
1800 }
1801
1802 static void cta_dolby_audio(const unsigned char *x, unsigned length)
1803 {
1804 unsigned char version = 1 + (x[0] & 0x07);
1805
1806 printf(" Version: %u (%u bytes)\n", version, length + 5);
1807 if (x[0] & 0x80)
1808 printf(" Headphone playback only\n");
1809 if (x[0] & 0x40)
1810 printf(" Height speaker zone present\n");
1811 if (x[0] & 0x20)
1812 printf(" Surround speaker zone present\n");
1813 if (x[0] & 0x10)
1814 printf(" Center speaker zone present\n");
1815 if (x[1] & 0x01)
1816 printf(" Supports Dolby MAT PCM decoding at 48 kHz only, does not support TrueHD\n");
1817 }
1818
1819 static void cta_uhda_fmm(const unsigned char *x, unsigned length)
1820 {
1821 printf(" Filmmaker Mode Content Type: %u\n", x[0]);
1822 printf(" Filmmaker Mode Content Subtype: %u\n", x[1]);
1823 }
1824
1825 const char *cta_speaker_map[] = {
1826 "FL/FR - Front Left/Right",
1827 "LFE1 - Low Frequency Effects 1",
1828 "FC - Front Center",
1829 "BL/BR - Back Left/Right",
1830 "BC - Back Center",
1831 "FLc/FRc - Front Left/Right of Center",
1832 "RLC/RRC - Rear Left/Right of Center (Deprecated)",
1833 "FLw/FRw - Front Left/Right Wide",
1834
1835 "TpFL/TpFR - Top Front Left/Right",
1836 "TpC - Top Center",
1837 "TpFC - Top Front Center",
1838 "LS/RS - Left/Right Surround",
1839 "LFE2 - Low Frequency Effects 2",
1840 "TpBC - Top Back Center",
1841 "SiL/SiR - Side Left/Right",
1842 "TpSiL/TpSiR - Top Side Left/Right",
1843
1844 "TpBL/TpBR - Top Back Left/Right",
1845 "BtFC - Bottom Front Center",
1846 "BtFL/BtFR - Bottom Front Left/Right",
1847 "TpLS/TpRS - Top Left/Right Surround (Deprecated for CTA-861)",
1848 "LSd/RSd - Left/Right Surround Direct (HDMI only)",
1849 NULL
1850 };
1851
1852 void edid_state::cta_sadb(const unsigned char *x, unsigned length)
1853 {
1854 unsigned sad_deprecated = 0x7f000;
1855 unsigned sad;
1856 unsigned i;
1857
1858 if (length < 3) {
1859 fail("Empty Data Block with length %u.\n", length);
1860 return;
1861 }
1862
1863 sad = ((x[2] << 16) | (x[1] << 8) | x[0]);
1864
1865 for (i = 0; cta_speaker_map[i]; i++) {
1866 bool deprecated = sad_deprecated & (1 << i);
1867
1868 if ((sad >> i) & 1)
1869 printf(" %s%s\n", cta_speaker_map[i],
1870 deprecated ? " (Deprecated, use the RCDB)" : "");
1871 }
1872 if (sad & 0xff040)
1873 warn("Specifies deprecated speakers.\n");
1874 }
1875
1876 static void cta_vesa_dtcdb(const unsigned char *x, unsigned length)
1877 {
1878 if (length != 7 && length != 15 && length != 31) {
1879 fail("Invalid length %u.\n", length);
1880 return;
1881 }
1882
1883 switch (x[0] >> 6) {
1884 case 0: printf(" White"); break;
1885 case 1: printf(" Red"); break;
1886 case 2: printf(" Green"); break;
1887 case 3: printf(" Blue"); break;
1888 }
1889 unsigned v = x[0] & 0x3f;
1890 printf(" transfer characteristics: %u", v);
1891 for (unsigned i = 1; i < length; i++)
1892 printf(" %u", v += x[i]);
1893 printf(" 1023\n");
1894 }
1895
1896 static void cta_vesa_vdddb(const unsigned char *x, unsigned length)
1897 {
1898 if (length != 30) {
1899 fail("Invalid length %u.\n", length);
1900 return;
1901 }
1902
1903 printf(" Interface Type: ");
1904 unsigned char v = x[0];
1905 switch (v >> 4) {
1906 case 0: printf("Analog (");
1907 switch (v & 0xf) {
1908 case 0: printf("15HD/VGA"); break;
1909 case 1: printf("VESA NAVI-V (15HD)"); break;
1910 case 2: printf("VESA NAVI-D"); break;
1911 default: printf("Reserved"); break;
1912 }
1913 printf(")\n");
1914 break;
1915 case 1: printf("LVDS %u lanes", v & 0xf); break;
1916 case 2: printf("RSDS %u lanes", v & 0xf); break;
1917 case 3: printf("DVI-D %u channels", v & 0xf); break;
1918 case 4: printf("DVI-I analog"); break;
1919 case 5: printf("DVI-I digital %u channels", v & 0xf); break;
1920 case 6: printf("HDMI-A"); break;
1921 case 7: printf("HDMI-B"); break;
1922 case 8: printf("MDDI %u channels", v & 0xf); break;
1923 case 9: printf("DisplayPort %u channels", v & 0xf); break;
1924 case 10: printf("IEEE-1394"); break;
1925 case 11: printf("M1 analog"); break;
1926 case 12: printf("M1 digital %u channels", v & 0xf); break;
1927 default: printf("Reserved"); break;
1928 }
1929 printf("\n");
1930
1931 printf(" Interface Standard Version: %u.%u\n", x[1] >> 4, x[1] & 0xf);
1932 printf(" Content Protection Support: ");
1933 switch (x[2]) {
1934 case 0: printf("None\n"); break;
1935 case 1: printf("HDCP\n"); break;
1936 case 2: printf("DTCP\n"); break;
1937 case 3: printf("DPCP\n"); break;
1938 default: printf("Reserved\n"); break;
1939 }
1940
1941 printf(" Minimum Clock Frequency: %u MHz\n", x[3] >> 2);
1942 printf(" Maximum Clock Frequency: %u MHz\n", ((x[3] & 0x03) << 8) | x[4]);
1943 printf(" Device Native Pixel Format: %ux%u\n",
1944 x[5] | (x[6] << 8), x[7] | (x[8] << 8));
1945 printf(" Aspect Ratio: %.2f\n", (100 + x[9]) / 100.0);
1946 v = x[0x0a];
1947 printf(" Default Orientation: ");
1948 switch ((v & 0xc0) >> 6) {
1949 case 0x00: printf("Landscape\n"); break;
1950 case 0x01: printf("Portrait\n"); break;
1951 case 0x02: printf("Not Fixed\n"); break;
1952 case 0x03: printf("Undefined\n"); break;
1953 }
1954 printf(" Rotation Capability: ");
1955 switch ((v & 0x30) >> 4) {
1956 case 0x00: printf("None\n"); break;
1957 case 0x01: printf("Can rotate 90 degrees clockwise\n"); break;
1958 case 0x02: printf("Can rotate 90 degrees counterclockwise\n"); break;
1959 case 0x03: printf("Can rotate 90 degrees in either direction)\n"); break;
1960 }
1961 printf(" Zero Pixel Location: ");
1962 switch ((v & 0x0c) >> 2) {
1963 case 0x00: printf("Upper Left\n"); break;
1964 case 0x01: printf("Upper Right\n"); break;
1965 case 0x02: printf("Lower Left\n"); break;
1966 case 0x03: printf("Lower Right\n"); break;
1967 }
1968 printf(" Scan Direction: ");
1969 switch (v & 0x03) {
1970 case 0x00: printf("Not defined\n"); break;
1971 case 0x01: printf("Fast Scan is on the Major (Long) Axis and Slow Scan is on the Minor Axis\n"); break;
1972 case 0x02: printf("Fast Scan is on the Minor (Short) Axis and Slow Scan is on the Major Axis\n"); break;
1973 case 0x03: printf("Reserved\n");
1974 fail("Scan Direction used the reserved value 0x03.\n");
1975 break;
1976 }
1977 printf(" Subpixel Information: ");
1978 switch (x[0x0b]) {
1979 case 0x00: printf("Not defined\n"); break;
1980 case 0x01: printf("RGB vertical stripes\n"); break;
1981 case 0x02: printf("RGB horizontal stripes\n"); break;
1982 case 0x03: printf("Vertical stripes using primary order\n"); break;
1983 case 0x04: printf("Horizontal stripes using primary order\n"); break;
1984 case 0x05: printf("Quad sub-pixels, red at top left\n"); break;
1985 case 0x06: printf("Quad sub-pixels, red at bottom left\n"); break;
1986 case 0x07: printf("Delta (triad) RGB sub-pixels\n"); break;
1987 case 0x08: printf("Mosaic\n"); break;
1988 case 0x09: printf("Quad sub-pixels, RGB + 1 additional color\n"); break;
1989 case 0x0a: printf("Five sub-pixels, RGB + 2 additional colors\n"); break;
1990 case 0x0b: printf("Six sub-pixels, RGB + 3 additional colors\n"); break;
1991 case 0x0c: printf("Clairvoyante, Inc. PenTile Matrix (tm) layout\n"); break;
1992 default: printf("Reserved\n"); break;
1993 }
1994 printf(" Horizontal and vertical dot/pixel pitch: %.2f x %.2f mm\n",
1995 (double)(x[0x0c]) / 100.0, (double)(x[0x0d]) / 100.0);
1996 v = x[0x0e];
1997 printf(" Dithering: ");
1998 switch (v >> 6) {
1999 case 0: printf("None\n"); break;
2000 case 1: printf("Spatial\n"); break;
2001 case 2: printf("Temporal\n"); break;
2002 case 3: printf("Spatial and Temporal\n"); break;
2003 }
2004 printf(" Direct Drive: %s\n", (v & 0x20) ? "Yes" : "No");
2005 printf(" Overdrive %srecommended\n", (v & 0x10) ? "not " : "");
2006 printf(" Deinterlacing: %s\n", (v & 0x08) ? "Yes" : "No");
2007
2008 v = x[0x0f];
2009 printf(" Audio Support: %s\n", (v & 0x80) ? "Yes" : "No");
2010 printf(" Separate Audio Inputs Provided: %s\n", (v & 0x40) ? "Yes" : "No");
2011 printf(" Audio Input Override: %s\n", (v & 0x20) ? "Yes" : "No");
2012 v = x[0x10];
2013 if (v)
2014 printf(" Audio Delay: %s%u ms\n", (v & 0x80) ? "" : "-", (v & 0x7f) * 2);
2015 else
2016 printf(" Audio Delay: no information provided\n");
2017 v = x[0x11];
2018 printf(" Frame Rate/Mode Conversion: ");
2019 switch (v >> 6) {
2020 case 0: printf("None\n"); break;
2021 case 1: printf("Single Buffering\n"); break;
2022 case 2: printf("Double Buffering\n"); break;
2023 case 3: printf("Advanced Frame Rate Conversion\n"); break;
2024 }
2025 if (v & 0x3f)
2026 printf(" Frame Rate Range: %u fps +/- %u fps\n",
2027 x[0x12], v & 0x3f);
2028 else
2029 printf(" Nominal Frame Rate: %u fps\n", x[0x12]);
2030 printf(" Color Bit Depth: %u @ interface, %u @ display\n",
2031 (x[0x13] >> 4) + 1, (x[0x13] & 0xf) + 1);
2032 v = x[0x15] & 3;
2033 if (v) {
2034 printf(" Additional Primary Chromaticities:\n");
2035 unsigned col_x = (x[0x16] << 2) | (x[0x14] >> 6);
2036 unsigned col_y = (x[0x17] << 2) | ((x[0x14] >> 4) & 3);
2037 printf(" Primary 4: 0.%04u, 0.%04u\n",
2038 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
2039 if (v > 1) {
2040 col_x = (x[0x18] << 2) | ((x[0x14] >> 2) & 3);
2041 col_y = (x[0x19] << 2) | (x[0x14] & 3);
2042 printf(" Primary 5: 0.%04u, 0.%04u\n",
2043 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
2044 if (v > 2) {
2045 col_x = (x[0x1a] << 2) | (x[0x15] >> 6);
2046 col_y = (x[0x1b] << 2) | ((x[0x15] >> 4) & 3);
2047 printf(" Primary 6: 0.%04u, 0.%04u\n",
2048 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
2049 }
2050 }
2051 }
2052
2053 v = x[0x1c];
2054 printf(" Response Time %s: %u ms\n",
2055 (v & 0x80) ? "White -> Black" : "Black -> White", v & 0x7f);
2056 v = x[0x1d];
2057 printf(" Overscan: %u%% x %u%%\n", v >> 4, v & 0xf);
2058 }
2059
2060 static double decode_uchar_as_double(unsigned char x)
2061 {
2062 signed char s = (signed char)x;
2063
2064 return s / 64.0;
2065 }
2066
2067 void edid_state::cta_rcdb(const unsigned char *x, unsigned length)
2068 {
2069 unsigned spm = ((x[3] << 16) | (x[2] << 8) | x[1]);
2070 unsigned i;
2071
2072 if (length < 4) {
2073 fail("Empty Data Block with length %u.\n", length);
2074 return;
2075 }
2076
2077 if ((x[0] & 0x20) && !cta.has_sldb)
2078 fail("'SLD' flag is 1, but no Speaker Location Data Block is found.\n");
2079 else if (!(x[0] & 0x20) && cta.has_sldb)
2080 fail("'SLD' flag is 0, but a Speaker Location Data Block is present.\n");
2081
2082 if (x[0] & 0x40) {
2083 printf(" Speaker count: %u\n", (x[0] & 0x1f) + 1);
2084 } else {
2085 if (x[0] & 0x1f)
2086 fail("'Speaker' flag is 0, but 'Speaker Count' is != 0.\n");
2087 if (x[0] & 0x20)
2088 fail("'SLD' flag is 1, but 'Speaker' is 0.\n");
2089 }
2090
2091 printf(" Speaker Presence Mask:\n");
2092 for (i = 0; cta_speaker_map[i]; i++) {
2093 if ((spm >> i) & 1)
2094 printf(" %s\n", cta_speaker_map[i]);
2095 }
2096
2097 if ((x[0] & 0xa0) == 0x80)
2098 fail("'Display' flag set, but not the 'SLD' flag.\n");
2099
2100 bool valid_max = cta.preparsed_sld_has_coord || (x[0] & 0x80);
2101
2102 if (valid_max && length >= 7) {
2103 printf(" Xmax: %u dm\n", x[4]);
2104 printf(" Ymax: %u dm\n", x[5]);
2105 printf(" Zmax: %u dm\n", x[6]);
2106 } else if (!valid_max && length >= 7) {
2107 // The RCDB should have been truncated.
2108 warn("'Display' flag is 0 and 'Coord' is 0 for all SLDs, but the Max coordinates are still present.\n");
2109 }
2110 if ((x[0] & 0x80) && length >= 10) {
2111 printf(" DisplayX: %.3f * Xmax\n", decode_uchar_as_double(x[7]));
2112 printf(" DisplayY: %.3f * Ymax\n", decode_uchar_as_double(x[8]));
2113 printf(" DisplayZ: %.3f * Zmax\n", decode_uchar_as_double(x[9]));
2114 } else if (!(x[0] & 0x80) && length >= 10) {
2115 // The RCDB should have been truncated.
2116 warn("'Display' flag is 0, but the Display coordinates are still present.\n");
2117 }
2118 }
2119
2120 static const struct {
2121 const char *name;
2122 double x, y, z;
2123 } speaker_location[] = {
2124 { "FL - Front Left", -1, 1, 0 },
2125 { "FR - Front Right", 1, 1, 0 },
2126 { "FC - Front Center", 0, 1, 0 },
2127 { "LFE1 - Low Frequency Effects 1", -0.5, 1, -1 },
2128 { "BL - Back Left", -1, -1, 0 },
2129 { "BR - Back Right", 1, -1, 0 },
2130 { "FLC - Front Left of Center", -0.5, 1, 0 },
2131 { "FRC - Front Right of Center", 0.5, 1, 0 },
2132 { "BC - Back Center", 0, -1, 0 },
2133 { "LFE2 - Low Frequency Effects 2", 0.5, 1, -1 },
2134 { "SiL - Side Left", -1, 1.0/3.0, 0 },
2135 { "SiR - Side Right", 1, 1.0/3.0, 0 },
2136 { "TpFL - Top Front Left", -1, 1, 1 },
2137 { "TpFR - Top Front Right", 1, 1, 1 },
2138 { "TpFC - Top Front Center", 0, 1, 1 },
2139 { "TpC - Top Center", 0, 0, 1 },
2140 { "TpBL - Top Back Left", -1, -1, 1 },
2141 { "TpBR - Top Back Right", 1, -1, 1 },
2142 { "TpSiL - Top Side Left", -1, 0, 1 },
2143 { "TpSiR - Top Side Right", 1, 0, 1 },
2144 { "TpBC - Top Back Center", 0, -1, 1 },
2145 { "BtFC - Bottom Front Center", 0, 1, -1 },
2146 { "BtFL - Bottom Front Left", -1, 1, -1 },
2147 { "BtFR - Bottom Front Right", 1, 1, -1 },
2148 { "FLW - Front Left Wide", -1, 2.0/3.0, 0 },
2149 { "FRW - Front Right Wide", 1, 2.0/3.0, 0 },
2150 { "LS - Left Surround", -1, 0, 0 },
2151 { "RS - Right Surround", 1, 0, 0 },
2152 };
2153
2154 void edid_state::cta_sldb(const unsigned char *x, unsigned length)
2155 {
2156 if (length < 2) {
2157 fail("Empty Data Block with length %u.\n", length);
2158 return;
2159 }
2160
2161 unsigned active_cnt = 0;
2162 unsigned channel_is_active = 0;
2163
2164 while (length >= 2) {
2165 printf(" Channel: %u (%sactive)\n", x[0] & 0x1f,
2166 (x[0] & 0x20) ? "" : "not ");
2167 if (x[0] & 0x20) {
2168 if (channel_is_active & (1U << (x[0] & 0x1f)))
2169 fail("Channel Index %u was already marked 'Active'.\n",
2170 x[0] & 0x1f);
2171 channel_is_active |= 1U << (x[0] & 0x1f);
2172 active_cnt++;
2173 }
2174
2175 unsigned speaker_id = x[1] & 0x1f;
2176
2177 if (speaker_id < ARRAY_SIZE(speaker_location)) {
2178 printf(" Speaker ID: %s\n", speaker_location[speaker_id].name);
2179 } else if (speaker_id == 0x1f) {
2180 printf(" Speaker ID: None Specified\n");
2181 } else {
2182 printf(" Speaker ID: Reserved (%u)\n", speaker_id);
2183 fail("Reserved Speaker ID specified.\n");
2184 }
2185 if (length >= 5 && (x[0] & 0x40)) {
2186 printf(" X: %.3f * Xmax\n", decode_uchar_as_double(x[2]));
2187 printf(" Y: %.3f * Ymax\n", decode_uchar_as_double(x[3]));
2188 printf(" Z: %.3f * Zmax\n", decode_uchar_as_double(x[4]));
2189 length -= 3;
2190 x += 3;
2191 } else if (speaker_id < ARRAY_SIZE(speaker_location)) {
2192 printf(" X: %.3f * Xmax (approximately)\n", speaker_location[speaker_id].x);
2193 printf(" Y: %.3f * Ymax (approximately)\n", speaker_location[speaker_id].y);
2194 printf(" Z: %.3f * Zmax (approximately)\n", speaker_location[speaker_id].z);
2195 }
2196
2197 length -= 2;
2198 x += 2;
2199 }
2200 if (active_cnt != cta.preparsed_speaker_count)
2201 fail("There are %u active speakers, but 'Speaker Count' is %u.\n",
2202 active_cnt, cta.preparsed_speaker_count);
2203 }
2204
2205 void edid_state::cta_preparse_sldb(const unsigned char *x, unsigned length)
2206 {
2207 cta.has_sldb = true;
2208 while (length >= 2) {
2209 if (length >= 5 && (x[0] & 0x40)) {
2210 cta.preparsed_sld_has_coord = true;
2211 return;
2212 }
2213 length -= 2;
2214 x += 2;
2215 }
2216 }
2217
2218 void edid_state::cta_vcdb(const unsigned char *x, unsigned length)
2219 {
2220 unsigned char d = x[0];
2221
2222 cta.has_vcdb = true;
2223 if (length < 1) {
2224 fail("Empty Data Block with length %u.\n", length);
2225 return;
2226 }
2227 printf(" YCbCr quantization: %s\n",
2228 (d & 0x80) ? "Selectable (via AVI YQ)" : "No Data");
2229 printf(" RGB quantization: %s\n",
2230 (d & 0x40) ? "Selectable (via AVI Q)" : "No Data");
2231 /*
2232 * If this bit is not set then that will result in interoperability
2233 * problems (specifically with PCs/laptops) that quite often do not
2234 * follow the default rules with respect to RGB Quantization Range
2235 * handling.
2236 *
2237 * Starting with the CTA-861-H spec this bit is now required to be
2238 * 1 for new designs.
2239 */
2240 if (!(d & 0x40))
2241 fail("Set Selectable RGB Quantization to avoid interop issues.\n");
2242 /*
2243 * Since most YCbCr formats use limited range, the interop issues are
2244 * less noticable than for RGB formats.
2245 *
2246 * Starting with the CTA-861-H spec this bit is now required to be
2247 * 1 for new designs, but just warn about it (for now).
2248 */
2249 if ((cta.byte3 & 0x30) && !(d & 0x80))
2250 warn("Set Selectable YCbCr Quantization to avoid interop issues.\n");
2251
2252 unsigned char s_pt = (d >> 4) & 0x03;
2253 unsigned char s_it = (d >> 2) & 0x03;
2254 unsigned char s_ce = d & 0x03;
2255
2256 printf(" PT scan behavior: ");
2257 switch (s_pt) {
2258 case 0: printf("No Data\n"); break;
2259 case 1: printf("Always Overscanned\n"); break;
2260 case 2: printf("Always Underscanned\n"); break;
2261 case 3: printf("Supports both over- and underscan\n"); break;
2262 }
2263 printf(" IT scan behavior: ");
2264 switch (s_it) {
2265 case 0: printf("IT video formats not supported\n"); break;
2266 case 1:
2267 printf("Always Overscanned\n");
2268 // See Table 52 of CTA-861-G for a description of Byte 3
2269 if (cta.byte3 & 0x80)
2270 fail("IT video formats are always overscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to underscanned.\n");
2271 break;
2272 case 2:
2273 printf("Always Underscanned\n");
2274 // See Table 52 of CTA-861-G for a description of Byte 3
2275 if (!(cta.byte3 & 0x80))
2276 fail("IT video formats are always underscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to overscanned.\n");
2277 break;
2278 case 3: printf("Supports both over- and underscan\n"); break;
2279 }
2280 if (s_it < 2)
2281 warn("IT scan behavior is expected to support underscanned.\n");
2282 printf(" CE scan behavior: ");
2283 switch (s_ce) {
2284 case 0: printf("CE video formats not supported\n"); break;
2285 case 1: printf("Always Overscanned\n"); break;
2286 case 2: printf("Always Underscanned\n"); break;
2287 case 3: printf("Supports both over- and underscan\n"); break;
2288 }
2289 if (s_ce == 0)
2290 warn("'CE video formats not supported' makes no sense.\n");
2291 else if (s_pt == s_it && s_pt == s_ce)
2292 warn("S_PT is equal to S_IT and S_CE, so should be set to 0 instead.\n");
2293 }
2294
2295 static const char *colorimetry1_map[] = {
2296 "xvYCC601",
2297 "xvYCC709",
2298 "sYCC601",
2299 "opYCC601",
2300 "opRGB",
2301 "BT2020cYCC",
2302 "BT2020YCC",
2303 "BT2020RGB",
2304 };
2305
2306 static const char *colorimetry2_map[] = {
2307 "Gamut Boundary Description Metadata Profile P0",
2308 "Reserved F41",
2309 "Reserved F42",
2310 "Reserved F43",
2311 "Default",
2312 "sRGB",
2313 "ICtCp",
2314 "ST2113RGB",
2315 };
2316
2317 void edid_state::cta_colorimetry_block(const unsigned char *x, unsigned length)
2318 {
2319 unsigned i;
2320
2321 if (length < 2) {
2322 fail("Empty Data Block with length %u.\n", length);
2323 return;
2324 }
2325 for (i = 0; i < ARRAY_SIZE(colorimetry1_map); i++)
2326 if (x[0] & (1 << i))
2327 printf(" %s\n", colorimetry1_map[i]);
2328 // Bit MD0 is used to indicate if HDMI Gamut Boundary Description
2329 // Metadata Profile P0 is supported. Bits F41-F43 are reserved
2330 // and must be set to 0.
2331 if (x[1] & 0xe)
2332 fail("Reserved bits F41-F43 must be 0.\n");
2333 for (i = 0; i < ARRAY_SIZE(colorimetry2_map); i++)
2334 if (x[1] & (1 << i))
2335 printf(" %s\n", colorimetry2_map[i]);
2336 // The sRGB bit (added in CTA-861.6) allows sources to explicitly
2337 // signal sRGB colorimetry. Without this the default colorimetry
2338 // of an RGB video is either sRGB or defaultRGB. It depends on the
2339 // Source which is used, and the Sink has no idea what it is getting.
2340 //
2341 // For proper compatibility with PCs enabling sRGB support is
2342 // desirable.
2343 if (!base.uses_srgb && !(x[1] & 0x20))
2344 warn("Set the sRGB colorimetry bit to avoid interop issues.\n");
2345 if (x[1] & 0xf0)
2346 cta.avi_version = 4;
2347 }
2348
2349 static const char *eotf_map[] = {
2350 "Traditional gamma - SDR luminance range",
2351 "Traditional gamma - HDR luminance range",
2352 "SMPTE ST2084",
2353 "Hybrid Log-Gamma",
2354 };
2355
2356 static void cta_hdr_static_metadata_block(const unsigned char *x, unsigned length)
2357 {
2358 unsigned i;
2359
2360 if (length < 2) {
2361 fail("Empty Data Block with length %u.\n", length);
2362 return;
2363 }
2364 printf(" Electro optical transfer functions:\n");
2365 for (i = 0; i < 6; i++) {
2366 if (x[0] & (1 << i)) {
2367 if (i < ARRAY_SIZE(eotf_map)) {
2368 printf(" %s\n", eotf_map[i]);
2369 } else {
2370 printf(" Unknown (%u)\n", i);
2371 fail("Unknown EOTF (%u).\n", i);
2372 }
2373 }
2374 }
2375 printf(" Supported static metadata descriptors:\n");
2376 for (i = 0; i < 8; i++) {
2377 if (x[1] & (1 << i))
2378 printf(" Static metadata type %u\n", i + 1);
2379 }
2380
2381 if (length >= 3)
2382 printf(" Desired content max luminance: %u (%.3f cd/m^2)\n",
2383 x[2], 50.0 * pow(2, x[2] / 32.0));
2384
2385 if (length >= 4)
2386 printf(" Desired content max frame-average luminance: %u (%.3f cd/m^2)\n",
2387 x[3], 50.0 * pow(2, x[3] / 32.0));
2388
2389 if (length >= 5)
2390 printf(" Desired content min luminance: %u (%.3f cd/m^2)\n",
2391 x[4], (50.0 * pow(2, x[2] / 32.0)) * pow(x[4] / 255.0, 2) / 100.0);
2392 }
2393
2394 static void cta_hdr_dyn_metadata_block(const unsigned char *x, unsigned length)
2395 {
2396 if (length < 3) {
2397 fail("Empty Data Block with length %u.\n", length);
2398 return;
2399 }
2400 while (length >= 3) {
2401 unsigned type_len = x[0];
2402 unsigned type = x[1] | (x[2] << 8);
2403
2404 if (length < type_len + 1)
2405 return;
2406 printf(" HDR Dynamic Metadata Type %u\n", type);
2407 switch (type) {
2408 case 1:
2409 case 4:
2410 if (type_len > 2)
2411 printf(" Version: %u\n", x[3] & 0xf);
2412 break;
2413 case 2:
2414 if (type_len > 2) {
2415 unsigned version = x[3] & 0xf;
2416 printf(" Version: %u\n", version);
2417 if (version >= 1) {
2418 if (x[3] & 0x10) printf(" Supports SL-HDR1 (ETSI TS 103 433-1)\n");
2419 if (x[3] & 0x20) printf(" Supports SL-HDR2 (ETSI TS 103 433-2)\n");
2420 if (x[3] & 0x40) printf(" Supports SL-HDR3 (ETSI TS 103 433-3)\n");
2421 }
2422 }
2423 break;
2424 default:
2425 break;
2426 }
2427 length -= type_len + 1;
2428 x += type_len + 1;
2429 }
2430 }
2431
2432 static const char *infoframe_types[] = {
2433 NULL,
2434 "Vendor-Specific",
2435 "Auxiliary Video Information",
2436 "Source Product Description",
2437 "Audio",
2438 "MPEG Source",
2439 "NTSC VBI",
2440 "Dynamic Range and Mastering",
2441 };
2442
2443 static void cta_ifdb(const unsigned char *x, unsigned length)
2444 {
2445 unsigned len_hdr = x[0] >> 5;
2446
2447 if (length < 2) {
2448 fail("Empty Data Block with length %u.\n", length);
2449 return;
2450 }
2451 if (x[0] & 0x1f)
2452 fail("Bits F14-F10 are 0x%02x instead of 0x00.\n", x[0] & 0x1f);
2453 printf(" VSIFs: %u\n", x[1]);
2454 if (length < len_hdr + 2)
2455 return;
2456 length -= len_hdr + 2;
2457 x += len_hdr + 2;
2458 while (length > 0) {
2459 unsigned payload_len = x[0] >> 5;
2460 unsigned char type = x[0] & 0x1f;
2461
2462 if (payload_len) {
2463 fail("Payload size must be 0, but it is %u.\n", payload_len);
2464 break;
2465 }
2466
2467 const char *name = NULL;
2468 if (type < ARRAY_SIZE(infoframe_types))
2469 name = infoframe_types[type];
2470 if (!name)
2471 name = "Unknown";
2472 printf(" %s InfoFrame (%u)", name, type);
2473
2474 if (type == 1) {
2475 if (length < 4) {
2476 fail("Remaining length %u < 4.\n");
2477 break;
2478 }
2479
2480 unsigned oui = (x[3] << 16) | (x[2] << 8) | x[1];
2481
2482 printf(", OUI %s\n", ouitohex(oui).c_str());
2483 x += 4;
2484 length -= 4;
2485 } else {
2486 printf("\n");
2487 x++;
2488 length--;
2489 }
2490 }
2491 }
2492
2493 void edid_state::cta_pidb(const unsigned char *x, unsigned length)
2494 {
2495 if (length < 4) {
2496 fail("Empty Data Block with length %u.\n", length);
2497 return;
2498 }
2499 unsigned oui = (x[0] << 16) | (x[1] << 8) | x[2];
2500 printf(" IEEE CID/OUI: %s\n", ouitohex(oui).c_str());
2501 if (length == 4)
2502 return;
2503 printf(" Version: %u\n", x[3]);
2504 if (x[3])
2505 fail("Unsupported version %u.\n", x[3]);
2506 if (length == 5)
2507 return;
2508 char pn[26];
2509 memcpy(pn, x + 4, length - 5);
2510 pn[length - 5] = 0;
2511 for (unsigned i = 0; i < length - 5; i++)
2512 if (x[4 + i] < 0x20 || x[4 + i] >= 0x80)
2513 fail("Product Name: invalid ASCII value at position %u.\n", i);
2514 printf(" Product Name: %s\n", pn);
2515 }
2516
2517 void edid_state::cta_displayid_type_7(const unsigned char *x, unsigned length)
2518 {
2519 check_displayid_datablock_revision(x[0], 0x00, 2);
2520
2521 if (length < 21U + ((x[0] & 0x70) >> 4)) {
2522 fail("Empty Data Block with length %u.\n", length);
2523 return;
2524 }
2525 parse_displayid_type_1_7_timing(x + 1, true, 2, true);
2526 }
2527
2528 void edid_state::cta_displayid_type_8(const unsigned char *x, unsigned length)
2529 {
2530 check_displayid_datablock_revision(x[0], 0xe8, 1);
2531 if (length < ((x[0] & 0x08) ? 3 : 2)) {
2532 fail("Empty Data Block with length %u.\n", length);
2533 return;
2534 }
2535
2536 unsigned sz = (x[0] & 0x08) ? 2 : 1;
2537 unsigned type = x[0] >> 6;
2538
2539 if (type) {
2540 fail("Only code type 0 is supported.\n");
2541 return;
2542 }
2543
2544 if (x[0] & 0x20)
2545 printf(" Also supports YCbCr 4:2:0\n");
2546
2547 x++;
2548 length--;
2549 for (unsigned i = 0; i < length / sz; i++) {
2550 unsigned id = x[i * sz];
2551
2552 if (sz == 2)
2553 id |= x[i * sz + 1] << 8;
2554 parse_displayid_type_4_8_timing(type, id, true);
2555 }
2556 }
2557
2558 void edid_state::cta_displayid_type_10(const unsigned char *x, unsigned length)
2559 {
2560 check_displayid_datablock_revision(x[0], 0x70);
2561 if (length < 7U + ((x[0] & 0x70) >> 4)) {
2562 fail("Empty Data Block with length %u.\n", length);
2563 return;
2564 }
2565
2566 unsigned sz = 6U + ((x[0] & 0x70) >> 4);
2567 x++;
2568 length--;
2569 for (unsigned i = 0; i < length / sz; i++)
2570 parse_displayid_type_10_timing(x + i * sz, sz, true);
2571 }
2572
2573 static void cta_hdmi_audio_block(const unsigned char *x, unsigned length)
2574 {
2575 unsigned num_descs;
2576
2577 if (length < 2) {
2578 fail("Empty Data Block with length %u.\n", length);
2579 return;
2580 }
2581 if (x[0] & 3) {
2582 printf(" Max Stream Count: %u\n", (x[0] & 3) + 1);
2583 if (x[0] & 4)
2584 printf(" Supports MS NonMixed\n");
2585 } else if (x[0] & 4) {
2586 fail("MS NonMixed support indicated but Max Stream Count == 0.\n");
2587 }
2588
2589 num_descs = x[1] & 7;
2590 if (num_descs == 0)
2591 return;
2592 length -= 2;
2593 x += 2;
2594 while (length >= 4) {
2595 if (length > 4) {
2596 unsigned format = x[0] & 0xf;
2597
2598 printf(" %s:\n", audio_format(format).c_str());
2599 printf(" Max channels: %u\n", (x[1] & 0x1f)+1);
2600 printf(" Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
2601 (x[2] & 0x40) ? " 192" : "",
2602 (x[2] & 0x20) ? " 176.4" : "",
2603 (x[2] & 0x10) ? " 96" : "",
2604 (x[2] & 0x08) ? " 88.2" : "",
2605 (x[2] & 0x04) ? " 48" : "",
2606 (x[2] & 0x02) ? " 44.1" : "",
2607 (x[2] & 0x01) ? " 32" : "");
2608 if (format == 1)
2609 printf(" Supported sample sizes (bits):%s%s%s\n",
2610 (x[3] & 0x04) ? " 24" : "",
2611 (x[3] & 0x02) ? " 20" : "",
2612 (x[3] & 0x01) ? " 16" : "");
2613 } else {
2614 unsigned sad = ((x[2] << 16) | (x[1] << 8) | x[0]);
2615 unsigned i;
2616
2617 switch (x[3] >> 4) {
2618 case 1:
2619 printf(" Speaker Allocation for 10.2 channels:\n");
2620 break;
2621 case 2:
2622 printf(" Speaker Allocation for 22.2 channels:\n");
2623 break;
2624 case 3:
2625 printf(" Speaker Allocation for 30.2 channels:\n");
2626 break;
2627 default:
2628 printf(" Unknown Speaker Allocation (0x%02x)\n", x[3] >> 4);
2629 return;
2630 }
2631
2632 for (i = 0; cta_speaker_map[i]; i++) {
2633 if ((sad >> i) & 1)
2634 printf(" %s\n", cta_speaker_map[i]);
2635 }
2636 }
2637 length -= 4;
2638 x += 4;
2639 }
2640 }
2641
2642 void edid_state::cta_block(const unsigned char *x, std::vector<unsigned> &found_tags)
2643 {
2644 unsigned length = x[0] & 0x1f;
2645 unsigned tag = (x[0] & 0xe0) >> 5;
2646 unsigned extended = (tag == 0x07) ? 1 : 0;
2647
2648 x++;
2649 if (extended && length) {
2650 tag <<= 8;
2651 tag |= x[0];
2652 length--;
2653 x++;
2654 }
2655
2656 bool dooutputname = true;
2657 bool audio_block = false;
2658 data_block.clear();
2659
2660 switch (tag) {
2661 case 0x01: data_block = "Audio Data Block"; audio_block = true; break;
2662 case 0x02: data_block = "Video Data Block"; break;
2663 case 0x03: data_block = "Vendor-Specific Data Block"; break;
2664 case 0x04: data_block = "Speaker Allocation Data Block"; audio_block = true; break;
2665 case 0x05: data_block = "VESA Display Transfer Characteristics Data Block"; break;
2666 case 0x06: data_block = "Video Format Data Block"; break;
2667 case 0x07: data_block = "Unknown CTA-861 Data Block (extended tag truncated)"; break;
2668
2669 case 0x700: data_block = "Video Capability Data Block"; break;
2670 case 0x701: data_block = "Vendor-Specific Video Data Block"; break;
2671 case 0x702: data_block = "VESA Video Display Device Data Block"; break;
2672 case 0x703: data_block = "VESA Video Timing Block Extension"; break;
2673 case 0x704: data_block = "Reserved for HDMI Video Data Block"; break;
2674 case 0x705: data_block = "Colorimetry Data Block"; break;
2675 case 0x706: data_block = "HDR Static Metadata Data Block"; break;
2676 case 0x707: data_block = "HDR Dynamic Metadata Data Block"; break;
2677 case 0x708: data_block = "Native Video Resolution Data Block"; break;
2678
2679 case 0x70d: data_block = "Video Format Preference Data Block"; break;
2680 case 0x70e: data_block = "YCbCr 4:2:0 Video Data Block"; break;
2681 case 0x70f: data_block = "YCbCr 4:2:0 Capability Map Data Block"; break;
2682 case 0x710: data_block = "Reserved for CTA-861 Miscellaneous Audio Fields"; break;
2683 case 0x711: data_block = "Vendor-Specific Audio Data Block"; audio_block = true; break;
2684 case 0x712: data_block = "HDMI Audio Data Block"; audio_block = true; break;
2685 case 0x713: data_block = "Room Configuration Data Block"; audio_block = true; break;
2686 case 0x714: data_block = "Speaker Location Data Block"; audio_block = true; break;
2687
2688 case 0x720: data_block = "InfoFrame Data Block"; break;
2689 case 0x721: data_block = "Product Information Data Block"; break;
2690
2691 case 0x722: data_block = "DisplayID Type VII Video Timing Data Block"; break;
2692 case 0x723: data_block = "DisplayID Type VIII Video Timing Data Block"; break;
2693 case 0x72a: data_block = "DisplayID Type X Video Timing Data Block"; break;
2694
2695 case 0x778: data_block = "HDMI Forum EDID Extension Override Data Block"; break;
2696 case 0x779: data_block = "HDMI Forum Sink Capability Data Block"; break;
2697 case 0x77a: data_block = "HDMI Forum Source-Based Tone Mapping Data Block"; break;
2698
2699 default:
2700 std::string unknown_name;
2701 if (tag < 0x700) unknown_name = "Unknown CTA-861 Data Block";
2702 else if (tag < 0x70d) unknown_name = "Unknown CTA-861 Video-Related Data Block";
2703 else if (tag < 0x720) unknown_name = "Unknown CTA-861 Audio-Related Data Block";
2704 else if (tag < 0x778) unknown_name = "Unknown CTA-861 Data Block";
2705 else if (tag < 0x780) unknown_name = "Unknown CTA-861 HDMI-Related Data Block";
2706 else unknown_name = "Unknown CTA-861 Data Block";
2707 unknown_name += std::string(" (") + (extended ? "extended " : "") + "tag " + utohex(tag & 0xff) + ", length " + std::to_string(length) + ")";
2708 printf(" %s:\n", unknown_name.c_str());
2709 warn("%s.\n", unknown_name.c_str());
2710 break;
2711 }
2712
2713 switch (tag) {
2714 case 0x03:
2715 case 0x701:
2716 case 0x711: {
2717 unsigned ouinum;
2718
2719 data_block_oui(data_block, x, length, &ouinum);
2720 x += (length < 3) ? length : 3;
2721 length -= (length < 3) ? length : 3;
2722 dooutputname = false;
2723 tag |= ouinum;
2724 break;
2725 }
2726 }
2727
2728 if (dooutputname && data_block.length())
2729 printf(" %s:\n", data_block.c_str());
2730
2731 switch (tag) {
2732 case 0x04:
2733 case 0x05:
2734 case 0x700:
2735 case 0x702:
2736 case 0x705:
2737 case 0x706:
2738 case 0x708:
2739 case 0x70d:
2740 case 0x70f:
2741 case 0x712:
2742 case 0x713:
2743 case 0x721:
2744 case 0x778:
2745 case 0x779:
2746 case 0x77a:
2747 if (std::find(found_tags.begin(), found_tags.end(), tag) != found_tags.end())
2748 fail("Only one instance of this Data Block is allowed.\n");
2749 break;
2750 }
2751
2752 // See Table 52 of CTA-861-G for a description of Byte 3
2753 if (audio_block && !(cta.byte3 & 0x40))
2754 fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
2755
2756 switch (tag) {
2757 case 0x01: cta_audio_block(x, length); break;
2758 case 0x02: cta_svd(x, length, false); break;
2759 case 0x03|kOUI_HDMI:
2760 cta_hdmi_block(x, length);
2761 // The HDMI OUI is present, so this EDID represents an HDMI
2762 // interface. And HDMI interfaces must use EDID version 1.3
2763 // according to the HDMI Specification, so check for this.
2764 if (base.edid_minor != 3)
2765 fail("The HDMI Specification requires EDID 1.3 instead of 1.%u.\n",
2766 base.edid_minor);
2767 break;
2768 case 0x03|kOUI_HDMIForum:
2769 if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
2770 fail("HDMI Forum VSDB did not immediately follow the HDMI VSDB.\n");
2771 if (cta.have_hf_scdb || cta.have_hf_vsdb)
2772 fail("Duplicate HDMI Forum VSDB/SCDB.\n");
2773 cta_hf_scdb(x, length);
2774 cta.have_hf_vsdb = true;
2775 break;
2776 case 0x03|kOUI_AMD: cta_amd(x, length); break;
2777 case 0x03|kOUI_Microsoft: if (length != 0x12) goto dodefault; cta_microsoft(x, length); break;
2778 case 0x03|kOUI_UHDA: cta_uhda_fmm(x, length); break;
2779 case 0x04: cta_sadb(x, length); break;
2780 case 0x05: cta_vesa_dtcdb(x, length); break;
2781 case 0x06: cta_vfdb(x, length); break;
2782 case 0x07: fail("Extended tag cannot have zero length.\n"); break;
2783 case 0x700: cta_vcdb(x, length); break;
2784 case 0x701|kOUI_HDR10: cta_hdr10plus(x, length); break;
2785 case 0x701|kOUI_Dolby: cta_dolby_video(x, length); break;
2786 // 0x701|kOUI_Apple: this almost certainly contains 'BLC Info/Corrections',
2787 // since the data (spread out over two VSDBs) is very similar to what is seen
2788 // in DisplayID blocks. Since I don't know how to parse this data, we still
2789 // default to a hex dump, but I mention this here in case data on how to
2790 // parse this becomes available.
2791 case 0x702: cta_vesa_vdddb(x, length); break;
2792 case 0x705: cta_colorimetry_block(x, length); break;
2793 case 0x706: cta_hdr_static_metadata_block(x, length); break;
2794 case 0x707: cta_hdr_dyn_metadata_block(x, length); break;
2795 case 0x708: cta_nvrdb(x, length); return;
2796 case 0x70d: cta_vfpdb(x, length); break;
2797 case 0x70e: cta_svd(x, length, true); break;
2798 case 0x70f: cta_y420cmdb(x, length); break;
2799 case 0x711|kOUI_Dolby: cta_dolby_audio(x, length); break;
2800 case 0x712: cta_hdmi_audio_block(x, length); break;
2801 case 0x713: cta_rcdb(x, length); break;
2802 case 0x714: cta_sldb(x, length); break;
2803 case 0x720: cta_ifdb(x, length); break;
2804 case 0x721: cta_pidb(x, length); break;
2805 case 0x722: cta_displayid_type_7(x, length); break;
2806 case 0x723: cta_displayid_type_8(x, length); break;
2807 case 0x72a: cta_displayid_type_10(x, length); break;
2808 case 0x778:
2809 cta_hf_eeodb(x, length);
2810 if (block_nr != 1)
2811 fail("Data Block can only be present in Block 1.\n");
2812 // This must be the first CTA-861 block
2813 if (cta.block_number > 0)
2814 fail("Data Block starts at a wrong offset.\n");
2815 break;
2816 case 0x779:
2817 if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
2818 fail("HDMI Forum SCDB did not immediately follow the HDMI VSDB.\n");
2819 if (cta.have_hf_scdb || cta.have_hf_vsdb)
2820 fail("Duplicate HDMI Forum VSDB/SCDB.\n");
2821 if (block_nr != 1)
2822 fail("Data Block can only be present in Block 1.\n");
2823 if (length < 2) {
2824 data_block = std::string("HDMI Forum SCDB");
2825 fail("Invalid length %u < 2.\n", length);
2826 break;
2827 }
2828 if (x[0] || x[1])
2829 printf(" Non-zero SCDB reserved fields!\n");
2830 cta_hf_scdb(x + 2, length - 2);
2831 cta.have_hf_scdb = true;
2832 break;
2833 case 0x77a:
2834 cta_hf_sbtmdb(x, length);
2835 break;
2836 dodefault:
2837 default:
2838 hex_block(" ", x, length);
2839 break;
2840 }
2841
2842 cta.block_number++;
2843 cta.previous_cta_tag = tag;
2844 found_tags.push_back(tag);
2845 }
2846
2847 void edid_state::preparse_cta_block(unsigned char *x)
2848 {
2849 unsigned version = x[1];
2850 unsigned offset = x[2];
2851
2852 if (offset >= 4) {
2853 unsigned char *detailed;
2854 bool update_checksum = false;
2855
2856 for (detailed = x + offset; detailed + 17 < x + 127; detailed += 18) {
2857 if (memchk(detailed, 18))
2858 break;
2859 update_checksum |= preparse_detailed_block(detailed);
2860 if (detailed[0] || detailed[1])
2861 cta.preparsed_total_dtds++;
2862 }
2863 if (update_checksum)
2864 replace_checksum(x, EDID_PAGE_SIZE);
2865 }
2866
2867 if (version < 3)
2868 return;
2869
2870 if (!cta.byte3)
2871 cta.byte3 = x[3];
2872
2873 for (unsigned i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
2874 bool for_ycbcr420 = false;
2875 unsigned oui;
2876
2877 switch ((x[i] & 0xe0) >> 5) {
2878 case 0x03:
2879 if ((x[i] & 0x1f) < 5)
2880 continue;
2881 oui = (x[i + 3] << 16) + (x[i + 2] << 8) + x[i + 1];
2882 if (oui == 0x000c03) {
2883 unsigned length = x[i] & 0x1f;
2884 unsigned b = i + 8;
2885
2886 cta.has_hdmi = true;
2887 cta.preparsed_phys_addr = (x[i + 4] << 8) | x[i + 5];
2888 if (length < 9 || !(x[b] & 0x20))
2889 continue;
2890 if (x[b] & 0x80) {
2891 if (length < 11)
2892 continue;
2893 if (x[b] & 0x40) {
2894 if (length < 13)
2895 continue;
2896 b += 2;
2897 }
2898 b += 2;
2899 }
2900 cta.preparsed_image_size = (enum hdmi_image_size)((x[b + 1] & 0x18) >> 3);
2901 } else if ((oui == 0xca125c || oui == 0x5c12ca) &&
2902 (x[i] & 0x1f) == 0x15 && replace_unique_ids) {
2903 memset(x + i + 6, 0, 16);
2904 replace_checksum(x, EDID_PAGE_SIZE);
2905 }
2906 break;
2907 case 0x06:
2908 if (!(x[i] & 0x1f) || cta.preparsed_first_vfd.rid)
2909 break;
2910 cta.preparsed_first_vfd = cta_parse_vfd(x + i + 2, (x[i + 1] & 3) + 1);
2911 break;
2912 case 0x07:
2913 if (x[i + 1] == 0x0d)
2914 cta.has_vfpdb = true;
2915 else if (x[i + 1] == 0x05)
2916 cta.has_cdb = true;
2917 else if (x[i + 1] == 0x08)
2918 cta.has_nvrdb = true;
2919 else if (x[i + 1] == 0x21)
2920 cta.has_pidb = true;
2921 else if (x[i + 1] == 0x13 && (x[i + 2] & 0x40)) {
2922 cta.preparsed_speaker_count = 1 + (x[i + 2] & 0x1f);
2923 cta.preparsed_sld = x[i + 2] & 0x20;
2924 } else if (x[i + 1] == 0x14)
2925 cta_preparse_sldb(x + i + 2, (x[i] & 0x1f) - 1);
2926 else if (x[i + 1] == 0x22)
2927 cta.preparsed_total_vtdbs++;
2928 else if (x[i + 1] == 0x23) {
2929 cta.preparsed_has_t8vtdb = true;
2930 cta.preparsed_t8vtdb_dmt = x[i + 3];
2931 if (x[i + 2] & 0x08)
2932 cta.preparsed_t8vtdb_dmt |= x[i + 4] << 8;
2933 } else if (x[i + 1] == 0x2a)
2934 cta.preparsed_total_vtdbs +=
2935 ((x[i] & 0x1f) - 2) / (6 + ((x[i + 2] & 0x70) >> 4));
2936 else if (x[i + 1] == 0x78)
2937 cta.hf_eeodb_blocks = x[i + 2];
2938 if (x[i + 1] != 0x0e)
2939 continue;
2940 for_ycbcr420 = true;
2941 #ifdef __EMSCRIPTEN__
2942 [[clang::fallthrough]];
2943 #endif
2944 /* fall-through */
2945 case 0x02:
2946 for (unsigned j = 1 + for_ycbcr420; j <= (x[i] & 0x1f); j++) {
2947 unsigned char vic = x[i + j];
2948
2949 if ((vic & 0x7f) <= 64)
2950 vic &= 0x7f;
2951 cta.preparsed_svds[for_ycbcr420].push_back(vic);
2952 cta.preparsed_has_vic[for_ycbcr420][vic] = true;
2953
2954 const struct timings *t = find_vic_id(vic);
2955
2956 if (!for_ycbcr420 && t &&
2957 t->pixclk_khz > cta.preparsed_max_vic_pixclk_khz)
2958 cta.preparsed_max_vic_pixclk_khz = t->pixclk_khz;
2959 }
2960 break;
2961 }
2962 }
2963 }
2964
2965 void edid_state::parse_cta_block(const unsigned char *x)
2966 {
2967 unsigned version = x[1];
2968 unsigned offset = x[2];
2969 const unsigned char *detailed;
2970
2971 // See Table 52 of CTA-861-G for a description of Byte 3
2972
2973 printf(" Revision: %u\n", version);
2974 if (version == 0)
2975 fail("Invalid CTA-861 Extension revision 0.\n");
2976 if (version == 2)
2977 fail("Deprecated CTA-861 Extension revision 2.\n");
2978 if (cta.has_hdmi && version != 3)
2979 fail("The HDMI Specification requires CTA Extension revision 3.\n");
2980 if (version > 3)
2981 warn("Unknown CTA-861 Extension revision %u.\n", version);
2982 if (offset > 0 && offset < 4)
2983 fail("Invalid CTA-861 Extension offset value (byte 2).\n");
2984
2985 if (version >= 1) do {
2986 if (version == 1 && x[3] != 0)
2987 fail("Non-zero byte 3.\n");
2988
2989 if (version < 3 && offset >= 4 && ((offset - 4) / 8)) {
2990 printf(" 8-byte timing descriptors: %u\n", (offset - 4) / 8);
2991 fail("8-byte descriptors were never used.\n");
2992 }
2993
2994 if (version >= 2) {
2995 if (x[3] & 0x80)
2996 printf(" Underscans IT Video Formats by default\n");
2997 else
2998 warn("IT Video Formats are overscanned by default, but normally this should be underscanned.\n");
2999 if (x[3] & 0x40)
3000 printf(" Basic audio support\n");
3001 if (x[3] & 0x20) {
3002 printf(" Supports YCbCr 4:4:4\n");
3003 cta.has_ycbcr444 = true;
3004 }
3005 if (x[3] & 0x10) {
3006 printf(" Supports YCbCr 4:2:2\n");
3007 cta.has_ycbcr422 = true;
3008 }
3009 // Disable this test: this fails a lot of EDIDs, and there are
3010 // also some corner cases where you only want to receive 4:4:4
3011 // and refuse a fallback to 4:2:2.
3012 // if ((x[3] & 0x30) && (x[3] & 0x30) != 0x30)
3013 // msg(!cta.has_hdmi, "If YCbCr support is indicated, then both 4:2:2 and 4:4:4 %s be supported.\n",
3014 // cta.has_hdmi ? "shall" : "should");
3015 printf(" Native detailed modes: %u\n", x[3] & 0x0f);
3016 if (cta.block_number == 0)
3017 cta.byte3 = x[3];
3018 else if (x[3] != cta.byte3)
3019 fail("Byte 3 must be the same for all CTA-861 Extension Blocks.\n");
3020 if (cta.block_number == 0) {
3021 unsigned native_dtds = x[3] & 0x0f;
3022
3023 cta.native_timings.clear();
3024 if (!native_dtds && !cta.has_vfpdb) {
3025 cta.first_svd_might_be_preferred = true;
3026 } else if (native_dtds > cta.preparsed_total_dtds) {
3027 fail("There are more Native DTDs (%u) than DTDs (%u).\n",
3028 native_dtds, cta.preparsed_total_dtds);
3029 }
3030 if (native_dtds > cta.preparsed_total_dtds)
3031 native_dtds = cta.preparsed_total_dtds;
3032 for (unsigned i = 0; i < native_dtds; i++) {
3033 char type[16];
3034
3035 sprintf(type, "DTD %3u", i + 1);
3036 cta.native_timings.push_back(timings_ext(i + 129, type));
3037 cta.has_svrs = true;
3038 }
3039 if (cta.has_hdmi && block_nr != (block_map.saw_block_1 ? 2 : 1))
3040 fail("The HDMI Specification requires that the first Extension Block (that is not a Block Map) is an CTA-861 Extension Block.\n");
3041 }
3042 }
3043
3044 if (offset < 4) {
3045 // Offset 0 means that there are no data blocks or DTDs,
3046 // so the remainder must be padding.
3047 if (!memchk(x + 4, 127 - 4)) {
3048 data_block = "Padding";
3049 fail("Contains non-zero bytes.\n");
3050 }
3051 break;
3052 }
3053
3054 if (offset > 127) {
3055 fail("Offset %u is larger than EDID block size-1 (%d).\n", offset, 127);
3056 break;
3057 }
3058 if (version >= 3) {
3059 unsigned i;
3060
3061 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
3062 cta_block(x + i, cta.found_tags);
3063 }
3064
3065 data_block.clear();
3066 if (i != offset)
3067 fail("Offset is %u, but should be %u.\n", offset, i);
3068 }
3069
3070 data_block = "Detailed Timing Descriptors";
3071 base.seen_non_detailed_descriptor = false;
3072 bool first = true;
3073 for (detailed = x + offset; detailed + 17 < x + 127; detailed += 18) {
3074 if (memchk(detailed, 18))
3075 break;
3076 if (first) {
3077 first = false;
3078 printf(" %s:\n", data_block.c_str());
3079 }
3080 detailed_block(detailed);
3081 }
3082 unused_bytes = x + 127 - detailed;
3083 if (!memchk(detailed, unused_bytes)) {
3084 data_block = "Padding";
3085 fail("Contains non-zero bytes.\n");
3086 }
3087 } while (0);
3088
3089 data_block.clear();
3090 if (!cta.first_cta)
3091 return;
3092
3093 cta.first_cta = false;
3094 if (base.serial_number && serial_strings.size())
3095 warn("Display Product Serial Number is set, so the Serial Number in the Base EDID should be 0.\n");
3096 if (!cta.has_vic_1 && !base.has_640x480p60_est_timing)
3097 fail("Required 640x480p60 timings are missing in the established timings"
3098 " and the SVD list (VIC 1).\n");
3099 if ((cta.supported_hdmi_vic_vsb_codes & cta.supported_hdmi_vic_codes) !=
3100 cta.supported_hdmi_vic_codes)
3101 fail("HDMI VIC Codes must have their CTA-861 VIC equivalents in the VSB.\n");
3102 if (!cta.has_vcdb)
3103 fail("Missing VCDB, needed for Set Selectable RGB Quantization to avoid interop issues.\n");
3104 if (!base.uses_srgb && !cta.has_cdb)
3105 warn("Add a Colorimetry Data Block with the sRGB colorimetry bit set to avoid interop issues.\n");
3106 }
3107
3108 void edid_state::cta_resolve_svr(timings_ext &t_ext)
3109 {
3110 if (t_ext.svr() == 254) {
3111 t_ext.flags = cta.t8vtdb.flags;
3112 add_str(t_ext.flags, ">=CTA-861-H");
3113 t_ext.t = cta.t8vtdb.t;
3114 } else if (t_ext.svr() <= 144) {
3115 if (t_ext.svr() < 129 || t_ext.svr() - 129 >= cta.vec_dtds.size())
3116 return;
3117 t_ext.flags = cta.vec_dtds[t_ext.svr() - 129].flags;
3118 t_ext.t = cta.vec_dtds[t_ext.svr() - 129].t;
3119 } else if (t_ext.svr() <= 160) {
3120 if (t_ext.svr() - 145 >= cta.vec_vtdbs.size())
3121 return;
3122 t_ext.flags = cta.vec_vtdbs[t_ext.svr() - 145].flags;
3123 add_str(t_ext.flags, ">=CTA-861-H");
3124 t_ext.t = cta.vec_vtdbs[t_ext.svr() - 145].t;
3125 } else if (t_ext.svr() <= 175) {
3126 t_ext.flags.clear();
3127 unsigned char rid = cta.preparsed_first_vfd.rid;
3128 t_ext.t = calc_ovt_mode(rids[rid].hact, rids[rid].vact,
3129 rids[rid].hratio, rids[rid].vratio,
3130 vf_rate_values[t_ext.svr() - 160]);
3131 t_ext.flags = ">=CTA-861.6";
3132 }
3133 }
3134
3135 void edid_state::cta_resolve_svrs()
3136 {
3137 for (vec_timings_ext::iterator iter = cta.preferred_timings_vfpdb.begin();
3138 iter != cta.preferred_timings_vfpdb.end(); ++iter) {
3139 if (iter->has_svr())
3140 cta_resolve_svr(*iter);
3141 }
3142
3143 for (vec_timings_ext::iterator iter = cta.native_timings.begin();
3144 iter != cta.native_timings.end(); ++iter) {
3145 if (iter->has_svr())
3146 cta_resolve_svr(*iter);
3147 }
3148
3149 for (vec_timings_ext::iterator iter = cta.native_timing_nvrdb.begin();
3150 iter != cta.native_timing_nvrdb.end(); ++iter) {
3151 if (iter->has_svr())
3152 cta_resolve_svr(*iter);
3153 }
3154 }
3155
3156 void edid_state::check_cta_blocks()
3157 {
3158 unsigned max_pref_prog_hact = 0;
3159 unsigned max_pref_prog_vact = 0;
3160 unsigned max_pref_ilace_hact = 0;
3161 unsigned max_pref_ilace_vact = 0;
3162
3163 data_block = "CTA-861";
3164
3165 // HDMI 1.4 goes up to 340 MHz. Dubious to have a DTD above that,
3166 // but no VICs. Displays often have a setting to turn off HDMI 2.x
3167 // support, dropping any HDMI 2.x VICs, but they sometimes forget
3168 // to replace the DTD in the base block as well.
3169 if (cta.warn_about_hdmi_2x_dtd)
3170 warn("DTD pixelclock indicates HDMI 2.x support, VICs indicate HDMI 1.x.\n");
3171
3172 if (cta.hdmi_max_rate && max_pixclk_khz > cta.hdmi_max_rate * 1000)
3173 fail("The maximum HDMI TMDS clock is %u kHz, but one or more video timings go up to %u kHz.\n",
3174 cta.hdmi_max_rate * 1000, max_pixclk_khz);
3175
3176 for (vec_timings_ext::iterator iter = cta.preferred_timings.begin();
3177 iter != cta.preferred_timings.end(); ++iter) {
3178 if (iter->t.interlaced &&
3179 (iter->t.vact > max_pref_ilace_vact ||
3180 (iter->t.vact == max_pref_ilace_vact && iter->t.hact >= max_pref_ilace_hact))) {
3181 max_pref_ilace_hact = iter->t.hact;
3182 max_pref_ilace_vact = iter->t.vact;
3183 }
3184 if (!iter->t.interlaced &&
3185 (iter->t.vact > max_pref_prog_vact ||
3186 (iter->t.vact == max_pref_prog_vact && iter->t.hact >= max_pref_prog_hact))) {
3187 max_pref_prog_hact = iter->t.hact;
3188 max_pref_prog_vact = iter->t.vact;
3189 }
3190 }
3191 for (vec_timings_ext::iterator iter = cta.preferred_timings_vfpdb.begin();
3192 iter != cta.preferred_timings_vfpdb.end(); ++iter) {
3193 if (iter->t.interlaced &&
3194 (iter->t.vact > max_pref_ilace_vact ||
3195 (iter->t.vact == max_pref_ilace_vact && iter->t.hact >= max_pref_ilace_hact))) {
3196 max_pref_ilace_hact = iter->t.hact;
3197 max_pref_ilace_vact = iter->t.vact;
3198 }
3199 if (!iter->t.interlaced &&
3200 (iter->t.vact > max_pref_prog_vact ||
3201 (iter->t.vact == max_pref_prog_vact && iter->t.hact >= max_pref_prog_hact))) {
3202 max_pref_prog_hact = iter->t.hact;
3203 max_pref_prog_vact = iter->t.vact;
3204 }
3205 }
3206
3207 unsigned native_prog = 0;
3208 unsigned native_prog_hact = 0;
3209 unsigned native_prog_vact = 0;
3210 bool native_prog_mixed_resolutions = false;
3211 unsigned native_ilace = 0;
3212 unsigned native_ilace_hact = 0;
3213 unsigned native_ilace_vact = 0;
3214 bool native_ilace_mixed_resolutions = false;
3215 unsigned native_nvrdb_hact = 0;
3216 unsigned native_nvrdb_vact = 0;
3217
3218 for (vec_timings_ext::iterator iter = cta.native_timings.begin();
3219 iter != cta.native_timings.end(); ++iter) {
3220 if (iter->t.interlaced) {
3221 native_ilace++;
3222 if (!native_ilace_hact) {
3223 native_ilace_hact = iter->t.hact;
3224 native_ilace_vact = iter->t.vact;
3225 } else if (native_ilace_hact != iter->t.hact ||
3226 native_ilace_vact != iter->t.vact) {
3227 native_ilace_mixed_resolutions = true;
3228 }
3229 } else {
3230 native_prog++;
3231 if (!native_prog_hact) {
3232 native_prog_hact = iter->t.hact;
3233 native_prog_vact = iter->t.vact;
3234 } else if (native_prog_hact != iter->t.hact ||
3235 native_prog_vact != iter->t.vact) {
3236 native_prog_mixed_resolutions = true;
3237 }
3238 }
3239 }
3240
3241 for (vec_timings_ext::iterator iter = cta.native_timing_nvrdb.begin();
3242 iter != cta.native_timing_nvrdb.end(); ++iter) {
3243 native_nvrdb_hact = iter->t.hact;
3244 native_nvrdb_vact = iter->t.vact;
3245 }
3246
3247 if (native_prog_mixed_resolutions)
3248 fail("Native progressive timings are a mix of several resolutions.\n");
3249 if (native_ilace_mixed_resolutions)
3250 fail("Native interlaced timings are a mix of several resolutions.\n");
3251 if (native_ilace && !native_prog)
3252 fail("A native interlaced timing is present, but not a native progressive timing.\n");
3253 if (!native_prog_mixed_resolutions && native_prog > 1)
3254 warn("Multiple native progressive timings are defined.\n");
3255 if (!native_ilace_mixed_resolutions && native_ilace > 1)
3256 warn("Multiple native interlaced timings are defined.\n");
3257
3258 if (native_nvrdb_vact &&
3259 (max_pref_prog_vact > native_nvrdb_vact ||
3260 (max_pref_prog_vact == native_nvrdb_vact && max_pref_prog_hact > native_nvrdb_hact)))
3261 warn("Native video resolution of %ux%u is smaller than the max preferred progressive resolution %ux%u.\n",
3262 native_nvrdb_hact, native_nvrdb_vact,
3263 max_pref_prog_hact, max_pref_prog_vact);
3264 else if (!native_nvrdb_vact && !native_prog_mixed_resolutions && native_prog_vact &&
3265 (max_pref_prog_vact > native_prog_vact ||
3266 (max_pref_prog_vact == native_prog_vact && max_pref_prog_hact > native_prog_hact)))
3267 warn("Native progressive resolution of %ux%u is smaller than the max preferred progressive resolution %ux%u.\n",
3268 native_prog_hact, native_prog_vact,
3269 max_pref_prog_hact, max_pref_prog_vact);
3270 if (!native_ilace_mixed_resolutions && native_ilace_vact &&
3271 (max_pref_ilace_vact > native_ilace_vact ||
3272 (max_pref_ilace_vact == native_ilace_vact && max_pref_ilace_hact > native_ilace_hact)))
3273 warn("Native interlaced resolution of %ux%u is smaller than the max preferred interlaced resolution %ux%u.\n",
3274 native_ilace_hact, native_ilace_vact,
3275 max_pref_ilace_hact, max_pref_ilace_vact);
3276
3277 if (dispid.native_width && native_prog_hact &&
3278 !native_prog_mixed_resolutions) {
3279 if (dispid.native_width != native_prog_hact ||
3280 dispid.native_height != native_prog_vact)
3281 fail("Mismatch between CTA-861 and DisplayID native progressive resolution.\n");
3282 }
3283 }