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

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: Added TODOs from Dale 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 // | Provider | ----> | AudioPullFifo | ----> | Consumer |
15 // push pull
16 // 2048 ----> (4096) ----> ~441 [#frames]
17
18 //DaleCurtis 2012/09/07 13:48:38
19 // As noted in my other comments, it's possible the Provider could ask for a 1024
20 // buffer size and the hardware wants a 2048 buffer.
21
22 // Number of channels in each audio bus.
23 static int kChannels = 2;
24
25 // Max number of audio framed the FIFO can contain.
26 static const int kMaxFramesInFifo = 2048;
27
28 // The provider will be asked to provide audio frames of this size by the
29 // consumer.
30 //static const int kReadFramesFromProvider = 2048;
31
32 // Max number of frames the consumer can ask for.
33 static const int kMaxFramesToConsume = 496;
34
35 // List of |frames_to_consume| which will be used as input parameter to
36 // AudioPullFifo::Consume() when the consumer asks for data.
37 // Sum(kConsumeFrames)=5733 and Mean(kConsumeFrames)=441, hence the provider
38 // will be called three times in this example and provide in total 6144 audio
39 // frames.
40 static const int kConsumeFrames[] =
41 {440, 441, 442, 440, 440, 441, 442, 440, 441, 442, 441, 441, 442};
42
43 //DaleCurtis 2012/09/07 13:48:38
44 // SincResampler will actually look something like 544, 512, 512, 512, 512.
45 // So I'd increase the spread on these test values some more.
46
47 class AudioPullFifoTest : public testing::Test {
48 public:
49 AudioPullFifoTest()
50 : audio_bus_(AudioBus::Create(kChannels, kMaxFramesToConsume)),
51 fill_value_(0) {}
52 ~AudioPullFifoTest() {}
53
54 void VerifyValue(const float data[], int size, float start_value) {
55 float value = start_value;
56 for (int i = 0; i < size; ++i) {
57 ASSERT_FLOAT_EQ(value++, data[i]) << "i=" << i;
58 }
59 }
60
61 // AudioPullFifo::ReadCB implementation where we increase a value for each
62 // audio frame that we provide. Note that all channels are given the same
63 // value to simplify the verification.
64 virtual void ProvideInput(AudioBus* audio_bus) {
65 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels());
66 EXPECT_EQ(audio_bus->frames(), kMaxFramesInFifo);
67 for (int i = 0; i < audio_bus->frames(); ++i) {
68 for (int j = 0; j < audio_bus->channels(); ++j) {
69 // Store same value in all channels.
70 audio_bus->channel(j)[i] = fill_value_;
71 }
72 fill_value_++;
73 }
74 }
75
76 protected:
77 scoped_ptr<AudioBus> audio_bus_;
78 int fill_value_;
79
80 DISALLOW_COPY_AND_ASSIGN(AudioPullFifoTest);
81 };
82
83 // Emulate a scenario where the consumer ask for data using the sizes in
84 // kConsumeFrames at each call. The provider is asked to provide input when
85 // the FIFO can't fulfill the request and kReadFramesFromProvider will be
86 // provided in each callback. The provider updates and stores a data value for
87 // each audio frame it provides which makes it possible to verify that the
88 // consumer reads out correct values.
89 TEST_F(AudioPullFifoTest, Consume) {
90 AudioPullFifo pull_fifo(kChannels, kMaxFramesInFifo, base::Bind(
91 &AudioPullFifoTest::ProvideInput, base::Unretained(this)));
92
93 // Consume data using different sizes, acquire audio frames from the FIFO
94 // and verify that the retrieved values matches the values written by the
95 // provider.
96 int start_value = 0;
97 for (int i = 0; i < sizeof(kConsumeFrames) / sizeof(kConsumeFrames[0]); ++i) {
98 int frames_to_consume = kConsumeFrames[i];
99 pull_fifo.Consume(audio_bus_.get(), frames_to_consume);
100 for (int j = 0; j < kChannels; ++j) {
101 VerifyValue(audio_bus_->channel(j), frames_to_consume, start_value);
102 }
103 start_value += frames_to_consume;
104 }
105 }
106
107 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698