/* 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
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);
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);
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