| Index: webrtc/voice_engine/audio_frame_pool.cc
|
| diff --git a/webrtc/voice_engine/audio_frame_pool.cc b/webrtc/voice_engine/audio_frame_pool.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..fd4b1ed66a593a33f9b786f8e42a591ccca6c332
|
| --- /dev/null
|
| +++ b/webrtc/voice_engine/audio_frame_pool.cc
|
| @@ -0,0 +1,51 @@
|
| +/*
|
| + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license
|
| + * that can be found in the LICENSE file in the root of the source
|
| + * tree. An additional intellectual property rights grant can be found
|
| + * in the file PATENTS. All contributing project authors may
|
| + * be found in the AUTHORS file in the root of the source tree.
|
| + */
|
| +
|
| +#include "webrtc/voice_engine/audio_frame_pool.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +AudioFramePool::AudioFramePool(size_t capacity) : audio_frame_queue_(capacity) {
|
| + for (size_t i = 0; i < capacity; ++i) {
|
| + std::unique_ptr<AudioFrame> audio_frame(new AudioFrame());
|
| + Push(std::move(audio_frame));
|
| + }
|
| + RTC_DCHECK_EQ(audio_frame_queue_.Capacity(), capacity);
|
| + RTC_DCHECK_EQ(audio_frame_queue_.Size(), capacity);
|
| +}
|
| +
|
| +AudioFramePool::~AudioFramePool() = default;
|
| +
|
| +void AudioFramePool::Push(std::unique_ptr<AudioFrame> audio_frame) {
|
| + // Swap "full" audio frame with "empty" in queue.
|
| + bool result = audio_frame_queue_.Insert(&audio_frame);
|
| + RTC_DCHECK(result) << "Audio frame pool is full";
|
| + // TODO(henrika): shall we verify that we swapped with an "empty" frame?
|
| + RTC_DCHECK(!audio_frame);
|
| +}
|
| +
|
| +std::unique_ptr<AudioFrame> AudioFramePool::Pop() {
|
| + // Swap "empty" audio frame with "full" from queue.
|
| + std::unique_ptr<AudioFrame> audio_frame;
|
| + bool result = audio_frame_queue_.Remove(&audio_frame);
|
| + if (!result) {
|
| + // TODO(henrika): if we ever enter this state, it means that audio has been
|
| + // recorded but we can't ask the pool for frames to place the audio in.
|
| + // Hence, recorded audio samples will be dropped.
|
| + LOG(LS_ERROR) << "Audio frame pool is empty";
|
| + }
|
| + if (size() < min_size_) {
|
| + min_size_ = size();
|
| + LOG(INFO) << "min size: " << min_size_;
|
| + }
|
| + return audio_frame;
|
| +}
|
| +
|
| +} // namespace webrtc
|
|
|