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

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

Issue 532303002: Revert of Reland 501823002: Used native deinterleaved and float point format for the input streams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « media/base/audio_block_fifo.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/audio_block_fifo.h" 5 #include "media/base/audio_block_fifo.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace media { 8 namespace media {
9 9
10 class AudioBlockFifoTest : public testing::Test { 10 class AudioBlockFifoTest : public testing::Test {
11 protected: 11 public:
12 AudioBlockFifoTest() {} 12 AudioBlockFifoTest() {}
13 virtual ~AudioBlockFifoTest() {} 13 virtual ~AudioBlockFifoTest() {}
14 14
15 void PushAndVerify(AudioBlockFifo* fifo, int frames_to_push,
16 int channels, int block_frames, int max_frames) {
17 const int bytes_per_sample = 2;
18 const int data_byte_size = bytes_per_sample * channels * frames_to_push;
19 scoped_ptr<uint8[]> data(new uint8[data_byte_size]);
20 memset(data.get(), 0, data_byte_size);
21
22 for (int filled_frames = max_frames - fifo->GetUnfilledFrames();
23 filled_frames + frames_to_push <= max_frames;) {
24 fifo->Push(data.get(), frames_to_push, bytes_per_sample);
25 filled_frames += frames_to_push;
26 EXPECT_EQ(max_frames - filled_frames, fifo->GetUnfilledFrames());
27 EXPECT_EQ(static_cast<int>(filled_frames / block_frames),
28 fifo->available_blocks());
29 }
30 }
31
15 private: 32 private:
16 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifoTest); 33 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifoTest);
17 }; 34 };
18 35
19 class AudioBlockFifoFormatTest : public AudioBlockFifoTest,
20 public testing::WithParamInterface<bool> {
21 protected:
22 void PushAndVerify(AudioBlockFifo* fifo,
23 int frames_to_push,
24 int channels,
25 int block_frames,
26 int max_frames) {
27 const int bytes_per_sample = 2;
28 const int data_byte_size = bytes_per_sample * channels * frames_to_push;
29 if (GetParam()) {
30 scoped_ptr<media::AudioBus> data =
31 AudioBus::Create(channels, frames_to_push);
32 for (int filled_frames = max_frames - fifo->GetUnfilledFrames();
33 filled_frames + frames_to_push <= max_frames;) {
34 fifo->Push(data.get());
35 filled_frames += frames_to_push;
36 EXPECT_EQ(max_frames - filled_frames, fifo->GetUnfilledFrames());
37 EXPECT_EQ(static_cast<int>(filled_frames / block_frames),
38 fifo->available_blocks());
39 }
40 } else {
41 scoped_ptr<uint8[]> data(new uint8[data_byte_size]);
42 memset(data.get(), 0, data_byte_size);
43 for (int filled_frames = max_frames - fifo->GetUnfilledFrames();
44 filled_frames + frames_to_push <= max_frames;) {
45 fifo->Push(data.get(), frames_to_push, bytes_per_sample);
46 filled_frames += frames_to_push;
47 EXPECT_EQ(max_frames - filled_frames, fifo->GetUnfilledFrames());
48 EXPECT_EQ(static_cast<int>(filled_frames / block_frames),
49 fifo->available_blocks());
50 }
51 }
52 }
53 };
54
55 // Verify that construction works as intended. 36 // Verify that construction works as intended.
56 TEST_F(AudioBlockFifoTest, Construct) { 37 TEST_F(AudioBlockFifoTest, Construct) {
57 const int channels = 6; 38 const int channels = 6;
58 const int frames = 128; 39 const int frames = 128;
59 const int blocks = 4; 40 const int blocks = 4;
60 AudioBlockFifo fifo(channels, frames, blocks); 41 AudioBlockFifo fifo(channels, frames, blocks);
61 EXPECT_EQ(0, fifo.available_blocks()); 42 EXPECT_EQ(0, fifo.available_blocks());
62 EXPECT_EQ(frames * blocks, fifo.GetUnfilledFrames()); 43 EXPECT_EQ(frames * blocks, fifo.GetUnfilledFrames());
63 } 44 }
64 45
65 // Pushes audio bus objects to/from a FIFO up to different degrees. 46 // Pushes audio bus objects to/from a FIFO up to different degrees.
66 TEST_P(AudioBlockFifoFormatTest, Push) { 47 TEST_F(AudioBlockFifoTest, Push) {
67 const int channels = 2; 48 const int channels = 2;
68 const int frames = 128; 49 const int frames = 128;
69 const int blocks = 2; 50 const int blocks = 2;
70 AudioBlockFifo fifo(channels, frames, blocks); 51 AudioBlockFifo fifo(channels, frames, blocks);
71 52
72 // Push frames / 2 of data until FIFO is full. 53 // Push frames / 2 of data until FIFO is full.
73 PushAndVerify(&fifo, frames / 2, channels, frames, frames * blocks); 54 PushAndVerify(&fifo, frames / 2, channels, frames, frames * blocks);
74 fifo.Clear(); 55 fifo.Clear();
75 56
76 // Push frames of data until FIFO is full. 57 // Push frames of data until FIFO is full.
77 PushAndVerify(&fifo, frames, channels, frames, frames * blocks); 58 PushAndVerify(&fifo, frames, channels, frames, frames * blocks);
78 fifo.Clear(); 59 fifo.Clear();
79 60
80 // Push 1.5 * frames of data. 61 // Push 1.5 * frames of data.
81 PushAndVerify(&fifo, frames * 1.5, channels, frames, frames * blocks); 62 PushAndVerify(&fifo, frames * 1.5, channels, frames, frames * blocks);
82 fifo.Clear(); 63 fifo.Clear();
83 } 64 }
84 65
85 // Perform a sequence of Push/Consume calls to different degrees, and verify 66 // Perform a sequence of Push/Consume calls to different degrees, and verify
86 // things are correct. 67 // things are correct.
87 TEST_P(AudioBlockFifoFormatTest, PushAndConsume) { 68 TEST_F(AudioBlockFifoTest, PushAndConsume) {
88 const int channels = 2; 69 const int channels = 2;
89 const int frames = 441; 70 const int frames = 441;
90 const int blocks = 4; 71 const int blocks = 4;
91 AudioBlockFifo fifo(channels, frames, blocks); 72 AudioBlockFifo fifo(channels, frames, blocks);
92 PushAndVerify(&fifo, frames, channels, frames, frames * blocks); 73 PushAndVerify(&fifo, frames, channels, frames, frames * blocks);
93 EXPECT_TRUE(fifo.GetUnfilledFrames() == 0); 74 EXPECT_TRUE(fifo.GetUnfilledFrames() == 0);
94 EXPECT_TRUE(fifo.available_blocks() == blocks); 75 EXPECT_TRUE(fifo.available_blocks() == blocks);
95 76
96 // Consume 1 block of data. 77 // Consume 1 block of data.
97 const AudioBus* bus = fifo.Consume(); 78 const AudioBus* bus = fifo.Consume();
(...skipping 14 matching lines...) Expand all
112 EXPECT_TRUE(frames == bus->frames()); 93 EXPECT_TRUE(frames == bus->frames());
113 EXPECT_TRUE(fifo.GetUnfilledFrames() == frames * i); 94 EXPECT_TRUE(fifo.GetUnfilledFrames() == frames * i);
114 EXPECT_TRUE(fifo.available_blocks() == (blocks - i)); 95 EXPECT_TRUE(fifo.available_blocks() == (blocks - i));
115 } 96 }
116 EXPECT_TRUE(fifo.GetUnfilledFrames() == frames * blocks); 97 EXPECT_TRUE(fifo.GetUnfilledFrames() == frames * blocks);
117 EXPECT_TRUE(fifo.available_blocks() == 0); 98 EXPECT_TRUE(fifo.available_blocks() == 0);
118 99
119 fifo.Clear(); 100 fifo.Clear();
120 int new_push_frames = 128; 101 int new_push_frames = 128;
121 // Change the input frame and try to fill up the FIFO. 102 // Change the input frame and try to fill up the FIFO.
122 PushAndVerify(&fifo, new_push_frames, channels, frames, frames * blocks); 103 PushAndVerify(&fifo, new_push_frames, channels, frames,
104 frames * blocks);
123 EXPECT_TRUE(fifo.GetUnfilledFrames() != 0); 105 EXPECT_TRUE(fifo.GetUnfilledFrames() != 0);
124 EXPECT_TRUE(fifo.available_blocks() == blocks - 1); 106 EXPECT_TRUE(fifo.available_blocks() == blocks -1);
125 107
126 // Consume all the existing filled blocks of data. 108 // Consume all the existing filled blocks of data.
127 while (fifo.available_blocks()) { 109 while (fifo.available_blocks()) {
128 const AudioBus* bus = fifo.Consume(); 110 const AudioBus* bus = fifo.Consume();
129 EXPECT_TRUE(channels == bus->channels()); 111 EXPECT_TRUE(channels == bus->channels());
130 EXPECT_TRUE(frames == bus->frames()); 112 EXPECT_TRUE(frames == bus->frames());
131 } 113 }
132 114
133 // Since one block of FIFO has not been completely filled up, there should 115 // Since one block of FIFO has not been completely filled up, there should
134 // be remaining frames. 116 // be remaining frames.
135 const int number_of_push = 117 const int number_of_push =
136 static_cast<int>(frames * blocks / new_push_frames); 118 static_cast<int>(frames * blocks / new_push_frames);
137 const int remain_frames = frames * blocks - fifo.GetUnfilledFrames(); 119 const int remain_frames = frames * blocks - fifo.GetUnfilledFrames();
138 EXPECT_EQ(number_of_push * new_push_frames - frames * (blocks - 1), 120 EXPECT_EQ(number_of_push * new_push_frames - frames * (blocks - 1),
139 remain_frames); 121 remain_frames);
140 122
141 // Completely fill up the buffer again. 123 // Completely fill up the buffer again.
142 new_push_frames = frames * blocks - remain_frames; 124 new_push_frames = frames * blocks - remain_frames;
143 PushAndVerify(&fifo, new_push_frames, channels, frames, frames * blocks); 125 PushAndVerify(&fifo, new_push_frames, channels, frames,
126 frames * blocks);
144 EXPECT_TRUE(fifo.GetUnfilledFrames() == 0); 127 EXPECT_TRUE(fifo.GetUnfilledFrames() == 0);
145 EXPECT_TRUE(fifo.available_blocks() == blocks); 128 EXPECT_TRUE(fifo.available_blocks() == blocks);
146 } 129 }
147 130
148 // Perform a sequence of Push/Consume calls to a 1 block FIFO. 131 // Perform a sequence of Push/Consume calls to a 1 block FIFO.
149 TEST_P(AudioBlockFifoFormatTest, PushAndConsumeOneBlockFifo) { 132 TEST_F(AudioBlockFifoTest, PushAndConsumeOneBlockFifo) {
150 static const int channels = 2; 133 static const int channels = 2;
151 static const int frames = 441; 134 static const int frames = 441;
152 static const int blocks = 1; 135 static const int blocks = 1;
153 AudioBlockFifo fifo(channels, frames, blocks); 136 AudioBlockFifo fifo(channels, frames, blocks);
154 PushAndVerify(&fifo, frames, channels, frames, frames * blocks); 137 PushAndVerify(&fifo, frames, channels, frames, frames * blocks);
155 EXPECT_TRUE(fifo.GetUnfilledFrames() == 0); 138 EXPECT_TRUE(fifo.GetUnfilledFrames() == 0);
156 EXPECT_TRUE(fifo.available_blocks() == blocks); 139 EXPECT_TRUE(fifo.available_blocks() == blocks);
157 140
158 // Consume 1 block of data. 141 // Consume 1 block of data.
159 const AudioBus* bus = fifo.Consume(); 142 const AudioBus* bus = fifo.Consume();
160 EXPECT_TRUE(channels == bus->channels()); 143 EXPECT_TRUE(channels == bus->channels());
161 EXPECT_TRUE(frames == bus->frames()); 144 EXPECT_TRUE(frames == bus->frames());
162 EXPECT_TRUE(fifo.available_blocks() == 0); 145 EXPECT_TRUE(fifo.available_blocks() == 0);
163 EXPECT_TRUE(fifo.GetUnfilledFrames() == frames); 146 EXPECT_TRUE(fifo.GetUnfilledFrames() == frames);
164 } 147 }
165 148
166 INSTANTIATE_TEST_CASE_P(AudioBlockFifoTests,
167 AudioBlockFifoFormatTest,
168 ::testing::Values(false, true));
169
170 } // namespace media 149 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_block_fifo.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698