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 14 #include <SLES/OpenSLES.h> 15 16 #include "webrtc/base/checks.h" 17 18 namespace webrtc { 19 20 SLDataFormat_PCM CreatePcmConfiguration(int sample_rate); 21 22 // Helper class for using SLObjectItf interfaces. 23 template <typename SLType, typename SLDerefType> 24 class ScopedSLObject { 25 public: ScopedSLObject()26 ScopedSLObject() : obj_(nullptr) {} 27 ~ScopedSLObject()28 ~ScopedSLObject() { Reset(); } 29 Receive()30 SLType* Receive() { 31 RTC_DCHECK(!obj_); 32 return &obj_; 33 } 34 35 SLDerefType operator->() { return *obj_; } 36 Get()37 SLType Get() const { return obj_; } 38 Reset()39 void Reset() { 40 if (obj_) { 41 (*obj_)->Destroy(obj_); 42 obj_ = nullptr; 43 } 44 } 45 46 private: 47 SLType obj_; 48 }; 49 50 typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf; 51 52 } // namespace webrtc_opensl 53 54 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_ 55