opensles_util.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef MEDIA_AUDIO_ANDROID_OPENSLES_UTIL_H_ 6#define MEDIA_AUDIO_ANDROID_OPENSLES_UTIL_H_ 7 8#include <SLES/OpenSLES.h> 9 10#include "base/logging.h" 11 12namespace media { 13 14template <typename SLType, typename SLDerefType> 15class ScopedSLObject { 16 public: 17 ScopedSLObject() : obj_(NULL) {} 18 19 ~ScopedSLObject() { Reset(); } 20 21 SLType* Receive() { 22 DCHECK(!obj_); 23 return &obj_; 24 } 25 26 SLDerefType operator->() { return *obj_; } 27 28 SLType Get() const { return obj_; } 29 30 void Reset() { 31 if (obj_) { 32 (*obj_)->Destroy(obj_); 33 obj_ = NULL; 34 } 35 } 36 37 private: 38 SLType obj_; 39}; 40 41typedef ScopedSLObject<SLObjectItf, const SLObjectItf_*> ScopedSLObjectItf; 42 43} // namespace media 44 45#endif // MEDIA_AUDIO_ANDROID_OPENSLES_UTIL_H_ 46