This is an automatic generated email to let you know that the following patch 
were queued:

Subject: edid-decode: add --ovt, --list-rids and --list-rid-timings
Author:  Hans Verkuil <[email protected]>
Date:    Thu Sep 16 16:53:28 2021 +0200

Add the new --ovt, --list-rids and --list-rid-timings options to
edid-decode.

Signed-off-by: Hans Verkuil <[email protected]>

 edid-decode.1       |  11 +++++
 edid-decode.cpp     | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 edid-decode.h       |   8 ++++
 parse-cta-block.cpp |  91 ++++++++++++++++++++++++++++++++++++++---
 4 files changed, 218 insertions(+), 8 deletions(-)

---

diff --git a/edid-decode.1 b/edid-decode.1
index f298e9529577..a47036578d12 100644
--- a/edid-decode.1
+++ b/edid-decode.1
@@ -328,6 +328,11 @@ The default secondary curve parameters are 40 for 
\fI<c>\fR, 600 for \fI<m>\fR,
 128 for \fI<k>\fR and 20 for \fI<j>\fR.
 These values correspond to the normal curve that GTF uses.
 .TP
+\fB\-\-ovt\fR 
(\fBrid\fR=\fI<rid>\fR|\fBw\fR=\fI<width>\fR,\fBh\fR=\fI<height>\fR),\fBfps\fR=\fI<fps>\fR
+Calculate the OVT timings for the given format.
+Either specify a \fI<rid>\fR or specify \fI<width>\fR and \fI<height>\fR.
+\fI<fps>\fR is frames per second.
+.TP
 \fB\-\-list\-established\-timings\fR
 List all known Established Timings.
 .TP
@@ -339,6 +344,12 @@ List all known VICs.
 .TP
 \fB\-\-list\-hdmi\-vics\fR
 List all known HDMI VICs.
+.TP
+\fB\-\-list\-rids\fR
+List all known CTA-861 RIDs.
+.TP
+\fB\-\-list\-rid\-timings\fR \fI<rid>\fR
+List all timings for the specified \fI<rid>\fR or all known RIDs if 
\fI<rid>\fR is 0.
 
 .PP
 .SH NOTES
diff --git a/edid-decode.cpp b/edid-decode.cpp
index 38560579d10d..b0183b6b8ea1 100644
--- a/edid-decode.cpp
+++ b/edid-decode.cpp
@@ -65,10 +65,13 @@ enum Option {
        OptHDMIVIC,
        OptCVT,
        OptGTF,
+       OptOVT,
        OptListEstTimings,
        OptListDMTs,
        OptListVICs,
        OptListHDMIVICs,
+       OptListRIDTimings,
+       OptListRIDs,
        OptLast = 256
 };
 
@@ -100,10 +103,13 @@ static struct option long_options[] = {
        { "hdmi-vic", required_argument, 0, OptHDMIVIC },
        { "cvt", required_argument, 0, OptCVT },
        { "gtf", required_argument, 0, OptGTF },
+       { "ovt", required_argument, 0, OptOVT },
        { "list-established-timings", no_argument, 0, OptListEstTimings },
        { "list-dmts", no_argument, 0, OptListDMTs },
        { "list-vics", no_argument, 0, OptListVICs },
        { "list-hdmi-vics", no_argument, 0, OptListHDMIVICs },
+       { "list-rid-timings", required_argument, 0, OptListRIDTimings },
+       { "list-rids", no_argument, 0, OptListRIDs },
        { 0, 0, 0, 0 }
 };
 
@@ -175,10 +181,15 @@ static void usage(void)
               "                        If 'secondary' is given, then the 
secondary GTF is used for\n"
               "                        reduced blanking, where <c>, <m>, <k> 
and <j> are parameters\n"
               "                        for the secondary curve.\n"
+              "  --ovt (rid=<rid>|w=<width>,h=<height>),fps=<fps>\n"
+              "                        Calculate the OVT timings for the given 
format.\n"
+              "                        Either specify a RID or explicitly 
specify width and height.\n"
               "  --list-established-timings List all known Established 
Timings.\n"
               "  --list-dmts           List all known DMTs.\n"
               "  --list-vics           List all known VICs.\n"
               "  --list-hdmi-vics      List all known HDMI VICs.\n"
+              "  --list-rids           List all known RIDs.\n"
+              "  --list-rid-timings <rid> List all timings for RID <rid> or 
all known RIDs if <rid> is 0.\n"
               "  -h, --help            Display this help message.\n");
 }
 
@@ -1823,11 +1834,101 @@ static void show_gtf(gtf_parsed_data &data)
        state.print_timings("", &t, "GTF", "", true, false);
 }
 
