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 "media/audio/android/opensles_input.h" | 8 #include "media/audio/android/opensles_input.h" |
9 #include "media/audio/android/opensles_output.h" | 9 #include "media/audio/android/opensles_output.h" |
10 #include "media/audio/audio_manager.h" | 10 #include "media/audio/audio_manager.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 void AudioManagerAndroid::GetAudioInputDeviceNames( | 41 void AudioManagerAndroid::GetAudioInputDeviceNames( |
42 media::AudioDeviceNames* device_names) { | 42 media::AudioDeviceNames* device_names) { |
43 DCHECK(device_names->empty()); | 43 DCHECK(device_names->empty()); |
44 device_names->push_front( | 44 device_names->push_front( |
45 media::AudioDeviceName(kDefaultDeviceName, kDefaultDeviceId)); | 45 media::AudioDeviceName(kDefaultDeviceName, kDefaultDeviceId)); |
46 } | 46 } |
47 | 47 |
48 AudioParameters AudioManagerAndroid::GetInputStreamParameters( | 48 AudioParameters AudioManagerAndroid::GetInputStreamParameters( |
49 const std::string& device_id) { | 49 const std::string& device_id) { |
50 // TODO(xians): figure out the right input sample rate and buffer size to | |
51 // achieve the best audio performance for Android devices. | |
52 // TODO(xians): query the native channel layout for the specific device. | |
53 static const int kDefaultSampleRate = 16000; | |
54 static const int kDefaultBufferSize = 1024; | 50 static const int kDefaultBufferSize = 1024; |
55 return AudioParameters( | 51 return AudioParameters( |
56 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, | 52 AudioParameters::AUDIO_PCM_LOW_LATENCY, |
57 kDefaultSampleRate, 16, kDefaultBufferSize); | 53 CHANNEL_LAYOUT_STEREO, |
| 54 GetNativeOutputSampleRatee(), |
| 55 16, |
| 56 kDefaultBufferSize); |
58 } | 57 } |
59 | 58 |
60 AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream( | 59 AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream( |
61 const AudioParameters& params) { | 60 const AudioParameters& params) { |
62 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 61 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
63 return new OpenSLESOutputStream(this, params); | 62 return new OpenSLESOutputStream(this, params); |
64 } | 63 } |
65 | 64 |
66 AudioOutputStream* AudioManagerAndroid::MakeLowLatencyOutputStream( | 65 AudioOutputStream* AudioManagerAndroid::MakeLowLatencyOutputStream( |
67 const AudioParameters& params) { | 66 const AudioParameters& params) { |
(...skipping 10 matching lines...) Expand all Loading... |
78 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( | 77 AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( |
79 const AudioParameters& params, const std::string& device_id) { | 78 const AudioParameters& params, const std::string& device_id) { |
80 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 79 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
81 return new OpenSLESInputStream(this, params); | 80 return new OpenSLESInputStream(this, params); |
82 } | 81 } |
83 | 82 |
84 AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters( | 83 AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters( |
85 const AudioParameters& input_params) { | 84 const AudioParameters& input_params) { |
86 // TODO(xians): figure out the right output sample rate and sample rate to | 85 // TODO(xians): figure out the right output sample rate and sample rate to |
87 // achieve the best audio performance for Android devices. | 86 // achieve the best audio performance for Android devices. |
88 static const int kDefaultSampleRate = 16000; | |
89 static const int kDefaultBufferSize = 1024; | 87 static const int kDefaultBufferSize = 1024; |
90 | 88 |
91 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 89 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
92 int sample_rate = kDefaultSampleRate; | 90 int sample_rate = GetNativeOutputSampleRatee(); |
93 int buffer_size = kDefaultBufferSize; | 91 int buffer_size = kDefaultBufferSize; |
94 int bits_per_sample = 16; | 92 int bits_per_sample = 16; |
95 int input_channels = 0; | 93 int input_channels = 0; |
96 if (input_params.IsValid()) { | 94 if (input_params.IsValid()) { |
97 // Use the client's input parameters if they are valid. | 95 // Use the client's input parameters if they are valid. |
98 sample_rate = input_params.sample_rate(); | 96 sample_rate = input_params.sample_rate(); |
99 bits_per_sample = input_params.bits_per_sample(); | 97 bits_per_sample = input_params.bits_per_sample(); |
100 channel_layout = input_params.channel_layout(); | 98 channel_layout = input_params.channel_layout(); |
101 input_channels = input_params.input_channels(); | 99 input_channels = input_params.input_channels(); |
102 | 100 |
103 // TODO(leozwang): Android defines the minimal buffer size requirment | 101 // TODO(leozwang): Android defines the minimal buffer size requirment |
104 // we should follow it. From Android 4.1, a new audio low latency api | 102 // we should follow it. From Android 4.1, a new audio low latency api |
105 // set was introduced and is under development, we want to take advantage | 103 // set was introduced and is under development, we want to take advantage |
106 // of it. | 104 // of it. |
107 buffer_size = std::min(buffer_size, input_params.frames_per_buffer()); | 105 buffer_size = std::min(buffer_size, input_params.frames_per_buffer()); |
108 } | 106 } |
109 | 107 |
110 int user_buffer_size = GetUserBufferSize(); | 108 int user_buffer_size = GetUserBufferSize(); |
111 if (user_buffer_size) | 109 if (user_buffer_size) |
112 buffer_size = user_buffer_size; | 110 buffer_size = user_buffer_size; |
113 | 111 |
114 return AudioParameters( | 112 return AudioParameters( |
115 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, | 113 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
116 sample_rate, bits_per_sample, buffer_size); | 114 sample_rate, bits_per_sample, buffer_size); |
117 } | 115 } |
118 | 116 |
119 } // namespace media | 117 } // namespace media |
OLD | NEW |