Blob Blame History Raw
From be3d349cd9a145484419c012de669b63be383096 Mon Sep 17 00:00:00 2001
From: "Xiang, Haihao" <haihao.xiang@intel.com>
Date: Tue, 18 Jul 2017 13:54:02 +0800
Subject: [PATCH 02/02] vainfo: Add '--help' to show available options

vainfo has '--display' and '--device' options, but these options are
hidden, hence add '--help' to show these options

Signed-off-by: Xiang, Haihao <haihao.xiang@intel.com>
---
 common/va_display.c |  8 ++++++++
 common/va_display.h |  4 ++++
 vainfo/vainfo.c     | 44 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/common/va_display.c b/common/va_display.c
index 30a25ae..d348c4f 100644
--- a/common/va_display.c
+++ b/common/va_display.c
@@ -190,3 +190,11 @@ va_put_surface(
         return g_display_hooks->put_surface(va_dpy, surface, src_rect, dst_rect);
     return VA_STATUS_ERROR_UNIMPLEMENTED;
 }
+
+void
+va_print_display_options(FILE *stream)
+{
+    fprintf(stream, "Display options:\n");
+    fprintf(stream, "\t--display display | help         Show information for the specified display, or the available display list \n");
+    fprintf(stream, "\t--device device                  Set device name, only available under drm display\n");
+}
diff --git a/common/va_display.h b/common/va_display.h
index 4ed33e0..5fc159c 100644
--- a/common/va_display.h
+++ b/common/va_display.h
@@ -26,6 +26,7 @@
 #define VA_DISPLAY_H
 
 #include <va/va.h>
+#include <stdio.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -57,6 +58,9 @@ va_put_surface(
     const VARectangle *dst_rect
 );
 
+void
+va_print_display_options(FILE *stream);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/vainfo/vainfo.c b/vainfo/vainfo.c
index 4405073..bfbf698 100644
--- a/vainfo/vainfo.c
+++ b/vainfo/vainfo.c
@@ -26,6 +26,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <getopt.h>
+
 #include "va_display.h"
 
 #define CHECK_VASTATUS(va_status,func, ret)                             \
@@ -88,6 +91,45 @@ static char * entrypoint_string(VAEntrypoint entrypoint)
     return "<unknown entrypoint>";
 }
 
+static void
+usage_exit(const char *program)
+{
+    fprintf(stdout, "Show information from VA-API driver\n");
+    fprintf(stdout, "Usage: %s --help\n", program);
+    fprintf(stdout, "\t--help print this message\n\n");
+    fprintf(stdout, "Usage: %s [options]\n", program);
+    va_print_display_options(stdout);
+
+    exit(0);
+}
+
+static void
+parse_args(const char *name, int argc, char **argv)
+{
+    int c, tmp;
+    int option_index = 0;
+    long file_size;
+
+    static struct option long_options[] = {
+        {"help",        no_argument,            0,      'h'},
+        { NULL,         0,                      NULL,   0 }
+    };
+
+    va_init_display_args(&argc, argv);
+
+    while ((c = getopt_long(argc, argv,
+                            "",
+                            long_options,
+                            &option_index)) != -1) {
+        switch(c) {
+        case 'h':
+        default:
+            usage_exit(name);
+            break;
+        }
+    }
+}
+
 int main(int argc, const char* argv[])
 {
   VADisplay va_dpy;
@@ -106,7 +148,7 @@ int main(int argc, const char* argv[])
   else
       name = argv[0];
 
-  va_init_display_args(&argc, (char **)argv);
+  parse_args(name, argc, (char **)argv);
 
   va_dpy = va_open_display();
   if (NULL == va_dpy)
-- 
2.13.6