Chromium Code Reviews| Index: media/audio/android/audio_manager_android.cc |
| =================================================================== |
| --- media/audio/android/audio_manager_android.cc (revision 200599) |
| +++ media/audio/android/audio_manager_android.cc (working copy) |
| @@ -56,13 +56,11 @@ |
| 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 size = GetMinInputFrameSize(GetNativeOutputSampleRate(), 2); |
|
no longer working on chromium
2013/05/20 09:59:26
nit, size -> buffer_size
leozwang1
2013/05/20 17:41:05
Done.
|
| return AudioParameters( |
| AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| - GetNativeOutputSampleRate(), 16, kDefaultBufferSize); |
| + GetNativeOutputSampleRate(), 16, size <= 0 ? kDefaultBufferSize : size); |
| } |
| AudioOutputStream* AudioManagerAndroid::MakeAudioOutputStream( |
| @@ -119,15 +117,25 @@ |
| return new OpenSLESInputStream(this, params); |
| } |
| +int AudioManagerAndroid::GetAudioOptimalOutputFrameSize(int sample_rate, |
|
no longer working on chromium
2013/05/20 09:59:26
nit, s/GetAudioOptimalOutputFrameSize/GetOptimalOu
leozwang1
2013/05/20 17:41:05
Done.
|
| + int channels) { |
| + const int kTargetFrameSize = 2048; |
|
no longer working on chromium
2013/05/20 09:59:26
kTargetFrameSize is the same as kDefaultBufferSize
leozwang1
2013/05/20 17:41:05
Done.
|
| + 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 ((kTargetFrameSize + frame_size / 2) / frame_size) * frame_size; |
|
no longer working on chromium
2013/05/20 09:59:26
I have to admit that I am not familiar with PROPER
leozwang1
2013/05/20 17:41:05
In order to achieve to "low latency", the buffer s
no longer working on chromium
2013/05/21 21:52:32
I understand that it needs to be a multiple of Get
Raymond Toy (Google)
2013/05/21 22:00:27
The low latency frame size varies quite a bit depe
|
| + } else |
|
no longer working on chromium
2013/05/20 09:59:26
nit, add { }
leozwang1
2013/05/20 17:41:05
Done.
|
| + return std::max(kTargetFrameSize, |
| + GetMinOutputFrameSize(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 = GetAudioOptimalOutputFrameSize(sample_rate, 2); |
| int bits_per_sample = 16; |
| int input_channels = 0; |
| if (input_params.IsValid()) { |
| @@ -136,8 +144,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 = buffer_size <= 0 ? kDefaultBufferSize : buffer_size; |
|
no longer working on chromium
2013/05/20 09:59:26
how buffer_size can be <= 0?
leozwang1
2013/05/20 17:41:05
good catch, it was latency code, removed it.
|
| } |
| int user_buffer_size = GetUserBufferSize(); |
| @@ -178,4 +185,27 @@ |
| j_audio_manager_.obj()); |
| } |
| +int AudioManagerAndroid::GetMinInputFrameSize(int rate, int channels) { |
|
no longer working on chromium
2013/05/20 09:59:26
could you please add comments here, to explain why
leozwang1
2013/05/20 17:41:05
Done.
|
| + return Java_AudioManagerAndroid_getMinInputBufSize( |
| + base::android::AttachCurrentThread(), rate, channels) / 2 / channels; |
|
no longer working on chromium
2013/05/20 09:59:26
nit, use sizeof(int16) instead of 2
leozwang1
2013/05/20 17:41:05
Done.
|
| +} |
| + |
| +int AudioManagerAndroid::GetMinOutputFrameSize(int rate, int channels) { |
| + // Get buffer size in frames, assuming 16-bit pcm samples. |
| + return Java_AudioManagerAndroid_getMinOutputBufSize( |
| + base::android::AttachCurrentThread(), rate, channels) / 2 / channels; |
| +} |
| + |
| +bool AudioManagerAndroid::IsAudioLowLatencySupported() { |
|
no longer working on chromium
2013/05/20 09:59:26
I don't think you need a separate IsAudioLowLatenc
leozwang1
2013/05/20 17:41:05
Currently it's called once, but it's just wrapper
|
| + return Java_AudioManagerAndroid_isAudioLowLatencySupported( |
| + base::android::AttachCurrentThread(), |
| + j_audio_manager_.obj()); |
| +} |
| + |
| +int AudioManagerAndroid::GetAudioLowLatencyFrameSize() { |
| + return Java_AudioManagerAndroid_getAudioLowLatencyFrameSize( |
| + base::android::AttachCurrentThread(), |
| + j_audio_manager_.obj()); |
| +} |
| + |
| } // namespace media |