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

Side by Side Diff: webrtc/sdk/android/src/jni/pc/peerconnectionfactory_jni.cc

Issue 2998403002: Android: Update convenience macro defining JNI-accessible methods (Closed)
Patch Set: Created 3 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright 2017 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2017 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
(...skipping 29 matching lines...) Expand all
40 // instead of "video_jni.cc", which doesn't bring in the video-specific 40 // instead of "video_jni.cc", which doesn't bring in the video-specific
41 // dependencies. 41 // dependencies.
42 42
43 // Field trials initialization string 43 // Field trials initialization string
44 static char* field_trials_init_string = nullptr; 44 static char* field_trials_init_string = nullptr;
45 45
46 // Set in PeerConnectionFactory_initializeAndroidGlobals(). 46 // Set in PeerConnectionFactory_initializeAndroidGlobals().
47 static bool factory_static_initialized = false; 47 static bool factory_static_initialized = false;
48 static bool video_hw_acceleration_enabled = true; 48 static bool video_hw_acceleration_enabled = true;
49 49
50 JOW(jlong, PeerConnectionFactory_nativeCreateObserver) 50 JNI_FUNCTION_DECLARATION(jlong,
51 (JNIEnv* jni, jclass, jobject j_observer) { 51 PeerConnectionFactory_nativeCreateObserver,
52 JNIEnv* jni,
53 jclass,
54 jobject j_observer) {
52 return (jlong) new PeerConnectionObserverJni(jni, j_observer); 55 return (jlong) new PeerConnectionObserverJni(jni, j_observer);
53 } 56 }
54 57
55 JOW(void, PeerConnectionFactory_nativeInitializeAndroidGlobals) 58 JNI_FUNCTION_DECLARATION(void,
56 (JNIEnv* jni, jclass, jobject context, jboolean video_hw_acceleration) { 59 PeerConnectionFactory_nativeInitializeAndroidGlobals,
60 JNIEnv* jni,
61 jclass,
62 jobject context,
63 jboolean video_hw_acceleration) {
57 video_hw_acceleration_enabled = video_hw_acceleration; 64 video_hw_acceleration_enabled = video_hw_acceleration;
58 if (!factory_static_initialized) { 65 if (!factory_static_initialized) {
59 webrtc::JVM::Initialize(GetJVM()); 66 webrtc::JVM::Initialize(GetJVM());
60 factory_static_initialized = true; 67 factory_static_initialized = true;
61 } 68 }
62 } 69 }
63 70
64 JOW(void, PeerConnectionFactory_initializeFieldTrials) 71 JNI_FUNCTION_DECLARATION(void,
65 (JNIEnv* jni, jclass, jstring j_trials_init_string) { 72 PeerConnectionFactory_initializeFieldTrials,
73 JNIEnv* jni,
74 jclass,
75 jstring j_trials_init_string) {
66 field_trials_init_string = NULL; 76 field_trials_init_string = NULL;
67 if (j_trials_init_string != NULL) { 77 if (j_trials_init_string != NULL) {
68 const char* init_string = 78 const char* init_string =
69 jni->GetStringUTFChars(j_trials_init_string, NULL); 79 jni->GetStringUTFChars(j_trials_init_string, NULL);
70 int init_string_length = jni->GetStringUTFLength(j_trials_init_string); 80 int init_string_length = jni->GetStringUTFLength(j_trials_init_string);
71 field_trials_init_string = new char[init_string_length + 1]; 81 field_trials_init_string = new char[init_string_length + 1];
72 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string); 82 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string);
73 jni->ReleaseStringUTFChars(j_trials_init_string, init_string); 83 jni->ReleaseStringUTFChars(j_trials_init_string, init_string);
74 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string; 84 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string;
75 } 85 }
76 webrtc::field_trial::InitFieldTrialsFromString(field_trials_init_string); 86 webrtc::field_trial::InitFieldTrialsFromString(field_trials_init_string);
77 } 87 }
78 88
79 JOW(void, PeerConnectionFactory_initializeInternalTracer)(JNIEnv* jni, jclass) { 89 JNI_FUNCTION_DECLARATION(void,
90 PeerConnectionFactory_initializeInternalTracer,
91 JNIEnv* jni,
92 jclass) {
80 rtc::tracing::SetupInternalTracer(); 93 rtc::tracing::SetupInternalTracer();
81 } 94 }
82 95
83 JOW(jstring, PeerConnectionFactory_nativeFieldTrialsFindFullName) 96 JNI_FUNCTION_DECLARATION(jstring,
84 (JNIEnv* jni, jclass, jstring j_name) { 97 PeerConnectionFactory_nativeFieldTrialsFindFullName,
98 JNIEnv* jni,
99 jclass,
100 jstring j_name) {
85 return JavaStringFromStdString( 101 return JavaStringFromStdString(
86 jni, webrtc::field_trial::FindFullName(JavaToStdString(jni, j_name))); 102 jni, webrtc::field_trial::FindFullName(JavaToStdString(jni, j_name)));
87 } 103 }
88 104
89 JOW(jboolean, PeerConnectionFactory_startInternalTracingCapture) 105 JNI_FUNCTION_DECLARATION(jboolean,
90 (JNIEnv* jni, jclass, jstring j_event_tracing_filename) { 106 PeerConnectionFactory_startInternalTracingCapture,
107 JNIEnv* jni,
108 jclass,
109 jstring j_event_tracing_filename) {
91 if (!j_event_tracing_filename) 110 if (!j_event_tracing_filename)
92 return false; 111 return false;
93 112
94 const char* init_string = 113 const char* init_string =
95 jni->GetStringUTFChars(j_event_tracing_filename, NULL); 114 jni->GetStringUTFChars(j_event_tracing_filename, NULL);
96 LOG(LS_INFO) << "Starting internal tracing to: " << init_string; 115 LOG(LS_INFO) << "Starting internal tracing to: " << init_string;
97 bool ret = rtc::tracing::StartInternalCapture(init_string); 116 bool ret = rtc::tracing::StartInternalCapture(init_string);
98 jni->ReleaseStringUTFChars(j_event_tracing_filename, init_string); 117 jni->ReleaseStringUTFChars(j_event_tracing_filename, init_string);
99 return ret; 118 return ret;
100 } 119 }
101 120
102 JOW(void, PeerConnectionFactory_stopInternalTracingCapture) 121 JNI_FUNCTION_DECLARATION(void,
103 (JNIEnv* jni, jclass) { 122 PeerConnectionFactory_stopInternalTracingCapture,
123 JNIEnv* jni,
124 jclass) {
104 rtc::tracing::StopInternalCapture(); 125 rtc::tracing::StopInternalCapture();
105 } 126 }
106 127
107 JOW(void, PeerConnectionFactory_shutdownInternalTracer)(JNIEnv* jni, jclass) { 128 JNI_FUNCTION_DECLARATION(void,
129 PeerConnectionFactory_shutdownInternalTracer,
130 JNIEnv* jni,
131 jclass) {
108 rtc::tracing::ShutdownInternalTracer(); 132 rtc::tracing::ShutdownInternalTracer();
109 } 133 }
110 134
111 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory) 135 JNI_FUNCTION_DECLARATION(
112 (JNIEnv* jni, 136 jlong,
113 jclass, 137 PeerConnectionFactory_nativeCreatePeerConnectionFactory,
114 jobject joptions, 138 JNIEnv* jni,
115 jobject jencoder_factory, 139 jclass,
116 jobject jdecoder_factory) { 140 jobject joptions,
141 jobject jencoder_factory,
142 jobject jdecoder_factory) {
117 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but 143 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
118 // ThreadManager only WrapCurrentThread()s the thread where it is first 144 // ThreadManager only WrapCurrentThread()s the thread where it is first
119 // created. Since the semantics around when auto-wrapping happens in 145 // created. Since the semantics around when auto-wrapping happens in
120 // webrtc/rtc_base/ are convoluted, we simply wrap here to avoid having to 146 // webrtc/rtc_base/ are convoluted, we simply wrap here to avoid having to
121 // think about ramifications of auto-wrapping there. 147 // think about ramifications of auto-wrapping there.
122 rtc::ThreadManager::Instance()->WrapCurrentThread(); 148 rtc::ThreadManager::Instance()->WrapCurrentThread();
123 webrtc::Trace::CreateTrace(); 149 webrtc::Trace::CreateTrace();
124 150
125 std::unique_ptr<rtc::Thread> network_thread = 151 std::unique_ptr<rtc::Thread> network_thread =
126 rtc::Thread::CreateWithSocketServer(); 152 rtc::Thread::CreateWithSocketServer();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 factory->SetOptions(options); 209 factory->SetOptions(options);
184 } 210 }
185 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( 211 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
186 std::move(network_thread), std::move(worker_thread), 212 std::move(network_thread), std::move(worker_thread),
187 std::move(signaling_thread), video_encoder_factory, video_decoder_factory, 213 std::move(signaling_thread), video_encoder_factory, video_decoder_factory,
188 network_monitor_factory, factory.release()); 214 network_monitor_factory, factory.release());
189 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); 215 owned_factory->InvokeJavaCallbacksOnFactoryThreads();
190 return jlongFromPointer(owned_factory); 216 return jlongFromPointer(owned_factory);
191 } 217 }
192 218
193 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { 219 JNI_FUNCTION_DECLARATION(void,
220 PeerConnectionFactory_nativeFreeFactory,
221 JNIEnv*,
222 jclass,
223 jlong j_p) {
194 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); 224 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p);
195 if (field_trials_init_string) { 225 if (field_trials_init_string) {
196 webrtc::field_trial::InitFieldTrialsFromString(NULL); 226 webrtc::field_trial::InitFieldTrialsFromString(NULL);
197 delete field_trials_init_string; 227 delete field_trials_init_string;
198 field_trials_init_string = NULL; 228 field_trials_init_string = NULL;
199 } 229 }
200 webrtc::Trace::ReturnTrace(); 230 webrtc::Trace::ReturnTrace();
201 } 231 }
202 232
203 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks) 233 JNI_FUNCTION_DECLARATION(void,
204 (JNIEnv*, jclass, jlong j_p) { 234 PeerConnectionFactory_nativeThreadsCallbacks,
235 JNIEnv*,
236 jclass,
237 jlong j_p) {
205 OwnedFactoryAndThreads* factory = 238 OwnedFactoryAndThreads* factory =
206 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); 239 reinterpret_cast<OwnedFactoryAndThreads*>(j_p);
207 factory->InvokeJavaCallbacksOnFactoryThreads(); 240 factory->InvokeJavaCallbacksOnFactoryThreads();
208 } 241 }
209 242
210 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream) 243 JNI_FUNCTION_DECLARATION(jlong,
211 (JNIEnv* jni, jclass, jlong native_factory, jstring label) { 244 PeerConnectionFactory_nativeCreateLocalMediaStream,
245 JNIEnv* jni,
246 jclass,
247 jlong native_factory,
248 jstring label) {
212 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 249 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
213 factoryFromJava(native_factory)); 250 factoryFromJava(native_factory));
214 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( 251 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
215 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); 252 factory->CreateLocalMediaStream(JavaToStdString(jni, label)));
216 return (jlong)stream.release(); 253 return (jlong)stream.release();
217 } 254 }
218 255
219 JOW(jlong, PeerConnectionFactory_nativeCreateAudioSource) 256 JNI_FUNCTION_DECLARATION(jlong,
220 (JNIEnv* jni, jclass, jlong native_factory, jobject j_constraints) { 257 PeerConnectionFactory_nativeCreateAudioSource,
258 JNIEnv* jni,
259 jclass,
260 jlong native_factory,
261 jobject j_constraints) {
221 std::unique_ptr<MediaConstraintsJni> constraints( 262 std::unique_ptr<MediaConstraintsJni> constraints(
222 new MediaConstraintsJni(jni, j_constraints)); 263 new MediaConstraintsJni(jni, j_constraints));
223 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 264 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
224 factoryFromJava(native_factory)); 265 factoryFromJava(native_factory));
225 cricket::AudioOptions options; 266 cricket::AudioOptions options;
226 CopyConstraintsIntoAudioOptions(constraints.get(), &options); 267 CopyConstraintsIntoAudioOptions(constraints.get(), &options);
227 rtc::scoped_refptr<webrtc::AudioSourceInterface> source( 268 rtc::scoped_refptr<webrtc::AudioSourceInterface> source(
228 factory->CreateAudioSource(options)); 269 factory->CreateAudioSource(options));
229 return (jlong)source.release(); 270 return (jlong)source.release();
230 } 271 }
231 272
232 JOW(jlong, PeerConnectionFactory_nativeCreateAudioTrack) 273 JNI_FUNCTION_DECLARATION(jlong,
233 (JNIEnv* jni, jclass, jlong native_factory, jstring id, jlong native_source) { 274 PeerConnectionFactory_nativeCreateAudioTrack,
275 JNIEnv* jni,
276 jclass,
277 jlong native_factory,
278 jstring id,
279 jlong native_source) {
234 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 280 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
235 factoryFromJava(native_factory)); 281 factoryFromJava(native_factory));
236 rtc::scoped_refptr<webrtc::AudioTrackInterface> track( 282 rtc::scoped_refptr<webrtc::AudioTrackInterface> track(
237 factory->CreateAudioTrack( 283 factory->CreateAudioTrack(
238 JavaToStdString(jni, id), 284 JavaToStdString(jni, id),
239 reinterpret_cast<webrtc::AudioSourceInterface*>(native_source))); 285 reinterpret_cast<webrtc::AudioSourceInterface*>(native_source)));
240 return (jlong)track.release(); 286 return (jlong)track.release();
241 } 287 }
242 288
243 JOW(jboolean, PeerConnectionFactory_nativeStartAecDump) 289 JNI_FUNCTION_DECLARATION(jboolean,
244 (JNIEnv* jni, 290 PeerConnectionFactory_nativeStartAecDump,
245 jclass, 291 JNIEnv* jni,
246 jlong native_factory, 292 jclass,
247 jint file, 293 jlong native_factory,
248 jint filesize_limit_bytes) { 294 jint file,
295 jint filesize_limit_bytes) {
249 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 296 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
250 factoryFromJava(native_factory)); 297 factoryFromJava(native_factory));
251 return factory->StartAecDump(file, filesize_limit_bytes); 298 return factory->StartAecDump(file, filesize_limit_bytes);
252 } 299 }
253 300
254 JOW(void, PeerConnectionFactory_nativeStopAecDump) 301 JNI_FUNCTION_DECLARATION(void,
255 (JNIEnv* jni, jclass, jlong native_factory) { 302 PeerConnectionFactory_nativeStopAecDump,
303 JNIEnv* jni,
304 jclass,
305 jlong native_factory) {
256 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 306 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
257 factoryFromJava(native_factory)); 307 factoryFromJava(native_factory));
258 factory->StopAecDump(); 308 factory->StopAecDump();
259 } 309 }
260 310
261 JOW(void, PeerConnectionFactory_nativeSetOptions) 311 JNI_FUNCTION_DECLARATION(void,
262 (JNIEnv* jni, jclass, jlong native_factory, jobject options) { 312 PeerConnectionFactory_nativeSetOptions,
313 JNIEnv* jni,
314 jclass,
315 jlong native_factory,
316 jobject options) {
263 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( 317 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory(
264 factoryFromJava(native_factory)); 318 factoryFromJava(native_factory));
265 webrtc::PeerConnectionFactoryInterface::Options options_to_set = 319 webrtc::PeerConnectionFactoryInterface::Options options_to_set =
266 JavaToNativePeerConnectionFactoryOptions(jni, options); 320 JavaToNativePeerConnectionFactoryOptions(jni, options);
267 factory->SetOptions(options_to_set); 321 factory->SetOptions(options_to_set);
268 322
269 if (options_to_set.disable_network_monitor) { 323 if (options_to_set.disable_network_monitor) {
270 OwnedFactoryAndThreads* owner = 324 OwnedFactoryAndThreads* owner =
271 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); 325 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
272 if (owner->network_monitor_factory()) { 326 if (owner->network_monitor_factory()) {
273 rtc::NetworkMonitorFactory::ReleaseFactory( 327 rtc::NetworkMonitorFactory::ReleaseFactory(
274 owner->network_monitor_factory()); 328 owner->network_monitor_factory());
275 owner->clear_network_monitor_factory(); 329 owner->clear_network_monitor_factory();
276 } 330 }
277 } 331 }
278 } 332 }
279 333
280 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnection) 334 JNI_FUNCTION_DECLARATION(jlong,
281 (JNIEnv* jni, 335 PeerConnectionFactory_nativeCreatePeerConnection,
282 jclass, 336 JNIEnv* jni,
283 jlong factory, 337 jclass,
284 jobject j_rtc_config, 338 jlong factory,
285 jobject j_constraints, 339 jobject j_rtc_config,
286 jlong observer_p) { 340 jobject j_constraints,
341 jlong observer_p) {
287 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> f( 342 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> f(
288 reinterpret_cast<webrtc::PeerConnectionFactoryInterface*>( 343 reinterpret_cast<webrtc::PeerConnectionFactoryInterface*>(
289 factoryFromJava(factory))); 344 factoryFromJava(factory)));
290 345
291 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config( 346 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config(
292 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive); 347 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive);
293 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config); 348 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config);
294 349
295 jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config); 350 jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config);
296 jfieldID j_key_type_id = GetFieldID(jni, j_rtc_config_class, "keyType", 351 jfieldID j_key_type_id = GetFieldID(jni, j_rtc_config_class, "keyType",
(...skipping 16 matching lines...) Expand all
313 PeerConnectionObserverJni* observer = 368 PeerConnectionObserverJni* observer =
314 reinterpret_cast<PeerConnectionObserverJni*>(observer_p); 369 reinterpret_cast<PeerConnectionObserverJni*>(observer_p);
315 observer->SetConstraints(new MediaConstraintsJni(jni, j_constraints)); 370 observer->SetConstraints(new MediaConstraintsJni(jni, j_constraints));
316 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config); 371 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config);
317 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc( 372 rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc(
318 f->CreatePeerConnection(rtc_config, nullptr, nullptr, observer)); 373 f->CreatePeerConnection(rtc_config, nullptr, nullptr, observer));
319 return (jlong)pc.release(); 374 return (jlong)pc.release();
320 } 375 }
321 376
322 } // namespace webrtc_jni 377 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/pc/peerconnection_jni.cc ('k') | webrtc/sdk/android/src/jni/pc/rtpreceiver_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698