blob: 5ff295b69df093177df95f3cce4f6796c1036a35 [file] [log] [blame]
henrike@webrtc.org82f014a2013-09-10 18:24:07 +00001/*
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
henrikab2619892015-05-18 16:49:16 +020016#include "webrtc/base/checks.h"
17
18namespace webrtc {
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000019
henrika521f7a82016-05-31 07:03:17 -070020// Returns a string representation given an integer SL_RESULT_XXX code.
21// The mapping can be found in <SLES/OpenSLES.h>.
22const char* GetSLErrorString(size_t code);
23
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000024SLDataFormat_PCM CreatePcmConfiguration(int sample_rate);
25
henrikab2619892015-05-18 16:49:16 +020026// Helper class for using SLObjectItf interfaces.
27template <typename SLType, typename SLDerefType>
28class ScopedSLObject {
29 public:
30 ScopedSLObject() : obj_(nullptr) {}
31
32 ~ScopedSLObject() { Reset(); }
33
34 SLType* Receive() {
henrikg91d6ede2015-09-17 00:24:34 -070035 RTC_DCHECK(!obj_);
henrikab2619892015-05-18 16:49:16 +020036 return &obj_;
37 }
38
39 SLDerefType operator->() { return *obj_; }
40
41 SLType Get() const { return obj_; }
42
43 void Reset() {
44 if (obj_) {
45 (*obj_)->Destroy(obj_);
46 obj_ = nullptr;
47 }
48 }
49
50 private:
51 SLType obj_;
52};
53
54typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf;
55
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000056} // namespace webrtc_opensl
57
58#endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_