Skip to contentSkip to conversation

edid-decode: bug fixes, additions, changes

PATCH In review joevt 2 participants 31 messages Sep 26, 2021 – Sep 27, 2021 Media (V4L/DVB)

lore
Share & tools
lore

joevt

author
#0 lore raw

v2 cover edid-decode: bug fixes, additions, changes

Corrections from previous attempt:
- patches are rebased from current edid-decode git repo master branch.
- using smtpBatchSize 20 so hopefully the mails will be sent this time.

Notes:
- Patch 02/28 replaces my previous patch 05/11.
It adds a new warning message.

- The problem with my previous patch 07/11 is addressed in patch 01/28 and 04/28 (and maybe elsewhere).

- Patches 06/28 to 26/28 replace my previous patch 11/11 (broken down into smaller steps this time). They contain some corrections.

- Includes some other changes.

joevt (29):
edid-decode: remove unnecessary length check
edid-decode: fix standard timing vertical pixels
edid-decode: exclude oui from _block functions
edid-decode: check cta_hdr10plus length
edid-decode: Capitalize fail sentence
edid-decode: Replace return with break in switch
edid-decode: extended tag length check
edid-decode: Output block type before fail
edid-decode: update Microsoft expected length
edid-decode: Capitalize fail sentence
edid-decode: make all OUI handlers the same
edid-decode: move OUI parsing to separate function
edid-decode: move unknown block warning
edid-decode: remove cta_ext_block
edid-decode: change unknown CTA block names
edid-decode: move audio fail/warn messages
edid-decode: replace first_block with block_number
edid-decode: move parse_displayid_block inner loop
edid-decode: remove offset from displayid_block
edid-decode: displayid_block len fixes
edid-decode: ignore DisplayID version for OUI check.
edid-decode: DisplayID non-0 filler fixes
edid-decode: DisplayID length checks
edid-decode: make OUI enum
edid-decode: more OUI changes
edid-decode: remove extra vendor field
edid-decode: re-add one EDID
edid-decode: add interesting EDID
edid-decode: fix indents

 data/apple-imac-retina-4k-21.5-inch-late-2015 | Bin 0 -> 256 bytes
 data/vizio-m60c3-hdmi-onkyo-txnr555           | Bin 0 -> 256 bytes
 edid-decode.cpp                               | 106 +++-
 edid-decode.h                                 |  32 +-
 oui.h                                         |  20 +
 parse-base-block.cpp                          |   5 +-
 parse-cta-block.cpp                           | 482 +++++++----------
 parse-displayid-block.cpp                     | 502 +++++++++---------
 8 files changed, 555 insertions(+), 592 deletions(-)
 create mode 100644 data/apple-imac-retina-4k-21.5-inch-late-2015
 create mode 100644 oui.h
Signature · 1 line
2.24.3 (Apple Git-128)
author
#1 lore raw

PATCH v2 1/29 edid-decode: remove unnecessary length check

The for loop also checks the length. Nothing will happen if length is zero as expected.

---
 edid-decode.cpp | 3 ---
 1 file changed, 3 deletions(-)
