Adds usage of RTC_LOG macros in code for Android

Bug: webrtc:8710
Change-Id: Ifeedc51ef7d4998278b9583d9530f8f2bdc8f3a2
Reviewed-on: https://webrtc-review.googlesource.com/39266
Commit-Queue: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21678}
This commit is contained in:
henrika 2018-01-12 14:35:07 +01:00 committed by Commit Bot
parent dde8702f11
commit 53e048d83a
2 changed files with 56 additions and 67 deletions

View file

@ -12,21 +12,13 @@
#include <utility> #include <utility>
#include <android/log.h>
#include "modules/audio_device/android/audio_common.h" #include "modules/audio_device/android/audio_common.h"
#include "modules/utility/include/helpers_android.h" #include "modules/utility/include/helpers_android.h"
#include "rtc_base/arraysize.h" #include "rtc_base/arraysize.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#define TAG "AudioManager"
#define ALOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
#define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__)
#define ALOGI(...) __android_log_print(ANDROID_LOG_INFO, TAG, __VA_ARGS__)
namespace webrtc { namespace webrtc {
// AudioManager::JavaAudioManager implementation // AudioManager::JavaAudioManager implementation
@ -41,11 +33,11 @@ AudioManager::JavaAudioManager::JavaAudioManager(
is_device_blacklisted_for_open_sles_usage_( is_device_blacklisted_for_open_sles_usage_(
native_reg->GetMethodId("isDeviceBlacklistedForOpenSLESUsage", native_reg->GetMethodId("isDeviceBlacklistedForOpenSLESUsage",
"()Z")) { "()Z")) {
ALOGD("JavaAudioManager::ctor @[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JavaAudioManager::ctor";
} }
AudioManager::JavaAudioManager::~JavaAudioManager() { AudioManager::JavaAudioManager::~JavaAudioManager() {
ALOGD("JavaAudioManager::dtor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JavaAudioManager::~dtor";
} }
bool AudioManager::JavaAudioManager::Init() { bool AudioManager::JavaAudioManager::Init() {
@ -76,7 +68,7 @@ AudioManager::AudioManager()
low_latency_playout_(false), low_latency_playout_(false),
low_latency_record_(false), low_latency_record_(false),
delay_estimate_in_milliseconds_(0) { delay_estimate_in_milliseconds_(0) {
ALOGD("ctor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "ctor";
RTC_CHECK(j_environment_); RTC_CHECK(j_environment_);
JNINativeMethod native_methods[] = { JNINativeMethod native_methods[] = {
{"nativeCacheAudioParameters", "(IIIZZZZZZIIJ)V", {"nativeCacheAudioParameters", "(IIIZZZZZZIIJ)V",
@ -91,14 +83,14 @@ AudioManager::AudioManager()
} }
AudioManager::~AudioManager() { AudioManager::~AudioManager() {
ALOGD("~dtor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
Close(); Close();
} }
void AudioManager::SetActiveAudioLayer( void AudioManager::SetActiveAudioLayer(
AudioDeviceModule::AudioLayer audio_layer) { AudioDeviceModule::AudioLayer audio_layer) {
ALOGD("SetActiveAudioLayer(%d)[tid=%d]", audio_layer, rtc::CurrentThreadId()); RTC_LOG(INFO) << "SetActiveAudioLayer: " << audio_layer;
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(!initialized_); RTC_DCHECK(!initialized_);
// Store the currently utilized audio layer. // Store the currently utilized audio layer.
@ -111,25 +103,27 @@ void AudioManager::SetActiveAudioLayer(
(audio_layer == AudioDeviceModule::kAndroidJavaAudio) (audio_layer == AudioDeviceModule::kAndroidJavaAudio)
? kHighLatencyModeDelayEstimateInMilliseconds ? kHighLatencyModeDelayEstimateInMilliseconds
: kLowLatencyModeDelayEstimateInMilliseconds; : kLowLatencyModeDelayEstimateInMilliseconds;
ALOGD("delay_estimate_in_milliseconds: %d", delay_estimate_in_milliseconds_); RTC_LOG(INFO) << "delay_estimate_in_milliseconds: "
<< delay_estimate_in_milliseconds_;
} }
SLObjectItf AudioManager::GetOpenSLEngine() { SLObjectItf AudioManager::GetOpenSLEngine() {
ALOGD("GetOpenSLEngine[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "GetOpenSLEngine";
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
// Only allow usage of OpenSL ES if such an audio layer has been specified. // Only allow usage of OpenSL ES if such an audio layer has been specified.
if (audio_layer_ != AudioDeviceModule::kAndroidOpenSLESAudio && if (audio_layer_ != AudioDeviceModule::kAndroidOpenSLESAudio &&
audio_layer_ != audio_layer_ !=
AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio) { AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio) {
ALOGI("Unable to create OpenSL engine for the current audio layer: %d", RTC_LOG(INFO)
audio_layer_); << "Unable to create OpenSL engine for the current audio layer: "
<< audio_layer_;
return nullptr; return nullptr;
} }
// OpenSL ES for Android only supports a single engine per application. // OpenSL ES for Android only supports a single engine per application.
// If one already has been created, return existing object instead of // If one already has been created, return existing object instead of
// creating a new. // creating a new.
if (engine_object_.Get() != nullptr) { if (engine_object_.Get() != nullptr) {
ALOGI("The OpenSL ES engine object has already been created"); RTC_LOG(WARNING) << "The OpenSL ES engine object has already been created";
return engine_object_.Get(); return engine_object_.Get();
} }
// Create the engine object in thread safe mode. // Create the engine object in thread safe mode.
@ -138,14 +132,15 @@ SLObjectItf AudioManager::GetOpenSLEngine() {
SLresult result = SLresult result =
slCreateEngine(engine_object_.Receive(), 1, option, 0, NULL, NULL); slCreateEngine(engine_object_.Receive(), 1, option, 0, NULL, NULL);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS) {
ALOGE("slCreateEngine() failed: %s", GetSLErrorString(result)); RTC_LOG(LS_ERROR) << "slCreateEngine() failed: "
<< GetSLErrorString(result);
engine_object_.Reset(); engine_object_.Reset();
return nullptr; return nullptr;
} }
// Realize the SL Engine in synchronous mode. // Realize the SL Engine in synchronous mode.
result = engine_object_->Realize(engine_object_.Get(), SL_BOOLEAN_FALSE); result = engine_object_->Realize(engine_object_.Get(), SL_BOOLEAN_FALSE);
if (result != SL_RESULT_SUCCESS) { if (result != SL_RESULT_SUCCESS) {
ALOGE("Realize() failed: %s", GetSLErrorString(result)); RTC_LOG(LS_ERROR) << "Realize() failed: " << GetSLErrorString(result);
engine_object_.Reset(); engine_object_.Reset();
return nullptr; return nullptr;
} }
@ -154,12 +149,12 @@ SLObjectItf AudioManager::GetOpenSLEngine() {
} }
bool AudioManager::Init() { bool AudioManager::Init() {
ALOGD("Init[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "Init";
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(!initialized_); RTC_DCHECK(!initialized_);
RTC_DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio); RTC_DCHECK_NE(audio_layer_, AudioDeviceModule::kPlatformDefaultAudio);
if (!j_audio_manager_->Init()) { if (!j_audio_manager_->Init()) {
ALOGE("init failed!"); RTC_LOG(LS_ERROR) << "Init() failed";
return false; return false;
} }
initialized_ = true; initialized_ = true;
@ -167,7 +162,7 @@ bool AudioManager::Init() {
} }
bool AudioManager::Close() { bool AudioManager::Close() {
ALOGD("Close[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "Close";
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
if (!initialized_) if (!initialized_)
return true; return true;
@ -177,7 +172,6 @@ bool AudioManager::Close() {
} }
bool AudioManager::IsCommunicationModeEnabled() const { bool AudioManager::IsCommunicationModeEnabled() const {
ALOGD("IsCommunicationModeEnabled()");
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
return j_audio_manager_->IsCommunicationModeEnabled(); return j_audio_manager_->IsCommunicationModeEnabled();
} }
@ -199,7 +193,6 @@ bool AudioManager::IsNoiseSuppressorSupported() const {
bool AudioManager::IsLowLatencyPlayoutSupported() const { bool AudioManager::IsLowLatencyPlayoutSupported() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
ALOGD("IsLowLatencyPlayoutSupported()");
// Some devices are blacklisted for usage of OpenSL ES even if they report // Some devices are blacklisted for usage of OpenSL ES even if they report
// that low-latency playout is supported. See b/21485703 for details. // that low-latency playout is supported. See b/21485703 for details.
return j_audio_manager_->IsDeviceBlacklistedForOpenSLESUsage() return j_audio_manager_->IsDeviceBlacklistedForOpenSLESUsage()
@ -209,13 +202,11 @@ bool AudioManager::IsLowLatencyPlayoutSupported() const {
bool AudioManager::IsLowLatencyRecordSupported() const { bool AudioManager::IsLowLatencyRecordSupported() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
ALOGD("IsLowLatencyRecordSupported()");
return low_latency_record_; return low_latency_record_;
} }
bool AudioManager::IsProAudioSupported() const { bool AudioManager::IsProAudioSupported() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
ALOGD("IsProAudioSupported()");
// TODO(henrika): return the state independently of if OpenSL ES is // TODO(henrika): return the state independently of if OpenSL ES is
// blacklisted or not for now. We could use the same approach as in // blacklisted or not for now. We could use the same approach as in
// IsLowLatencyPlayoutSupported() but I can't see the need for it yet. // IsLowLatencyPlayoutSupported() but I can't see the need for it yet.
@ -224,13 +215,11 @@ bool AudioManager::IsProAudioSupported() const {
bool AudioManager::IsStereoPlayoutSupported() const { bool AudioManager::IsStereoPlayoutSupported() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
ALOGD("IsStereoPlayoutSupported()");
return (playout_parameters_.channels() == 2); return (playout_parameters_.channels() == 2);
} }
bool AudioManager::IsStereoRecordSupported() const { bool AudioManager::IsStereoRecordSupported() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
ALOGD("IsStereoRecordSupported()");
return (record_parameters_.channels() == 2); return (record_parameters_.channels() == 2);
} }
@ -272,18 +261,19 @@ void AudioManager::OnCacheAudioParameters(JNIEnv* env,
jboolean pro_audio, jboolean pro_audio,
jint output_buffer_size, jint output_buffer_size,
jint input_buffer_size) { jint input_buffer_size) {
ALOGD("OnCacheAudioParameters[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO)
ALOGD("hardware_aec: %d", hardware_aec); << "OnCacheAudioParameters: "
ALOGD("hardware_agc: %d", hardware_agc); << "hardware_aec: " << static_cast<bool>(hardware_aec)
ALOGD("hardware_ns: %d", hardware_ns); << ", hardware_agc: " << static_cast<bool>(hardware_agc)
ALOGD("low_latency_output: %d", low_latency_output); << ", hardware_ns: " << static_cast<bool>(hardware_ns)
ALOGD("low_latency_input: %d", low_latency_input); << ", low_latency_output: " << static_cast<bool>(low_latency_output)
ALOGD("pro_audio: %d", pro_audio); << ", low_latency_input: " << static_cast<bool>(low_latency_input)
ALOGD("sample_rate: %d", sample_rate); << ", pro_audio: " << static_cast<bool>(pro_audio)
ALOGD("output_channels: %d", output_channels); << ", sample_rate: " << static_cast<int>(sample_rate)
ALOGD("input_channels: %d", input_channels); << ", output_channels: " << static_cast<int>(output_channels)
ALOGD("output_buffer_size: %d", output_buffer_size); << ", input_channels: " << static_cast<int>(input_channels)
ALOGD("input_buffer_size: %d", input_buffer_size); << ", output_buffer_size: " << static_cast<int>(output_buffer_size)
<< ", input_buffer_size: " << static_cast<int>(input_buffer_size);
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
hardware_aec_ = hardware_aec; hardware_aec_ = hardware_aec;
hardware_agc_ = hardware_agc; hardware_agc_ = hardware_agc;

View file

@ -15,12 +15,9 @@
#include "modules/utility/include/jvm_android.h" #include "modules/utility/include/jvm_android.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/platform_thread.h" #include "rtc_base/platform_thread.h"
#define TAG "JVM"
#define ALOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#define ALOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
namespace webrtc { namespace webrtc {
JVM* g_jvm; JVM* g_jvm;
@ -41,10 +38,10 @@ struct {
// stack. Consequently, we only look up all classes once in native WebRTC. // stack. Consequently, we only look up all classes once in native WebRTC.
// http://developer.android.com/training/articles/perf-jni.html#faq_FindClass // http://developer.android.com/training/articles/perf-jni.html#faq_FindClass
void LoadClasses(JNIEnv* jni) { void LoadClasses(JNIEnv* jni) {
ALOGD("LoadClasses"); RTC_LOG(INFO) << "LoadClasses:";
for (auto& c : loaded_classes) { for (auto& c : loaded_classes) {
jclass localRef = FindClass(jni, c.name); jclass localRef = FindClass(jni, c.name);
ALOGD("name: %s", c.name); RTC_LOG(INFO) << "name: " << c.name;
CHECK_EXCEPTION(jni) << "Error during FindClass: " << c.name; CHECK_EXCEPTION(jni) << "Error during FindClass: " << c.name;
RTC_CHECK(localRef) << c.name; RTC_CHECK(localRef) << c.name;
jclass globalRef = reinterpret_cast<jclass>(jni->NewGlobalRef(localRef)); jclass globalRef = reinterpret_cast<jclass>(jni->NewGlobalRef(localRef));
@ -73,12 +70,12 @@ jclass LookUpClass(const char* name) {
// AttachCurrentThreadIfNeeded implementation. // AttachCurrentThreadIfNeeded implementation.
AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded() AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded()
: attached_(false) { : attached_(false) {
ALOGD("AttachCurrentThreadIfNeeded::ctor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::ctor";
JavaVM* jvm = JVM::GetInstance()->jvm(); JavaVM* jvm = JVM::GetInstance()->jvm();
RTC_CHECK(jvm); RTC_CHECK(jvm);
JNIEnv* jni = GetEnv(jvm); JNIEnv* jni = GetEnv(jvm);
if (!jni) { if (!jni) {
ALOGD("Attaching thread to JVM"); RTC_LOG(INFO) << "Attaching thread to JVM";
JNIEnv* env = nullptr; JNIEnv* env = nullptr;
jint ret = jvm->AttachCurrentThread(&env, nullptr); jint ret = jvm->AttachCurrentThread(&env, nullptr);
attached_ = (ret == JNI_OK); attached_ = (ret == JNI_OK);
@ -86,10 +83,10 @@ AttachCurrentThreadIfNeeded::AttachCurrentThreadIfNeeded()
} }
AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() { AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() {
ALOGD("AttachCurrentThreadIfNeeded::dtor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "AttachCurrentThreadIfNeeded::dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
if (attached_) { if (attached_) {
ALOGD("Detaching thread from JVM"); RTC_LOG(INFO) << "Detaching thread from JVM";
jint res = JVM::GetInstance()->jvm()->DetachCurrentThread(); jint res = JVM::GetInstance()->jvm()->DetachCurrentThread();
RTC_CHECK(res == JNI_OK) << "DetachCurrentThread failed: " << res; RTC_CHECK(res == JNI_OK) << "DetachCurrentThread failed: " << res;
} }
@ -98,11 +95,11 @@ AttachCurrentThreadIfNeeded::~AttachCurrentThreadIfNeeded() {
// GlobalRef implementation. // GlobalRef implementation.
GlobalRef::GlobalRef(JNIEnv* jni, jobject object) GlobalRef::GlobalRef(JNIEnv* jni, jobject object)
: jni_(jni), j_object_(NewGlobalRef(jni, object)) { : jni_(jni), j_object_(NewGlobalRef(jni, object)) {
ALOGD("GlobalRef::ctor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "GlobalRef::ctor";
} }
GlobalRef::~GlobalRef() { GlobalRef::~GlobalRef() {
ALOGD("GlobalRef::dtor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "GlobalRef::dtor";
DeleteGlobalRef(jni_, j_object_); DeleteGlobalRef(jni_, j_object_);
} }
@ -135,18 +132,18 @@ void GlobalRef::CallVoidMethod(jmethodID methodID, ...) {
// NativeRegistration implementation. // NativeRegistration implementation.
NativeRegistration::NativeRegistration(JNIEnv* jni, jclass clazz) NativeRegistration::NativeRegistration(JNIEnv* jni, jclass clazz)
: JavaClass(jni, clazz), jni_(jni) { : JavaClass(jni, clazz), jni_(jni) {
ALOGD("NativeRegistration::ctor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "NativeRegistration::ctor";
} }
NativeRegistration::~NativeRegistration() { NativeRegistration::~NativeRegistration() {
ALOGD("NativeRegistration::dtor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "NativeRegistration::dtor";
jni_->UnregisterNatives(j_class_); jni_->UnregisterNatives(j_class_);
CHECK_EXCEPTION(jni_) << "Error during UnregisterNatives"; CHECK_EXCEPTION(jni_) << "Error during UnregisterNatives";
} }
std::unique_ptr<GlobalRef> NativeRegistration::NewObject( std::unique_ptr<GlobalRef> NativeRegistration::NewObject(
const char* name, const char* signature, ...) { const char* name, const char* signature, ...) {
ALOGD("NativeRegistration::NewObject[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "NativeRegistration::NewObject";
va_list args; va_list args;
va_start(args, signature); va_start(args, signature);
jobject obj = jni_->NewObjectV(j_class_, jobject obj = jni_->NewObjectV(j_class_,
@ -186,17 +183,17 @@ jint JavaClass::CallStaticIntMethod(jmethodID methodID, ...) {
// JNIEnvironment implementation. // JNIEnvironment implementation.
JNIEnvironment::JNIEnvironment(JNIEnv* jni) : jni_(jni) { JNIEnvironment::JNIEnvironment(JNIEnv* jni) : jni_(jni) {
ALOGD("JNIEnvironment::ctor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JNIEnvironment::ctor";
} }
JNIEnvironment::~JNIEnvironment() { JNIEnvironment::~JNIEnvironment() {
ALOGD("JNIEnvironment::dtor[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JNIEnvironment::dtor";
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
} }
std::unique_ptr<NativeRegistration> JNIEnvironment::RegisterNatives( std::unique_ptr<NativeRegistration> JNIEnvironment::RegisterNatives(
const char* name, const JNINativeMethod *methods, int num_methods) { const char* name, const JNINativeMethod *methods, int num_methods) {
ALOGD("JNIEnvironment::RegisterNatives(%s)", name); RTC_LOG(INFO) << "JNIEnvironment::RegisterNatives: " << name;
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
jclass clazz = LookUpClass(name); jclass clazz = LookUpClass(name);
jni_->RegisterNatives(clazz, methods, num_methods); jni_->RegisterNatives(clazz, methods, num_methods);
@ -219,7 +216,7 @@ std::string JNIEnvironment::JavaToStdString(const jstring& j_string) {
// static // static
void JVM::Initialize(JavaVM* jvm) { void JVM::Initialize(JavaVM* jvm) {
ALOGD("JVM::Initialize[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JVM::Initialize";
RTC_CHECK(!g_jvm); RTC_CHECK(!g_jvm);
g_jvm = new JVM(jvm); g_jvm = new JVM(jvm);
} }
@ -237,7 +234,7 @@ void JVM::Initialize(JavaVM* jvm, jobject context) {
// static // static
void JVM::Uninitialize() { void JVM::Uninitialize() {
ALOGD("JVM::Uninitialize[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JVM::Uninitialize";
RTC_DCHECK(g_jvm); RTC_DCHECK(g_jvm);
delete g_jvm; delete g_jvm;
g_jvm = nullptr; g_jvm = nullptr;
@ -250,19 +247,20 @@ JVM* JVM::GetInstance() {
} }
JVM::JVM(JavaVM* jvm) : jvm_(jvm) { JVM::JVM(JavaVM* jvm) : jvm_(jvm) {
ALOGD("JVM::JVM[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JVM::JVM";
RTC_CHECK(jni()) << "AttachCurrentThread() must be called on this thread."; RTC_CHECK(jni()) << "AttachCurrentThread() must be called on this thread.";
LoadClasses(jni()); LoadClasses(jni());
} }
JVM::~JVM() { JVM::~JVM() {
ALOGD("JVM::~JVM[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JVM::~JVM";
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
FreeClassReferences(jni()); FreeClassReferences(jni());
} }
std::unique_ptr<JNIEnvironment> JVM::environment() { std::unique_ptr<JNIEnvironment> JVM::environment() {
ALOGD("JVM::environment[tid=%d]", rtc::CurrentThreadId()); RTC_LOG(INFO) << "JVM::environment";
;
// The JNIEnv is used for thread-local storage. For this reason, we cannot // The JNIEnv is used for thread-local storage. For this reason, we cannot
// share a JNIEnv between threads. If a piece of code has no other way to get // share a JNIEnv between threads. If a piece of code has no other way to get
// its JNIEnv, we should share the JavaVM, and use GetEnv to discover the // its JNIEnv, we should share the JavaVM, and use GetEnv to discover the
@ -270,14 +268,15 @@ std::unique_ptr<JNIEnvironment> JVM::environment() {
// See // http://developer.android.com/training/articles/perf-jni.html. // See // http://developer.android.com/training/articles/perf-jni.html.
JNIEnv* jni = GetEnv(jvm_); JNIEnv* jni = GetEnv(jvm_);
if (!jni) { if (!jni) {
ALOGE("AttachCurrentThread() has not been called on this thread."); RTC_LOG(LS_ERROR)
<< "AttachCurrentThread() has not been called on this thread";
return std::unique_ptr<JNIEnvironment>(); return std::unique_ptr<JNIEnvironment>();
} }
return std::unique_ptr<JNIEnvironment>(new JNIEnvironment(jni)); return std::unique_ptr<JNIEnvironment>(new JNIEnvironment(jni));
} }
JavaClass JVM::GetClass(const char* name) { JavaClass JVM::GetClass(const char* name) {
ALOGD("JVM::GetClass(%s)[tid=%d]", name, rtc::CurrentThreadId()); RTC_LOG(INFO) << "JVM::GetClass: " << name;
RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(thread_checker_.CalledOnValidThread());
return JavaClass(jni(), LookUpClass(name)); return JavaClass(jni(), LookUpClass(name));
} }