• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_
12 #define MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_
13 
14 #include <SLES/OpenSLES.h>
15 #include <stddef.h>
16 
17 #include "rtc_base/checks.h"
18 
19 namespace webrtc {
20 
21 // Returns a string representation given an integer SL_RESULT_XXX code.
22 // The mapping can be found in <SLES/OpenSLES.h>.
23 const char* GetSLErrorString(size_t code);
24 
25 // Configures an SL_DATAFORMAT_PCM structure based on native audio parameters.
26 SLDataFormat_PCM CreatePCMConfiguration(size_t channels,
27                                         int sample_rate,
28                                         size_t bits_per_sample);
29 
30 // Helper class for using SLObjectItf interfaces.
31 template <typename SLType, typename SLDerefType>
32 class ScopedSLObject {
33  public:
ScopedSLObject()34   ScopedSLObject() : obj_(nullptr) {}
35 
~ScopedSLObject()36   ~ScopedSLObject() { Reset(); }
37 
Receive()38   SLType* Receive() {
39     RTC_DCHECK(!obj_);
40     return &obj_;
41   }
42 
43   SLDerefType operator->() { return *obj_; }
44 
Get()45   SLType Get() const { return obj_; }
46 
Reset()47   void Reset() {
48     if (obj_) {
49       (*obj_)->Destroy(obj_);
50       obj_ = nullptr;
51     }
52   }
53 
54  private:
55   SLType obj_;
56 };
57 
58 typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf;
59 
60 }  // namespace webrtc
61 
62 #endif  // MODULES_AUDIO_DEVICE_ANDROID_OPENSLES_COMMON_H_
63