Index: media/audio/audio_manager_base.cc |
=================================================================== |
--- media/audio/audio_manager_base.cc (revision 187380) |
+++ media/audio/audio_manager_base.cc (working copy) |
@@ -9,6 +9,9 @@ |
#include "base/command_line.h" |
#include "base/message_loop_proxy.h" |
#include "base/threading/thread.h" |
+#if defined(OS_ANDROID) |
+#include "jni/AudioManagerAndroid_jni.h" |
+#endif |
#include "media/audio/audio_output_dispatcher_impl.h" |
#include "media/audio/audio_output_proxy.h" |
#include "media/audio/audio_output_resampler.h" |
@@ -31,6 +34,11 @@ |
static const int kMaxInputChannels = 2; |
+#if defined(OS_ANDROID) |
+static const int kAudioModeNormal = 0x00000000; |
+static const int kAudioModeInCommunication = 0x00000003; |
+#endif |
+ |
const char AudioManagerBase::kDefaultDeviceName[] = "Default"; |
const char AudioManagerBase::kDefaultDeviceId[] = "default"; |
@@ -161,6 +169,11 @@ |
if (stream) |
++num_input_streams_; |
+#if defined(OS_ANDROID) |
+ if (num_input_streams_ == 1) |
+ SetAudioMode(kAudioModeInCommunication); |
+#endif |
+ |
return stream; |
} |
@@ -250,6 +263,10 @@ |
// TODO(xians) : Have a clearer destruction path for the AudioInputStream. |
--num_input_streams_; |
delete stream; |
+#if defined(OS_ANDROID) |
+ if (!num_input_streams_) |
+ SetAudioMode(kAudioModeNormal); |
+#endif |
} |
void AudioManagerBase::IncreaseActiveInputStreamCount() { |
@@ -317,6 +334,13 @@ |
#endif // defined(OS_IOS) |
} |
+#if defined(OS_ANDROID) |
+// static |
+bool AudioManagerBase::RegisterAudioManager(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+#endif |
+ |
void AudioManagerBase::AddOutputDeviceChangeListener( |
AudioDeviceListener* listener) { |
DCHECK(message_loop_->BelongsToCurrentThread()); |
@@ -345,4 +369,14 @@ |
return AudioParameters(); |
} |
+#if defined(OS_ANDROID) |
+void AudioManagerBase::SetAudioMode(int mode) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ jobject context = base::android::GetApplicationContext(); |
+ DCHECK(context); |
+ |
+ Java_AudioManagerAndroid_setMode(env, context, mode); |
+} |
+#endif |
+ |
} // namespace media |