#include <string.h>
#include <dlfcn.h>
#include <unistd.h>
+#ifdef ANDROID
+#include <cutils/log.h>
+/* support versions < JellyBean */
+#ifndef ALOGE
+#define ALOGE LOGE
+#endif
+#ifndef ALOGI
+#define ALOGI LOGI
+#endif
+#endif
#define DRIVER_EXTENSION "_drv_video.so"
/*
* read a config "env" for libva.conf or from environment setting
- * liva.conf has higher priority
+ * libva.conf has higher priority
* return 0: the "env" is set, and the value is copied into env_value
* 1: the env is not set
*/
fp = fopen("/etc/libva.conf", "r");
while (fp && (fgets(oneline, 1024, fp) != NULL)) {
- if (strlen(oneline) == 1)
- continue;
+ if (strlen(oneline) == 1)
+ continue;
token = strtok_r(oneline, "=\n", &saveptr);
- value = strtok_r(NULL, "=\n", &saveptr);
+ value = strtok_r(NULL, "=\n", &saveptr);
- if (NULL == token || NULL == value)
- continue;
+ if (NULL == token || NULL == value)
+ continue;
if (strcmp(token, env) == 0) {
if (env_value) {
return pDisplayContext && (pDisplayContext->vadpy_magic == VA_DISPLAY_MAGIC) && pDisplayContext->vaIsValid(pDisplayContext);
}
+static void default_log_error(const char *buffer)
+{
+# ifdef ANDROID
+ ALOGE("%s", buffer);
+# else
+ fprintf(stderr, "libva error: %s", buffer);
+# endif
+}
+
+static void default_log_info(const char *buffer)
+{
+# ifdef ANDROID
+ ALOGI("%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_MessagingInit()
+{
+#if ENABLE_VA_MESSAGING
+ char env_value[1024];
+
+ if (va_parseConfig("LIBVA_MESSAGING_LEVEL", &env_value[0]) == 0) {
+ if (strcmp(env_value, "0") == 0) {
+ vaSetInfoCallback(NULL);
+ vaSetErrorCallback(NULL);
+ }
+
+ if (strcmp(env_value, "1") == 0) {
+ vaSetInfoCallback(NULL);
+ }
+ }
+#endif
+}
+
void va_errorMessage(const char *msg, ...)
{
+#if ENABLE_VA_MESSAGING
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);
}
else if (len > 0)
va_log_error(buf);
+#endif
}
void va_infoMessage(const char *msg, ...)
{
+#if ENABLE_VA_MESSAGING
char buf[512], *dynbuf;
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);
}
else if (len > 0)
va_log_info(buf);
+#endif
}
static bool va_checkVtable(void *ptr, char *function)
int minor;
} compatible_versions[] = {
{ VA_MAJOR_VERSION, VA_MINOR_VERSION },
+ { 0, 39 },
{ 0, 38 },
{ 0, 37 },
{ 0, 36 },
va_FoolInit(dpy);
+ va_MessagingInit();
+
va_infoMessage("VA-API version %s\n", VA_VERSION_S);
vaStatus = va_getDriverName(dpy, &driver_name);