Log to the webrtc log stream from webrtc/modules java code.

The purpose is to gather all webrtc logging in a single place and allow the app to redirect all webrtc logging to a single stream for offline debugging.

Moved Logging.java to webrtc/base to be shared by talk/ and modules/.

R=glaznev@webrtc.org, henrika@webrtc.org, magjed@webrtc.org, tommi@webrtc.org

Review URL: https://codereview.webrtc.org/1335103004 .

Cr-Commit-Position: refs/heads/master@{#9959}
This commit is contained in:
Jiayang Liu 2015-09-16 16:20:36 -07:00
parent 2520e7200e
commit 7754285f7c
12 changed files with 83 additions and 78 deletions

View File

@ -111,8 +111,12 @@
'type': 'none',
'actions': [
{
# TODO(jiayl): extract peerconnection_java_files and android_java_files into a webrtc
# gyp var that can be included here, or better yet, build a proper .jar in webrtc
# and include it here.
'variables': {
'java_src_dir': 'app/webrtc/java/src',
'webrtc_base_dir': '<(webrtc_root)/base',
'webrtc_modules_dir': '<(webrtc_root)/modules',
'build_jar_log': '<(INTERMEDIATE_DIR)/build_jar.log',
'peerconnection_java_files': [
@ -121,7 +125,6 @@
'app/webrtc/java/src/org/webrtc/CallSessionFileRotatingLogSink.java',
'app/webrtc/java/src/org/webrtc/DataChannel.java',
'app/webrtc/java/src/org/webrtc/IceCandidate.java',
'app/webrtc/java/src/org/webrtc/Logging.java',
'app/webrtc/java/src/org/webrtc/MediaConstraints.java',
'app/webrtc/java/src/org/webrtc/MediaSource.java',
'app/webrtc/java/src/org/webrtc/MediaStream.java',
@ -136,10 +139,8 @@
'app/webrtc/java/src/org/webrtc/VideoRenderer.java',
'app/webrtc/java/src/org/webrtc/VideoSource.java',
'app/webrtc/java/src/org/webrtc/VideoTrack.java',
'<(webrtc_base_dir)/java/src/org/webrtc/Logging.java',
],
# TODO(fischman): extract this into a webrtc gyp var that can be
# included here, or better yet, build a proper .jar in webrtc
# and include it here.
'android_java_files': [
'app/webrtc/java/android/org/webrtc/Camera2Enumerator.java',
'app/webrtc/java/android/org/webrtc/CameraEnumerationAndroid.java',
@ -219,9 +220,11 @@
],
'variables': {
'java_in_dir': 'app/webrtc/java',
'webrtc_base_dir': '<(webrtc_root)/base',
'webrtc_modules_dir': '<(webrtc_root)/modules',
'additional_src_dirs' : [
'app/webrtc/java/android',
'<(webrtc_base_dir)/java/src',
'<(webrtc_modules_dir)/audio_device/android/java/src',
'<(webrtc_modules_dir)/video_capture/android/java/src',
'<(webrtc_modules_dir)/video_render/android/java/src',

View File

@ -1,41 +1,26 @@
/*
* libjingle
* Copyright 2013 Google Inc.
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
package org.webrtc;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.util.EnumSet;
/** Java wrapper for WebRTC & libjingle logging. */
/** Java wrapper for WebRTC logging. */
public class Logging {
static {
System.loadLibrary("jingle_peerconnection_so");
try {
System.loadLibrary("jingle_peerconnection_so");
} catch (Throwable t) {
}
}
// Keep in sync with webrtc/common_types.h:TraceLevel.
@ -87,7 +72,10 @@ public class Logging {
}
public static void log(Severity severity, String tag, String message) {
nativeLog(severity.ordinal(), tag, message);
try {
nativeLog(severity.ordinal(), tag, message);
} catch (Throwable t) {
}
}
public static void d(String tag, String message) {

View File

@ -239,6 +239,7 @@
'type': 'none',
'variables': {
'java_in_dir': '<(webrtc_root)/modules/video_capture/android/java',
'additional_src_dirs': [ '<(webrtc_root)/base/java/src', ],
},
'includes': [
'../../build/java.gypi',
@ -249,6 +250,7 @@
'type': 'none',
'variables': {
'java_in_dir': '<(webrtc_root)/modules/audio_device/android/java',
'additional_src_dirs': [ '<(webrtc_root)/base/java/src', ],
'never_lint': 1,
},
'includes': [

View File

@ -17,7 +17,8 @@ import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.os.Build;
import android.util.Log;
import org.webrtc.Logging;
import java.lang.Math;
@ -244,11 +245,11 @@ class WebRtcAudioManager {
}
private static void Logd(String msg) {
Log.d(TAG, msg);
Logging.d(TAG, msg);
}
private static void Loge(String msg) {
Log.e(TAG, msg);
Logging.e(TAG, msg);
}
private native void nativeCacheAudioParameters(

View File

@ -24,7 +24,8 @@ import android.media.MediaRecorder.AudioSource;
import android.os.Build;
import android.os.Process;
import android.os.SystemClock;
import android.util.Log;
import org.webrtc.Logging;
class WebRtcAudioRecord {
private static final boolean DEBUG = false;
@ -271,11 +272,11 @@ class WebRtcAudioRecord {
}
private static void Logd(String msg) {
Log.d(TAG, msg);
Logging.d(TAG, msg);
}
private static void Loge(String msg) {
Log.e(TAG, msg);
Logging.e(TAG, msg);
}
private native void nativeCacheDirectBufferAddress(

View File

@ -18,7 +18,8 @@ import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.os.Process;
import android.util.Log;
import org.webrtc.Logging;
class WebRtcAudioTrack {
private static final boolean DEBUG = true;
@ -248,11 +249,11 @@ class WebRtcAudioTrack {
}
private static void Logd(String msg) {
Log.d(TAG, msg);
Logging.d(TAG, msg);
}
private static void Loge(String msg) {
Log.e(TAG, msg);
Logging.e(TAG, msg);
}
private native void nativeCacheDirectBufferAddress(

View File

@ -18,7 +18,8 @@ import android.media.audiofx.AudioEffect.Descriptor;
import android.media.AudioManager;
import android.os.Build;
import android.os.Process;
import android.util.Log;
import org.webrtc.Logging;
import java.lang.Thread;
@ -109,7 +110,7 @@ public final class WebRtcAudioUtils {
// Information about the current build, taken from system properties.
public static void logDeviceInfo(String tag) {
Log.d(tag, "Android SDK: " + Build.VERSION.SDK_INT + ", "
Logging.d(tag, "Android SDK: " + Build.VERSION.SDK_INT + ", "
+ "Release: " + Build.VERSION.RELEASE + ", "
+ "Brand: " + Build.BRAND + ", "
+ "Device: " + Build.DEVICE + ", "

View File

@ -13,7 +13,9 @@
'type': 'none',
'variables': {
'java_in_dir': 'audio_device/android/java',
'additional_src_dirs': [ '../base/java/src', ],
},
'includes': [ '../../build/java.gypi' ],
}, # audio_device_module_java
{
@ -24,6 +26,7 @@
],
'variables': {
'java_in_dir': 'video_capture/android/java',
'additional_src_dirs': [ '../base/java/src', ],
},
'includes': [ '../../build/java.gypi' ],
}, # video_capture_module_java
@ -32,6 +35,7 @@
'type': 'none',
'variables': {
'java_in_dir': 'video_render/android/java',
'additional_src_dirs': [ '../base/java/src', ],
},
'includes': [ '../../build/java.gypi' ],
}, # video_render_module_java

View File

@ -25,12 +25,13 @@ import android.opengl.GLES20;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceHolder;
import android.view.WindowManager;
import org.webrtc.Logging;
// Wrapper for android Camera, with support for direct local preview rendering.
// Threading notes: this class is called from ViE C++ code, and from Camera &
// SurfaceHolder Java callbacks. Since these calls happen on different threads,
@ -102,7 +103,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
private synchronized boolean startCapture(
final int width, final int height,
final int min_mfps, final int max_mfps) {
Log.d(TAG, "startCapture: " + width + "x" + height + "@" +
Logging.d(TAG, "startCapture: " + width + "x" + height + "@" +
min_mfps + ":" + max_mfps);
if (cameraThread != null || cameraThreadHandler != null) {
throw new RuntimeException("Camera thread already started!");
@ -164,10 +165,10 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
}
}
Log.d(TAG, "Camera orientation: " + info.orientation +
Logging.d(TAG, "Camera orientation: " + info.orientation +
" .Device orientation: " + getDeviceOrientation());
Camera.Parameters parameters = camera.getParameters();
Log.d(TAG, "isVideoStabilizationSupported: " +
Logging.d(TAG, "isVideoStabilizationSupported: " +
parameters.isVideoStabilizationSupported());
if (parameters.isVideoStabilizationSupported()) {
parameters.setVideoStabilization(true);
@ -193,17 +194,17 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
}
}
if (frameDropRatio == Integer.MAX_VALUE) {
Log.e(TAG, "Can not find camera fps range");
Logging.e(TAG, "Can not find camera fps range");
error = new RuntimeException("Can not find camera fps range");
exchange(result, false);
return;
}
if (frameDropRatio > 1) {
Log.d(TAG, "Frame dropper is enabled. Ratio: " + frameDropRatio);
Logging.d(TAG, "Frame dropper is enabled. Ratio: " + frameDropRatio);
}
min_mfps *= frameDropRatio;
max_mfps *= frameDropRatio;
Log.d(TAG, "Camera preview mfps range: " + min_mfps + " - " + max_mfps);
Logging.d(TAG, "Camera preview mfps range: " + min_mfps + " - " + max_mfps);
parameters.setPreviewFpsRange(min_mfps, max_mfps);
int format = ImageFormat.NV21;
@ -224,7 +225,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
} catch (RuntimeException e) {
error = e;
}
Log.e(TAG, "startCapture failed", error);
Logging.e(TAG, "startCapture failed", error);
if (camera != null) {
Exchanger<Boolean> resultDropper = new Exchanger<Boolean>();
stopCaptureOnCameraThread(resultDropper);
@ -236,7 +237,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
// Called by native code. Returns true when camera is known to be stopped.
private synchronized boolean stopCapture() {
Log.d(TAG, "stopCapture");
Logging.d(TAG, "stopCapture");
final Exchanger<Boolean> result = new Exchanger<Boolean>();
cameraThreadHandler.post(new Runnable() {
@Override public void run() {
@ -251,7 +252,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
}
cameraThreadHandler = null;
cameraThread = null;
Log.d(TAG, "stopCapture done");
Logging.d(TAG, "stopCapture done");
return status;
}
@ -285,7 +286,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
} catch (RuntimeException e) {
error = e;
}
Log.e(TAG, "Failed to stop camera", error);
Logging.e(TAG, "Failed to stop camera", error);
exchange(result, false);
Looper.myLooper().quit();
return;
@ -341,7 +342,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
double durationMs = captureTimeMs - lastCaptureTimeMs;
averageDurationMs = 0.9 * averageDurationMs + 0.1 * durationMs;
if ((frameCount % 30) == 0) {
Log.d(TAG, "Camera TS " + captureTimeMs +
Logging.d(TAG, "Camera TS " + captureTimeMs +
". Duration: " + (int)durationMs + " ms. FPS: " +
(int) (1000 / averageDurationMs + 0.5));
}
@ -380,7 +381,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
private void setPreviewRotationOnCameraThread(
int rotation, Exchanger<IOException> result) {
Log.v(TAG, "setPreviewRotation:" + rotation);
Logging.v(TAG, "setPreviewRotation:" + rotation);
int resultRotation = 0;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
@ -398,13 +399,13 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
@Override
public synchronized void surfaceChanged(
SurfaceHolder holder, int format, int width, int height) {
Log.d(TAG, "VideoCaptureAndroid::surfaceChanged ignored: " +
Logging.d(TAG, "VideoCaptureAndroid::surfaceChanged ignored: " +
format + ": " + width + "x" + height);
}
@Override
public synchronized void surfaceCreated(final SurfaceHolder holder) {
Log.d(TAG, "VideoCaptureAndroid::surfaceCreated");
Logging.d(TAG, "VideoCaptureAndroid::surfaceCreated");
if (camera == null || cameraThreadHandler == null) {
return;
}
@ -422,7 +423,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
@Override
public synchronized void surfaceDestroyed(SurfaceHolder holder) {
Log.d(TAG, "VideoCaptureAndroid::surfaceDestroyed");
Logging.d(TAG, "VideoCaptureAndroid::surfaceDestroyed");
if (camera == null || cameraThreadHandler == null) {
return;
}

View File

@ -16,12 +16,13 @@ import android.hardware.Camera.CameraInfo;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.Size;
import android.hardware.Camera;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.webrtc.Logging;
public class VideoCaptureDeviceInfoAndroid {
private final static String TAG = "WEBRTC-JC";
@ -57,9 +58,9 @@ public class VideoCaptureDeviceInfoAndroid {
Parameters parameters = camera.getParameters();
supportedSizes = parameters.getSupportedPreviewSizes();
supportedFpsRanges = parameters.getSupportedPreviewFpsRange();
Log.d(TAG, uniqueName);
Logging.d(TAG, uniqueName);
} catch (RuntimeException e) {
Log.e(TAG, "Failed to open " + uniqueName + ", skipping", e);
Logging.e(TAG, "Failed to open " + uniqueName + ", skipping", e);
continue;
} finally {
if (camera != null) {
@ -91,7 +92,7 @@ public class VideoCaptureDeviceInfoAndroid {
}
}
if (is30fpsRange && !is15fpsRange) {
Log.d(TAG, "Adding 15 fps support");
Logging.d(TAG, "Adding 15 fps support");
int[] newRange = new int [Parameters.PREVIEW_FPS_MAX_INDEX + 1];
newRange[Parameters.PREVIEW_FPS_MIN_INDEX] = 15000;
newRange[Parameters.PREVIEW_FPS_MAX_INDEX] = 15000;
@ -123,7 +124,7 @@ public class VideoCaptureDeviceInfoAndroid {
.put("mfpsRanges", mfpsRanges);
}
String ret = devices.toString(2);
Log.d(TAG, ret);
Logging.d(TAG, ret);
return ret;
} catch (JSONException e) {
throw new RuntimeException(e);

View File

@ -23,7 +23,8 @@ import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.Log;
import org.webrtc.Logging;
public class ViEAndroidGLES20 extends GLSurfaceView
implements GLSurfaceView.Renderer {
@ -85,7 +86,7 @@ public class ViEAndroidGLES20 extends GLSurfaceView
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
Log.w(TAG, "creating OpenGL ES 2.0 context");
Logging.w(TAG, "creating OpenGL ES 2.0 context");
checkEglError("Before eglCreateContext", egl);
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
EGLContext context = egl.eglCreateContext(display, eglConfig,
@ -102,7 +103,7 @@ public class ViEAndroidGLES20 extends GLSurfaceView
private static void checkEglError(String prompt, EGL10 egl) {
int error;
while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) {
Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));
Logging.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));
}
}
@ -193,9 +194,9 @@ public class ViEAndroidGLES20 extends GLSurfaceView
private void printConfigs(EGL10 egl, EGLDisplay display,
EGLConfig[] configs) {
int numConfigs = configs.length;
Log.w(TAG, String.format("%d configurations", numConfigs));
Logging.w(TAG, String.format("%d configurations", numConfigs));
for (int i = 0; i < numConfigs; i++) {
Log.w(TAG, String.format("Configuration %d:\n", i));
Logging.w(TAG, String.format("Configuration %d:\n", i));
printConfig(egl, display, configs[i]);
}
}
@ -277,9 +278,9 @@ public class ViEAndroidGLES20 extends GLSurfaceView
int attribute = attributes[i];
String name = names[i];
if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
Log.w(TAG, String.format(" %s: %d\n", name, value[0]));
Logging.w(TAG, String.format(" %s: %d\n", name, value[0]));
} else {
// Log.w(TAG, String.format(" %s: failed\n", name));
// Logging.w(TAG, String.format(" %s: failed\n", name));
while (egl.eglGetError() != EGL10.EGL_SUCCESS);
}
}

View File

@ -21,11 +21,12 @@ import java.nio.ByteBuffer;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.SurfaceHolder.Callback;
import org.webrtc.Logging;
public class ViESurfaceRenderer implements Callback {
private final static String TAG = "WEBRTC";
@ -58,11 +59,11 @@ public class ViESurfaceRenderer implements Callback {
public void surfaceChanged(SurfaceHolder holder, int format,
int in_width, int in_height) {
Log.d(TAG, "ViESurfaceRender::surfaceChanged");
Logging.d(TAG, "ViESurfaceRender::surfaceChanged");
changeDestRect(in_width, in_height);
Log.d(TAG, "ViESurfaceRender::surfaceChanged" +
Logging.d(TAG, "ViESurfaceRender::surfaceChanged" +
" in_width:" + in_width + " in_height:" + in_height +
" srcRect.left:" + srcRect.left +
" srcRect.top:" + srcRect.top +
@ -80,7 +81,7 @@ public class ViESurfaceRenderer implements Callback {
Rect dst = surfaceHolder.getSurfaceFrame();
if(dst != null) {
changeDestRect(dst.right - dst.left, dst.bottom - dst.top);
Log.d(TAG, "ViESurfaceRender::surfaceCreated" +
Logging.d(TAG, "ViESurfaceRender::surfaceCreated" +
" dst.left:" + dst.left +
" dst.top:" + dst.top +
" dst.right:" + dst.right +
@ -99,13 +100,13 @@ public class ViESurfaceRenderer implements Callback {
}
public void surfaceDestroyed(SurfaceHolder holder) {
Log.d(TAG, "ViESurfaceRenderer::surfaceDestroyed");
Logging.d(TAG, "ViESurfaceRenderer::surfaceDestroyed");
bitmap = null;
byteBuffer = null;
}
public Bitmap CreateBitmap(int width, int height) {
Log.d(TAG, "CreateByteBitmap " + width + ":" + height);
Logging.d(TAG, "CreateByteBitmap " + width + ":" + height);
if (bitmap == null) {
try {
android.os.Process.setThreadPriority(
@ -123,7 +124,7 @@ public class ViESurfaceRenderer implements Callback {
}
public ByteBuffer CreateByteBuffer(int width, int height) {
Log.d(TAG, "CreateByteBuffer " + width + ":" + height);
Logging.d(TAG, "CreateByteBuffer " + width + ":" + height);
if (bitmap == null) {
bitmap = CreateBitmap(width, height);
byteBuffer = ByteBuffer.allocateDirect(width * height * 2);
@ -133,7 +134,7 @@ public class ViESurfaceRenderer implements Callback {
public void SetCoordinates(float left, float top,
float right, float bottom) {
Log.d(TAG, "SetCoordinates " + left + "," + top + ":" +
Logging.d(TAG, "SetCoordinates " + left + "," + top + ":" +
right + "," + bottom);
dstLeftScale = left;
dstTopScale = top;