diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-10 16:25:34 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-10 16:25:34 +0000 |
commit | 52dd877e7341b9b78fb58cef41ac886744b6a78f (patch) | |
tree | 6cedb769757555bbfe2c98a7134ec6cc0192efd7 /media/base/audio_fifo_unittest.cc | |
parent | 9567f9cc4114c1f004aa57a5cb166f07e9c86693 (diff) | |
download | chromium_src-52dd877e7341b9b78fb58cef41ac886744b6a78f.zip chromium_src-52dd877e7341b9b78fb58cef41ac886744b6a78f.tar.gz chromium_src-52dd877e7341b9b78fb58cef41ac886744b6a78f.tar.bz2 |
Adds media::AudioPullFifo class to Chrome.
A FIFO (First In First Out) buffer to handle mismatches in buffer sizes
between a provider and consumer. The consumer will pull data from this FIFO.
If data is already available in the FIFO, it is provided to the consumer.
If insufficient data is available to satisfy the request, the FIFO will ask
the provider for more data to fulfill a request.
Patch by henrika@chromium.org:
http://codereview.chromium.org/10915123/
BUG=none
TEST=--gtest_filter=AudioPullFifoTest.*
TBR=henrika
Review URL: https://chromiumcodereview.appspot.com/10914178
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155744 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/audio_fifo_unittest.cc')
-rw-r--r-- | media/base/audio_fifo_unittest.cc | 112 |
1 files changed, 46 insertions, 66 deletions
diff --git a/media/base/audio_fifo_unittest.cc b/media/base/audio_fifo_unittest.cc index 00b642b..dd5ffd9 100644 --- a/media/base/audio_fifo_unittest.cc +++ b/media/base/audio_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. +// TODO(henrika): add test which included |start_frame| in Consume() call. + #include "media/base/audio_fifo.h" #include "testing/gtest/include/gtest/gtest.h" @@ -26,11 +28,10 @@ TEST_F(AudioFifoTest, Construct) { static const int kChannels = 6; static const int kMaxFrameCount = 128; AudioFifo fifo(kChannels, kMaxFrameCount); - EXPECT_EQ(fifo.frames_in_fifo(), 0); + EXPECT_EQ(fifo.frames(), 0); } // Pushes audio bus objects to a FIFO and fill it up to different degrees. -// Also, verify that it is not possible to overflow the FIFO. TEST_F(AudioFifoTest, Push) { static const int kChannels = 2; static const int kMaxFrameCount = 128; @@ -38,65 +39,50 @@ TEST_F(AudioFifoTest, Push) { { SCOPED_TRACE("Push 50%"); scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount / 2); - EXPECT_EQ(fifo.frames_in_fifo(), 0); - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), bus->frames()); + EXPECT_EQ(fifo.frames(), 0); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), bus->frames()); fifo.Clear(); } { SCOPED_TRACE("Push 100%"); scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount); - EXPECT_EQ(fifo.frames_in_fifo(), 0); - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), bus->frames()); + EXPECT_EQ(fifo.frames(), 0); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), bus->frames()); fifo.Clear(); } - { - SCOPED_TRACE("Overflow"); - scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount + 1); - EXPECT_EQ(fifo.frames_in_fifo(), 0); - EXPECT_FALSE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), 0); - } } // Consumes audio bus objects from a FIFO and empty it to different degrees. -// Also, verify that it is not possible to ask for more data than the FIFO -// contains (corresponds to underrun). TEST_F(AudioFifoTest, Consume) { static const int kChannels = 2; static const int kMaxFrameCount = 128; AudioFifo fifo(kChannels, kMaxFrameCount); { scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount); - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), kMaxFrameCount); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), kMaxFrameCount); } { SCOPED_TRACE("Consume 50%"); scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount / 2); - EXPECT_TRUE(fifo.Consume(bus.get(), bus->frames())); - EXPECT_TRUE(fifo.frames_in_fifo() == bus->frames()); - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), kMaxFrameCount); + fifo.Consume(bus.get(), 0, bus->frames()); + EXPECT_TRUE(fifo.frames() == bus->frames()); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), kMaxFrameCount); } { SCOPED_TRACE("Consume 100%"); scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount); - EXPECT_TRUE(fifo.Consume(bus.get(), bus->frames())); - EXPECT_EQ(fifo.frames_in_fifo(), 0); - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), kMaxFrameCount); - } - { - SCOPED_TRACE("Underrun"); - scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kMaxFrameCount + 1); - EXPECT_FALSE(fifo.Consume(bus.get(), bus->frames())); - EXPECT_EQ(fifo.frames_in_fifo(), kMaxFrameCount); + fifo.Consume(bus.get(), 0, bus->frames()); + EXPECT_EQ(fifo.frames(), 0); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), kMaxFrameCount); } } -// Verify that the frames_in_fifo() method of the FIFO works as intended while +// Verify that the frames() method of the FIFO works as intended while // appending and removing audio bus elements to/from the FIFO. TEST_F(AudioFifoTest, FramesInFifo) { static const int kChannels = 2; @@ -107,25 +93,19 @@ TEST_F(AudioFifoTest, FramesInFifo) { // one audio frame each time. scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, 1); int n = 0; - while (fifo.frames_in_fifo() < kMaxFrameCount) { - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), ++n); + while (fifo.frames() < kMaxFrameCount) { + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), ++n); } - - // Ensure that we can't append more data when the FIFO is full. - EXPECT_EQ(fifo.frames_in_fifo(), kMaxFrameCount); - EXPECT_FALSE(fifo.Push(bus.get())); + EXPECT_EQ(fifo.frames(), kMaxFrameCount); // Empty the FIFO and verify that the size decreases as it should. // Reduce the size of the FIFO by one frame each time. - while (fifo.frames_in_fifo() > 0) { - EXPECT_TRUE(fifo.Consume(bus.get(), bus->frames())); - EXPECT_EQ(fifo.frames_in_fifo(), --n); + while (fifo.frames() > 0) { + fifo.Consume(bus.get(), 0, bus->frames()); + EXPECT_EQ(fifo.frames(), --n); } - - // Ensure that we can't remove more data when the FIFO is empty. - EXPECT_EQ(fifo.frames_in_fifo(), 0); - EXPECT_FALSE(fifo.Consume(bus.get(), bus->frames())); + EXPECT_EQ(fifo.frames(), 0); // Verify that a steady-state size of #frames in the FIFO is maintained // during a sequence of Push/Consume calls which involves wrapping. We ensure @@ -134,12 +114,12 @@ TEST_F(AudioFifoTest, FramesInFifo) { scoped_ptr<AudioBus> bus2 = AudioBus::Create(kChannels, (kMaxFrameCount / 4) - 1); const int frames_in_fifo = bus2->frames(); - EXPECT_TRUE(fifo.Push(bus2.get())); - EXPECT_EQ(fifo.frames_in_fifo(), frames_in_fifo); + fifo.Push(bus2.get()); + EXPECT_EQ(fifo.frames(), frames_in_fifo); for (int n = 0; n < kMaxFrameCount; ++n) { - EXPECT_TRUE(fifo.Push(bus2.get())); - EXPECT_TRUE(fifo.Consume(bus2.get(), frames_in_fifo)); - EXPECT_EQ(fifo.frames_in_fifo(), frames_in_fifo); + fifo.Push(bus2.get()); + fifo.Consume(bus2.get(), 0, frames_in_fifo); + EXPECT_EQ(fifo.frames(), frames_in_fifo); } } @@ -153,23 +133,23 @@ TEST_F(AudioFifoTest, VerifyDataValues) { AudioFifo fifo(kChannels, kFifoFrameCount); scoped_ptr<AudioBus> bus = AudioBus::Create(kChannels, kFrameCount); - EXPECT_EQ(fifo.frames_in_fifo(), 0); + EXPECT_EQ(fifo.frames(), 0); EXPECT_EQ(bus->frames(), kFrameCount); // Start by filling up the FIFO with audio frames. The first audio frame // will contain all 1's, the second all 2's etc. All channels contain the // same value. int value = 1; - while (fifo.frames_in_fifo() < kFifoFrameCount) { + while (fifo.frames() < kFifoFrameCount) { for (int j = 0; j < bus->channels(); ++j) std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value); - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), bus->frames() * value); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), bus->frames() * value); ++value; } // FIFO should be full now. - EXPECT_EQ(fifo.frames_in_fifo(), kFifoFrameCount); + EXPECT_EQ(fifo.frames(), kFifoFrameCount); // Consume all audio frames in the FIFO and verify that the stored values // are correct. In this example, we shall read out: 1, 2, 3, 4, 5 in that @@ -178,8 +158,8 @@ TEST_F(AudioFifoTest, VerifyDataValues) { value = 1; int n = 1; const int frames_to_consume = bus->frames() / 2; - while (fifo.frames_in_fifo() > 0) { - EXPECT_TRUE(fifo.Consume(bus.get(), frames_to_consume)); + while (fifo.frames() > 0) { + fifo.Consume(bus.get(), 0, frames_to_consume); for (int j = 0; j < bus->channels(); ++j) VerifyValue(bus->channel(j), frames_to_consume, value); if (n++ % 2 == 0) @@ -187,26 +167,26 @@ TEST_F(AudioFifoTest, VerifyDataValues) { } // FIFO should be empty now. - EXPECT_EQ(fifo.frames_in_fifo(), 0); + EXPECT_EQ(fifo.frames(), 0); // Push one audio bus to the FIFO and fill it with 1's. value = 1; for (int j = 0; j < bus->channels(); ++j) std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value); - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), bus->frames()); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), bus->frames()); // Keep calling Consume/Push a few rounds and verify that we read out the // correct values. The number of elements shall be fixed (kFrameCount) during // this phase. for (int i = 0; i < 5 * kFifoFrameCount; i++) { - EXPECT_TRUE(fifo.Consume(bus.get(), bus->frames())); + fifo.Consume(bus.get(), 0, bus->frames()); for (int j = 0; j < bus->channels(); ++j) { VerifyValue(bus->channel(j), bus->channels(), value); std::fill(bus->channel(j), bus->channel(j) + bus->frames(), value + 1); } - EXPECT_TRUE(fifo.Push(bus.get())); - EXPECT_EQ(fifo.frames_in_fifo(), bus->frames()); + fifo.Push(bus.get()); + EXPECT_EQ(fifo.frames(), bus->frames()); ++value; } } |