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 26 matching lines...) Expand all Loading... |
37 | 37 |
38 #include <jni.h> | 38 #include <jni.h> |
39 #undef JNIEXPORT | 39 #undef JNIEXPORT |
40 #define JNIEXPORT __attribute__((visibility("default"))) | 40 #define JNIEXPORT __attribute__((visibility("default"))) |
41 | 41 |
42 #include <limits> | 42 #include <limits> |
43 #include <memory> | 43 #include <memory> |
44 #include <utility> | 44 #include <utility> |
45 | 45 |
46 #include "webrtc/api/androidvideocapturer.h" | 46 #include "webrtc/api/androidvideocapturer.h" |
| 47 #include "webrtc/api/androidvideotracksource.h" |
47 #include "webrtc/api/android/jni/androidmediadecoder_jni.h" | 48 #include "webrtc/api/android/jni/androidmediadecoder_jni.h" |
48 #include "webrtc/api/android/jni/androidmediaencoder_jni.h" | 49 #include "webrtc/api/android/jni/androidmediaencoder_jni.h" |
49 #include "webrtc/api/android/jni/androidnetworkmonitor_jni.h" | 50 #include "webrtc/api/android/jni/androidnetworkmonitor_jni.h" |
50 #include "webrtc/api/android/jni/androidvideocapturer_jni.h" | 51 #include "webrtc/api/android/jni/androidvideocapturer_jni.h" |
51 #include "webrtc/api/android/jni/classreferenceholder.h" | 52 #include "webrtc/api/android/jni/classreferenceholder.h" |
52 #include "webrtc/api/android/jni/jni_helpers.h" | 53 #include "webrtc/api/android/jni/jni_helpers.h" |
53 #include "webrtc/api/android/jni/native_handle_impl.h" | 54 #include "webrtc/api/android/jni/native_handle_impl.h" |
54 #include "webrtc/api/mediaconstraintsinterface.h" | 55 #include "webrtc/api/mediaconstraintsinterface.h" |
55 #include "webrtc/api/peerconnectioninterface.h" | 56 #include "webrtc/api/peerconnectioninterface.h" |
56 #include "webrtc/api/rtpreceiverinterface.h" | 57 #include "webrtc/api/rtpreceiverinterface.h" |
57 #include "webrtc/api/rtpsenderinterface.h" | 58 #include "webrtc/api/rtpsenderinterface.h" |
| 59 #include "webrtc/api/videosourceproxy.h" |
58 #include "webrtc/api/webrtcsdp.h" | 60 #include "webrtc/api/webrtcsdp.h" |
59 #include "webrtc/base/bind.h" | 61 #include "webrtc/base/bind.h" |
60 #include "webrtc/base/checks.h" | 62 #include "webrtc/base/checks.h" |
61 #include "webrtc/base/event_tracer.h" | 63 #include "webrtc/base/event_tracer.h" |
62 #include "webrtc/base/logging.h" | 64 #include "webrtc/base/logging.h" |
63 #include "webrtc/base/logsinks.h" | 65 #include "webrtc/base/logsinks.h" |
64 #include "webrtc/base/messagequeue.h" | 66 #include "webrtc/base/messagequeue.h" |
65 #include "webrtc/base/networkmonitor.h" | 67 #include "webrtc/base/networkmonitor.h" |
66 #include "webrtc/base/rtccertificategenerator.h" | 68 #include "webrtc/base/rtccertificategenerator.h" |
67 #include "webrtc/base/ssladapter.h" | 69 #include "webrtc/base/ssladapter.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 using webrtc::kVideoCodecVP8; | 111 using webrtc::kVideoCodecVP8; |
110 | 112 |
111 namespace webrtc_jni { | 113 namespace webrtc_jni { |
112 | 114 |
113 // Field trials initialization string | 115 // Field trials initialization string |
114 static char *field_trials_init_string = NULL; | 116 static char *field_trials_init_string = NULL; |
115 | 117 |
116 // Set in PeerConnectionFactory_initializeAndroidGlobals(). | 118 // Set in PeerConnectionFactory_initializeAndroidGlobals(). |
117 static bool factory_static_initialized = false; | 119 static bool factory_static_initialized = false; |
118 static bool video_hw_acceleration_enabled = true; | 120 static bool video_hw_acceleration_enabled = true; |
| 121 static jobject j_application_context = nullptr; |
119 | 122 |
120 // Return the (singleton) Java Enum object corresponding to |index|; | 123 // Return the (singleton) Java Enum object corresponding to |index|; |
121 // |state_class_fragment| is something like "MediaSource$State". | 124 // |state_class_fragment| is something like "MediaSource$State". |
122 static jobject JavaEnumFromIndex( | 125 static jobject JavaEnumFromIndex( |
123 JNIEnv* jni, const std::string& state_class_fragment, int index) { | 126 JNIEnv* jni, const std::string& state_class_fragment, int index) { |
124 const std::string state_class = "org/webrtc/" + state_class_fragment; | 127 const std::string state_class = "org/webrtc/" + state_class_fragment; |
125 return JavaEnumFromIndex(jni, FindClass(jni, state_class.c_str()), | 128 return JavaEnumFromIndex(jni, FindClass(jni, state_class.c_str()), |
126 state_class, index); | 129 state_class, index); |
127 } | 130 } |
128 | 131 |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 JOW(void, PeerConnection_freePeerConnection)(JNIEnv*, jclass, jlong j_p) { | 927 JOW(void, PeerConnection_freePeerConnection)(JNIEnv*, jclass, jlong j_p) { |
925 CHECK_RELEASE(reinterpret_cast<PeerConnectionInterface*>(j_p)); | 928 CHECK_RELEASE(reinterpret_cast<PeerConnectionInterface*>(j_p)); |
926 } | 929 } |
927 | 930 |
928 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { | 931 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { |
929 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); | 932 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); |
930 delete p; | 933 delete p; |
931 } | 934 } |
932 | 935 |
933 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { | 936 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { |
934 CHECK_RELEASE(reinterpret_cast<MediaSourceInterface*>(j_p)); | 937 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); |
935 } | 938 } |
936 | 939 |
937 JOW(void, VideoRenderer_freeWrappedVideoRenderer)(JNIEnv*, jclass, jlong j_p) { | 940 JOW(void, VideoRenderer_freeWrappedVideoRenderer)(JNIEnv*, jclass, jlong j_p) { |
938 delete reinterpret_cast<JavaVideoRendererWrapper*>(j_p); | 941 delete reinterpret_cast<JavaVideoRendererWrapper*>(j_p); |
939 } | 942 } |
940 | 943 |
941 JOW(void, VideoRenderer_releaseNativeFrame)( | 944 JOW(void, VideoRenderer_releaseNativeFrame)( |
942 JNIEnv* jni, jclass, jlong j_frame_ptr) { | 945 JNIEnv* jni, jclass, jlong j_frame_ptr) { |
943 delete reinterpret_cast<const cricket::VideoFrame*>(j_frame_ptr); | 946 delete reinterpret_cast<const cricket::VideoFrame*>(j_frame_ptr); |
944 } | 947 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 | 981 |
979 JOW(void, MediaStream_free)(JNIEnv*, jclass, jlong j_p) { | 982 JOW(void, MediaStream_free)(JNIEnv*, jclass, jlong j_p) { |
980 CHECK_RELEASE(reinterpret_cast<MediaStreamInterface*>(j_p)); | 983 CHECK_RELEASE(reinterpret_cast<MediaStreamInterface*>(j_p)); |
981 } | 984 } |
982 | 985 |
983 JOW(jlong, PeerConnectionFactory_nativeCreateObserver)( | 986 JOW(jlong, PeerConnectionFactory_nativeCreateObserver)( |
984 JNIEnv * jni, jclass, jobject j_observer) { | 987 JNIEnv * jni, jclass, jobject j_observer) { |
985 return (jlong)new PCOJava(jni, j_observer); | 988 return (jlong)new PCOJava(jni, j_observer); |
986 } | 989 } |
987 | 990 |
988 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)( | 991 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals) |
989 JNIEnv* jni, jclass, jobject context, | 992 (JNIEnv* jni, |
990 jboolean initialize_audio, jboolean initialize_video, | 993 jclass, |
991 jboolean video_hw_acceleration) { | 994 jobject context, |
| 995 jboolean initialize_audio, |
| 996 jboolean initialize_video, |
| 997 jboolean video_hw_acceleration) { |
992 bool failure = false; | 998 bool failure = false; |
993 video_hw_acceleration_enabled = video_hw_acceleration; | 999 video_hw_acceleration_enabled = video_hw_acceleration; |
994 AndroidNetworkMonitor::SetAndroidContext(jni, context); | 1000 AndroidNetworkMonitor::SetAndroidContext(jni, context); |
995 if (!factory_static_initialized) { | 1001 if (!factory_static_initialized) { |
| 1002 RTC_DCHECK(j_application_context == nullptr); |
| 1003 j_application_context = NewGlobalRef(jni, context); |
| 1004 |
996 if (initialize_video) { | 1005 if (initialize_video) { |
997 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context); | 1006 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context); |
998 } | 1007 } |
999 if (initialize_audio) | 1008 if (initialize_audio) |
1000 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); | 1009 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); |
1001 factory_static_initialized = true; | 1010 factory_static_initialized = true; |
1002 } | 1011 } |
1003 return !failure; | 1012 return !failure; |
1004 } | 1013 } |
1005 | 1014 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 factory_(factory) {} | 1077 factory_(factory) {} |
1069 | 1078 |
1070 ~OwnedFactoryAndThreads() { | 1079 ~OwnedFactoryAndThreads() { |
1071 CHECK_RELEASE(factory_); | 1080 CHECK_RELEASE(factory_); |
1072 if (network_monitor_factory_ != nullptr) { | 1081 if (network_monitor_factory_ != nullptr) { |
1073 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); | 1082 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); |
1074 } | 1083 } |
1075 } | 1084 } |
1076 | 1085 |
1077 PeerConnectionFactoryInterface* factory() { return factory_; } | 1086 PeerConnectionFactoryInterface* factory() { return factory_; } |
| 1087 Thread* signaling_thread() { return signaling_thread_.get(); } |
| 1088 Thread* worker_thread() { return worker_thread_.get(); } |
1078 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } | 1089 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } |
1079 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } | 1090 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } |
1080 rtc::NetworkMonitorFactory* network_monitor_factory() { | 1091 rtc::NetworkMonitorFactory* network_monitor_factory() { |
1081 return network_monitor_factory_; | 1092 return network_monitor_factory_; |
1082 } | 1093 } |
1083 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } | 1094 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } |
1084 void InvokeJavaCallbacksOnFactoryThreads(); | 1095 void InvokeJavaCallbacksOnFactoryThreads(); |
1085 | 1096 |
1086 private: | 1097 private: |
1087 void JavaCallbackOnFactoryThreads(); | 1098 void JavaCallbackOnFactoryThreads(); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 // native factory and constraints. | 1274 // native factory and constraints. |
1264 std::unique_ptr<ConstraintsWrapper> constraints( | 1275 std::unique_ptr<ConstraintsWrapper> constraints( |
1265 new ConstraintsWrapper(jni, j_constraints)); | 1276 new ConstraintsWrapper(jni, j_constraints)); |
1266 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1277 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1267 factoryFromJava(native_factory)); | 1278 factoryFromJava(native_factory)); |
1268 rtc::scoped_refptr<VideoTrackSourceInterface> source( | 1279 rtc::scoped_refptr<VideoTrackSourceInterface> source( |
1269 factory->CreateVideoSource(capturer.release(), constraints.get())); | 1280 factory->CreateVideoSource(capturer.release(), constraints.get())); |
1270 return (jlong)source.release(); | 1281 return (jlong)source.release(); |
1271 } | 1282 } |
1272 | 1283 |
| 1284 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource2) |
| 1285 (JNIEnv* jni, jclass, jlong native_factory, jobject j_egl_context) { |
| 1286 OwnedFactoryAndThreads* factory = |
| 1287 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
| 1288 |
| 1289 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source( |
| 1290 new rtc::RefCountedObject<webrtc::AndroidVideoTrackSource>( |
| 1291 factory->signaling_thread(), jni, j_egl_context)); |
| 1292 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = |
| 1293 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), |
| 1294 factory->worker_thread(), source); |
| 1295 |
| 1296 return (jlong)proxy_source.release(); |
| 1297 } |
| 1298 |
| 1299 JOW(void, PeerConnectionFactory_nativeInitializeVideoCapturer) |
| 1300 (JNIEnv* jni, |
| 1301 jclass, |
| 1302 jlong native_factory, |
| 1303 jobject j_video_capturer, |
| 1304 jlong native_source, |
| 1305 jobject j_frame_observer) { |
| 1306 LOG(LS_INFO) << "PeerConnectionFactory_nativeInitializeVideoCapturer"; |
| 1307 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
| 1308 factoryFromJava(native_factory)); |
| 1309 auto proxy_source = |
| 1310 reinterpret_cast<webrtc::VideoTrackSourceProxy*>(native_source); |
| 1311 auto source = reinterpret_cast<webrtc::AndroidVideoTrackSource*>( |
| 1312 proxy_source->internal()); |
| 1313 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper = |
| 1314 source->surface_texture_helper(); |
| 1315 jni->CallVoidMethod( |
| 1316 j_video_capturer, |
| 1317 GetMethodID(jni, FindClass(jni, "org/webrtc/VideoCapturer"), "initialize", |
| 1318 "(Lorg/webrtc/SurfaceTextureHelper;Landroid/content/" |
| 1319 "Context;Lorg/webrtc/VideoCapturer$CapturerObserver;)V"), |
| 1320 surface_texture_helper |
| 1321 ? surface_texture_helper->GetJavaSurfaceTextureHelper() |
| 1322 : nullptr, |
| 1323 j_application_context, j_frame_observer); |
| 1324 CHECK_EXCEPTION(jni) << "error during VideoCapturer.initialize()"; |
| 1325 } |
| 1326 |
1273 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)( | 1327 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)( |
1274 JNIEnv* jni, jclass, jlong native_factory, jstring id, | 1328 JNIEnv* jni, jclass, jlong native_factory, jstring id, |
1275 jlong native_source) { | 1329 jlong native_source) { |
1276 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1330 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1277 factoryFromJava(native_factory)); | 1331 factoryFromJava(native_factory)); |
1278 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack( | 1332 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack( |
1279 JavaToStdString(jni, id), | 1333 JavaToStdString(jni, id), |
1280 reinterpret_cast<VideoTrackSourceInterface*>(native_source))); | 1334 reinterpret_cast<VideoTrackSourceInterface*>(native_source))); |
1281 return (jlong)track.release(); | 1335 return (jlong)track.release(); |
1282 } | 1336 } |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 return JavaStringFromStdString( | 2345 return JavaStringFromStdString( |
2292 jni, | 2346 jni, |
2293 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2347 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
2294 } | 2348 } |
2295 | 2349 |
2296 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2350 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
2297 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2351 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
2298 } | 2352 } |
2299 | 2353 |
2300 } // namespace webrtc_jni | 2354 } // namespace webrtc_jni |
OLD | NEW |