OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_device/android/opensles_common.h" | 11 #include "webrtc/modules/audio_device/android/opensles_common.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
| 14 #include <SLES/OpenSLES.h> |
14 | 15 |
| 16 #include "webrtc/base/arraysize.h" |
15 #include "webrtc/modules/audio_device/android/audio_common.h" | 17 #include "webrtc/modules/audio_device/android/audio_common.h" |
16 | 18 |
17 using webrtc::kNumChannels; | 19 using webrtc::kNumChannels; |
18 | 20 |
19 namespace webrtc { | 21 namespace webrtc { |
20 | 22 |
| 23 // Returns a string representation given an integer SL_RESULT_XXX code. |
| 24 // The mapping can be found in <SLES/OpenSLES.h>. |
| 25 const char* GetSLErrorString(size_t code) { |
| 26 static const char* sl_error_strings[] = { |
| 27 "SL_RESULT_SUCCESS", // 0 |
| 28 "SL_RESULT_PRECONDITIONS_VIOLATED", // 1 |
| 29 "SL_RESULT_PARAMETER_INVALID", // 2 |
| 30 "SL_RESULT_MEMORY_FAILURE", // 3 |
| 31 "SL_RESULT_RESOURCE_ERROR", // 4 |
| 32 "SL_RESULT_RESOURCE_LOST", // 5 |
| 33 "SL_RESULT_IO_ERROR", // 6 |
| 34 "SL_RESULT_BUFFER_INSUFFICIENT", // 7 |
| 35 "SL_RESULT_CONTENT_CORRUPTED", // 8 |
| 36 "SL_RESULT_CONTENT_UNSUPPORTED", // 9 |
| 37 "SL_RESULT_CONTENT_NOT_FOUND", // 10 |
| 38 "SL_RESULT_PERMISSION_DENIED", // 11 |
| 39 "SL_RESULT_FEATURE_UNSUPPORTED", // 12 |
| 40 "SL_RESULT_INTERNAL_ERROR", // 13 |
| 41 "SL_RESULT_UNKNOWN_ERROR", // 14 |
| 42 "SL_RESULT_OPERATION_ABORTED", // 15 |
| 43 "SL_RESULT_CONTROL_LOST", // 16 |
| 44 }; |
| 45 |
| 46 if (code >= arraysize(sl_error_strings)) { |
| 47 return "SL_RESULT_UNKNOWN_ERROR"; |
| 48 } |
| 49 return sl_error_strings[code]; |
| 50 } |
| 51 |
21 SLDataFormat_PCM CreatePcmConfiguration(int sample_rate) { | 52 SLDataFormat_PCM CreatePcmConfiguration(int sample_rate) { |
22 SLDataFormat_PCM configuration; | 53 SLDataFormat_PCM configuration; |
23 configuration.formatType = SL_DATAFORMAT_PCM; | 54 configuration.formatType = SL_DATAFORMAT_PCM; |
24 configuration.numChannels = kNumChannels; | 55 configuration.numChannels = kNumChannels; |
25 // According to the opensles documentation in the ndk: | 56 // According to the opensles documentation in the ndk: |
26 // samplesPerSec is actually in units of milliHz, despite the misleading name. | 57 // samplesPerSec is actually in units of milliHz, despite the misleading name. |
27 // It further recommends using constants. However, this would lead to a lot | 58 // It further recommends using constants. However, this would lead to a lot |
28 // of boilerplate code so it is not done here. | 59 // of boilerplate code so it is not done here. |
29 configuration.samplesPerSec = sample_rate * 1000; | 60 configuration.samplesPerSec = sample_rate * 1000; |
30 configuration.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; | 61 configuration.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16; |
31 configuration.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16; | 62 configuration.containerSize = SL_PCMSAMPLEFORMAT_FIXED_16; |
32 configuration.channelMask = SL_SPEAKER_FRONT_CENTER; | 63 configuration.channelMask = SL_SPEAKER_FRONT_CENTER; |
33 if (2 == configuration.numChannels) { | 64 if (2 == configuration.numChannels) { |
34 configuration.channelMask = | 65 configuration.channelMask = |
35 SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; | 66 SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT; |
36 } | 67 } |
37 configuration.endianness = SL_BYTEORDER_LITTLEENDIAN; | 68 configuration.endianness = SL_BYTEORDER_LITTLEENDIAN; |
38 return configuration; | 69 return configuration; |
39 } | 70 } |
40 | 71 |
41 } // namespace webrtc_opensl | 72 } // namespace webrtc_opensl |
OLD | NEW |