summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2016-10-19 13:37:36 +0100
committerSean V Kelley <seanvk@posteo.de>2016-10-27 11:41:25 -0700
commit5c47c33ad1dcfb4298054f7e8664dc910010d73f (patch)
tree9279104a6cac374c6b168138be931f000cce5a90
parent3b7e4999950a04fabd42edbead8c2f24c6cdf3cf (diff)
Add callbacks for error and info messages.
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@linkmauve.fr> Reviewed-by: Sean V Kelley <seanvk@posteo.de>
-rw-r--r--va/sysdeps.h20
-rw-r--r--va/va.c53
-rw-r--r--va/va.h15
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