Do not initialize internal tracer if it has already been initialized.
Bug: b/68989834 Change-Id: I7bb02d58cef5c14c6433d1fc7a95b46ff2b27f6f Reviewed-on: https://webrtc-review.googlesource.com/23280 Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Commit-Queue: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20696}
This commit is contained in:
committed by
Commit Bot
parent
c48badaed6
commit
4e3832124f
@ -568,6 +568,7 @@ if (rtc_include_tests) {
|
|||||||
"instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java",
|
"instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java",
|
||||||
"instrumentationtests/src/org/webrtc/MediaCodecVideoEncoderTest.java",
|
"instrumentationtests/src/org/webrtc/MediaCodecVideoEncoderTest.java",
|
||||||
"instrumentationtests/src/org/webrtc/NetworkMonitorTest.java",
|
"instrumentationtests/src/org/webrtc/NetworkMonitorTest.java",
|
||||||
|
"instrumentationtests/src/org/webrtc/PeerConnectionFactoryTest.java",
|
||||||
"instrumentationtests/src/org/webrtc/PeerConnectionTest.java",
|
"instrumentationtests/src/org/webrtc/PeerConnectionTest.java",
|
||||||
"instrumentationtests/src/org/webrtc/RendererCommonTest.java",
|
"instrumentationtests/src/org/webrtc/RendererCommonTest.java",
|
||||||
"instrumentationtests/src/org/webrtc/SurfaceTextureHelperTest.java",
|
"instrumentationtests/src/org/webrtc/SurfaceTextureHelperTest.java",
|
||||||
|
|||||||
@ -29,7 +29,9 @@ public class PeerConnectionFactory {
|
|||||||
|
|
||||||
private static final String TAG = "PeerConnectionFactory";
|
private static final String TAG = "PeerConnectionFactory";
|
||||||
private static final String VIDEO_CAPTURER_THREAD_NAME = "VideoCapturerThread";
|
private static final String VIDEO_CAPTURER_THREAD_NAME = "VideoCapturerThread";
|
||||||
|
|
||||||
private final long nativeFactory;
|
private final long nativeFactory;
|
||||||
|
private static volatile boolean internalTracerInitialized = false;
|
||||||
private static Context applicationContext;
|
private static Context applicationContext;
|
||||||
private static Thread networkThread;
|
private static Thread networkThread;
|
||||||
private static Thread workerThread;
|
private static Thread workerThread;
|
||||||
@ -120,7 +122,7 @@ public class PeerConnectionFactory {
|
|||||||
NativeLibrary.initialize(options.nativeLibraryLoader);
|
NativeLibrary.initialize(options.nativeLibraryLoader);
|
||||||
nativeInitializeAndroidGlobals(options.applicationContext, options.enableVideoHwAcceleration);
|
nativeInitializeAndroidGlobals(options.applicationContext, options.enableVideoHwAcceleration);
|
||||||
initializeFieldTrials(options.fieldTrials);
|
initializeFieldTrials(options.fieldTrials);
|
||||||
if (options.enableInternalTracer) {
|
if (options.enableInternalTracer && !internalTracerInitialized) {
|
||||||
initializeInternalTracer();
|
initializeInternalTracer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,6 +156,17 @@ public class PeerConnectionFactory {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void initializeInternalTracer() {
|
||||||
|
internalTracerInitialized = true;
|
||||||
|
nativeInitializeInternalTracer();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shutdownInternalTracer() {
|
||||||
|
internalTracerInitialized = false;
|
||||||
|
nativeShutdownInternalTracer();
|
||||||
|
}
|
||||||
|
|
||||||
// Field trial initialization. Must be called before PeerConnectionFactory
|
// Field trial initialization. Must be called before PeerConnectionFactory
|
||||||
// is created.
|
// is created.
|
||||||
// Deprecated, use PeerConnectionFactory.initialize instead.
|
// Deprecated, use PeerConnectionFactory.initialize instead.
|
||||||
@ -172,10 +185,10 @@ public class PeerConnectionFactory {
|
|||||||
// Internal tracing initialization. Must be called before PeerConnectionFactory is created to
|
// Internal tracing initialization. Must be called before PeerConnectionFactory is created to
|
||||||
// prevent racing with tracing code.
|
// prevent racing with tracing code.
|
||||||
// Deprecated, use PeerConnectionFactory.initialize instead.
|
// Deprecated, use PeerConnectionFactory.initialize instead.
|
||||||
@Deprecated public static native void initializeInternalTracer();
|
private static native void nativeInitializeInternalTracer();
|
||||||
// Internal tracing shutdown, called to prevent resource leaks. Must be called after
|
// Internal tracing shutdown, called to prevent resource leaks. Must be called after
|
||||||
// PeerConnectionFactory is gone to prevent races with code performing tracing.
|
// PeerConnectionFactory is gone to prevent races with code performing tracing.
|
||||||
public static native void shutdownInternalTracer();
|
private static native void nativeShutdownInternalTracer();
|
||||||
// Start/stop internal capturing of internal tracing.
|
// Start/stop internal capturing of internal tracing.
|
||||||
public static native boolean startInternalTracingCapture(String tracing_filename);
|
public static native boolean startInternalTracingCapture(String tracing_filename);
|
||||||
public static native void stopInternalTracingCapture();
|
public static native void stopInternalTracingCapture();
|
||||||
|
|||||||
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* 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 android.support.test.InstrumentationRegistry;
|
||||||
|
import android.support.test.filters.SmallTest;
|
||||||
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class PeerConnectionFactoryTest {
|
||||||
|
@SmallTest
|
||||||
|
@Test
|
||||||
|
public void testInitialize() {
|
||||||
|
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
|
||||||
|
.builder(InstrumentationRegistry.getTargetContext())
|
||||||
|
.createInitializationOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
|
@Test
|
||||||
|
public void testInitializeTwice() {
|
||||||
|
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
|
||||||
|
.builder(InstrumentationRegistry.getTargetContext())
|
||||||
|
.createInitializationOptions());
|
||||||
|
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
|
||||||
|
.builder(InstrumentationRegistry.getTargetContext())
|
||||||
|
.createInitializationOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
|
@Test
|
||||||
|
public void testInitializeTwiceWithTracer() {
|
||||||
|
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
|
||||||
|
.builder(InstrumentationRegistry.getTargetContext())
|
||||||
|
.setEnableInternalTracer(true)
|
||||||
|
.createInitializationOptions());
|
||||||
|
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
|
||||||
|
.builder(InstrumentationRegistry.getTargetContext())
|
||||||
|
.setEnableInternalTracer(true)
|
||||||
|
.createInitializationOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SmallTest
|
||||||
|
@Test
|
||||||
|
public void testInitializeWithTracerAndShutdown() {
|
||||||
|
PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
|
||||||
|
.builder(InstrumentationRegistry.getTargetContext())
|
||||||
|
.setEnableInternalTracer(true)
|
||||||
|
.createInitializationOptions());
|
||||||
|
PeerConnectionFactory.shutdownInternalTracer();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -93,7 +93,7 @@ JNI_FUNCTION_DECLARATION(void,
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNI_FUNCTION_DECLARATION(void,
|
JNI_FUNCTION_DECLARATION(void,
|
||||||
PeerConnectionFactory_initializeInternalTracer,
|
PeerConnectionFactory_nativeInitializeInternalTracer,
|
||||||
JNIEnv* jni,
|
JNIEnv* jni,
|
||||||
jclass) {
|
jclass) {
|
||||||
rtc::tracing::SetupInternalTracer();
|
rtc::tracing::SetupInternalTracer();
|
||||||
@ -132,7 +132,7 @@ JNI_FUNCTION_DECLARATION(void,
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNI_FUNCTION_DECLARATION(void,
|
JNI_FUNCTION_DECLARATION(void,
|
||||||
PeerConnectionFactory_shutdownInternalTracer,
|
PeerConnectionFactory_nativeShutdownInternalTracer,
|
||||||
JNIEnv* jni,
|
JNIEnv* jni,
|
||||||
jclass) {
|
jclass) {
|
||||||
rtc::tracing::ShutdownInternalTracer();
|
rtc::tracing::ShutdownInternalTracer();
|
||||||
|
|||||||
Reference in New Issue
Block a user