[vlc-devel] [PATCH] Push messages to Android stack

Rafaël Carré funman at videolan.org
Thu Jan 19 23:12:32 CET 2012


From: Jean-Baptiste Kempf <jb at videolan.org>

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
Signed-off-by: Rafaël Carré <funman at videolan.org>
---
 configure.ac        |    4 ++++
 src/misc/messages.c |    7 +++++++
 src/posix/thread.c  |   16 ++++++++++++----
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4f09324..e242138 100644
--- a/configure.ac
+++ b/configure.ac
@@ -469,6 +469,10 @@ glibc run-time. Alternatively, build with --disable-nls.])
   ])
 ])
 
+if test "${HAVE_ANDROID}" = "1"; then
+    VLC_ADD_LIBS([libvlccore],[-llog])
+fi
+
 dnl Plugin compilation stuff
 
 VLC_LIBRARY_SUFFIX
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 66bd62e..fa00fed 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -228,10 +228,17 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
     va_list ap;
 
     va_copy (ap, args);
+#ifdef __ANDROID__
+#include <android/log.h>
+    static const android_LogPriority prioritytype[4] = {ANDROID_LOG_INFO, ANDROID_LOG_ERROR,
+                                           ANDROID_LOG_WARN, ANDROID_LOG_DEBUG };
+    __android_log_vprint(prioritytype[type], "vlc", format, ap);
+#else
     if (priv->b_color)
         PrintColorMsg (&priv->i_verbose, type, &msg, format, ap);
     else
         PrintMsg (&priv->i_verbose, type, &msg, format, ap);
+#endif
     va_end (ap);
 
 #ifdef WIN32
diff --git a/src/posix/thread.c b/src/posix/thread.c
index 7c4860e..473095a 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -136,6 +136,14 @@ static struct timespec mtime_to_ts (mtime_t date)
     return ts;
 }
 
+#if defined(__ANDROID__) && !defined(NDEBUG)
+# include <android/log.h>
+# define LOG_TAG "VLC/pthread"
+# define FATAL(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
+#else
+# define FATAL(...) fprintf(stderr, __VA_ARGS__)
+#endif
+
 /**
  * Print a backtrace to the standard error for debugging purpose.
  */
@@ -176,8 +184,8 @@ vlc_thread_fatal (const char *action, int error,
                   const char *function, const char *file, unsigned line)
 {
     int canc = vlc_savecancel ();
-    fprintf (stderr, "LibVLC fatal error %s (%d) in thread %lu ",
-             action, error, vlc_threadid ());
+    FATAL ("LibVLC fatal error %s (%d) in thread %lu ",
+           action, error, vlc_threadid ());
     vlc_trace (function, file, line);
 
     /* Sometimes strerror_r() crashes too, so make sure we print an error
@@ -185,7 +193,7 @@ vlc_thread_fatal (const char *action, int error,
 #ifdef __GLIBC__
     /* Avoid the strerror_r() prototype brain damage in glibc */
     errno = error;
-    fprintf (stderr, " Error message: %m\n");
+    FATAL (" Error message: %m\n");
 #else
     char buf[1000];
     const char *msg;
@@ -202,7 +210,7 @@ vlc_thread_fatal (const char *action, int error,
             msg = "unknown (invalid error number)";
             break;
     }
-    fprintf (stderr, " Error message: %s\n", msg);
+    FATAL (" Error message: %s\n", msg);
 #endif
     fflush (stderr);
 
-- 
1.7.8.3



More information about the vlc-devel mailing list