Android: Remove static thread references from PeerconnectionFactory
This CL prepares for adding stack trace capability to the native part of the Android PeerConnectionFactory code. The main blocker this CL removes is the static printStackTrace() function. We need this function to be non-static since the C++ counterpart of PCF is non-static. This Cl also performs various other cleanups in surrounding code. This CL: * Removes static thread references from PeerconnectionFactory and turns them into non-static member variables. * Adds a non-static alternative to PeerconnectionFactory.printStackTraces(). * Removes the rtc::Thread::Invoke() calls, and turns them into asynchronous posts. * Consolidates the two different Java PCF ctors into one, so that there is one shared path used by both native API and Java API. Bug: webrtc:10168 Change-Id: I05dbf5b17069d4a115d9adafc25faa121f23b945 Reviewed-on: https://webrtc-review.googlesource.com/c/115961 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26329}
This commit is contained in:
committed by
Commit Bot
parent
dc32cc00e8
commit
fad0893688
@ -29,11 +29,17 @@ public class PeerConnectionFactory {
|
||||
private static final String TAG = "PeerConnectionFactory";
|
||||
private static final String VIDEO_CAPTURER_THREAD_NAME = "VideoCapturerThread";
|
||||
|
||||
private long nativeFactory;
|
||||
private static volatile boolean internalTracerInitialized;
|
||||
@Nullable private static Thread networkThread;
|
||||
@Nullable private static Thread workerThread;
|
||||
@Nullable private static Thread signalingThread;
|
||||
|
||||
// Remove these once deprecated static printStackTrace() is gone.
|
||||
@Nullable private static Thread staticNetworkThread;
|
||||
@Nullable private static Thread staticWorkerThread;
|
||||
@Nullable private static Thread staticSignalingThread;
|
||||
|
||||
private long nativeFactory;
|
||||
@Nullable private volatile Thread networkThread;
|
||||
@Nullable private volatile Thread workerThread;
|
||||
@Nullable private volatile Thread signalingThread;
|
||||
|
||||
public static class InitializationOptions {
|
||||
final Context applicationContext;
|
||||
@ -218,9 +224,17 @@ public class PeerConnectionFactory {
|
||||
}
|
||||
|
||||
public PeerConnectionFactory createPeerConnectionFactory() {
|
||||
return new PeerConnectionFactory(options, audioDeviceModule, audioEncoderFactoryFactory,
|
||||
audioDecoderFactoryFactory, videoEncoderFactory, videoDecoderFactory,
|
||||
audioProcessingFactory, fecControllerFactoryFactory, mediaTransportFactoryFactory);
|
||||
checkInitializeHasBeenCalled();
|
||||
return nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options,
|
||||
audioDeviceModule == null ? 0 : audioDeviceModule.getNativeAudioDeviceModulePointer(),
|
||||
audioEncoderFactoryFactory.createNativeAudioEncoderFactory(),
|
||||
audioDecoderFactoryFactory.createNativeAudioDecoderFactory(), videoEncoderFactory,
|
||||
videoDecoderFactory,
|
||||
audioProcessingFactory == null ? 0 : audioProcessingFactory.createNative(),
|
||||
fecControllerFactoryFactory == null ? 0 : fecControllerFactoryFactory.createNative(),
|
||||
mediaTransportFactoryFactory == null
|
||||
? 0
|
||||
: mediaTransportFactoryFactory.createNativeMediaTransportFactory());
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,7 +267,7 @@ public class PeerConnectionFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkInitializeHasBeenCalled() {
|
||||
private static void checkInitializeHasBeenCalled() {
|
||||
if (!NativeLibrary.isLoaded() || ContextUtils.getApplicationContext() == null) {
|
||||
throw new IllegalStateException(
|
||||
"PeerConnectionFactory.initialize was not called before creating a "
|
||||
@ -298,30 +312,6 @@ public class PeerConnectionFactory {
|
||||
nativeStopInternalTracingCapture();
|
||||
}
|
||||
|
||||
private PeerConnectionFactory(Options options, @Nullable AudioDeviceModule audioDeviceModule,
|
||||
AudioEncoderFactoryFactory audioEncoderFactoryFactory,
|
||||
AudioDecoderFactoryFactory audioDecoderFactoryFactory,
|
||||
@Nullable VideoEncoderFactory videoEncoderFactory,
|
||||
@Nullable VideoDecoderFactory videoDecoderFactory,
|
||||
@Nullable AudioProcessingFactory audioProcessingFactory,
|
||||
@Nullable FecControllerFactoryFactoryInterface fecControllerFactoryFactory,
|
||||
@Nullable MediaTransportFactoryFactory mediaTransportFactoryFactory) {
|
||||
checkInitializeHasBeenCalled();
|
||||
nativeFactory = nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options,
|
||||
audioDeviceModule == null ? 0 : audioDeviceModule.getNativeAudioDeviceModulePointer(),
|
||||
audioEncoderFactoryFactory.createNativeAudioEncoderFactory(),
|
||||
audioDecoderFactoryFactory.createNativeAudioDecoderFactory(), videoEncoderFactory,
|
||||
videoDecoderFactory,
|
||||
audioProcessingFactory == null ? 0 : audioProcessingFactory.createNative(),
|
||||
fecControllerFactoryFactory == null ? 0 : fecControllerFactoryFactory.createNative(),
|
||||
mediaTransportFactoryFactory == null
|
||||
? 0
|
||||
: mediaTransportFactoryFactory.createNativeMediaTransportFactory());
|
||||
if (nativeFactory == 0) {
|
||||
throw new RuntimeException("Failed to initialize PeerConnectionFactory!");
|
||||
}
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
PeerConnectionFactory(long nativeFactory) {
|
||||
checkInitializeHasBeenCalled();
|
||||
@ -463,11 +453,6 @@ public class PeerConnectionFactory {
|
||||
nativeFactory = 0;
|
||||
}
|
||||
|
||||
public void threadsCallbacks() {
|
||||
checkPeerConnectionFactoryExists();
|
||||
nativeInvokeThreadsCallbacks(nativeFactory);
|
||||
}
|
||||
|
||||
/** Returns a pointer to the native webrtc::PeerConnectionFactoryInterface. */
|
||||
public long getNativePeerConnectionFactory() {
|
||||
checkPeerConnectionFactoryExists();
|
||||
@ -498,27 +483,43 @@ public class PeerConnectionFactory {
|
||||
}
|
||||
}
|
||||
|
||||
/** Deprecated, use non-static version instead. */
|
||||
@Deprecated
|
||||
public static void printStackTraces() {
|
||||
printStackTrace(networkThread, "Network thread");
|
||||
printStackTrace(workerThread, "Worker thread");
|
||||
printStackTrace(staticNetworkThread, "Network thread");
|
||||
printStackTrace(staticWorkerThread, "Worker thread");
|
||||
printStackTrace(staticSignalingThread, "Signaling thread");
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the Java stack traces for the critical threads used by PeerConnectionFactory, namely;
|
||||
* signaling thread, worker thread, and network thread. If printNativeStackTraces is true, also
|
||||
* attempt to print the C++ stack traces for these threads.
|
||||
*/
|
||||
public void printInternalStackTraces(boolean printNativeStackTraces) {
|
||||
printStackTrace(signalingThread, "Signaling thread");
|
||||
printStackTrace(workerThread, "Worker thread");
|
||||
printStackTrace(networkThread, "Network thread");
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private static void onNetworkThreadReady() {
|
||||
private void onNetworkThreadReady() {
|
||||
networkThread = Thread.currentThread();
|
||||
staticNetworkThread = networkThread;
|
||||
Logging.d(TAG, "onNetworkThreadReady");
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private static void onWorkerThreadReady() {
|
||||
private void onWorkerThreadReady() {
|
||||
workerThread = Thread.currentThread();
|
||||
staticWorkerThread = workerThread;
|
||||
Logging.d(TAG, "onWorkerThreadReady");
|
||||
}
|
||||
|
||||
@CalledByNative
|
||||
private static void onSignalingThreadReady() {
|
||||
private void onSignalingThreadReady() {
|
||||
signalingThread = Thread.currentThread();
|
||||
staticSignalingThread = signalingThread;
|
||||
Logging.d(TAG, "onSignalingThreadReady");
|
||||
}
|
||||
|
||||
@ -534,10 +535,11 @@ public class PeerConnectionFactory {
|
||||
private static native boolean nativeStartInternalTracingCapture(String tracingFilename);
|
||||
private static native void nativeStopInternalTracingCapture();
|
||||
|
||||
private static native long nativeCreatePeerConnectionFactory(Context context, Options options,
|
||||
long nativeAudioDeviceModule, long audioEncoderFactory, long audioDecoderFactory,
|
||||
VideoEncoderFactory encoderFactory, VideoDecoderFactory decoderFactory,
|
||||
long nativeAudioProcessor, long nativeFecControllerFactory, long mediaTransportFactory);
|
||||
private static native PeerConnectionFactory nativeCreatePeerConnectionFactory(Context context,
|
||||
Options options, long nativeAudioDeviceModule, long audioEncoderFactory,
|
||||
long audioDecoderFactory, VideoEncoderFactory encoderFactory,
|
||||
VideoDecoderFactory decoderFactory, long nativeAudioProcessor,
|
||||
long nativeFecControllerFactory, long mediaTransportFactory);
|
||||
|
||||
private static native long nativeCreatePeerConnection(long factory,
|
||||
PeerConnection.RTCConfiguration rtcConfig, MediaConstraints constraints, long nativeObserver,
|
||||
@ -552,7 +554,6 @@ public class PeerConnectionFactory {
|
||||
private static native boolean nativeStartAecDump(
|
||||
long factory, int file_descriptor, int filesize_limit_bytes);
|
||||
private static native void nativeStopAecDump(long factory);
|
||||
private static native void nativeInvokeThreadsCallbacks(long factory);
|
||||
private static native void nativeFreeFactory(long factory);
|
||||
private static native long nativeGetNativePeerConnectionFactory(long factory);
|
||||
private static native void nativeInjectLoggable(JNILogging jniLogging, int severity);
|
||||
|
||||
Reference in New Issue
Block a user