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

Unified Diff: media/base/audio_block_fifo_unittest.cc

Issue 557693003: Dynamically allocate more memory to AudioBlockFifo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed the comments and added unittests. Created 6 years, 3 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
« media/base/audio_block_fifo.cc ('K') | « media/base/audio_block_fifo.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_block_fifo_unittest.cc
diff --git a/media/base/audio_block_fifo_unittest.cc b/media/base/audio_block_fifo_unittest.cc
index 8e8b5e071521896dfc2e0ef953ef1f1e02125165..a5a847d136148dff98759e8dfb2083e673102216 100644
--- a/media/base/audio_block_fifo_unittest.cc
+++ b/media/base/audio_block_fifo_unittest.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/time/time.h"
+#include "media/audio/audio_power_monitor.h"
#include "media/base/audio_block_fifo.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -17,7 +19,7 @@ class AudioBlockFifoTest : public testing::Test {
const int bytes_per_sample = 2;
const int data_byte_size = bytes_per_sample * channels * frames_to_push;
scoped_ptr<uint8[]> data(new uint8[data_byte_size]);
- memset(data.get(), 0, data_byte_size);
+ memset(data.get(), 1, data_byte_size);
for (int filled_frames = max_frames - fifo->GetUnfilledFrames();
filled_frames + frames_to_push <= max_frames;) {
@@ -29,6 +31,19 @@ class AudioBlockFifoTest : public testing::Test {
}
}
+ void ConsumeAndVerify(AudioBlockFifo* fifo, int expected_unfilled_frames,
+ int expected_available_blocks) {
+ const AudioBus* bus = fifo->Consume();
+ EXPECT_EQ(fifo->GetUnfilledFrames(), expected_unfilled_frames);
+ EXPECT_EQ(fifo->available_blocks(), expected_available_blocks);
+ const int dummy_sample_rate = 44100;
+ AudioPowerMonitor audio_level(dummy_sample_rate,
DaleCurtis 2014/09/16 19:36:53 This is kind of confusing, I'd just check for non-
no longer working on chromium 2014/09/18 12:42:49 Done, now it only checks the value.
+ base::TimeDelta::FromMilliseconds(10));
+ audio_level.Scan(*bus, bus->frames());
+ std::pair<float, bool> power = audio_level.ReadCurrentPowerAndClip();
+ EXPECT_NE(power.first, AudioPowerMonitor::zero_power());
+ }
+
private:
DISALLOW_COPY_AND_ASSIGN(AudioBlockFifoTest);
};
@@ -146,4 +161,55 @@ TEST_F(AudioBlockFifoTest, PushAndConsumeOneBlockFifo) {
EXPECT_TRUE(fifo.GetUnfilledFrames() == frames);
}
+// Dynamically increase the capacity of FIFO and verify buffers are correct.
+TEST_F(AudioBlockFifoTest, DynamicallyIncreaseCapacity) {
+ // Create a FIFO with default blocks of buffers.
+ const int channels = 2;
+ const int frames = 441;
+ const int default_blocks = 2;
+ AudioBlockFifo fifo(channels, frames, default_blocks);
+ PushAndVerify(&fifo, frames, channels, frames, frames * default_blocks);
+ EXPECT_TRUE(fifo.GetUnfilledFrames() == 0);
+ EXPECT_TRUE(fifo.available_blocks() == default_blocks);
+
+ // Increase the capacity dynamically for the first time.
+ const int new_blocks_1 = 3;
+ fifo.IncreaseCapacity(new_blocks_1);
+ int expected_unfilled_frames = new_blocks_1 * frames;
+ int expected_available_blocks = default_blocks;
+ EXPECT_EQ(fifo.GetUnfilledFrames(), expected_unfilled_frames);
+ EXPECT_EQ(fifo.available_blocks(), expected_available_blocks);
+
+ // Verify the previous buffer is not affected by the dynamic capacity
+ // increment.
+ expected_unfilled_frames = (new_blocks_1 + 1) * frames;
+ expected_available_blocks = default_blocks - 1;
+ ConsumeAndVerify(&fifo, expected_unfilled_frames, expected_available_blocks);
+
+ // Fill another |new_blocks_1 + 0.5| blocks of data to the FIFO.
+ const int frames_to_push = static_cast<int>((new_blocks_1 + 0.5) * frames);
+ int max_frames = frames * (default_blocks + new_blocks_1);
+ PushAndVerify(&fifo, frames_to_push, channels, frames, max_frames);
+ expected_unfilled_frames = max_frames - frames - frames_to_push;
+ expected_available_blocks = new_blocks_1 + 1;
+ EXPECT_EQ(fifo.GetUnfilledFrames(), expected_unfilled_frames);
+ EXPECT_EQ(fifo.available_blocks(), expected_available_blocks);
+
+ // Increase the capacity dynamically for the second time.
+ const int new_blocks_2 = 2;
+ fifo.IncreaseCapacity(new_blocks_2);
+ expected_unfilled_frames += new_blocks_2 * frames;
+ EXPECT_EQ(fifo.GetUnfilledFrames(), expected_unfilled_frames);
+ EXPECT_EQ(fifo.available_blocks(), expected_available_blocks);
+
+ // Verify the previous buffers are not affected by the dynamic capacity
+ // increment.
+ for (int i = 1; i <= expected_available_blocks; ++i) {
+ expected_unfilled_frames += frames;
+ expected_available_blocks -= 1;
+ ConsumeAndVerify(&fifo, expected_unfilled_frames,
+ expected_available_blocks);
+ }
+}
+
} // namespace media
« media/base/audio_block_fifo.cc ('K') | « media/base/audio_block_fifo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698