From patchwork Fri Mar 4 12:49:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shashank Sharma X-Patchwork-Id: 12769043 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18067C4332F for ; Fri, 4 Mar 2022 12:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232847AbiCDMvS (ORCPT ); Fri, 4 Mar 2022 07:51:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232332AbiCDMvM (ORCPT ); Fri, 4 Mar 2022 07:51:12 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FAFB1B1DEB for ; Fri, 4 Mar 2022 04:50:23 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id kt27so17385601ejb.0 for ; Fri, 04 Mar 2022 04:50:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HrixOrzT5DDaI61xAtG2tbo7EVFW4Xf4sUGZ9bCTAu8=; b=faInEy+YTi6Z3f1Nc0rs4abixNyACcuL+A6e3ZfKw6v9pkVFvc2DMq6itf48j/TgOo DmMUecFWrrqXg1BUcSJfJ5Oex51NYgEjkIsPVHGs5F4Tjy2MziMDj136h19IZ/wpLmim uMD45Kup8vcpHgfwmNpefTuQbidWRU9ewZIJfPsKLekd33KBtUiYFV7tDMJBUqjUS0/Y UrFeA6u9OwvVqiYG4gZHnpOCUNkEV3eottbNABfqgDzc2fq3oTR2eKJK3EmJiBx5+cbj b3VC2B1h7jSSdKawmyg2bT56o16Y8kA03JaBfKeu0mv5yNhZJ0Qlp86lvJC4oqUykFg7 bJcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=HrixOrzT5DDaI61xAtG2tbo7EVFW4Xf4sUGZ9bCTAu8=; b=M+dfjd92N+N6nbKVFO0vXmmni51qDq4tV3BLKWvdAX8cnHc6PhZcRTltJ9KUXa+/it P4PEZic4MLjiZcYq159HO5WbUpx5j91EqUP8NOQi4B/ipmVxc5dE0ULWhESnONqPFT+m rhURxWkGT3AfRM5e84mgFBJ11KN3GdEKPxjschTBgc62cJfNkJWPWrYBvKiEljj2kUCr mlHkKemE5sgZzdy5ZU4QBnADr7s7BtEtIWTI6Bf8xd0ur+AjYpjRotx+1hLEZnl0X3/1 KV2hPAkl1Lm+WQRP+G95hR5GCFucV+pAvGd9Dd6aqFaOW4t+6Jds404DV3qtxIeQu+5f 7YcA== X-Gm-Message-State: AOAM5309XYhpf1+QLM7FK/4gY3KPNSuST2W8hNslhsIRsJPi8wX0VjFn BGWld8IDoM40h1LyQWdGfiofPTJPlUcIdMvcwz0= X-Google-Smtp-Source: ABdhPJzwbZrldhQYchpBHFXOF4RMO2mprPJTeTxenWNPhN55VEXhqGm2N+aSD+G8AbJzue9mrKzIZg== X-Received: by 2002:a17:907:728b:b0:6da:97db:b66d with SMTP id dt11-20020a170907728b00b006da97dbb66dmr5115886ejc.636.1646398221743; Fri, 04 Mar 2022 04:50:21 -0800 (PST) Received: from shashanks-buildpc.. ([2a02:8109:b540:9438:542e:fe2:e980:5b1]) by smtp.gmail.com with ESMTPSA id e5-20020a170906374500b006d5825520a7sm1736359ejc.71.2022.03.04.04.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 04:50:21 -0800 (PST) From: Shashank Sharma To: linux-media@vger.kernel.org Cc: hverkuil-cisco@xs4all.nl, Shashank Sharma , Pekka Paalanen , Jani Nikula , Shashank Sharma Subject: [PATCH 1/3] edid-decode: Introduce libedid-decode wrapper Date: Fri, 4 Mar 2022 13:49:59 +0100 Message-Id: <20220304125001.1732057-1-contactshashanksharma@gmail.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Shashank Sharma This patch does some small changes to make the core logic of edid-decode tool available to a shared library wrapper. With these changes, the EDID's 'state' variable will be avialble to another process via some library API calls. Cc: Pekka Paalanen Cc: Jani Nikula Signed-off-by: Shashank Sharma --- Makefile | 22 +++++++++++++++++++++- edid-decode.cpp | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1843700..ebf3370 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,20 @@ ifeq ($(OS),Windows_NT) bindir ?= /usr/bin mandir ?= /usr/share/man + libdir ?= /usr/lib + includedir ?= /usr/include else UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) bindir ?= /usr/local/sbin mandir ?= /usr/local/share/man + libdir ?= /usr/local/lib + includedir ?= /usr/include else bindir ?= /usr/bin mandir ?= /usr/share/man + libdir ?= /usr/lib + includedir ?= /usr/include endif endif @@ -19,6 +25,11 @@ SOURCES = edid-decode.cpp parse-base-block.cpp parse-cta-block.cpp \ parse-di-ext-block.cpp parse-vtb-ext-block.cpp calc-gtf-cvt.cpp WARN_FLAGS = -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter -Wimplicit-fallthrough +LIB_NAME = libedid-decode.so +LIB_FLAGS = -fPIC +LIBLINK_FLAGS = -shared +LIB_SOURCES = libedid-decode-api.cpp + all: edid-decode sha = -DSHA=$(shell if test -d .git ; then git rev-parse --short=12 HEAD ; fi) @@ -30,11 +41,20 @@ edid-decode: $(SOURCES) edid-decode.h oui.h Makefile edid-decode.js: $(SOURCES) edid-decode.h oui.h Makefile $(EMXX) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(WARN_FLAGS) $(sha) $(date) -s EXPORTED_FUNCTIONS='["_parse_edid"]' -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' -o $@ $(SOURCES) -lm +libedid-decode: $(SOURCES) edid-decode.h oui.h Makefile + $(CXX) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(WARN_FLAGS) -g $(LIB_FLAGS) $(sha) $(date) $(LIBLINK_FLAGS) -o $(LIB_NAME) $(LIB_SOURCES) $(SOURCES) -lm + clean: - rm -f edid-decode + rm -f edid-decode libedid-decode.so install: mkdir -p $(DESTDIR)$(bindir) install -m 0755 edid-decode $(DESTDIR)$(bindir) mkdir -p $(DESTDIR)$(mandir)/man1 install -m 0644 edid-decode.1 $(DESTDIR)$(mandir)/man1 + +install-lib: + mkdir -p $(DESTDIR)$(libdir) + mkdir -p $(DESTDIR)$(includedir) + install -m 0755 libedid-decode.so $(DESTDIR)$(libdir) + install -m 0644 libedid-decode-api.h $(DESTDIR)$(includedir) diff --git a/edid-decode.cpp b/edid-decode.cpp index 4a90aba..babff4a 100644 --- a/edid-decode.cpp +++ b/edid-decode.cpp @@ -21,7 +21,7 @@ #define STR(x) #x #define STRING(x) STR(x) -static edid_state state; +edid_state state; static unsigned char edid[EDID_PAGE_SIZE * EDID_MAX_BLOCKS]; static bool odd_hex_digits; @@ -1012,6 +1012,19 @@ static bool extract_edid(int fd, FILE *error) state.edid_size = edid_data.size(); return true; } +struct edid_state *extract_edid_state(int fd, FILE *error) +{ + bool ret; + + ret = extract_edid(fd, error); + if (ret) { + /* update the number of blocks */ + state.num_blocks = state.edid_size / EDID_PAGE_SIZE; + return &state; + } + + return NULL; +} static unsigned char crc_calc(const unsigned char *b) { From patchwork Fri Mar 4 12:50:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shashank Sharma X-Patchwork-Id: 12769044 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B50C4C433FE for ; Fri, 4 Mar 2022 12:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233283AbiCDMvR (ORCPT ); Fri, 4 Mar 2022 07:51:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234115AbiCDMvO (ORCPT ); Fri, 4 Mar 2022 07:51:14 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A52611B4039 for ; Fri, 4 Mar 2022 04:50:25 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id dr20so17256585ejc.6 for ; Fri, 04 Mar 2022 04:50:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cfVrQaTuSRlspnqFAOyIP+LzK9x+KLsv1yujUpM5yK4=; b=XzbUhhZwoGMeAuarUiQlVNg7qtcsd95BHUen2GDfFfPoiAGCOoS/+rYVB8kSBpb+Td +1hp/MJXX4IAKRxPSxSMcjapfHmyl015DBq7Q2QiamD9SAs/BRa+iY0zwUWFP3VhL0xq lXrbpA8bOLvqLYRfyLc7b/jxoKh+d9fKQQ+UYbSSYbcdDNhFYThgXI1Vhpyf5/vPyCFY w3iG2AwSKE+P051KpvZJiHkaJqEONnCQN4edzIjU+Xr/4Ixab8bs3yXdbOhuj+Vx4b+M 5pElJ3T/DVbJHisDLuCF5iujfVR/5j8pybMLrM/gSthaphqWwk4+5aGr8VvIuL82nyvx sfuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cfVrQaTuSRlspnqFAOyIP+LzK9x+KLsv1yujUpM5yK4=; b=uQRAjTAa9QATJu92kx8dJsZm2WgIKbrr2MvXGPsTA8bpbfVHemslMnAArqxyGXmOh/ oDjxgpdQOrOF183sQ6k2EjpmbCMDOIDsBVduHDzAP9C3Lm7/e4dH10IXGbNYA+G9XieU ocQMDBB1Ng6/qIQq5la/NlgG1Xf9gOYWLT5HCSMDt/FrUoVgyM6PAP3NLQc7R64AxhgW mNENXNiCNM9Inauk54ufiJYpkq1rwBUeLfpqQAIUolXHDgO3lrn1X3qeEC0mP8UL5y54 ysmmaTKKyC+m7qx8bQ6zgHlqshPbEl6Q1TXvkaCiZZP9LAtx7tMQdgTelzVkglEaxVtM PU1g== X-Gm-Message-State: AOAM530CYuN1wtBVGsrvTKMf60w7Lsg0chYlMGL5qW7vkp5xWhb4x+/M fVBro3HQo1tB6hd855IolW9UtCXOZPQXuWSzCQA= X-Google-Smtp-Source: ABdhPJxVH78yoL6OoghqiXAxPgz4zkBKXpbbaYML+qe2spY4AYFgSnbDBdpkaFDRFC0taF7ZKt6s5A== X-Received: by 2002:a17:906:a148:b0:6cd:50c7:8d4d with SMTP id bu8-20020a170906a14800b006cd50c78d4dmr30680350ejb.641.1646398223148; Fri, 04 Mar 2022 04:50:23 -0800 (PST) Received: from shashanks-buildpc.. ([2a02:8109:b540:9438:542e:fe2:e980:5b1]) by smtp.gmail.com with ESMTPSA id e5-20020a170906374500b006d5825520a7sm1736359ejc.71.2022.03.04.04.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 04:50:22 -0800 (PST) From: Shashank Sharma To: linux-media@vger.kernel.org Cc: hverkuil-cisco@xs4all.nl, Shashank Sharma , Pekka Paalanen , Jani Nikula , Shashank Sharma Subject: [PATCH 2/3] edid-decode: Introduce libedid-decode APIs Date: Fri, 4 Mar 2022 13:50:00 +0100 Message-Id: <20220304125001.1732057-2-contactshashanksharma@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220304125001.1732057-1-contactshashanksharma@gmail.com> References: <20220304125001.1732057-1-contactshashanksharma@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Shashank Sharma 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 Cc: Jani Nikula Signed-off-by: Shashank Sharma --- 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 + */ +#include +#include +#include +#include +#include +#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 + */ + +#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 From patchwork Fri Mar 4 12:50:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shashank Sharma X-Patchwork-Id: 12769042 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14848C433F5 for ; Fri, 4 Mar 2022 12:50:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232756AbiCDMvQ (ORCPT ); Fri, 4 Mar 2022 07:51:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbiCDMvO (ORCPT ); Fri, 4 Mar 2022 07:51:14 -0500 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8F4B1B1DF8 for ; Fri, 4 Mar 2022 04:50:25 -0800 (PST) Received: by mail-ed1-x529.google.com with SMTP id y11so10107717eda.12 for ; Fri, 04 Mar 2022 04:50:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1JGUzzrE4T+E8JakKE2PaZYv8Zw6QAorMEDh7v6Jzsg=; b=PYEzKQ8ajnNFS9Io1BRwYTtBJF7svjmgISbaJQLLK6c6QHedZg5DmlqvApX1Mf3yN0 icFJmHcKhkaN8x9vm31foidKyZX4bO2wH0/TNa0i+n3OlocOSbS2PLSdVFOejs9PQ7lV Ej44M4vcE35kLdChkH42d0eHxz3Efh2L5NTPgrc/e5pE8MlwjBiyyv4ErwxQ6zS+KkWp 21R5hgearP1oGkOr9yRq7CievCdw/jTsDiPXvD2ovfLeGTBCqMscHm4z5N4c27amKYcp BEMjCCWdsk+zHAr6M10lJ5HwUffHIjT9YcQ5TmmdRuVxbiFA1FJcWT00oyJRGMoCT68u jcHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1JGUzzrE4T+E8JakKE2PaZYv8Zw6QAorMEDh7v6Jzsg=; b=HZcJrF4ttvuYRMiwXvVgZtjEEGhtAWcwEopyN7GSpiFFvwGvxSe8/hTy16Fbn97FcA lSM2JIfJ5KXvIWskA06oEHNh2TjH6JNhRnrRhkHonF2p/cYUZeDB8THlHrq7SqMOY/QI cOWNeG0YR4RiaFt7otv8EHma/tOvR64GADMHXLNcJFnCJvjSKjB3o/veXQCIJxOjVDLL 7RTpjPb/8Rq1rHF9Bw/AwxqDtg+SXGz4S8/I/5Id2FYpU4WKEnFJwe/ymiQRbbla3bgU s5C0C38s6ecdcb3fruPBn2o8Qsh0518QQoWSHPZT6XKj7lFXJquNyMV3BpKspCTqDohT f9iQ== X-Gm-Message-State: AOAM533ki6sDpHxvII2XrKXIjELjzk51Fwr8862pOV11sBiKFdDMiXLc LXvwRqY7X7rgpNZLj7bsC7WC6O2KDPbR48T74/8= X-Google-Smtp-Source: ABdhPJyL8GnyYoXdwEYGJPHxOGZ1WopGk3d17hIQHeqDdvbUh5oR4LHtM4EOo/GzYhzucTfdq7PpXA== X-Received: by 2002:a05:6402:26cc:b0:415:b6f7:bfa with SMTP id x12-20020a05640226cc00b00415b6f70bfamr12921475edd.42.1646398224198; Fri, 04 Mar 2022 04:50:24 -0800 (PST) Received: from shashanks-buildpc.. ([2a02:8109:b540:9438:542e:fe2:e980:5b1]) by smtp.gmail.com with ESMTPSA id e5-20020a170906374500b006d5825520a7sm1736359ejc.71.2022.03.04.04.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 04:50:23 -0800 (PST) From: Shashank Sharma To: linux-media@vger.kernel.org Cc: hverkuil-cisco@xs4all.nl, Shashank Sharma , Pekka Paalanen , Jani Nikula , Shashank Sharma Subject: [PATCH 3/3] edid-decode: Add test utility for libedid-decode Date: Fri, 4 Mar 2022 13:50:01 +0100 Message-Id: <20220304125001.1732057-3-contactshashanksharma@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220304125001.1732057-1-contactshashanksharma@gmail.com> References: <20220304125001.1732057-1-contactshashanksharma@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Shashank Sharma This patch adds a small test utility to show usage of libedid-decode. Cc: Pekka Paalanen Cc: Jani Nikula Signed-off-by: Shashank Sharma --- Makefile | 3 ++ test-lib.cpp | 121 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 test-lib.cpp diff --git a/Makefile b/Makefile index ebf3370..fdd02a0 100644 --- a/Makefile +++ b/Makefile @@ -44,6 +44,9 @@ edid-decode.js: $(SOURCES) edid-decode.h oui.h Makefile libedid-decode: $(SOURCES) edid-decode.h oui.h Makefile $(CXX) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(WARN_FLAGS) -g $(LIB_FLAGS) $(sha) $(date) $(LIBLINK_FLAGS) -o $(LIB_NAME) $(LIB_SOURCES) $(SOURCES) -lm +libedid-test: + $(CXX) -o test-lib test-lib.cpp -g -L$(PWD) -ledid-decode + clean: rm -f edid-decode libedid-decode.so diff --git a/test-lib.cpp b/test-lib.cpp new file mode 100644 index 0000000..9b86adb --- /dev/null +++ b/test-lib.cpp @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: MIT +/* + * Author: Shashank Sharma + */ + +#include +#include +#include "libedid-decode-api.h" +#define EDID_PATH "/sys/class/drm/card0-HDMI-A-1/edid" + +/* This is a sample program to demo the usages of libedid-decode */ + +int main(void) +{ + int ret; + unsigned int u_ret; + struct edid_state *estate; + int w = 0, h = 0; + + estate = libedid_parse_edid(EDID_PATH); + if (!estate) { + printf("Failed to parse EDID\n"); + return -1; + } + + printf("EDID parsing success\n"); + + + ret = libedid_num_blks(estate); + if (ret < 0) { + printf("Error: failed to get num blocks\n"); + return -1; + } + printf("EDID: No of blocks: %d\n", ret); + + ret = libedid_has_cta_blks(estate); + if (ret < 0) { + printf("Error: failed to check CTA block\n"); + return -1; + } + printf("EDID: EDID %s CTA blocks\n", ret ? "has" : "doesn't have"); + + ret = libedid_get_edid_version_minor(estate); + if (ret < 0) { + printf("Error: failed to check EDID version\n"); + return -1; + } + printf("EDID: EDID version: 1.%d\n", ret); + + ret = libedid_get_edid_get_num_dtd(estate); + if (ret < 0) { + printf("Error: failed to check EDID num DTDs\n"); + return -1; + } + printf("EDID: EDID has %d DTDs\n", ret); + + ret = libedid_if_preferred_mode_native(estate); + if (ret < 0) { + printf("Error: failed to check preferred mode\n"); + return -1; + } + printf("EDID: EDID preferred mode is %s\n", ret ? "native" : "not native"); + + ret = libedid_get_max_display_w_h_mm(estate, &w, &h); + if (ret < 0) { + printf("Error: failed to check height/width\n"); + return -1; + } + printf("EDID: EDID hxw is %dx%d\n", w, h); + + ret = libedid_ctablk_has_hdmi(estate); + if (ret < 0) { + printf("Error: failed to check CTA HDMI support\n"); + return -1; + } + printf("EDID: CTA block %s HDMI\n", ret ? "supports" : "doesn't support"); + + ret = libedid_ctablk_has_vcdb(estate); + if (ret < 0) { + printf("Error: failed to check CTA VCDB support\n"); + return -1; + } + printf("EDID: CTA block %s VCDB\n", ret ? "has" : "doesn't have"); + + ret = libedid_ctablk_has_hfvsdb(estate); + if (ret < 0) { + printf("Error: failed to check CTA HF-VSDB support\n"); + return -1; + } + printf("EDID: CTA block %s HF-VSDB\n", ret ? "has" : "doesn't have"); + + u_ret = libedid_get_max_pclk_khz(estate); + if (u_ret == 0) { + printf("Error: failed to get max pixel clock\n"); + return -1; + } + printf("EDID: EDID's max pixel clock is %u KHz\n", u_ret); + + u_ret = libedid_get_max_hfreq_hz(estate); + if (u_ret == 0) { + printf("Error: failed to get max hfreq\n"); + return -1; + } + printf("EDID: EDID's max hfreq is %u Hz\n", u_ret); + + u_ret = libedid_get_max_vfreq_hz(estate); + if (u_ret == 0) { + printf("Error: failed to get max vfreq\n"); + return -1; + } + printf("EDID: EDID's max vfreq is %u Hz\n", u_ret); + + u_ret = libedid_ctablk_supported_hdmi_vics(estate); + if (u_ret == 0) { + printf("Error: failed to get supported VICs\n"); + return -1; + } + printf("EDID: EDID's supported HDMI VICs map is %u\n", u_ret); + + return 0; +} \ No newline at end of file