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

Side by Side Diff: media/base/audio_pull_fifo_unittest.cc

Issue 10915123: Adds media::AudioPullFifo class to Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now builds on all platforms Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "media/base/audio_pull_fifo.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace media {
11
12 // Block diagram of a possible real-world usage:
13 //
14 // | Producer | ----> | AudioPullFifo | ----> | Consumer |
15 // push pull
16 // 2048 ----> (2048) ----> ~512
17
18 // Number of channels in each audio bus.
19 static int kChannels = 2;
20
21 // Max number of audio framed the FIFO can contain.
22 static const int kMaxFramesInFifo = 2048;
23
24 // List of |frames_to_consume| which will be used as input parameter to
25 // AudioPullFifo::Consume() when the consumer asks for data.
26 static const int kConsumeFrames[] =
DaleCurtis 2012/09/10 08:28:26 How long does this take to run? We can probably cu
henrika (OOO until Aug 14) 2012/09/10 09:35:31 It takes ~10ms on my machine. Will keep as is.
27 {544, 512, 512, 512, 512, 2048, 544, 441, 442, 467, 540, 440, 433, 500};
28
29 class AudioPullFifoTest : public testing::Test {
30 public:
31 AudioPullFifoTest()
32 : audio_bus_(AudioBus::Create(kChannels, kMaxFramesInFifo)),
33 fill_value_(0) {}
34 virtual ~AudioPullFifoTest() {}
35
36 void VerifyValue(const float data[], int size, float start_value) {
37 float value = start_value;
38 for (int i = 0; i < size; ++i) {
39 ASSERT_FLOAT_EQ(value++, data[i]) << "i=" << i;
40 }
41 }
42
43 // AudioPullFifo::ReadCB implementation where we increase a value for each
44 // audio frame that we provide. Note that all channels are given the same
45 // value to simplify the verification.
46 virtual void ProvideInput(AudioBus* audio_bus) {
47 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels());
48 EXPECT_EQ(audio_bus->frames(), kMaxFramesInFifo);
49 for (int i = 0; i < audio_bus->frames(); ++i) {
50 for (int j = 0; j < audio_bus->channels(); ++j) {
51 // Store same value in all channels.
52 audio_bus->channel(j)[i] = fill_value_;
53 }
54 fill_value_++;
55 }
56 }
57
58 protected:
59 scoped_ptr<AudioBus> audio_bus_;
60 int fill_value_;
61
62 DISALLOW_COPY_AND_ASSIGN(AudioPullFifoTest);
63 };
64
65 // Emulate a scenario where the consumer ask for data using the sizes in
66 // kConsumeFrames at each call. The producer is asked to provide input when
67 // the FIFO can't fulfill the request and kReadFramesFromProvider will be
68 // provided in each callback. The producer updates and stores a data value for
69 // each audio frame it provides which makes it possible to verify that the
70 // consumer reads out correct values.
71 TEST_F(AudioPullFifoTest, Consume) {
DaleCurtis 2012/09/10 08:28:26 Instead of using an array of test values like this
henrika (OOO until Aug 14) 2012/09/10 09:35:31 Nice tip; did not know about it. Will modify.
72 AudioPullFifo pull_fifo(kChannels, kMaxFramesInFifo, base::Bind(
73 &AudioPullFifoTest::ProvideInput, base::Unretained(this)));
74
75 // Consume data using different sizes, acquire audio frames from the FIFO
76 // and verify that the retrieved values matches the values written by the
77 // producer.
78 int start_value = 0;
79 for (size_t i = 0; i < arraysize(kConsumeFrames); ++i) {
80 int frames_to_consume = kConsumeFrames[i];
DaleCurtis 2012/09/10 08:28:26 SCOPED_TRACE() with the kConsumeFrames information
henrika (OOO until Aug 14) 2012/09/10 09:35:31 Thanks.
81 pull_fifo.Consume(audio_bus_.get(), frames_to_consume);
82 for (int j = 0; j < kChannels; ++j) {
83 VerifyValue(audio_bus_->channel(j), frames_to_consume, start_value);
84 }
85 start_value += frames_to_consume;
86 }
87 }
88
89 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698