Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1995)

Unified Diff: media/audio/android/audio_manager_android.cc

Issue 15217002: Using native sampling rate and optimal buffer size for audio on Android. (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: bytes->frames and address Min's comments Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/android/audio_manager_android.cc
===================================================================
--- media/audio/android/audio_manager_android.cc (revision 201553)
+++ media/audio/android/audio_manager_android.cc (working copy)
@@ -22,6 +22,9 @@
static const int kAudioModeNormal = 0x00000000;
static const int kAudioModeInCommunication = 0x00000003;
+static const int kDefaultInputBufferSize = 1024;
+static const int kDefaultOutputBufferSize = 2048;
+
AudioManager* CreateAudioManager() {
return new AudioManagerAndroid();
}
@@ -56,13 +59,13 @@
AudioParameters AudioManagerAndroid::GetInputStreamParameters(
const std::string& device_id) {
- // TODO(leozwang): Android defines the minimal buffer size requirment
- // we should use it.
- static const int kDefaultBufferSize = 1024;
- // TODO(xians): query the native channel layout for the specific device.
+ int buffer_size = Java_AudioManagerAndroid_getMinInputFrameSize(
+ base::android::AttachCurrentThread(), GetNativeOutputSampleRate(), 2);
+
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
- GetNativeOutputSampleRate(), 16, kDefaultBufferSize);
+ GetNativeOutputSampleRate(), 16,
+ buffer_size <= 0 ? kDefaultInputBufferSize : buffer_size);
}
AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream(
@@ -119,15 +122,27 @@
return new OpenSLESInputStream(this, params);
}
+int AudioManagerAndroid::GetOptimalOutputFrameSize(int sample_rate,
+ int channels) {
+ if (IsAudioLowLatencySupported()) {
+ int frame_size = GetAudioLowLatencyFrameSize();
+ // Return the optimal size as a multiple of the low latency frame
+ // size that is close to the target frame size.
+ return ((kDefaultOutputBufferSize + frame_size / 2) / frame_size) *
+ frame_size;
+ } else {
+ return std::max(kDefaultOutputBufferSize,
+ Java_AudioManagerAndroid_getMinOutputFrameSize(
+ base::android::AttachCurrentThread(),
+ sample_rate, channels));
+ }
+}
+
AudioParameters AudioManagerAndroid::GetPreferredOutputStreamParameters(
const AudioParameters& input_params) {
- // TODO(leozwang): Android defines the minimal buffer size requirment
- // we should use it.
- static const int kDefaultBufferSize = 2048;
-
ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
int sample_rate = GetNativeOutputSampleRate();
- int buffer_size = kDefaultBufferSize;
+ int buffer_size = GetOptimalOutputFrameSize(sample_rate, 2);
int bits_per_sample = 16;
int input_channels = 0;
if (input_params.IsValid()) {
@@ -136,8 +151,7 @@
bits_per_sample = input_params.bits_per_sample();
channel_layout = input_params.channel_layout();
input_channels = input_params.input_channels();
-
- buffer_size = std::min(buffer_size, input_params.frames_per_buffer());
+ buffer_size = GetOptimalOutputFrameSize(sample_rate, channel_layout);
}
int user_buffer_size = GetUserBufferSize();
@@ -178,4 +192,16 @@
j_audio_manager_.obj());
}
+bool AudioManagerAndroid::IsAudioLowLatencySupported() {
+ return Java_AudioManagerAndroid_isAudioLowLatencySupported(
+ base::android::AttachCurrentThread(),
+ j_audio_manager_.obj());
+}
+
+int AudioManagerAndroid::GetAudioLowLatencyFrameSize() {
no longer working on chromium 2013/05/27 16:04:56 Can this GetAudioLowLatencyFrameSize be used by bo
leozwang1 2013/05/27 16:11:37 this low latency mode is for output only now.
+ return Java_AudioManagerAndroid_getAudioLowLatencyFrameSize(
+ base::android::AttachCurrentThread(),
+ j_audio_manager_.obj());
+}
+
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698