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 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 using webrtc::StatsReport; | 109 using webrtc::StatsReport; |
110 using webrtc::StatsReports; | 110 using webrtc::StatsReports; |
111 using webrtc::VideoTrackSourceInterface; | 111 using webrtc::VideoTrackSourceInterface; |
112 using webrtc::VideoTrackInterface; | 112 using webrtc::VideoTrackInterface; |
113 using webrtc::VideoTrackVector; | 113 using webrtc::VideoTrackVector; |
114 using webrtc::kVideoCodecVP8; | 114 using webrtc::kVideoCodecVP8; |
115 | 115 |
116 namespace webrtc_jni { | 116 namespace webrtc_jni { |
117 | 117 |
118 // Field trials initialization string | 118 // Field trials initialization string |
119 static char *field_trials_init_string = NULL; | 119 static char* field_trials_init_string = nullptr; |
120 | 120 |
121 // Set in PeerConnectionFactory_initializeAndroidGlobals(). | 121 // Set in PeerConnectionFactory_initializeAndroidGlobals(). |
122 static bool factory_static_initialized = false; | 122 static bool factory_static_initialized = false; |
123 static bool video_hw_acceleration_enabled = true; | 123 static bool video_hw_acceleration_enabled = true; |
124 static jobject j_application_context = nullptr; | 124 static jobject j_application_context = nullptr; |
125 | 125 |
126 // Return the (singleton) Java Enum object corresponding to |index|; | 126 // Return the (singleton) Java Enum object corresponding to |index|; |
127 // |state_class_fragment| is something like "MediaSource$State". | 127 // |state_class_fragment| is something like "MediaSource$State". |
128 static jobject JavaEnumFromIndex( | 128 static jobject JavaEnumFromIndex( |
129 JNIEnv* jni, const std::string& state_class_fragment, int index) { | 129 JNIEnv* jni, const std::string& state_class_fragment, int index) { |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 jni->NewObject(*candidate_class, ctor, j_mid, -1, j_sdp); | 482 jni->NewObject(*candidate_class, ctor, j_mid, -1, j_sdp); |
483 CHECK_EXCEPTION(jni) << "error during Java Candidate NewObject"; | 483 CHECK_EXCEPTION(jni) << "error during Java Candidate NewObject"; |
484 return j_candidate; | 484 return j_candidate; |
485 } | 485 } |
486 | 486 |
487 jobjectArray ToJavaCandidateArray( | 487 jobjectArray ToJavaCandidateArray( |
488 JNIEnv* jni, | 488 JNIEnv* jni, |
489 const std::vector<cricket::Candidate>& candidates) { | 489 const std::vector<cricket::Candidate>& candidates) { |
490 jclass candidate_class = FindClass(jni, "org/webrtc/IceCandidate"); | 490 jclass candidate_class = FindClass(jni, "org/webrtc/IceCandidate"); |
491 jobjectArray java_candidates = | 491 jobjectArray java_candidates = |
492 jni->NewObjectArray(candidates.size(), candidate_class, NULL); | 492 jni->NewObjectArray(candidates.size(), candidate_class, nullptr); |
493 int i = 0; | 493 int i = 0; |
494 for (const cricket::Candidate& candidate : candidates) { | 494 for (const cricket::Candidate& candidate : candidates) { |
495 jobject j_candidate = ToJavaCandidate(jni, &candidate_class, candidate); | 495 jobject j_candidate = ToJavaCandidate(jni, &candidate_class, candidate); |
496 jni->SetObjectArrayElement(java_candidates, i++, j_candidate); | 496 jni->SetObjectArrayElement(java_candidates, i++, j_candidate); |
497 } | 497 } |
498 return java_candidates; | 498 return java_candidates; |
499 } | 499 } |
500 | 500 |
501 jobjectArray ToJavaMediaStreamArray( | 501 jobjectArray ToJavaMediaStreamArray( |
502 JNIEnv* jni, | 502 JNIEnv* jni, |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 jobjectArray j_reports = ReportsToJava(jni(), reports); | 787 jobjectArray j_reports = ReportsToJava(jni(), reports); |
788 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onComplete", | 788 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onComplete", |
789 "([Lorg/webrtc/StatsReport;)V"); | 789 "([Lorg/webrtc/StatsReport;)V"); |
790 jni()->CallVoidMethod(*j_observer_global_, m, j_reports); | 790 jni()->CallVoidMethod(*j_observer_global_, m, j_reports); |
791 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 791 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
792 } | 792 } |
793 | 793 |
794 private: | 794 private: |
795 jobjectArray ReportsToJava( | 795 jobjectArray ReportsToJava( |
796 JNIEnv* jni, const StatsReports& reports) { | 796 JNIEnv* jni, const StatsReports& reports) { |
797 jobjectArray reports_array = jni->NewObjectArray( | 797 jobjectArray reports_array = |
798 reports.size(), *j_stats_report_class_, NULL); | 798 jni->NewObjectArray(reports.size(), *j_stats_report_class_, nullptr); |
799 int i = 0; | 799 int i = 0; |
800 for (const auto* report : reports) { | 800 for (const auto* report : reports) { |
801 ScopedLocalRefFrame local_ref_frame(jni); | 801 ScopedLocalRefFrame local_ref_frame(jni); |
802 jstring j_id = JavaStringFromStdString(jni, report->id()->ToString()); | 802 jstring j_id = JavaStringFromStdString(jni, report->id()->ToString()); |
803 jstring j_type = JavaStringFromStdString(jni, report->TypeToString()); | 803 jstring j_type = JavaStringFromStdString(jni, report->TypeToString()); |
804 jobjectArray j_values = ValuesToJava(jni, report->values()); | 804 jobjectArray j_values = ValuesToJava(jni, report->values()); |
805 jobject j_report = jni->NewObject(*j_stats_report_class_, | 805 jobject j_report = jni->NewObject(*j_stats_report_class_, |
806 j_stats_report_ctor_, | 806 j_stats_report_ctor_, |
807 j_id, | 807 j_id, |
808 j_type, | 808 j_type, |
809 report->timestamp(), | 809 report->timestamp(), |
810 j_values); | 810 j_values); |
811 jni->SetObjectArrayElement(reports_array, i++, j_report); | 811 jni->SetObjectArrayElement(reports_array, i++, j_report); |
812 } | 812 } |
813 return reports_array; | 813 return reports_array; |
814 } | 814 } |
815 | 815 |
816 jobjectArray ValuesToJava(JNIEnv* jni, const StatsReport::Values& values) { | 816 jobjectArray ValuesToJava(JNIEnv* jni, const StatsReport::Values& values) { |
817 jobjectArray j_values = jni->NewObjectArray( | 817 jobjectArray j_values = |
818 values.size(), *j_value_class_, NULL); | 818 jni->NewObjectArray(values.size(), *j_value_class_, nullptr); |
819 int i = 0; | 819 int i = 0; |
820 for (const auto& it : values) { | 820 for (const auto& it : values) { |
821 ScopedLocalRefFrame local_ref_frame(jni); | 821 ScopedLocalRefFrame local_ref_frame(jni); |
822 // Should we use the '.name' enum value here instead of converting the | 822 // Should we use the '.name' enum value here instead of converting the |
823 // name to a string? | 823 // name to a string? |
824 jstring j_name = JavaStringFromStdString(jni, it.second->display_name()); | 824 jstring j_name = JavaStringFromStdString(jni, it.second->display_name()); |
825 jstring j_value = JavaStringFromStdString(jni, it.second->ToString()); | 825 jstring j_value = JavaStringFromStdString(jni, it.second->ToString()); |
826 jobject j_element_value = | 826 jobject j_element_value = |
827 jni->NewObject(*j_value_class_, j_value_ctor_, j_name, j_value); | 827 jni->NewObject(*j_value_class_, j_value_ctor_, j_name, j_value); |
828 jni->SetObjectArrayElement(j_values, i++, j_element_value); | 828 jni->SetObjectArrayElement(j_values, i++, j_element_value); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 // Make a shallow copy of |frame| to be used with Java. The callee has | 881 // Make a shallow copy of |frame| to be used with Java. The callee has |
882 // ownership of the frame, and the frame should be released with | 882 // ownership of the frame, and the frame should be released with |
883 // VideoRenderer.releaseNativeFrame(). | 883 // VideoRenderer.releaseNativeFrame(). |
884 static jlong javaShallowCopy(const webrtc::VideoFrame* frame) { | 884 static jlong javaShallowCopy(const webrtc::VideoFrame* frame) { |
885 return jlongFromPointer(new webrtc::VideoFrame(*frame)); | 885 return jlongFromPointer(new webrtc::VideoFrame(*frame)); |
886 } | 886 } |
887 | 887 |
888 // Return a VideoRenderer.I420Frame referring to the data in |frame|. | 888 // Return a VideoRenderer.I420Frame referring to the data in |frame|. |
889 jobject CricketToJavaI420Frame(const webrtc::VideoFrame* frame) { | 889 jobject CricketToJavaI420Frame(const webrtc::VideoFrame* frame) { |
890 jintArray strides = jni()->NewIntArray(3); | 890 jintArray strides = jni()->NewIntArray(3); |
891 jint* strides_array = jni()->GetIntArrayElements(strides, NULL); | 891 jint* strides_array = jni()->GetIntArrayElements(strides, nullptr); |
892 strides_array[0] = frame->video_frame_buffer()->StrideY(); | 892 strides_array[0] = frame->video_frame_buffer()->StrideY(); |
893 strides_array[1] = frame->video_frame_buffer()->StrideU(); | 893 strides_array[1] = frame->video_frame_buffer()->StrideU(); |
894 strides_array[2] = frame->video_frame_buffer()->StrideV(); | 894 strides_array[2] = frame->video_frame_buffer()->StrideV(); |
895 jni()->ReleaseIntArrayElements(strides, strides_array, 0); | 895 jni()->ReleaseIntArrayElements(strides, strides_array, 0); |
896 jobjectArray planes = jni()->NewObjectArray(3, *j_byte_buffer_class_, NULL); | 896 jobjectArray planes = |
| 897 jni()->NewObjectArray(3, *j_byte_buffer_class_, nullptr); |
897 jobject y_buffer = jni()->NewDirectByteBuffer( | 898 jobject y_buffer = jni()->NewDirectByteBuffer( |
898 const_cast<uint8_t*>(frame->video_frame_buffer()->DataY()), | 899 const_cast<uint8_t*>(frame->video_frame_buffer()->DataY()), |
899 frame->video_frame_buffer()->StrideY() * | 900 frame->video_frame_buffer()->StrideY() * |
900 frame->video_frame_buffer()->height()); | 901 frame->video_frame_buffer()->height()); |
901 size_t chroma_height = (frame->height() + 1) / 2; | 902 size_t chroma_height = (frame->height() + 1) / 2; |
902 jobject u_buffer = jni()->NewDirectByteBuffer( | 903 jobject u_buffer = jni()->NewDirectByteBuffer( |
903 const_cast<uint8_t*>(frame->video_frame_buffer()->DataU()), | 904 const_cast<uint8_t*>(frame->video_frame_buffer()->DataU()), |
904 frame->video_frame_buffer()->StrideU() * chroma_height); | 905 frame->video_frame_buffer()->StrideU() * chroma_height); |
905 jobject v_buffer = jni()->NewDirectByteBuffer( | 906 jobject v_buffer = jni()->NewDirectByteBuffer( |
906 const_cast<uint8_t*>(frame->video_frame_buffer()->DataV()), | 907 const_cast<uint8_t*>(frame->video_frame_buffer()->DataV()), |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1012 << "buffered_amount overflowed jlong!"; | 1013 << "buffered_amount overflowed jlong!"; |
1013 return static_cast<jlong>(buffered_amount); | 1014 return static_cast<jlong>(buffered_amount); |
1014 } | 1015 } |
1015 | 1016 |
1016 JOW(void, DataChannel_close)(JNIEnv* jni, jobject j_dc) { | 1017 JOW(void, DataChannel_close)(JNIEnv* jni, jobject j_dc) { |
1017 ExtractNativeDC(jni, j_dc)->Close(); | 1018 ExtractNativeDC(jni, j_dc)->Close(); |
1018 } | 1019 } |
1019 | 1020 |
1020 JOW(jboolean, DataChannel_sendNative)(JNIEnv* jni, jobject j_dc, | 1021 JOW(jboolean, DataChannel_sendNative)(JNIEnv* jni, jobject j_dc, |
1021 jbyteArray data, jboolean binary) { | 1022 jbyteArray data, jboolean binary) { |
1022 jbyte* bytes = jni->GetByteArrayElements(data, NULL); | 1023 jbyte* bytes = jni->GetByteArrayElements(data, nullptr); |
1023 bool ret = ExtractNativeDC(jni, j_dc)->Send(DataBuffer( | 1024 bool ret = ExtractNativeDC(jni, j_dc)->Send(DataBuffer( |
1024 rtc::CopyOnWriteBuffer(bytes, jni->GetArrayLength(data)), | 1025 rtc::CopyOnWriteBuffer(bytes, jni->GetArrayLength(data)), |
1025 binary)); | 1026 binary)); |
1026 jni->ReleaseByteArrayElements(data, bytes, JNI_ABORT); | 1027 jni->ReleaseByteArrayElements(data, bytes, JNI_ABORT); |
1027 return ret; | 1028 return ret; |
1028 } | 1029 } |
1029 | 1030 |
1030 JOW(void, DataChannel_dispose)(JNIEnv* jni, jobject j_dc) { | 1031 JOW(void, DataChannel_dispose)(JNIEnv* jni, jobject j_dc) { |
1031 CHECK_RELEASE(ExtractNativeDC(jni, j_dc)); | 1032 CHECK_RELEASE(ExtractNativeDC(jni, j_dc)); |
1032 } | 1033 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 | 1151 |
1151 if (initialize_audio) | 1152 if (initialize_audio) |
1152 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); | 1153 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); |
1153 factory_static_initialized = true; | 1154 factory_static_initialized = true; |
1154 } | 1155 } |
1155 return !failure; | 1156 return !failure; |
1156 } | 1157 } |
1157 | 1158 |
1158 JOW(void, PeerConnectionFactory_initializeFieldTrials)( | 1159 JOW(void, PeerConnectionFactory_initializeFieldTrials)( |
1159 JNIEnv* jni, jclass, jstring j_trials_init_string) { | 1160 JNIEnv* jni, jclass, jstring j_trials_init_string) { |
1160 field_trials_init_string = NULL; | 1161 field_trials_init_string = nullptr; |
1161 if (j_trials_init_string != NULL) { | 1162 if (j_trials_init_string != nullptr) { |
1162 const char* init_string = | 1163 const char* init_string = |
1163 jni->GetStringUTFChars(j_trials_init_string, NULL); | 1164 jni->GetStringUTFChars(j_trials_init_string, nullptr); |
1164 int init_string_length = jni->GetStringUTFLength(j_trials_init_string); | 1165 int init_string_length = jni->GetStringUTFLength(j_trials_init_string); |
1165 field_trials_init_string = new char[init_string_length + 1]; | 1166 field_trials_init_string = new char[init_string_length + 1]; |
1166 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string); | 1167 rtc::strcpyn(field_trials_init_string, init_string_length + 1, init_string); |
1167 jni->ReleaseStringUTFChars(j_trials_init_string, init_string); | 1168 jni->ReleaseStringUTFChars(j_trials_init_string, init_string); |
1168 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string; | 1169 LOG(LS_INFO) << "initializeFieldTrials: " << field_trials_init_string; |
1169 } | 1170 } |
1170 webrtc::field_trial::InitFieldTrialsFromString(field_trials_init_string); | 1171 webrtc::field_trial::InitFieldTrialsFromString(field_trials_init_string); |
1171 } | 1172 } |
1172 | 1173 |
1173 JOW(void, PeerConnectionFactory_initializeInternalTracer)(JNIEnv* jni, jclass) { | 1174 JOW(void, PeerConnectionFactory_initializeInternalTracer)(JNIEnv* jni, jclass) { |
1174 rtc::tracing::SetupInternalTracer(); | 1175 rtc::tracing::SetupInternalTracer(); |
1175 } | 1176 } |
1176 | 1177 |
1177 JOW(jstring, PeerConnectionFactory_nativeFieldTrialsFindFullName) | 1178 JOW(jstring, PeerConnectionFactory_nativeFieldTrialsFindFullName) |
1178 (JNIEnv* jni, jclass, jstring j_name) { | 1179 (JNIEnv* jni, jclass, jstring j_name) { |
1179 return JavaStringFromStdString( | 1180 return JavaStringFromStdString( |
1180 jni, webrtc::field_trial::FindFullName(JavaToStdString(jni, j_name))); | 1181 jni, webrtc::field_trial::FindFullName(JavaToStdString(jni, j_name))); |
1181 } | 1182 } |
1182 | 1183 |
1183 JOW(jboolean, PeerConnectionFactory_startInternalTracingCapture)( | 1184 JOW(jboolean, PeerConnectionFactory_startInternalTracingCapture)( |
1184 JNIEnv* jni, jclass, jstring j_event_tracing_filename) { | 1185 JNIEnv* jni, jclass, jstring j_event_tracing_filename) { |
1185 if (!j_event_tracing_filename) | 1186 if (!j_event_tracing_filename) |
1186 return false; | 1187 return false; |
1187 | 1188 |
1188 const char* init_string = | 1189 const char* init_string = |
1189 jni->GetStringUTFChars(j_event_tracing_filename, NULL); | 1190 jni->GetStringUTFChars(j_event_tracing_filename, nullptr); |
1190 LOG(LS_INFO) << "Starting internal tracing to: " << init_string; | 1191 LOG(LS_INFO) << "Starting internal tracing to: " << init_string; |
1191 bool ret = rtc::tracing::StartInternalCapture(init_string); | 1192 bool ret = rtc::tracing::StartInternalCapture(init_string); |
1192 jni->ReleaseStringUTFChars(j_event_tracing_filename, init_string); | 1193 jni->ReleaseStringUTFChars(j_event_tracing_filename, init_string); |
1193 return ret; | 1194 return ret; |
1194 } | 1195 } |
1195 | 1196 |
1196 JOW(void, PeerConnectionFactory_stopInternalTracingCapture)( | 1197 JOW(void, PeerConnectionFactory_stopInternalTracingCapture)( |
1197 JNIEnv* jni, jclass) { | 1198 JNIEnv* jni, jclass) { |
1198 rtc::tracing::StopInternalCapture(); | 1199 rtc::tracing::StopInternalCapture(); |
1199 } | 1200 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 std::unique_ptr<Thread> network_thread = | 1331 std::unique_ptr<Thread> network_thread = |
1331 rtc::Thread::CreateWithSocketServer(); | 1332 rtc::Thread::CreateWithSocketServer(); |
1332 network_thread->SetName("network_thread", nullptr); | 1333 network_thread->SetName("network_thread", nullptr); |
1333 RTC_CHECK(network_thread->Start()) << "Failed to start thread"; | 1334 RTC_CHECK(network_thread->Start()) << "Failed to start thread"; |
1334 | 1335 |
1335 std::unique_ptr<Thread> worker_thread = rtc::Thread::Create(); | 1336 std::unique_ptr<Thread> worker_thread = rtc::Thread::Create(); |
1336 worker_thread->SetName("worker_thread", nullptr); | 1337 worker_thread->SetName("worker_thread", nullptr); |
1337 RTC_CHECK(worker_thread->Start()) << "Failed to start thread"; | 1338 RTC_CHECK(worker_thread->Start()) << "Failed to start thread"; |
1338 | 1339 |
1339 std::unique_ptr<Thread> signaling_thread = rtc::Thread::Create(); | 1340 std::unique_ptr<Thread> signaling_thread = rtc::Thread::Create(); |
1340 signaling_thread->SetName("signaling_thread", NULL); | 1341 signaling_thread->SetName("signaling_thread", nullptr); |
1341 RTC_CHECK(signaling_thread->Start()) << "Failed to start thread"; | 1342 RTC_CHECK(signaling_thread->Start()) << "Failed to start thread"; |
1342 | 1343 |
1343 WebRtcVideoEncoderFactory* encoder_factory = nullptr; | 1344 WebRtcVideoEncoderFactory* encoder_factory = nullptr; |
1344 WebRtcVideoDecoderFactory* decoder_factory = nullptr; | 1345 WebRtcVideoDecoderFactory* decoder_factory = nullptr; |
1345 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; | 1346 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; |
1346 | 1347 |
1347 PeerConnectionFactoryInterface::Options options; | 1348 PeerConnectionFactoryInterface::Options options; |
1348 bool has_options = joptions != NULL; | 1349 bool has_options = joptions != nullptr; |
1349 if (has_options) { | 1350 if (has_options) { |
1350 options = ParseOptionsFromJava(jni, joptions); | 1351 options = ParseOptionsFromJava(jni, joptions); |
1351 } | 1352 } |
1352 | 1353 |
1353 if (video_hw_acceleration_enabled) { | 1354 if (video_hw_acceleration_enabled) { |
1354 encoder_factory = new MediaCodecVideoEncoderFactory(); | 1355 encoder_factory = new MediaCodecVideoEncoderFactory(); |
1355 decoder_factory = new MediaCodecVideoDecoderFactory(); | 1356 decoder_factory = new MediaCodecVideoDecoderFactory(); |
1356 } | 1357 } |
1357 // Do not create network_monitor_factory only if the options are | 1358 // Do not create network_monitor_factory only if the options are |
1358 // provided and disable_network_monitor therein is set to true. | 1359 // provided and disable_network_monitor therein is set to true. |
(...skipping 17 matching lines...) Expand all Loading... |
1376 std::move(network_thread), std::move(worker_thread), | 1377 std::move(network_thread), std::move(worker_thread), |
1377 std::move(signaling_thread), encoder_factory, decoder_factory, | 1378 std::move(signaling_thread), encoder_factory, decoder_factory, |
1378 network_monitor_factory, factory.release()); | 1379 network_monitor_factory, factory.release()); |
1379 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); | 1380 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); |
1380 return jlongFromPointer(owned_factory); | 1381 return jlongFromPointer(owned_factory); |
1381 } | 1382 } |
1382 | 1383 |
1383 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { | 1384 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { |
1384 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1385 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1385 if (field_trials_init_string) { | 1386 if (field_trials_init_string) { |
1386 webrtc::field_trial::InitFieldTrialsFromString(NULL); | 1387 webrtc::field_trial::InitFieldTrialsFromString(nullptr); |
1387 delete field_trials_init_string; | 1388 delete field_trials_init_string; |
1388 field_trials_init_string = NULL; | 1389 field_trials_init_string = nullptr; |
1389 } | 1390 } |
1390 webrtc::Trace::ReturnTrace(); | 1391 webrtc::Trace::ReturnTrace(); |
1391 } | 1392 } |
1392 | 1393 |
1393 static PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { | 1394 static PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { |
1394 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); | 1395 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); |
1395 } | 1396 } |
1396 | 1397 |
1397 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( | 1398 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( |
1398 JNIEnv*, jclass, jlong j_p) { | 1399 JNIEnv*, jclass, jlong j_p) { |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 jfieldID native_pc_id = GetFieldID(jni, | 1873 jfieldID native_pc_id = GetFieldID(jni, |
1873 GetObjectClass(jni, j_pc), "nativePeerConnection", "J"); | 1874 GetObjectClass(jni, j_pc), "nativePeerConnection", "J"); |
1874 jlong j_p = GetLongField(jni, j_pc, native_pc_id); | 1875 jlong j_p = GetLongField(jni, j_pc, native_pc_id); |
1875 return rtc::scoped_refptr<PeerConnectionInterface>( | 1876 return rtc::scoped_refptr<PeerConnectionInterface>( |
1876 reinterpret_cast<PeerConnectionInterface*>(j_p)); | 1877 reinterpret_cast<PeerConnectionInterface*>(j_p)); |
1877 } | 1878 } |
1878 | 1879 |
1879 JOW(jobject, PeerConnection_getLocalDescription)(JNIEnv* jni, jobject j_pc) { | 1880 JOW(jobject, PeerConnection_getLocalDescription)(JNIEnv* jni, jobject j_pc) { |
1880 const SessionDescriptionInterface* sdp = | 1881 const SessionDescriptionInterface* sdp = |
1881 ExtractNativePC(jni, j_pc)->local_description(); | 1882 ExtractNativePC(jni, j_pc)->local_description(); |
1882 return sdp ? JavaSdpFromNativeSdp(jni, sdp) : NULL; | 1883 return sdp ? JavaSdpFromNativeSdp(jni, sdp) : nullptr; |
1883 } | 1884 } |
1884 | 1885 |
1885 JOW(jobject, PeerConnection_getRemoteDescription)(JNIEnv* jni, jobject j_pc) { | 1886 JOW(jobject, PeerConnection_getRemoteDescription)(JNIEnv* jni, jobject j_pc) { |
1886 const SessionDescriptionInterface* sdp = | 1887 const SessionDescriptionInterface* sdp = |
1887 ExtractNativePC(jni, j_pc)->remote_description(); | 1888 ExtractNativePC(jni, j_pc)->remote_description(); |
1888 return sdp ? JavaSdpFromNativeSdp(jni, sdp) : NULL; | 1889 return sdp ? JavaSdpFromNativeSdp(jni, sdp) : nullptr; |
1889 } | 1890 } |
1890 | 1891 |
1891 JOW(jobject, PeerConnection_createDataChannel)( | 1892 JOW(jobject, PeerConnection_createDataChannel)( |
1892 JNIEnv* jni, jobject j_pc, jstring j_label, jobject j_init) { | 1893 JNIEnv* jni, jobject j_pc, jstring j_label, jobject j_init) { |
1893 DataChannelInit init = JavaDataChannelInitToNative(jni, j_init); | 1894 DataChannelInit init = JavaDataChannelInitToNative(jni, j_init); |
1894 rtc::scoped_refptr<DataChannelInterface> channel( | 1895 rtc::scoped_refptr<DataChannelInterface> channel( |
1895 ExtractNativePC(jni, j_pc)->CreateDataChannel( | 1896 ExtractNativePC(jni, j_pc)->CreateDataChannel( |
1896 JavaToStdString(jni, j_label), &init)); | 1897 JavaToStdString(jni, j_label), &init)); |
1897 // Mustn't pass channel.get() directly through NewObject to avoid reading its | 1898 // Mustn't pass channel.get() directly through NewObject to avoid reading its |
1898 // vararg parameter as 64-bit and reading memory that doesn't belong to the | 1899 // vararg parameter as 64-bit and reading memory that doesn't belong to the |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 jstring j_type_string = (jstring)jni->CallObjectMethod( | 1948 jstring j_type_string = (jstring)jni->CallObjectMethod( |
1948 j_type, j_canonical_form_id); | 1949 j_type, j_canonical_form_id); |
1949 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; | 1950 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; |
1950 std::string std_type = JavaToStdString(jni, j_type_string); | 1951 std::string std_type = JavaToStdString(jni, j_type_string); |
1951 | 1952 |
1952 jfieldID j_description_id = GetFieldID( | 1953 jfieldID j_description_id = GetFieldID( |
1953 jni, GetObjectClass(jni, j_sdp), "description", "Ljava/lang/String;"); | 1954 jni, GetObjectClass(jni, j_sdp), "description", "Ljava/lang/String;"); |
1954 jstring j_description = (jstring)GetObjectField(jni, j_sdp, j_description_id); | 1955 jstring j_description = (jstring)GetObjectField(jni, j_sdp, j_description_id); |
1955 std::string std_description = JavaToStdString(jni, j_description); | 1956 std::string std_description = JavaToStdString(jni, j_description); |
1956 | 1957 |
1957 return webrtc::CreateSessionDescription( | 1958 return webrtc::CreateSessionDescription(std_type, std_description, nullptr); |
1958 std_type, std_description, NULL); | |
1959 } | 1959 } |
1960 | 1960 |
1961 JOW(void, PeerConnection_setLocalDescription)( | 1961 JOW(void, PeerConnection_setLocalDescription)( |
1962 JNIEnv* jni, jobject j_pc, | 1962 JNIEnv* jni, jobject j_pc, |
1963 jobject j_observer, jobject j_sdp) { | 1963 jobject j_observer, jobject j_sdp) { |
1964 rtc::scoped_refptr<SetSdpObserverWrapper> observer( | 1964 rtc::scoped_refptr<SetSdpObserverWrapper> observer( |
1965 new rtc::RefCountedObject<SetSdpObserverWrapper>( | 1965 new rtc::RefCountedObject<SetSdpObserverWrapper>(jni, j_observer, |
1966 jni, j_observer, reinterpret_cast<ConstraintsWrapper*>(NULL))); | 1966 nullptr)); |
1967 ExtractNativePC(jni, j_pc)->SetLocalDescription( | 1967 ExtractNativePC(jni, j_pc)->SetLocalDescription( |
1968 observer, JavaSdpToNativeSdp(jni, j_sdp)); | 1968 observer, JavaSdpToNativeSdp(jni, j_sdp)); |
1969 } | 1969 } |
1970 | 1970 |
1971 JOW(void, PeerConnection_setRemoteDescription)( | 1971 JOW(void, PeerConnection_setRemoteDescription)( |
1972 JNIEnv* jni, jobject j_pc, | 1972 JNIEnv* jni, jobject j_pc, |
1973 jobject j_observer, jobject j_sdp) { | 1973 jobject j_observer, jobject j_sdp) { |
1974 rtc::scoped_refptr<SetSdpObserverWrapper> observer( | 1974 rtc::scoped_refptr<SetSdpObserverWrapper> observer( |
1975 new rtc::RefCountedObject<SetSdpObserverWrapper>( | 1975 new rtc::RefCountedObject<SetSdpObserverWrapper>(jni, j_observer, |
1976 jni, j_observer, reinterpret_cast<ConstraintsWrapper*>(NULL))); | 1976 nullptr)); |
1977 ExtractNativePC(jni, j_pc)->SetRemoteDescription( | 1977 ExtractNativePC(jni, j_pc)->SetRemoteDescription( |
1978 observer, JavaSdpToNativeSdp(jni, j_sdp)); | 1978 observer, JavaSdpToNativeSdp(jni, j_sdp)); |
1979 } | 1979 } |
1980 | 1980 |
1981 JOW(jboolean, PeerConnection_nativeSetConfiguration)( | 1981 JOW(jboolean, PeerConnection_nativeSetConfiguration)( |
1982 JNIEnv* jni, jobject j_pc, jobject j_rtc_config, jlong native_observer) { | 1982 JNIEnv* jni, jobject j_pc, jobject j_rtc_config, jlong native_observer) { |
1983 // Need to merge constraints into RTCConfiguration again, which are stored | 1983 // Need to merge constraints into RTCConfiguration again, which are stored |
1984 // in the observer object. | 1984 // in the observer object. |
1985 PCOJava* observer = reinterpret_cast<PCOJava*>(native_observer); | 1985 PCOJava* observer = reinterpret_cast<PCOJava*>(native_observer); |
1986 PeerConnectionInterface::RTCConfiguration rtc_config( | 1986 PeerConnectionInterface::RTCConfiguration rtc_config( |
1987 PeerConnectionInterface::RTCConfigurationType::kAggressive); | 1987 PeerConnectionInterface::RTCConfigurationType::kAggressive); |
1988 JavaRTCConfigurationToJsepRTCConfiguration(jni, j_rtc_config, &rtc_config); | 1988 JavaRTCConfigurationToJsepRTCConfiguration(jni, j_rtc_config, &rtc_config); |
1989 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config); | 1989 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config); |
1990 return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config); | 1990 return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config); |
1991 } | 1991 } |
1992 | 1992 |
1993 JOW(jboolean, PeerConnection_nativeAddIceCandidate)( | 1993 JOW(jboolean, PeerConnection_nativeAddIceCandidate)( |
1994 JNIEnv* jni, jobject j_pc, jstring j_sdp_mid, | 1994 JNIEnv* jni, jobject j_pc, jstring j_sdp_mid, |
1995 jint j_sdp_mline_index, jstring j_candidate_sdp) { | 1995 jint j_sdp_mline_index, jstring j_candidate_sdp) { |
1996 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); | 1996 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); |
1997 std::string sdp = JavaToStdString(jni, j_candidate_sdp); | 1997 std::string sdp = JavaToStdString(jni, j_candidate_sdp); |
1998 std::unique_ptr<IceCandidateInterface> candidate( | 1998 std::unique_ptr<IceCandidateInterface> candidate( |
1999 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, NULL)); | 1999 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, nullptr)); |
2000 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); | 2000 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); |
2001 } | 2001 } |
2002 | 2002 |
2003 static cricket::Candidate GetCandidateFromJava(JNIEnv* jni, | 2003 static cricket::Candidate GetCandidateFromJava(JNIEnv* jni, |
2004 jobject j_candidate) { | 2004 jobject j_candidate) { |
2005 jclass j_candidate_class = GetObjectClass(jni, j_candidate); | 2005 jclass j_candidate_class = GetObjectClass(jni, j_candidate); |
2006 jfieldID j_sdp_mid_id = | 2006 jfieldID j_sdp_mid_id = |
2007 GetFieldID(jni, j_candidate_class, "sdpMid", "Ljava/lang/String;"); | 2007 GetFieldID(jni, j_candidate_class, "sdpMid", "Ljava/lang/String;"); |
2008 std::string sdp_mid = | 2008 std::string sdp_mid = |
2009 JavaToStdString(jni, GetStringField(jni, j_candidate, j_sdp_mid_id)); | 2009 JavaToStdString(jni, GetStringField(jni, j_candidate, j_sdp_mid_id)); |
2010 jfieldID j_sdp_id = | 2010 jfieldID j_sdp_id = |
2011 GetFieldID(jni, j_candidate_class, "sdp", "Ljava/lang/String;"); | 2011 GetFieldID(jni, j_candidate_class, "sdp", "Ljava/lang/String;"); |
2012 std::string sdp = | 2012 std::string sdp = |
2013 JavaToStdString(jni, GetStringField(jni, j_candidate, j_sdp_id)); | 2013 JavaToStdString(jni, GetStringField(jni, j_candidate, j_sdp_id)); |
2014 cricket::Candidate candidate; | 2014 cricket::Candidate candidate; |
2015 if (!webrtc::SdpDeserializeCandidate(sdp_mid, sdp, &candidate, NULL)) { | 2015 if (!webrtc::SdpDeserializeCandidate(sdp_mid, sdp, &candidate, nullptr)) { |
2016 LOG(LS_ERROR) << "SdpDescrializeCandidate failed with sdp " << sdp; | 2016 LOG(LS_ERROR) << "SdpDescrializeCandidate failed with sdp " << sdp; |
2017 } | 2017 } |
2018 return candidate; | 2018 return candidate; |
2019 } | 2019 } |
2020 | 2020 |
2021 JOW(jboolean, PeerConnection_nativeRemoveIceCandidates) | 2021 JOW(jboolean, PeerConnection_nativeRemoveIceCandidates) |
2022 (JNIEnv* jni, jobject j_pc, jobjectArray j_candidates) { | 2022 (JNIEnv* jni, jobject j_pc, jobjectArray j_candidates) { |
2023 std::vector<cricket::Candidate> candidates; | 2023 std::vector<cricket::Candidate> candidates; |
2024 size_t num_candidates = jni->GetArrayLength(j_candidates); | 2024 size_t num_candidates = jni->GetArrayLength(j_candidates); |
2025 for (size_t i = 0; i < num_candidates; ++i) { | 2025 for (size_t i = 0; i < num_candidates; ++i) { |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2725 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) | 2725 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) |
2726 ->inter_tone_gap(); | 2726 ->inter_tone_gap(); |
2727 } | 2727 } |
2728 | 2728 |
2729 JOW(void, DtmfSender_free) | 2729 JOW(void, DtmfSender_free) |
2730 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { | 2730 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { |
2731 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); | 2731 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); |
2732 } | 2732 } |
2733 | 2733 |
2734 } // namespace webrtc_jni | 2734 } // namespace webrtc_jni |
OLD | NEW |