| 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" |
| 11 #include "base/android/scoped_java_ref.h" | 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "jni/AudioManagerAndroid_jni.h" | 16 #include "jni/AudioManagerAndroid_jni.h" |
| 17 #include "media/audio/android/audio_record_input.h" | 17 #include "media/audio/android/audio_record_input.h" |
| 18 #include "media/audio/android/opensles_input.h" | 18 #include "media/audio/android/opensles_input.h" |
| 19 #include "media/audio/android/opensles_output.h" | 19 #include "media/audio/android/opensles_output.h" |
| 20 #include "media/audio/audio_device_description.h" |
| 20 #include "media/audio/audio_manager.h" | 21 #include "media/audio/audio_manager.h" |
| 21 #include "media/audio/fake_audio_input_stream.h" | 22 #include "media/audio/fake_audio_input_stream.h" |
| 22 #include "media/base/audio_parameters.h" | 23 #include "media/base/audio_parameters.h" |
| 23 #include "media/base/channel_layout.h" | 24 #include "media/base/channel_layout.h" |
| 24 | 25 |
| 25 using base::android::AppendJavaStringArrayToStringVector; | 26 using base::android::AppendJavaStringArrayToStringVector; |
| 26 using base::android::AttachCurrentThread; | 27 using base::android::AttachCurrentThread; |
| 27 using base::android::ConvertJavaStringToUTF8; | 28 using base::android::ConvertJavaStringToUTF8; |
| 28 using base::android::ConvertUTF8ToJavaString; | 29 using base::android::ConvertUTF8ToJavaString; |
| 29 using base::android::ScopedJavaLocalRef; | 30 using base::android::ScopedJavaLocalRef; |
| 30 | 31 |
| 31 namespace media { | 32 namespace media { |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 void AddDefaultDevice(AudioDeviceNames* device_names) { | 35 void AddDefaultDevice(AudioDeviceNames* device_names) { |
| 35 DCHECK(device_names->empty()); | 36 DCHECK(device_names->empty()); |
| 36 device_names->push_front(AudioDeviceName(AudioManager::GetDefaultDeviceName(), | 37 device_names->push_front(AudioDeviceName::CreateDefault()); |
| 37 AudioManagerBase::kDefaultDeviceId)); | |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Maximum number of output streams that can be open simultaneously. | 40 // Maximum number of output streams that can be open simultaneously. |
| 41 const int kMaxOutputStreams = 10; | 41 const int kMaxOutputStreams = 10; |
| 42 | 42 |
| 43 const int kDefaultInputBufferSize = 1024; | 43 const int kDefaultInputBufferSize = 1024; |
| 44 const int kDefaultOutputBufferSize = 2048; | 44 const int kDefaultOutputBufferSize = 2048; |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 356 } |
| 357 | 357 |
| 358 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { | 358 bool AudioManagerAndroid::SetAudioDevice(const std::string& device_id) { |
| 359 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 359 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 360 | 360 |
| 361 // Send the unique device ID to the Java audio manager and make the | 361 // Send the unique device ID to the Java audio manager and make the |
| 362 // device switch. Provide an empty string to the Java audio manager | 362 // device switch. Provide an empty string to the Java audio manager |
| 363 // if the default device is selected. | 363 // if the default device is selected. |
| 364 JNIEnv* env = AttachCurrentThread(); | 364 JNIEnv* env = AttachCurrentThread(); |
| 365 ScopedJavaLocalRef<jstring> j_device_id = ConvertUTF8ToJavaString( | 365 ScopedJavaLocalRef<jstring> j_device_id = ConvertUTF8ToJavaString( |
| 366 env, | 366 env, device_id == AudioDeviceDescription::kDefaultDeviceId ? std::string() |
| 367 device_id == AudioManagerBase::kDefaultDeviceId ? | 367 : device_id); |
| 368 std::string() : device_id); | |
| 369 return Java_AudioManagerAndroid_setDevice( | 368 return Java_AudioManagerAndroid_setDevice( |
| 370 env, j_audio_manager_.obj(), j_device_id.obj()); | 369 env, j_audio_manager_.obj(), j_device_id.obj()); |
| 371 } | 370 } |
| 372 | 371 |
| 373 int AudioManagerAndroid::GetNativeOutputSampleRate() { | 372 int AudioManagerAndroid::GetNativeOutputSampleRate() { |
| 374 return Java_AudioManagerAndroid_getNativeOutputSampleRate( | 373 return Java_AudioManagerAndroid_getNativeOutputSampleRate( |
| 375 base::android::AttachCurrentThread(), | 374 base::android::AttachCurrentThread(), |
| 376 j_audio_manager_.obj()); | 375 j_audio_manager_.obj()); |
| 377 } | 376 } |
| 378 | 377 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 output_volume_override_ = volume; | 411 output_volume_override_ = volume; |
| 413 | 412 |
| 414 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 413 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 415 for (OutputStreams::iterator it = streams_.begin(); | 414 for (OutputStreams::iterator it = streams_.begin(); |
| 416 it != streams_.end(); ++it) { | 415 it != streams_.end(); ++it) { |
| 417 (*it)->SetVolume(volume); | 416 (*it)->SetVolume(volume); |
| 418 } | 417 } |
| 419 } | 418 } |
| 420 | 419 |
| 421 } // namespace media | 420 } // namespace media |
| OLD | NEW |