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

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: test 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
« no previous file with comments | « media/base/audio_pull_fifo.cc ('k') | media/media.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/stringprintf.h"
8 #include "media/base/audio_pull_fifo.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace media {
12
13 // Block diagram of a possible real-world usage:
14 //
15 // | Producer | ----> | AudioPullFifo | ----> | Consumer |
16 // push pull
17 // 2048 ----> (2048) ----> ~512
18
19 // Number of channels in each audio bus.
20 static int kChannels = 2;
21
22 // Max number of audio framed the FIFO can contain.
23 static const int kMaxFramesInFifo = 2048;
24
25 class AudioPullFifoTest
26 : public testing::TestWithParam<int> {
27 public:
28 AudioPullFifoTest()
29 : pull_fifo_(kChannels, kMaxFramesInFifo, base::Bind(
30 &AudioPullFifoTest::ProvideInput, base::Unretained(this))),
31 audio_bus_(AudioBus::Create(kChannels, kMaxFramesInFifo)),
32 fill_value_(0) {}
33 virtual ~AudioPullFifoTest() {}
34
35 void VerifyValue(const float data[], int size, float start_value) {
36 float value = start_value;
37 for (int i = 0; i < size; ++i) {
38 ASSERT_FLOAT_EQ(value++, data[i]) << "i=" << i;
39 }
40 }
41
42 // Consume data using different sizes, acquire audio frames from the FIFO
43 // and verify that the retrieved values matches the values written by the
44 // producer.
45 void ConsumeTest(int frames_to_consume) {
46 int start_value = 0;
47 SCOPED_TRACE(base::StringPrintf("Checking frames_to_consume %d",
48 frames_to_consume));
49 pull_fifo_.Consume(audio_bus_.get(), frames_to_consume);
50 for (int j = 0; j < kChannels; ++j) {
51 VerifyValue(audio_bus_->channel(j), frames_to_consume, start_value);
52 }
53 start_value += frames_to_consume;
54 }
55
56 // AudioPullFifo::ReadCB implementation where we increase a value for each
57 // audio frame that we provide. Note that all channels are given the same
58 // value to simplify the verification.
59 virtual void ProvideInput(AudioBus* audio_bus) {
60 EXPECT_EQ(audio_bus->channels(), audio_bus_->channels());
61 EXPECT_EQ(audio_bus->frames(), kMaxFramesInFifo);
62 for (int i = 0; i < audio_bus->frames(); ++i) {
63 for (int j = 0; j < audio_bus->channels(); ++j) {
64 // Store same value in all channels.
65 audio_bus->channel(j)[i] = fill_value_;
66 }
67 fill_value_++;
68 }
69 }
70
71 protected:
72 AudioPullFifo pull_fifo_;
73 scoped_ptr<AudioBus> audio_bus_;
74 int fill_value_;
75
76 DISALLOW_COPY_AND_ASSIGN(AudioPullFifoTest);
77 };
78
79 TEST_P(AudioPullFifoTest, Consume) {
80 ConsumeTest(GetParam());
81 }
82
83 // Test common |frames_to_consume| values which will be used as input
84 // parameter to AudioPullFifo::Consume() when the consumer asks for data.
85 INSTANTIATE_TEST_CASE_P(
86 AudioPullFifoTest, AudioPullFifoTest,
87 testing::Values(544, 512, 512, 512, 512, 2048, 544, 441, 440, 433, 500));
88
89 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_pull_fifo.cc ('k') | media/media.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698