[vlc-commits] [Git][videolan/vlc][master] logger: add emscripten module

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Fri Feb 25 19:44:51 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
85a5bb17 by Mehdi Sabwat at 2022-02-25T17:05:07+00:00
logger: add emscripten module

Co-authored-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>
Co-authored-by: Thomas Guillem <thomas at gllm.fr>

- - - - -


2 changed files:

- modules/logger/Makefile.am
- + modules/logger/emscripten.c


Changes:

=====================================
modules/logger/Makefile.am
=====================================
@@ -25,3 +25,9 @@ endif
 
 libjson_tracer_plugin_la_SOURCES = logger/json.c
 logger_LTLIBRARIES += libjson_tracer_plugin.la
+
+libemscripten_logger_plugin_la_SOURCES = logger/emscripten.c
+
+if HAVE_EMSCRIPTEN
+logger_LTLIBRARIES += libemscripten_logger_plugin.la
+endif


=====================================
modules/logger/emscripten.c
=====================================
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * emscripten.c: Emscripten logger
+ *****************************************************************************
+ * Copyright © 2022 VLC authors, VideoLAN and Videolabs
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <emscripten.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+
+static void EmscriptenPrintMsg(void *opaque, int type, const vlc_log_t *p_item,
+                               const char *format, va_list ap)
+{
+    int prio;
+    char *message;
+    int verbosity = (int)opaque;
+
+    if (verbosity < type)
+        return;
+
+    if (vasprintf(&message, format, ap) < 0)
+        return;
+    switch (type) {
+        case VLC_MSG_ERR:
+            prio = EM_LOG_CONSOLE | EM_LOG_ERROR;
+            break;
+        case VLC_MSG_WARN:
+            prio = EM_LOG_CONSOLE | EM_LOG_WARN;
+            break;
+        case VLC_MSG_INFO:
+            prio = EM_LOG_CONSOLE | EM_LOG_INFO;
+            break;
+        case VLC_MSG_DBG:
+            prio = EM_LOG_CONSOLE | EM_LOG_DEBUG;
+        default:
+            prio = EM_LOG_CONSOLE;
+    }
+
+    emscripten_log(prio, "[vlc.js: 0x%"PRIxPTR"/0x%"PRIxPTR"] %s %s: %s",
+                   p_item->i_object_id, p_item->tid, p_item->psz_module,
+                   p_item->psz_object_type, message);
+    free(message);
+}
+
+static const struct vlc_logger_operations ops = { EmscriptenPrintMsg, NULL };
+
+static const struct vlc_logger_operations *Open(vlc_object_t *obj, void **sysp)
+{
+    int verbosity = var_InheritInteger(obj, "verbose");
+
+    if (verbosity < 0)
+        return NULL;
+    verbosity += VLC_MSG_ERR;
+    *sysp = (void *)(int)verbosity;
+    return &ops;
+}
+
+vlc_module_begin()
+    set_shortname(N_("emlog"))
+    set_description(N_("Emscripten logger"))
+    set_subcategory(SUBCAT_ADVANCED_MISC)
+    set_capability("logger", 30)
+    set_callback(Open)
+vlc_module_end ()



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/85a5bb173e99dcc0417ffd3810fe8a63afde56c7

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/85a5bb173e99dcc0417ffd3810fe8a63afde56c7
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list