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 | 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 jobject j_frame = | |
875 (video_frame.video_frame_buffer()->native_handle() != nullptr) | |
876 ? CricketToJavaTextureFrame(&video_frame) | |
877 : CricketToJavaI420Frame(&video_frame); | |
878 // |j_callbacks_| is responsible for releasing |j_frame| with | |
879 // VideoRenderer.renderFrameDone(). | |
880 jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame); | |
881 CHECK_EXCEPTION(jni()); | |
882 } | |
883 | |
884 private: | |
885 // Make a shallow copy of |frame| to be used with Java. The callee has | |
886 // ownership of the frame, and the frame should be released with | |
887 // VideoRenderer.releaseNativeFrame(). | |
888 static jlong javaShallowCopy(const webrtc::VideoFrame* frame) { | |
889 return jlongFromPointer(new webrtc::VideoFrame(*frame)); | |
890 } | |
891 | |
892 // Return a VideoRenderer.I420Frame referring to the data in |frame|. | |
893 jobject CricketToJavaI420Frame(const webrtc::VideoFrame* frame) { | |
894 jintArray strides = jni()->NewIntArray(3); | |
895 jint* strides_array = jni()->GetIntArrayElements(strides, NULL); | |
896 strides_array[0] = frame->video_frame_buffer()->StrideY(); | |
897 strides_array[1] = frame->video_frame_buffer()->StrideU(); | |
898 strides_array[2] = frame->video_frame_buffer()->StrideV(); | |
899 jni()->ReleaseIntArrayElements(strides, strides_array, 0); | |
900 jobjectArray planes = jni()->NewObjectArray(3, *j_byte_buffer_class_, NULL); | |
901 jobject y_buffer = jni()->NewDirectByteBuffer( | |
902 const_cast<uint8_t*>(frame->video_frame_buffer()->DataY()), | |
903 frame->video_frame_buffer()->StrideY() * | |
904 frame->video_frame_buffer()->height()); | |
905 size_t chroma_height = (frame->height() + 1) / 2; | |
906 jobject u_buffer = jni()->NewDirectByteBuffer( | |
907 const_cast<uint8_t*>(frame->video_frame_buffer()->DataU()), | |
908 frame->video_frame_buffer()->StrideU() * chroma_height); | |
909 jobject v_buffer = jni()->NewDirectByteBuffer( | |
910 const_cast<uint8_t*>(frame->video_frame_buffer()->DataV()), | |
911 frame->video_frame_buffer()->StrideV() * chroma_height); | |
912 | |
913 jni()->SetObjectArrayElement(planes, 0, y_buffer); | |
914 jni()->SetObjectArrayElement(planes, 1, u_buffer); | |
915 jni()->SetObjectArrayElement(planes, 2, v_buffer); | |
916 return jni()->NewObject( | |
917 *j_frame_class_, j_i420_frame_ctor_id_, | |
918 frame->width(), frame->height(), | |
919 static_cast<int>(frame->rotation()), | |
920 strides, planes, javaShallowCopy(frame)); | |
921 } | |
922 | |
923 // Return a VideoRenderer.I420Frame referring texture object in |frame|. | |
924 jobject CricketToJavaTextureFrame(const webrtc::VideoFrame* frame) { | |
925 NativeHandleImpl* handle = reinterpret_cast<NativeHandleImpl*>( | |
926 frame->video_frame_buffer()->native_handle()); | |
927 jfloatArray sampling_matrix = handle->sampling_matrix.ToJava(jni()); | |
928 | |
929 return jni()->NewObject( | |
930 *j_frame_class_, j_texture_frame_ctor_id_, | |
931 frame->width(), frame->height(), | |
932 static_cast<int>(frame->rotation()), | |
933 handle->oes_texture_id, sampling_matrix, javaShallowCopy(frame)); | |
934 } | |
935 | |
936 JNIEnv* jni() { | |
937 return AttachCurrentThreadIfNeeded(); | |
938 } | |
939 | |
940 ScopedGlobalRef<jobject> j_callbacks_; | |
941 jmethodID j_render_frame_id_; | |
942 ScopedGlobalRef<jclass> j_frame_class_; | |
943 jmethodID j_i420_frame_ctor_id_; | |
944 jmethodID j_texture_frame_ctor_id_; | |
945 ScopedGlobalRef<jclass> j_byte_buffer_class_; | |
946 }; | |
947 | |
948 // Adapter between the C++ RtpReceiverObserverInterface and the Java | 851 // Adapter between the C++ RtpReceiverObserverInterface and the Java |
949 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and | 852 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and |
950 // dispatches C++ callbacks to Java. | 853 // dispatches C++ callbacks to Java. |
951 class RtpReceiverObserver : public RtpReceiverObserverInterface { | 854 class RtpReceiverObserver : public RtpReceiverObserverInterface { |
952 public: | 855 public: |
953 RtpReceiverObserver(JNIEnv* jni, jobject j_observer) | 856 RtpReceiverObserver(JNIEnv* jni, jobject j_observer) |
954 : j_observer_global_(jni, j_observer) {} | 857 : j_observer_global_(jni, j_observer) {} |
955 | 858 |
956 ~RtpReceiverObserver() override {} | 859 ~RtpReceiverObserver() override {} |
957 | 860 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 | 983 |
1081 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { | 984 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { |
1082 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); | 985 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); |
1083 delete p; | 986 delete p; |
1084 } | 987 } |
1085 | 988 |
1086 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { | 989 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { |
1087 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); | 990 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); |
1088 } | 991 } |
1089 | 992 |
1090 JOW(void, VideoRenderer_freeWrappedVideoRenderer)(JNIEnv*, jclass, jlong j_p) { | |
1091 delete reinterpret_cast<JavaVideoRendererWrapper*>(j_p); | |
1092 } | |
1093 | |
1094 JOW(void, VideoRenderer_releaseNativeFrame)( | |
1095 JNIEnv* jni, jclass, jlong j_frame_ptr) { | |
1096 delete reinterpret_cast<const webrtc::VideoFrame*>(j_frame_ptr); | |
1097 } | |
1098 | |
1099 JOW(void, MediaStreamTrack_free)(JNIEnv*, jclass, jlong j_p) { | 993 JOW(void, MediaStreamTrack_free)(JNIEnv*, jclass, jlong j_p) { |
1100 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release(); | 994 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release(); |
1101 } | 995 } |
1102 | 996 |
1103 JOW(jboolean, MediaStream_nativeAddAudioTrack)( | 997 JOW(jboolean, MediaStream_nativeAddAudioTrack)( |
1104 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) { | 998 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) { |
1105 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack( | 999 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack( |
1106 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer)); | 1000 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer)); |
1107 } | 1001 } |
1108 | 1002 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 rtc::tracing::ShutdownInternalTracer(); | 1091 rtc::tracing::ShutdownInternalTracer(); |
1198 } | 1092 } |
1199 | 1093 |
1200 JOW(void, AudioTrack_nativeSetVolume) | 1094 JOW(void, AudioTrack_nativeSetVolume) |
1201 (JNIEnv*, jclass, jlong j_p, jdouble volume) { | 1095 (JNIEnv*, jclass, jlong j_p, jdouble volume) { |
1202 rtc::scoped_refptr<AudioSourceInterface> source( | 1096 rtc::scoped_refptr<AudioSourceInterface> source( |
1203 reinterpret_cast<AudioTrackInterface*>(j_p)->GetSource()); | 1097 reinterpret_cast<AudioTrackInterface*>(j_p)->GetSource()); |
1204 source->SetVolume(volume); | 1098 source->SetVolume(volume); |
1205 } | 1099 } |
1206 | 1100 |
1207 // Helper struct for working around the fact that CreatePeerConnectionFactory() | |
1208 // comes in two flavors: either entirely automagical (constructing its own | |
1209 // threads and deleting them on teardown, but no external codec factory support) | |
1210 // or entirely manual (requires caller to delete threads after factory | |
1211 // teardown). This struct takes ownership of its ctor's arguments to present a | |
1212 // single thing for Java to hold and eventually free. | |
1213 class OwnedFactoryAndThreads { | |
1214 public: | |
1215 OwnedFactoryAndThreads(std::unique_ptr<Thread> network_thread, | |
1216 std::unique_ptr<Thread> worker_thread, | |
1217 std::unique_ptr<Thread> signaling_thread, | |
1218 WebRtcVideoEncoderFactory* encoder_factory, | |
1219 WebRtcVideoDecoderFactory* decoder_factory, | |
1220 rtc::NetworkMonitorFactory* network_monitor_factory, | |
1221 PeerConnectionFactoryInterface* factory) | |
1222 : network_thread_(std::move(network_thread)), | |
1223 worker_thread_(std::move(worker_thread)), | |
1224 signaling_thread_(std::move(signaling_thread)), | |
1225 encoder_factory_(encoder_factory), | |
1226 decoder_factory_(decoder_factory), | |
1227 network_monitor_factory_(network_monitor_factory), | |
1228 factory_(factory) {} | |
1229 | |
1230 ~OwnedFactoryAndThreads() { | |
1231 CHECK_RELEASE(factory_); | |
1232 if (network_monitor_factory_ != nullptr) { | |
1233 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); | |
1234 } | |
1235 } | |
1236 | |
1237 PeerConnectionFactoryInterface* factory() { return factory_; } | |
1238 Thread* signaling_thread() { return signaling_thread_.get(); } | |
1239 Thread* worker_thread() { return worker_thread_.get(); } | |
1240 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } | |
1241 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } | |
1242 rtc::NetworkMonitorFactory* network_monitor_factory() { | |
1243 return network_monitor_factory_; | |
1244 } | |
1245 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } | |
1246 void InvokeJavaCallbacksOnFactoryThreads(); | |
1247 | |
1248 private: | |
1249 void JavaCallbackOnFactoryThreads(); | |
1250 | |
1251 const std::unique_ptr<Thread> network_thread_; | |
1252 const std::unique_ptr<Thread> worker_thread_; | |
1253 const std::unique_ptr<Thread> signaling_thread_; | |
1254 WebRtcVideoEncoderFactory* encoder_factory_; | |
1255 WebRtcVideoDecoderFactory* decoder_factory_; | |
1256 rtc::NetworkMonitorFactory* network_monitor_factory_; | |
1257 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. | |
1258 }; | |
1259 | |
1260 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { | |
1261 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | |
1262 ScopedLocalRefFrame local_ref_frame(jni); | |
1263 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); | |
1264 jmethodID m = nullptr; | |
1265 if (network_thread_->IsCurrent()) { | |
1266 LOG(LS_INFO) << "Network thread JavaCallback"; | |
1267 m = GetStaticMethodID(jni, j_factory_class, "onNetworkThreadReady", "()V"); | |
1268 } | |
1269 if (worker_thread_->IsCurrent()) { | |
1270 LOG(LS_INFO) << "Worker thread JavaCallback"; | |
1271 m = GetStaticMethodID(jni, j_factory_class, "onWorkerThreadReady", "()V"); | |
1272 } | |
1273 if (signaling_thread_->IsCurrent()) { | |
1274 LOG(LS_INFO) << "Signaling thread JavaCallback"; | |
1275 m = GetStaticMethodID( | |
1276 jni, j_factory_class, "onSignalingThreadReady", "()V"); | |
1277 } | |
1278 if (m != nullptr) { | |
1279 jni->CallStaticVoidMethod(j_factory_class, m); | |
1280 CHECK_EXCEPTION(jni) << "error during JavaCallback::CallStaticVoidMethod"; | |
1281 } | |
1282 } | |
1283 | |
1284 void OwnedFactoryAndThreads::InvokeJavaCallbacksOnFactoryThreads() { | |
1285 LOG(LS_INFO) << "InvokeJavaCallbacksOnFactoryThreads."; | |
1286 network_thread_->Invoke<void>(RTC_FROM_HERE, | |
1287 [this] { JavaCallbackOnFactoryThreads(); }); | |
1288 worker_thread_->Invoke<void>(RTC_FROM_HERE, | |
1289 [this] { JavaCallbackOnFactoryThreads(); }); | |
1290 signaling_thread_->Invoke<void>(RTC_FROM_HERE, | |
1291 [this] { JavaCallbackOnFactoryThreads(); }); | |
1292 } | |
1293 | |
1294 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni, | 1101 PeerConnectionFactoryInterface::Options ParseOptionsFromJava(JNIEnv* jni, |
1295 jobject options) { | 1102 jobject options) { |
1296 jclass options_class = jni->GetObjectClass(options); | 1103 jclass options_class = jni->GetObjectClass(options); |
1297 jfieldID network_ignore_mask_field = | 1104 jfieldID network_ignore_mask_field = |
1298 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); | 1105 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); |
1299 int network_ignore_mask = | 1106 int network_ignore_mask = |
1300 jni->GetIntField(options, network_ignore_mask_field); | 1107 jni->GetIntField(options, network_ignore_mask_field); |
1301 | 1108 |
1302 jfieldID disable_encryption_field = | 1109 jfieldID disable_encryption_field = |
1303 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... |
1346 WebRtcVideoDecoderFactory* decoder_factory = nullptr; | 1153 WebRtcVideoDecoderFactory* decoder_factory = nullptr; |
1347 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; | 1154 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; |
1348 | 1155 |
1349 PeerConnectionFactoryInterface::Options options; | 1156 PeerConnectionFactoryInterface::Options options; |
1350 bool has_options = joptions != NULL; | 1157 bool has_options = joptions != NULL; |
1351 if (has_options) { | 1158 if (has_options) { |
1352 options = ParseOptionsFromJava(jni, joptions); | 1159 options = ParseOptionsFromJava(jni, joptions); |
1353 } | 1160 } |
1354 | 1161 |
1355 if (video_hw_acceleration_enabled) { | 1162 if (video_hw_acceleration_enabled) { |
1356 encoder_factory = new MediaCodecVideoEncoderFactory(); | 1163 encoder_factory = CreateVideoEncoderFactory(); |
1357 decoder_factory = new MediaCodecVideoDecoderFactory(); | 1164 decoder_factory = CreateVideoDecoderFactory(); |
1358 } | 1165 } |
1359 // Do not create network_monitor_factory only if the options are | 1166 // Do not create network_monitor_factory only if the options are |
1360 // provided and disable_network_monitor therein is set to true. | 1167 // provided and disable_network_monitor therein is set to true. |
1361 if (!(has_options && options.disable_network_monitor)) { | 1168 if (!(has_options && options.disable_network_monitor)) { |
1362 network_monitor_factory = new AndroidNetworkMonitorFactory(); | 1169 network_monitor_factory = new AndroidNetworkMonitorFactory(); |
1363 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); | 1170 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); |
1364 } | 1171 } |
1365 | 1172 |
1366 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1173 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1367 webrtc::CreatePeerConnectionFactory( | 1174 webrtc::CreatePeerConnectionFactory( |
(...skipping 17 matching lines...) Expand all Loading... |
1385 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { | 1192 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { |
1386 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1193 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1387 if (field_trials_init_string) { | 1194 if (field_trials_init_string) { |
1388 webrtc::field_trial::InitFieldTrialsFromString(NULL); | 1195 webrtc::field_trial::InitFieldTrialsFromString(NULL); |
1389 delete field_trials_init_string; | 1196 delete field_trials_init_string; |
1390 field_trials_init_string = NULL; | 1197 field_trials_init_string = NULL; |
1391 } | 1198 } |
1392 webrtc::Trace::ReturnTrace(); | 1199 webrtc::Trace::ReturnTrace(); |
1393 } | 1200 } |
1394 | 1201 |
1395 static PeerConnectionFactoryInterface* factoryFromJava(jlong j_p) { | |
1396 return reinterpret_cast<OwnedFactoryAndThreads*>(j_p)->factory(); | |
1397 } | |
1398 | |
1399 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( | 1202 JOW(void, PeerConnectionFactory_nativeThreadsCallbacks)( |
1400 JNIEnv*, jclass, jlong j_p) { | 1203 JNIEnv*, jclass, jlong j_p) { |
1401 OwnedFactoryAndThreads *factory = | 1204 OwnedFactoryAndThreads *factory = |
1402 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1205 reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1403 factory->InvokeJavaCallbacksOnFactoryThreads(); | 1206 factory->InvokeJavaCallbacksOnFactoryThreads(); |
1404 } | 1207 } |
1405 | 1208 |
1406 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( | 1209 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( |
1407 JNIEnv* jni, jclass, jlong native_factory, jstring label) { | 1210 JNIEnv* jni, jclass, jlong native_factory, jstring label) { |
1408 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1211 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1409 factoryFromJava(native_factory)); | 1212 factoryFromJava(native_factory)); |
1410 rtc::scoped_refptr<MediaStreamInterface> stream( | 1213 rtc::scoped_refptr<MediaStreamInterface> stream( |
1411 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); | 1214 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); |
1412 return (jlong)stream.release(); | 1215 return (jlong)stream.release(); |
1413 } | 1216 } |
1414 | 1217 |
1415 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) | |
1416 (JNIEnv* jni, | |
1417 jclass, | |
1418 jlong native_factory, | |
1419 jobject j_surface_texture_helper, | |
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_surface_texture_helper, | |
1427 is_screencast)); | |
1428 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = | |
1429 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), | |
1430 factory->worker_thread(), source); | |
1431 | |
1432 return (jlong)proxy_source.release(); | |
1433 } | |
1434 | |
1435 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)( | |
1436 JNIEnv* jni, jclass, jlong native_factory, jstring id, | |
1437 jlong native_source) { | |
1438 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | |
1439 factoryFromJava(native_factory)); | |
1440 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack( | |
1441 JavaToStdString(jni, id), | |
1442 reinterpret_cast<VideoTrackSourceInterface*>(native_source))); | |
1443 return (jlong)track.release(); | |
1444 } | |
1445 | |
1446 JOW(jlong, PeerConnectionFactory_nativeCreateAudioSource)( | 1218 JOW(jlong, PeerConnectionFactory_nativeCreateAudioSource)( |
1447 JNIEnv* jni, jclass, jlong native_factory, jobject j_constraints) { | 1219 JNIEnv* jni, jclass, jlong native_factory, jobject j_constraints) { |
1448 std::unique_ptr<ConstraintsWrapper> constraints( | 1220 std::unique_ptr<ConstraintsWrapper> constraints( |
1449 new ConstraintsWrapper(jni, j_constraints)); | 1221 new ConstraintsWrapper(jni, j_constraints)); |
1450 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1222 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1451 factoryFromJava(native_factory)); | 1223 factoryFromJava(native_factory)); |
1452 cricket::AudioOptions options; | 1224 cricket::AudioOptions options; |
1453 CopyConstraintsIntoAudioOptions(constraints.get(), &options); | 1225 CopyConstraintsIntoAudioOptions(constraints.get(), &options); |
1454 rtc::scoped_refptr<AudioSourceInterface> source( | 1226 rtc::scoped_refptr<AudioSourceInterface> source( |
1455 factory->CreateAudioSource(options)); | 1227 factory->CreateAudioSource(options)); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 OwnedFactoryAndThreads* owner = | 1266 OwnedFactoryAndThreads* owner = |
1495 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | 1267 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
1496 if (owner->network_monitor_factory()) { | 1268 if (owner->network_monitor_factory()) { |
1497 rtc::NetworkMonitorFactory::ReleaseFactory( | 1269 rtc::NetworkMonitorFactory::ReleaseFactory( |
1498 owner->network_monitor_factory()); | 1270 owner->network_monitor_factory()); |
1499 owner->clear_network_monitor_factory(); | 1271 owner->clear_network_monitor_factory(); |
1500 } | 1272 } |
1501 } | 1273 } |
1502 } | 1274 } |
1503 | 1275 |
1504 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( | |
1505 JNIEnv* jni, jclass, jlong native_factory, jobject local_egl_context, | |
1506 jobject remote_egl_context) { | |
1507 OwnedFactoryAndThreads* owned_factory = | |
1508 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | |
1509 | |
1510 jclass j_eglbase14_context_class = | |
1511 FindClass(jni, "org/webrtc/EglBase14$Context"); | |
1512 | |
1513 MediaCodecVideoEncoderFactory* encoder_factory = | |
1514 static_cast<MediaCodecVideoEncoderFactory*> | |
1515 (owned_factory->encoder_factory()); | |
1516 if (encoder_factory && | |
1517 jni->IsInstanceOf(local_egl_context, j_eglbase14_context_class)) { | |
1518 LOG(LS_INFO) << "Set EGL context for HW encoding."; | |
1519 encoder_factory->SetEGLContext(jni, local_egl_context); | |
1520 } | |
1521 | |
1522 MediaCodecVideoDecoderFactory* decoder_factory = | |
1523 static_cast<MediaCodecVideoDecoderFactory*> | |
1524 (owned_factory->decoder_factory()); | |
1525 if (decoder_factory) { | |
1526 LOG(LS_INFO) << "Set EGL context for HW decoding."; | |
1527 decoder_factory->SetEGLContext(jni, remote_egl_context); | |
1528 } | |
1529 } | |
1530 | |
1531 static PeerConnectionInterface::IceTransportsType | 1276 static PeerConnectionInterface::IceTransportsType |
1532 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) { | 1277 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) { |
1533 std::string enum_name = GetJavaEnumName( | 1278 std::string enum_name = GetJavaEnumName( |
1534 jni, "org/webrtc/PeerConnection$IceTransportsType", | 1279 jni, "org/webrtc/PeerConnection$IceTransportsType", |
1535 j_ice_transports_type); | 1280 j_ice_transports_type); |
1536 | 1281 |
1537 if (enum_name == "ALL") | 1282 if (enum_name == "ALL") |
1538 return PeerConnectionInterface::kAll; | 1283 return PeerConnectionInterface::kAll; |
1539 | 1284 |
1540 if (enum_name == "RELAY") | 1285 if (enum_name == "RELAY") |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2152 ExtractNativePC(jni, j_pc)->Close(); | 1897 ExtractNativePC(jni, j_pc)->Close(); |
2153 return; | 1898 return; |
2154 } | 1899 } |
2155 | 1900 |
2156 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) { | 1901 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) { |
2157 rtc::scoped_refptr<MediaSourceInterface> p( | 1902 rtc::scoped_refptr<MediaSourceInterface> p( |
2158 reinterpret_cast<MediaSourceInterface*>(j_p)); | 1903 reinterpret_cast<MediaSourceInterface*>(j_p)); |
2159 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); | 1904 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); |
2160 } | 1905 } |
2161 | 1906 |
2162 JOW(jlong, VideoRenderer_nativeWrapVideoRenderer)( | |
2163 JNIEnv* jni, jclass, jobject j_callbacks) { | |
2164 std::unique_ptr<JavaVideoRendererWrapper> renderer( | |
2165 new JavaVideoRendererWrapper(jni, j_callbacks)); | |
2166 return (jlong)renderer.release(); | |
2167 } | |
2168 | |
2169 JOW(void, VideoRenderer_nativeCopyPlane)( | |
2170 JNIEnv *jni, jclass, jobject j_src_buffer, jint width, jint height, | |
2171 jint src_stride, jobject j_dst_buffer, jint dst_stride) { | |
2172 size_t src_size = jni->GetDirectBufferCapacity(j_src_buffer); | |
2173 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); | |
2174 RTC_CHECK(src_stride >= width) << "Wrong source stride " << src_stride; | |
2175 RTC_CHECK(dst_stride >= width) << "Wrong destination stride " << dst_stride; | |
2176 RTC_CHECK(src_size >= src_stride * height) | |
2177 << "Insufficient source buffer capacity " << src_size; | |
2178 RTC_CHECK(dst_size >= dst_stride * height) | |
2179 << "Insufficient destination buffer capacity " << dst_size; | |
2180 uint8_t *src = | |
2181 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer)); | |
2182 uint8_t *dst = | |
2183 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); | |
2184 if (src_stride == dst_stride) { | |
2185 memcpy(dst, src, src_stride * height); | |
2186 } else { | |
2187 for (int i = 0; i < height; i++) { | |
2188 memcpy(dst, src, width); | |
2189 src += src_stride; | |
2190 dst += dst_stride; | |
2191 } | |
2192 } | |
2193 } | |
2194 | |
2195 JOW(void, FileVideoCapturer_nativeI420ToNV21)( | 1907 JOW(void, FileVideoCapturer_nativeI420ToNV21)( |
2196 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, | 1908 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, |
2197 jbyteArray j_dst_buffer) { | 1909 jbyteArray j_dst_buffer) { |
2198 size_t src_size = jni->GetArrayLength(j_src_buffer); | 1910 size_t src_size = jni->GetArrayLength(j_src_buffer); |
2199 size_t dst_size = jni->GetArrayLength(j_dst_buffer); | 1911 size_t dst_size = jni->GetArrayLength(j_dst_buffer); |
2200 int src_stride = width; | 1912 int src_stride = width; |
2201 int dst_stride = width; | 1913 int dst_stride = width; |
2202 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); | 1914 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); |
2203 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); | 1915 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); |
2204 | 1916 |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2716 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) | 2428 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) |
2717 ->inter_tone_gap(); | 2429 ->inter_tone_gap(); |
2718 } | 2430 } |
2719 | 2431 |
2720 JOW(void, DtmfSender_free) | 2432 JOW(void, DtmfSender_free) |
2721 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { | 2433 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { |
2722 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); | 2434 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); |
2723 } | 2435 } |
2724 | 2436 |
2725 } // namespace webrtc_jni | 2437 } // namespace webrtc_jni |
OLD | NEW |