PeerConnection.java: enable setting trace & log levels from Java
Replaces the hard-coded scheme that was there before and lets apps decide what to log and to where. R=wu@webrtc.org Review URL: https://webrtc-codereview.appspot.com/1969004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@4498 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
c4e1ab515b
commit
c883fdc273
@ -1013,16 +1013,7 @@ extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
|
|||||||
return -1;
|
return -1;
|
||||||
g_class_reference_holder = new ClassReferenceHolder(jni);
|
g_class_reference_holder = new ClassReferenceHolder(jni);
|
||||||
|
|
||||||
#ifdef ANDROID
|
|
||||||
webrtc::Trace::CreateTrace();
|
webrtc::Trace::CreateTrace();
|
||||||
CHECK(!webrtc::Trace::SetTraceFile("/sdcard/trace.txt", false),
|
|
||||||
"SetTraceFile failed");
|
|
||||||
CHECK(!webrtc::Trace::SetLevelFilter(webrtc::kTraceAll),
|
|
||||||
"SetLevelFilter failed");
|
|
||||||
#endif // ANDROID
|
|
||||||
|
|
||||||
// Uncomment to get sensitive logs emitted (to stderr or logcat).
|
|
||||||
// talk_base::LogMessage::LogToDebug(talk_base::LS_SENSITIVE);
|
|
||||||
|
|
||||||
return JNI_VERSION_1_6;
|
return JNI_VERSION_1_6;
|
||||||
}
|
}
|
||||||
@ -1091,6 +1082,19 @@ JOW(void, DataChannel_dispose)(JNIEnv* jni, jobject j_dc) {
|
|||||||
ExtractNativeDC(jni, j_dc)->Release();
|
ExtractNativeDC(jni, j_dc)->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JOW(void, Logging_nativeEnableTracing)(
|
||||||
|
JNIEnv* jni, jclass, jstring j_path, jint nativeLevels,
|
||||||
|
jint nativeSeverity) {
|
||||||
|
std::string path = JavaToStdString(jni, j_path);
|
||||||
|
if (nativeLevels != webrtc::kTraceNone) {
|
||||||
|
CHECK(!webrtc::Trace::SetTraceFile(path.c_str(), false),
|
||||||
|
"SetTraceFile failed");
|
||||||
|
CHECK(!webrtc::Trace::SetLevelFilter(nativeLevels),
|
||||||
|
"SetLevelFilter failed");
|
||||||
|
}
|
||||||
|
talk_base::LogMessage::LogToDebug(nativeSeverity);
|
||||||
|
}
|
||||||
|
|
||||||
JOW(void, PeerConnection_freePeerConnection)(JNIEnv*, jclass, jlong j_p) {
|
JOW(void, PeerConnection_freePeerConnection)(JNIEnv*, jclass, jlong j_p) {
|
||||||
reinterpret_cast<PeerConnectionInterface*>(j_p)->Release();
|
reinterpret_cast<PeerConnectionInterface*>(j_p)->Release();
|
||||||
}
|
}
|
||||||
|
80
talk/app/webrtc/java/src/org/webrtc/Logging.java
Normal file
80
talk/app/webrtc/java/src/org/webrtc/Logging.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* libjingle
|
||||||
|
* Copyright 2013, Google Inc.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.webrtc;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
/** Java wrapper for WebRTC & libjingle logging. */
|
||||||
|
public class Logging {
|
||||||
|
static {
|
||||||
|
System.loadLibrary("jingle_peerconnection_so");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep in sync with webrtc/common_types.h:TraceLevel.
|
||||||
|
public enum TraceLevel {
|
||||||
|
TRACE_NONE(0x0000),
|
||||||
|
TRACE_STATEINFO(0x0001),
|
||||||
|
TRACE_WARNING(0x0002),
|
||||||
|
TRACE_ERROR(0x0004),
|
||||||
|
TRACE_CRITICAL(0x0008),
|
||||||
|
TRACE_APICALL(0x0010),
|
||||||
|
TRACE_DEFAULT(0x00ff),
|
||||||
|
TRACE_MODULECALL(0x0020),
|
||||||
|
TRACE_MEMORY(0x0100),
|
||||||
|
TRACE_TIMER(0x0200),
|
||||||
|
TRACE_STREAM(0x0400),
|
||||||
|
TRACE_DEBUG(0x0800),
|
||||||
|
TRACE_INFO(0x1000),
|
||||||
|
TRACE_TERSEINFO(0x2000),
|
||||||
|
TRACE_ALL(0xffff);
|
||||||
|
|
||||||
|
public final int level;
|
||||||
|
TraceLevel(int level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Keep in sync with talk/base/logging.h:LoggingSeverity.
|
||||||
|
public enum Severity {
|
||||||
|
LS_SENSITIVE, LS_VERBOSE, LS_INFO, LS_WARNING, LS_ERROR,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Enable tracing to |path| at |levels| and |severity|.
|
||||||
|
public static void enableTracing(
|
||||||
|
String path, EnumSet<TraceLevel> levels, Severity severity) {
|
||||||
|
int nativeLevel = 0;
|
||||||
|
for (TraceLevel level : levels) {
|
||||||
|
nativeLevel |= level.level;
|
||||||
|
}
|
||||||
|
nativeEnableTracing(path, nativeLevel, severity.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native void nativeEnableTracing(
|
||||||
|
String path, int nativeLevels, int nativeSeverity);
|
||||||
|
}
|
@ -38,6 +38,7 @@ import java.lang.ref.WeakReference;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -474,6 +475,12 @@ public class PeerConnectionTest extends TestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompleteSession() throws Exception {
|
public void testCompleteSession() throws Exception {
|
||||||
|
// Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
|
||||||
|
// Logging.enableTracing(
|
||||||
|
// "/tmp/AMI-nope.txt",
|
||||||
|
// EnumSet.of(Logging.TraceLevel.TRACE_ALL),
|
||||||
|
// Logging.Severity.LS_SENSITIVE);
|
||||||
|
|
||||||
CountDownLatch testDone = new CountDownLatch(1);
|
CountDownLatch testDone = new CountDownLatch(1);
|
||||||
|
|
||||||
PeerConnectionFactory factory = new PeerConnectionFactory();
|
PeerConnectionFactory factory = new PeerConnectionFactory();
|
||||||
|
@ -44,6 +44,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.webrtc.DataChannel;
|
import org.webrtc.DataChannel;
|
||||||
import org.webrtc.IceCandidate;
|
import org.webrtc.IceCandidate;
|
||||||
|
import org.webrtc.Logging;
|
||||||
import org.webrtc.MediaConstraints;
|
import org.webrtc.MediaConstraints;
|
||||||
import org.webrtc.MediaStream;
|
import org.webrtc.MediaStream;
|
||||||
import org.webrtc.PeerConnection;
|
import org.webrtc.PeerConnection;
|
||||||
@ -58,6 +59,7 @@ import org.webrtc.VideoRenderer.I420Frame;
|
|||||||
import org.webrtc.VideoSource;
|
import org.webrtc.VideoSource;
|
||||||
import org.webrtc.VideoTrack;
|
import org.webrtc.VideoTrack;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -98,6 +100,12 @@ public class AppRTCDemoActivity extends Activity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
|
||||||
|
// Logging.enableTracing(
|
||||||
|
// "/sdcard/trace.txt",
|
||||||
|
// EnumSet.of(Logging.TraceLevel.TRACE_ALL),
|
||||||
|
// Logging.Severity.LS_SENSITIVE);
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
wakeLock = powerManager.newWakeLock(
|
wakeLock = powerManager.newWakeLock(
|
||||||
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "AppRTCDemo");
|
PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "AppRTCDemo");
|
||||||
|
@ -86,6 +86,7 @@
|
|||||||
'app/webrtc/java/src/org/webrtc/AudioTrack.java',
|
'app/webrtc/java/src/org/webrtc/AudioTrack.java',
|
||||||
'app/webrtc/java/src/org/webrtc/DataChannel.java',
|
'app/webrtc/java/src/org/webrtc/DataChannel.java',
|
||||||
'app/webrtc/java/src/org/webrtc/IceCandidate.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/MediaConstraints.java',
|
||||||
'app/webrtc/java/src/org/webrtc/MediaSource.java',
|
'app/webrtc/java/src/org/webrtc/MediaSource.java',
|
||||||
'app/webrtc/java/src/org/webrtc/MediaStream.java',
|
'app/webrtc/java/src/org/webrtc/MediaStream.java',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user