Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Unified Diff: webrtc/voice_engine/audio_frame_pool.cc

Issue 2665693002: Moves channel-dependent audio input processing to separate encoder task queue (Closed)
Patch Set: Increased prio of queue Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698