edid-decode.cpp +0 -3
index d5062dd..d77646d 100644
@@ -700,9 +700,6 @@ void hex_block(const char *prefix, const unsigned char *x,
 {
 	unsigned i, j;
 
-	if (!length)
-		return;
-
 	for (i = 0; i < length; i += step) {
 		unsigned len = min(step, length - i);
 
Signature · 1 line
2.24.3 (Apple Git-128)
author
#2 lore raw

PATCH v2 2/29 edid-decode: fix standard timing vertical pixels

In reply to joevt

Don't do ceiling to nearest 8 pixels for active vertical lines. See examples elo-4600l-hdmi and kogan-kaled24144f-hdmi.

Section 3.9 and 3.10.3.6 of EDID 1.4 does not say vertical lines must be a multiple of 8. This line of code appears to have been added to satisfy the 3rd example in VTB-EXT spec but that example has an incorrect HAP indicator decimal value so it cannot be trusted. Also, all 3 examples have an incorrect vertical refresh value as noted in parse-vtb-ext-block.cpp. The VESA DMT spec has the following examples that are not a multiple of 8 lines which support this change:
1400x1050 4:3
1440x900 16:10
1600x900 16:9
1680x1050 16:10

Finally, Ref. D-8 of EDID 1.4 says about Section 3.9 that "The Standard Timings Identification code may not be used to identify timings which do not match one of these standard aspect ratios."

If vertical lines is odd then a warning is output. That way an attempt to use ST to describe 1360x768 (a common resolution) will result in a warning (since the nearest result that can be described by an ST is 1360x765).

---
 parse-base-block.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
parse-base-block.cpp +4 -1
index 174af51..dd56eed 100644
@@ -573,7 +573,6 @@ void edid_state::print_standard_timing(const char *prefix, unsigned char b1, uns
 		break;
 	}
 	vact = (double)hact * vratio / hratio;
-	vact = 8 * ((vact + 7) / 8);
 	refresh = (b2 & 0x3f) + 60;
 
 	formula.hact = hact;
@@ -605,6 +604,10 @@ void edid_state::print_standard_timing(const char *prefix, unsigned char b1, uns
 		min_vert_freq_hz = min(min_vert_freq_hz, refresh);
 		max_vert_freq_hz = max(max_vert_freq_hz, refresh);
 	}
+
+	// See Ref. D-8 in the EDID-1.4 spec
+	if (vact & 1)
+		warn("Standard Timing %ux%u has a dubious odd vertical resolution.\n", hact, vact);
 }
 
 void edid_state::detailed_display_range_limits(const unsigned char *x)
Signature · 1 line
2.24.3 (Apple Git-128)
author
#3 lore raw

PATCH v2 3/29 edid-decode: exclude oui from _block functions

In reply to joevt

cta_hdmi_block is the only function that has oui included. Make it like all the other functions by increasing x by 3 (the size of the oui) and decreasing length by the same amount.

---
 parse-cta-block.cpp | 48 ++++++++++++++++++++++-----------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
parse-cta-block.cpp +24 -24
index ee0b01d..f018df5 100644
@@ -652,57 +652,57 @@ void edid_state::cta_hdmi_block(const unsigned char *x, unsigned length)
 {
 	unsigned len_vic, len_3d;
 
-	if (length < 4) {
+	if (length < 1) {
 		fail("Empty Data Block with length %u.\n", length);
 		return;
 	}
-	printf("    Source physical address: %x.%x.%x.%x\n", x[3] >> 4, x[3] & 0x0f,
-	       x[4] >> 4, x[4] & 0x0f);
+	printf("    Source physical address: %x.%x.%x.%x\n", x[0] >> 4, x[0] & 0x0f,
+	       x[1] >> 4, x[1] & 0x0f);
 
-	if (length < 6)
+	if (length < 3)
 		return;
 
-	if (x[5] & 0x80)
+	if (x[2] & 0x80)
 		printf("    Supports_AI\n");
-	if (x[5] & 0x40)
+	if (x[2] & 0x40)
 		printf("    DC_48bit\n");
-	if (x[5] & 0x20)
+	if (x[2] & 0x20)
 		printf("    DC_36bit\n");
-	if (x[5] & 0x10)
+	if (x[2] & 0x10)
 		printf("    DC_30bit\n");
-	if (x[5] & 0x08)
+	if (x[2] & 0x08)
 		printf("    DC_Y444\n");
 	/* two reserved bits */
-	if (x[5] & 0x01)
+	if (x[2] & 0x01)
 		printf("    DVI_Dual\n");
 
-	if (length < 7)
+	if (length < 4)
 		return;
 
-	printf("    Maximum TMDS clock: %u MHz\n", x[6] * 5);
-	if (x[6] * 5 > 340)
+	printf("    Maximum TMDS clock: %u MHz\n", x[3] * 5);
+	if (x[3] * 5 > 340)
 		fail("HDMI VSDB Max TMDS rate is > 340.\n");
 
-	if (length < 8)
+	if (length < 5)
 		return;
 
-	if (x[7] & 0x0f) {
+	if (x[4] & 0x0f) {
 		printf("    Supported Content Types:\n");
-		if (x[7] & 0x01)
+		if (x[4] & 0x01)
 			printf("      Graphics\n");
-		if (x[7] & 0x02)
+		if (x[4] & 0x02)
 			printf("      Photo\n");
-		if (x[7] & 0x04)
+		if (x[4] & 0x04)
 			printf("      Cinema\n");
-		if (x[7] & 0x08)
+		if (x[4] & 0x08)
 			printf("      Game\n");
 	}
 
-	unsigned b = 8;
-	if (x[7] & 0x80) {
+	unsigned b = 5;
+	if (x[4] & 0x80) {
 		hdmi_latency(x[b], x[b + 1], false);
 
-		if (x[7] & 0x40) {
+		if (x[4] & 0x40) {
 			if (x[b] == x[b + 2] &&
 			    x[b + 1] == x[b + 3])
 				warn("Progressive and Interlaced latency values are identical, no need for both.\n");
@@ -712,7 +712,7 @@ void edid_state::cta_hdmi_block(const unsigned char *x, unsigned length)
 		b += 2;
 	}
 
-	if (!(x[7] & 0x20))
+	if (!(x[4] & 0x20))
 		return;
 
 	bool mask = false;
@@ -2248,7 +2248,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 			fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
 		printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
 		if (oui == 0x000c03) {
-			cta_hdmi_block(x + 1, length);
+			cta_hdmi_block(x + 4, length - 3);
 			cta.last_block_was_hdmi_vsdb = 1;
 			cta.first_block = 0;
 			// The HDMI OUI is present, so this EDID represents an HDMI
Signature · 1 line
2.24.3 (Apple Git-128)
author
#4 lore raw

PATCH v2 4/29 edid-decode: check cta_hdr10plus length

In reply to joevt

- if the length is 0 then it cannot get Application Version. Output a fail message.
- cta_hdr10plus may output hex after "Application Version: %u". If the hex is longer than 16 characters, then more lines of hex will be output and they won't align with the first line. Instead, always start the hex on a new line.

---
 parse-cta-block.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
parse-cta-block.cpp +6 -5
index f018df5..6607426 100644
@@ -1133,11 +1133,12 @@ static void cta_microsoft(const unsigned char *x, unsigned length)
 
 static void cta_hdr10plus(const unsigned char *x, unsigned length)
 {
-	printf("    Application Version: %u", x[0]);
-	if (length > 1)
-		hex_block("  ", x + 1, length - 1);
-	else
-		printf("\n");
+	if (length == 0) {
+		fail("Empty Data Block with length %u.\n", length);
+		return;
+	}
+	printf("    Application Version: %u\n", x[0]);
+	hex_block("    ", x + 1, length - 1);
 }
 
 // Convert a PQ value (0-1) to cd/m^2 aka nits (0-10000)
Signature · 1 line
2.24.3 (Apple Git-128)
author
#5 lore raw

PATCH v2 5/29 edid-decode: Capitalize fail sentence

In reply to joevt

- Most fail messages are a sentence that starts with a capital letter and ends with a period.
- Remove unnessary break from last switch case.
- Remove extra line.

---
 parse-cta-block.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
parse-cta-block.cpp +1 -3
index 6607426..042b933 100644
@@ -2091,13 +2091,11 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 	case 0x79:
 		if (duplicate)
 			fail("Only one instance of this Data Block is allowed.\n");
-		break;
 	}
 
-
 	// See Table 52 of CTA-861-G for a description of Byte 3
 	if (audio_block && !(cta.byte3 & 0x40))
-		fail("audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
+		fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
 
 	if (data_block.length())
 		printf("  %s:\n", data_block.c_str());
Signature · 1 line
2.24.3 (Apple Git-128)
#6 lore raw

Re: [PATCH v2 05/29] edid-decode: Capitalize fail sentence

Quoted 2 lines · joevt

- Most fail messages are a sentence that starts with a capital letter and ends with a period.
- Remove unnessary break from last switch case.

I dropped this change. It is good coding practice to always include a break for the last switch case. If someone adds a new case later, then this avoids an accidental fall-through scenario.

No need to repost, I'll take care of this.

Regards,

Hans

Quoted 27 lines

- Remove extra line.

---
 parse-cta-block.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
parse-cta-block.cpp +1 -3
index 6607426..042b933 100644
@@ -2091,13 +2091,11 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 	case 0x79:
 		if (duplicate)
 			fail("Only one instance of this Data Block is allowed.\n");
-		break;
 	}
 
-
 	// See Table 52 of CTA-861-G for a description of Byte 3
 	if (audio_block && !(cta.byte3 & 0x40))
-		fail("audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
+		fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
 
 	if (data_block.length())
 		printf("  %s:\n", data_block.c_str());
author
#7 lore raw

PATCH v2 6/29 edid-decode: Replace return with break in switch

In reply to joevt

Use break to leave a switch instead of return.
Move code that was after switch to default statement in switch. This way, we can move switch or have other code after switch.

---
 parse-cta-block.cpp | 51 +++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 25 deletions(-)
parse-cta-block.cpp +26 -25
index 042b933..bba3af2 100644
@@ -2101,12 +2101,12 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 		printf("  %s:\n", data_block.c_str());
 
 	switch (x[0]) {
-	case 0x00: cta_vcdb(x + 1, length); return;
+	case 0x00: cta_vcdb(x + 1, length); break;
 	case 0x01:
 		if (length < 3) {
 			data_block = std::string("Vendor-Specific Video Data Block");
 			fail("Invalid length %u < 3.\n", length);
-			return;
+			break;
 		}
 		oui = (x[3] << 16) + (x[2] << 8) + x[1];
 		name = oui_name(oui);
@@ -2122,7 +2122,7 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 			data_block.clear();
 			warn("Unknown Extended Vendor-Specific Video Data Block, OUI %s.\n",
 			     ouitohex(oui).c_str());
-			return;
+			break;
 		}
 		data_block = std::string("Vendor-Specific Video Data Block (") + name + ")";
 		if (reverse)
@@ -2134,19 +2134,19 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 			cta_dolby_video(x + 4, length - 3);
 		else
 			hex_block("    ", x + 4, length - 3);
-		return;
-	case 0x02: cta_vesa_vdddb(x + 1, length); return;
-	case 0x05: cta_colorimetry_block(x + 1, length); return;
-	case 0x06: cta_hdr_static_metadata_block(x + 1, length); return;
-	case 0x07: cta_hdr_dyn_metadata_block(x + 1, length); return;
-	case 0x0d: cta_vfpdb(x + 1, length); return;
-	case 0x0e: cta_svd(x + 1, length, true); return;
-	case 0x0f: cta_y420cmdb(x + 1, length); return;
+		break;
+	case 0x02: cta_vesa_vdddb(x + 1, length); break;
+	case 0x05: cta_colorimetry_block(x + 1, length); break;
+	case 0x06: cta_hdr_static_metadata_block(x + 1, length); break;
+	case 0x07: cta_hdr_dyn_metadata_block(x + 1, length); break;
+	case 0x0d: cta_vfpdb(x + 1, length); break;
+	case 0x0e: cta_svd(x + 1, length, true); break;
+	case 0x0f: cta_y420cmdb(x + 1, length); break;
 	case 0x11:
 		if (length < 3) {
 			data_block = std::string("Vendor-Specific Audio Data Block");
 			fail("Invalid length %u < 3.\n", length);
-			return;
+			break;
 		}
 		oui = (x[3] << 16) + (x[2] << 8) + x[1];
 		name = oui_name(oui);
@@ -2162,7 +2162,7 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 			data_block.clear();
 			warn("Unknown Extended Vendor-Specific Audio Data Block, OUI %s.\n",
 			     ouitohex(oui).c_str());
-			return;
+			break;
 		}
 		data_block = std::string("Vendor-Specific Audio Data Block (") + name + ")";
 		if (reverse)
@@ -2172,20 +2172,20 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 			cta_dolby_audio(x + 4, length - 3);
 		else
 			hex_block("    ", x + 4, length - 3);
-		return;
-	case 0x12: cta_hdmi_audio_block(x + 1, length); return;
-	case 0x13: cta_rcdb(x + 1, length); return;
-	case 0x14: cta_sldb(x + 1, length); return;
-	case 0x20: cta_ifdb(x + 1, length); return;
-	case 0x34: cta_displayid_type_7(x + 1, length); return;
-	case 0x35: cta_displayid_type_8(x + 1, length); return;
-	case 0x42: cta_displayid_type_10(x + 1, length); return;
+		break;
+	case 0x12: cta_hdmi_audio_block(x + 1, length); break;
+	case 0x13: cta_rcdb(x + 1, length); break;
+	case 0x14: cta_sldb(x + 1, length); break;
+	case 0x20: cta_ifdb(x + 1, length); break;
+	case 0x34: cta_displayid_type_7(x + 1, length); break;
+	case 0x35: cta_displayid_type_8(x + 1, length); break;
+	case 0x42: cta_displayid_type_10(x + 1, length); break;
 	case 0x78:
 		cta_hf_eeodb(x + 1, length);
 		// This must be the first CTA-861 block
 		if (!cta.first_block)
 			fail("Block starts at a wrong offset.\n");
-		return;
+		break;
 	case 0x79:
 		if (!cta.last_block_was_hdmi_vsdb)
 			fail("HDMI Forum SCDB did not immediately follow the HDMI VSDB.\n");
@@ -2194,16 +2194,17 @@ void edid_state::cta_ext_block(const unsigned char *x, unsigned length,
 		if (length < 2) {
 			data_block = std::string("HDMI Forum SCDB");
 			fail("Invalid length %u < 2.\n", length);
-			return;
+			break;
 		}
 		if (x[1] || x[2])
 			printf("  Non-zero SCDB reserved fields!\n");
 		cta_hf_scdb(x + 3, length - 2);
 		cta.have_hf_scdb = 1;
-		return;
+		break;
+	default:
+		hex_block("    ", x + 1, length);
 	}
 
-	hex_block("    ", x + 1, length);
 }
 
 void edid_state::cta_block(const unsigned char *x, bool duplicate)
Signature · 1 line
2.24.3 (Apple Git-128)
author
#8 lore raw

PATCH v2 7/29 edid-decode: extended tag length check

In reply to joevt

Change:
- Don't read extended tag if length of extended block is zero. Report a fail in that case.

Modifications that don't change behavior but help with the above change or with changes in later commits:
- Differentiate extended tags from normal tags by adding 0x700 to the extended tag byte.
- Increase x after parsing each byte (the tag/length byte and the extended tag byte). Decrease length if there's an extended byte.
- Change cta_ext_block so that x parameter points to byte after the extended tag. Since x points to after extended tag, pass the extended tag as a parameter.
- After reading an OUI, increase x by 3 and decrease length by 3.

---
 edid-decode.h       |   2 +-
 parse-cta-block.cpp | 208 ++++++++++++++++++++++++--------------------
 2 files changed, 113 insertions(+), 97 deletions(-)
edid-decode.h +1 -1
index aef2bab..57cb6e6 100644
@@ -344,7 +344,7 @@ struct edid_state {
 	void cta_displayid_type_7(const unsigned char *x, unsigned length);
 	void cta_displayid_type_8(const unsigned char *x, unsigned length);
 	void cta_displayid_type_10(const unsigned char *x, unsigned length);
-	void cta_ext_block(const unsigned char *x, unsigned length, bool duplicate);
+	void cta_ext_block(unsigned tag, const unsigned char *x, unsigned length, bool duplicate);
 	void cta_block(const unsigned char *x, bool duplicate);
 	void preparse_cta_block(const unsigned char *x);
 	void parse_cta_block(const unsigned char *x);
parse-cta-block.cpp +112 -96

353 lines not on this page · raw message

Signature · 1 line
2.24.3 (Apple Git-128)
author
#9 lore raw

PATCH v2 8/29 edid-decode: Output block type before fail

In reply to joevt

For extended tags, block type should be output before fail messages (duplicate failure, or missing audio failure).
For normal tags 0x04 and 0x05, fail message should appear after block type instead of block data to be consistent (and also to indicate that the failure is because of the block type and not the contents of the block).

---
 parse-cta-block.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
parse-cta-block.cpp +6 -6
index f1ad041..fb2e9ea 100644
@@ -2078,6 +2078,9 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 		return;
 	}
 
+	if (data_block.length())
+		printf("  %s:\n", data_block.c_str());
+
 	switch (tag) {
 	case 0x700:
 	case 0x702:
@@ -2097,9 +2100,6 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 	if (audio_block && !(cta.byte3 & 0x40))
 		fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
 
-	if (data_block.length())
-		printf("  %s:\n", data_block.c_str());
-
 	switch (tag) {
 	case 0x700: cta_vcdb(x, length); break;
 	case 0x701:
@@ -2294,17 +2294,17 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x04:
 		data_block = "Speaker Allocation Data Block";
 		printf("  %s:\n", data_block.c_str());
-		cta_sadb(x, length);
-		audio_block = true;
 		if (duplicate)
 			fail("Only one instance of this Data Block is allowed.\n");
+		cta_sadb(x, length);
+		audio_block = true;
 		break;
 	case 0x05:
 		data_block = "VESA Display Transfer Characteristics Data Block";
 		printf("  %s:\n", data_block.c_str());
-		cta_vesa_dtcdb(x, length);
 		if (duplicate)
 			fail("Only one instance of this Data Block is allowed.\n");
+		cta_vesa_dtcdb(x, length);
 		break;
 	case 0x07:
 		data_block = "Unknown CTA-861 Data Block (extended tag truncated)";
Signature · 1 line
2.24.3 (Apple Git-128)
author
#10 lore raw

PATCH v2 9/29 edid-decode: update Microsoft expected length

In reply to joevt

Since we excluded the size of the OUI from the length in a previous commit, we need to decrease the expected length accordingly. See example DELA07B/5F1B08ADB0A0, LENB800/61B4B713B745

Really, length checks should probably be done in the parse function. If length is greater than expected then parse up to the expected length and output the rest as hex with a warning. If length is less than expected then parse up to the length and warn that some expected bytes are missing.

---
 parse-cta-block.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
parse-cta-block.cpp +1 -1
index fb2e9ea..3b6126a 100644
@@ -2285,7 +2285,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 			cta_amd(x, length);
 			break;
 		}
-		if (oui == 0xca125c && length == 0x15) {
+		if (oui == 0xca125c && length == 0x12) {
 			cta_microsoft(x, length);
 			break;
 		}
Signature · 1 line
2.24.3 (Apple Git-128)
author
#11 lore raw

PATCH v2 10/29 edid-decode: Capitalize fail sentence

In reply to joevt

Most fail messages are a sentence that starts with a capital letter and ends with a period.

---
 parse-cta-block.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
parse-cta-block.cpp +1 -1
index 3b6126a..7568780 100644
@@ -2326,7 +2326,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 
 	// See Table 52 of CTA-861-G for a description of Byte 3
 	if (audio_block && !(cta.byte3 & 0x40))
-		fail("audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
+		fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
 	cta.first_block = 0;
 	cta.last_block_was_hdmi_vsdb = 0;
 }
Signature · 1 line
2.24.3 (Apple Git-128)
author
#12 lore raw

PATCH v2 11/29 edid-decode: make all OUI handlers the same

In reply to joevt

Because they are the same but with different block names.

For Vendor-Specific Data Block there are a couple fixes:
1) If the length is not enough to contain an OUI, then a fail is output. I have a corrupted EDID that would cause 20000+ lines of hex to be output without this check.
2) The return statement for VSDB with unknown OUI is changed to a break statement. The code after the switch statement will be executed which causes the block to be considered as a first block or as not a hdmi vsdb.

---
 parse-cta-block.cpp | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
parse-cta-block.cpp +22 -17
index 7568780..b4645b4 100644
@@ -2030,6 +2030,7 @@ static void cta_hdmi_audio_block(const unsigned char *x, unsigned length)
 void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned length,
 			       bool duplicate)
 {
+	const char *block_name;
 	const char *name;
 	unsigned oui;
 	bool reverse = false;
@@ -2103,8 +2104,9 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 	switch (tag) {
 	case 0x700: cta_vcdb(x, length); break;
 	case 0x701:
+		block_name = "Vendor-Specific Video Data Block";
 		if (length < 3) {
-			data_block = std::string("Vendor-Specific Video Data Block");
+			data_block = std::string(block_name);
 			fail("Invalid length %u < 3.\n", length);
 			break;
 		}
@@ -2117,15 +2119,13 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 				reverse = true;
 		}
 		if (!name) {
-			printf("  Vendor-Specific Video Data Block, OUI %s:\n",
-			       ouitohex(oui).c_str());
+			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
 			hex_block("    ", x, length);
 			data_block.clear();
-			warn("Unknown Extended Vendor-Specific Video Data Block, OUI %s.\n",
-			     ouitohex(oui).c_str());
+			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
 			break;
 		}
-		data_block = std::string("Vendor-Specific Video Data Block (") + name + ")";
+		data_block = std::string(block_name) + " (" + name + ")";
 		if (reverse)
 			fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
 		printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
@@ -2144,8 +2144,9 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 	case 0x70e: cta_svd(x, length, true); break;
 	case 0x70f: cta_y420cmdb(x, length); break;
 	case 0x711:
+		block_name = "Vendor-Specific Audio Data Block";
 		if (length < 3) {
-			data_block = std::string("Vendor-Specific Audio Data Block");
+			data_block = std::string(block_name);
 			fail("Invalid length %u < 3.\n", length);
 			break;
 		}
@@ -2158,15 +2159,13 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 				reverse = true;
 		}
 		if (!name) {
-			printf("  Vendor-Specific Audio Data Block, OUI %s:\n",
-			       ouitohex(oui).c_str());
+			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
 			hex_block("    ", x, length);
 			data_block.clear();
-			warn("Unknown Extended Vendor-Specific Audio Data Block, OUI %s.\n",
-			     ouitohex(oui).c_str());
+			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
 			break;
 		}
-		data_block = std::string("Vendor-Specific Audio Data Block (") + name + ")";
+		data_block = std::string(block_name) + " (" + name + ")";
 		if (reverse)
 			fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
 		printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
@@ -2222,6 +2221,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		x++;
 	}
 
+	const char *block_name;
 	const char *name;
 	unsigned oui;
 	bool reverse = false;
@@ -2240,6 +2240,12 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		cta_svd(x, length, false);
 		break;
 	case 0x03:
+		block_name = "Vendor-Specific Data Block";
+		if (length < 3) {
+			data_block = std::string(block_name);
+			fail("Invalid length %u < 3.\n", length);
+			break;
+		}
 		oui = (x[2] << 16) + (x[1] << 8) + x[0];
 		x += 3; length -=3;
 		name = oui_name(oui);
@@ -2249,14 +2255,13 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 				reverse = true;
 		}
 		if (!name) {
-			printf("  Vendor-Specific Data Block, OUI %s:\n", ouitohex(oui).c_str());
+			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
 			hex_block("    ", x, length);
 			data_block.clear();
-			warn("Unknown Vendor-Specific Data Block, OUI %s.\n",
-			     ouitohex(oui).c_str());
-			return;
+			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
+			break;
 		}
-		data_block = std::string("Vendor-Specific Data Block (") + name + ")";
+		data_block = std::string(block_name) + " (" + name + ")";
 		if (reverse)
 			fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
 		printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
Signature · 1 line
2.24.3 (Apple Git-128)
author
#13 lore raw

PATCH v2 12/29 edid-decode: move OUI parsing to separate function

In reply to joevt

Since all three occurrences of OUI parsing are the same in parse-cta-block.cpp, we can move them to a separate function in edid-decode.cpp (because we may want to use the function for non-CTA parsing as well).

data_block_oui contains identical code except for the following:
1) The warning for unknown OUI name is output after the block name instead of after the block contents.

Other changes that don't affect output:
- oui is set to 0 if the OUI is unknown so that it can't lead to executing any known OUI code by the caller.
- A macro is used to call data_block_oui. It updates x and length appropriately for the caller.

---
 edid-decode.cpp     | 34 +++++++++++++++++
 edid-decode.h       |  2 +
 parse-cta-block.cpp | 91 +++++----------------------------------------
 3 files changed, 46 insertions(+), 81 deletions(-)
edid-decode.cpp +34 -0
index d77646d..ec903f9 100644
@@ -679,6 +679,40 @@ const char *oui_name(unsigned oui, bool reverse)
 	}
 }
 
+void edid_state::data_block_oui(const char *block_name, const unsigned char *x, unsigned length, unsigned *ouinum)
+{
+	const char *name;
+	unsigned oui = 0;
+	bool reverse = false;
+
+	if (length < 3) {
+		data_block = std::string(block_name);
+		fail("Invalid length %u < 3.\n", length);
+	}
+	else {
+		oui = (x[2] << 16) + (x[1] << 8) + x[0];
+		x += 3; length -=3;
+		name = oui_name(oui);
+		if (!name) {
+			name = oui_name(oui, true);
+			if (name)
+				reverse = true;
+		}
+		if (!name) {
+			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
+			data_block.clear();
+			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
+		}
+		else {
+			data_block = std::string(block_name) + " (" + name + ")";
+			if (reverse)
+				fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
+			printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
+		}
+	}
+	if (ouinum) *ouinum = oui;
+}
+
 std::string ouitohex(unsigned oui)
 {
 	char buf[32];
edid-decode.h +2 -0
index 57cb6e6..2409718 100644
@@ -331,6 +331,8 @@ struct edid_state {
 	void list_dmts();
 	void list_established_timings();
 
+	void data_block_oui(const char *block_name, const unsigned char *x, unsigned length, unsigned *ouinum);
+
 	void print_vic_index(const char *prefix, unsigned idx, const char *suffix, bool ycbcr420 = false);
 	void hdmi_latency(unsigned char vid_lat, unsigned char aud_lat, bool is_ilaced);
 	void cta_vcdb(const unsigned char *x, unsigned length);
parse-cta-block.cpp +10 -81

126 lines not on this page · raw message

Signature · 1 line
2.24.3 (Apple Git-128)
author
#14 lore raw

PATCH v2 13/29 edid-decode: move unknown block warning

In reply to joevt

Also, make cta_block like cta_ext_block

First, fix the first switch statement in cta_ext_block. The first switch statement sets or clears data_block (the name of the block which is used in the Warnings and Failures section of the output). Remove hex_block because it will be done by the third switch statement that handles outputting the contents of each block.
The "Unknown Extended CTA-861 Data Block 0x%02x.\n" warning now appears after the block name instead of after the block contents (because it's not the contents that caused the error).

Then, in cta_block:
1) Create a first switch statement like that of cta_ext_block (described above).
The "Unknown CTA-861 Data Block %u.\n" warning now appears after the block name instead of after the block contents (because it's not the contents that caused the error).
2) Create a second switch statement like that of cta_ext_block. It handles checking for duplicate blocks.
3) After checking for duplicates, check cta_byte3 / audio_block discrepancy, exactly like cta_ext_block does. These lines come from after the original switch statement of cta_block.
4) The original switch statement of cta_block has lines that are moved to the new first and second switch statements.

---
 parse-cta-block.cpp | 82 +++++++++++++++++++++------------------------
 1 file changed, 38 insertions(+), 44 deletions(-)
parse-cta-block.cpp +38 -44
index 0000249..3503cd1 100644
@@ -2068,6 +2068,7 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 	case 0x778: data_block = "HDMI Forum EDID Extension Override Data Block"; break;
 	case 0x779: data_block = "HDMI Forum Sink Capability Data Block"; break;
 	default:
+		data_block.clear();
 		if (tag < 0x70d)
 			printf("  Unknown CTA-861 Video-Related");
 		else if (tag < 0x720)
@@ -2077,10 +2078,7 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 		else
 			printf("  Unknown CTA-861");
 		printf(" Data Block (extended tag 0x%02x)\n", tag & 0xff);
-		hex_block("    ", x, length);
-		data_block.clear();
 		warn("Unknown Extended CTA-861 Data Block 0x%02x.\n", tag & 0xff);
-		return;
 	}
 
 	if (data_block.length())
