OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 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_VOICE_ENGINE_AUDIO_FRAME_POOL_H_ |
| 12 #define WEBRTC_VOICE_ENGINE_AUDIO_FRAME_POOL_H_ |
| 13 |
| 14 #include <limits> |
| 15 #include <memory> |
| 16 #include <utility> |
| 17 |
| 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/constructormagic.h" |
| 20 #include "webrtc/base/logging.h" |
| 21 #include "webrtc/base/swap_queue.h" |
| 22 #include "webrtc/modules/include/module_common_types.h" |
| 23 |
| 24 namespace webrtc { |
| 25 |
| 26 // Wraps usage of SwapQueue and creates a queue of allocated audio frames. |
| 27 // The user can then add or remove audio frames in an efficient manner and |
| 28 // thereby avoid continus resource allocations. |
| 29 class AudioFramePool { |
| 30 public: |
| 31 // Creates and allocates resources for a pool of |capacity| elements. |
| 32 explicit AudioFramePool(size_t capacity); |
| 33 ~AudioFramePool(); |
| 34 |
| 35 // Number of elements in the pool. |
| 36 size_t size() const { return audio_frame_queue_.Size(); } |
| 37 |
| 38 // Adds an audio frame to the pool. |
| 39 void Push(std::unique_ptr<AudioFrame> audio_frame); |
| 40 |
| 41 // Returns an audio frame from the pool. |
| 42 std::unique_ptr<AudioFrame> Pop(); |
| 43 |
| 44 private: |
| 45 // The internal swap queue is thread safe. Hence, not adding any extra locks |
| 46 // in this wrapper even if consumer and producer are on separate threads. |
| 47 SwapQueue<std::unique_ptr<AudioFrame>> audio_frame_queue_; |
| 48 |
| 49 // Tracks minimum size (number of elements). Used for debugging purposes |
| 50 // to find a suitable capacity. |
| 51 size_t min_size_ = std::numeric_limits<std::size_t>::max(); |
| 52 |
| 53 RTC_DISALLOW_COPY_AND_ASSIGN(AudioFramePool); |
| 54 }; |
| 55 |
| 56 } // namespace webrtc |
| 57 |
| 58 #endif // WEBRTC_VOICE_ENGINE_AUDIO_FRAME_POOL_H_ |
OLD | NEW |