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