@@ -2161,7 +2159,6 @@ void edid_state::cta_ext_block(unsigned tag, const unsigned char *x, unsigned le
 	default:
 		hex_block("    ", x, length);
 	}
-
 }
 
 void edid_state::cta_block(const unsigned char *x, bool duplicate)
@@ -2181,17 +2178,37 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	bool audio_block = false;
 
 	switch (tag) {
-	case 0x01:
-		data_block = "Audio Data Block";
-		printf("  %s:\n", data_block.c_str());
-		cta_audio_block(x, length);
-		audio_block = true;
-		break;
-	case 0x02:
-		data_block = "Video Data Block";
+	case 0x01: data_block = "Audio Data Block"; audio_block = true; break;
+	case 0x02: data_block = "Video Data Block"; break;
+	case 0x03: data_block.clear(); break;
+	case 0x04: data_block = "Speaker Allocation Data Block"; audio_block = true; break;
+	case 0x05: data_block = "VESA Display Transfer Characteristics Data Block"; break;
+
+	case 0x07: data_block.clear(); break;
+	default:
+		data_block.clear();
+		if (extended) break;
+		printf("  Unknown CTA-861 tag 0x%02x\n", tag);
+		warn("Unknown CTA-861 Data Block %u.\n", tag);
+	}
+
+	if (data_block.length())
 		printf("  %s:\n", data_block.c_str());
-		cta_svd(x, length, false);
-		break;
+
+	switch (tag) {
+	case 0x04:
+	case 0x05:
+		if (duplicate)
+			fail("Only one instance of this Data Block is allowed.\n");
+	}
+
+	// See Table 52 of CTA-861-G for a description of Byte 3
+	if (audio_block && !(cta.byte3 & 0x40))
+		fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
+
+	switch (tag) {
+	case 0x01: cta_audio_block(x, length); break;
+	case 0x02: cta_svd(x, length, false); break;
 	case 0x03:
 		data_block_o("Vendor-Specific Data Block");
 		if (oui == 0x000c03) {
@@ -2225,42 +2242,19 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		}
 		hex_block("    ", x, length);
 		break;
-	case 0x04:
-		data_block = "Speaker Allocation Data Block";
-		printf("  %s:\n", data_block.c_str());
-		if (duplicate)
-			fail("Only one instance of this Data Block is allowed.\n");
-		cta_sadb(x, length);
-		audio_block = true;
-		break;
-	case 0x05:
-		data_block = "VESA Display Transfer Characteristics Data Block";
-		printf("  %s:\n", data_block.c_str());
-		if (duplicate)
-			fail("Only one instance of this Data Block is allowed.\n");
-		cta_vesa_dtcdb(x, length);
-		break;
+	case 0x04: cta_sadb(x, length); break;
+	case 0x05: cta_vesa_dtcdb(x, length); break;
 	case 0x07:
-		data_block = "Unknown CTA-861 Data Block (extended tag truncated)";
-		printf("  %s:\n", data_block.c_str());
+		printf("  Unknown CTA-861 Data Block (extended tag truncated):\n");
 		fail("Extended tag cannot have zero length.\n");
 		break;
-	default: {
-		if (extended) {
+	default:
+		if (extended)
 			cta_ext_block(tag, x, length, duplicate);
-			break;
-		}
-		printf("  Unknown CTA-861 tag 0x%02x\n", tag);
-		hex_block("    ", x, length);
-		data_block.clear();
-		warn("Unknown CTA-861 Data Block %u.\n", tag);
-		break;
-	}
+		else
+			hex_block("    ", x, length);
 	}
 
-	// See Table 52 of CTA-861-G for a description of Byte 3
-	if (audio_block && !(cta.byte3 & 0x40))
-		fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
 	cta.first_block = 0;
 	cta.last_block_was_hdmi_vsdb = 0;
 }
Signature · 1 line
2.24.3 (Apple Git-128)
author
#15 lore raw

PATCH v2 14/29 edid-decode: remove cta_ext_block

In reply to joevt

Since cta_ext_block is exactly like cta_block now, we can move its code (mostly without modification) to cta_block. This way it's easier to ensure that the blocks are handled consistently (order of statements, including fails, warnings, defaults, etc.)

This change should not affect output.

---
 edid-decode.h       |   1 -
 parse-cta-block.cpp | 187 +++++++++++++++++++-------------------------
 2 files changed, 80 insertions(+), 108 deletions(-)
edid-decode.h +0 -1
index 2409718..ccf8558 100644
@@ -346,7 +346,6 @@ struct edid_state {
 	void cta_displayid_type_7(const unsigned char *x, unsigned length);
 	void cta_displayid_type_8(const unsigned char *x, unsigned length);
 	void cta_displayid_type_10(const unsigned char *x, unsigned length);
-	void cta_ext_block(unsigned tag, const unsigned char *x, unsigned length, bool duplicate);
 	void cta_block(const unsigned char *x, bool duplicate);
 	void preparse_cta_block(const unsigned char *x);
 	void parse_cta_block(const unsigned char *x);
parse-cta-block.cpp +80 -107

224 lines not on this page · raw message

Signature · 1 line
2.24.3 (Apple Git-128)
author
#16 lore raw

PATCH v2 15/29 edid-decode: change unknown CTA block names

In reply to joevt

Make consistent the Unknown CTA-861 Data Block names and warnings.

- Add " Data Block" suffix for normal tags (like unknown extended tags and known normal tags have).
- Put tag in parenthesis (like unknown extended tags).
- Output colon after unknown block name (like known tags).
- Make warning same as block name (so the block mentioned in the warning section can be found more easily in the edid output).

1) Unknown normal tags:
Before:
- name: "Unknown CTA-861 tag 0x$$"
- warning: "Unknown CTA-861 Data Block #."
After:
"Unknown CTA-861 Data Block (tag 0x$$):" (with period instead of colon for warning)

2) Unknown extended tags:
Before:
- name: "Unknown CTA-861 @Data Block (extended tag 0x$$)" (@ = "", "Video-Related ", "Audio-Related ", "HDMI-Related ")
- warning: "Unknown Extended CTA-861 Data Block 0x$$."
After:
- "Unknown CTA-861 @Data Block (extended tag 0x$$):" (with period instead of colon for warning)

We still have the following from a previous commit:
3) Truncated extended tag (when length is not enough to get the extended tag):
Before:
name: "Unknown CTA-861 Data Block (extended tag truncated):"
failure: "Extended tag cannot have zero length."

Since the name is different than the failure message, we should set data_block so both are output to the failure section:
After:
failure: "Unknown CTA-861 Data Block (extended tag truncated): Extended tag cannot have zero length."

---
 parse-cta-block.cpp | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)
parse-cta-block.cpp +12 -21
index 79354c5..16c7bee 100644
@@ -2057,7 +2057,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x04: data_block = "Speaker Allocation Data Block"; audio_block = true; break;
 	case 0x05: data_block = "VESA Display Transfer Characteristics Data Block"; break;
 
-	case 0x07: data_block.clear(); break;
+	case 0x07: data_block = "Unknown CTA-861 Data Block (extended tag truncated)"; break;
 
 	case 0x700: data_block = "Video Capability Data Block"; break;
 	case 0x701: data_block.clear(); break;
@@ -2088,22 +2088,16 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 
 	default:
 		data_block.clear();
-		if (tag < 0x700) {
-			printf("  Unknown CTA-861 tag 0x%02x\n", tag);
-			warn("Unknown CTA-861 Data Block %u.\n", tag);
-		}
-		else {
-			if (tag < 0x70d)
-				printf("  Unknown CTA-861 Video-Related");
-			else if (tag < 0x720)
-				printf("  Unknown CTA-861 Audio-Related");
-			else if (tag >= 0x778 && tag <= 0x77f)
-				printf("  Unknown CTA-861 HDMI-Related");
-			else
-				printf("  Unknown CTA-861");
-			printf(" Data Block (extended tag 0x%02x)\n", tag & 0xff);
-			warn("Unknown Extended CTA-861 Data Block 0x%02x.\n", tag & 0xff);
-		}
+		std::string unknown_name;
+		     if (tag < 0x700) unknown_name = "Unknown CTA-861 Data Block";
+		else if (tag < 0x70d) unknown_name = "Unknown CTA-861 Video-Related Data Block";
+		else if (tag < 0x720) unknown_name = "Unknown CTA-861 Audio-Related Data Block";
+		else if (tag < 0x778) unknown_name = "Unknown CTA-861 Data Block";
+		else if (tag < 0x780) unknown_name = "Unknown CTA-861 HDMI-Related Data Block";
+		else                  unknown_name = "Unknown CTA-861 Data Block";
+		unknown_name += std::string(" (") + (extended ? "extended " : "") + "tag " + utohex(tag & 0xff) + ")";
+		printf("  %s:\n", unknown_name.c_str());
+		warn("%s.\n", unknown_name.c_str());
 	}
 
 	if (data_block.length())
@@ -2168,10 +2162,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		break;
 	case 0x04: cta_sadb(x, length); break;
 	case 0x05: cta_vesa_dtcdb(x, length); break;
-	case 0x07:
-		printf("  Unknown CTA-861 Data Block (extended tag truncated):\n");
-		fail("Extended tag cannot have zero length.\n");
-		break;
+	case 0x07: fail("Extended tag cannot have zero length.\n"); break;
 	case 0x700: cta_vcdb(x, length); break;
 	case 0x701:
 		data_block_o("Vendor-Specific Video Data Block");
