| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/audio/android/audio_manager_android.h" | 5 #include "media/audio/android/audio_manager_android.h" |
| 6 | 6 |
| 7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
| 8 #include "base/android/context_utils.h" | 8 #include "base/android/context_utils.h" |
| 9 #include "base/android/jni_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 AudioManagerAndroid::~AudioManagerAndroid() { | 71 AudioManagerAndroid::~AudioManagerAndroid() { |
| 72 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 72 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 73 Shutdown(); | 73 Shutdown(); |
| 74 | 74 |
| 75 if (j_audio_manager_.is_null()) | 75 if (j_audio_manager_.is_null()) |
| 76 return; | 76 return; |
| 77 DVLOG(2) << "Destroying Java part of the audio manager"; | 77 DVLOG(2) << "Destroying Java part of the audio manager"; |
| 78 Java_AudioManagerAndroid_close(base::android::AttachCurrentThread(), | 78 Java_AudioManagerAndroid_close(base::android::AttachCurrentThread(), |
| 79 j_audio_manager_.obj()); | 79 j_audio_manager_); |
| 80 j_audio_manager_.Reset(); | 80 j_audio_manager_.Reset(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void AudioManagerAndroid::InitializeIfNeeded() { | 83 void AudioManagerAndroid::InitializeIfNeeded() { |
| 84 GetTaskRunner()->PostTask( | 84 GetTaskRunner()->PostTask( |
| 85 FROM_HERE, base::Bind(base::Bind(base::IgnoreResult( | 85 FROM_HERE, base::Bind(base::Bind(base::IgnoreResult( |
| 86 &AudioManagerAndroid::GetJavaAudioManager)), | 86 &AudioManagerAndroid::GetJavaAudioManager)), |
| 87 base::Unretained(this))); | 87 base::Unretained(this))); |
| 88 } | 88 } |
| 89 | 89 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 // Most probable reason for a NULL result here is that the process lacks | 112 // Most probable reason for a NULL result here is that the process lacks |
| 113 // MODIFY_AUDIO_SETTINGS or RECORD_AUDIO permissions. | 113 // MODIFY_AUDIO_SETTINGS or RECORD_AUDIO permissions. |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 jsize len = env->GetArrayLength(j_device_array.obj()); | 116 jsize len = env->GetArrayLength(j_device_array.obj()); |
| 117 AudioDeviceName device; | 117 AudioDeviceName device; |
| 118 for (jsize i = 0; i < len; ++i) { | 118 for (jsize i = 0; i < len; ++i) { |
| 119 ScopedJavaLocalRef<jobject> j_device( | 119 ScopedJavaLocalRef<jobject> j_device( |
| 120 env, env->GetObjectArrayElement(j_device_array.obj(), i)); | 120 env, env->GetObjectArrayElement(j_device_array.obj(), i)); |
| 121 ScopedJavaLocalRef<jstring> j_device_name = | 121 ScopedJavaLocalRef<jstring> j_device_name = |
| 122 Java_AudioDeviceName_name(env, j_device.obj()); | 122 Java_AudioDeviceName_name(env, j_device); |
| 123 ConvertJavaStringToUTF8(env, j_device_name.obj(), &device.device_name); | 123 ConvertJavaStringToUTF8(env, j_device_name.obj(), &device.device_name); |
| 124 ScopedJavaLocalRef<jstring> j_device_id = | 124 ScopedJavaLocalRef<jstring> j_device_id = |
| 125 Java_AudioDeviceName_id(env, j_device.obj()); | 125 Java_AudioDeviceName_id(env, j_device); |
| 126 ConvertJavaStringToUTF8(env, j_device_id.obj(), &device.unique_id); | 126 ConvertJavaStringToUTF8(env, j_device_id.obj(), &device.unique_id); |
| 127 device_names->push_back(device); | 127 device_names->push_back(device); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 void AudioManagerAndroid::GetAudioOutputDeviceNames( | 131 void AudioManagerAndroid::GetAudioOutputDeviceNames( |
| 132 AudioDeviceNames* device_names) { | 132 AudioDeviceNames* device_names) { |
| 133 // TODO(henrika): enumerate using GetAudioInputDeviceNames(). | 133 // TODO(henrika): enumerate using GetAudioInputDeviceNames(). |
| 134 AddDefaultDevice(device_names); | 134 AddDefaultDevice(device_names); |
| 135 } | 135 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // Create the Android audio manager on the audio thread. | 354 // Create the Android audio manager on the audio thread. |
| 355 DVLOG(2) << "Creating Java part of the audio manager"; | 355 DVLOG(2) << "Creating Java part of the audio manager"; |
| 356 j_audio_manager_.Reset(Java_AudioManagerAndroid_createAudioManagerAndroid( | 356 j_audio_manager_.Reset(Java_AudioManagerAndroid_createAudioManagerAndroid( |
| 357 base::android::AttachCurrentThread(), | 357 base::android::AttachCurrentThread(), |
| 358 base::android::GetApplicationContext(), | 358 base::android::GetApplicationContext(), |
| 359 reinterpret_cast<intptr_t>(this))); | 359 reinterpret_cast<intptr_t>(this))); |
| 360 | 360 |
| 361 // Prepare the list of audio devices and register receivers for device | 361 // Prepare the list of audio devices and register receivers for device |
| 362 // notifications. | 362 // notifications. |
| 363 Java_AudioManagerAndroid_init(base::android::AttachCurrentThread(), | 363 Java_AudioManagerAndroid_init(base::android::AttachCurrentThread(), |
| 364 j_audio_manager_.obj()); | 364 j_audio_manager_); |
| 365 } | 365 } |
| 366 return j_audio_manager_.obj(); | 366 return j_audio_manager_.obj(); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) { | 369 void AudioManagerAndroid::SetCommunicationAudioModeOn(bool on) { |
| 370 Java_AudioManagerAndroid_setCommunicationAudioModeOn( | 370 Java_AudioManagerAndroid_setCommunicationAudioModeOn( |
| 371 base::android::AttachCurrentThread(), GetJavaAudioManager(), on); | 371 base::android::AttachCurrentThread(), GetJavaAudioManager(), on); |
| 372 } | 372 } |
| 373 | 373 |
| 374 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { | 374 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { |
| 375 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 375 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 376 | 376 |
| 377 // Send the unique device ID to the Java audio manager and make the | 377 // Send the unique device ID to the Java audio manager and make the |
| 378 // device switch. Provide an empty string to the Java audio manager | 378 // device switch. Provide an empty string to the Java audio manager |
| 379 // if the default device is selected. | 379 // if the default device is selected. |
| 380 JNIEnv* env = AttachCurrentThread(); | 380 JNIEnv* env = AttachCurrentThread(); |
| 381 ScopedJavaLocalRef<jstring> j_device_id = ConvertUTF8ToJavaString( | 381 ScopedJavaLocalRef<jstring> j_device_id = ConvertUTF8ToJavaString( |
| 382 env, device_id == AudioDeviceDescription::kDefaultDeviceId ? std::string() | 382 env, device_id == AudioDeviceDescription::kDefaultDeviceId ? std::string() |
| 383 : device_id); | 383 : device_id); |
| 384 return Java_AudioManagerAndroid_setDevice(env, GetJavaAudioManager(), | 384 return Java_AudioManagerAndroid_setDevice(env, GetJavaAudioManager(), |
| 385 j_device_id.obj()); | 385 j_device_id); |
| 386 } | 386 } |
| 387 | 387 |
| 388 int AudioManagerAndroid::GetNativeOutputSampleRate() { | 388 int AudioManagerAndroid::GetNativeOutputSampleRate() { |
| 389 return Java_AudioManagerAndroid_getNativeOutputSampleRate( | 389 return Java_AudioManagerAndroid_getNativeOutputSampleRate( |
| 390 base::android::AttachCurrentThread(), GetJavaAudioManager()); | 390 base::android::AttachCurrentThread(), GetJavaAudioManager()); |
| 391 } | 391 } |
| 392 | 392 |
| 393 bool AudioManagerAndroid::IsAudioLowLatencySupported() { | 393 bool AudioManagerAndroid::IsAudioLowLatencySupported() { |
| 394 return Java_AudioManagerAndroid_isAudioLowLatencySupported( | 394 return Java_AudioManagerAndroid_isAudioLowLatencySupported( |
| 395 base::android::AttachCurrentThread(), GetJavaAudioManager()); | 395 base::android::AttachCurrentThread(), GetJavaAudioManager()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 424 output_volume_override_ = volume; | 424 output_volume_override_ = volume; |
| 425 | 425 |
| 426 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 426 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 427 for (OutputStreams::iterator it = streams_.begin(); | 427 for (OutputStreams::iterator it = streams_.begin(); |
| 428 it != streams_.end(); ++it) { | 428 it != streams_.end(); ++it) { |
| 429 (*it)->SetVolume(volume); | 429 (*it)->SetVolume(volume); |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 | 432 |
| 433 } // namespace media | 433 } // namespace media |
| OLD | NEW |