Discussion:
[PATCH] Add callbacks for error and info messages.
(too old to reply)
Emmanuel Gil Peyrot
2016-10-19 12:37:36 UTC
Permalink
This lets any application using libva choose the best way to report
info and error messages to the user, for example graphical application
can open a popup on errors and write info messages in the toolbar.

Signed-off-by: Emmanuel Gil Peyrot <***@linkmauve.fr>
---
va/sysdeps.h | 20 --------------------
va/va.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
va/va.h | 15 +++++++++++++++
3 files changed, 68 insertions(+), 20 deletions(-)

diff --git a/va/sysdeps.h b/va/sysdeps.h
index 4de764d..164a274 100644
--- a/va/sysdeps.h
+++ b/va/sysdeps.h
@@ -46,26 +46,6 @@

/* Android logging utilities */
# include <utils/Log.h>
-
-# ifdef ANDROID_ALOG
-# define va_log_error(buffer) do { ALOGE("%s", buffer); } while (0)
-# define va_log_info(buffer) do { ALOGI("%s", buffer); } while (0)
-# elif ANDROID_LOG
-# define va_log_error(buffer) do { LOGE("%s", buffer); } while (0)
-# define va_log_info(buffer) do { LOGI("%s", buffer); } while (0)
-# endif
-#endif
-
-#ifndef va_log_error
-#define va_log_error(buffer) do { \
- fprintf(stderr, "libva error: %s", buffer); \
- } while (0)
-#endif
-
-#ifndef va_log_info
-#define va_log_info(buffer) do { \
- fprintf(stderr, "libva info: %s", buffer); \
- } while (0)
#endif

#if defined __GNUC__ && defined HAVE_GNUC_VISIBILITY_ATTRIBUTE
diff --git a/va/va.c b/va/va.c
index b524fc7..5cf7220 100644
--- a/va/va.c
+++ b/va/va.c
@@ -106,12 +106,62 @@ int vaDisplayIsValid(VADisplay dpy)
return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
}

+static void default_log_error(const char *buffer)
+{
+# ifdef ANDROID_ALOG
+ ALOGE("%s", buffer);
+# elif ANDROID_LOG
+ LOGE("%s", buffer);
+# else
+ fprintf(stderr, "libva error: %s", buffer);
+# endif
+}
+
+static void default_log_info(const char *buffer)
+{
+# ifdef ANDROID_ALOG
+ ALOGI("%s", buffer);
+# elif ANDROID_LOG
+ LOGI("%s", buffer);
+# else
+ fprintf(stderr, "libva info: %s", buffer);
+# endif
+}
+
+static vaMessageCallback va_log_error = default_log_error;
+static vaMessageCallback va_log_info = default_log_info;
+
+/**
+ * Set the callback for error messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetErrorCallback(vaMessageCallback callback)
+{
+ vaMessageCallback old_callback = va_log_error;
+ va_log_error = callback;
+ return old_callback;
+}
+
+/**
+ * Set the callback for info messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetInfoCallback(vaMessageCallback callback)
+{
+ vaMessageCallback old_callback = va_log_info;
+ va_log_info = callback;
+ return old_callback;
+}
+
void va_errorMessage(const char *msg, ...)
{
char buf[512], *dynbuf;
va_list args;
int n, len;

+ if (va_log_error == NULL)
+ return;
+
va_start(args, msg);
len = vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
@@ -137,6 +187,9 @@ void va_infoMessage(const char *msg, ...)
va_list args;
int n, len;

+ if (va_log_info == NULL)
+ return;
+
va_start(args, msg);
len = vsnprintf(buf, sizeof(buf), msg, args);
va_end(args);
diff --git a/va/va.h b/va/va.h
index 665aafb..88628a8 100644
--- a/va/va.h
+++ b/va/va.h
@@ -230,6 +230,21 @@ typedef struct _VARectangle
unsigned short height;
} VARectangle;

+/** Type of a message callback, used for both error and info log. */
+typedef void (*vaMessageCallback)(const char *message);
+
+/**
+ * Set the callback for error messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetErrorCallback(vaMessageCallback);
+
+/**
+ * Set the callback for info messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetInfoCallback(vaMessageCallback);
+
/**
* Initialization:
* A display must be obtained by calling vaGetDisplay() before calling
--
2.10.0
Sean V Kelley
2016-10-24 22:54:17 UTC
Permalink
Post by Emmanuel Gil Peyrot
This lets any application using libva choose the best way to report
info and error messages to the user, for example graphical
application
can open a popup on errors and write info messages in the toolbar.
What version of Libva are you testing this with?

Sean
Post by Emmanuel Gil Peyrot
---
 va/sysdeps.h | 20 --------------------
 va/va.c      | 53
+++++++++++++++++++++++++++++++++++++++++++++++++++++
 va/va.h      | 15 +++++++++++++++
 3 files changed, 68 insertions(+), 20 deletions(-)
diff --git a/va/sysdeps.h b/va/sysdeps.h
index 4de764d..164a274 100644
--- a/va/sysdeps.h
+++ b/va/sysdeps.h
@@ -46,26 +46,6 @@
 
 /* Android logging utilities */
 # include <utils/Log.h>
