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 WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_SINGLE_RW_FIFO_H_ 12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_SINGLE_RW_FIFO_H_ 13 14 #include "webrtc/base/scoped_ptr.h" 15 #include "webrtc/system_wrappers/interface/atomic32.h" 16 #include "webrtc/typedefs.h" 17 18 namespace webrtc { 19 20 // Implements a lock-free FIFO losely based on 21 // http://src.chromium.org/viewvc/chrome/trunk/src/media/base/audio_fifo.cc 22 // Note that this class assumes there is one producer (writer) and one 23 // consumer (reader) thread. 24 class SingleRwFifo { 25 public: 26 explicit SingleRwFifo(int capacity); 27 ~SingleRwFifo(); 28 29 void Push(int8_t* mem); 30 int8_t* Pop(); 31 32 void Clear(); 33 34 int size() { return size_.Value(); } 35 int capacity() const { return capacity_; } 36 37 private: 38 rtc::scoped_ptr<int8_t* []> queue_; 39 int capacity_; 40 41 Atomic32 size_; 42 43 int read_pos_; 44 int write_pos_; 45 }; 46 47 } // namespace webrtc 48 49 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_SINGLE_RW_FIFO_H_ 50