Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: webrtc/sdk/android/src/jni/peerconnection_jni.cc

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

Powered by Google App Engine
This is Rietveld 408576698