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 #include "webrtc/voice_engine/audio_frame_pool.h" |
| 12 |
| 13 namespace webrtc { |
| 14 |
| 15 AudioFramePool::AudioFramePool(size_t capacity) : audio_frame_queue_(capacity) { |
| 16 for (size_t i = 0; i < capacity; ++i) { |
| 17 std::unique_ptr<AudioFrame> audio_frame(new AudioFrame()); |
| 18 Push(std::move(audio_frame)); |
| 19 } |
| 20 RTC_DCHECK_EQ(audio_frame_queue_.Capacity(), capacity); |
| 21 RTC_DCHECK_EQ(audio_frame_queue_.Size(), capacity); |
| 22 } |
| 23 |
| 24 AudioFramePool::~AudioFramePool() = default; |
| 25 |
| 26 void AudioFramePool::Push(std::unique_ptr<AudioFrame> audio_frame) { |
| 27 // Swap "full" audio frame with "empty" in queue. |
| 28 bool result = audio_frame_queue_.Insert(&audio_frame); |
| 29 RTC_DCHECK(result) << "Audio frame pool is full"; |
| 30 // TODO(henrika): shall we verify that we swapped with an "empty" frame? |
| 31 RTC_DCHECK(!audio_frame); |
| 32 } |
| 33 |
| 34 std::unique_ptr<AudioFrame> AudioFramePool::Pop() { |
| 35 // Swap "empty" audio frame with "full" from queue. |
| 36 std::unique_ptr<AudioFrame> audio_frame; |
| 37 bool result = audio_frame_queue_.Remove(&audio_frame); |
| 38 if (!result) { |
| 39 // TODO(henrika): if we ever enter this state, it means that audio has been |
| 40 // recorded but we can't ask the pool for frames to place the audio in. |
| 41 // Hence, recorded audio samples will be dropped. |
| 42 LOG(LS_ERROR) << "Audio frame pool is empty"; |
| 43 } |
| 44 if (size() < min_size_) { |
| 45 min_size_ = size(); |
| 46 LOG(INFO) << "min size: " << min_size_; |
| 47 } |
| 48 return audio_frame; |
| 49 } |
| 50 |
| 51 } // namespace webrtc |
OLD | NEW |