[vlc-commits] Messages: add AndroidPrintMsg cb for Android
Thomas Guillem
git at videolan.org
Wed Dec 3 16:10:37 CET 2014
vlc/vlc-2.2 | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Dec 2 09:33:49 2014 +0000| [94df30dc1f5ae842c155ba1f9075152221f6762e] | committer: Jean-Baptiste Kempf
Messages: add AndroidPrintMsg cb for Android
On android 5.0, PrintMsg blocks on fprintf when stderr is locked by flockfile.
This commit adds a default log callback for android in order to fix this issue,
and in order to have early logs (before libvlc_log_set is called).
Close #12870
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
(cherry picked from commit 1df6e651c0a46a99bcc99a66f98c7277d84aff16)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=94df30dc1f5ae842c155ba1f9075152221f6762e
---
src/misc/messages.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 8452a5a..f75fd67 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -41,6 +41,10 @@
#include <vlc_charset.h>
#include "../libvlc.h"
+#ifdef __ANDROID__
+#include <android/log.h>
+#endif
+
/**
* Emit a log message.
* \param obj VLC object emitting the message or NULL
@@ -227,6 +231,43 @@ static void Win32DebugOutputMsg (void* d, int type, const vlc_log_t *p_item,
}
#endif
+#ifdef __ANDROID__
+static void AndroidPrintMsg (void *d, int type, const vlc_log_t *p_item,
+ const char *format, va_list ap)
+{
+ int verbose = (intptr_t)d;
+ int prio;
+
+ if (verbose < 0 || verbose < (type - VLC_MSG_ERR))
+ return;
+
+ int canc = vlc_savecancel ();
+
+ char *format2;
+ if (asprintf (&format2, "[%0*"PRIxPTR"] %s %s: %s",
+ ptr_width, p_item->i_object_id, p_item->psz_module,
+ p_item->psz_object_type, format) < 0)
+ return;
+ switch (type) {
+ case VLC_MSG_INFO:
+ prio = ANDROID_LOG_INFO;
+ break;
+ case VLC_MSG_ERR:
+ prio = ANDROID_LOG_ERROR;
+ break;
+ case VLC_MSG_WARN:
+ prio = ANDROID_LOG_WARN;
+ break;
+ default:
+ case VLC_MSG_DBG:
+ prio = ANDROID_LOG_DEBUG;
+ }
+ __android_log_vprint (prio, "VLC", format2, ap);
+ free (format2);
+ vlc_restorecancel (canc);
+}
+#endif
+
/**
* Sets the message logging callback.
* \param cb message callback, or NULL to reset
@@ -238,12 +279,16 @@ void vlc_LogSet (libvlc_int_t *vlc, vlc_log_cb cb, void *opaque)
if (cb == NULL)
{
+#ifdef __ANDROID__
+ cb = AndroidPrintMsg;
+#else
#if defined (HAVE_ISATTY) && !defined (_WIN32)
if (isatty (STDERR_FILENO) && var_InheritBool (vlc, "color"))
cb = PrintColorMsg;
else
#endif
cb = PrintMsg;
+#endif // __ANDROID__
opaque = (void *)(intptr_t)priv->log.verbose;
}
More information about the vlc-commits
mailing list