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 | |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 17 | #include "webrtc/rtc_base/checks.h" |
| 18 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 19 | namespace webrtc { |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 20 | |
henrika | 521f7a8 | 2016-05-31 07:03:17 -0700 | [diff] [blame] | 21 | // Returns a string representation given an integer SL_RESULT_XXX code. |
| 22 | // The mapping can be found in <SLES/OpenSLES.h>. |
| 23 | const char* GetSLErrorString(size_t code); |
| 24 | |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 25 | // Configures an SL_DATAFORMAT_PCM structure based on native audio parameters. |
| 26 | SLDataFormat_PCM CreatePCMConfiguration(size_t channels, |
| 27 | int sample_rate, |
| 28 | size_t bits_per_sample); |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 29 | |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 30 | // Helper class for using SLObjectItf interfaces. |
| 31 | template <typename SLType, typename SLDerefType> |
| 32 | class ScopedSLObject { |
| 33 | public: |
| 34 | ScopedSLObject() : obj_(nullptr) {} |
| 35 | |
| 36 | ~ScopedSLObject() { Reset(); } |
| 37 | |
| 38 | SLType* Receive() { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 39 | RTC_DCHECK(!obj_); |
henrika | b261989 | 2015-05-18 16:49:16 +0200 | [diff] [blame] | 40 | return &obj_; |
| 41 | } |
| 42 | |
| 43 | SLDerefType operator->() { return *obj_; } |
| 44 | |
| 45 | SLType Get() const { return obj_; } |
| 46 | |
| 47 | void Reset() { |
| 48 | if (obj_) { |
| 49 | (*obj_)->Destroy(obj_); |
| 50 | obj_ = nullptr; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | SLType obj_; |
| 56 | }; |
| 57 | |
| 58 | typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf; |
| 59 | |
henrika | 918b554 | 2016-09-19 15:44:09 +0200 | [diff] [blame] | 60 | } // namespace webrtc |
henrike@webrtc.org | 82f014a | 2013-09-10 18:24:07 +0000 | [diff] [blame] | 61 | |
| 62 | #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_ |