Signature · 1 line
2.24.3 (Apple Git-128)
author
#17 lore raw

PATCH v2 16/29 edid-decode: move audio fail/warn messages

In reply to joevt

For tag 0x711, the "Audio information is present" fail message appears before the block name. Output the block name before any fail/warning messages related to the block.

For tags that are supposed to have an OUI but are not long enough:
- Output the block name before the "Invalid length" fail message. The fail message should include the block name but we don't want cta_block to output data_block so clear it after the fail, before exiting.

For tags with a 3 byte OUI:
- Since we are calling data_block_oui early (before data_block is output in cta_block), don't output block name in data_block_oui - cta_block will do that for us.
- data_block now includes the OUI (the block name in the failure/warning section will match block name in the EDID section).

Probably things would be simpler if we always set data_block to the block name, then have fail/warning messages that don't include the block name so they don't look redundant in the failures/warnings sections. For example we could have something like:
Unknown CTA-861 Data Block (tag 0x00): Invalid tag.
Vendor-Specific Data Block, OUI $$-$$-$$: Unknown OUI.
etc.

Sample corrupted EDID (combination of vizio-e65e0-hdmi and /System/Library/Displays/Contents/Resources/Overrides/DisplayVendorID-593a/DisplayProductID-1018:edid-patches):
00ffffffffffff00593a181001010101001a0103808f50782a6a6da4554f9e270e474aa5ce00d1c0010101010101010101010101010104740030f2705a80b0588a0048684200001e023a801871382d40582c450048684200001e000000fc004536352d45310a202020202020000000fd00174c0f8c26000a202020202020014502035171575f645d625e631022201f2105041307060302111215160132570600000000000000000000090707150750830100006f030c002000383ca05b5b0060010000000061666065e3060f01e305e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ea

---
 edid-decode.cpp     |  6 +++---
 parse-cta-block.cpp | 11 ++++-------
 2 files changed, 7 insertions(+), 10 deletions(-)
