Call VideoCapturer.initialize directly from Java.

Passing the call through JNI is unnecessary.

Bug: webrtc:7730
Change-Id: Icf1ecd7e2ea54033342120311c70d47b4a4f7c9a
Reviewed-on: https://chromium-review.googlesource.com/521050
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#18408}
This commit is contained in:
Sami Kalliomäki
2017-06-02 09:51:39 +02:00
committed by Commit Bot
parent dbb497af84
commit 58c742ce7d
4 changed files with 24 additions and 51 deletions

View File

@ -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<webrtc_jni::SurfaceTextureHelper>(
jni,
j_surface_texture_helper)),
is_screencast_(is_screencast) {
LOG(LS_INFO) << "AndroidVideoTrackSource ctor";
camera_thread_checker_.DetachFromThread();

View File

@ -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_; }

View File

@ -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<OwnedFactoryAndThreads*>(native_factory);
rtc::scoped_refptr<webrtc::AndroidVideoTrackSource> source(
new rtc::RefCountedObject<webrtc::AndroidVideoTrackSource>(
factory->signaling_thread(), jni, j_egl_context, is_screencast));
factory->signaling_thread(), jni, j_surface_texture_helper,
is_screencast));
rtc::scoped_refptr<webrtc::VideoTrackSourceProxy> 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<PeerConnectionFactoryInterface> factory(
factoryFromJava(native_factory));
auto proxy_source =
reinterpret_cast<webrtc::VideoTrackSourceProxy*>(native_source);
auto source = reinterpret_cast<webrtc::AndroidVideoTrackSource*>(
proxy_source->internal());
rtc::scoped_refptr<SurfaceTextureHelper> 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) {