Put options as the argument of the java PeerConnectionFactory constructor.
BUG= Review URL: https://codereview.webrtc.org/1581903002 Cr-Commit-Position: refs/heads/master@{#11257}
This commit is contained in:
parent
5d332ac8ff
commit
67b1e1ab0b
@ -1142,8 +1142,36 @@ void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() {
|
||||
Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
|
||||
}
|
||||
|
||||
PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni,
|
||||
jobject options) {
|
||||
jclass options_class = jni->GetObjectClass(options);
|
||||
jfieldID network_ignore_mask_field =
|
||||
jni->GetFieldID(options_class, "networkIgnoreMask", "I");
|
||||
int network_ignore_mask =
|
||||
jni->GetIntField(options, network_ignore_mask_field);
|
||||
|
||||
jfieldID disable_encryption_field =
|
||||
jni->GetFieldID(options_class, "disableEncryption", "Z");
|
||||
bool disable_encryption =
|
||||
jni->GetBooleanField(options, disable_encryption_field);
|
||||
|
||||
jfieldID disable_network_monitor_field =
|
||||
jni->GetFieldID(options_class, "disableNetworkMonitor", "Z");
|
||||
bool disable_network_monitor =
|
||||
jni->GetBooleanField(options, disable_network_monitor_field);
|
||||
|
||||
PeerConnectionFactoryInterface::Options native_options;
|
||||
|
||||
// This doesn't necessarily match the c++ version of this struct; feel free
|
||||
// to add more parameters as necessary.
|
||||
native_options.network_ignore_mask = network_ignore_mask;
|
||||
native_options.disable_encryption = disable_encryption;
|
||||
native_options.disable_network_monitor = disable_network_monitor;
|
||||
return native_options;
|
||||
}
|
||||
|
||||
JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
|
||||
JNIEnv* jni, jclass) {
|
||||
JNIEnv* jni, jclass, jobject joptions) {
|
||||
// talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
|
||||
// ThreadManager only WrapCurrentThread()s the thread where it is first
|
||||
// created. Since the semantics around when auto-wrapping happens in
|
||||
@ -1161,13 +1189,22 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
|
||||
WebRtcVideoDecoderFactory* decoder_factory = nullptr;
|
||||
rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
|
||||
|
||||
PeerConnectionFactoryInterface::Options options;
|
||||
bool has_options = joptions != NULL;
|
||||
if (has_options) {
|
||||
options = ParseOptionsFromJava(jni, joptions);
|
||||
}
|
||||
#if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
|
||||
if (video_hw_acceleration_enabled) {
|
||||
encoder_factory = new MediaCodecVideoEncoderFactory();
|
||||
decoder_factory = new MediaCodecVideoDecoderFactory();
|
||||
}
|
||||
network_monitor_factory = new AndroidNetworkMonitorFactory();
|
||||
rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory);
|
||||
// Do not create network_monitor_factory only if the options are
|
||||
// provided and disable_network_monitor therein is set to true.
|
||||
if (!(has_options && options.disable_network_monitor)) {
|
||||
network_monitor_factory = new AndroidNetworkMonitorFactory();
|
||||
rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory);
|
||||
}
|
||||
#endif
|
||||
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
|
||||
webrtc::CreatePeerConnectionFactory(worker_thread,
|
||||
@ -1177,6 +1214,11 @@ JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
|
||||
decoder_factory));
|
||||
RTC_CHECK(factory) << "Failed to create the peer connection factory; "
|
||||
<< "WebRTC/libjingle init likely failed on this device";
|
||||
// TODO(honghaiz): Maybe put the options as the argument of
|
||||
// CreatePeerConnectionFactory.
|
||||
if (has_options) {
|
||||
factory->SetOptions(options);
|
||||
}
|
||||
OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
|
||||
worker_thread, signaling_thread,
|
||||
encoder_factory, decoder_factory,
|
||||
@ -1307,40 +1349,9 @@ JOW(void, PeerConnectionFactory_nativeSetOptions)(
|
||||
JNIEnv* jni, jclass, jlong native_factory, jobject options) {
|
||||
rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
|
||||
factoryFromJava(native_factory));
|
||||
jclass options_class = jni->GetObjectClass(options);
|
||||
jfieldID network_ignore_mask_field =
|
||||
jni->GetFieldID(options_class, "networkIgnoreMask", "I");
|
||||
int network_ignore_mask =
|
||||
jni->GetIntField(options, network_ignore_mask_field);
|
||||
|
||||
jfieldID disable_encryption_field =
|
||||
jni->GetFieldID(options_class, "disableEncryption", "Z");
|
||||
bool disable_encryption =
|
||||
jni->GetBooleanField(options, disable_encryption_field);
|
||||
|
||||
jfieldID disable_network_monitor_field =
|
||||
jni->GetFieldID(options_class, "disableNetworkMonitor", "Z");
|
||||
bool disable_network_monitor =
|
||||
jni->GetBooleanField(options, disable_network_monitor_field);
|
||||
|
||||
PeerConnectionFactoryInterface::Options options_to_set;
|
||||
|
||||
// This doesn't necessarily match the c++ version of this struct; feel free
|
||||
// to add more parameters as necessary.
|
||||
options_to_set.network_ignore_mask = network_ignore_mask;
|
||||
options_to_set.disable_encryption = disable_encryption;
|
||||
options_to_set.disable_network_monitor = disable_network_monitor;
|
||||
PeerConnectionFactoryInterface::Options options_to_set =
|
||||
ParseOptionsFromJava(jni, options);
|
||||
factory->SetOptions(options_to_set);
|
||||
|
||||
if (disable_network_monitor) {
|
||||
OwnedFactoryAndThreads* owner =
|
||||
reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
|
||||
if (owner->network_monitor_factory()) {
|
||||
rtc::NetworkMonitorFactory::ReleaseFactory(
|
||||
owner->network_monitor_factory());
|
||||
owner->clear_network_monitor_factory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)(
|
||||
|
||||
@ -83,8 +83,13 @@ public class PeerConnectionFactory {
|
||||
public static native boolean startInternalTracingCapture(String tracing_filename);
|
||||
public static native void stopInternalTracingCapture();
|
||||
|
||||
@Deprecated
|
||||
public PeerConnectionFactory() {
|
||||
nativeFactory = nativeCreatePeerConnectionFactory();
|
||||
this(null);
|
||||
}
|
||||
|
||||
public PeerConnectionFactory(Options options) {
|
||||
nativeFactory = nativeCreatePeerConnectionFactory(options);
|
||||
if (nativeFactory == 0) {
|
||||
throw new RuntimeException("Failed to initialize PeerConnectionFactory!");
|
||||
}
|
||||
@ -166,6 +171,7 @@ public class PeerConnectionFactory {
|
||||
nativeStopRtcEventLog(nativeFactory);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setOptions(Options options) {
|
||||
nativeSetOptions(nativeFactory, options);
|
||||
}
|
||||
@ -225,7 +231,7 @@ public class PeerConnectionFactory {
|
||||
Logging.d(TAG, "onSignalingThreadReady");
|
||||
}
|
||||
|
||||
private static native long nativeCreatePeerConnectionFactory();
|
||||
private static native long nativeCreatePeerConnectionFactory(Options options);
|
||||
|
||||
private static native long nativeCreateObserver(
|
||||
PeerConnection.Observer observer);
|
||||
@ -258,6 +264,7 @@ public class PeerConnectionFactory {
|
||||
|
||||
private static native void nativeStopRtcEventLog(long nativeFactory);
|
||||
|
||||
@Deprecated
|
||||
public native void nativeSetOptions(long nativeFactory, Options options);
|
||||
|
||||
private static native void nativeSetVideoHwAccelerationOptions(
|
||||
|
||||
@ -517,7 +517,11 @@ public class PeerConnectionTest {
|
||||
}
|
||||
|
||||
void doTest() throws Exception {
|
||||
PeerConnectionFactory factory = new PeerConnectionFactory();
|
||||
// Allow loopback interfaces too since our Android devices often don't
|
||||
// have those.
|
||||
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
|
||||
options.networkIgnoreMask = 0;
|
||||
PeerConnectionFactory factory = new PeerConnectionFactory(options);
|
||||
// Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
|
||||
// NOTE: this _must_ happen while |factory| is alive!
|
||||
// Logging.enableTracing(
|
||||
@ -525,12 +529,6 @@ public class PeerConnectionTest {
|
||||
// EnumSet.of(Logging.TraceLevel.TRACE_ALL),
|
||||
// Logging.Severity.LS_SENSITIVE);
|
||||
|
||||
// Allow loopback interfaces too since our Android devices often don't
|
||||
// have those.
|
||||
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
|
||||
options.networkIgnoreMask = 0;
|
||||
factory.setOptions(options);
|
||||
|
||||
MediaConstraints pcConstraints = new MediaConstraints();
|
||||
pcConstraints.mandatory.add(
|
||||
new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
|
||||
|
||||
@ -337,11 +337,10 @@ public class PeerConnectionClient {
|
||||
peerConnectionParameters.videoCodecHwAcceleration)) {
|
||||
events.onPeerConnectionError("Failed to initializeAndroidGlobals");
|
||||
}
|
||||
factory = new PeerConnectionFactory();
|
||||
if (options != null) {
|
||||
Log.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMask);
|
||||
factory.setOptions(options);
|
||||
}
|
||||
factory = new PeerConnectionFactory(options);
|
||||
Log.d(TAG, "Peer connection factory created.");
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user