-
-# ifdef ANDROID_ALOG
-#  define va_log_error(buffer)  do { ALOGE("%s", buffer); } while
(0)
-#  define va_log_info(buffer)   do { ALOGI("%s", buffer); } while
(0)
-# elif ANDROID_LOG
-#  define va_log_error(buffer)  do { LOGE("%s", buffer); } while (0)
-#  define va_log_info(buffer)   do { LOGI("%s", buffer); } while (0)
-# endif
-#endif
-
-#ifndef va_log_error
-#define va_log_error(buffer) do {                       \
-        fprintf(stderr, "libva error: %s", buffer);     \
-    } while (0)
-#endif
-
-#ifndef va_log_info
-#define va_log_info(buffer) do {                        \
-        fprintf(stderr, "libva info: %s", buffer);      \
-    } while (0)
 #endif
 
 #if defined __GNUC__ && defined HAVE_GNUC_VISIBILITY_ATTRIBUTE
diff --git a/va/va.c b/va/va.c
index b524fc7..5cf7220 100644
--- a/va/va.c
+++ b/va/va.c
@@ -106,12 +106,62 @@ int vaDisplayIsValid(VADisplay dpy)
     return pDisplayContext && (pDisplayContext->vadpy_magic ==
VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
 }
 
+static void default_log_error(const char *buffer)
+{
+# ifdef ANDROID_ALOG
+    ALOGE("%s", buffer);
+# elif ANDROID_LOG
+    LOGE("%s", buffer);
+# else
+    fprintf(stderr, "libva error: %s", buffer);
+# endif
+}
+
+static void default_log_info(const char *buffer)
+{
+# ifdef ANDROID_ALOG
+    ALOGI("%s", buffer);
+# elif ANDROID_LOG
+    LOGI("%s", buffer);
+# else
+    fprintf(stderr, "libva info: %s", buffer);
+# endif
+}
+
+static vaMessageCallback va_log_error = default_log_error;
+static vaMessageCallback va_log_info = default_log_info;
+
+/**
+ * Set the callback for error messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetErrorCallback(vaMessageCallback callback)
+{
+    vaMessageCallback old_callback = va_log_error;
+    va_log_error = callback;
+    return old_callback;
+}
+
+/**
+ * Set the callback for info messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetInfoCallback(vaMessageCallback callback)
+{
+    vaMessageCallback old_callback = va_log_info;
+    va_log_info = callback;
+    return old_callback;
+}
+
 void va_errorMessage(const char *msg, ...)
 {
     char buf[512], *dynbuf;
     va_list args;
     int n, len;
 
+    if (va_log_error == NULL)
+        return;
+
     va_start(args, msg);
     len = vsnprintf(buf, sizeof(buf), msg, args);
     va_end(args);
@@ -137,6 +187,9 @@ void va_infoMessage(const char *msg, ...)
     va_list args;
     int n, len;
 
+    if (va_log_info == NULL)
+        return;
+
     va_start(args, msg);
     len = vsnprintf(buf, sizeof(buf), msg, args);
     va_end(args);
diff --git a/va/va.h b/va/va.h
index 665aafb..88628a8 100644
--- a/va/va.h
+++ b/va/va.h
@@ -230,6 +230,21 @@ typedef struct _VARectangle
     unsigned short height;
 } VARectangle;
 
+/** Type of a message callback, used for both error and info log. */
+typedef void (*vaMessageCallback)(const char *message);
+
+/**
+ * Set the callback for error messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetErrorCallback(vaMessageCallback);
+
+/**
+ * Set the callback for info messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetInfoCallback(vaMessageCallback);
+
 /**
  * A display must be obtained by calling vaGetDisplay() before
calling
Emmanuel Gil Peyrot
2016-10-25 14:55:49 UTC
Permalink
Post by Sean V Kelley
Post by Emmanuel Gil Peyrot
This lets any application using libva choose the best way to report
info and error messages to the user, for example graphical
application
can open a popup on errors and write info messages in the toolbar.
What version of Libva are you testing this with?
Hi, I wrote and tested that patch against libva master,
3b7e4999950a04fabd42edbead8c2f24c6cdf3cf, corresponding to 0.39.4.
Post by Sean V Kelley
Sean
--
Emmanuel Gil Peyrot
Xiang, Haihao
2016-10-27 15:55:03 UTC
Permalink
-----Original Message-----
Emmanuel Gil Peyrot
Sent: Tuesday, October 25, 2016 10:56 PM
Subject: Re: [Libva] [PATCH] Add callbacks for error and info messages.
Post by Sean V Kelley
Post by Emmanuel Gil Peyrot
This lets any application using libva choose the best way to report
info and error messages to the user, for example graphical
application can open a popup on errors and write info messages in
the toolbar.
What version of Libva are you testing this with?
Hi, I wrote and tested that patch against libva master,
3b7e4999950a04fabd42edbead8c2f24c6cdf3cf, corresponding to 0.39.4.
User might use the APIs in a multithread program however cannot get the expected result.
Post by Sean V Kelley
Sean
--
Emmanuel Gil Peyrot
_______________________________________________
Libva mailing list
https://lists.freedesktop.org/mailman/listinfo/libva
Sean V Kelley
2016-10-27 18:41:52 UTC
Permalink
Post by Xiang, Haihao
-----Original Message-----
Emmanuel Gil Peyrot
Sent: Tuesday, October 25, 2016 10:56 PM
Subject: Re: [Libva] [PATCH] Add callbacks for error and info messages.
Post by Sean V Kelley
Post by Emmanuel Gil Peyrot
This lets any application using libva choose the best way to report
info and error messages to the user, for example graphical
application can open a popup on errors and write info messages in
the toolbar.
What version of Libva are you testing this with?
Hi, I wrote and tested that patch against libva master,
3b7e4999950a04fabd42edbead8c2f24c6cdf3cf, corresponding to 0.39.4.
User might use the APIs in a multithread program however cannot get
the expected result. 
Good point Haihao. Due to multiple contexts, you may not see the
results you are expecting depending on the UI thread and backing
process. Your applicaiton would need to keep track of the contexts so
that anything provided is meaningful to the user.

This is not an unusual situation and one we deal with on ChromeOS.

This is more of a caveat and I'm okay with merging it.

You should just be aware.

Applied, thanks.

Sean
Post by Xiang, Haihao
Post by Sean V Kelley
Sean
--
Emmanuel Gil Peyrot
_______________________________________________
Libva mailing list
https://lists.freedesktop.org/mailman/listinfo/libva
Loading...