Index: media/audio/android/audio_manager_android.cc |
diff --git a/media/audio/android/audio_manager_android.cc b/media/audio/android/audio_manager_android.cc |
index 93296d7b41fc86741a5a50726c226ef59ebaa50c..80e1a27ed434930cd4ea2345e9f953a8b7dc5c18 100644 |
--- a/media/audio/android/audio_manager_android.cc |
+++ b/media/audio/android/audio_manager_android.cc |
@@ -8,8 +8,9 @@ |
#include "media/audio/android/opensles_input.h" |
#include "media/audio/android/opensles_output.h" |
#include "media/audio/audio_manager.h" |
-#include "media/audio/audio_util.h" |
+#include "media/audio/audio_parameters.h" |
#include "media/audio/fake_audio_input_stream.h" |
+#include "media/base/channel_layout.h" |
namespace media { |
@@ -43,20 +44,16 @@ void AudioManagerAndroid::GetAudioInputDeviceNames( |
media::AudioDeviceName(kDefaultDeviceName, kDefaultDeviceId)); |
} |
-AudioParameters |
-AudioManagerAndroid::GetPreferredLowLatencyOutputStreamParameters( |
- const AudioParameters& input_params) { |
- // TODO(leozwang): Android defines the minimal buffer size requirment |
- // we should follow it. From Android 4.1, a new audio low latency api |
- // set was introduced and is under development, we want to take advantage |
- // of it. |
- int buffer_size = GetAudioHardwareBufferSize(); |
- if (input_params.frames_per_buffer() < buffer_size) |
- buffer_size = input_params.frames_per_buffer(); |
- |
+AudioParameters AudioManagerAndroid::GetInputStreamParameters( |
+ const std::string& device_id) { |
+ // TODO(xians): figure out the right input sample rate and buffer size to |
+ // achieve the best audio performance for Android devices. |
+ // TODO(xians): query the native channel layout for the specific device. |
+ static const int kDefaultSampleRate = 16000; |
+ static const int kDefaultBufferSize = 1024; |
return AudioParameters( |
- AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(), |
- input_params.sample_rate(), 16, buffer_size); |
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
+ kDefaultSampleRate, 16, kDefaultBufferSize); |
} |
AudioOutputStream* AudioManagerAndroid::MakeLinearOutputStream( |
@@ -83,4 +80,35 @@ AudioInputStream* AudioManagerAndroid::MakeLowLatencyInputStream( |
return new OpenSLESInputStream(this, params); |
} |
+AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters( |
+ const AudioParameters& input_params) { |
+ // TODO(xians): figure out the right output sample rate and sample rate to |
+ // achieve the best audio performance for Android devices. |
+ static const int kDefaultSampleRate = 16000; |
+ static const int kDefaultBufferSize = 1024; |
+ |
+ ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
+ int sample_rate = kDefaultSampleRate; |
+ int buffer_size = kDefaultBufferSize; |
+ int bits_per_sample = 16; |
+ int input_channels = 0; |
+ if (input_params.IsValid()) { |
+ // Use the client's input parameters if they are valid. |
+ sample_rate = input_params.sample_rate(); |
+ bits_per_sample = input_params.bits_per_sample(); |
+ channel_layout = input_params.channel_layout(); |
+ input_channels = input_params.input_channels(); |
+ |
+ // TODO(leozwang): Android defines the minimal buffer size requirment |
+ // we should follow it. From Android 4.1, a new audio low latency api |
+ // set was introduced and is under development, we want to take advantage |
+ // of it. |
+ buffer_size = std::min(buffer_size, input_params.frames_per_buffer()); |
+ } |
+ |
+ return AudioParameters( |
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
+ sample_rate, bits_per_sample, buffer_size); |
+} |
+ |
} // namespace media |