[PATCH 2/3] edid-decode: Introduce libedid-decode APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Shashank Sharma <shashank.sharma@xxxxxxx>

This patch adds a shared library wrapper for edid-decode
tool. With this library acting as an interface, other Linux
processes would also be able to analyze their EDIDs using the
core logic of edid-decode tools.

This would be particularly useful for applications like a Compositor
who wants to extract the information from an EDID, but doesn't
want to add tons of code to do that.

The initial version of the library APIs are basic and fundamental to
understand the response of the community. The long term plan is to
introduce more capable APIs which can:
- extract color correction and colorspace capabilities of the display
  from their respective CTA-861 blocks.
- extract advance information like static and dynamic HDR capabilities,
  YCBCR 4:2:0 support, color depth and bpc, max pixel clocks for
  HDMI 2.0, 2.1 etc.

This infomration will help a display manager or compositor to take
several decisions related to display states and modeset.

Cc: Pekka Paalanen <ppaalanen@xxxxxxxxx>
Cc: Jani Nikula <jani.nikula@xxxxxxxxx>
Signed-off-by: Shashank Sharma <contactshashanksharma@xxxxxxxxx>
---
 libedid-decode-api.cpp | 174 +++++++++++++++++++++++++++++++++++++++++
 libedid-decode-api.h   |  27 +++++++
 2 files changed, 201 insertions(+)
 create mode 100644 libedid-decode-api.cpp
 create mode 100644 libedid-decode-api.h

diff --git a/libedid-decode-api.cpp b/libedid-decode-api.cpp
new file mode 100644
index 0000000..ce06ba6
--- /dev/null
+++ b/libedid-decode-api.cpp
@@ -0,0 +1,174 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Author: Shashank Sharma <contactshashanksharma@xxxxxxxxx>
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "libedid-decode-api.h"
+
+extern struct edid_state *extract_edid_state(int fd, FILE *error);
+
+/*
+ * This is the init function for the API, a user must call
+ * this function with the EDID file node, to extract the edid
+ * into a state, and then call the rest of the APIs with that state
+ * to extract information about EDID.
+ */
+struct edid_state *libedid_parse_edid(const char *edid_path)
+{
+    int edid_fd, ret;
+    struct edid_state *estate;
+
+    if (!edid_path) {
+        printf("No EDID path provided\n");
+        return NULL;
+    }
+
+    /* Expecting path to a connector's EDID file like /sys/class/drm/..../edid */
+    edid_fd = open(edid_path, O_RDONLY);
+    if (edid_fd < 0) {
+        printf("Failed to open fd at path %s\n", edid_path);
+        return NULL;
+    }
+
+    /* Extract the infomrmation from edid node and prepare it's state */
+    estate = extract_edid_state(edid_fd, stderr);
+    if (!estate) {
+        printf("Failed to extract EDID\n");
+        return NULL;
+    }
+    printf("EDID extracted\n");
+
+    /* Now parse edid blocks */
+    ret = estate->parse_edid();
+    if (ret < 0) {
+        printf("Error parsing edid, err=%d \n", ret);
+        estate = NULL;
+    }
+
+    close(edid_fd);
+    return estate;
+}
+
+int libedid_num_blks(struct edid_state *estate)
+{
+    if (estate)
+        return estate->num_blocks;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+int libedid_has_cta_blks(struct edid_state *estate)
+{
+    if (estate)
+        return estate->has_cta;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+unsigned int libedid_get_max_hfreq_hz(struct edid_state *estate)
+{
+    if (estate)
+        return estate->max_hor_freq_hz;
+
+    printf("EDID state not initialized\n");
+    return 0;
+}
+
+unsigned int libedid_get_max_vfreq_hz(struct edid_state *estate)
+{
+    if (estate)
+        return estate->max_vert_freq_hz;
+
+    printf("EDID state not initialized\n");
+    return 0;
+}
+
+unsigned int libedid_get_max_pclk_khz(struct edid_state *estate)
+{
+    if (estate)
+        return estate->max_pixclk_khz;
+
+    printf("EDID state not initialized\n");
+    return 0;
+}
+
+int libedid_get_edid_version_minor(struct edid_state *estate)
+{
+    if (estate)
+        return estate->base.edid_minor;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+int libedid_get_edid_get_num_dtd(struct edid_state *estate)
+{
+    if (estate)
+        return estate->base.dtd_cnt;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+int libedid_if_preferred_mode_native(struct edid_state *estate)
+{
+    if (estate)
+        return estate->base.preferred_is_also_native;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+int libedid_get_max_display_w_h_mm(struct edid_state *estate, int *wmm, int *hmm)
+{
+    if (estate && hmm && wmm) {
+        *hmm = estate->base.max_display_height_mm;
+        *wmm = estate->base.max_display_width_mm;
+        return 0;
+    }
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+int libedid_ctablk_has_hdmi(struct edid_state *estate)
+{
+    if (estate)
+        return estate->cta.has_hdmi;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+int libedid_ctablk_has_vcdb(struct edid_state *estate)
+{
+    if (estate)
+        return estate->cta.has_vcdb;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+int libedid_ctablk_has_hfvsdb(struct edid_state *estate)
+{
+    if (estate)
+        return estate->cta.have_hf_vsdb;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
+
+unsigned int libedid_ctablk_supported_hdmi_vics(struct edid_state *estate)
+{
+    if (estate)
+        return estate->cta.supported_hdmi_vic_codes;
+
+    printf("EDID state not initialized\n");
+    return -1;
+}
\ No newline at end of file
diff --git a/libedid-decode-api.h b/libedid-decode-api.h
new file mode 100644
index 0000000..742b4a4
--- /dev/null
+++ b/libedid-decode-api.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Author: Shashank Sharma <contactshashanksharma@xxxxxxxxx>
+ */
+
+#ifndef __LIBEDID_DECODE_API_H_
+#define __LIBEDID_DECODE_API_H_
+
+#include "edid-decode.h"
+
+struct edid_state *libedid_parse_edid(const char *edid_path);
+int libedid_num_blks(struct edid_state *estate);
+int libedid_has_cta_blks(struct edid_state *estate);
+int libedid_get_edid_version_minor(struct edid_state *estate);
+int libedid_get_edid_get_num_dtd(struct edid_state *estate);
+int libedid_if_preferred_mode_native(struct edid_state *estate);
+int libedid_get_max_display_w_h_mm(struct edid_state *estate, int *wmm, int *hmm);
+int libedid_ctablk_has_hdmi(struct edid_state *estate);
+int libedid_ctablk_has_vcdb(struct edid_state *estate);
+int libedid_ctablk_has_hfvsdb(struct edid_state *estate);
+
+unsigned int libedid_get_max_pclk_khz(struct edid_state *estate);
+unsigned int libedid_get_max_hfreq_hz(struct edid_state *estate);
+unsigned int libedid_get_max_vfreq_hz(struct edid_state *estate);
+unsigned int libedid_ctablk_supported_hdmi_vics(struct edid_state *estate);
+
+#endif
-- 
2.32.0




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux