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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "webrtc/base/checks.h" | 54 #include "webrtc/base/checks.h" |
55 #include "webrtc/base/event_tracer.h" | 55 #include "webrtc/base/event_tracer.h" |
56 #include "webrtc/base/logging.h" | 56 #include "webrtc/base/logging.h" |
57 #include "webrtc/base/logsinks.h" | 57 #include "webrtc/base/logsinks.h" |
58 #include "webrtc/base/messagequeue.h" | 58 #include "webrtc/base/messagequeue.h" |
59 #include "webrtc/base/networkmonitor.h" | 59 #include "webrtc/base/networkmonitor.h" |
60 #include "webrtc/base/rtccertificategenerator.h" | 60 #include "webrtc/base/rtccertificategenerator.h" |
61 #include "webrtc/base/ssladapter.h" | 61 #include "webrtc/base/ssladapter.h" |
62 #include "webrtc/base/stringutils.h" | 62 #include "webrtc/base/stringutils.h" |
63 #include "webrtc/media/base/videocapturer.h" | 63 #include "webrtc/media/base/videocapturer.h" |
64 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" | |
65 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" | |
66 #include "webrtc/modules/utility/include/jvm_android.h" | 64 #include "webrtc/modules/utility/include/jvm_android.h" |
67 #include "webrtc/system_wrappers/include/field_trial.h" | |
68 #include "webrtc/pc/webrtcsdp.h" | 65 #include "webrtc/pc/webrtcsdp.h" |
69 #include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h" | |
70 #include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h" | |
71 #include "webrtc/sdk/android/src/jni/androidnetworkmonitor_jni.h" | 66 #include "webrtc/sdk/android/src/jni/androidnetworkmonitor_jni.h" |
72 #include "webrtc/sdk/android/src/jni/androidvideotracksource.h" | 67 // Adding 'nogncheck' to disable the gn include headers check. |
| 68 // We don't want to always depend on audio and video related targets. |
| 69 #include "webrtc/sdk/android/src/jni/androidvideotracksource.h" // nogncheck |
73 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" | 70 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" |
74 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | 71 #include "webrtc/sdk/android/src/jni/jni_helpers.h" |
75 #include "webrtc/sdk/android/src/jni/native_handle_impl.h" | 72 #include "webrtc/sdk/android/src/jni/ownedfactoryandthreads.h" |
76 #include "webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h" | 73 #include "webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h" |
| 74 #include "webrtc/system_wrappers/include/field_trial.h" |
77 // Adding 'nogncheck' to disable the gn include headers check. | 75 // Adding 'nogncheck' to disable the gn include headers check. |
78 // We don't want to depend on 'system_wrappers:field_trial_default' because | 76 // We don't want to depend on 'system_wrappers:field_trial_default' because |
79 // clients should be able to provide their own implementation. | 77 // clients should be able to provide their own implementation. |
80 #include "webrtc/system_wrappers/include/field_trial_default.h" // nogncheck | 78 #include "webrtc/system_wrappers/include/field_trial_default.h" // nogncheck |
81 #include "webrtc/system_wrappers/include/logcat_trace_context.h" | 79 #include "webrtc/system_wrappers/include/logcat_trace_context.h" |
82 #include "webrtc/system_wrappers/include/trace.h" | 80 #include "webrtc/system_wrappers/include/trace.h" |
83 #include "webrtc/voice_engine/include/voe_base.h" | 81 #include "webrtc/voice_engine/include/voe_base.h" // nogncheck |
84 | 82 |
85 using cricket::WebRtcVideoDecoderFactory; | 83 using cricket::WebRtcVideoDecoderFactory; |
86 using cricket::WebRtcVideoEncoderFactory; | 84 using cricket::WebRtcVideoEncoderFactory; |
87 using rtc::Bind; | 85 using rtc::Bind; |
88 using rtc::Thread; | 86 using rtc::Thread; |
89 using rtc::ThreadManager; | 87 using rtc::ThreadManager; |
90 using webrtc::AudioSourceInterface; | 88 using webrtc::AudioSourceInterface; |
91 using webrtc::AudioTrackInterface; | 89 using webrtc::AudioTrackInterface; |
92 using webrtc::AudioTrackVector; | 90 using webrtc::AudioTrackVector; |
93 using webrtc::CreateSessionDescriptionObserver; | 91 using webrtc::CreateSessionDescriptionObserver; |
(...skipping 12 matching lines...) Expand all Loading... |
106 using webrtc::PeerConnectionInterface; | 104 using webrtc::PeerConnectionInterface; |
107 using webrtc::PeerConnectionObserver; | 105 using webrtc::PeerConnectionObserver; |
108 using webrtc::RtpReceiverInterface; | 106 using webrtc::RtpReceiverInterface; |
109 using webrtc::RtpReceiverObserverInterface; | 107 using webrtc::RtpReceiverObserverInterface; |
110 using webrtc::RtpSenderInterface; | 108 using webrtc::RtpSenderInterface; |
111 using webrtc::SessionDescriptionInterface; | 109 using webrtc::SessionDescriptionInterface; |
112 using webrtc::SetSessionDescriptionObserver; | 110 using webrtc::SetSessionDescriptionObserver; |
113 using webrtc::StatsObserver; | 111 using webrtc::StatsObserver; |
114 using webrtc::StatsReport; | 112 using webrtc::StatsReport; |
115 using webrtc::StatsReports; | 113 using webrtc::StatsReports; |
116 using webrtc::VideoTrackSourceInterface; | |
117 using webrtc::VideoTrackInterface; | 114 using webrtc::VideoTrackInterface; |
118 using webrtc::VideoTrackVector; | |
119 using webrtc::kVideoCodecVP8; | |
120 | 115 |
121 namespace webrtc_jni { | 116 namespace webrtc_jni { |
122 | 117 |
| 118 WebRtcVideoEncoderFactory* CreateVideoEncoderFactory(); |
| 119 |
| 120 WebRtcVideoDecoderFactory* CreateVideoDecoderFactory(); |
| 121 |
| 122 jobject GetJavaSurfaceTextureHelper( |
| 123 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper); |
| 124 |
123 // Field trials initialization string | 125 // Field trials initialization string |
124 static char *field_trials_init_string = NULL; | 126 static char *field_trials_init_string = NULL; |
125 | 127 |
126 // Set in PeerConnectionFactory_initializeAndroidGlobals(). | 128 // Set in PeerConnectionFactory_initializeAndroidGlobals(). |
127 static bool factory_static_initialized = false; | 129 static bool factory_static_initialized = false; |
128 static bool video_hw_acceleration_enabled = true; | 130 static bool video_hw_acceleration_enabled = true; |
129 static jobject j_application_context = nullptr; | 131 static jobject j_application_context = nullptr; |
130 | 132 |
131 // Return the (singleton) Java Enum object corresponding to |index|; | 133 // Return the (singleton) Java Enum object corresponding to |index|; |
132 // |state_class_fragment| is something like "MediaSource$State". | 134 // |state_class_fragment| is something like "MediaSource$State". |
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 } | 842 } |
841 | 843 |
842 const ScopedGlobalRef<jobject> j_observer_global_; | 844 const ScopedGlobalRef<jobject> j_observer_global_; |
843 const ScopedGlobalRef<jclass> j_observer_class_; | 845 const ScopedGlobalRef<jclass> j_observer_class_; |
844 const ScopedGlobalRef<jclass> j_stats_report_class_; | 846 const ScopedGlobalRef<jclass> j_stats_report_class_; |
845 const jmethodID j_stats_report_ctor_; | 847 const jmethodID j_stats_report_ctor_; |
846 const ScopedGlobalRef<jclass> j_value_class_; | 848 const ScopedGlobalRef<jclass> j_value_class_; |
847 const jmethodID j_value_ctor_; | 849 const jmethodID j_value_ctor_; |
848 }; | 850 }; |
849 | 851 |
850 // Wrapper dispatching rtc::VideoSinkInterface to a Java VideoRenderer | |
851 // instance. | |
852 class JavaVideoRendererWrapper | |
853 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { | |
854 public: | |
855 JavaVideoRendererWrapper(JNIEnv* jni, jobject j_callbacks) | |
856 : j_callbacks_(jni, j_callbacks), | |
857 j_render_frame_id_(GetMethodID( | |
858 jni, GetObjectClass(jni, j_callbacks), "renderFrame", | |
859 "(Lorg/webrtc/VideoRenderer$I420Frame;)V")), | |
860 j_frame_class_(jni, | |
861 FindClass(jni, "org/webrtc/VideoRenderer$I420Frame")), | |
862 j_i420_frame_ctor_id_(GetMethodID( | |
863 jni, *j_frame_class_, "<init>", "(III[I[Ljava/nio/ByteBuffer;J)V")), | |
864 j_texture_frame_ctor_id_(GetMethodID( | |
865 jni, *j_frame_class_, "<init>", | |
866 "(IIII[FJ)V")), | |
867 j_byte_buffer_class_(jni, FindClass(jni, "java/nio/ByteBuffer")) { | |
868 CHECK_EXCEPTION(jni); | |
869 } | |
870 | |
871 virtual ~JavaVideoRendererWrapper() {} | |
872 | |
873 void OnFrame(const webrtc::VideoFrame& video_frame) override { | |
874 ScopedLocalRefFrame local_ref_frame(jni()); | |
875 jobject j_frame = | |
876 (video_frame.video_frame_buffer()->native_handle() != nullptr) | |
877 ? CricketToJavaTextureFrame(&video_frame) | |
878 : CricketToJavaI420Frame(&video_frame); | |
879 // |j_callbacks_| is responsible for releasing |j_frame| with | |
880 // VideoRenderer.renderFrameDone(). | |
881 jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame); | |
882 CHECK_EXCEPTION(jni()); | |
883 } | |
884 | |
885 private: | |
886 // Make a shallow copy of |frame| to be used with Java. The callee has | |
887 // ownership of the frame, and the frame should be released with | |
888 // VideoRenderer.releaseNativeFrame(). | |
889 static jlong javaShallowCopy(const webrtc::VideoFrame* frame) { | |
890 return jlongFromPointer(new webrtc::VideoFrame(*frame)); | |
891 } | |
892 | |
893 // Return a VideoRenderer.I420Frame referring to the data in |frame|. | |
894 jobject CricketToJavaI420Frame(const webrtc::VideoFrame* frame) { | |
895 jintArray strides = jni()->NewIntArray(3); | |
896 jint* strides_array = jni()->GetIntArrayElements(strides, NULL); | |
897 strides_array[0] = frame->video_frame_buffer()->StrideY(); | |
898 strides_array[1] = frame->video_frame_buffer()->StrideU(); | |
899 strides_array[2] = frame->video_frame_buffer()->StrideV(); | |
900 jni()->ReleaseIntArrayElements(strides, strides_array, 0); | |
901 jobjectArray planes = jni()->NewObjectArray(3, *j_byte_buffer_class_, NULL); | |
902 jobject y_buffer = jni()->NewDirectByteBuffer( | |
903 const_cast<uint8_t*>(frame->video_frame_buffer()->DataY()), | |
904 frame->video_frame_buffer()->StrideY() * | |
905 frame->video_frame_buffer()->height()); | |
906 size_t chroma_height = (frame->height() + 1) / 2; | |
907 jobject u_buffer = jni()->NewDirectByteBuffer( | |
908 const_cast<uint8_t*>(frame->video_frame_buffer()->DataU()), | |
909 frame->video_frame_buffer()->StrideU() * chroma_height); | |
910 jobject v_buffer = jni()->NewDirectByteBuffer( | |
911 const_cast<uint8_t*>(frame->video_frame_buffer()->DataV()), | |
912 frame->video_frame_buffer()->StrideV() * chroma_height); | |
913 | |
914 jni()->SetObjectArrayElement(planes, 0, y_buffer); | |
915 jni()->SetObjectArrayElement(planes, 1, u_buffer); | |
916 jni()->SetObjectArrayElement(planes, 2, v_buffer); | |
917 return jni()->NewObject( | |
918 *j_frame_class_, j_i420_frame_ctor_id_, | |
919 frame->width(), frame->height(), | |
920 static_cast<int>(frame->rotation()), | |
921 strides, planes, javaShallowCopy(frame)); | |
922 } | |
923 | |
924 // Return a VideoRenderer.I420Frame referring texture object in |frame|. | |
925 jobject CricketToJavaTextureFrame(const webrtc::VideoFrame* frame) { | |
926 NativeHandleImpl* handle = reinterpret_cast<NativeHandleImpl*>( | |
927 frame->video_frame_buffer()->native_handle()); | |
928 jfloatArray sampling_matrix = handle->sampling_matrix.ToJava(jni()); | |
929 | |
930 return jni()->NewObject( | |
931 *j_frame_class_, j_texture_frame_ctor_id_, | |
932 frame->width(), frame->height(), | |
933 static_cast<int>(frame->rotation()), | |
934 handle->oes_texture_id, sampling_matrix, javaShallowCopy(frame)); | |
935 } | |
936 | |
937 JNIEnv* jni() { | |
938 return AttachCurrentThreadIfNeeded(); | |
939 } | |
940 | |
941 ScopedGlobalRef<jobject> j_callbacks_; | |
942 jmethodID j_render_frame_id_; | |
943 ScopedGlobalRef<jclass> j_frame_class_; | |
944 jmethodID j_i420_frame_ctor_id_; | |
945 jmethodID j_texture_frame_ctor_id_; | |
946 ScopedGlobalRef<jclass> j_byte_buffer_class_; | |
947 }; | |
948 | |
949 // Adapter between the C++ RtpReceiverObserverInterface and the Java | 852 // Adapter between the C++ RtpReceiverObserverInterface and the Java |
950 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and | 853 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and |
951 // dispatches C++ callbacks to Java. | 854 // dispatches C++ callbacks to Java. |
952 class RtpReceiverObserver : public RtpReceiverObserverInterface { | 855 class RtpReceiverObserver : public RtpReceiverObserverInterface { |
953 public: | 856 public: |
954 RtpReceiverObserver(JNIEnv* jni, jobject j_observer) | 857 RtpReceiverObserver(JNIEnv* jni, jobject j_observer) |
955 : j_observer_global_(jni, j_observer) {} | 858 : j_observer_global_(jni, j_observer) {} |
956 | 859 |
957 ~RtpReceiverObserver() override {} | 860 ~RtpReceiverObserver() override {} |
958 | 861 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 | 984 |
1082 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { | 985 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { |
1083 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); | 986 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); |
1084 delete p; | 987 delete p; |
1085 } | 988 } |
1086 | 989 |
1087 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { | 990 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { |
1088 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); | 991 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); |
1089 } | 992 } |
1090 | 993 |
1091 JOW(void, VideoRenderer_freeWrappedVideoRenderer)(JNIEnv*, jclass, jlong j_p) { | |
1092 delete reinterpret_cast<JavaVideoRendererWrapper*>(j_p); | |
1093 } | |
1094 | |
1095 JOW(void, VideoRenderer_releaseNativeFrame)( | |
1096 JNIEnv* jni, jclass, jlong j_frame_ptr) { | |
1097 delete reinterpret_cast<const webrtc::VideoFrame*>(j_frame_ptr); | |
1098 } | |
1099 | |
1100 JOW(void, MediaStreamTrack_free)(JNIEnv*, jclass, jlong j_p) { | 994 JOW(void, MediaStreamTrack_free)(JNIEnv*, jclass, jlong j_p) { |
1101 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release(); | 995 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release(); |
1102 } | 996 } |
1103 | 997 |
1104 JOW(jboolean, MediaStream_nativeAddAudioTrack)( | 998 JOW(jboolean, MediaStream_nativeAddAudioTrack)( |
1105 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) { | 999 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) { |
1106 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack( | 1000 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack( |
1107 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer)); | 1001 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer)); |
1108 } | 1002 } |
1109 | 1003 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 rtc::tracing::ShutdownInternalTracer(); | 1094 rtc::tracing::ShutdownInternalTracer(); |
1201 } | 1095 } |
1202 | 1096 |
1203 JOW(void, AudioTrack_nativeSetVolume) | 1097 JOW(void, AudioTrack_nativeSetVolume) |
1204 (JNIEnv*, jclass, jlong j_p, jdouble volume) { | 1098 (JNIEnv*, jclass, jlong j_p, jdouble volume) { |
1205 rtc::scoped_refptr<AudioSourceInterface> source( | 1099 rtc::scoped_refptr<AudioSourceInterface> source( |
1206 reinterpret_cast<AudioTrackInterface*>(j_p)->GetSource()); | 1100 reinterpret_cast<AudioTrackInterface*>(j_p)->GetSource()); |
1207 source->SetVolume(volume); | 1101 source->SetVolume(volume); |
1208 } | 1102 } |
1209 | 1103 |
1210 // Helper struct for working around the fact that CreatePeerConnectionFactory() | |
1211 // comes in two flavors: either entirely automagical (constructing its own | |
1212 // threads and deleting them on teardown, but no external codec factory support) | |
1213 // or entirely manual (requires caller to delete threads after factory | |
1214 // teardown). This struct takes ownership of its ctor's arguments to present a | |
1215 // single thing for Java to hold and eventually free. | |
1216 class OwnedFactoryAndThreads { | |
1217 public: | |
1218 OwnedFactoryAndThreads(std::unique_ptr<Thread> network_thread, | |
1219 std::unique_ptr<Thread> worker_thread, | |
1220 std::unique_ptr<Thread> signaling_thread, | |
1221 WebRtcVideoEncoderFactory* encoder_factory, | |
1222 WebRtcVideoDecoderFactory* decoder_factory, | |
1223 rtc::NetworkMonitorFactory* network_monitor_factory, | |
1224 PeerConnectionFactoryInterface* factory) | |
1225 : network_thread_(std::move(network_thread)), | |
1226 worker_thread_(std::move(worker_thread)), | |
1227 signaling_thread_(std::move(signaling_thread)), | |
1228 encoder_factory_(encoder_factory), | |
1229 decoder_factory_(decoder_factory), | |
1230 network_monitor_factory_(network_monitor_factory), | |
1231 factory_(factory) {} | |
1232 | |
1233 ~OwnedFactoryAndThreads() { | |
1234 CHECK_RELEASE(factory_); | |
1235 if (network_monitor_factory_ != nullptr) { | |
1236 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); | |
1237 } | |
1238 } | |
1239 | |
1240 PeerConnectionFactoryInterface* factory() { return factory_; } | |
1241 Thread* signaling_thread() { return signaling_thread_.get(); } | |
1242 Thread* worker_thread() { return worker_thread_.get(); } | |
1243 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } | |
1244 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } | |
1245 rtc::NetworkMonitorFactory* network_monitor_factory() { | |
1246 return network_monitor_factory_; | |
1247 } | |
1248 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } | |
1249 void InvokeJavaCallbacksOnFactoryThreads(); | |
1250 | |
1251 private: | |
1252 void JavaCallbackOnFactoryThreads(); | |
1253 | |
1254 const std::unique_ptr<Thread> network_thread_; | |
1255 const std::unique_ptr<Thread> worker_thread_; | |
1256 const std::unique_ptr<Thread> signaling_thread_; | |
1257 WebRtcVideoEncoderFactory* encoder_factory_; | |
1258 WebRtcVideoDecoderFactory* decoder_factory_; | |
1259 rtc::NetworkMonitorFactory* network_monitor_factory_; | |
1260 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. | |
1261 }; | |
1262 | |
1263 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { | |
1264 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | |
1265 ScopedLocalRefFrame local_ref_frame(jni); | |
1266 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); | |
1267 jmethodID m = nullptr; | |
1268 if (network_thread_->IsCurrent()) { | |
1269 LOG(LS_INFO) << "Network thread JavaCallback"; | |
1270 m = GetStaticMethodID(jni, j_factory_class, "onNetworkThreadReady", "()V"); | |
1271 } | |
1272 if (worker_thread_->IsCurrent()) { | |
1273 LOG(LS_INFO) << "Worker thread JavaCallback"; | |
1274 m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V"); | |
1275 } | |
1276 if (signaling_thread_->IsCurrent()) { | |
1277 LOG(LS_INFO) << "Signaling thread JavaCallback"; | |
1278 m = GetStaticMethodID( | |
1279 jni, j_factory_class, "onSignalingThreadReady", "()V"); | |
1280 } | |
1281 if (m != nullptr) { | |
1282 jni->CallStaticVoidMethod(j_factory_class, m); | |
1283 CHECK_EXCEPTION(jni) << "error during JavaCallback::CallStaticVoidMethod"; | |
1284 } | |
1285 } | |
1286 | |
1287 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { | |
1288 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; | |
1289 network_thread_->Invoke<void>(RTC_FROM_HERE, | |
1290 [this] { JavaCallbackOnFactoryThreads(); }); | |
1291 worker_thread_->Invoke<void>(RTC_FROM_HERE, | |
1292 [this] { JavaCallbackOnFactoryThreads(); }); | |
1293 signaling_thread_->Invoke<void>(RTC_FROM_HERE, | |
1294 [this] { JavaCallbackOnFactoryThreads(); }); | |
1295 } | |
1296 | |
1297 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni, | 1104 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni, |
1298 jobject options) { | 1105 jobject options) { |
1299 jclass options_class = jni->GetObjectClass(options); | 1106 jclass options_class = jni->GetObjectClass(options); |
1300 jfieldID network_ignore_mask_field = | 1107 jfieldID network_ignore_mask_field = |
1301 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); | 1108 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); |
1302 int network_ignore_mask = | 1109 int network_ignore_mask = |
1303 jni->GetIntField(options, network_ignore_mask_field); | 1110 jni->GetIntField(options, network_ignore_mask_field); |
1304 | 1111 |
1305 jfieldID disable_encryption_field = | 1112 jfieldID disable_encryption_field = |
1306 jni->GetFieldID(options_class, "disableEncryption", "Z"); | 1113 jni->GetFieldID(options_class, "disableEncryption", "Z"); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 WebRtcVideoDecoderFactory* decoder_factory = nullptr; | 1156 WebRtcVideoDecoderFactory* decoder_factory = nullptr; |
1350 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; | 1157 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; |
1351 | 1158 |
1352 PeerConnectionFactoryInterface::Options options; | 1159 PeerConnectionFactoryInterface::Options options; |
1353 bool has_options = joptions != NULL; | 1160 bool has_options = joptions != NULL; |
1354 if (has_options) { | 1161 if (has_options) { |
1355 options = ParseOptionsFromJava(jni, joptions); | 1162 options = ParseOptionsFromJava(jni, joptions); |
1356 } | 1163 } |
1357 | 1164 |
1358 if (video_hw_acceleration_enabled) { | 1165 if (video_hw_acceleration_enabled) { |
1359 encoder_factory = new MediaCodecVideoEncoderFactory(); | 1166 encoder_factory = CreateVideoEncoderFactory(); |
1360 decoder_factory = new MediaCodecVideoDecoderFactory(); | 1167 decoder_factory = CreateVideoDecoderFactory(); |
1361 } | 1168 } |
1362 // Do not create network_monitor_factory only if the options are | 1169 // Do not create network_monitor_factory only if the options are |
1363 // provided and disable_network_monitor therein is set to true. | 1170 // provided and disable_network_monitor therein is set to true. |
1364 if (!(has_options && options.disable_network_monitor)) { | 1171 if (!(has_options && options.disable_network_monitor)) { |
1365 network_monitor_factory = new AndroidNetworkMonitorFactory(); | 1172 network_monitor_factory = new AndroidNetworkMonitorFactory(); |
1366 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); | 1173 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); |
1367 } | 1174 } |
1368 | 1175 |
1369 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1176 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1370 webrtc::CreatePeerConnectionFactory( | 1177 webrtc::CreatePeerConnectionFactory( |
(...skipping 17 matching lines...) Expand all Loading... |
1388 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { | 1195 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { |
1389 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1196 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1390 if (field_trials_init_string) { | 1197 if (field_trials_init_string) { |
1391 webrtc::field_trial::InitFieldTrialsFromString(NULL); | 1198 webrtc::field_trial::InitFieldTrialsFromString(NULL); |
1392 delete field_trials_init_string; | 1199 delete field_trials_init_string; |
1393 field_trials_init_string = NULL; | 1200 field_trials_init_string = NULL; |
1394 } | 1201 } |
1395 webrtc::Trace::ReturnTrace(); | 1202 webrtc::Trace::ReturnTrace(); |
1396 } | 1203 } |
1397 | 1204 |
1398 static PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { | |
1399 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); | |
1400 } | |
1401 | |
1402 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( | 1205 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( |
1403 JNIEnv*, jclass, jlong j_p) { | 1206 JNIEnv*, jclass, jlong j_p) { |
1404 OwnedFactoryAndThreads *factory = | 1207 OwnedFactoryAndThreads *factory = |
1405 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1208 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1406 factory->InvokeJavaCallbacksOnFactoryThreads(); | 1209 factory->InvokeJavaCallbacksOnFactoryThreads(); |
1407 } | 1210 } |
1408 | 1211 |
1409 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( | 1212 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( |
1410 JNIEnv* jni, jclass, jlong native_factory, jstring label) { | 1213 JNIEnv* jni, jclass, jlong native_factory, jstring label) { |
1411 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1214 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1412 factoryFromJava(native_factory)); | 1215 factoryFromJava(native_factory)); |
1413 rtc::scoped_refptr<MediaStreamInterface> stream( | 1216 rtc::scoped_refptr<MediaStreamInterface> stream( |
1414 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); | 1217 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); |
1415 return (jlong)stream.release(); | 1218 return (jlong)stream.release(); |
1416 } | 1219 } |
1417 | 1220 |
1418 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) | |
1419 (JNIEnv* jni, jclass, jlong native_factory, jobject j_egl_context, | |
1420 jboolean is_screencast) { | |
1421 OwnedFactoryAndThreads* factory = | |
1422 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | |
1423 | |
1424 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source( | |
1425 new rtc::RefCountedObject<webrtc::AndroidVideoTrackSource>( | |
1426 factory->signaling_thread(), jni, j_egl_context, is_screencast)); | |
1427 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = | |
1428 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), | |
1429 factory->worker_thread(), source); | |
1430 | |
1431 return (jlong)proxy_source.release(); | |
1432 } | |
1433 | |
1434 JOW(void, PeerConnectionFactory_nativeInitializeVideoCapturer) | 1221 JOW(void, PeerConnectionFactory_nativeInitializeVideoCapturer) |
1435 (JNIEnv* jni, | 1222 (JNIEnv* jni, |
1436 jclass, | 1223 jclass, |
1437 jlong native_factory, | 1224 jlong native_factory, |
1438 jobject j_video_capturer, | 1225 jobject j_video_capturer, |
1439 jlong native_source, | 1226 jlong native_source, |
1440 jobject j_frame_observer) { | 1227 jobject j_frame_observer) { |
1441 LOG(LS_INFO) << "PeerConnectionFactory_nativeInitializeVideoCapturer"; | 1228 LOG(LS_INFO) << "PeerConnectionFactory_nativeInitializeVideoCapturer"; |
1442 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1229 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1443 factoryFromJava(native_factory)); | 1230 factoryFromJava(native_factory)); |
| 1231 if (!native_source) { |
| 1232 return; |
| 1233 } |
1444 auto proxy_source = | 1234 auto proxy_source = |
1445 reinterpret_cast<webrtc::VideoTrackSourceProxy*>(native_source); | 1235 reinterpret_cast<webrtc::VideoTrackSourceProxy*>(native_source); |
1446 auto source = reinterpret_cast<webrtc::AndroidVideoTrackSource*>( | 1236 auto source = reinterpret_cast<webrtc::AndroidVideoTrackSource*>( |
1447 proxy_source->internal()); | 1237 proxy_source->internal()); |
1448 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper = | 1238 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper = |
1449 source->surface_texture_helper(); | 1239 source->surface_texture_helper(); |
1450 jni->CallVoidMethod( | 1240 jni->CallVoidMethod( |
1451 j_video_capturer, | 1241 j_video_capturer, |
1452 GetMethodID(jni, FindClass(jni, "org/webrtc/VideoCapturer"), "initialize", | 1242 GetMethodID(jni, FindClass(jni, "org/webrtc/VideoCapturer"), "initialize", |
1453 "(Lorg/webrtc/SurfaceTextureHelper;Landroid/content/" | 1243 "(Lorg/webrtc/SurfaceTextureHelper;Landroid/content/" |
1454 "Context;Lorg/webrtc/VideoCapturer$CapturerObserver;)V"), | 1244 "Context;Lorg/webrtc/VideoCapturer$CapturerObserver;)V"), |
1455 surface_texture_helper | 1245 GetJavaSurfaceTextureHelper(surface_texture_helper), |
1456 ? surface_texture_helper->GetJavaSurfaceTextureHelper() | |
1457 : nullptr, | |
1458 j_application_context, j_frame_observer); | 1246 j_application_context, j_frame_observer); |
1459 CHECK_EXCEPTION(jni) << "error during VideoCapturer.initialize()"; | 1247 CHECK_EXCEPTION(jni) << "error during VideoCapturer.initialize()"; |
1460 } | 1248 } |
1461 | 1249 |
1462 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)( | |
1463 JNIEnv* jni, jclass, jlong native_factory, jstring id, | |
1464 jlong native_source) { | |
1465 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | |
1466 factoryFromJava(native_factory)); | |
1467 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack( | |
1468 JavaToStdString(jni, id), | |
1469 reinterpret_cast<VideoTrackSourceInterface*>(native_source))); | |
1470 return (jlong)track.release(); | |
1471 } | |
1472 | |
1473 JOW(jlong, PeerConnectionFactory_nativeCreateAudioSource)( | 1250 JOW(jlong, PeerConnectionFactory_nativeCreateAudioSource)( |
1474 JNIEnv* jni, jclass, jlong native_factory, jobject j_constraints) { | 1251 JNIEnv* jni, jclass, jlong native_factory, jobject j_constraints) { |
1475 std::unique_ptr<ConstraintsWrapper> constraints( | 1252 std::unique_ptr<ConstraintsWrapper> constraints( |
1476 new ConstraintsWrapper(jni, j_constraints)); | 1253 new ConstraintsWrapper(jni, j_constraints)); |
1477 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1254 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1478 factoryFromJava(native_factory)); | 1255 factoryFromJava(native_factory)); |
1479 cricket::AudioOptions options; | 1256 cricket::AudioOptions options; |
1480 CopyConstraintsIntoAudioOptions(constraints.get(), &options); | 1257 CopyConstraintsIntoAudioOptions(constraints.get(), &options); |
1481 rtc::scoped_refptr<AudioSourceInterface> source( | 1258 rtc::scoped_refptr<AudioSourceInterface> source( |
1482 factory->CreateAudioSource(options)); | 1259 factory->CreateAudioSource(options)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 OwnedFactoryAndThreads* owner = | 1298 OwnedFactoryAndThreads* owner = |
1522 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | 1299 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
1523 if (owner->network_monitor_factory()) { | 1300 if (owner->network_monitor_factory()) { |
1524 rtc::NetworkMonitorFactory::ReleaseFactory( | 1301 rtc::NetworkMonitorFactory::ReleaseFactory( |
1525 owner->network_monitor_factory()); | 1302 owner->network_monitor_factory()); |
1526 owner->clear_network_monitor_factory(); | 1303 owner->clear_network_monitor_factory(); |
1527 } | 1304 } |
1528 } | 1305 } |
1529 } | 1306 } |
1530 | 1307 |
1531 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( | |
1532 JNIEnv* jni, jclass, jlong native_factory, jobject local_egl_context, | |
1533 jobject remote_egl_context) { | |
1534 OwnedFactoryAndThreads* owned_factory = | |
1535 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | |
1536 | |
1537 jclass j_eglbase14_context_class = | |
1538 FindClass(jni, "org/webrtc/EglBase14$Context"); | |
1539 | |
1540 MediaCodecVideoEncoderFactory* encoder_factory = | |
1541 static_cast<MediaCodecVideoEncoderFactory*> | |
1542 (owned_factory->encoder_factory()); | |
1543 if (encoder_factory && | |
1544 jni->IsInstanceOf(local_egl_context, j_eglbase14_context_class)) { | |
1545 LOG(LS_INFO) << "Set EGL context for HW encoding."; | |
1546 encoder_factory->SetEGLContext(jni, local_egl_context); | |
1547 } | |
1548 | |
1549 MediaCodecVideoDecoderFactory* decoder_factory = | |
1550 static_cast<MediaCodecVideoDecoderFactory*> | |
1551 (owned_factory->decoder_factory()); | |
1552 if (decoder_factory) { | |
1553 LOG(LS_INFO) << "Set EGL context for HW decoding."; | |
1554 decoder_factory->SetEGLContext(jni, remote_egl_context); | |
1555 } | |
1556 } | |
1557 | |
1558 static PeerConnectionInterface::IceTransportsType | 1308 static PeerConnectionInterface::IceTransportsType |
1559 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) { | 1309 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) { |
1560 std::string enum_name = GetJavaEnumName( | 1310 std::string enum_name = GetJavaEnumName( |
1561 jni, "org/webrtc/PeerConnection$IceTransportsType", | 1311 jni, "org/webrtc/PeerConnection$IceTransportsType", |
1562 j_ice_transports_type); | 1312 j_ice_transports_type); |
1563 | 1313 |
1564 if (enum_name == "ALL") | 1314 if (enum_name == "ALL") |
1565 return PeerConnectionInterface::kAll; | 1315 return PeerConnectionInterface::kAll; |
1566 | 1316 |
1567 if (enum_name == "RELAY") | 1317 if (enum_name == "RELAY") |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 ExtractNativePC(jni, j_pc)->Close(); | 1929 ExtractNativePC(jni, j_pc)->Close(); |
2180 return; | 1930 return; |
2181 } | 1931 } |
2182 | 1932 |
2183 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) { | 1933 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) { |
2184 rtc::scoped_refptr<MediaSourceInterface> p( | 1934 rtc::scoped_refptr<MediaSourceInterface> p( |
2185 reinterpret_cast<MediaSourceInterface*>(j_p)); | 1935 reinterpret_cast<MediaSourceInterface*>(j_p)); |
2186 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); | 1936 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); |
2187 } | 1937 } |
2188 | 1938 |
2189 JOW(jlong, VideoRenderer_nativeWrapVideoRenderer)( | |
2190 JNIEnv* jni, jclass, jobject j_callbacks) { | |
2191 std::unique_ptr<JavaVideoRendererWrapper> renderer( | |
2192 new JavaVideoRendererWrapper(jni, j_callbacks)); | |
2193 return (jlong)renderer.release(); | |
2194 } | |
2195 | |
2196 JOW(void, VideoRenderer_nativeCopyPlane)( | |
2197 JNIEnv *jni, jclass, jobject j_src_buffer, jint width, jint height, | |
2198 jint src_stride, jobject j_dst_buffer, jint dst_stride) { | |
2199 size_t src_size = jni->GetDirectBufferCapacity(j_src_buffer); | |
2200 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); | |
2201 RTC_CHECK(src_stride >= width) << "Wrong source stride " << src_stride; | |
2202 RTC_CHECK(dst_stride >= width) << "Wrong destination stride " << dst_stride; | |
2203 RTC_CHECK(src_size >= src_stride * height) | |
2204 << "Insufficient source buffer capacity " << src_size; | |
2205 RTC_CHECK(dst_size >= dst_stride * height) | |
2206 << "Insufficient destination buffer capacity " << dst_size; | |
2207 uint8_t *src = | |
2208 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer)); | |
2209 uint8_t *dst = | |
2210 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); | |
2211 if (src_stride == dst_stride) { | |
2212 memcpy(dst, src, src_stride * height); | |
2213 } else { | |
2214 for (int i = 0; i < height; i++) { | |
2215 memcpy(dst, src, width); | |
2216 src += src_stride; | |
2217 dst += dst_stride; | |
2218 } | |
2219 } | |
2220 } | |
2221 | |
2222 JOW(void, FileVideoCapturer_nativeI420ToNV21)( | 1939 JOW(void, FileVideoCapturer_nativeI420ToNV21)( |
2223 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, | 1940 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, |
2224 jbyteArray j_dst_buffer) { | 1941 jbyteArray j_dst_buffer) { |
2225 size_t src_size = jni->GetArrayLength(j_src_buffer); | 1942 size_t src_size = jni->GetArrayLength(j_src_buffer); |
2226 size_t dst_size = jni->GetArrayLength(j_dst_buffer); | 1943 size_t dst_size = jni->GetArrayLength(j_dst_buffer); |
2227 int src_stride = width; | 1944 int src_stride = width; |
2228 int dst_stride = width; | 1945 int dst_stride = width; |
2229 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); | 1946 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); |
2230 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); | 1947 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); |
2231 | 1948 |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2743 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) | 2460 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) |
2744 ->inter_tone_gap(); | 2461 ->inter_tone_gap(); |
2745 } | 2462 } |
2746 | 2463 |
2747 JOW(void, DtmfSender_free) | 2464 JOW(void, DtmfSender_free) |
2748 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { | 2465 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { |
2749 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); | 2466 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); |
2750 } | 2467 } |
2751 | 2468 |
2752 } // namespace webrtc_jni | 2469 } // namespace webrtc_jni |
OLD | NEW |