diff --git a/modules/audio_device/android/audio_manager.h b/modules/audio_device/android/audio_manager.h index d2d0eb623b..685603d8c8 100644 --- a/modules/audio_device/android/audio_manager.h +++ b/modules/audio_device/android/audio_manager.h @@ -162,9 +162,10 @@ class AudioManager { // other methods are called from the same thread. rtc::ThreadChecker thread_checker_; - // Calls AttachCurrentThread() if this thread is not attached at construction. + // Calls JavaVM::AttachCurrentThread() if this thread is not attached at + // construction. // Also ensures that DetachCurrentThread() is called at destruction. - AttachCurrentThreadIfNeeded attach_thread_if_needed_; + JvmThreadConnector attach_thread_if_needed_; // Wraps the JNI interface pointer and methods associated with it. std::unique_ptr j_environment_; diff --git a/modules/audio_device/android/audio_record_jni.h b/modules/audio_device/android/audio_record_jni.h index a700a51b2b..28c8fc466d 100644 --- a/modules/audio_device/android/audio_record_jni.h +++ b/modules/audio_device/android/audio_record_jni.h @@ -39,7 +39,7 @@ namespace webrtc { // All public methods must also be called on the same thread. A thread checker // will RTC_DCHECK if any method is called on an invalid thread. // -// This class uses AttachCurrentThreadIfNeeded to attach to a Java VM if needed +// This class uses JvmThreadConnector to attach to a Java VM if needed // and detach when the object goes out of scope. Additional thread checking // guarantees that no other (possibly non attached) thread is used. class AudioRecordJni { @@ -116,9 +116,10 @@ class AudioRecordJni { // thread in Java. Detached during construction of this object. rtc::ThreadChecker thread_checker_java_; - // Calls AttachCurrentThread() if this thread is not attached at construction. + // Calls JavaVM::AttachCurrentThread() if this thread is not attached at + // construction. // Also ensures that DetachCurrentThread() is called at destruction. - AttachCurrentThreadIfNeeded attach_thread_if_needed_; + JvmThreadConnector attach_thread_if_needed_; // Wraps the JNI interface pointer and methods associated with it. std::unique_ptr j_environment_; diff --git a/modules/audio_device/android/audio_track_jni.h b/modules/audio_device/android/audio_track_jni.h index 469aa82bbd..ccbdbe2794 100644 --- a/modules/audio_device/android/audio_track_jni.h +++ b/modules/audio_device/android/audio_track_jni.h @@ -35,7 +35,7 @@ namespace webrtc { // All public methods must also be called on the same thread. A thread checker // will RTC_DCHECK if any method is called on an invalid thread. // -// This class uses AttachCurrentThreadIfNeeded to attach to a Java VM if needed +// This class uses JvmThreadConnector to attach to a Java VM if needed // and detach when the object goes out of scope. Additional thread checking // guarantees that no other (possibly non attached) thread is used. class AudioTrackJni { @@ -114,9 +114,10 @@ class AudioTrackJni { // thread in Java. Detached during construction of this object. rtc::ThreadChecker thread_checker_java_; - // Calls AttachCurrentThread() if this thread is not attached at construction. + // Calls JavaVM::AttachCurrentThread() if this thread is not attached at + // construction. // Also ensures that DetachCurrentThread() is called at destruction. - AttachCurrentThreadIfNeeded attach_thread_if_needed_; + JvmThreadConnector attach_thread_if_needed_; // Wraps the JNI interface pointer and methods associated with it. std::unique_ptr j_environment_; diff --git a/modules/audio_device/android/build_info.h b/modules/audio_device/android/build_info.h index 2e292e8f08..7cdf19271f 100644 --- a/modules/audio_device/android/build_info.h +++ b/modules/audio_device/android/build_info.h @@ -69,7 +69,7 @@ class BuildInfo { // Ensures that this class can access a valid JNI interface pointer even // if the creating thread was not attached to the JVM. - AttachCurrentThreadIfNeeded attach_thread_if_needed_; + JvmThreadConnector attach_thread_if_needed_; // Provides access to the JNIEnv interface pointer and the JavaToStdString() // method which is used to translate Java strings to std strings. diff --git a/modules/utility/include/jvm_android.h b/modules/utility/include/jvm_android.h index eb18cc27f3..3caab87761 100644 --- a/modules/utility/include/jvm_android.h +++ b/modules/utility/include/jvm_android.h @@ -21,15 +21,17 @@ namespace webrtc { +// RAII JavaVM AttachCurrentThread/DetachCurrentThread object. +// // The JNI interface pointer (JNIEnv) is valid only in the current thread. // Should another thread need to access the Java VM, it must first call // AttachCurrentThread() to attach itself to the VM and obtain a JNI interface // pointer. The native thread remains attached to the VM until it calls // DetachCurrentThread() to detach. -class AttachCurrentThreadIfNeeded { +class JvmThreadConnector { public: - AttachCurrentThreadIfNeeded(); - ~AttachCurrentThreadIfNeeded(); + JvmThreadConnector(); + ~JvmThreadConnector(); private: rtc::ThreadChecker thread_checker_; diff --git a/modules/utility/source/jvm_android.cc b/modules/utility/source/jvm_android.cc index 2d48c2d7be..c861c433a2 100644 --- a/modules/utility/source/jvm_android.cc +++ b/modules/utility/source/jvm_android.cc @@ -67,9 +67,9 @@ jclass LookUpClass(const char* name) { return 0; } -// AttachCurrentThreadIfNeeded implementation. -AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded() : attached_(false) { - RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::ctor"; +// JvmThreadConnector implementation. +JvmThreadConnector::JvmThreadConnector() : attached_(false) { + RTC_LOG(INFO) << "JvmThreadConnector::ctor"; JavaVM* jvm = JVM::GetInstance()->jvm(); RTC_CHECK(jvm); JNIEnv* jni = GetEnv(jvm); @@ -81,8 +81,8 @@ AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded() : attached_(false) { } } -AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() { - RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::dtor"; +JvmThreadConnector::~JvmThreadConnector() { + RTC_LOG(INFO) << "JvmThreadConnector::dtor"; RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (attached_) { RTC_LOG(INFO) << "Detaching thread from JVM";