henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_ |
| 12 | #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_ |
| 13 | |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 15 | #include <SLES/OpenSLES.h> |
| 16 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 17 | namespace webrtc { |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 18 | |
henrika | 521f7a8 | 2016-05-31 07:03:17 -0700 | [diff] [blame] | 19 | // Returns a string representation given an integer SL_RESULT_XXX code. |
| 20 | // The mapping can be found in <SLES/OpenSLES.h>. |
| 21 | const char* GetSLErrorString(size_t code); |
| 22 | |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 23 | // Configures an SL_DATAFORMAT_PCM structure based on native audio parameters. |
| 24 | SLDataFormat_PCM CreatePCMConfiguration(size_t channels, |
| 25 | int sample_rate, |
| 26 | size_t bits_per_sample); |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 27 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 28 | // Helper class for using SLObjectItf interfaces. |
| 29 | template <typename SLType, typename SLDerefType> |
| 30 | class ScopedSLObject { |
| 31 | public: |
| 32 | ScopedSLObject() : obj_(nullptr) {} |
| 33 | |
| 34 | ~ScopedSLObject() { Reset(); } |
| 35 | |
| 36 | SLType* Receive() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 37 | RTC_DCHECK(!obj_); |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 38 | return &obj_; |
| 39 | } |
| 40 | |
| 41 | SLDerefType operator->() { return *obj_; } |
| 42 | |
| 43 | SLType Get() const { return obj_; } |
| 44 | |
| 45 | void Reset() { |
| 46 | if (obj_) { |
| 47 | (*obj_)->Destroy(obj_); |
| 48 | obj_ = nullptr; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | private: |
| 53 | SLType obj_; |
| 54 | }; |
| 55 | |
| 56 | typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf; |
| 57 | |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 58 | } // namespace webrtc |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 59 | |
| 60 | #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_ |