+enum ovt_opts {
+       OVT_RID,
+       OVT_WIDTH,
+       OVT_HEIGHT,
+       OVT_FPS,
+};
+
+static int parse_ovt_subopt(char **subopt_str, unsigned *value)
+{
+       int opt;
+       char *opt_str;
+
+       static const char * const subopt_list[] = {
+               "rid",
+               "w",
+               "h",
+               "fps",
+               nullptr
+       };
+
+       opt = getsubopt(subopt_str, (char* const*) subopt_list, &opt_str);
+
+       if (opt == -1) {
+               fprintf(stderr, "Invalid suboptions specified.\n");
+               usage();
+               std::exit(EXIT_FAILURE);
+       }
+       if (opt_str == nullptr) {
+               fprintf(stderr, "No value given to suboption <%s>.\n",
+                               subopt_list[opt]);
+               usage();
+               std::exit(EXIT_FAILURE);
+       }
+
+       if (opt_str)
+               *value = strtoul(opt_str, NULL, 0);
+       return opt;
+}
+
+static void parse_ovt(char *optarg)
+{
+       unsigned rid = 0;
+       unsigned w = 0, h = 0;
+       unsigned fps = 0;
+
+       while (*optarg != '\0') {
+               int opt;
+               unsigned opt_val;
+
+               opt = parse_ovt_subopt(&optarg, &opt_val);
+
+               switch (opt) {
+               case OVT_RID:
+                       rid = opt_val;
+                       break;
+               case OVT_WIDTH:
+                       w = opt_val;
+                       break;
+               case OVT_HEIGHT:
+                       h = opt_val;
+                       break;
+               case OVT_FPS:
+                       fps = opt_val;
+                       break;
+               default:
+                       break;
+               }
+       }
+
+       if ((!rid && (!w || !h)) || !fps) {
+               fprintf(stderr, "Missing rid, width, height and/or fps.\n");
+               usage();
+               std::exit(EXIT_FAILURE);
+       }
+       unsigned hratio = 0, vratio = 0;
+       if (rid) {
+               const cta_rid *r = find_rid(rid);
+
+               if (r) {
+                       w = r->hact;
+                       h = r->vact;
+                       hratio = r->hratio;
+                       vratio = r->vratio;
+               }
+       }
+       timings t = state.calc_ovt_mode(w, h, hratio, vratio, fps);
+       state.print_timings("", &t, "OVT", "", true, false);
+}
+
 int main(int argc, char **argv)
 {
        char short_options[26 * 2 * 2 + 1];
        enum output_format out_fmt = OUT_FMT_DEFAULT;
        gtf_parsed_data gtf_data;
+       unsigned list_rid = 0;
        int ret;
 
        while (1) {
@@ -1918,6 +2019,12 @@ int main(int argc, char **argv)
                case OptGTF:
                        parse_gtf(optarg, gtf_data);
                        break;
+               case OptOVT:
+                       parse_ovt(optarg);
+                       break;
+               case OptListRIDTimings:
+                       list_rid = strtoul(optarg, NULL, 0);
+                       break;
                case ':':
                        fprintf(stderr, "Option '%s' requires a value.\n",
                                argv[optind]);
@@ -1946,13 +2053,18 @@ int main(int argc, char **argv)
                state.cta_list_vics();
        if (options[OptListHDMIVICs])
                state.cta_list_hdmi_vics();
+       if (options[OptListRIDs])
+               state.cta_list_rids();
+       if (options[OptListRIDTimings])
+               state.cta_list_rid_timings(list_rid);
 
        if (options[OptListEstTimings] || options[OptListDMTs] ||
-           options[OptListVICs] || options[OptListHDMIVICs])
+           options[OptListVICs] || options[OptListHDMIVICs] ||
+           options[OptListRIDs] || options[OptListRIDTimings])
                return 0;
 
        if (options[OptCVT] || options[OptDMT] || options[OptVIC] ||
-           options[OptHDMIVIC] || options[OptSTD])
+           options[OptHDMIVIC] || options[OptSTD] || options[OptOVT])
                return 0;
 
        if (options[OptGTF] && (!gtf_data.params_from_edid || optind == argc)) {
diff --git a/edid-decode.h b/edid-decode.h
index 7ba972d9ce49..e05a514dd9a7 100644
--- a/edid-decode.h
+++ b/edid-decode.h
@@ -118,6 +118,11 @@ enum gtf_ip_parm {
 
 typedef std::vector<timings_ext> vec_timings_ext;
 
+struct cta_rid {
+       unsigned hact, vact;
+       unsigned hratio, vratio;
+};
+
 struct cta_vfd {
        unsigned char rid;
        unsigned char fr_factor;
@@ -391,6 +396,8 @@ struct edid_state {
        void check_cta_blocks();
        void cta_list_vics();
        void cta_list_hdmi_vics();
+       void cta_list_rids();
+       void cta_list_rid_timings(unsigned list_rid = 0);
 
        void set_displayid_native_res(unsigned w, unsigned h);
        void parse_digital_interface(const unsigned char *x);
@@ -505,6 +512,7 @@ bool timings_close_match(const timings &t1, const timings 
&t2);
 const struct timings *find_dmt_id(unsigned char dmt_id);
 const struct timings *close_match_to_dmt(const timings &t, unsigned &dmt);
 const struct timings *find_vic_id(unsigned char vic);
+const struct cta_rid *find_rid(unsigned char rid);
 const struct timings *find_hdmi_vic_id(unsigned char hdmi_vic);
 const struct timings *cta_close_match_to_vic(const timings &t, unsigned &vic);
 unsigned char hdmi_vic_to_vic(unsigned char hdmi_vic);
diff --git a/parse-cta-block.cpp b/parse-cta-block.cpp
index d3c0aec5755a..e846a66f8929 100644
--- a/parse-cta-block.cpp
+++ b/parse-cta-block.cpp
@@ -189,12 +189,7 @@ static const struct timings edid_cta_modes2[] = {
        {  4096, 2160, 256, 135, 1188000, 0, false,   88,  88, 128, true,   8, 
10,  72, true  },
 };
 
-struct edid_rid {
-       unsigned hact, vact;
-       unsigned hratio, vratio;
-};
-
-static const edid_rid rids[] = {
+static const cta_rid rids[] = {
        /* RID 0-9 */
        {     0,    0,  0,  0 },
        {  1280,  720, 16,  9 },
@@ -229,6 +224,41 @@ static const edid_rid rids[] = {
        { 20480, 8640, 64, 27 },
 };
 
+static const unsigned char rid2vic[ARRAY_SIZE(rids)][8] = {
+       /* RID 0-9 */
+       {},
+       {  60,  61,  62, 108,  19,   4,  41,  47 },
+       {  65,  66,  67, 109,  68,  69,  70,  71 },
+       {  79,  80,  81, 110,  82,  83,  84,  85 },
+       {  32,  33,  34, 111,  31,  16,  64,  63 },
+       {  72,  73,  74, 112,  75,  76,  77,  78 },
+       {  86,  87,  88, 113,  89,  90,  91,  92 },
+       {},
+       {},
+       {},
+       /* RID 10-19 */
+       {},
+       {  93,  94,  95, 114,  96,  97, 117, 118 },
+       { 103, 104, 105, 116, 106, 107, 119, 120 },
+       { 121, 122, 123, 124, 125, 126, 127, 193 },
+       {},
+       {},
+       {},
+       {},
+       {},
+       { 194, 195, 196, 197, 198, 199, 200, 201 },
+       /* RID 20-28 */
+       { 202, 203, 204, 205, 206, 207, 208, 209 },
+       { 210, 211, 212, 213, 214, 215, 216, 217 },
+       {},
+       {},
+       {},
+       {},
+       {},
+       {},
+       {},
+};
+
 static const unsigned vf_rate_values[] = {
        /* Rate Index 0-7 */
          0,  24,  25,  30,  48,  50,  60, 100,
@@ -261,6 +291,20 @@ const struct timings *find_hdmi_vic_id(unsigned char 
hdmi_vic)
        return NULL;
 }
 
+const struct cta_rid *find_rid(unsigned char rid)
+{
+       if (rid > 0 && rid < ARRAY_SIZE(rids))
+               return &rids[rid];
+       return NULL;
+}
+
+static unsigned char rid_to_vic(unsigned char rid, unsigned char rate_index)
+{
+       if (vf_rate_values[rate_index] > 120)
+               return 0;
+       return rid2vic[rid][rate_index - 1];
+}
+
 const struct timings *cta_close_match_to_vic(const timings &t, unsigned &vic)
 {
        for (vic = 1; vic <= ARRAY_SIZE(edid_cta_modes1); vic++) {
@@ -299,6 +343,41 @@ void edid_state::cta_list_hdmi_vics()
        }
 }
 
+void edid_state::cta_list_rids()
+{
+       for (unsigned i = 1; i < ARRAY_SIZE(rids); i++) {
+               printf("RID %2u: %5ux%-4u %2u:%-2u\n", i,
+                      rids[i].hact, rids[i].vact,
+                      rids[i].hratio, rids[i].vratio);
+       }
+}
+
+void edid_state::cta_list_rid_timings(unsigned list_rid)
+{
+       for (unsigned rid = 1; rid < ARRAY_SIZE(rids); rid++) {
+               char type[16];
+
+               if (list_rid && rid != list_rid)
+                       continue;
+
+               sprintf(type, "RID %u", rid);
+               for (unsigned i = 1; i < ARRAY_SIZE(vf_rate_values); i++) {
+                       unsigned fps = vf_rate_values[i];
+
+                       if (rid_to_vic(rid, i)) {
+                               printf("%s: %5ux%-4u  %7.3f Hz %3u:%-2u maps to 
VIC %u\n", type,
+                                      rids[rid].hact, rids[rid].vact, 
(double)fps,
+                                      rids[rid].hratio, rids[rid].vratio,
+                                      rid_to_vic(rid, i));
+                               continue;
+                       }
+                       timings t = calc_ovt_mode(rids[rid].hact, 
rids[rid].vact,
+                                                 rids[rid].hratio, 
rids[rid].vratio, fps);
+                       print_timings("", &t, type, "", false, false);
+               }
+       }
+}
+
 static std::string audio_ext_format(unsigned char x)
 {
        if (x >= 1 && x <= 3)

_______________________________________________
linuxtv-commits mailing list
[email protected]
https://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to