0003-Push-messages-to-Android-stack.patch 3.04 KB
Newer Older
1
From 054afb010cefa90f3ad8d50c23959be7375475b8 Mon Sep 17 00:00:00 2001
ivoire's avatar
ivoire committed
2
From: Jean-Baptiste Kempf <jb@videolan.org>
3
Date: Sun, 31 Jul 2011 00:20:40 +0200
4
Subject: [PATCH 3/7] Push messages to Android stack
ivoire's avatar
ivoire committed
5

6
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
ivoire's avatar
ivoire committed
7 8
---
 configure.ac        |    1 +
Rafaël Carré's avatar
Rafaël Carré committed
9
 src/misc/messages.c |    7 +++++++
ivoire's avatar
ivoire committed
10
 src/posix/thread.c  |   16 ++++++++++++----
Rafaël Carré's avatar
Rafaël Carré committed
11
 3 files changed, 20 insertions(+), 4 deletions(-)
ivoire's avatar
ivoire committed
12 13

diff --git a/configure.ac b/configure.ac
14
index e739e75..d4a8d4e 100644
ivoire's avatar
ivoire committed
15 16
--- a/configure.ac
+++ b/configure.ac
17
@@ -445,6 +445,7 @@ fi
ivoire's avatar
ivoire committed
18 19 20 21 22 23 24 25
 
 if test "${HAVE_ANDROID}" = "1"; then
     AC_REPLACE_FUNCS([pthread_cancel])
+    VLC_ADD_LIBS([libvlccore],[-llog])
 fi
 
 dnl
diff --git a/src/misc/messages.c b/src/misc/messages.c
26
index 66bd62e..4308897 100644
ivoire's avatar
ivoire committed
27 28
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
29
@@ -228,10 +228,17 @@ void vlc_vaLog (vlc_object_t *obj, int type, const char *module,
Rafaël Carré's avatar
Rafaël Carré committed
30 31 32
     va_list ap;
 
     va_copy (ap, args);
ivoire's avatar
ivoire committed
33 34 35 36
+#ifdef __ANDROID__
+#include <android/log.h>
+    android_LogPriority prioritytype[4] = {ANDROID_LOG_INFO, ANDROID_LOG_ERROR,
+                                           ANDROID_LOG_WARN, ANDROID_LOG_DEBUG };
Rafaël Carré's avatar
Rafaël Carré committed
37
+    __android_log_vprint(prioritytype[type], "vlc", format, ap);
ivoire's avatar
ivoire committed
38 39
+#else
     if (priv->b_color)
Rafaël Carré's avatar
Rafaël Carré committed
40 41 42
         PrintColorMsg (&priv->i_verbose, type, &msg, format, ap);
     else
         PrintMsg (&priv->i_verbose, type, &msg, format, ap);
ivoire's avatar
ivoire committed
43
+#endif
Rafaël Carré's avatar
Rafaël Carré committed
44 45
     va_end (ap);
 
46
 #ifdef WIN32
ivoire's avatar
ivoire committed
47
diff --git a/src/posix/thread.c b/src/posix/thread.c
48
index 9d9c771..d8a442b 100644
ivoire's avatar
ivoire committed
49 50
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
51 52 53
@@ -136,6 +136,14 @@ static struct timespec mtime_to_ts (mtime_t date)
     return ts;
 }
ivoire's avatar
ivoire committed
54 55 56 57 58 59 60 61 62 63 64 65
 
+#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.
  */
66
@@ -176,8 +184,8 @@ vlc_thread_fatal (const char *action, int error,
ivoire's avatar
ivoire committed
67 68 69 70 71 72 73 74 75 76
                   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
77
@@ -185,7 +193,7 @@ vlc_thread_fatal (const char *action, int error,
ivoire's avatar
ivoire committed
78 79 80 81 82 83 84 85
 #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;
86
@@ -202,7 +210,7 @@ vlc_thread_fatal (const char *action, int error,
ivoire's avatar
ivoire committed
87 88 89 90 91 92 93 94 95
             msg = "unknown (invalid error number)";
             break;
     }
-    fprintf (stderr, " Error message: %s\n", msg);
+    FATAL (" Error message: %s\n", msg);
 #endif
     fflush (stderr);
 
-- 
96
1.7.5.4
ivoire's avatar
ivoire committed
97