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); | |
Taylor Brandstetter
2017/06/16 22:19:09
It's odd to have these declarations in the .cc fil
Zhi Huang
2017/06/17 01:46:43
Done.
| |
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 | 131 |
130 // Return the (singleton) Java Enum object corresponding to |index|; | 132 // Return the (singleton) Java Enum object corresponding to |index|; |
131 // |state_class_fragment| is something like "MediaSource$State". | 133 // |state_class_fragment| is something like "MediaSource$State". |
132 static jobject JavaEnumFromIndex( | 134 static jobject JavaEnumFromIndex( |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 } | 841 } |
840 | 842 |
841 const ScopedGlobalRef<jobject> j_observer_global_; | 843 const ScopedGlobalRef<jobject> j_observer_global_; |
842 const ScopedGlobalRef<jclass> j_observer_class_; | 844 const ScopedGlobalRef<jclass> j_observer_class_; |
843 const ScopedGlobalRef<jclass> j_stats_report_class_; | 845 const ScopedGlobalRef<jclass> j_stats_report_class_; |
844 const jmethodID j_stats_report_ctor_; | 846 const jmethodID j_stats_report_ctor_; |
845 const ScopedGlobalRef<jclass> j_value_class_; | 847 const ScopedGlobalRef<jclass> j_value_class_; |
846 const jmethodID j_value_ctor_; | 848 const jmethodID j_value_ctor_; |
847 }; | 849 }; |
848 | 850 |
849 // Wrapper dispatching rtc::VideoSinkInterface to a Java VideoRenderer | |
850 // instance. | |
851 class JavaVideoRendererWrapper | |
852 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { | |
853 public: | |
854 JavaVideoRendererWrapper(JNIEnv* jni, jobject j_callbacks) | |
855 : j_callbacks_(jni, j_callbacks), | |
856 j_render_frame_id_(GetMethodID( | |
857 jni, GetObjectClass(jni, j_callbacks), "renderFrame", | |
858 "(Lorg/webrtc/VideoRenderer$I420Frame;)V")), | |
859 j_frame_class_(jni, | |
860 FindClass(jni, "org/webrtc/VideoRenderer$I420Frame")), | |
861 j_i420_frame_ctor_id_(GetMethodID( | |
862 jni, *j_frame_class_, "<init>", "(III[I[Ljava/nio/ByteBuffer;J)V")), | |
863 j_texture_frame_ctor_id_(GetMethodID( | |
864 jni, *j_frame_class_, "<init>", | |
865 "(IIII[FJ)V")), | |
866 j_byte_buffer_class_(jni, FindClass(jni, "java/nio/ByteBuffer")) { | |
867 CHECK_EXCEPTION(jni); | |
868 } | |
869 | |
870 virtual ~JavaVideoRendererWrapper() {} | |
871 | |
872 void OnFrame(const webrtc::VideoFrame& video_frame) override { | |
873 ScopedLocalRefFrame local_ref_frame(jni()); | |
874 | |
875 jobject j_frame; | |
876 if (video_frame.video_frame_buffer()->type() == | |
877 webrtc::VideoFrameBuffer::Type::kNative) { | |
878 AndroidVideoFrameBuffer* android_buffer = | |
879 static_cast<AndroidVideoFrameBuffer*>( | |
880 video_frame.video_frame_buffer().get()); | |
881 switch (android_buffer->android_type()) { | |
882 case AndroidVideoFrameBuffer::AndroidType::kTextureBuffer: | |
883 j_frame = ToJavaTextureFrame(&video_frame); | |
884 break; | |
885 case AndroidVideoFrameBuffer::AndroidType::kJavaBuffer: | |
886 j_frame = static_cast<AndroidVideoBuffer*>(android_buffer) | |
887 ->ToJavaI420Frame(jni(), video_frame.width(), | |
888 video_frame.height(), | |
889 video_frame.rotation()); | |
890 break; | |
891 default: | |
892 RTC_NOTREACHED(); | |
893 } | |
894 } else { | |
895 j_frame = ToJavaI420Frame(&video_frame); | |
896 } | |
897 // |j_callbacks_| is responsible for releasing |j_frame| with | |
898 // VideoRenderer.renderFrameDone(). | |
899 jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame); | |
900 CHECK_EXCEPTION(jni()); | |
901 } | |
902 | |
903 private: | |
904 // Make a shallow copy of |frame| to be used with Java. The callee has | |
905 // ownership of the frame, and the frame should be released with | |
906 // VideoRenderer.releaseNativeFrame(). | |
907 static jlong javaShallowCopy(const webrtc::VideoFrame* frame) { | |
908 return jlongFromPointer(new webrtc::VideoFrame(*frame)); | |
909 } | |
910 | |
911 // Return a VideoRenderer.I420Frame referring to the data in |frame|. | |
912 jobject ToJavaI420Frame(const webrtc::VideoFrame* frame) { | |
913 jintArray strides = jni()->NewIntArray(3); | |
914 jint* strides_array = jni()->GetIntArrayElements(strides, NULL); | |
915 rtc::scoped_refptr<webrtc::I420BufferInterface> i420_buffer = | |
916 frame->video_frame_buffer()->ToI420(); | |
917 strides_array[0] = i420_buffer->StrideY(); | |
918 strides_array[1] = i420_buffer->StrideU(); | |
919 strides_array[2] = i420_buffer->StrideV(); | |
920 jni()->ReleaseIntArrayElements(strides, strides_array, 0); | |
921 jobjectArray planes = jni()->NewObjectArray(3, *j_byte_buffer_class_, NULL); | |
922 jobject y_buffer = jni()->NewDirectByteBuffer( | |
923 const_cast<uint8_t*>(i420_buffer->DataY()), | |
924 i420_buffer->StrideY() * i420_buffer->height()); | |
925 size_t chroma_height = i420_buffer->ChromaHeight(); | |
926 jobject u_buffer = | |
927 jni()->NewDirectByteBuffer(const_cast<uint8_t*>(i420_buffer->DataU()), | |
928 i420_buffer->StrideU() * chroma_height); | |
929 jobject v_buffer = | |
930 jni()->NewDirectByteBuffer(const_cast<uint8_t*>(i420_buffer->DataV()), | |
931 i420_buffer->StrideV() * chroma_height); | |
932 | |
933 jni()->SetObjectArrayElement(planes, 0, y_buffer); | |
934 jni()->SetObjectArrayElement(planes, 1, u_buffer); | |
935 jni()->SetObjectArrayElement(planes, 2, v_buffer); | |
936 return jni()->NewObject( | |
937 *j_frame_class_, j_i420_frame_ctor_id_, | |
938 frame->width(), frame->height(), | |
939 static_cast<int>(frame->rotation()), | |
940 strides, planes, javaShallowCopy(frame)); | |
941 } | |
942 | |
943 // Return a VideoRenderer.I420Frame referring texture object in |frame|. | |
944 jobject ToJavaTextureFrame(const webrtc::VideoFrame* frame) { | |
945 NativeHandleImpl handle = | |
946 static_cast<AndroidTextureBuffer*>(frame->video_frame_buffer().get()) | |
947 ->native_handle_impl(); | |
948 jfloatArray sampling_matrix = handle.sampling_matrix.ToJava(jni()); | |
949 | |
950 return jni()->NewObject( | |
951 *j_frame_class_, j_texture_frame_ctor_id_, frame->width(), | |
952 frame->height(), static_cast<int>(frame->rotation()), | |
953 handle.oes_texture_id, sampling_matrix, javaShallowCopy(frame)); | |
954 } | |
955 | |
956 JNIEnv* jni() { | |
957 return AttachCurrentThreadIfNeeded(); | |
958 } | |
959 | |
960 ScopedGlobalRef<jobject> j_callbacks_; | |
961 jmethodID j_render_frame_id_; | |
962 ScopedGlobalRef<jclass> j_frame_class_; | |
963 jmethodID j_i420_frame_ctor_id_; | |
964 jmethodID j_texture_frame_ctor_id_; | |
965 ScopedGlobalRef<jclass> j_byte_buffer_class_; | |
966 }; | |
967 | |
968 // Adapter between the C++ RtpReceiverObserverInterface and the Java | 851 // Adapter between the C++ RtpReceiverObserverInterface and the Java |
969 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and | 852 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and |
970 // dispatches C++ callbacks to Java. | 853 // dispatches C++ callbacks to Java. |
971 class RtpReceiverObserver : public RtpReceiverObserverInterface { | 854 class RtpReceiverObserver : public RtpReceiverObserverInterface { |
972 public: | 855 public: |
973 RtpReceiverObserver(JNIEnv* jni, jobject j_observer) | 856 RtpReceiverObserver(JNIEnv* jni, jobject j_observer) |
974 : j_observer_global_(jni, j_observer) {} | 857 : j_observer_global_(jni, j_observer) {} |
975 | 858 |
976 ~RtpReceiverObserver() override {} | 859 ~RtpReceiverObserver() override {} |
977 | 860 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1100 | 983 |
1101 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { | 984 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { |
1102 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); | 985 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); |
1103 delete p; | 986 delete p; |
1104 } | 987 } |
1105 | 988 |
1106 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { | 989 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { |
1107 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); | 990 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); |
1108 } | 991 } |
1109 | 992 |
1110 JOW(void, VideoRenderer_freeWrappedVideoRenderer)(JNIEnv*, jclass, jlong j_p) { | |
1111 delete reinterpret_cast<JavaVideoRendererWrapper*>(j_p); | |
1112 } | |
1113 | |
1114 JOW(void, VideoRenderer_releaseNativeFrame)( | |
1115 JNIEnv* jni, jclass, jlong j_frame_ptr) { | |
1116 delete reinterpret_cast<const webrtc::VideoFrame*>(j_frame_ptr); | |
1117 } | |
1118 | |
1119 JOW(void, MediaStreamTrack_free)(JNIEnv*, jclass, jlong j_p) { | 993 JOW(void, MediaStreamTrack_free)(JNIEnv*, jclass, jlong j_p) { |
1120 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release(); | 994 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release(); |
1121 } | 995 } |
1122 | 996 |
1123 JOW(jboolean, MediaStream_nativeAddAudioTrack)( | 997 JOW(jboolean, MediaStream_nativeAddAudioTrack)( |
1124 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) { | 998 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) { |
1125 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack( | 999 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack( |
1126 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer)); | 1000 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer)); |
1127 } | 1001 } |
1128 | 1002 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1217 rtc::tracing::ShutdownInternalTracer(); | 1091 rtc::tracing::ShutdownInternalTracer(); |
1218 } | 1092 } |
1219 | 1093 |
1220 JOW(void, AudioTrack_nativeSetVolume) | 1094 JOW(void, AudioTrack_nativeSetVolume) |
1221 (JNIEnv*, jclass, jlong j_p, jdouble volume) { | 1095 (JNIEnv*, jclass, jlong j_p, jdouble volume) { |
1222 rtc::scoped_refptr<AudioSourceInterface> source( | 1096 rtc::scoped_refptr<AudioSourceInterface> source( |
1223 reinterpret_cast<AudioTrackInterface*>(j_p)->GetSource()); | 1097 reinterpret_cast<AudioTrackInterface*>(j_p)->GetSource()); |
1224 source->SetVolume(volume); | 1098 source->SetVolume(volume); |
1225 } | 1099 } |
1226 | 1100 |
1227 // Helper struct for working around the fact that CreatePeerConnectionFactory() | |
1228 // comes in two flavors: either entirely automagical (constructing its own | |
1229 // threads and deleting them on teardown, but no external codec factory support) | |
1230 // or entirely manual (requires caller to delete threads after factory | |
1231 // teardown). This struct takes ownership of its ctor's arguments to present a | |
1232 // single thing for Java to hold and eventually free. | |
1233 class OwnedFactoryAndThreads { | |
1234 public: | |
1235 OwnedFactoryAndThreads(std::unique_ptr<Thread> network_thread, | |
1236 std::unique_ptr<Thread> worker_thread, | |
1237 std::unique_ptr<Thread> signaling_thread, | |
1238 WebRtcVideoEncoderFactory* encoder_factory, | |
1239 WebRtcVideoDecoderFactory* decoder_factory, | |
1240 rtc::NetworkMonitorFactory* network_monitor_factory, | |
1241 PeerConnectionFactoryInterface* factory) | |
1242 : network_thread_(std::move(network_thread)), | |
1243 worker_thread_(std::move(worker_thread)), | |
1244 signaling_thread_(std::move(signaling_thread)), | |
1245 encoder_factory_(encoder_factory), | |
1246 decoder_factory_(decoder_factory), | |
1247 network_monitor_factory_(network_monitor_factory), | |
1248 factory_(factory) {} | |
1249 | |
1250 ~OwnedFactoryAndThreads() { | |
1251 CHECK_RELEASE(factory_); | |
1252 if (network_monitor_factory_ != nullptr) { | |
1253 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); | |
1254 } | |
1255 } | |
1256 | |
1257 PeerConnectionFactoryInterface* factory() { return factory_; } | |
1258 Thread* signaling_thread() { return signaling_thread_.get(); } | |
1259 Thread* worker_thread() { return worker_thread_.get(); } | |
1260 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } | |
1261 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } | |
1262 rtc::NetworkMonitorFactory* network_monitor_factory() { | |
1263 return network_monitor_factory_; | |
1264 } | |
1265 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } | |
1266 void InvokeJavaCallbacksOnFactoryThreads(); | |
1267 | |
1268 private: | |
1269 void JavaCallbackOnFactoryThreads(); | |
1270 | |
1271 const std::unique_ptr<Thread> network_thread_; | |
1272 const std::unique_ptr<Thread> worker_thread_; | |
1273 const std::unique_ptr<Thread> signaling_thread_; | |
1274 WebRtcVideoEncoderFactory* encoder_factory_; | |
1275 WebRtcVideoDecoderFactory* decoder_factory_; | |
1276 rtc::NetworkMonitorFactory* network_monitor_factory_; | |
1277 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. | |
1278 }; | |
1279 | |
1280 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { | |
1281 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | |
1282 ScopedLocalRefFrame local_ref_frame(jni); | |
1283 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); | |
1284 jmethodID m = nullptr; | |
1285 if (network_thread_->IsCurrent()) { | |
1286 LOG(LS_INFO) << "Network thread JavaCallback"; | |
1287 m = GetStaticMethodID(jni, j_factory_class, "onNetworkThreadReady", "()V"); | |
1288 } | |
1289 if (worker_thread_->IsCurrent()) { | |
1290 LOG(LS_INFO) << "Worker thread JavaCallback"; | |
1291 m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V"); | |
1292 } | |
1293 if (signaling_thread_->IsCurrent()) { | |
1294 LOG(LS_INFO) << "Signaling thread JavaCallback"; | |
1295 m = GetStaticMethodID( | |
1296 jni, j_factory_class, "onSignalingThreadReady", "()V"); | |
1297 } | |
1298 if (m != nullptr) { | |
1299 jni->CallStaticVoidMethod(j_factory_class, m); | |
1300 CHECK_EXCEPTION(jni) << "error during JavaCallback::CallStaticVoidMethod"; | |
1301 } | |
1302 } | |
1303 | |
1304 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { | |
1305 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; | |
1306 network_thread_->Invoke<void>(RTC_FROM_HERE, | |
1307 [this] { JavaCallbackOnFactoryThreads(); }); | |
1308 worker_thread_->Invoke<void>(RTC_FROM_HERE, | |
1309 [this] { JavaCallbackOnFactoryThreads(); }); | |
1310 signaling_thread_->Invoke<void>(RTC_FROM_HERE, | |
1311 [this] { JavaCallbackOnFactoryThreads(); }); | |
1312 } | |
1313 | |
1314 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni, | 1101 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni, |
1315 jobject options) { | 1102 jobject options) { |
1316 jclass options_class = jni->GetObjectClass(options); | 1103 jclass options_class = jni->GetObjectClass(options); |
1317 jfieldID network_ignore_mask_field = | 1104 jfieldID network_ignore_mask_field = |
1318 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); | 1105 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); |
1319 int network_ignore_mask = | 1106 int network_ignore_mask = |
1320 jni->GetIntField(options, network_ignore_mask_field); | 1107 jni->GetIntField(options, network_ignore_mask_field); |
1321 | 1108 |
1322 jfieldID disable_encryption_field = | 1109 jfieldID disable_encryption_field = |
1323 jni->GetFieldID(options_class, "disableEncryption", "Z"); | 1110 jni->GetFieldID(options_class, "disableEncryption", "Z"); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1366 WebRtcVideoDecoderFactory* decoder_factory = nullptr; | 1153 WebRtcVideoDecoderFactory* decoder_factory = nullptr; |
1367 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; | 1154 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; |
1368 | 1155 |
1369 PeerConnectionFactoryInterface::Options options; | 1156 PeerConnectionFactoryInterface::Options options; |
1370 bool has_options = joptions != NULL; | 1157 bool has_options = joptions != NULL; |
1371 if (has_options) { | 1158 if (has_options) { |
1372 options = ParseOptionsFromJava(jni, joptions); | 1159 options = ParseOptionsFromJava(jni, joptions); |
1373 } | 1160 } |
1374 | 1161 |
1375 if (video_hw_acceleration_enabled) { | 1162 if (video_hw_acceleration_enabled) { |
1376 encoder_factory = new MediaCodecVideoEncoderFactory(); | 1163 encoder_factory = CreateVideoEncoderFactory(); |
1377 decoder_factory = new MediaCodecVideoDecoderFactory(); | 1164 decoder_factory = CreateVideoDecoderFactory(); |
1378 } | 1165 } |
1379 // Do not create network_monitor_factory only if the options are | 1166 // Do not create network_monitor_factory only if the options are |
1380 // provided and disable_network_monitor therein is set to true. | 1167 // provided and disable_network_monitor therein is set to true. |
1381 if (!(has_options && options.disable_network_monitor)) { | 1168 if (!(has_options && options.disable_network_monitor)) { |
1382 network_monitor_factory = new AndroidNetworkMonitorFactory(); | 1169 network_monitor_factory = new AndroidNetworkMonitorFactory(); |
1383 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); | 1170 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); |
1384 } | 1171 } |
1385 | 1172 |
1386 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1173 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1387 webrtc::CreatePeerConnectionFactory( | 1174 webrtc::CreatePeerConnectionFactory( |
(...skipping 17 matching lines...) Expand all Loading... | |
1405 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { | 1192 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { |
1406 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1193 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1407 if (field_trials_init_string) { | 1194 if (field_trials_init_string) { |
1408 webrtc::field_trial::InitFieldTrialsFromString(NULL); | 1195 webrtc::field_trial::InitFieldTrialsFromString(NULL); |
1409 delete field_trials_init_string; | 1196 delete field_trials_init_string; |
1410 field_trials_init_string = NULL; | 1197 field_trials_init_string = NULL; |
1411 } | 1198 } |
1412 webrtc::Trace::ReturnTrace(); | 1199 webrtc::Trace::ReturnTrace(); |
1413 } | 1200 } |
1414 | 1201 |
1415 static PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { | |
1416 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); | |
1417 } | |
1418 | |
1419 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( | 1202 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( |
1420 JNIEnv*, jclass, jlong j_p) { | 1203 JNIEnv*, jclass, jlong j_p) { |
1421 OwnedFactoryAndThreads *factory = | 1204 OwnedFactoryAndThreads *factory = |
1422 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1205 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1423 factory->InvokeJavaCallbacksOnFactoryThreads(); | 1206 factory->InvokeJavaCallbacksOnFactoryThreads(); |
1424 } | 1207 } |
1425 | 1208 |
1426 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( | 1209 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( |
1427 JNIEnv* jni, jclass, jlong native_factory, jstring label) { | 1210 JNIEnv* jni, jclass, jlong native_factory, jstring label) { |
1428 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1211 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1429 factoryFromJava(native_factory)); | 1212 factoryFromJava(native_factory)); |
1430 rtc::scoped_refptr<MediaStreamInterface> stream( | 1213 rtc::scoped_refptr<MediaStreamInterface> stream( |
1431 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); | 1214 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); |
1432 return (jlong)stream.release(); | 1215 return (jlong)stream.release(); |
1433 } | 1216 } |
1434 | 1217 |
1435 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) | |
1436 (JNIEnv* jni, | |
1437 jclass, | |
1438 jlong native_factory, | |
1439 jobject j_surface_texture_helper, | |
1440 jboolean is_screencast) { | |
1441 OwnedFactoryAndThreads* factory = | |
1442 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | |
1443 | |
1444 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source( | |
1445 new rtc::RefCountedObject<webrtc::AndroidVideoTrackSource>( | |
1446 factory->signaling_thread(), jni, j_surface_texture_helper, | |
1447 is_screencast)); | |
1448 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = | |
1449 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), | |
1450 factory->worker_thread(), source); | |
1451 | |
1452 return (jlong)proxy_source.release(); | |
1453 } | |
1454 | |
1455 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)( | |
1456 JNIEnv* jni, jclass, jlong native_factory, jstring id, | |
1457 jlong native_source) { | |
1458 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | |
1459 factoryFromJava(native_factory)); | |
1460 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack( | |
1461 JavaToStdString(jni, id), | |
1462 reinterpret_cast<VideoTrackSourceInterface*>(native_source))); | |
1463 return (jlong)track.release(); | |
1464 } | |
1465 | |
1466 JOW(jlong, PeerConnectionFactory_nativeCreateAudioSource)( | 1218 JOW(jlong, PeerConnectionFactory_nativeCreateAudioSource)( |
1467 JNIEnv* jni, jclass, jlong native_factory, jobject j_constraints) { | 1219 JNIEnv* jni, jclass, jlong native_factory, jobject j_constraints) { |
1468 std::unique_ptr<ConstraintsWrapper> constraints( | 1220 std::unique_ptr<ConstraintsWrapper> constraints( |
1469 new ConstraintsWrapper(jni, j_constraints)); | 1221 new ConstraintsWrapper(jni, j_constraints)); |
1470 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1222 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1471 factoryFromJava(native_factory)); | 1223 factoryFromJava(native_factory)); |
1472 cricket::AudioOptions options; | 1224 cricket::AudioOptions options; |
1473 CopyConstraintsIntoAudioOptions(constraints.get(), &options); | 1225 CopyConstraintsIntoAudioOptions(constraints.get(), &options); |
1474 rtc::scoped_refptr<AudioSourceInterface> source( | 1226 rtc::scoped_refptr<AudioSourceInterface> source( |
1475 factory->CreateAudioSource(options)); | 1227 factory->CreateAudioSource(options)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1514 OwnedFactoryAndThreads* owner = | 1266 OwnedFactoryAndThreads* owner = |
1515 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | 1267 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
1516 if (owner->network_monitor_factory()) { | 1268 if (owner->network_monitor_factory()) { |
1517 rtc::NetworkMonitorFactory::ReleaseFactory( | 1269 rtc::NetworkMonitorFactory::ReleaseFactory( |
1518 owner->network_monitor_factory()); | 1270 owner->network_monitor_factory()); |
1519 owner->clear_network_monitor_factory(); | 1271 owner->clear_network_monitor_factory(); |
1520 } | 1272 } |
1521 } | 1273 } |
1522 } | 1274 } |
1523 | 1275 |
1524 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( | |
1525 JNIEnv* jni, jclass, jlong native_factory, jobject local_egl_context, | |
1526 jobject remote_egl_context) { | |
1527 OwnedFactoryAndThreads* owned_factory = | |
1528 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | |
1529 | |
1530 jclass j_eglbase14_context_class = | |
1531 FindClass(jni, "org/webrtc/EglBase14$Context"); | |
1532 | |
1533 MediaCodecVideoEncoderFactory* encoder_factory = | |
1534 static_cast<MediaCodecVideoEncoderFactory*> | |
1535 (owned_factory->encoder_factory()); | |
1536 if (encoder_factory && | |
1537 jni->IsInstanceOf(local_egl_context, j_eglbase14_context_class)) { | |
1538 LOG(LS_INFO) << "Set EGL context for HW encoding."; | |
1539 encoder_factory->SetEGLContext(jni, local_egl_context); | |
1540 } | |
1541 | |
1542 MediaCodecVideoDecoderFactory* decoder_factory = | |
1543 static_cast<MediaCodecVideoDecoderFactory*> | |
1544 (owned_factory->decoder_factory()); | |
1545 if (decoder_factory) { | |
1546 LOG(LS_INFO) << "Set EGL context for HW decoding."; | |
1547 decoder_factory->SetEGLContext(jni, remote_egl_context); | |
1548 } | |
1549 } | |
1550 | |
1551 static PeerConnectionInterface::IceTransportsType | 1276 static PeerConnectionInterface::IceTransportsType |
1552 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) { | 1277 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) { |
1553 std::string enum_name = GetJavaEnumName( | 1278 std::string enum_name = GetJavaEnumName( |
1554 jni, "org/webrtc/PeerConnection$IceTransportsType", | 1279 jni, "org/webrtc/PeerConnection$IceTransportsType", |
1555 j_ice_transports_type); | 1280 j_ice_transports_type); |
1556 | 1281 |
1557 if (enum_name == "ALL") | 1282 if (enum_name == "ALL") |
1558 return PeerConnectionInterface::kAll; | 1283 return PeerConnectionInterface::kAll; |
1559 | 1284 |
1560 if (enum_name == "RELAY") | 1285 if (enum_name == "RELAY") |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2172 ExtractNativePC(jni, j_pc)->Close(); | 1897 ExtractNativePC(jni, j_pc)->Close(); |
2173 return; | 1898 return; |
2174 } | 1899 } |
2175 | 1900 |
2176 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) { | 1901 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) { |
2177 rtc::scoped_refptr<MediaSourceInterface> p( | 1902 rtc::scoped_refptr<MediaSourceInterface> p( |
2178 reinterpret_cast<MediaSourceInterface*>(j_p)); | 1903 reinterpret_cast<MediaSourceInterface*>(j_p)); |
2179 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); | 1904 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); |
2180 } | 1905 } |
2181 | 1906 |
2182 JOW(jlong, VideoRenderer_nativeWrapVideoRenderer)( | |
2183 JNIEnv* jni, jclass, jobject j_callbacks) { | |
2184 std::unique_ptr<JavaVideoRendererWrapper> renderer( | |
2185 new JavaVideoRendererWrapper(jni, j_callbacks)); | |
2186 return (jlong)renderer.release(); | |
2187 } | |
2188 | |
2189 JOW(void, VideoRenderer_nativeCopyPlane)( | |
2190 JNIEnv *jni, jclass, jobject j_src_buffer, jint width, jint height, | |
2191 jint src_stride, jobject j_dst_buffer, jint dst_stride) { | |
2192 size_t src_size = jni->GetDirectBufferCapacity(j_src_buffer); | |
2193 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); | |
2194 RTC_CHECK(src_stride >= width) << "Wrong source stride " << src_stride; | |
2195 RTC_CHECK(dst_stride >= width) << "Wrong destination stride " << dst_stride; | |
2196 RTC_CHECK(src_size >= src_stride * height) | |
2197 << "Insufficient source buffer capacity " << src_size; | |
2198 RTC_CHECK(dst_size >= dst_stride * height) | |
2199 << "Insufficient destination buffer capacity " << dst_size; | |
2200 uint8_t *src = | |
2201 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer)); | |
2202 uint8_t *dst = | |
2203 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); | |
2204 if (src_stride == dst_stride) { | |
2205 memcpy(dst, src, src_stride * height); | |
2206 } else { | |
2207 for (int i = 0; i < height; i++) { | |
2208 memcpy(dst, src, width); | |
2209 src += src_stride; | |
2210 dst += dst_stride; | |
2211 } | |
2212 } | |
2213 } | |
2214 | |
2215 JOW(void, FileVideoCapturer_nativeI420ToNV21)( | 1907 JOW(void, FileVideoCapturer_nativeI420ToNV21)( |
2216 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, | 1908 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, |
2217 jbyteArray j_dst_buffer) { | 1909 jbyteArray j_dst_buffer) { |
2218 size_t src_size = jni->GetArrayLength(j_src_buffer); | 1910 size_t src_size = jni->GetArrayLength(j_src_buffer); |
2219 size_t dst_size = jni->GetArrayLength(j_dst_buffer); | 1911 size_t dst_size = jni->GetArrayLength(j_dst_buffer); |
2220 int src_stride = width; | 1912 int src_stride = width; |
2221 int dst_stride = width; | 1913 int dst_stride = width; |
2222 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); | 1914 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); |
2223 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); | 1915 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); |
2224 | 1916 |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2736 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) | 2428 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) |
2737 ->inter_tone_gap(); | 2429 ->inter_tone_gap(); |
2738 } | 2430 } |
2739 | 2431 |
2740 JOW(void, DtmfSender_free) | 2432 JOW(void, DtmfSender_free) |
2741 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { | 2433 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { |
2742 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); | 2434 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); |
2743 } | 2435 } |
2744 | 2436 |
2745 } // namespace webrtc_jni | 2437 } // namespace webrtc_jni |
OLD | NEW |