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/logging.h" | 7 #include "base/logging.h" |
8 #include "jni/AudioManagerAndroid_jni.h" | 8 #include "jni/AudioManagerAndroid_jni.h" |
9 #include "media/audio/android/opensles_input.h" | 9 #include "media/audio/android/opensles_input.h" |
10 #include "media/audio/android/opensles_output.h" | 10 #include "media/audio/android/opensles_output.h" |
11 #include "media/audio/audio_manager.h" | 11 #include "media/audio/audio_manager.h" |
12 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
13 #include "media/audio/audio_util.h" | 13 #include "media/audio/audio_util.h" |
14 #include "media/audio/fake_audio_input_stream.h" | 14 #include "media/audio/fake_audio_input_stream.h" |
15 #include "media/base/channel_layout.h" | 15 #include "media/base/channel_layout.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
| 19 namespace { |
| 20 |
| 21 void AddDefaultDevice(AudioDeviceNames* device_names) { |
| 22 DCHECK(device_names->empty()); |
| 23 device_names->push_front( |
| 24 AudioDeviceName(kDefaultDeviceName, kDefaultDeviceId)); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
19 // Maximum number of output streams that can be open simultaneously. | 29 // Maximum number of output streams that can be open simultaneously. |
20 static const int kMaxOutputStreams = 10; | 30 static const int kMaxOutputStreams = 10; |
21 | 31 |
22 static const int kAudioModeNormal = 0x00000000; | 32 static const int kAudioModeNormal = 0x00000000; |
23 static const int kAudioModeInCommunication = 0x00000003; | 33 static const int kAudioModeInCommunication = 0x00000003; |
24 | 34 |
25 static const int kDefaultInputBufferSize = 1024; | 35 static const int kDefaultInputBufferSize = 1024; |
26 static const int kDefaultOutputBufferSize = 2048; | 36 static const int kDefaultOutputBufferSize = 2048; |
27 | 37 |
28 AudioManager* CreateAudioManager() { | 38 AudioManager* CreateAudioManager() { |
(...skipping 15 matching lines...) Expand all Loading... |
44 | 54 |
45 bool AudioManagerAndroid::HasAudioOutputDevices() { | 55 bool AudioManagerAndroid::HasAudioOutputDevices() { |
46 return true; | 56 return true; |
47 } | 57 } |
48 | 58 |
49 bool AudioManagerAndroid::HasAudioInputDevices() { | 59 bool AudioManagerAndroid::HasAudioInputDevices() { |
50 return true; | 60 return true; |
51 } | 61 } |
52 | 62 |
53 void AudioManagerAndroid::GetAudioInputDeviceNames( | 63 void AudioManagerAndroid::GetAudioInputDeviceNames( |
54 media::AudioDeviceNames* device_names) { | 64 AudioDeviceNames* device_names) { |
55 DCHECK(device_names->empty()); | 65 AddDefaultDevice(device_names); |
56 device_names->push_front( | 66 } |
57 media::AudioDeviceName(kDefaultDeviceName, kDefaultDeviceId)); | 67 |
| 68 void AudioManagerAndroid::GetAudioOutputDeviceNames( |
| 69 AudioDeviceNames* device_names) { |
| 70 AddDefaultDevice(device_names); |
58 } | 71 } |
59 | 72 |
60 AudioParameters AudioManagerAndroid::GetInputStreamParameters( | 73 AudioParameters AudioManagerAndroid::GetInputStreamParameters( |
61 const std::string& device_id) { | 74 const std::string& device_id) { |
62 // Use mono as preferred number of input channels on Android to save | 75 // Use mono as preferred number of input channels on Android to save |
63 // resources. Using mono also avoids a driver issue seen on Samsung | 76 // resources. Using mono also avoids a driver issue seen on Samsung |
64 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. | 77 // Galaxy S3 and S4 devices. See http://crbug.com/256851 for details. |
65 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; | 78 ChannelLayout channel_layout = CHANNEL_LAYOUT_MONO; |
66 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( | 79 int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize( |
67 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), | 80 base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), |
(...skipping 15 matching lines...) Expand all Loading... |
83 if (stream && output_stream_count() == 1) { | 96 if (stream && output_stream_count() == 1) { |
84 SetAudioMode(kAudioModeInCommunication); | 97 SetAudioMode(kAudioModeInCommunication); |
85 RegisterHeadsetReceiver(); | 98 RegisterHeadsetReceiver(); |
86 } | 99 } |
87 return stream; | 100 return stream; |
88 } | 101 } |
89 | 102 |
90 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( | 103 AudioInputStream* AudioManagerAndroid::MakeAudioInputStream( |
91 const AudioParameters& params, const std::string& device_id) { | 104 const AudioParameters& params, const std::string& device_id) { |
92 AudioInputStream* stream = | 105 AudioInputStream* stream = |
93 AudioManagerBase::MakeAudioInputStream(params, device_id); | 106 AudioManagerBase::MakeAudioInputStream(params, device_id); |
94 return stream; | 107 return stream; |
95 } | 108 } |
96 | 109 |
97 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) { | 110 void AudioManagerAndroid::ReleaseOutputStream(AudioOutputStream* stream) { |
98 AudioManagerBase::ReleaseOutputStream(stream); | 111 AudioManagerBase::ReleaseOutputStream(stream); |
99 if (!output_stream_count()) { | 112 if (!output_stream_count()) { |
100 UnregisterHeadsetReceiver(); | 113 UnregisterHeadsetReceiver(); |
101 SetAudioMode(kAudioModeNormal); | 114 SetAudioMode(kAudioModeNormal); |
102 } | 115 } |
103 } | 116 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 j_audio_manager_.obj()); | 222 j_audio_manager_.obj()); |
210 } | 223 } |
211 | 224 |
212 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { | 225 int AudioManagerAndroid::GetAudioLowLatencyOutputFrameSize() { |
213 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( | 226 return Java_AudioManagerAndroid_getAudioLowLatencyOutputFrameSize( |
214 base::android::AttachCurrentThread(), | 227 base::android::AttachCurrentThread(), |
215 j_audio_manager_.obj()); | 228 j_audio_manager_.obj()); |
216 } | 229 } |
217 | 230 |
218 } // namespace media | 231 } // namespace media |
OLD | NEW |