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