[Libva] [PATCH v2, android] android-log: enable logs according to Android version

Charles, Daniel daniel.charles at intel.com
Wed Aug 1 12:38:14 PDT 2012


On Wed, Aug 1, 2012 at 12:28 PM, Daniel Charles
<daniel.charles at intel.com> wrote:
> Log functions available are now Android compatible and log statements
> will show on user space android logging system.
>
> Defined a LOG_TAG and make it available for all versions of Android.
>
> Signed-off-by: Daniel Charles <daniel.charles at intel.com>
> ---
>  va/Android.mk |   13 +++++++++++--
>  va/sysdeps.h  |   15 +++++++++++++++
>  va/va.c       |   38 ++++++++++++++++++++++++++++++++++----
>  3 files changed, 60 insertions(+), 6 deletions(-)
>
> diff --git a/va/Android.mk b/va/Android.mk
> index 4a9923e..97cac95 100755
> --- a/va/Android.mk
> +++ b/va/Android.mk
> @@ -26,11 +26,13 @@
>  LOCAL_PATH:= $(call my-dir)
>
>  LIBVA_DRIVERS_PATH = /system/lib
> +#Version set to Android Jelly Bean
> +NEED_VERSION := 4.1
> +USE_ALOG := $(filter $(NEED_VERSION),$(firstword $(sort $(PLATFORM_VERSION) \
> +                                   $(NEED_VERSION))))
>
>  include $(CLEAR_VARS)
>
> -#LIBVA_MINOR_VERSION := 31
> -#LIBVA_MAJOR_VERSION := 0
>
>  LOCAL_SRC_FILES := \
>         va.c \
> @@ -41,6 +43,13 @@ LOCAL_CFLAGS += \
>         -DANDROID \
>         -DVA_DRIVERS_PATH="\"$(LIBVA_DRIVERS_PATH)\""
>
> +#Android Jelly Bean defined ALOGx, older versions use LOGx
> +ifeq ($(USE_ALOG), $(NEED_VERSION))
> +LOCAL_CFLAGS += -DANDROID_ALOG
> +else
> +LOCAL_CFLAGS += -DANDROID_LOG
> +endif
> +
>  LOCAL_C_INCLUDES += \
>         $(TARGET_OUT_HEADERS)/libva \
>         $(LOCAL_PATH)/x11 \
> diff --git a/va/sysdeps.h b/va/sysdeps.h
> index 0752b17..d8b963d 100644
> --- a/va/sysdeps.h
> +++ b/va/sysdeps.h
> @@ -39,6 +39,21 @@
>  # define Bool  int
>  # define True  1
>  # define False 0
> +
> +# define LOG_TAG "lib-va"
> +# include <utils/Log.h>
> +
> +#ifdef ANDROID_ALOG
> +# define va_log_error(buffer) ALOGE("%s", buffer);
> +# define VA_log_info(buffer) ALOGI("%s", buffer);
> +#elif ANDROID_LOG
> +# define va_log_error(buffer) LOGE("%s", buffer);
> +# define va_log_info(buffer) LOGI("%s", buffer);
>  #endif
>
> +#else
> +
> +# define va_log_error(buffer) fprintf(stderr, "libva error: %s", buffer);
> +# define va_log_info(buffer) fprintf(stderr, "libva info: %s", buffer);
> +#endif /* ANDROID */
>  #endif /* SYSDEPS_H */
> diff --git a/va/va.c b/va/va.c
> index 1bbe047..a7dd1ed 100644
> --- a/va/va.c
> +++ b/va/va.c
> @@ -105,22 +105,52 @@ int vaDisplayIsValid(VADisplay dpy)
>
>  void va_errorMessage(const char *msg, ...)
>  {
> +    char buffer[512];
> +    char *alloc_buffer;
>      va_list args;
> +    int len;
>
> -    fprintf(stderr, "libva error: ");
>      va_start(args, msg);
> -    vfprintf(stderr, msg, args);
> +    len=vsnprintf(buffer, 512, msg, args);
>      va_end(args);
> +
> +    if (len >= 512) {
> +        va_start(args, msg);
> +        alloc_buffer=(char *)calloc(len+1, sizeof(char));
> +        if (alloc_buffer)
> +            if (len ==
> +                    vsnprintf(alloc_buffer,len+1,msg,args))
> +                va_log_error(alloc_buffer);
> +        va_end(args);
> +        free(alloc_buffer);
> +    } else {
> +        va_log_error(buffer);
> +    }
>  }
>
>  void va_infoMessage(const char *msg, ...)
>  {
> +    char buffer[512];
> +    char *alloc_buffer;
>      va_list args;
> +    int len;
>
> -    fprintf(stderr, "libva: ");
>      va_start(args, msg);
> -    vfprintf(stderr, msg, args);
> +    len=vsnprintf(buffer, 512, msg, args);

using strlen(msg) as the second argument here would cause the
re-allocation to be called too often. So using static+dynamic advise
made in Gwenole's last comment looks like a better approach.

>      va_end(args);
> +
> +    if (len >= 512) {
> +        va_start(args, msg);
> +        alloc_buffer=(char *)calloc(len+1, sizeof(char));
> +        if (alloc_buffer)
> +            if (len ==
> +                    vsnprintf(alloc_buffer,len+1,msg,args))
> +                va_log_info(alloc_buffer);
> +        va_end(args);
> +        free(alloc_buffer);
> +    } else {
> +        va_log_info(buffer);
> +    }
>  }
>

After reviewing all the current error and info messages in this
library, the re-allocation should not be used with this patch although
it is good to have.

Let me know if this is good enough to apply.

Thanks.
-- 
Daniel
>  static Bool va_checkVtable(void *ptr, char *function)
> --
> 1.7.7.6
>


More information about the Libva mailing list