blob: b0859c2b6af7fbebed6a53735e98e4e5ffd98ae0 [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
henrika918b5542016-09-19 15:44:09 +020014#include <stddef.h>
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000015#include <SLES/OpenSLES.h>
16
henrikab2619892015-05-18 16:49:16 +020017namespace webrtc {
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000018
henrika521f7a82016-05-31 07:03:17 -070019// Returns a string representation given an integer SL_RESULT_XXX code.
20// The mapping can be found in <SLES/OpenSLES.h>.
21const char* GetSLErrorString(size_t code);
22
henrika918b5542016-09-19 15:44:09 +020023// Configures an SL_DATAFORMAT_PCM structure based on native audio parameters.
24SLDataFormat_PCM CreatePCMConfiguration(size_t channels,
25 int sample_rate,
26 size_t bits_per_sample);
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000027
henrikab2619892015-05-18 16:49:16 +020028// Helper class for using SLObjectItf interfaces.
29template <typename SLType, typename SLDerefType>
30class ScopedSLObject {
31 public:
32 ScopedSLObject() : obj_(nullptr) {}
33
34 ~ScopedSLObject() { Reset(); }
35
36 SLType* Receive() {
henrikg91d6ede2015-09-17 00:24:34 -070037 RTC_DCHECK(!obj_);
henrikab2619892015-05-18 16:49:16 +020038 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
56typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf;
57
henrika918b5542016-09-19 15:44:09 +020058} // namespace webrtc
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000059
60#endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_