diff --git a/webrtc/sdk/android/api/org/webrtc/PeerConnectionFactory.java b/webrtc/sdk/android/api/org/webrtc/PeerConnectionFactory.java index b7d85f04e3..b70aab045e 100644 --- a/webrtc/sdk/android/api/org/webrtc/PeerConnectionFactory.java +++ b/webrtc/sdk/android/api/org/webrtc/PeerConnectionFactory.java @@ -30,6 +30,7 @@ public class PeerConnectionFactory { } private static final String TAG = "PeerConnectionFactory"; + private static final String VIDEO_CAPTURER_THREAD_NAME = "VideoCapturerThread"; private final long nativeFactory; private static Context applicationContext; private static Thread networkThread; @@ -135,12 +136,14 @@ public class PeerConnectionFactory { public VideoSource createVideoSource(VideoCapturer capturer) { final EglBase.Context eglContext = localEglbase == null ? null : localEglbase.getEglBaseContext(); + final SurfaceTextureHelper surfaceTextureHelper = + SurfaceTextureHelper.create(VIDEO_CAPTURER_THREAD_NAME, eglContext); long nativeAndroidVideoTrackSource = - nativeCreateVideoSource(nativeFactory, eglContext, capturer.isScreencast()); + nativeCreateVideoSource(nativeFactory, surfaceTextureHelper, capturer.isScreencast()); VideoCapturer.CapturerObserver capturerObserver = new AndroidVideoTrackSourceObserver(nativeAndroidVideoTrackSource); - nativeInitializeVideoCapturer( - nativeFactory, capturer, nativeAndroidVideoTrackSource, capturerObserver); + capturer.initialize( + surfaceTextureHelper, ContextUtils.getApplicationContext(), capturerObserver); return new VideoSource(nativeAndroidVideoTrackSource); } @@ -254,11 +257,7 @@ public class PeerConnectionFactory { private static native long nativeCreateLocalMediaStream(long nativeFactory, String label); private static native long nativeCreateVideoSource( - long nativeFactory, EglBase.Context eglContext, boolean is_screencast); - - private static native void nativeInitializeVideoCapturer(long native_factory, - VideoCapturer j_video_capturer, long native_source, - VideoCapturer.CapturerObserver j_frame_observer); + long nativeFactory, SurfaceTextureHelper surfaceTextureHelper, boolean is_screencast); private static native long nativeCreateVideoTrack( long nativeFactory, String id, long nativeVideoSource); diff --git a/webrtc/sdk/android/src/jni/androidvideotracksource.cc b/webrtc/sdk/android/src/jni/androidvideotracksource.cc index 1a4a276ae2..d4f59bbf55 100644 --- a/webrtc/sdk/android/src/jni/androidvideotracksource.cc +++ b/webrtc/sdk/android/src/jni/androidvideotracksource.cc @@ -19,16 +19,17 @@ const int kRequiredResolutionAlignment = 2; namespace webrtc { -AndroidVideoTrackSource::AndroidVideoTrackSource(rtc::Thread* signaling_thread, - JNIEnv* jni, - jobject j_egl_context, - bool is_screencast) +AndroidVideoTrackSource::AndroidVideoTrackSource( + rtc::Thread* signaling_thread, + JNIEnv* jni, + jobject j_surface_texture_helper, + bool is_screencast) : AdaptedVideoTrackSource(kRequiredResolutionAlignment), signaling_thread_(signaling_thread), - surface_texture_helper_(webrtc_jni::SurfaceTextureHelper::create( - jni, - "Camera SurfaceTextureHelper", - j_egl_context)), + surface_texture_helper_( + new rtc::RefCountedObject( + jni, + j_surface_texture_helper)), is_screencast_(is_screencast) { LOG(LS_INFO) << "AndroidVideoTrackSource ctor"; camera_thread_checker_.DetachFromThread(); diff --git a/webrtc/sdk/android/src/jni/androidvideotracksource.h b/webrtc/sdk/android/src/jni/androidvideotracksource.h index ae34c8d563..b68a1d51b4 100644 --- a/webrtc/sdk/android/src/jni/androidvideotracksource.h +++ b/webrtc/sdk/android/src/jni/androidvideotracksource.h @@ -27,7 +27,7 @@ class AndroidVideoTrackSource : public rtc::AdaptedVideoTrackSource { public: AndroidVideoTrackSource(rtc::Thread* signaling_thread, JNIEnv* jni, - jobject j_egl_context, + jobject j_surface_texture_helper, bool is_screencast = false); bool is_screencast() const override { return is_screencast_; } diff --git a/webrtc/sdk/android/src/jni/peerconnection_jni.cc b/webrtc/sdk/android/src/jni/peerconnection_jni.cc index 55230bd63a..adcdb55e49 100644 --- a/webrtc/sdk/android/src/jni/peerconnection_jni.cc +++ b/webrtc/sdk/android/src/jni/peerconnection_jni.cc @@ -126,7 +126,6 @@ static char *field_trials_init_string = NULL; // Set in PeerConnectionFactory_initializeAndroidGlobals(). static bool factory_static_initialized = false; static bool video_hw_acceleration_enabled = true; -static jobject j_application_context = nullptr; // Return the (singleton) Java Enum object corresponding to |index|; // |state_class_fragment| is something like "MediaSource$State". @@ -1146,8 +1145,6 @@ JOW(void, PeerConnectionFactory_nativeInitializeAndroidGlobals) jboolean video_hw_acceleration) { video_hw_acceleration_enabled = video_hw_acceleration; if (!factory_static_initialized) { - RTC_DCHECK(j_application_context == nullptr); - j_application_context = NewGlobalRef(jni, context); webrtc::JVM::Initialize(GetJVM()); factory_static_initialized = true; } @@ -1416,14 +1413,18 @@ JOW(jlong, PeerConnectionFactory_nativeCreateLocalMediaStream)( } JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) -(JNIEnv* jni, jclass, jlong native_factory, jobject j_egl_context, - jboolean is_screencast) { +(JNIEnv* jni, + jclass, + jlong native_factory, + jobject j_surface_texture_helper, + jboolean is_screencast) { OwnedFactoryAndThreads* factory = reinterpret_cast(native_factory); rtc::scoped_refptr source( new rtc::RefCountedObject( - factory->signaling_thread(), jni, j_egl_context, is_screencast)); + factory->signaling_thread(), jni, j_surface_texture_helper, + is_screencast)); rtc::scoped_refptr proxy_source = webrtc::VideoTrackSourceProxy::Create(factory->signaling_thread(), factory->worker_thread(), source); @@ -1431,34 +1432,6 @@ JOW(jlong, PeerConnectionFactory_nativeCreateVideoSource) return (jlong)proxy_source.release(); } -JOW(void, PeerConnectionFactory_nativeInitializeVideoCapturer) -(JNIEnv* jni, - jclass, - jlong native_factory, - jobject j_video_capturer, - jlong native_source, - jobject j_frame_observer) { - LOG(LS_INFO) << "PeerConnectionFactory_nativeInitializeVideoCapturer"; - rtc::scoped_refptr factory( - factoryFromJava(native_factory)); - auto proxy_source = - reinterpret_cast(native_source); - auto source = reinterpret_cast( - proxy_source->internal()); - rtc::scoped_refptr surface_texture_helper = - source->surface_texture_helper(); - jni->CallVoidMethod( - j_video_capturer, - GetMethodID(jni, FindClass(jni, "org/webrtc/VideoCapturer"), "initialize", - "(Lorg/webrtc/SurfaceTextureHelper;Landroid/content/" - "Context;Lorg/webrtc/VideoCapturer$CapturerObserver;)V"), - surface_texture_helper - ? surface_texture_helper->GetJavaSurfaceTextureHelper() - : nullptr, - j_application_context, j_frame_observer); - CHECK_EXCEPTION(jni) << "error during VideoCapturer.initialize()"; -} - JOW(jlong, PeerConnectionFactory_nativeCreateVideoTrack)( JNIEnv* jni, jclass, jlong native_factory, jstring id, jlong native_source) {