Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: talk/app/webrtc/java/jni/peerconnection_jni.cc

Issue 1581903002: Put options as the argument of the PeerConnectionFactory constructor (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | talk/app/webrtc/java/src/org/webrtc/PeerConnectionFactory.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1135 }
1136 1136
1137 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { 1137 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() {
1138 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; 1138 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads.";
1139 worker_thread_->Invoke<void>( 1139 worker_thread_->Invoke<void>(
1140 Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this)); 1140 Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
1141 signaling_thread_->Invoke<void>( 1141 signaling_thread_->Invoke<void>(
1142 Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this)); 1142 Bind(&OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads, this));
1143 } 1143 }
1144 1144
1145 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni,
1146 jobject options) {
1147 jclass options_class = jni->GetObjectClass(options);
1148 jfieldID network_ignore_mask_field =
1149 jni->GetFieldID(options_class, "networkIgnoreMask", "I");
1150 int network_ignore_mask =
1151 jni->GetIntField(options, network_ignore_mask_field);
1152
1153 jfieldID disable_encryption_field =
1154 jni->GetFieldID(options_class, "disableEncryption", "Z");
1155 bool disable_encryption =
1156 jni->GetBooleanField(options, disable_encryption_field);
1157
1158 jfieldID disable_network_monitor_field =
1159 jni->GetFieldID(options_class, "disableNetworkMonitor", "Z");
1160 bool disable_network_monitor =
1161 jni->GetBooleanField(options, disable_network_monitor_field);
1162
1163 PeerConnectionFactoryInterface::Options native_options;
1164
1165 // This doesn't necessarily match the c++ version of this struct; feel free
1166 // to add more parameters as necessary.
1167 native_options.network_ignore_mask = network_ignore_mask;
1168 native_options.disable_encryption = disable_encryption;
1169 native_options.disable_network_monitor = disable_network_monitor;
1170 return native_options;
1171 }
1172
1145 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)( 1173 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
1146 JNIEnv* jni, jclass) { 1174 JNIEnv* jni, jclass, jobject joptions) {
1147 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but 1175 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
1148 // ThreadManager only WrapCurrentThread()s the thread where it is first 1176 // ThreadManager only WrapCurrentThread()s the thread where it is first
1149 // created. Since the semantics around when auto-wrapping happens in 1177 // created. Since the semantics around when auto-wrapping happens in
1150 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think 1178 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think
1151 // about ramifications of auto-wrapping there. 1179 // about ramifications of auto-wrapping there.
1152 rtc::ThreadManager::Instance()->WrapCurrentThread(); 1180 rtc::ThreadManager::Instance()->WrapCurrentThread();
1153 webrtc::Trace::CreateTrace(); 1181 webrtc::Trace::CreateTrace();
1154 Thread* worker_thread = new Thread(); 1182 Thread* worker_thread = new Thread();
1155 worker_thread->SetName("worker_thread", NULL); 1183 worker_thread->SetName("worker_thread", NULL);
1156 Thread* signaling_thread = new Thread(); 1184 Thread* signaling_thread = new Thread();
1157 signaling_thread->SetName("signaling_thread", NULL); 1185 signaling_thread->SetName("signaling_thread", NULL);
1158 RTC_CHECK(worker_thread->Start() && signaling_thread->Start()) 1186 RTC_CHECK(worker_thread->Start() && signaling_thread->Start())
1159 << "Failed to start threads"; 1187 << "Failed to start threads";
1160 WebRtcVideoEncoderFactory* encoder_factory = nullptr; 1188 WebRtcVideoEncoderFactory* encoder_factory = nullptr;
1161 WebRtcVideoDecoderFactory* decoder_factory = nullptr; 1189 WebRtcVideoDecoderFactory* decoder_factory = nullptr;
1162 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; 1190 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
1163 1191
1192 PeerConnectionFactoryInterface::Options options;
1193 bool has_options = joptions != NULL;
1194 if (has_options) {
1195 options = ParseOptionsFromJava(jni, joptions);
1196 }
1164 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 1197 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
1165 if (video_hw_acceleration_enabled) { 1198 if (video_hw_acceleration_enabled) {
1166 encoder_factory = new MediaCodecVideoEncoderFactory(); 1199 encoder_factory = new MediaCodecVideoEncoderFactory();
1167 decoder_factory = new MediaCodecVideoDecoderFactory(); 1200 decoder_factory = new MediaCodecVideoDecoderFactory();
1168 } 1201 }
1169 network_monitor_factory = new AndroidNetworkMonitorFactory(); 1202 // Do not create network_monitor_factory only if the options are
1170 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); 1203 // provided and disable_network_monitor therein is set to true.
1204 if (!(has_options && options.disable_network_monitor)) {
1205 network_monitor_factory = new AndroidNetworkMonitorFactory();
1206 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory);
1207 }
1171 #endif 1208 #endif
1172 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1209 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1173 webrtc::CreatePeerConnectionFactory(worker_thread, 1210 webrtc::CreatePeerConnectionFactory(worker_thread,
1174 signaling_thread, 1211 signaling_thread,
1175 NULL, 1212 NULL,
1176 encoder_factory, 1213 encoder_factory,
1177 decoder_factory)); 1214 decoder_factory));
1178 RTC_CHECK(factory) << "Failed to create the peer connection factory; " 1215 RTC_CHECK(factory) << "Failed to create the peer connection factory; "
1179 << "WebRTC/libjingle init likely failed on this device"; 1216 << "WebRTC/libjingle init likely failed on this device";
1217 // TODO(honghaiz): Maybe put the options as the argument of
1218 // CreatePeerConnectionFactory.
1219 if (has_options) {
1220 factory->SetOptions(options);
1221 }
1180 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( 1222 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
1181 worker_thread, signaling_thread, 1223 worker_thread, signaling_thread,
1182 encoder_factory, decoder_factory, 1224 encoder_factory, decoder_factory,
1183 network_monitor_factory, factory.release()); 1225 network_monitor_factory, factory.release());
1184 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); 1226 owned_factory->InvokeJavaCallbacksOnFactoryThreads();
1185 return jlongFromPointer(owned_factory); 1227 return jlongFromPointer(owned_factory);
1186 } 1228 }
1187 1229
1188 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { 1230 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) {
1189 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); 1231 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1342 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1301 factoryFromJava(native_factory)); 1343 factoryFromJava(native_factory));
1302 factory->StopRtcEventLog(); 1344 factory->StopRtcEventLog();
1303 #endif 1345 #endif
1304 } 1346 }
1305 1347
1306 JOW(void, PeerConnectionFactory_nativeSetOptions)( 1348 JOW(void, PeerConnectionFactory_nativeSetOptions)(
1307 JNIEnv* jni, jclass, jlong native_factory, jobject options) { 1349 JNIEnv* jni, jclass, jlong native_factory, jobject options) {
1308 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1350 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1309 factoryFromJava(native_factory)); 1351 factoryFromJava(native_factory));
1310 jclass options_class = jni->GetObjectClass(options); 1352 PeerConnectionFactoryInterface::Options options_to_set =
1311 jfieldID network_ignore_mask_field = 1353 ParseOptionsFromJava(jni, options);
1312 jni->GetFieldID(options_class, "networkIgnoreMask", "I");
1313 int network_ignore_mask =
1314 jni->GetIntField(options, network_ignore_mask_field);
1315
1316 jfieldID disable_encryption_field =
1317 jni->GetFieldID(options_class, "disableEncryption", "Z");
1318 bool disable_encryption =
1319 jni->GetBooleanField(options, disable_encryption_field);
1320
1321 jfieldID disable_network_monitor_field =
1322 jni->GetFieldID(options_class, "disableNetworkMonitor", "Z");
1323 bool disable_network_monitor =
1324 jni->GetBooleanField(options, disable_network_monitor_field);
1325
1326 PeerConnectionFactoryInterface::Options options_to_set;
1327
1328 // This doesn't necessarily match the c++ version of this struct; feel free
1329 // to add more parameters as necessary.
1330 options_to_set.network_ignore_mask = network_ignore_mask;
1331 options_to_set.disable_encryption = disable_encryption;
1332 options_to_set.disable_network_monitor = disable_network_monitor;
1333 factory->SetOptions(options_to_set); 1354 factory->SetOptions(options_to_set);
1334
1335 if (disable_network_monitor) {
1336 OwnedFactoryAndThreads* owner =
1337 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
1338 if (owner->network_monitor_factory()) {
1339 rtc::NetworkMonitorFactory::ReleaseFactory(
1340 owner->network_monitor_factory());
1341 owner->clear_network_monitor_factory();
1342 }
1343 }
1344 } 1355 }
1345 1356
1346 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( 1357 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)(
1347 JNIEnv* jni, jclass, jlong native_factory, jobject local_egl_context, 1358 JNIEnv* jni, jclass, jlong native_factory, jobject local_egl_context,
1348 jobject remote_egl_context) { 1359 jobject remote_egl_context) {
1349 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 1360 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
1350 OwnedFactoryAndThreads* owned_factory = 1361 OwnedFactoryAndThreads* owned_factory =
1351 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); 1362 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
1352 1363
1353 jclass j_eglbase14_context_class = 1364 jclass j_eglbase14_context_class =
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after
2147 return JavaStringFromStdString( 2158 return JavaStringFromStdString(
2148 jni, 2159 jni,
2149 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); 2160 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id());
2150 } 2161 }
2151 2162
2152 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { 2163 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) {
2153 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); 2164 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release();
2154 } 2165 }
2155 2166
2156 } // namespace webrtc_jni 2167 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « no previous file | talk/app/webrtc/java/src/org/webrtc/PeerConnectionFactory.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698