From 06034c7d6401b8e447aac98fd062b87523ae5f4f Mon Sep 17 00:00:00 2001 From: lliuu Date: Wed, 12 Apr 2017 10:13:21 -0700 Subject: [PATCH] Revert of Android Logging.java: Load native library only when needed (patchset #2 id:2 of https://codereview.webrtc.org/2817593003/ ) Reason for revert: Change in Logging.java breaking compilation (incorrect reference to enum) Original issue's description: > Reland of Android Logging.java: Load native library only when needed (patchset #1 id:1 of https://codereview.webrtc.org/2816753002/ ) > > Reason for revert: > Fix bug in original CL. > > Original issue's description: > > Revert of Android Logging.java: Load native library only when needed (patchset #3 id:40001 of https://codereview.webrtc.org/2803203002/ ) > > > > Reason for revert: > > Breaks C++ logs in Java apps. > > > > Original issue's description: > > > Android Logging.java: Load native library only when needed > > > > > > Logging.java currently always tries to load jingle_peerconnection_so in > > > the static section, but some clients don't want to use it. This CL loads > > > jingle_peerconnection_so only when a client requests it by calling one > > > of: > > > * Logging.enableLogThreads > > > * Logging.enableLogTimeStamps > > > * Logging.enableTracing > > > * Logging.enableLogToDebugOutput > > > > > > BUG=b/36410678 > > > > > > Review-Url: https://codereview.webrtc.org/2803203002 > > > Cr-Commit-Position: refs/heads/master@{#17647} > > > Committed: https://chromium.googlesource.com/external/webrtc/+/dee5eb14e1d4e5bd894772448cc9418e94b3a967 > > > > TBR=sakal@webrtc.org,glaznev@webrtc.org,noahric@chromium.org,magjed@webrtc.org > > # Not skipping CQ checks because original CL landed more than 1 days ago. > > BUG=b/36410678 > > > > Review-Url: https://codereview.webrtc.org/2816753002 > > Cr-Commit-Position: refs/heads/master@{#17676} > > Committed: https://chromium.googlesource.com/external/webrtc/+/6e4a4427dc58ca252461310981e1f07ed987c334 > > TBR=sakal@webrtc.org,glaznev@webrtc.org,noahric@chromium.org,brandtr@webrtc.org > # Skipping CQ checks because original CL landed less than 1 days ago. > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=b/36410678 > > Review-Url: https://codereview.webrtc.org/2817593003 > Cr-Commit-Position: refs/heads/master@{#17677} > Committed: https://chromium.googlesource.com/external/webrtc/+/297714619fc4252c08ef8a04ac4ca18653c70b39 TBR=sakal@webrtc.org,glaznev@webrtc.org,noahric@chromium.org,brandtr@webrtc.org,magjed@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=b/36410678 Review-Url: https://codereview.webrtc.org/2814133002 Cr-Commit-Position: refs/heads/master@{#17678} --- webrtc/base/java/src/org/webrtc/Logging.java | 47 ++++++------------- .../api/org/webrtc/FileVideoCapturer.java | 4 -- .../api/org/webrtc/VideoFileRenderer.java | 4 -- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/webrtc/base/java/src/org/webrtc/Logging.java b/webrtc/base/java/src/org/webrtc/Logging.java index b96520778d..736dcf0d43 100644 --- a/webrtc/base/java/src/org/webrtc/Logging.java +++ b/webrtc/base/java/src/org/webrtc/Logging.java @@ -16,40 +16,23 @@ import java.util.EnumSet; import java.util.logging.Level; import java.util.logging.Logger; -/** - * Java wrapper for WebRTC logging. Logging defaults to java.util.logging.Logger, but will switch to - * native logging (rtc::LogMessage) if one of the following static functions are called from the - * app: - * - Logging.enableLogThreads - * - Logging.enableLogTimeStamps - * - Logging.enableTracing - * - Logging.enableLogToDebugOutput - * Using native logging requires the presence of the jingle_peerconnection_so library. - */ +/** Java wrapper for WebRTC logging. */ public class Logging { - private static final Logger fallbackLogger = createFallbackLogger(); + private static final Logger fallbackLogger = Logger.getLogger("org.webrtc.Logging"); private static volatile boolean tracingEnabled; private static volatile boolean loggingEnabled; - private static enum NativeLibStatus { UNINITIALIZED, LOADED, FAILED } - private static volatile NativeLibStatus nativeLibStatus = UNINITIALIZED; + private static volatile boolean nativeLibLoaded; - private static Logger createFallbackLogger() { - final Logger fallbackLogger = Logger.getLogger("org.webrtc.Logging"); - fallbackLogger.setLevel(Level.ALL); - return fallbackLogger; - } + static { + try { + System.loadLibrary("jingle_peerconnection_so"); + nativeLibLoaded = true; + } catch (UnsatisfiedLinkError t) { + // If native logging is unavailable, log to system log. + fallbackLogger.setLevel(Level.ALL); - private static boolean loadNativeLibrary() { - if (nativeLibStatus == NativeLibStatus.UNINITIALIZED) { - try { - System.loadLibrary("jingle_peerconnection_so"); - nativeLibStatus = NativeLibStatus.LOADED; - } catch (UnsatisfiedLinkError t) { - nativeLibStatus = NativeLibStatus.FAILED; - fallbackLogger.log(Level.WARNING, "Failed to load jingle_peerconnection_so: ", t); - } + fallbackLogger.log(Level.WARNING, "Failed to load jingle_peerconnection_so: ", t); } - return nativeLibStatus == NativeLibStatus.LOADED; } // Keep in sync with webrtc/common_types.h:TraceLevel. @@ -80,7 +63,7 @@ public class Logging { public enum Severity { LS_SENSITIVE, LS_VERBOSE, LS_INFO, LS_WARNING, LS_ERROR, LS_NONE } public static void enableLogThreads() { - if (!loadNativeLibrary()) { + if (!nativeLibLoaded) { fallbackLogger.log(Level.WARNING, "Cannot enable log thread because native lib not loaded."); return; } @@ -88,7 +71,7 @@ public class Logging { } public static void enableLogTimeStamps() { - if (!loadNativeLibrary()) { + if (!nativeLibLoaded) { fallbackLogger.log( Level.WARNING, "Cannot enable log timestamps because native lib not loaded."); return; @@ -100,7 +83,7 @@ public class Logging { // On Android, use "logcat:" for |path| to send output there. // Note: this function controls the output of the WEBRTC_TRACE() macros. public static synchronized void enableTracing(String path, EnumSet levels) { - if (!loadNativeLibrary()) { + if (!nativeLibLoaded) { fallbackLogger.log(Level.WARNING, "Cannot enable tracing because native lib not loaded."); return; } @@ -120,7 +103,7 @@ public class Logging { // output. On Android, the output will be directed to Logcat. // Note: this function starts collecting the output of the LOG() macros. public static synchronized void enableLogToDebugOutput(Severity severity) { - if (!loadNativeLibrary()) { + if (!nativeLibLoaded) { fallbackLogger.log(Level.WARNING, "Cannot enable logging because native lib not loaded."); return; } diff --git a/webrtc/sdk/android/api/org/webrtc/FileVideoCapturer.java b/webrtc/sdk/android/api/org/webrtc/FileVideoCapturer.java index a71e9327ae..a0552247c9 100644 --- a/webrtc/sdk/android/api/org/webrtc/FileVideoCapturer.java +++ b/webrtc/sdk/android/api/org/webrtc/FileVideoCapturer.java @@ -20,10 +20,6 @@ import java.io.RandomAccessFile; import java.io.IOException; public class FileVideoCapturer implements VideoCapturer { - static { - System.loadLibrary("jingle_peerconnection_so"); - } - private interface VideoReader { int getFrameWidth(); int getFrameHeight(); diff --git a/webrtc/sdk/android/api/org/webrtc/VideoFileRenderer.java b/webrtc/sdk/android/api/org/webrtc/VideoFileRenderer.java index 17676c0d82..02a4a3fd0f 100644 --- a/webrtc/sdk/android/api/org/webrtc/VideoFileRenderer.java +++ b/webrtc/sdk/android/api/org/webrtc/VideoFileRenderer.java @@ -22,10 +22,6 @@ import java.util.ArrayList; * Can be used to save the video frames to file. */ public class VideoFileRenderer implements VideoRenderer.Callbacks { - static { - System.loadLibrary("jingle_peerconnection_so"); - } - private static final String TAG = "VideoFileRenderer"; private final HandlerThread renderThread;