OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 package org.webrtc; | 11 package org.webrtc; |
12 | 12 |
13 import java.util.List; | 13 import java.util.List; |
14 | 14 |
15 /** | 15 /** |
16 * Java wrapper for a C++ PeerConnectionFactoryInterface. Main entry point to | 16 * Java wrapper for a C++ PeerConnectionFactoryInterface. The base class of a Pe
erConnectionFactory |
17 * the PeerConnection API for clients. | 17 * without loading any library. |
18 */ | 18 */ |
19 public class PeerConnectionFactory { | 19 public class PeerConnectionFactoryBase { |
20 private static volatile boolean nativeLibLoaded; | 20 protected static volatile boolean nativeLibLoaded; |
21 | 21 |
22 static { | 22 protected static final String TAG = "PeerConnectionFactoryBase"; |
23 try { | 23 protected final long nativeFactory; |
24 System.loadLibrary("jingle_peerconnection_so"); | 24 protected static Thread networkThread; |
25 nativeLibLoaded = true; | 25 protected static Thread workerThread; |
26 } catch (UnsatisfiedLinkError t) { | 26 protected static Thread signalingThread; |
27 nativeLibLoaded = false; | 27 protected EglBase localEglbase; |
28 } | 28 protected EglBase remoteEglbase; |
29 } | |
30 | |
31 private static final String TAG = "PeerConnectionFactory"; | |
32 private final long nativeFactory; | |
33 private static Thread networkThread; | |
34 private static Thread workerThread; | |
35 private static Thread signalingThread; | |
36 private EglBase localEglbase; | |
37 private EglBase remoteEglbase; | |
38 | 29 |
39 public static class Options { | 30 public static class Options { |
40 // Keep in sync with webrtc/base/network.h! | 31 // Keep in sync with webrtc/base/network.h! |
41 static final int ADAPTER_TYPE_UNKNOWN = 0; | 32 static final int ADAPTER_TYPE_UNKNOWN = 0; |
42 static final int ADAPTER_TYPE_ETHERNET = 1 << 0; | 33 static final int ADAPTER_TYPE_ETHERNET = 1 << 0; |
43 static final int ADAPTER_TYPE_WIFI = 1 << 1; | 34 static final int ADAPTER_TYPE_WIFI = 1 << 1; |
44 static final int ADAPTER_TYPE_CELLULAR = 1 << 2; | 35 static final int ADAPTER_TYPE_CELLULAR = 1 << 2; |
45 static final int ADAPTER_TYPE_VPN = 1 << 3; | 36 static final int ADAPTER_TYPE_VPN = 1 << 3; |
46 static final int ADAPTER_TYPE_LOOPBACK = 1 << 4; | 37 static final int ADAPTER_TYPE_LOOPBACK = 1 << 4; |
47 | 38 |
48 public int networkIgnoreMask; | 39 public int networkIgnoreMask; |
49 public boolean disableEncryption; | 40 public boolean disableEncryption; |
50 public boolean disableNetworkMonitor; | 41 public boolean disableNetworkMonitor; |
51 } | 42 } |
52 | 43 |
53 // Must be called at least once before creating a PeerConnectionFactory | 44 protected static native void initializeAndroidGlobals( |
54 // (for example, at application startup time). | |
55 public static native void initializeAndroidGlobals( | |
56 android.content.Context context, boolean videoHwAcceleration); | 45 android.content.Context context, boolean videoHwAcceleration); |
57 | 46 |
58 // Older signature of initializeAndroidGlobals. The extra parameters are now m
eaningless. | 47 // Older signature of initializeAndroidGlobals. The extra parameters are now m
eaningless. |
59 @Deprecated | 48 @Deprecated |
60 public static boolean initializeAndroidGlobals(Object context, boolean initial
izeAudio, | 49 protected static boolean initializeAndroidGlobals(Object context, boolean init
ializeAudio, |
61 boolean initializeVideo, boolean videoHwAcceleration) { | 50 boolean initializeVideo, boolean videoHwAcceleration) { |
62 initializeAndroidGlobals((android.content.Context) context, videoHwAccelerat
ion); | 51 initializeAndroidGlobals((android.content.Context) context, videoHwAccelerat
ion); |
63 return true; | 52 return true; |
64 } | 53 } |
65 | 54 |
66 // Field trial initialization. Must be called before PeerConnectionFactory | 55 protected static native void initializeFieldTrials(String fieldTrialsInitStrin
g); |
67 // is created. | |
68 public static native void initializeFieldTrials(String fieldTrialsInitString); | |
69 // Wrapper of webrtc::field_trial::FindFullName. Develop the feature with defa
ult behaviour off. | |
70 // Example usage: | |
71 // if (PeerConnectionFactory.fieldTrialsFindFullName("WebRTCExperiment").equal
s("Enabled")) { | |
72 // method1(); | |
73 // } else { | |
74 // method2(); | |
75 // } | |
76 public static String fieldTrialsFindFullName(String name) { | 56 public static String fieldTrialsFindFullName(String name) { |
77 return nativeLibLoaded ? nativeFieldTrialsFindFullName(name) : ""; | 57 return nativeLibLoaded ? nativeFieldTrialsFindFullName(name) : ""; |
78 } | 58 } |
79 private static native String nativeFieldTrialsFindFullName(String name); | 59 private static native String nativeFieldTrialsFindFullName(String name); |
80 // Internal tracing initialization. Must be called before PeerConnectionFactor
y is created to | 60 protected static native void initializeInternalTracer(); |
81 // prevent racing with tracing code. | 61 protected static native void shutdownInternalTracer(); |
82 public static native void initializeInternalTracer(); | 62 protected static native boolean startInternalTracingCapture(String tracing_fil
ename); |
83 // Internal tracing shutdown, called to prevent resource leaks. Must be called
after | 63 protected static native void stopInternalTracingCapture(); |
84 // PeerConnectionFactory is gone to prevent races with code performing tracing
. | |
85 public static native void shutdownInternalTracer(); | |
86 // Start/stop internal capturing of internal tracing. | |
87 public static native boolean startInternalTracingCapture(String tracing_filena
me); | |
88 public static native void stopInternalTracingCapture(); | |
89 | 64 |
90 @Deprecated | 65 @Deprecated |
91 public PeerConnectionFactory() { | 66 public PeerConnectionFactoryBase() { |
92 this(null); | 67 this(null); |
93 } | 68 } |
94 | 69 |
95 // Note: initializeAndroidGlobals must be called at least once before | 70 // Note: initializeAndroidGlobals must be called at least once before |
96 // constructing a PeerConnectionFactory. | 71 // constructing a PeerConnectionFactory. |
97 public PeerConnectionFactory(Options options) { | 72 public PeerConnectionFactoryBase(Options options) { |
98 nativeFactory = nativeCreatePeerConnectionFactory(options); | 73 nativeFactory = nativeCreatePeerConnectionFactory(options); |
99 if (nativeFactory == 0) { | 74 if (nativeFactory == 0) { |
100 throw new RuntimeException("Failed to initialize PeerConnectionFactory!"); | 75 throw new RuntimeException("Failed to initialize PeerConnectionFactory!"); |
101 } | 76 } |
102 } | 77 } |
103 | 78 |
104 public PeerConnection createPeerConnection(PeerConnection.RTCConfiguration rtc
Config, | 79 public PeerConnection createPeerConnection(PeerConnection.RTCConfiguration rtc
Config, |
105 MediaConstraints constraints, PeerConnection.Observer observer) { | 80 MediaConstraints constraints, PeerConnection.Observer observer) { |
106 long nativeObserver = nativeCreateObserver(observer); | 81 long nativeObserver = nativeCreateObserver(observer); |
107 if (nativeObserver == 0) { | 82 if (nativeObserver == 0) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (localEglbase != null) | 172 if (localEglbase != null) |
198 localEglbase.release(); | 173 localEglbase.release(); |
199 if (remoteEglbase != null) | 174 if (remoteEglbase != null) |
200 remoteEglbase.release(); | 175 remoteEglbase.release(); |
201 } | 176 } |
202 | 177 |
203 public void threadsCallbacks() { | 178 public void threadsCallbacks() { |
204 nativeThreadsCallbacks(nativeFactory); | 179 nativeThreadsCallbacks(nativeFactory); |
205 } | 180 } |
206 | 181 |
207 private static void printStackTrace(Thread thread, String threadName) { | 182 protected static void printStackTrace(Thread thread, String threadName) { |
208 if (thread != null) { | 183 if (thread != null) { |
209 StackTraceElement[] stackTraces = thread.getStackTrace(); | 184 StackTraceElement[] stackTraces = thread.getStackTrace(); |
210 if (stackTraces.length > 0) { | 185 if (stackTraces.length > 0) { |
211 Logging.d(TAG, threadName + " stacks trace:"); | 186 Logging.d(TAG, threadName + " stacks trace:"); |
212 for (StackTraceElement stackTrace : stackTraces) { | 187 for (StackTraceElement stackTrace : stackTraces) { |
213 Logging.d(TAG, stackTrace.toString()); | 188 Logging.d(TAG, stackTrace.toString()); |
214 } | 189 } |
215 } | 190 } |
216 } | 191 } |
217 } | 192 } |
218 | 193 |
219 public static void printStackTraces() { | 194 public static void printStackTraces() { |
220 printStackTrace(networkThread, "Network thread"); | 195 printStackTrace(networkThread, "Network thread"); |
221 printStackTrace(workerThread, "Worker thread"); | 196 printStackTrace(workerThread, "Worker thread"); |
222 printStackTrace(signalingThread, "Signaling thread"); | 197 printStackTrace(signalingThread, "Signaling thread"); |
223 } | 198 } |
224 | 199 |
225 private static void onNetworkThreadReady() { | 200 protected static void onNetworkThreadReady() { |
226 networkThread = Thread.currentThread(); | 201 networkThread = Thread.currentThread(); |
227 Logging.d(TAG, "onNetworkThreadReady"); | 202 Logging.d(TAG, "onNetworkThreadReady"); |
228 } | 203 } |
229 | 204 |
230 private static void onWorkerThreadReady() { | 205 protected static void onWorkerThreadReady() { |
231 workerThread = Thread.currentThread(); | 206 workerThread = Thread.currentThread(); |
232 Logging.d(TAG, "onWorkerThreadReady"); | 207 Logging.d(TAG, "onWorkerThreadReady"); |
233 } | 208 } |
234 | 209 |
235 private static void onSignalingThreadReady() { | 210 protected static void onSignalingThreadReady() { |
236 signalingThread = Thread.currentThread(); | 211 signalingThread = Thread.currentThread(); |
237 Logging.d(TAG, "onSignalingThreadReady"); | 212 Logging.d(TAG, "onSignalingThreadReady"); |
238 } | 213 } |
239 | 214 |
240 private static native long nativeCreatePeerConnectionFactory(Options options); | 215 private static native long nativeCreatePeerConnectionFactory(Options options); |
241 | 216 |
242 private static native long nativeCreateObserver(PeerConnection.Observer observ
er); | 217 private static native long nativeCreateObserver(PeerConnection.Observer observ
er); |
243 | 218 |
244 private static native long nativeCreatePeerConnection(long nativeFactory, | 219 private static native long nativeCreatePeerConnection(long nativeFactory, |
245 PeerConnection.RTCConfiguration rtcConfig, MediaConstraints constraints, l
ong nativeObserver); | 220 PeerConnection.RTCConfiguration rtcConfig, MediaConstraints constraints, l
ong nativeObserver); |
(...skipping 23 matching lines...) Expand all Loading... |
269 | 244 |
270 @Deprecated public native void nativeSetOptions(long nativeFactory, Options op
tions); | 245 @Deprecated public native void nativeSetOptions(long nativeFactory, Options op
tions); |
271 | 246 |
272 private static native void nativeSetVideoHwAccelerationOptions( | 247 private static native void nativeSetVideoHwAccelerationOptions( |
273 long nativeFactory, Object localEGLContext, Object remoteEGLContext); | 248 long nativeFactory, Object localEGLContext, Object remoteEGLContext); |
274 | 249 |
275 private static native void nativeThreadsCallbacks(long nativeFactory); | 250 private static native void nativeThreadsCallbacks(long nativeFactory); |
276 | 251 |
277 private static native void nativeFreeFactory(long nativeFactory); | 252 private static native void nativeFreeFactory(long nativeFactory); |
278 } | 253 } |
OLD | NEW |