Rabbit-R1/original r1/java/sources/org/webrtc/PeerConnectionFactory.java
2024-05-21 17:08:36 -04:00

509 lines
22 KiB
Java

package org.webrtc;
import android.content.Context;
import android.os.Process;
import java.util.List;
import org.webrtc.Logging;
import org.webrtc.NativeLibrary;
import org.webrtc.PeerConnection;
import org.webrtc.audio.AudioDeviceModule;
import org.webrtc.audio.JavaAudioDeviceModule;
/* loaded from: classes3.dex */
public class PeerConnectionFactory {
private static final String TAG = "PeerConnectionFactory";
public static final String TRIAL_ENABLED = "Enabled";
private static final String VIDEO_CAPTURER_THREAD_NAME = "VideoCapturerThread";
@Deprecated
public static final String VIDEO_FRAME_EMIT_TRIAL = "VideoFrameEmit";
private static volatile boolean internalTracerInitialized;
private static ThreadInfo staticNetworkThread;
private static ThreadInfo staticSignalingThread;
private static ThreadInfo staticWorkerThread;
private long nativeFactory;
private volatile ThreadInfo networkThread;
private volatile ThreadInfo signalingThread;
private volatile ThreadInfo workerThread;
/* loaded from: classes3.dex */
public static class Options {
static final int ADAPTER_TYPE_ANY = 32;
static final int ADAPTER_TYPE_CELLULAR = 4;
static final int ADAPTER_TYPE_ETHERNET = 1;
static final int ADAPTER_TYPE_LOOPBACK = 16;
static final int ADAPTER_TYPE_UNKNOWN = 0;
static final int ADAPTER_TYPE_VPN = 8;
static final int ADAPTER_TYPE_WIFI = 2;
public boolean disableEncryption;
public boolean disableNetworkMonitor;
public int networkIgnoreMask;
boolean getDisableEncryption() {
return this.disableEncryption;
}
boolean getDisableNetworkMonitor() {
return this.disableNetworkMonitor;
}
int getNetworkIgnoreMask() {
return this.networkIgnoreMask;
}
}
private static native long nativeCreateAudioSource(long j, MediaConstraints mediaConstraints);
private static native long nativeCreateAudioTrack(long j, String str, long j2);
private static native long nativeCreateLocalMediaStream(long j, String str);
private static native long nativeCreatePeerConnection(long j, PeerConnection.RTCConfiguration rTCConfiguration, MediaConstraints mediaConstraints, long j2, SSLCertificateVerifier sSLCertificateVerifier);
/* JADX INFO: Access modifiers changed from: private */
public static native PeerConnectionFactory nativeCreatePeerConnectionFactory(Context context, Options options, long j, long j2, long j3, VideoEncoderFactory videoEncoderFactory, VideoDecoderFactory videoDecoderFactory, long j4, long j5, long j6, long j7, long j8);
private static native long nativeCreateVideoSource(long j, boolean z, boolean z2);
private static native long nativeCreateVideoTrack(long j, String str, long j2);
private static native void nativeDeleteLoggable();
private static native String nativeFindFieldTrialsFullName(String str);
private static native void nativeFreeFactory(long j);
private static native long nativeGetNativePeerConnectionFactory(long j);
private static native void nativeInitializeAndroidGlobals();
private static native void nativeInitializeFieldTrials(String str);
private static native void nativeInitializeInternalTracer();
private static native void nativeInjectLoggable(JNILogging jNILogging, int i);
private static native void nativePrintStackTrace(int i);
private static native void nativePrintStackTracesOfRegisteredThreads();
private static native void nativeShutdownInternalTracer();
private static native boolean nativeStartAecDump(long j, int i, int i2);
private static native boolean nativeStartInternalTracingCapture(String str);
private static native void nativeStopAecDump(long j);
private static native void nativeStopInternalTracingCapture();
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes3.dex */
public static class ThreadInfo {
final Thread thread;
final int tid;
public static ThreadInfo getCurrent() {
return new ThreadInfo(Thread.currentThread(), Process.myTid());
}
private ThreadInfo(Thread thread, int i) {
this.thread = thread;
this.tid = i;
}
}
/* loaded from: classes3.dex */
public static class InitializationOptions {
final Context applicationContext;
final boolean enableInternalTracer;
final String fieldTrials;
Loggable loggable;
Logging.Severity loggableSeverity;
final NativeLibraryLoader nativeLibraryLoader;
final String nativeLibraryName;
private InitializationOptions(Context context, String str, boolean z, NativeLibraryLoader nativeLibraryLoader, String str2, Loggable loggable, Logging.Severity severity) {
this.applicationContext = context;
this.fieldTrials = str;
this.enableInternalTracer = z;
this.nativeLibraryLoader = nativeLibraryLoader;
this.nativeLibraryName = str2;
this.loggable = loggable;
this.loggableSeverity = severity;
}
public static Builder builder(Context context) {
return new Builder(context);
}
/* loaded from: classes3.dex */
public static class Builder {
private final Context applicationContext;
private boolean enableInternalTracer;
private Loggable loggable;
private Logging.Severity loggableSeverity;
private String fieldTrials = "";
private NativeLibraryLoader nativeLibraryLoader = new NativeLibrary.DefaultLoader();
private String nativeLibraryName = "jingle_peerconnection_so";
public Builder setEnableInternalTracer(boolean z) {
this.enableInternalTracer = z;
return this;
}
public Builder setFieldTrials(String str) {
this.fieldTrials = str;
return this;
}
public Builder setInjectableLogger(Loggable loggable, Logging.Severity severity) {
this.loggable = loggable;
this.loggableSeverity = severity;
return this;
}
public Builder setNativeLibraryLoader(NativeLibraryLoader nativeLibraryLoader) {
this.nativeLibraryLoader = nativeLibraryLoader;
return this;
}
public Builder setNativeLibraryName(String str) {
this.nativeLibraryName = str;
return this;
}
Builder(Context context) {
this.applicationContext = context;
}
public InitializationOptions createInitializationOptions() {
return new InitializationOptions(this.applicationContext, this.fieldTrials, this.enableInternalTracer, this.nativeLibraryLoader, this.nativeLibraryName, this.loggable, this.loggableSeverity);
}
}
}
/* loaded from: classes3.dex */
public static class Builder {
private AudioDecoderFactoryFactory audioDecoderFactoryFactory;
private AudioDeviceModule audioDeviceModule;
private AudioEncoderFactoryFactory audioEncoderFactoryFactory;
private AudioProcessingFactory audioProcessingFactory;
private FecControllerFactoryFactoryInterface fecControllerFactoryFactory;
private NetEqFactoryFactory neteqFactoryFactory;
private NetworkControllerFactoryFactory networkControllerFactoryFactory;
private NetworkStatePredictorFactoryFactory networkStatePredictorFactoryFactory;
private Options options;
private VideoDecoderFactory videoDecoderFactory;
private VideoEncoderFactory videoEncoderFactory;
public Builder setAudioDeviceModule(AudioDeviceModule audioDeviceModule) {
this.audioDeviceModule = audioDeviceModule;
return this;
}
public Builder setFecControllerFactoryFactoryInterface(FecControllerFactoryFactoryInterface fecControllerFactoryFactoryInterface) {
this.fecControllerFactoryFactory = fecControllerFactoryFactoryInterface;
return this;
}
public Builder setNetEqFactoryFactory(NetEqFactoryFactory netEqFactoryFactory) {
this.neteqFactoryFactory = netEqFactoryFactory;
return this;
}
public Builder setNetworkControllerFactoryFactory(NetworkControllerFactoryFactory networkControllerFactoryFactory) {
this.networkControllerFactoryFactory = networkControllerFactoryFactory;
return this;
}
public Builder setNetworkStatePredictorFactoryFactory(NetworkStatePredictorFactoryFactory networkStatePredictorFactoryFactory) {
this.networkStatePredictorFactoryFactory = networkStatePredictorFactoryFactory;
return this;
}
public Builder setOptions(Options options) {
this.options = options;
return this;
}
public Builder setVideoDecoderFactory(VideoDecoderFactory videoDecoderFactory) {
this.videoDecoderFactory = videoDecoderFactory;
return this;
}
public Builder setVideoEncoderFactory(VideoEncoderFactory videoEncoderFactory) {
this.videoEncoderFactory = videoEncoderFactory;
return this;
}
private Builder() {
this.audioEncoderFactoryFactory = new BuiltinAudioEncoderFactoryFactory();
this.audioDecoderFactoryFactory = new BuiltinAudioDecoderFactoryFactory();
}
public Builder setAudioEncoderFactoryFactory(AudioEncoderFactoryFactory audioEncoderFactoryFactory) {
if (audioEncoderFactoryFactory == null) {
throw new IllegalArgumentException("PeerConnectionFactory.Builder does not accept a null AudioEncoderFactoryFactory.");
}
this.audioEncoderFactoryFactory = audioEncoderFactoryFactory;
return this;
}
public Builder setAudioDecoderFactoryFactory(AudioDecoderFactoryFactory audioDecoderFactoryFactory) {
if (audioDecoderFactoryFactory == null) {
throw new IllegalArgumentException("PeerConnectionFactory.Builder does not accept a null AudioDecoderFactoryFactory.");
}
this.audioDecoderFactoryFactory = audioDecoderFactoryFactory;
return this;
}
public Builder setAudioProcessingFactory(AudioProcessingFactory audioProcessingFactory) {
if (audioProcessingFactory == null) {
throw new NullPointerException("PeerConnectionFactory builder does not accept a null AudioProcessingFactory.");
}
this.audioProcessingFactory = audioProcessingFactory;
return this;
}
public PeerConnectionFactory createPeerConnectionFactory() {
PeerConnectionFactory.checkInitializeHasBeenCalled();
if (this.audioDeviceModule == null) {
this.audioDeviceModule = JavaAudioDeviceModule.builder(ContextUtils.getApplicationContext()).createAudioDeviceModule();
}
Context applicationContext = ContextUtils.getApplicationContext();
Options options = this.options;
long nativeAudioDeviceModulePointer = this.audioDeviceModule.getNativeAudioDeviceModulePointer();
long createNativeAudioEncoderFactory = this.audioEncoderFactoryFactory.createNativeAudioEncoderFactory();
long createNativeAudioDecoderFactory = this.audioDecoderFactoryFactory.createNativeAudioDecoderFactory();
VideoEncoderFactory videoEncoderFactory = this.videoEncoderFactory;
VideoDecoderFactory videoDecoderFactory = this.videoDecoderFactory;
AudioProcessingFactory audioProcessingFactory = this.audioProcessingFactory;
long createNative = audioProcessingFactory == null ? 0L : audioProcessingFactory.createNative();
FecControllerFactoryFactoryInterface fecControllerFactoryFactoryInterface = this.fecControllerFactoryFactory;
long createNative2 = fecControllerFactoryFactoryInterface == null ? 0L : fecControllerFactoryFactoryInterface.createNative();
NetworkControllerFactoryFactory networkControllerFactoryFactory = this.networkControllerFactoryFactory;
long createNativeNetworkControllerFactory = networkControllerFactoryFactory == null ? 0L : networkControllerFactoryFactory.createNativeNetworkControllerFactory();
NetworkStatePredictorFactoryFactory networkStatePredictorFactoryFactory = this.networkStatePredictorFactoryFactory;
long createNativeNetworkStatePredictorFactory = networkStatePredictorFactoryFactory == null ? 0L : networkStatePredictorFactoryFactory.createNativeNetworkStatePredictorFactory();
NetEqFactoryFactory netEqFactoryFactory = this.neteqFactoryFactory;
return PeerConnectionFactory.nativeCreatePeerConnectionFactory(applicationContext, options, nativeAudioDeviceModulePointer, createNativeAudioEncoderFactory, createNativeAudioDecoderFactory, videoEncoderFactory, videoDecoderFactory, createNative, createNative2, createNativeNetworkControllerFactory, createNativeNetworkStatePredictorFactory, netEqFactoryFactory == null ? 0L : netEqFactoryFactory.createNativeNetEqFactory());
}
}
public static Builder builder() {
return new Builder();
}
public static void initialize(InitializationOptions initializationOptions) {
ContextUtils.initialize(initializationOptions.applicationContext);
NativeLibrary.initialize(initializationOptions.nativeLibraryLoader, initializationOptions.nativeLibraryName);
nativeInitializeAndroidGlobals();
nativeInitializeFieldTrials(initializationOptions.fieldTrials);
if (initializationOptions.enableInternalTracer && !internalTracerInitialized) {
initializeInternalTracer();
}
if (initializationOptions.loggable != null) {
Logging.injectLoggable(initializationOptions.loggable, initializationOptions.loggableSeverity);
nativeInjectLoggable(new JNILogging(initializationOptions.loggable), initializationOptions.loggableSeverity.ordinal());
} else {
Logging.d(TAG, "PeerConnectionFactory was initialized without an injected Loggable. Any existing Loggable will be deleted.");
Logging.deleteInjectedLoggable();
nativeDeleteLoggable();
}
}
/* JADX INFO: Access modifiers changed from: private */
public static void checkInitializeHasBeenCalled() {
if (!NativeLibrary.isLoaded() || ContextUtils.getApplicationContext() == null) {
throw new IllegalStateException("PeerConnectionFactory.initialize was not called before creating a PeerConnectionFactory.");
}
}
private static void initializeInternalTracer() {
internalTracerInitialized = true;
nativeInitializeInternalTracer();
}
public static void shutdownInternalTracer() {
internalTracerInitialized = false;
nativeShutdownInternalTracer();
}
@Deprecated
public static void initializeFieldTrials(String str) {
nativeInitializeFieldTrials(str);
}
public static String fieldTrialsFindFullName(String str) {
return NativeLibrary.isLoaded() ? nativeFindFieldTrialsFullName(str) : "";
}
public static boolean startInternalTracingCapture(String str) {
return nativeStartInternalTracingCapture(str);
}
public static void stopInternalTracingCapture() {
nativeStopInternalTracingCapture();
}
PeerConnectionFactory(long j) {
checkInitializeHasBeenCalled();
if (j == 0) {
throw new RuntimeException("Failed to initialize PeerConnectionFactory!");
}
this.nativeFactory = j;
}
PeerConnection createPeerConnectionInternal(PeerConnection.RTCConfiguration rTCConfiguration, MediaConstraints mediaConstraints, PeerConnection.Observer observer, SSLCertificateVerifier sSLCertificateVerifier) {
checkPeerConnectionFactoryExists();
long createNativePeerConnectionObserver = PeerConnection.createNativePeerConnectionObserver(observer);
if (createNativePeerConnectionObserver == 0) {
return null;
}
long nativeCreatePeerConnection = nativeCreatePeerConnection(this.nativeFactory, rTCConfiguration, mediaConstraints, createNativePeerConnectionObserver, sSLCertificateVerifier);
if (nativeCreatePeerConnection == 0) {
return null;
}
return new PeerConnection(nativeCreatePeerConnection);
}
@Deprecated
public PeerConnection createPeerConnection(PeerConnection.RTCConfiguration rTCConfiguration, MediaConstraints mediaConstraints, PeerConnection.Observer observer) {
return createPeerConnectionInternal(rTCConfiguration, mediaConstraints, observer, null);
}
@Deprecated
public PeerConnection createPeerConnection(List<PeerConnection.IceServer> list, MediaConstraints mediaConstraints, PeerConnection.Observer observer) {
return createPeerConnection(new PeerConnection.RTCConfiguration(list), mediaConstraints, observer);
}
public PeerConnection createPeerConnection(List<PeerConnection.IceServer> list, PeerConnection.Observer observer) {
return createPeerConnection(new PeerConnection.RTCConfiguration(list), observer);
}
public PeerConnection createPeerConnection(PeerConnection.RTCConfiguration rTCConfiguration, PeerConnection.Observer observer) {
return createPeerConnection(rTCConfiguration, (MediaConstraints) null, observer);
}
public PeerConnection createPeerConnection(PeerConnection.RTCConfiguration rTCConfiguration, PeerConnectionDependencies peerConnectionDependencies) {
return createPeerConnectionInternal(rTCConfiguration, null, peerConnectionDependencies.getObserver(), peerConnectionDependencies.getSSLCertificateVerifier());
}
public MediaStream createLocalMediaStream(String str) {
checkPeerConnectionFactoryExists();
return new MediaStream(nativeCreateLocalMediaStream(this.nativeFactory, str));
}
public VideoSource createVideoSource(boolean z, boolean z2) {
checkPeerConnectionFactoryExists();
return new VideoSource(nativeCreateVideoSource(this.nativeFactory, z, z2));
}
public VideoSource createVideoSource(boolean z) {
return createVideoSource(z, true);
}
public VideoTrack createVideoTrack(String str, VideoSource videoSource) {
checkPeerConnectionFactoryExists();
return new VideoTrack(nativeCreateVideoTrack(this.nativeFactory, str, videoSource.getNativeVideoTrackSource()));
}
public AudioSource createAudioSource(MediaConstraints mediaConstraints) {
checkPeerConnectionFactoryExists();
return new AudioSource(nativeCreateAudioSource(this.nativeFactory, mediaConstraints));
}
public AudioTrack createAudioTrack(String str, AudioSource audioSource) {
checkPeerConnectionFactoryExists();
return new AudioTrack(nativeCreateAudioTrack(this.nativeFactory, str, audioSource.getNativeAudioSource()));
}
public boolean startAecDump(int i, int i2) {
checkPeerConnectionFactoryExists();
return nativeStartAecDump(this.nativeFactory, i, i2);
}
public void stopAecDump() {
checkPeerConnectionFactoryExists();
nativeStopAecDump(this.nativeFactory);
}
public void dispose() {
checkPeerConnectionFactoryExists();
nativeFreeFactory(this.nativeFactory);
this.networkThread = null;
this.workerThread = null;
this.signalingThread = null;
this.nativeFactory = 0L;
}
public long getNativePeerConnectionFactory() {
checkPeerConnectionFactoryExists();
return nativeGetNativePeerConnectionFactory(this.nativeFactory);
}
public long getNativeOwnedFactoryAndThreads() {
checkPeerConnectionFactoryExists();
return this.nativeFactory;
}
private void checkPeerConnectionFactoryExists() {
if (this.nativeFactory == 0) {
throw new IllegalStateException("PeerConnectionFactory has been disposed.");
}
}
private static void printStackTrace(ThreadInfo threadInfo, boolean z) {
if (threadInfo == null) {
return;
}
String name = threadInfo.thread.getName();
StackTraceElement[] stackTrace = threadInfo.thread.getStackTrace();
if (stackTrace.length > 0) {
Logging.w(TAG, name + " stacktrace:");
for (StackTraceElement stackTraceElement : stackTrace) {
Logging.w(TAG, stackTraceElement.toString());
}
}
if (z) {
Logging.w(TAG, "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***");
Logging.w(TAG, "pid: " + Process.myPid() + ", tid: " + threadInfo.tid + ", name: " + name + " >>> WebRTC <<<");
nativePrintStackTrace(threadInfo.tid);
}
}
@Deprecated
public static void printStackTraces() {
printStackTrace(staticNetworkThread, false);
printStackTrace(staticWorkerThread, false);
printStackTrace(staticSignalingThread, false);
}
public void printInternalStackTraces(boolean z) {
printStackTrace(this.signalingThread, z);
printStackTrace(this.workerThread, z);
printStackTrace(this.networkThread, z);
if (z) {
nativePrintStackTracesOfRegisteredThreads();
}
}
private void onNetworkThreadReady() {
this.networkThread = ThreadInfo.getCurrent();
staticNetworkThread = this.networkThread;
Logging.d(TAG, "onNetworkThreadReady");
}
private void onWorkerThreadReady() {
this.workerThread = ThreadInfo.getCurrent();
staticWorkerThread = this.workerThread;
Logging.d(TAG, "onWorkerThreadReady");
}
private void onSignalingThreadReady() {
this.signalingThread = ThreadInfo.getCurrent();
staticSignalingThread = this.signalingThread;
Logging.d(TAG, "onSignalingThreadReady");
}
}