edid-decode.cpp +3 -3
index ec903f9..666a2c6 100644
@@ -686,12 +686,13 @@ void edid_state::data_block_oui(const char *block_name, const unsigned char *x,
 	bool reverse = false;
 
 	if (length < 3) {
+		printf("  %s:\n", block_name);
 		data_block = std::string(block_name);
 		fail("Invalid length %u < 3.\n", length);
+		data_block.clear();
 	}
 	else {
 		oui = (x[2] << 16) + (x[1] << 8) + x[0];
-		x += 3; length -=3;
 		name = oui_name(oui);
 		if (!name) {
 			name = oui_name(oui, true);
@@ -704,10 +705,9 @@ void edid_state::data_block_oui(const char *block_name, const unsigned char *x,
 			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
 		}
 		else {
-			data_block = std::string(block_name) + " (" + name + ")";
+			data_block = std::string(block_name) + " (" + name + "), OUI " + ouitohex(oui);
 			if (reverse)
 				fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
-			printf("  %s, OUI %s:\n", data_block.c_str(), ouitohex(oui).c_str());
 		}
 	}
 	if (ouinum) *ouinum = oui;
parse-cta-block.cpp +4 -7
index 16c7bee..607e42b 100644
@@ -2049,18 +2049,19 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 
 	unsigned oui;
 	bool audio_block = false;
+	data_block.clear();
 
 	switch (tag) {
 	case 0x01: data_block = "Audio Data Block"; audio_block = true; break;
 	case 0x02: data_block = "Video Data Block"; break;
-	case 0x03: data_block.clear(); break;
+	case 0x03: data_block_o("Vendor-Specific Data Block"); break;
 	case 0x04: data_block = "Speaker Allocation Data Block"; audio_block = true; break;
 	case 0x05: data_block = "VESA Display Transfer Characteristics Data Block"; break;
 
 	case 0x07: data_block = "Unknown CTA-861 Data Block (extended tag truncated)"; break;
 
 	case 0x700: data_block = "Video Capability Data Block"; break;
-	case 0x701: data_block.clear(); break;
+	case 0x701: data_block_o("Vendor-Specific Video Data Block"); break;
 	case 0x702: data_block = "VESA Video Display Device Data Block"; break;
 	case 0x703: data_block = "VESA Video Timing Block Extension"; break;
 	case 0x704: data_block = "Reserved for HDMI Video Data Block"; break;
@@ -2072,7 +2073,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x70e: data_block = "YCbCr 4:2:0 Video Data Block"; break;
 	case 0x70f: data_block = "YCbCr 4:2:0 Capability Map Data Block"; break;
 	case 0x710: data_block = "Reserved for CTA-861 Miscellaneous Audio Fields"; break;
-	case 0x711: data_block.clear(); audio_block = true; break;
+	case 0x711: data_block_o("Vendor-Specific Audio Data Block"); audio_block = true; break;
 	case 0x712: data_block = "HDMI Audio Data Block"; audio_block = true; break;
 	case 0x713: data_block = "Room Configuration Data Block"; audio_block = true; break;
 	case 0x714: data_block = "Speaker Location Data Block"; audio_block = true; break;
@@ -2087,7 +2088,6 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x779: data_block = "HDMI Forum Sink Capability Data Block"; break;
 
 	default:
-		data_block.clear();
 		std::string unknown_name;
 		     if (tag < 0x700) unknown_name = "Unknown CTA-861 Data Block";
 		else if (tag < 0x70d) unknown_name = "Unknown CTA-861 Video-Related Data Block";
@@ -2128,7 +2128,6 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x01: cta_audio_block(x, length); break;
 	case 0x02: cta_svd(x, length, false); break;
 	case 0x03:
-		data_block_o("Vendor-Specific Data Block");
 		if (oui == 0x000c03) {
 			cta_hdmi_block(x, length);
 			cta.last_block_was_hdmi_vsdb = 1;
@@ -2165,7 +2164,6 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x07: fail("Extended tag cannot have zero length.\n"); break;
 	case 0x700: cta_vcdb(x, length); break;
 	case 0x701:
-		data_block_o("Vendor-Specific Video Data Block");
 		if (oui == 0x90848b)
 			cta_hdr10plus(x, length);
 		else if (oui == 0x00d046)
@@ -2181,7 +2179,6 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x70e: cta_svd(x, length, true); break;
 	case 0x70f: cta_y420cmdb(x, length); break;
 	case 0x711:
-		data_block_o("Vendor-Specific Audio Data Block");
 		if (oui == 0x00d046)
 			cta_dolby_audio(x, length);
 		else
Signature · 1 line
2.24.3 (Apple Git-128)
author
#18 lore raw

PATCH v2 17/29 edid-decode: replace first_block with block_number

In reply to joevt

track progress instead of milestones.

With a flag like first_block, you can only know if you're at the first block or not.
But with a progressing value like block_number, you can know when you're at the first block or second block etc. and you can know how many blocks have been done. We'll also replace last_block_was_hdmi_vsdb in a later commit.
Both of these changes will cleanup the hdmi block.

---
 edid-decode.h       |  5 +++--
 parse-cta-block.cpp | 10 +++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)
edid-decode.h +3 -2
index ccf8558..dbc00c2 100644
@@ -154,7 +154,8 @@ struct edid_state {
 		cta.has_vic_1 = cta.first_svd_might_be_preferred = cta.has_sldb =
 			cta.has_hdmi = cta.has_vcdb = cta.has_vfpdb = false;
 		cta.last_block_was_hdmi_vsdb = cta.have_hf_vsdb = cta.have_hf_scdb = false;
-		cta.first_block = cta.first_svd = true;
+		cta.block_number = 0;
+		cta.first_svd = true;
 		cta.supported_hdmi_vic_codes = cta.supported_hdmi_vic_vsb_codes = 0;
 		memset(cta.vics, 0, sizeof(cta.vics));
 		memset(cta.preparsed_has_vic, 0, sizeof(cta.preparsed_has_vic));
@@ -259,7 +260,7 @@ struct edid_state {
 		unsigned short preparsed_phys_addr;
 		bool last_block_was_hdmi_vsdb;
 		bool have_hf_vsdb, have_hf_scdb;
-		bool first_block;
+		unsigned block_number;
 		bool first_svd;
 		unsigned supported_hdmi_vic_codes;
 		unsigned supported_hdmi_vic_vsb_codes;
parse-cta-block.cpp +5 -5
index 607e42b..13b3b73 100644
@@ -2131,7 +2131,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		if (oui == 0x000c03) {
 			cta_hdmi_block(x, length);
 			cta.last_block_was_hdmi_vsdb = 1;
-			cta.first_block = 0;
+			cta.block_number++;
 			// The HDMI OUI is present, so this EDID represents an HDMI
 			// interface. And HDMI interfaces must use EDID version 1.3
 			// according to the HDMI Specification, so check for this.
@@ -2194,7 +2194,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x778:
 		cta_hf_eeodb(x, length);
 		// This must be the first CTA-861 block
-		if (!cta.first_block)
+		if (cta.block_number > 0)
 			fail("Block starts at a wrong offset.\n");
 		break;
 	case 0x779:
@@ -2216,7 +2216,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		hex_block("    ", x, length);
 	}
 
-	cta.first_block = 0;
+	cta.block_number++;
 	cta.last_block_was_hdmi_vsdb = 0;
 }
 
@@ -2333,11 +2333,11 @@ void edid_state::parse_cta_block(const unsigned char *x)
 //				msg(!cta.has_hdmi, "If YCbCr support is indicated, then both 4:2:2 and 4:4:4 %s be supported.\n",
 //				    cta.has_hdmi ? "shall" : "should");
 			printf("  Native detailed modes: %u\n", x[3] & 0x0f);
-			if (cta.first_block)
+			if (cta.block_number == 0)
 				cta.byte3 = x[3];
 			else if (x[3] != cta.byte3)
 				fail("Byte 3 must be the same for all CTA-861 Extension Blocks.\n");
-			if (cta.first_block) {
+			if (cta.block_number == 0) {
 				unsigned native_dtds = x[3] & 0x0f;
 
 				cta.native_timings.clear();
Signature · 1 line
2.24.3 (Apple Git-128)
author
#19 lore raw

PATCH v2 18/29 edid-decode: move parse_displayid_block inner loop

In reply to joevt

Move it to a new function displayid_block. Then we can simplify it later.
This is mostly just a copy/paste. No output should change.
The new function returns 0xff for len to signal a break from the loop in parse_displayid_block. That will be cleaned up later.

first_data_block is replaced with dispid.block_number (similar to cta.block_number)

---
 edid-decode.h             |  3 ++
 parse-displayid-block.cpp | 95 +++++++++++++++++++++------------------
 2 files changed, 54 insertions(+), 44 deletions(-)
edid-decode.h +3 -0
index dbc00c2..4636978 100644
@@ -176,6 +176,7 @@ struct edid_state {
 		dispid.is_display = dispid.has_product_identification =
 			dispid.has_display_parameters = dispid.has_type_1_7 =
 			dispid.has_display_interface_features = false;
+		dispid.block_number = 0;
 
 		// Block Map block state
 		block_map.saw_block_1 = false;
@@ -283,6 +284,7 @@ struct edid_state {
 		bool has_display_interface_features;
 		vec_timings_ext preferred_timings;
 		unsigned native_width, native_height;
+		unsigned block_number;
 		// Keep track of the found CTA-861 Tag/Extended Tag pairs.
 		// The unsigned value is equal to: (tag << 8) | ext_tag
 		std::set<unsigned> found_tags;
@@ -393,6 +395,7 @@ struct edid_state {
 	void parse_displayid_type_10_timing(const unsigned char *x, unsigned sz,
 					    bool is_cta = false);
 	void preparse_displayid_block(const unsigned char *x);
+	unsigned displayid_block(const unsigned version, const unsigned char *x, unsigned offset, unsigned length);
 	void parse_displayid_block(const unsigned char *x);
 	void parse_displayid_vesa(const unsigned char *x);
 	void parse_displayid_cta_data_block(const unsigned char *x);
parse-displayid-block.cpp +51 -44

131 lines not on this page · raw message

Signature · 1 line
2.24.3 (Apple Git-128)
author
#20 lore raw

PATCH v2 19/29 edid-decode: remove offset from displayid_block

In reply to joevt

Change the function so that x points to the start of the DisplayID block.

---
 edid-decode.h             |   2 +-
 parse-displayid-block.cpp | 136 +++++++++++++++++++-------------------
 2 files changed, 69 insertions(+), 69 deletions(-)
edid-decode.h +1 -1
index 4636978..c53dba3 100644
@@ -395,7 +395,7 @@ struct edid_state {
 	void parse_displayid_type_10_timing(const unsigned char *x, unsigned sz,
 					    bool is_cta = false);
 	void preparse_displayid_block(const unsigned char *x);
-	unsigned displayid_block(const unsigned version, const unsigned char *x, unsigned offset, unsigned length);
+	unsigned displayid_block(const unsigned version, const unsigned char *x, unsigned length);
 	void parse_displayid_block(const unsigned char *x);
 	void parse_displayid_vesa(const unsigned char *x);
 	void parse_displayid_cta_data_block(const unsigned char *x);
parse-displayid-block.cpp +68 -68

246 lines not on this page · raw message

Signature · 1 line
2.24.3 (Apple Git-128)
author
#21 lore raw

PATCH v2 20/29 edid-decode: displayid_block len fixes

In reply to joevt

- Calculate len early like we do for CTA blocks (set to zero if there's no bytes remaining to get len). We'll use this for OUI errors later.
- The return value of the displayid_block function is now the entire length of the DisplayID data block. Returning length will thus terminate the loop in parse_displayid_block, so we don't need the 0xff magic number.
- Bug fix: For the "Not enough bytes remain (%d) for a DisplayID data block or the DisplayID filler is non-0.\n" fail message, if length remaining is only 1 then don't check the byte beyond that. Also change "or" to "and" in that message.

---
 parse-displayid-block.cpp | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
parse-displayid-block.cpp +12 -14
index 17f1805..c090056 100644
@@ -1656,6 +1656,7 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 	unsigned i;
 	unsigned tag = x[0];
 		unsigned oui = 0;
+	unsigned len = (length < 3) ? 0 : x[2];
 
 		switch (tag) {
 		// DisplayID 1.3:
@@ -1732,18 +1733,17 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 
 		if (length < 3) {
 			// report a problem when the remaining bytes are not 0.
-		if (tag || x[1]) {
-				fail("Not enough bytes remain (%d) for a DisplayID data block or the DisplayID filler is non-0.\n", length);
+		if (tag || (length > 1 && x[1])) {
+			fail("Not enough bytes remain (%d) for a DisplayID data block and the DisplayID filler is non-0.\n", length);
 			}
-		return 0xff;
+		return length;
 		}
 
 	unsigned block_rev = x[1] & 0x07;
-	unsigned len = x[2];
 
 		if (length < len + 3) {
 			fail("The length of this DisplayID data block (%d) exceeds the number of bytes remaining (%d).\n", len + 3, length);
-		return 0xff;
+		return length;
 		}
 
 		if (!tag && !len) {
@@ -1751,7 +1751,7 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 		if (!memchk(x, length)) {
 				fail("Non-0 filler bytes in the DisplayID block.\n");
 			}
-		return 0xff;
+		return length;
 		}
 
 		printf("  %s:\n", data_block.c_str());
@@ -1867,7 +1867,7 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 	case 0x27: parse_displayid_stereo_display_intf(x); break;
 	case 0x28: parse_displayid_tiled_display_topology(x, true); break;
 	case 0x29: parse_displayid_ContainerID(x); break;
-	case 0x2b: parse_displayid_adaptive_sync(x + offset); break;
+	case 0x2b: parse_displayid_adaptive_sync(x); break;
 		case 0x32: {
 		   unsigned sz = 6 + ((x[1] & 0x70) >> 4);
 
@@ -1892,7 +1892,7 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 			     data_block.c_str());
 
 	dispid.block_number++;
-	return len;
+	return len + 3;
 }
 
 void edid_state::parse_displayid_block(const unsigned char *x)
@@ -1932,12 +1932,10 @@ void edid_state::parse_displayid_block(const unsigned char *x)
 		length = 121;
 	}
 
-	unsigned offset = 5;
-	while (length > 0) {
-		unsigned len = displayid_block(version, x + offset, length);
-		if (len == 0xff) break;
-		length -= len + 3;
-		offset += len + 3;
+	unsigned len;
+	for (const unsigned char *y = x + 5; length > 0; y += len) {
+		len = displayid_block(version, y, length);
+		length -= len;
 	}
 
 	/*
Signature · 1 line
2.24.3 (Apple Git-128)
author
#22 lore raw

PATCH v2 21/29 edid-decode: ignore DisplayID version for OUI check.

In reply to joevt

- Interpret VESA data block even if DisplayID version is not 2.0. See example apple-xdr-6k.
- Remove the "Unknown DisplayID Data Block" fail message for these tags because there's a "Use of DisplayID v#.# tag for DisplayID v%u.%u.\n" fail message for them.
- Include tag number for ambiguous DisplayID tags.
- Don't need tag number for 0x81 because it's not ambiguous.

---
 parse-displayid-block.cpp | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
parse-displayid-block.cpp +4 -7
index c090056..5266bb3 100644
@@ -1697,8 +1697,7 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 		// 0x2a .. 0x7d RESERVED for Additional VESA-defined Data Blocks
 		case 0x7e: // DisplayID 2.0
 		case 0x7f: // DisplayID 1.3
-			if ((tag == 0x7e && version >= 0x20) ||
-			    (tag == 0x7f && version < 0x20)) {
+		{
 			oui = (x[3] << 16) + (x[4] << 8) + x[5];
 				const char *name = oui_name(oui);
 				bool reversed = false;
@@ -1709,17 +1708,15 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 						reversed = true;
 				}
 				if (name)
-					data_block = std::string("Vendor-Specific Data Block (") + name + ")";
+				data_block = "Vendor-Specific Data Block (" + utohex(tag) + ") (" + name + ")";
 				else
-					data_block = "Vendor-Specific Data Block, OUI " + ouitohex(oui);
+				data_block = "Vendor-Specific Data Block (" + utohex(tag) + "), OUI " + ouitohex(oui);
 				if (reversed)
 					fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order.\n").c_str());
-			} else {
-				data_block = "Unknown DisplayID Data Block (" + utohex(tag) + ")";
 			}
 			break;
 		// 0x80 RESERVED
-		case 0x81: data_block = "CTA-861 DisplayID Data Block (" + utohex(tag) + ")"; break;
+	case 0x81: data_block = "CTA-861 DisplayID Data Block"; break;
 		// 0x82 .. 0xff RESERVED
 		default:   data_block = "Unknown DisplayID Data Block (" + utohex(tag) + ")"; break;
 		}
Signature · 1 line
2.24.3 (Apple Git-128)
author
#23 lore raw

PATCH v2 22/29 edid-decode: DisplayID non-0 filler fixes

In reply to joevt

It's probably not a Product Identification Data Block or any kind of block so data_block should be cleared (so that the block name doesn't appear in the Failures section for this fail). Output hex data because it might contain interesting data (it's at least known to be not zero).

---
 parse-displayid-block.cpp | 3 +++
 1 file changed, 3 insertions(+)
parse-displayid-block.cpp +3 -0
index 5266bb3..dc2ec7b 100644
@@ -1745,8 +1745,11 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 
 		if (!tag && !len) {
 			// A Product Identification Data Block with no payload bytes is not valid - assume this is the end.
+		data_block.clear(); // Probably not a Product Identification Data Block so clear this.
 		if (!memchk(x, length)) {
+			printf("  Filler:\n");
 				fail("Non-0 filler bytes in the DisplayID block.\n");
+			hex_block("    ", x, length);
 			}
 		return length;
 		}
Signature · 1 line
2.24.3 (Apple Git-128)
author
#24 lore raw

PATCH v2 23/29 edid-decode: DisplayID length checks

In reply to joevt

- Only report DisplayID version discrepancy for a data block after verifying that the data block exists and is properly sized. The fail message is output after the block name instead of before the block name.
- Output hex bytes of non-zero filler when length is 1 or 2. We did the same for lengths longer than that in a previous commit.
- Output hex bytes that are skipped when the block length is longer than the number of bytes remaining in the DisplayID block.

---
 parse-displayid-block.cpp | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
parse-displayid-block.cpp +16 -10
index dc2ec7b..269444b 100644
@@ -1721,25 +1721,22 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 		default:   data_block = "Unknown DisplayID Data Block (" + utohex(tag) + ")"; break;
 		}
 
-		if (version >= 0x20 && (tag < 0x20 || tag == 0x7f))
-			fail("Use of DisplayID v1.x tag for DisplayID v%u.%u.\n",
-			     version >> 4, version & 0xf);
-		if (version < 0x20 && tag >= 0x20 && tag <= 0x7e)
-			fail("Use of DisplayID v2.0 tag for DisplayID v%u.%u.\n",
-			     version >> 4, version & 0xf);
-
 		if (length < 3) {
-			// report a problem when the remaining bytes are not 0.
+		// Report a problem when the remaining bytes are not 0.
+		data_block.clear(); // Probably not a Data Block so clear this.
 		if (tag || (length > 1 && x[1])) {
+			printf("  Filler:\n");
 			fail("Not enough bytes remain (%d) for a DisplayID data block and the DisplayID filler is non-0.\n", length);
+			hex_block("    ", x, length);
 			}
 		return length;
 		}
 
-	unsigned block_rev = x[1] & 0x07;
-
 		if (length < len + 3) {
+		data_block.clear(); // Probably not a Data Block so clear this.
+		printf("  Filler:\n");
 			fail("The length of this DisplayID data block (%d) exceeds the number of bytes remaining (%d).\n", len + 3, length);
+		hex_block("    ", x, length);
 		return length;
 		}
 
@@ -1756,6 +1753,15 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 
 		printf("  %s:\n", data_block.c_str());
 
+	if (version >= 0x20 && (tag < 0x20 || tag == 0x7f))
+		fail("Use of DisplayID v1.x tag for DisplayID v%u.%u.\n",
+			 version >> 4, version & 0xf);
+	if (version < 0x20 && tag >= 0x20 && tag <= 0x7e)
+		fail("Use of DisplayID v2.0 tag for DisplayID v%u.%u.\n",
+			 version >> 4, version & 0xf);
+
+	unsigned block_rev = x[1] & 0x07;
+
 		switch (tag) {
 	case 0x00: parse_displayid_product_id(x); break;
 	case 0x01: parse_displayid_parameters(x); break;
Signature · 1 line
2.24.3 (Apple Git-128)
author
#25 lore raw

PATCH v2 24/29 edid-decode: make OUI enum

In reply to joevt

Instead of a 3 byte value, create an enumeration of known OUIs. This way, it can be combined with tag value to identify a data block type with a single value. This value can be used in a switch statement or other places (see later commits).

- The list of known OUIs is in a new file oui.h. It contains the 3 byte value, a enum base name for the enum, and the OUI name.
- The oui.h can be included in other source files for different purposes be changing the oneoui macro. It's used in edid-decode.h to define the enumeration.
- Function oui_name uses oui.h to convert an OUI to the enum value. Removed the reverse parameter - OUI byte order is now handled by the caller, data_block_oui.

- data_block_oui is modified to do the following:
- It will return the oui enumeration.
- It is made suitable for OUIs in DisplayID data blocks.
- The ignorezeos flag is only true for the DisplayID "Product Identification Data Block". If the data block is zeros then it's probably not a data block so ignore it. For "Product Identification Data Block", the OUI doesn't change the interpretation of the data block so caller (displayid_block) then immediately clears the OUI enum.
- The do_ascii flag is true for DisplayID v1.2 data blocks (section 4.1.1 of the DisplayID 1.3 spec says Manufacturer/Vendor ID is ASCII).
- The big_endian flag is true for DisplayID v2.0 data blocks and false for CTA-861 data blocks.
- It always outputs the block name first so that fails and warnings will appear after the block name instead of before.

data_block_oui does the following:
- It gets the OUI bytes in the order determined by the big_endian flag. An OUI is a 24 bit number.
- It gets a PNP ID value (ASCII) with the same 3 bytes. A PNP ID in oui.h is a 32 bit number (3 characters [A-Z] followed by a NULL) so it cannot be confused with an OUI in the same file.
- If bytes of the OUI extend beyond the end of the block then they are assumed to be zero, and it does not try to convert the OUI to a name, and the enum result is 0 which is invalid, and the PNP result is "?" which is invalid.
- It tries to match the OUI. If that doesn't match then it tries to match the reversed OUI. If DisplayID v1.2 then it also tries to match PNP if the other two didn't match.

- If ASCII is expected (DisplayID v1.2) and found, the output block name is "block_name, PNP ID 'ABC'". It is output with a colon as usual.

- The "Unknown block_name, OUI %s." warning message is replaced by "Unknown OUI %s." (or with "Unknown OUI %s (possible PNP %s)." if ASCII is expected and the OUI is valid ASCII). In either case, the warning is prefixed by "block_name, OUI %s:" or "block_name, PNP ID %s:" in the warnings and failures section.

- The "Invalid length %u < 3." fail message is replaced by "Data block length (%d) is not enough to contain an OUI.".

- The "OUI %s is in the wrong byte order" fail message (which is missing the trailing period) is replaced with "Endian-ness (be|le) of OUI is different than expected (le|be)."

- In parse-cta-block.cpp and parse-displayid-block.cpp, in the first switch statement, any tag with an OUI has its block name output by data_block_oui so they'll set dooutputname to false to stop the block name from being output again.

- In parse-displayid-block.cpp, don't include OUI in hex dump of unknown data block types.

---
 edid-decode.cpp           | 117 +++++++++++++++++++++++++-------------
 edid-decode.h             |   8 ++-
 oui.h                     |  20 +++++++
 parse-cta-block.cpp       |  78 ++++++++++---------------
 parse-displayid-block.cpp |  46 ++++++---------
 5 files changed, 148 insertions(+), 121 deletions(-)
 create mode 100644 oui.h
edid-decode.cpp +76 -41
index 666a2c6..0da7d85 100644
@@ -657,60 +657,95 @@ std::string utohex(unsigned char x)
 	return buf;
 }
 
-const char *oui_name(unsigned oui, bool reverse)
+const char *oui_name(unsigned oui, unsigned *ouinum)
 {
-	if (reverse)
-		oui = (oui >> 16) | (oui & 0xff00) | ((oui & 0xff) << 16);
-
+	unsigned ouinumscratch;
+	if (!ouinum) ouinum = &ouinumscratch;
+	const char *name;
 	switch (oui) {
-	case 0x00001a: return "AMD";
-	case 0x000c03: return "HDMI";
-	case 0x00044b: return "NVIDIA";
-	case 0x000c6e: return "ASUS";
-	case 0x0010fa: return "Apple";
-	case 0x0014b9: return "MSTAR";
-	case 0x00d046: return "Dolby";
-	case 0x00e047: return "InFocus";
-	case 0x3a0292: return "VESA";
-	case 0x90848b: return "HDR10+";
-	case 0xc45dd8: return "HDMI Forum";
-	case 0xca125c: return "Microsoft";
-	default: return NULL;
+		#define oneoui(c,k,n) case c: *ouinum = kOUI_##k; name = n; break;
+		#include "oui.h"
+		default: *ouinum = 0; name = NULL;
 	}
+	return name;
 }
 
-void edid_state::data_block_oui(const char *block_name, const unsigned char *x, unsigned length, unsigned *ouinum)
+void edid_state::data_block_oui(std::string block_name, const unsigned char *x,
+	unsigned length, unsigned *ouinum, bool ignorezeros, bool do_ascii, bool big_endian)
 {
-	const char *name;
-	unsigned oui = 0;
-	bool reverse = false;
+	std::string buf;
+	char ascii[4];
+	unsigned oui;
+	const char *ouiname = NULL;
+	bool matched_reverse = false;
+	bool matched_ascii = false;
+	bool valid_ascii = false;
+
+	if (big_endian)
+		oui = ((length > 0 ? x[0] : 0) << 16) + ((length > 1 ? x[1] : 0) << 8) + (length > 2 ? x[2] : 0);
+	else
+		oui = ((length > 2 ? x[2] : 0) << 16) + ((length > 1 ? x[1] : 0) << 8) + (length > 0 ? x[0] : 0);
 
+	buf = ouitohex(oui);
 	if (length < 3) {
-		printf("  %s:\n", block_name);
-		data_block = std::string(block_name);
-		fail("Invalid length %u < 3.\n", length);
-		data_block.clear();
-	}
-	else {
-		oui = (x[2] << 16) + (x[1] << 8) + x[0];
-		name = oui_name(oui);
-		if (!name) {
-			name = oui_name(oui, true);
-			if (name)
-				reverse = true;
+		sprintf(ascii, "?"); // some characters are null
+		if (ouinum) *ouinum = 0; // doesn't match a known OUI
+	} else {
+		valid_ascii = (x[0] >= 'A' && x[1] >= 'A' && x[2] >= 'A' && x[0] <= 'Z' && x[1] <= 'Z' && x[2] <= 'Z');
+		sprintf(ascii, "%c%c%c", x[0], x[1], x[2]);
+
+		ouiname = oui_name(oui, ouinum);
+		if (!ouiname) {
+			big_endian = !big_endian;
+			unsigned reversedoui = ((oui & 0xff) << 16) + (oui & 0x00ff00) + (oui >> 16);
+			ouiname = oui_name(reversedoui, ouinum);
+			if (ouiname) {
+				oui = reversedoui;
+				buf = ouitohex(oui);
+				matched_reverse = true;
+			}
+			else if (do_ascii && valid_ascii)
+			{
+				unsigned asciioui = (x[0] << 24) + (x[1] << 16) + (x[2] << 8);
+				ouiname = oui_name(asciioui, ouinum);
+				if (ouiname) {
+					matched_ascii = true;
+				}
+			}
 		}
-		if (!name) {
-			printf("  %s, OUI %s:\n", block_name, ouitohex(oui).c_str());
-			data_block.clear();
-			warn("Unknown %s, OUI %s.\n", block_name, ouitohex(oui).c_str());
+	}
+
+	std::string name;
+	if (ouiname) {
+		if (matched_ascii)
+			name = block_name + " (" + ouiname + ")" + ", PNP ID '" + ascii + "'";
+		else
+			name = block_name + " (" + ouiname + ")" + ", OUI " + buf;
+	} else if (do_ascii && valid_ascii) {
+		name = block_name + ", PNP ID '" + ascii + "'";
+	} else {
+		name = block_name + ", OUI " + buf;
+	}
+	// assign string to data_block before outputting errors
+	data_block = name;
+
+	if (oui || !ignorezeros) {
+		printf("  %s:\n", data_block.c_str());
+		if (length < 3)
+			fail("Data block length (%d) is not enough to contain an OUI.\n", length);
+		else if (ouiname) {
+			if (do_ascii && !valid_ascii)
+				fail("Expected PNP ID but found OUI.\n");
+			if (matched_reverse)
+				fail("Endian-ness (%s) of OUI is different than expected (%s).\n", big_endian ? "be" : "le", big_endian ? "le" : "be");
 		}
 		else {
-			data_block = std::string(block_name) + " (" + name + "), OUI " + ouitohex(oui);
-			if (reverse)
-				fail((std::string("OUI ") + ouitohex(oui) + " is in the wrong byte order\n").c_str());
+			if (valid_ascii)
+				warn("Unknown OUI %s (possible PNP %s).\n", buf.c_str(), ascii);
+			else
+				warn("Unknown OUI %s.\n", buf.c_str());
 		}
 	}
-	if (ouinum) *ouinum = oui;
 }
 
 std::string ouitohex(unsigned oui)
edid-decode.h +6 -2
index c53dba3..9f73e9c 100644
@@ -334,7 +334,8 @@ struct edid_state {
 	void list_dmts();
 	void list_established_timings();
 
-	void data_block_oui(const char *block_name, const unsigned char *x, unsigned length, unsigned *ouinum);
+	void data_block_oui(std::string block_name, const unsigned char *x, unsigned length, unsigned *ouinum,
+	                    bool ignorezeros = false, bool do_ascii = false, bool big_endian = false);
 
 	void print_vic_index(const char *prefix, unsigned idx, const char *suffix, bool ycbcr420 = false);
 	void hdmi_latency(unsigned char vid_lat, unsigned char aud_lat, bool is_ilaced);
@@ -460,7 +461,7 @@ void hex_block(const char *prefix, const unsigned char *x, unsigned length,
 	       bool show_ascii = true, unsigned step = 16);
 std::string block_name(unsigned char block);
 void calc_ratio(struct timings *t);
-const char *oui_name(unsigned oui, bool reverse = false);
+const char *oui_name(unsigned oui, unsigned *ouinum = NULL);
 
 bool timings_close_match(const timings &t1, const timings &t2);
 const struct timings *find_dmt_id(unsigned char dmt_id);
@@ -471,4 +472,7 @@ const struct timings *cta_close_match_to_vic(const timings &t, unsigned &vic);
 unsigned char hdmi_vic_to_vic(unsigned char hdmi_vic);
 char *extract_string(const unsigned char *x, unsigned len);
 
+#define oneoui(c,k,n) const unsigned kOUI_##k = __LINE__<<12;
+#include "oui.h"
+
 #endif
oui.h new file +20 -0
new file mode 100644
index 0000000..c90f025
@@ -0,0 +1,20 @@
+// http://standards-oui.ieee.org/oui/oui.txt
+oneoui(0x000c03, HDMI,         "HDMI"        )
+oneoui(0xc45dd8, HDMIForum,    "HDMI Forum"  )
+oneoui(0x90848b, HDR10,        "HDR10+"      )
+oneoui(0x00001a, AMD,          "AMD"         )
+oneoui(0x00044b, NVIDIA,       "NVIDIA"      )
+oneoui(0x000c6e, ASUS,         "ASUS"        )
+oneoui(0x0010fa, Apple,        "Apple"       )
+oneoui(0x0014b9, MSTAR,        "MSTAR"       )
+oneoui(0x00d046, Dolby,        "Dolby"       )
+oneoui(0x00e047, InFocus,      "InFocus"     )
+oneoui(0xca125c, Microsoft,    "Microsoft"   )
+
+// http://standards-oui.ieee.org/cid/cid.txt
+oneoui(0x3a0292, VESA,         "VESA"        )
+
+// https://uefi.org/pnp_id_list
+oneoui('APP\0' , asciiApple,   "Apple"       )
+
+#undef oneoui
parse-cta-block.cpp +30 -48

124 lines not on this page · raw message

parse-displayid-block.cpp +16 -30

91 lines not on this page · raw message

Signature · 1 line
2.24.3 (Apple Git-128)
author
#26 lore raw

PATCH v2 25/29 edid-decode: more OUI changes

In reply to joevt

Since OUI is part of the tag, we can make the following changes:

- Replace cta.last_block_was_hdmi_vsdb with cta.previous_cta_tag. Instead of remembering if the last tag was HDMI VSDB, we can just always remember the last tag value and compare it to the HDMI VSDB tag value. With this change, we can clean up the HDMI VSDB case statement (remove the two lines that also exist at the end of the switch and change the return to a break.

- Change found_tags from std::set to std::vector. std::vector not only remembers all the flags, but also their order so you could use it to find the number of tags or the first tag (replace block_number?) or the last tag (replace previous_cta_tag?). We could replace previous_cta_tag except found_tags is separate for DisplayID block for some reason, while previous_cta_tag is used for CTA data blocks in both CTA blocks and DisplayID blocks. Maybe there should be only one found_tags, like there is only one previous_cta_tag.

- Remove duplicate parameter from cta_block. Instead, pass the list of found_tags that we want to check for duplicates. This way, the tag value doesn't need to be recalculated.

- For blocks with OUI that we don't know how to parse, skip OUI even if it is zero. Make sure length passed to hex_block is not negative.

---
 edid-decode.h             | 15 ++++++++-------
 parse-cta-block.cpp       | 33 ++++++++++++---------------------
 parse-displayid-block.cpp | 27 +++++++++++----------------
 3 files changed, 31 insertions(+), 44 deletions(-)
edid-decode.h +8 -7
index 9f73e9c..6a40092 100644
@@ -153,7 +153,8 @@ struct edid_state {
 		// CTA-861 block state
 		cta.has_vic_1 = cta.first_svd_might_be_preferred = cta.has_sldb =
 			cta.has_hdmi = cta.has_vcdb = cta.has_vfpdb = false;
-		cta.last_block_was_hdmi_vsdb = cta.have_hf_vsdb = cta.have_hf_scdb = false;
+		cta.previous_cta_tag = 0xfff;
+		cta.have_hf_vsdb = cta.have_hf_scdb = false;
 		cta.block_number = 0;
 		cta.first_svd = true;
 		cta.supported_hdmi_vic_codes = cta.supported_hdmi_vic_vsb_codes = 0;
@@ -244,8 +245,8 @@ struct edid_state {
 		vec_timings_ext preferred_timings;
 		bool preparsed_has_t8vtdb;
 		// Keep track of the found Tag/Extended Tag pairs.
-		// The unsigned value is equal to: (tag << 8) | ext_tag
-		std::set<unsigned> found_tags;
+		// The unsigned value is equal to: (tag) | (OUI enum << 12) or (extended tag) | (tag << 8) | (OUI enum << 12)
+		std::vector<unsigned> found_tags;
 		timings_ext t8vtdb;
 		vec_timings_ext native_timings;
 		bool has_vic_1;
@@ -259,7 +260,7 @@ struct edid_state {
 		bool preparsed_sld;
 		bool has_sldb;
 		unsigned short preparsed_phys_addr;
-		bool last_block_was_hdmi_vsdb;
+		unsigned previous_cta_tag;
 		bool have_hf_vsdb, have_hf_scdb;
 		unsigned block_number;
 		bool first_svd;
@@ -286,8 +287,8 @@ struct edid_state {
 		unsigned native_width, native_height;
 		unsigned block_number;
 		// Keep track of the found CTA-861 Tag/Extended Tag pairs.
-		// The unsigned value is equal to: (tag << 8) | ext_tag
-		std::set<unsigned> found_tags;
+		// The unsigned value is equal to: (tag) | (OUI enum << 12) or (extended tag) | (tag << 8) | (OUI enum << 12)
+		std::vector<unsigned> found_tags;
 	} dispid;
 
 	// Block Map block state
@@ -350,7 +351,7 @@ struct edid_state {
 	void cta_displayid_type_7(const unsigned char *x, unsigned length);
 	void cta_displayid_type_8(const unsigned char *x, unsigned length);
 	void cta_displayid_type_10(const unsigned char *x, unsigned length);
-	void cta_block(const unsigned char *x, bool duplicate);
+	void cta_block(const unsigned char *x, std::vector<unsigned> &found_tags);
 	void preparse_cta_block(const unsigned char *x);
 	void parse_cta_block(const unsigned char *x);
 	void cta_resolve_svr(vec_timings_ext::iterator iter);
parse-cta-block.cpp +12 -21
index 71e0041..9ae7597 100644
@@ -2029,13 +2029,15 @@ static void cta_hdmi_audio_block(const unsigned char *x, unsigned length)
 
 #define data_block_o(n) \
 	do { \
+		unsigned ouinum; \
 		data_block_oui(n, x, length, &ouinum); \
 		x += (length < 3) ? length : 3; \
 		length -= (length < 3) ? length : 3; \
 		dooutputname = false; \
+		tag |= ouinum; \
 	} while(0)
 
-void edid_state::cta_block(const unsigned char *x, bool duplicate)
+void edid_state::cta_block(const unsigned char *x, std::vector<unsigned> &found_tags)
 {
 	unsigned length = x[0] & 0x1f;
 	unsigned tag=(x[0] & 0xe0) >> 5;
@@ -2048,7 +2050,6 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		x++;
 	}
 
-	unsigned ouinum = 0;
 	bool dooutputname = true;
 	bool audio_block = false;
 	data_block.clear();
@@ -2118,7 +2119,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	case 0x713:
 	case 0x778:
 	case 0x779:
-		if (duplicate)
+		if (std::find(found_tags.begin(), found_tags.end(), tag) != found_tags.end())
 			fail("Only one instance of this Data Block is allowed.\n");
 	}
 
@@ -2126,28 +2127,25 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 	if (audio_block && !(cta.byte3 & 0x40))
 		fail("Audio information is present, but bit 6 of Byte 3 of the CTA-861 Extension header indicates no Basic Audio support.\n");
 
-	tag |= ouinum;
 	switch (tag) {
 	case 0x01: cta_audio_block(x, length); break;
 	case 0x02: cta_svd(x, length, false); break;
 	case 0x03|kOUI_HDMI:
 		cta_hdmi_block(x, length);
-		cta.last_block_was_hdmi_vsdb = 1;
-		cta.block_number++;
 		// The HDMI OUI is present, so this EDID represents an HDMI
 		// interface. And HDMI interfaces must use EDID version 1.3
 		// according to the HDMI Specification, so check for this.
 		if (base.edid_minor != 3)
 			fail("The HDMI Specification requires EDID 1.3 instead of 1.%u.\n",
 				 base.edid_minor);
-		return;
+		break;
 	case 0x03|kOUI_HDMIForum:
-		if (!cta.last_block_was_hdmi_vsdb)
+		if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
 			fail("HDMI Forum VSDB did not immediately follow the HDMI VSDB.\n");
 		if (cta.have_hf_scdb || cta.have_hf_vsdb)
 			fail("Duplicate HDMI Forum VSDB/SCDB.\n");
 		cta_hf_scdb(x, length);
-		cta.have_hf_vsdb = 1;
+		cta.have_hf_vsdb = true;
 		break;
 	case 0x03|kOUI_AMD: cta_amd(x, length); break;
 	case 0x03|kOUI_Microsoft: if (length != 0x12) goto dodefault; cta_microsoft(x, length); break;
@@ -2179,7 +2177,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 			fail("Block starts at a wrong offset.\n");
 		break;
 	case 0x779:
-		if (!cta.last_block_was_hdmi_vsdb)
+		if (cta.previous_cta_tag != (0x03|kOUI_HDMI))
 			fail("HDMI Forum SCDB did not immediately follow the HDMI VSDB.\n");
 		if (cta.have_hf_scdb || cta.have_hf_vsdb)
 			fail("Duplicate HDMI Forum VSDB/SCDB.\n");
@@ -2191,7 +2189,7 @@ void edid_state::cta_block(const unsigned char *x, bool duplicate)
 		if (x[0] || x[1])
 			printf("  Non-zero SCDB reserved fields!\n");
 		cta_hf_scdb(x + 2, length - 2);
-		cta.have_hf_scdb = 1;
+		cta.have_hf_scdb = true;
 		break;
 dodefault:
 	default:
@@ -2199,7 +2197,8 @@ dodefault:
 	}
 
 	cta.block_number++;
-	cta.last_block_was_hdmi_vsdb = 0;
+	cta.previous_cta_tag = tag;
+	found_tags.push_back(tag);
 }
 
 void edid_state::preparse_cta_block(const unsigned char *x)
@@ -2345,15 +2344,7 @@ void edid_state::parse_cta_block(const unsigned char *x)
 			unsigned i;
 
 			for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
-				unsigned tag = (x[i] & 0xe0) << 3;
-
-				if (tag == 0x700)
-					tag |= x[i + 1];
-				bool duplicate = cta.found_tags.find(tag) != cta.found_tags.end();
-
-				cta_block(x + i, duplicate);
-				if (!duplicate)
-					cta.found_tags.insert(tag);
+				cta_block(x + i, cta.found_tags);
 			}
 
 			data_block.clear();
parse-displayid-block.cpp +11 -16
index 597005e..a38c90e 100644
@@ -1556,15 +1556,7 @@ void edid_state::parse_displayid_cta_data_block(const unsigned char *x)
 	x += 3;
 
 	for (i = 0; i < len; i += (x[i] & 0x1f) + 1) {
-		unsigned tag = (x[i] & 0xe0) << 3;
-
-		if (tag == 0x700)
-			tag |= x[i + 1];
-		bool duplicate = dispid.found_tags.find(tag) != dispid.found_tags.end();
-
-		cta_block(x + i, duplicate);
-		if (!duplicate)
-			dispid.found_tags.insert(tag);
+		cta_block(x + i, dispid.found_tags);
 	}
 
 	if (i != len)
@@ -1653,21 +1645,25 @@ void edid_state::preparse_displayid_block(const unsigned char *x)
 
 #define data_block_o(n, a, b) \
 do { \
+	unsigned ouinum; \
 	data_block_oui(n, x + 3, len, &ouinum, tag == 0, a, b); \
 	dooutputname = false; \
+	if (tag != 0x00 && tag != 0x20) tag |= ouinum; \
+	hasoui = true; \
 } while (0)
 
 unsigned edid_state::displayid_block(const unsigned version, const unsigned char *x, unsigned length)
 {
 	unsigned i;
 	unsigned tag = x[0];
-	unsigned ouinum = 0;
+	unsigned tag_version = (tag < 0x20) ? 1 : (tag < 0x7f) ? 2 : (tag < 0x80) ? 1 : 0;
 	bool dooutputname = true;
 	unsigned len = (length < 3) ? 0 : x[2];
+	bool hasoui = false;
 
 		switch (tag) {
 		// DisplayID 1.3:
-	case 0x00: data_block_o("Product Identification Data Block (" + utohex(tag) + ")", true, false); ouinum = 0; break;
+	case 0x00: data_block_o("Product Identification Data Block (" + utohex(tag) + ")", true, false); break;
 		case 0x01: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break;
 		case 0x02: data_block = "Color Characteristics Data Block"; break;
 		case 0x03: data_block = "Video Timing Modes Type 1 - Detailed Timings Data Block"; break;
@@ -1689,7 +1685,7 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 		case 0x13: data_block = "Video Timing Modes Type 6 - Detailed Timings Data Block"; break;
 		// 0x14 .. 0x7e RESERVED for Additional VESA-defined Data Blocks
 		// DisplayID 2.0
-	case 0x20: data_block_o("Product Identification Data Block (" + utohex(tag) + ")", false, false); ouinum = 0; break;
+	case 0x20: data_block_o("Product Identification Data Block (" + utohex(tag) + ")", false, false); break;
 		case 0x21: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break;
 		case 0x22: data_block = "Video Timing Modes Type 7 - Detailed Timings Data Block"; break;
 		case 0x23: data_block = "Video Timing Modes Type 8 - Enumerated Timing Codes Data Block"; break;
@@ -1743,16 +1739,15 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 	if (dooutputname && data_block.length())
 		printf("  %s:\n", data_block.c_str());
 
-	if (version >= 0x20 && (tag < 0x20 || tag == 0x7f))
+	if (version >= 0x20 && tag_version == 1)
 		fail("Use of DisplayID v1.x tag for DisplayID v%u.%u.\n",
 			 version >> 4, version & 0xf);
-	if (version < 0x20 && tag >= 0x20 && tag <= 0x7e)
+	if (version < 0x20 && tag_version == 2)
 		fail("Use of DisplayID v2.0 tag for DisplayID v%u.%u.\n",
 			 version >> 4, version & 0xf);
 
 	unsigned block_rev = x[1] & 0x07;
 
-	tag |= ouinum;
 		switch (tag) {
 	case 0x00: parse_displayid_product_id(x); break;
 	case 0x01: parse_displayid_parameters(x); break;
@@ -1875,7 +1870,7 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 		}
 	case 0x7e|kOUI_VESA: parse_displayid_vesa(x); break;
 	case 0x81: parse_displayid_cta_data_block(x); break;
-	default: hex_block("    ", x + 3 + (ouinum ? 3 : 0), len - (ouinum ? 3 : 0)); break;
+	default: hex_block("    ", x + 3 + (hasoui ? 3 : 0), (len > (hasoui ? 3 : 0)) ? len - (hasoui ? 3 : 0) : 0); break;
 		}
 
 		if ((tag == 0x00 || tag == 0x20) &&
Signature · 1 line
2.24.3 (Apple Git-128)
author
#27 lore raw

PATCH v2 26/29 edid-decode: remove extra vendor field

In reply to joevt

- Since we use the data_block_oui function to get the vendor for the Production Identification Data Block, we don't need to output the vendor OUI or ID separately. data_block_oui is better because it will get the OUI's name (if it is known) and it verifies that the ID is valid ASCII (don't want to print weird control characters).

---
 parse-displayid-block.cpp | 6 ------
 1 file changed, 6 deletions(-)
parse-displayid-block.cpp +0 -6
index a38c90e..ba2c15e 100644
@@ -81,12 +81,6 @@ void edid_state::parse_displayid_product_id(const unsigned char *x)
 	check_displayid_datablock_revision(x[1]);
 
 	dispid.has_product_identification = true;
-	if (dispid.version >= 0x20) {
-		unsigned oui = (x[3] << 16) | (x[4] << 8) | x[5];
-		printf("    Vendor OUI %s\n", ouitohex(oui).c_str());
-	} else {
-		printf("    Vendor ID: %c%c%c\n", x[3], x[4], x[5]);
-	}
 	printf("    Product Code: %u\n", x[6] | (x[7] << 8));
 	unsigned sn = x[8] | (x[9] << 8) | (x[10] << 16) | (x[11] << 24);
 	if (sn) {
Signature · 1 line
2.24.3 (Apple Git-128)
author
#28 lore raw

PATCH v2 27/29 edid-decode: re-add one EDID

In reply to joevt

- This one somehow got truncated.

---
 data/vizio-m60c3-hdmi-onkyo-txnr555 | Bin 0 -> 256 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
data/vizio-m60c3-hdmi-onkyo-txnr555 binary +0 -0
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..93369abc45fd4348188e5b3a3f285f38c27fe3b4 100644
GIT binary patch
Signature · 1 line
2.24.3 (Apple Git-128)
author
#29 lore raw

PATCH v2 28/29 edid-decode: add interesting EDID

In reply to joevt

It contains "Audio information is present, but bit ..." message and "CTA-861 DisplayID Data Block" data block.

Looks like nested blocks (CTA blocks in a DisplayID block) need more indenting. Currently, indents are mostly hardcoded so they aren't suited for nested blocks. Maybe we could add indenting using the following:
- Store current indent level in edid_state.
- Replace printf with printi which will print spaces for current indent level.
- For changing indent, you could use indent++ to indent and indent-- to outdent.
- Maybe some C++ tricks can be used to automatically outdent:
- Call a function that returns an object that has a constructor that increments indent.
- Then the destructor can automatically decrement indent when the scope of the object ends.
- We could also add a custom indenting string (currently it's two spaces per indent, but we could make it 4 or 8 spaces, or we could make it a tab).

---
 data/apple-imac-retina-4k-21.5-inch-late-2015 | Bin 0 -> 256 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 data/apple-imac-retina-4k-21.5-inch-late-2015
data/apple-imac-retina-4k-21.5-inch-late-2015 new file binary +0 -0
new file mode 100644
index 0000000000000000000000000000000000000000..0a28a06cf6b2fb0332c64a21a476c3919173c26d
GIT binary patch
Signature · 1 line
2.24.3 (Apple Git-128)
author
#30 lore raw

PATCH v2 29/29 edid-decode: fix indents

In reply to joevt

The indenting was messed up during rebase.

---
 parse-displayid-block.cpp | 230 +++++++++++++++++++-------------------
 1 file changed, 115 insertions(+), 115 deletions(-)
parse-displayid-block.cpp +115 -115
index ba2c15e..3fa0759 100644
@@ -1655,80 +1655,80 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 	unsigned len = (length < 3) ? 0 : x[2];
 	bool hasoui = false;
 
-		switch (tag) {
-		// DisplayID 1.3:
+	switch (tag) {
+	// DisplayID 1.3:
 	case 0x00: data_block_o("Product Identification Data Block (" + utohex(tag) + ")", true, false); break;
-		case 0x01: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break;
-		case 0x02: data_block = "Color Characteristics Data Block"; break;
-		case 0x03: data_block = "Video Timing Modes Type 1 - Detailed Timings Data Block"; break;
-		case 0x04: data_block = "Video Timing Modes Type 2 - Detailed Timings Data Block"; break;
-		case 0x05: data_block = "Video Timing Modes Type 3 - Short Timings Data Block"; break;
-		case 0x06: data_block = "Video Timing Modes Type 4 - DMT Timings Data Block"; break;
-		case 0x07: data_block = "Supported Timing Modes Type 1 - VESA DMT Timings Data Block"; break;
-		case 0x08: data_block = "Supported Timing Modes Type 2 - CTA-861 Timings Data Block"; break;
-		case 0x09: data_block = "Video Timing Range Data Block"; break;
-		case 0x0a: data_block = "Product Serial Number Data Block"; break;
-		case 0x0b: data_block = "GP ASCII String Data Block"; break;
-		case 0x0c: data_block = "Display Device Data Data Block"; break;
-		case 0x0d: data_block = "Interface Power Sequencing Data Block"; break;
-		case 0x0e: data_block = "Transfer Characteristics Data Block"; break;
-		case 0x0f: data_block = "Display Interface Data Block"; break;
-		case 0x10: data_block = "Stereo Display Interface Data Block (" + utohex(tag) + ")"; break;
-		case 0x11: data_block = "Video Timing Modes Type 5 - Short Timings Data Block"; break;
-		case 0x12: data_block = "Tiled Display Topology Data Block (" + utohex(tag) + ")"; break;
-		case 0x13: data_block = "Video Timing Modes Type 6 - Detailed Timings Data Block"; break;
-		// 0x14 .. 0x7e RESERVED for Additional VESA-defined Data Blocks
-		// DisplayID 2.0
+	case 0x01: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break;
+	case 0x02: data_block = "Color Characteristics Data Block"; break;
+	case 0x03: data_block = "Video Timing Modes Type 1 - Detailed Timings Data Block"; break;
+	case 0x04: data_block = "Video Timing Modes Type 2 - Detailed Timings Data Block"; break;
+	case 0x05: data_block = "Video Timing Modes Type 3 - Short Timings Data Block"; break;
+	case 0x06: data_block = "Video Timing Modes Type 4 - DMT Timings Data Block"; break;
+	case 0x07: data_block = "Supported Timing Modes Type 1 - VESA DMT Timings Data Block"; break;
+	case 0x08: data_block = "Supported Timing Modes Type 2 - CTA-861 Timings Data Block"; break;
+	case 0x09: data_block = "Video Timing Range Data Block"; break;
+	case 0x0a: data_block = "Product Serial Number Data Block"; break;
+	case 0x0b: data_block = "GP ASCII String Data Block"; break;
+	case 0x0c: data_block = "Display Device Data Data Block"; break;
+	case 0x0d: data_block = "Interface Power Sequencing Data Block"; break;
+	case 0x0e: data_block = "Transfer Characteristics Data Block"; break;
+	case 0x0f: data_block = "Display Interface Data Block"; break;
+	case 0x10: data_block = "Stereo Display Interface Data Block (" + utohex(tag) + ")"; break;
+	case 0x11: data_block = "Video Timing Modes Type 5 - Short Timings Data Block"; break;
+	case 0x12: data_block = "Tiled Display Topology Data Block (" + utohex(tag) + ")"; break;
+	case 0x13: data_block = "Video Timing Modes Type 6 - Detailed Timings Data Block"; break;
+	// 0x14 .. 0x7e RESERVED for Additional VESA-defined Data Blocks
+	// DisplayID 2.0
 	case 0x20: data_block_o("Product Identification Data Block (" + utohex(tag) + ")", false, false); break;
-		case 0x21: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break;
-		case 0x22: data_block = "Video Timing Modes Type 7 - Detailed Timings Data Block"; break;
-		case 0x23: data_block = "Video Timing Modes Type 8 - Enumerated Timing Codes Data Block"; break;
-		case 0x24: data_block = "Video Timing Modes Type 9 - Formula-based Timings Data Block"; break;
-		case 0x25: data_block = "Dynamic Video Timing Range Limits Data Block"; break;
-		case 0x26: data_block = "Display Interface Features Data Block"; break;
-		case 0x27: data_block = "Stereo Display Interface Data Block (" + utohex(tag) + ")"; break;
-		case 0x28: data_block = "Tiled Display Topology Data Block (" + utohex(tag) + ")"; break;
-		case 0x29: data_block = "ContainerID Data Block"; break;
-		case 0x2b: data_block = "Adaptive Sync Data Block"; break;
-		case 0x32: data_block = "Video Timing Modes Type 10 - Formula-based Timings Data Block"; break;
-		// 0x2a .. 0x7d RESERVED for Additional VESA-defined Data Blocks
+	case 0x21: data_block = "Display Parameters Data Block (" + utohex(tag) + ")"; break;
+	case 0x22: data_block = "Video Timing Modes Type 7 - Detailed Timings Data Block"; break;
+	case 0x23: data_block = "Video Timing Modes Type 8 - Enumerated Timing Codes Data Block"; break;
+	case 0x24: data_block = "Video Timing Modes Type 9 - Formula-based Timings Data Block"; break;
+	case 0x25: data_block = "Dynamic Video Timing Range Limits Data Block"; break;
+	case 0x26: data_block = "Display Interface Features Data Block"; break;
+	case 0x27: data_block = "Stereo Display Interface Data Block (" + utohex(tag) + ")"; break;
+	case 0x28: data_block = "Tiled Display Topology Data Block (" + utohex(tag) + ")"; break;
+	case 0x29: data_block = "ContainerID Data Block"; break;
+	case 0x2b: data_block = "Adaptive Sync Data Block"; break;
+	case 0x32: data_block = "Video Timing Modes Type 10 - Formula-based Timings Data Block"; break;
+	// 0x2a .. 0x7d RESERVED for Additional VESA-defined Data Blocks
 	case 0x7e: data_block_o("Vendor-Specific Data Block (" + utohex(tag) + ")", false, true); break; // DisplayID 2.0
 	case 0x7f: data_block_o("Vendor-Specific Data Block (" + utohex(tag) + ")", true, false); break; // DisplayID 1.3
-		// 0x80 RESERVED
+	// 0x80 RESERVED
 	case 0x81: data_block = "CTA-861 DisplayID Data Block"; break;
-		// 0x82 .. 0xff RESERVED
-		default:   data_block = "Unknown DisplayID Data Block (" + utohex(tag) + ")"; break;
-		}
+	// 0x82 .. 0xff RESERVED
+	default:   data_block = "Unknown DisplayID Data Block (" + utohex(tag) + ")"; break;
+	}
 
-		if (length < 3) {
+	if (length < 3) {
 		// Report a problem when the remaining bytes are not 0.
 		data_block.clear(); // Probably not a Data Block so clear this.
 		if (tag || (length > 1 && x[1])) {
 			printf("  Filler:\n");
 			fail("Not enough bytes remain (%d) for a DisplayID data block and the DisplayID filler is non-0.\n", length);
 			hex_block("    ", x, length);
-			}
-		return length;
 		}
+		return length;
+	}
 
-		if (length < len + 3) {
+	if (length < len + 3) {
 		data_block.clear(); // Probably not a Data Block so clear this.
 		printf("  Filler:\n");
-			fail("The length of this DisplayID data block (%d) exceeds the number of bytes remaining (%d).\n", len + 3, length);
+		fail("The length of this DisplayID data block (%d) exceeds the number of bytes remaining (%d).\n", len + 3, length);
 		hex_block("    ", x, length);
 		return length;
-		}
+	}
 
-		if (!tag && !len) {
-			// A Product Identification Data Block with no payload bytes is not valid - assume this is the end.
+	if (!tag && !len) {
+		// A Product Identification Data Block with no payload bytes is not valid - assume this is the end.
 		data_block.clear(); // Probably not a Product Identification Data Block so clear this.
 		if (!memchk(x, length)) {
 			printf("  Filler:\n");
-				fail("Non-0 filler bytes in the DisplayID block.\n");
+			fail("Non-0 filler bytes in the DisplayID block.\n");
 			hex_block("    ", x, length);
-			}
-		return length;
 		}
+		return length;
+	}
 
 	if (dooutputname && data_block.length())
 		printf("  %s:\n", data_block.c_str());
@@ -1742,135 +1742,135 @@ unsigned edid_state::displayid_block(const unsigned version, const unsigned char
 
 	unsigned block_rev = x[1] & 0x07;
 
-		switch (tag) {
+	switch (tag) {
 	case 0x00: parse_displayid_product_id(x); break;
 	case 0x01: parse_displayid_parameters(x); break;
 	case 0x02: parse_displayid_color_characteristics(x); break;
-		case 0x03:
+	case 0x03:
 		   check_displayid_datablock_revision(x[1], 0, block_rev & 1);
-			   for (i = 0; i < len / 20; i++)
+		   for (i = 0; i < len / 20; i++)
 			   parse_displayid_type_1_7_timing(&x[3 + (i * 20)], false, block_rev);
-			   break;
-		case 0x04:
+		   break;
+	case 0x04:
 		   check_displayid_datablock_revision(x[1]);
-			   for (i = 0; i < len / 11; i++)
+		   for (i = 0; i < len / 11; i++)
 			   parse_displayid_type_2_timing(&x[3 + (i * 11)]);
-			   break;
-		case 0x05:
+		   break;
+	case 0x05:
 		   check_displayid_datablock_revision(x[1], 0, block_rev & 1);
-			   for (i = 0; i < len / 3; i++)
+		   for (i = 0; i < len / 3; i++)
 			   parse_displayid_type_3_timing(&x[3 + (i * 3)]);
-			   break;
-		case 0x06:
+		   break;
+	case 0x06:
 		   check_displayid_datablock_revision(x[1], 0xc0, 1);
-			   for (i = 0; i < len; i++)
+		   for (i = 0; i < len; i++)
 			   parse_displayid_type_4_8_timing((x[1] & 0xc0) >> 6, x[3 + i]);
-			   break;
-		case 0x07:
+		   break;
+	case 0x07:
 		   check_displayid_datablock_revision(x[1]);
-			   for (i = 0; i < min(len, 10) * 8; i++)
+		   for (i = 0; i < min(len, 10) * 8; i++)
 			   if (x[3 + i / 8] & (1 << (i % 8))) {
-					   char type[16];
-					   sprintf(type, "DMT 0x%02x", i + 1);
-					   print_timings("    ", find_dmt_id(i + 1), type);
-				   }
-			   break;
-		case 0x08:
+				   char type[16];
+				   sprintf(type, "DMT 0x%02x", i + 1);
+				   print_timings("    ", find_dmt_id(i + 1), type);
+			   }
+		   break;
+	case 0x08:
 		   check_displayid_datablock_revision(x[1]);
-			   for (i = 0; i < min(len, 8) * 8; i++)
+		   for (i = 0; i < min(len, 8) * 8; i++)
 			   if (x[3 + i / 8] & (1 << (i % 8))) {
-					   char type[16];
-					   sprintf(type, "VIC %3u", i + 1);
-					   print_timings("    ", find_vic_id(i + 1), type);
-				   }
-			   break;
+				   char type[16];
+				   sprintf(type, "VIC %3u", i + 1);
+				   print_timings("    ", find_vic_id(i + 1), type);
+			   }
+		   break;
 	case 0x09: parse_displayid_video_timing_range_limits(x); break;
-		case 0x0a:
+	case 0x0a:
 	case 0x0b: parse_displayid_string(x); break;
 	case 0x0c: parse_displayid_display_device(x); break;
 	case 0x0d: parse_displayid_intf_power_sequencing(x); break;
 	case 0x0e: parse_displayid_transfer_characteristics(x); break;
 	case 0x0f: parse_displayid_display_intf(x); break;
 	case 0x10: parse_displayid_stereo_display_intf(x); break;
-		case 0x11:
+	case 0x11:
 		   check_displayid_datablock_revision(x[1]);
-			   for (i = 0; i < len / 7; i++)
+		   for (i = 0; i < len / 7; i++)
 			   parse_displayid_type_5_timing(&x[3 + (i * 7)]);
-			   break;
+		   break;
 	case 0x12: parse_displayid_tiled_display_topology(x, false); break;
-		case 0x13:
+	case 0x13:
 		   check_displayid_datablock_revision(x[1]);
 		   for (i = 0; i < len; i += (x[3 + i + 2] & 0x40) ? 17 : 14)
 			   parse_displayid_type_6_timing(&x[3 + i]);
-			   break;
+		   break;
 	case 0x20: parse_displayid_product_id(x); break;
-		case 0x21:
-			   if (block_rev >= 1)
+	case 0x21:
+		   if (block_rev >= 1)
 			   check_displayid_datablock_revision(x[1], 0x80, 1);
-			   else
+		   else
 			   check_displayid_datablock_revision(x[1], 0x80, 0);
 		   parse_displayid_parameters_v2(x, block_rev);
-			   break;
-		case 0x22: {
-			   unsigned sz = 20;
+		   break;
+	case 0x22: {
+		   unsigned sz = 20;
 
-			   if (block_rev >= 2)
+		   if (block_rev >= 2)
 			   check_displayid_datablock_revision(x[1], 0x08, 2);
-			   else if (block_rev == 1)
+		   else if (block_rev == 1)
 			   check_displayid_datablock_revision(x[1], 0x08, 1);
-			   else
+		   else
 			   check_displayid_datablock_revision(x[1]);
 		   sz += (x[1] & 0x70) >> 4;
 		   if (block_rev >= 1 && (x[1] & 0x08))
-				   printf("    These timings support DSC pass-through\n");
-			   for (i = 0; i < len / sz; i++)
+			   printf("    These timings support DSC pass-through\n");
+		   for (i = 0; i < len / sz; i++)
 			   parse_displayid_type_1_7_timing(&x[3 + i * sz], true, block_rev);
-			   break;
-		}
-		case 0x23:
-			   if (block_rev)
+		   break;
+	}
+	case 0x23:
+		   if (block_rev)
 			   check_displayid_datablock_revision(x[1], 0xe8, 1);
-			   else
+		   else
 			   check_displayid_datablock_revision(x[1], 0xc8);
 		   if (x[1] & 0x08) {
-				   for (i = 0; i < len / 2; i++)
+			   for (i = 0; i < len / 2; i++)
 				   parse_displayid_type_4_8_timing((x[1] & 0xc0) >> 6,
 								   x[3 + i * 2] |
 								   (x[4 + i * 2] << 8));
-			   } else {
-				   for (i = 0; i < len; i++)
+		   } else {
+			   for (i = 0; i < len; i++)
 				   parse_displayid_type_4_8_timing((x[1] & 0xc0) >> 6,
 								   x[3 + i]);
-			   }
-			   break;
-		case 0x24:
+		   }
+		   break;
+	case 0x24:
 		   check_displayid_datablock_revision(x[1]);
-			   for (i = 0; i < len / 6; i++)
+		   for (i = 0; i < len / 6; i++)
 			   parse_displayid_type_9_timing(&x[3 + i * 6]);
-			   break;
+		   break;
 	case 0x25: parse_displayid_dynamic_video_timings_range_limits(x); break;
 	case 0x26: parse_displayid_interface_features(x); break;
 	case 0x27: parse_displayid_stereo_display_intf(x); break;
 	case 0x28: parse_displayid_tiled_display_topology(x, true); break;
 	case 0x29: parse_displayid_ContainerID(x); break;
 	case 0x2b: parse_displayid_adaptive_sync(x); break;
-		case 0x32: {
+	case 0x32: {
 		   unsigned sz = 6 + ((x[1] & 0x70) >> 4);
 
 		   check_displayid_datablock_revision(x[1], 0x70);
-			   for (i = 0; i < len / sz; i++)
+		   for (i = 0; i < len / sz; i++)
 			   parse_displayid_type_10_timing(&x[3 + i * sz], sz);
-			   break;
-		}
+		   break;
+	}
 	case 0x7e|kOUI_VESA: parse_displayid_vesa(x); break;
 	case 0x81: parse_displayid_cta_data_block(x); break;
 	default: hex_block("    ", x + 3 + (hasoui ? 3 : 0), (len > (hasoui ? 3 : 0)) ? len - (hasoui ? 3 : 0) : 0); break;
-		}
+	}
 
-		if ((tag == 0x00 || tag == 0x20) &&
+	if ((tag == 0x00 || tag == 0x20) &&
 		(!dispid.is_base_block || dispid.block_number > 0))
-			fail("%s is required to be the first DisplayID Data Block.\n",
-			     data_block.c_str());
+		fail("%s is required to be the first DisplayID Data Block.\n",
+		     data_block.c_str());
 
 	dispid.block_number++;
 	return len + 3;
Signature · 1 line
2.24.3 (Apple Git-128)