blob: 75e4ff4b71998169faec87ebf3c451742af899b1 [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
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000020SLDataFormat_PCM CreatePcmConfiguration(int sample_rate);
21
henrikab2619892015-05-18 16:49:16 +020022// Helper class for using SLObjectItf interfaces.
23template <typename SLType, typename SLDerefType>
24class ScopedSLObject {
25 public:
26 ScopedSLObject() : obj_(nullptr) {}
27
28 ~ScopedSLObject() { Reset(); }
29
30 SLType* Receive() {
31 DCHECK(!obj_);
32 return &obj_;
33 }
34
35 SLDerefType operator->() { return *obj_; }
36
37 SLType Get() const { return obj_; }
38
39 void Reset() {
40 if (obj_) {
41 (*obj_)->Destroy(obj_);
42 obj_ = nullptr;
43 }
44 }
45
46 private:
47 SLType obj_;
48};
49
50typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf;
51
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000052} // namespace webrtc_opensl
53
54#endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_