blob: 90988eef5ad79fd329854057c800c38de61bc397 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_
12#define MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000013
henrika918b5542016-09-19 15:44:09 +020014#include <stddef.h>
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000015#include <SLES/OpenSLES.h>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/checks.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020018
henrikab2619892015-05-18 16:49:16 +020019namespace webrtc {
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000020
henrika521f7a82016-05-31 07:03:17 -070021// Returns a string representation given an integer SL_RESULT_XXX code.
22// The mapping can be found in <SLES/OpenSLES.h>.
23const char* GetSLErrorString(size_t code);
24
henrika918b5542016-09-19 15:44:09 +020025// Configures an SL_DATAFORMAT_PCM structure based on native audio parameters.
26SLDataFormat_PCM CreatePCMConfiguration(size_t channels,
27 int sample_rate,
28 size_t bits_per_sample);
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000029
henrikab2619892015-05-18 16:49:16 +020030// Helper class for using SLObjectItf interfaces.
31template <typename SLType, typename SLDerefType>
32class ScopedSLObject {
33 public:
34 ScopedSLObject() : obj_(nullptr) {}
35
36 ~ScopedSLObject() { Reset(); }
37
38 SLType* Receive() {
henrikg91d6ede2015-09-17 00:24:34 -070039 RTC_DCHECK(!obj_);
henrikab2619892015-05-18 16:49:16 +020040 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
58typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf;
59
henrika918b5542016-09-19 15:44:09 +020060} // namespace webrtc
henrike@webrtc.org82f014a2013-09-10 18:24:07 +000061
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020062#endif // MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_