Chromium Code Reviews| Index: webrtc/modules/audio_device/android/opensles_common.cc |
| diff --git a/webrtc/modules/audio_device/android/opensles_common.cc b/webrtc/modules/audio_device/android/opensles_common.cc |
| index 9e3cbf7b9a9da6f5f20a53761d585d696701ee4a..d0768efaa6e89040f0d9e30a78e572f20a058560 100644 |
| --- a/webrtc/modules/audio_device/android/opensles_common.cc |
| +++ b/webrtc/modules/audio_device/android/opensles_common.cc |
| @@ -10,13 +10,10 @@ |
| #include "webrtc/modules/audio_device/android/opensles_common.h" |
| -#include <assert.h> |
| #include <SLES/OpenSLES.h> |
| #include "webrtc/base/arraysize.h" |
| -#include "webrtc/modules/audio_device/android/audio_common.h" |
| - |
| -using webrtc::kNumChannels; |
| +#include "webrtc/base/checks.h" |
| namespace webrtc { |
| @@ -49,24 +46,47 @@ const char* GetSLErrorString(size_t code) { |
| return sl_error_strings[code]; |
| } |
| -SLDataFormat_PCM CreatePcmConfiguration(int sample_rate) { |
| - SLDataFormat_PCM configuration; |
| - configuration.formatType = SL_DATAFORMAT_PCM; |
| - configuration.numChannels = kNumChannels; |
| - // According to the opensles documentation in the ndk: |
| - // samplesPerSec is actually in units of milliHz, despite the misleading name. |
| - // It further recommends using constants. However, this would lead to a lot |
| - // of boilerplate code so it is not done here. |
| - configuration.samplesPerSec = sample_rate * 1000; |
| - configuration.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; |
| - configuration.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16; |
| - configuration.channelMask = SL_SPEAKER_FRONT_CENTER; |
| - if (2 == configuration.numChannels) { |
| - configuration.channelMask = |
| - SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; |
| +SLDataFormat_PCM CreatePCMConfiguration(size_t channels, |
| + int sample_rate, |
| + size_t bits_per_sample) { |
| + RTC_CHECK_EQ(bits_per_sample, SL_PCMSAMPLEFORMAT_FIXED_16); |
| + SLDataFormat_PCM format; |
| + format.formatType = SL_DATAFORMAT_PCM; |
| + format.numChannels = static_cast<SLuint32>(channels); |
| + // Note that, the unit of sample rate is actually in milliHertz and not Hertz. |
| + switch (sample_rate) { |
| + case 8000: |
| + format.samplesPerSec = SL_SAMPLINGRATE_8; |
| + break; |
| + case 16000: |
| + format.samplesPerSec = SL_SAMPLINGRATE_16; |
| + break; |
| + case 22050: |
| + format.samplesPerSec = SL_SAMPLINGRATE_22_05; |
| + break; |
| + case 32000: |
| + format.samplesPerSec = SL_SAMPLINGRATE_32; |
| + break; |
| + case 44100: |
| + format.samplesPerSec = SL_SAMPLINGRATE_44_1; |
| + break; |
| + case 48000: |
| + format.samplesPerSec = SL_SAMPLINGRATE_48; |
| + break; |
| + default: |
|
tommi
2016/09/15 09:34:13
I think I've read somewhere that 96kHz is supporte
henrika_webrtc
2016/09/16 13:30:47
Great feedback. You are correct. I have never seen
|
| + RTC_CHECK(false) << "Unsupported sample rate: " << sample_rate; |
|
tommi
2016/09/15 09:34:12
nit: also include a break; here for consistency.
henrika_webrtc
2016/09/16 13:30:47
Done.
|
| } |
| - configuration.endianness = SL_BYTEORDER_LITTLEENDIAN; |
| - return configuration; |
| + format.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; |
| + format.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16; |
| + format.endianness = SL_BYTEORDER_LITTLEENDIAN; |
| + if (format.numChannels == 1) |
|
tommi
2016/09/15 09:34:13
{}
(see lines below)
henrika_webrtc
2016/09/16 13:30:47
Done.
|
| + format.channelMask = SL_SPEAKER_FRONT_CENTER; |
| + else if (format.numChannels == 2) |
| + format.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; |
| + else |
| + RTC_CHECK(false) << "Unsupported number of channels: " |
| + << format.numChannels; |
| + return format; |
| } |
| -} // namespace webrtc_opensl |
| +} // namespace webrtc |