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

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

Issue 2854123003: Build WebRTC with data channel only. (Closed)
Patch Set: Add a Java level test. Created 3 years, 7 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" 64 // Adding 'nogncheck' to disable the gn include headers check.
65 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" 65 // We don't want to always depend on audio and video related targets.
66 #include "webrtc/media/engine/webrtcvideodecoderfactory.h" // nogncheck
67 #include "webrtc/media/engine/webrtcvideoencoderfactory.h" // nogncheck
66 #include "webrtc/modules/utility/include/jvm_android.h" 68 #include "webrtc/modules/utility/include/jvm_android.h"
67 #include "webrtc/system_wrappers/include/field_trial.h"
68 #include "webrtc/pc/webrtcsdp.h" 69 #include "webrtc/pc/webrtcsdp.h"
69 #include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h" 70 #include "webrtc/sdk/android/src/jni/androidmediadecoder_jni.h" // nogncheck
70 #include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h" 71 #include "webrtc/sdk/android/src/jni/androidmediaencoder_jni.h" // nogncheck
71 #include "webrtc/sdk/android/src/jni/androidnetworkmonitor_jni.h" 72 #include "webrtc/sdk/android/src/jni/androidnetworkmonitor_jni.h"
72 #include "webrtc/sdk/android/src/jni/androidvideotracksource.h" 73 #include "webrtc/sdk/android/src/jni/androidvideotracksource.h" // nogncheck
73 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" 74 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
74 #include "webrtc/sdk/android/src/jni/jni_helpers.h" 75 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
75 #include "webrtc/sdk/android/src/jni/native_handle_impl.h" 76 #include "webrtc/sdk/android/src/jni/native_handle_impl.h" // nogncheck
76 #include "webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h" 77 #include "webrtc/sdk/android/src/jni/rtcstatscollectorcallbackwrapper.h"
78 #include "webrtc/system_wrappers/include/field_trial.h"
77 // Adding 'nogncheck' to disable the gn include headers check. 79 // Adding 'nogncheck' to disable the gn include headers check.
78 // We don't want to depend on 'system_wrappers:field_trial_default' because 80 // We don't want to depend on 'system_wrappers:field_trial_default' because
79 // clients should be able to provide their own implementation. 81 // clients should be able to provide their own implementation.
80 #include "webrtc/system_wrappers/include/field_trial_default.h" // nogncheck 82 #include "webrtc/system_wrappers/include/field_trial_default.h" // nogncheck
81 #include "webrtc/system_wrappers/include/logcat_trace_context.h" 83 #include "webrtc/system_wrappers/include/logcat_trace_context.h"
82 #include "webrtc/system_wrappers/include/trace.h" 84 #include "webrtc/system_wrappers/include/trace.h"
83 #include "webrtc/voice_engine/include/voe_base.h" 85 #include "webrtc/voice_engine/include/voe_base.h" // nogncheck
84 86
85 using cricket::WebRtcVideoDecoderFactory; 87 using cricket::WebRtcVideoDecoderFactory;
86 using cricket::WebRtcVideoEncoderFactory; 88 using cricket::WebRtcVideoEncoderFactory;
87 using rtc::Bind; 89 using rtc::Bind;
88 using rtc::Thread; 90 using rtc::Thread;
89 using rtc::ThreadManager; 91 using rtc::ThreadManager;
90 using webrtc::AudioSourceInterface; 92 using webrtc::AudioSourceInterface;
91 using webrtc::AudioTrackInterface; 93 using webrtc::AudioTrackInterface;
92 using webrtc::AudioTrackVector; 94 using webrtc::AudioTrackVector;
93 using webrtc::CreateSessionDescriptionObserver; 95 using webrtc::CreateSessionDescriptionObserver;
(...skipping 19 matching lines...) Expand all
113 using webrtc::StatsObserver; 115 using webrtc::StatsObserver;
114 using webrtc::StatsReport; 116 using webrtc::StatsReport;
115 using webrtc::StatsReports; 117 using webrtc::StatsReports;
116 using webrtc::VideoTrackSourceInterface; 118 using webrtc::VideoTrackSourceInterface;
117 using webrtc::VideoTrackInterface; 119 using webrtc::VideoTrackInterface;
118 using webrtc::VideoTrackVector; 120 using webrtc::VideoTrackVector;
119 using webrtc::kVideoCodecVP8; 121 using webrtc::kVideoCodecVP8;
120 122
121 namespace webrtc_jni { 123 namespace webrtc_jni {
122 124
125 WebRtcVideoEncoderFactory* CreateVideoEncoderFactory();
126
127 WebRtcVideoDecoderFactory* CreateVideoDecoderFactory();
128
129 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource>
130 CreateAndroidVideoTrackSource(rtc::Thread* signaling_thread,
131 JNIEnv* jni,
132 jobject j_egl_context,
133 bool is_screencast = false);
134
135 jobject GetJavaSurfaceTextureHelper(
136 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper);
137
138 void EncoderFactorySetEGLContext(MediaCodecVideoEncoderFactory* encoder_factory,
139 JNIEnv* jni,
140 jobject local_egl_context);
141
142 void DecoderFactorySetEGLContext(MediaCodecVideoDecoderFactory* decoder_factory,
143 JNIEnv* jni,
144 jobject remote_egl_context);
145
123 // Field trials initialization string 146 // Field trials initialization string
124 static char *field_trials_init_string = NULL; 147 static char *field_trials_init_string = NULL;
125 148
126 // Set in PeerConnectionFactory_initializeAndroidGlobals(). 149 // Set in PeerConnectionFactory_initializeAndroidGlobals().
127 static bool factory_static_initialized = false; 150 static bool factory_static_initialized = false;
128 static bool video_hw_acceleration_enabled = true; 151 static bool video_hw_acceleration_enabled = true;
129 static jobject j_application_context = nullptr; 152 static jobject j_application_context = nullptr;
130 153
131 // Return the (singleton) Java Enum object corresponding to |index|; 154 // Return the (singleton) Java Enum object corresponding to |index|;
132 // |state_class_fragment| is something like "MediaSource$State". 155 // |state_class_fragment| is something like "MediaSource$State".
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 } 863 }
841 864
842 const ScopedGlobalRef<jobject> j_observer_global_; 865 const ScopedGlobalRef<jobject> j_observer_global_;
843 const ScopedGlobalRef<jclass> j_observer_class_; 866 const ScopedGlobalRef<jclass> j_observer_class_;
844 const ScopedGlobalRef<jclass> j_stats_report_class_; 867 const ScopedGlobalRef<jclass> j_stats_report_class_;
845 const jmethodID j_stats_report_ctor_; 868 const jmethodID j_stats_report_ctor_;
846 const ScopedGlobalRef<jclass> j_value_class_; 869 const ScopedGlobalRef<jclass> j_value_class_;
847 const jmethodID j_value_ctor_; 870 const jmethodID j_value_ctor_;
848 }; 871 };
849 872
850 // Wrapper dispatching rtc::VideoSinkInterface to a Java VideoRenderer
851 // instance.
852 class JavaVideoRendererWrapper
853 : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
854 public:
855 JavaVideoRendererWrapper(JNIEnv* jni, jobject j_callbacks)
856 : j_callbacks_(jni, j_callbacks),
857 j_render_frame_id_(GetMethodID(
858 jni, GetObjectClass(jni, j_callbacks), "renderFrame",
859 "(Lorg/webrtc/VideoRenderer$I420Frame;)V")),
860 j_frame_class_(jni,
861 FindClass(jni, "org/webrtc/VideoRenderer$I420Frame")),
862 j_i420_frame_ctor_id_(GetMethodID(
863 jni, *j_frame_class_, "<init>", "(III[I[Ljava/nio/ByteBuffer;J)V")),
864 j_texture_frame_ctor_id_(GetMethodID(
865 jni, *j_frame_class_, "<init>",
866 "(IIII[FJ)V")),
867 j_byte_buffer_class_(jni, FindClass(jni, "java/nio/ByteBuffer")) {
868 CHECK_EXCEPTION(jni);
869 }
870
871 virtual ~JavaVideoRendererWrapper() {}
872
873 void OnFrame(const webrtc::VideoFrame& video_frame) override {
874 ScopedLocalRefFrame local_ref_frame(jni());
875 jobject j_frame =
876 (video_frame.video_frame_buffer()->native_handle() != nullptr)
877 ? CricketToJavaTextureFrame(&video_frame)
878 : CricketToJavaI420Frame(&video_frame);
879 // |j_callbacks_| is responsible for releasing |j_frame| with
880 // VideoRenderer.renderFrameDone().
881 jni()->CallVoidMethod(*j_callbacks_, j_render_frame_id_, j_frame);
882 CHECK_EXCEPTION(jni());
883 }
884
885 private:
886 // Make a shallow copy of |frame| to be used with Java. The callee has
887 // ownership of the frame, and the frame should be released with
888 // VideoRenderer.releaseNativeFrame().
889 static jlong javaShallowCopy(const webrtc::VideoFrame* frame) {
890 return jlongFromPointer(new webrtc::VideoFrame(*frame));
891 }
892
893 // Return a VideoRenderer.I420Frame referring to the data in |frame|.
894 jobject CricketToJavaI420Frame(const webrtc::VideoFrame* frame) {
895 jintArray strides = jni()->NewIntArray(3);
896 jint* strides_array = jni()->GetIntArrayElements(strides, NULL);
897 strides_array[0] = frame->video_frame_buffer()->StrideY();
898 strides_array[1] = frame->video_frame_buffer()->StrideU();
899 strides_array[2] = frame->video_frame_buffer()->StrideV();
900 jni()->ReleaseIntArrayElements(strides, strides_array, 0);
901 jobjectArray planes = jni()->NewObjectArray(3, *j_byte_buffer_class_, NULL);
902 jobject y_buffer = jni()->NewDirectByteBuffer(
903 const_cast<uint8_t*>(frame->video_frame_buffer()->DataY()),
904 frame->video_frame_buffer()->StrideY() *
905 frame->video_frame_buffer()->height());
906 size_t chroma_height = (frame->height() + 1) / 2;
907 jobject u_buffer = jni()->NewDirectByteBuffer(
908 const_cast<uint8_t*>(frame->video_frame_buffer()->DataU()),
909 frame->video_frame_buffer()->StrideU() * chroma_height);
910 jobject v_buffer = jni()->NewDirectByteBuffer(
911 const_cast<uint8_t*>(frame->video_frame_buffer()->DataV()),
912 frame->video_frame_buffer()->StrideV() * chroma_height);
913
914 jni()->SetObjectArrayElement(planes, 0, y_buffer);
915 jni()->SetObjectArrayElement(planes, 1, u_buffer);
916 jni()->SetObjectArrayElement(planes, 2, v_buffer);
917 return jni()->NewObject(
918 *j_frame_class_, j_i420_frame_ctor_id_,
919 frame->width(), frame->height(),
920 static_cast<int>(frame->rotation()),
921 strides, planes, javaShallowCopy(frame));
922 }
923
924 // Return a VideoRenderer.I420Frame referring texture object in |frame|.
925 jobject CricketToJavaTextureFrame(const webrtc::VideoFrame* frame) {
926 NativeHandleImpl* handle = reinterpret_cast<NativeHandleImpl*>(
927 frame->video_frame_buffer()->native_handle());
928 jfloatArray sampling_matrix = handle->sampling_matrix.ToJava(jni());
929
930 return jni()->NewObject(
931 *j_frame_class_, j_texture_frame_ctor_id_,
932 frame->width(), frame->height(),
933 static_cast<int>(frame->rotation()),
934 handle->oes_texture_id, sampling_matrix, javaShallowCopy(frame));
935 }
936
937 JNIEnv* jni() {
938 return AttachCurrentThreadIfNeeded();
939 }
940
941 ScopedGlobalRef<jobject> j_callbacks_;
942 jmethodID j_render_frame_id_;
943 ScopedGlobalRef<jclass> j_frame_class_;
944 jmethodID j_i420_frame_ctor_id_;
945 jmethodID j_texture_frame_ctor_id_;
946 ScopedGlobalRef<jclass> j_byte_buffer_class_;
947 };
948
949 // Adapter between the C++ RtpReceiverObserverInterface and the Java 873 // Adapter between the C++ RtpReceiverObserverInterface and the Java
950 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and 874 // RtpReceiver.Observer interface. Wraps an instance of the Java interface and
951 // dispatches C++ callbacks to Java. 875 // dispatches C++ callbacks to Java.
952 class RtpReceiverObserver : public RtpReceiverObserverInterface { 876 class RtpReceiverObserver : public RtpReceiverObserverInterface {
953 public: 877 public:
954 RtpReceiverObserver(JNIEnv* jni, jobject j_observer) 878 RtpReceiverObserver(JNIEnv* jni, jobject j_observer)
955 : j_observer_global_(jni, j_observer) {} 879 : j_observer_global_(jni, j_observer) {}
956 880
957 ~RtpReceiverObserver() override {} 881 ~RtpReceiverObserver() override {}
958 882
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1005
1082 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { 1006 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) {
1083 PCOJava* p = reinterpret_cast<PCOJava*>(j_p); 1007 PCOJava* p = reinterpret_cast<PCOJava*>(j_p);
1084 delete p; 1008 delete p;
1085 } 1009 }
1086 1010
1087 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) { 1011 JOW(void, MediaSource_free)(JNIEnv*, jclass, jlong j_p) {
1088 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release(); 1012 reinterpret_cast<rtc::RefCountInterface*>(j_p)->Release();
1089 } 1013 }
1090 1014
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) { 1015 JOW(void, MediaStreamTrack_free)(JNIEnv*, jclass, jlong j_p) {
1101 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release(); 1016 reinterpret_cast<MediaStreamTrackInterface*>(j_p)->Release();
1102 } 1017 }
1103 1018
1104 JOW(jboolean, MediaStream_nativeAddAudioTrack)( 1019 JOW(jboolean, MediaStream_nativeAddAudioTrack)(
1105 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) { 1020 JNIEnv* jni, jclass, jlong pointer, jlong j_audio_track_pointer) {
1106 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack( 1021 return reinterpret_cast<MediaStreamInterface*>(pointer)->AddTrack(
1107 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer)); 1022 reinterpret_cast<AudioTrackInterface*>(j_audio_track_pointer));
1108 } 1023 }
1109 1024
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 WebRtcVideoDecoderFactory* decoder_factory = nullptr; 1265 WebRtcVideoDecoderFactory* decoder_factory = nullptr;
1351 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; 1266 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
1352 1267
1353 PeerConnectionFactoryInterface::Options options; 1268 PeerConnectionFactoryInterface::Options options;
1354 bool has_options = joptions != NULL; 1269 bool has_options = joptions != NULL;
1355 if (has_options) { 1270 if (has_options) {
1356 options = ParseOptionsFromJava(jni, joptions); 1271 options = ParseOptionsFromJava(jni, joptions);
1357 } 1272 }
1358 1273
1359 if (video_hw_acceleration_enabled) { 1274 if (video_hw_acceleration_enabled) {
1360 encoder_factory = new MediaCodecVideoEncoderFactory(); 1275 encoder_factory = CreateVideoEncoderFactory();
1361 decoder_factory = new MediaCodecVideoDecoderFactory(); 1276 decoder_factory = CreateVideoDecoderFactory();
1362 } 1277 }
1363 // Do not create network_monitor_factory only if the options are 1278 // Do not create network_monitor_factory only if the options are
1364 // provided and disable_network_monitor therein is set to true. 1279 // provided and disable_network_monitor therein is set to true.
1365 if (!(has_options && options.disable_network_monitor)) { 1280 if (!(has_options && options.disable_network_monitor)) {
1366 network_monitor_factory = new AndroidNetworkMonitorFactory(); 1281 network_monitor_factory = new AndroidNetworkMonitorFactory();
1367 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); 1282 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory);
1368 } 1283 }
1369 1284
1370 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1285 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1371 webrtc::CreatePeerConnectionFactory( 1286 webrtc::CreatePeerConnectionFactory(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1324
1410 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( 1325 JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)(
1411 JNIEnv* jni, jclass, jlong native_factory, jstring label) { 1326 JNIEnv* jni, jclass, jlong native_factory, jstring label) {
1412 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1327 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1413 factoryFromJava(native_factory)); 1328 factoryFromJava(native_factory));
1414 rtc::scoped_refptr<MediaStreamInterface> stream( 1329 rtc::scoped_refptr<MediaStreamInterface> stream(
1415 factory->CreateLocalMediaStream(JavaToStdString(jni, label))); 1330 factory->CreateLocalMediaStream(JavaToStdString(jni, label)));
1416 return (jlong)stream.release(); 1331 return (jlong)stream.release();
1417 } 1332 }
1418 1333
1419 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) 1334 JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource)
magjed_webrtc 2017/05/26 09:43:13 I would like to move this to video_jni.cc. I don't
Zhi Huang 2017/05/31 00:03:29 Done.
1420 (JNIEnv* jni, jclass, jlong native_factory, jobject j_egl_context, 1335 (JNIEnv* jni, jclass, jlong native_factory, jobject j_egl_context,
1421 jboolean is_screencast) { 1336 jboolean is_screencast) {
1422 OwnedFactoryAndThreads* factory = 1337 OwnedFactoryAndThreads* factory =
1423 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); 1338 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
1424 1339
1425 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source( 1340 rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source =
1426 new rtc::RefCountedObject<webrtc::AndroidVideoTrackSource>( 1341 CreateAndroidVideoTrackSource(factory->signaling_thread(), jni,
1427 factory->signaling_thread(), jni, j_egl_context, is_screencast)); 1342 j_egl_context, is_screencast);
1343 if (!source) {
1344 return (jlong)0;
1345 }
1428 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source = 1346 rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> proxy_source =
1429 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), 1347 webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(),
1430 factory->worker_thread(), source); 1348 factory->worker_thread(), source);
1431 1349
1432 return (jlong)proxy_source.release(); 1350 return (jlong)proxy_source.release();
1433 } 1351 }
1434 1352
1435 JOW(void, PeerConnectionFactory_nativeInitializeVideoCapturer) 1353 JOW(void, PeerConnectionFactory_nativeInitializeVideoCapturer)
magjed_webrtc 2017/05/26 09:43:13 Same here, move to video_jni.cc.
Zhi Huang 2017/05/31 00:03:29 I didn't move this method entirely to video_jni.cc
magjed_webrtc 2017/05/31 09:40:57 Is it possible to fix by adding 'extern jobject j_
1436 (JNIEnv* jni, 1354 (JNIEnv* jni,
1437 jclass, 1355 jclass,
1438 jlong native_factory, 1356 jlong native_factory,
1439 jobject j_video_capturer, 1357 jobject j_video_capturer,
1440 jlong native_source, 1358 jlong native_source,
1441 jobject j_frame_observer) { 1359 jobject j_frame_observer) {
1442 LOG(LS_INFO) << "PeerConnectionFactory_nativeInitializeVideoCapturer"; 1360 LOG(LS_INFO) << "PeerConnectionFactory_nativeInitializeVideoCapturer";
1443 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1361 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1444 factoryFromJava(native_factory)); 1362 factoryFromJava(native_factory));
1363 if (!native_source) {
1364 LOG(LS_WARNING) << "Failed to initialize the VideoCapturer.";
1365 return;
1366 }
1445 auto proxy_source = 1367 auto proxy_source =
1446 reinterpret_cast<webrtc::VideoTrackSourceProxy*>(native_source); 1368 reinterpret_cast<webrtc::VideoTrackSourceProxy*>(native_source);
1447 auto source = reinterpret_cast<webrtc::AndroidVideoTrackSource*>( 1369 auto source = reinterpret_cast<webrtc::AndroidVideoTrackSource*>(
1448 proxy_source->internal()); 1370 proxy_source->internal());
1371
1449 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper = 1372 rtc::scoped_refptr<SurfaceTextureHelper> surface_texture_helper =
1450 source->surface_texture_helper(); 1373 source->surface_texture_helper();
1451 jni->CallVoidMethod( 1374 jni->CallVoidMethod(
1452 j_video_capturer, 1375 j_video_capturer,
1453 GetMethodID(jni, FindClass(jni, "org/webrtc/VideoCapturer"), "initialize", 1376 GetMethodID(jni, FindClass(jni, "org/webrtc/VideoCapturer"), "initialize",
1454 "(Lorg/webrtc/SurfaceTextureHelper;Landroid/content/" 1377 "(Lorg/webrtc/SurfaceTextureHelper;Landroid/content/"
1455 "Context;Lorg/webrtc/VideoCapturer$CapturerObserver;)V"), 1378 "Context;Lorg/webrtc/VideoCapturer$CapturerObserver;)V"),
1456 surface_texture_helper 1379 GetJavaSurfaceTextureHelper(surface_texture_helper),
1457 ? surface_texture_helper->GetJavaSurfaceTextureHelper()
1458 : nullptr,
1459 j_application_context, j_frame_observer); 1380 j_application_context, j_frame_observer);
1460 CHECK_EXCEPTION(jni) << "error during VideoCapturer.initialize()"; 1381 CHECK_EXCEPTION(jni) << "error during VideoCapturer.initialize()";
1461 } 1382 }
1462 1383
1463 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)( 1384 JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)(
magjed_webrtc 2017/05/26 09:43:13 Move to video_jni.cc.
Zhi Huang 2017/05/31 00:03:29 Done.
1464 JNIEnv* jni, jclass, jlong native_factory, jstring id, 1385 JNIEnv* jni, jclass, jlong native_factory, jstring id,
1465 jlong native_source) { 1386 jlong native_source) {
1466 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1387 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1467 factoryFromJava(native_factory)); 1388 factoryFromJava(native_factory));
1468 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack( 1389 rtc::scoped_refptr<VideoTrackInterface> track(factory->CreateVideoTrack(
1469 JavaToStdString(jni, id), 1390 JavaToStdString(jni, id),
1470 reinterpret_cast<VideoTrackSourceInterface*>(native_source))); 1391 reinterpret_cast<VideoTrackSourceInterface*>(native_source)));
1471 return (jlong)track.release(); 1392 return (jlong)track.release();
1472 } 1393 }
1473 1394
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1522 OwnedFactoryAndThreads* owner = 1443 OwnedFactoryAndThreads* owner =
1523 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); 1444 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
1524 if (owner->network_monitor_factory()) { 1445 if (owner->network_monitor_factory()) {
1525 rtc::NetworkMonitorFactory::ReleaseFactory( 1446 rtc::NetworkMonitorFactory::ReleaseFactory(
1526 owner->network_monitor_factory()); 1447 owner->network_monitor_factory());
1527 owner->clear_network_monitor_factory(); 1448 owner->clear_network_monitor_factory();
1528 } 1449 }
1529 } 1450 }
1530 } 1451 }
1531 1452
1532 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( 1453 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)(
magjed_webrtc 2017/05/26 09:43:13 Move to video_jni.cc.
Zhi Huang 2017/05/31 00:03:29 Done.
1533 JNIEnv* jni, jclass, jlong native_factory, jobject local_egl_context, 1454 JNIEnv* jni, jclass, jlong native_factory, jobject local_egl_context,
1534 jobject remote_egl_context) { 1455 jobject remote_egl_context) {
1535 OwnedFactoryAndThreads* owned_factory = 1456 OwnedFactoryAndThreads* owned_factory =
1536 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); 1457 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory);
1537 1458
1538 jclass j_eglbase14_context_class = 1459 jclass j_eglbase14_context_class =
1539 FindClass(jni, "org/webrtc/EglBase14$Context"); 1460 FindClass(jni, "org/webrtc/EglBase14$Context");
1540 1461
1541 MediaCodecVideoEncoderFactory* encoder_factory = 1462 MediaCodecVideoEncoderFactory* encoder_factory =
1542 static_cast<MediaCodecVideoEncoderFactory*> 1463 static_cast<MediaCodecVideoEncoderFactory*>
1543 (owned_factory->encoder_factory()); 1464 (owned_factory->encoder_factory());
1544 if (encoder_factory && 1465 if (encoder_factory &&
1545 jni->IsInstanceOf(local_egl_context, j_eglbase14_context_class)) { 1466 jni->IsInstanceOf(local_egl_context, j_eglbase14_context_class)) {
1546 LOG(LS_INFO) << "Set EGL context for HW encoding."; 1467 LOG(LS_INFO) << "Set EGL context for HW encoding.";
1547 encoder_factory->SetEGLContext(jni, local_egl_context); 1468 EncoderFactorySetEGLContext(encoder_factory, jni, local_egl_context);
1548 } 1469 }
1549 1470
1550 MediaCodecVideoDecoderFactory* decoder_factory = 1471 MediaCodecVideoDecoderFactory* decoder_factory =
1551 static_cast<MediaCodecVideoDecoderFactory*> 1472 static_cast<MediaCodecVideoDecoderFactory*>
1552 (owned_factory->decoder_factory()); 1473 (owned_factory->decoder_factory());
1553 if (decoder_factory) { 1474 if (decoder_factory) {
1554 LOG(LS_INFO) << "Set EGL context for HW decoding."; 1475 LOG(LS_INFO) << "Set EGL context for HW decoding.";
1555 decoder_factory->SetEGLContext(jni, remote_egl_context); 1476 DecoderFactorySetEGLContext(decoder_factory, jni, remote_egl_context);
1556 } 1477 }
1557 } 1478 }
1558 1479
1559 static PeerConnectionInterface::IceTransportsType 1480 static PeerConnectionInterface::IceTransportsType
1560 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) { 1481 JavaIceTransportsTypeToNativeType(JNIEnv* jni, jobject j_ice_transports_type) {
1561 std::string enum_name = GetJavaEnumName( 1482 std::string enum_name = GetJavaEnumName(
1562 jni, "org/webrtc/PeerConnection$IceTransportsType", 1483 jni, "org/webrtc/PeerConnection$IceTransportsType",
1563 j_ice_transports_type); 1484 j_ice_transports_type);
1564 1485
1565 if (enum_name == "ALL") 1486 if (enum_name == "ALL")
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 ExtractNativePC(jni, j_pc)->Close(); 2101 ExtractNativePC(jni, j_pc)->Close();
2181 return; 2102 return;
2182 } 2103 }
2183 2104
2184 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) { 2105 JOW(jobject, MediaSource_nativeState)(JNIEnv* jni, jclass, jlong j_p) {
2185 rtc::scoped_refptr<MediaSourceInterface> p( 2106 rtc::scoped_refptr<MediaSourceInterface> p(
2186 reinterpret_cast<MediaSourceInterface*>(j_p)); 2107 reinterpret_cast<MediaSourceInterface*>(j_p));
2187 return JavaEnumFromIndex(jni, "MediaSource$State", p->state()); 2108 return JavaEnumFromIndex(jni, "MediaSource$State", p->state());
2188 } 2109 }
2189 2110
2190 JOW(jlong, VideoRenderer_nativeWrapVideoRenderer)(
2191 JNIEnv* jni, jclass, jobject j_callbacks) {
2192 std::unique_ptr<JavaVideoRendererWrapper> renderer(
2193 new JavaVideoRendererWrapper(jni, j_callbacks));
2194 return (jlong)renderer.release();
2195 }
2196
2197 JOW(void, VideoRenderer_nativeCopyPlane)(
2198 JNIEnv *jni, jclass, jobject j_src_buffer, jint width, jint height,
2199 jint src_stride, jobject j_dst_buffer, jint dst_stride) {
2200 size_t src_size = jni->GetDirectBufferCapacity(j_src_buffer);
2201 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer);
2202 RTC_CHECK(src_stride >= width) << "Wrong source stride " << src_stride;
2203 RTC_CHECK(dst_stride >= width) << "Wrong destination stride " << dst_stride;
2204 RTC_CHECK(src_size >= src_stride * height)
2205 << "Insufficient source buffer capacity " << src_size;
2206 RTC_CHECK(dst_size >= dst_stride * height)
2207 << "Insufficient destination buffer capacity " << dst_size;
2208 uint8_t *src =
2209 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer));
2210 uint8_t *dst =
2211 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer));
2212 if (src_stride == dst_stride) {
2213 memcpy(dst, src, src_stride * height);
2214 } else {
2215 for (int i = 0; i < height; i++) {
2216 memcpy(dst, src, width);
2217 src += src_stride;
2218 dst += dst_stride;
2219 }
2220 }
2221 }
2222
2223 JOW(void, FileVideoCapturer_nativeI420ToNV21)( 2111 JOW(void, FileVideoCapturer_nativeI420ToNV21)(
2224 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height, 2112 JNIEnv *jni, jclass, jbyteArray j_src_buffer, jint width, jint height,
2225 jbyteArray j_dst_buffer) { 2113 jbyteArray j_dst_buffer) {
2226 size_t src_size = jni->GetArrayLength(j_src_buffer); 2114 size_t src_size = jni->GetArrayLength(j_src_buffer);
2227 size_t dst_size = jni->GetArrayLength(j_dst_buffer); 2115 size_t dst_size = jni->GetArrayLength(j_dst_buffer);
2228 int src_stride = width; 2116 int src_stride = width;
2229 int dst_stride = width; 2117 int dst_stride = width;
2230 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2); 2118 RTC_CHECK_GE(src_size, src_stride * height * 3 / 2);
2231 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2); 2119 RTC_CHECK_GE(dst_size, dst_stride * height * 3 / 2);
2232 2120
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
2744 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer) 2632 return reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)
2745 ->inter_tone_gap(); 2633 ->inter_tone_gap();
2746 } 2634 }
2747 2635
2748 JOW(void, DtmfSender_free) 2636 JOW(void, DtmfSender_free)
2749 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) { 2637 (JNIEnv* jni, jclass, jlong j_dtmf_sender_pointer) {
2750 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release(); 2638 reinterpret_cast<DtmfSenderInterface*>(j_dtmf_sender_pointer)->Release();
2751 } 2639 }
2752 2640
2753 } // namespace webrtc_jni 2641 } // namespace webrtc_jni
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698