From: Emmanuel Gil Peyrot Date: Wed, 19 Oct 2016 12:37:36 +0000 (+0100) Subject: Add callbacks for error and info messages. X-Git-Tag: android-x86-7.1-r1~66 X-Git-Url: http://git.osdn.net/view?p=android-x86%2Fhardware-intel-common-libva.git;a=commitdiff_plain;h=5c47c33ad1dcfb4298054f7e8664dc910010d73f 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 Reviewed-by: Sean V Kelley --- 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 - -# 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