OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "platform/audio/PushPullFIFO.h" | 5 #include "platform/audio/PushPullFIFO.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <vector> | 8 #include <vector> |
9 #include "platform/audio/AudioUtilities.h" | 9 #include "platform/audio/AudioUtilities.h" |
10 #include "platform/testing/TestingPlatformSupport.h" | 10 #include "platform/testing/TestingPlatformSupport.h" |
| 11 #include "platform/wtf/Functional.h" |
| 12 #include "platform/heap/Persistent.h" |
11 #include "platform/wtf/PtrUtil.h" | 13 #include "platform/wtf/PtrUtil.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 | 15 |
14 namespace blink { | 16 namespace blink { |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 // Check the basic contract of FIFO. | 20 // Check the basic contract of FIFO. |
19 TEST(PushPullFIFOBasicTest, BasicTests) { | 21 TEST(PushPullFIFOBasicTest, BasicTests) { |
20 // This suppresses the multi-thread warning for GTest. Potently it increases | 22 // This suppresses the multi-thread warning for GTest. Potently it increases |
21 // the test execution time, but this specific test is very short and simple. | 23 // the test execution time, but this specific test is very short and simple. |
22 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; | 24 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
23 | 25 |
24 // FIFO length exceeding the maximum length allowed will cause crash. | 26 // FIFO length exceeding the maximum length allowed will cause crash. |
25 // i.e.) m_fifoLength <= kMaxFIFOLength | 27 // i.e.) m_fifoLength <= kMaxFIFOLength |
26 EXPECT_DEATH(new PushPullFIFO(2, PushPullFIFO::kMaxFIFOLength + 1), ""); | 28 EXPECT_DEATH(new PushPullFIFO(2, PushPullFIFO::kMaxFIFOLength + 1), ""); |
27 | 29 |
28 std::unique_ptr<PushPullFIFO> test_fifo = | 30 std::unique_ptr<PushPullFIFO> test_fifo = |
29 WTF::WrapUnique(new PushPullFIFO(2, 1024)); | 31 WTF::WrapUnique(new PushPullFIFO(2, 1024)); |
30 | 32 |
31 // The input bus length must be |AudioUtilities::kRenderQuantumFrames|. | 33 // The input bus length must be |AudioUtilities::kRenderQuantumFrames|. |
32 // i.e.) inputBus->length() == kRenderQuantumFrames | 34 // i.e.) inputBus->length() == kRenderQuantumFrames |
33 RefPtr<AudioBus> input_bus_of129_frames = | 35 RefPtr<AudioBus> input_bus_129_frames = |
34 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames + 1); | 36 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames + 1); |
35 EXPECT_DEATH(test_fifo->Push(input_bus_of129_frames.Get()), ""); | 37 EXPECT_DEATH(test_fifo->Push(input_bus_129_frames.Get()), ""); |
36 RefPtr<AudioBus> input_bus_of127_frames = | 38 RefPtr<AudioBus> input_bus_127_frames = |
37 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames - 1); | 39 AudioBus::Create(2, AudioUtilities::kRenderQuantumFrames - 1); |
38 EXPECT_DEATH(test_fifo->Push(input_bus_of127_frames.Get()), ""); | 40 EXPECT_DEATH(test_fifo->Push(input_bus_127_frames.Get()), ""); |
39 | 41 |
40 // Pull request frames cannot exceed the length of output bus. | 42 // Pull request frames cannot exceed the length of output bus. |
41 // i.e.) framesRequested <= outputBus->length() | 43 // i.e.) framesRequested <= outputBus->length() |
42 RefPtr<AudioBus> output_bus_of512_frames = AudioBus::Create(2, 512); | 44 RefPtr<AudioBus> output_bus_512_frames = AudioBus::Create(2, 512); |
43 EXPECT_DEATH(test_fifo->Pull(output_bus_of512_frames.Get(), 513), ""); | 45 EXPECT_DEATH(test_fifo->Pull(output_bus_512_frames.Get(), 513), ""); |
44 | 46 |
45 // Pull request frames cannot exceed the length of FIFO. | 47 // Pull request frames cannot exceed the length of FIFO. |
46 // i.e.) framesRequested <= m_fifoLength | 48 // i.e.) framesRequested <= m_fifoLength |
47 RefPtr<AudioBus> output_bus_of1025_frames = AudioBus::Create(2, 1025); | 49 RefPtr<AudioBus> output_bus_1025_frames = AudioBus::Create(2, 1025); |
48 EXPECT_DEATH(test_fifo->Pull(output_bus_of1025_frames.Get(), 1025), ""); | 50 EXPECT_DEATH(test_fifo->Pull(output_bus_1025_frames.Get(), 1025), ""); |
49 } | 51 } |
50 | 52 |
51 // Fills each AudioChannel in an AudioBus with a series of linearly increasing | 53 // Fills each AudioChannel in an AudioBus with a series of linearly increasing |
52 // values starting from |startingValue| and incrementing by 1. Then return value | 54 // values starting from |startingValue| and incrementing by 1. Then return value |
53 // will be |startingValue| + |bus_length|. | 55 // will be |startingValue| + |bus_length|. |
54 size_t FillBusWithLinearRamp(AudioBus* target_bus, size_t starting_value) { | 56 size_t FillBusWithLinearRamp(AudioBus* target_bus, size_t starting_value) { |
55 for (unsigned c = 0; c < target_bus->NumberOfChannels(); ++c) { | 57 for (unsigned c = 0; c < target_bus->NumberOfChannels(); ++c) { |
56 float* bus_channel = target_bus->Channel(c)->MutableData(); | 58 float* bus_channel = target_bus->Channel(c)->MutableData(); |
57 for (size_t i = 0; i < target_bus->Channel(c)->length(); ++i) { | 59 for (size_t i = 0; i < target_bus->Channel(c)->length(); ++i) { |
58 bus_channel[i] = static_cast<float>(starting_value + i); | 60 bus_channel[i] = static_cast<float>(starting_value + i); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 const PushPullFIFOStateForTest actual_state = fifo->GetStateForTest(); | 164 const PushPullFIFOStateForTest actual_state = fifo->GetStateForTest(); |
163 | 165 |
164 // Verify the read/write indexes. | 166 // Verify the read/write indexes. |
165 EXPECT_EQ(expected_state.index_read, actual_state.index_read); | 167 EXPECT_EQ(expected_state.index_read, actual_state.index_read); |
166 EXPECT_EQ(expected_state.index_write, actual_state.index_write); | 168 EXPECT_EQ(expected_state.index_write, actual_state.index_write); |
167 EXPECT_EQ(expected_state.overflow_count, actual_state.overflow_count); | 169 EXPECT_EQ(expected_state.overflow_count, actual_state.overflow_count); |
168 EXPECT_EQ(expected_state.underflow_count, actual_state.underflow_count); | 170 EXPECT_EQ(expected_state.underflow_count, actual_state.underflow_count); |
169 | 171 |
170 // Verify in-FIFO samples. | 172 // Verify in-FIFO samples. |
171 for (const auto& sample : expected_state.fifo_samples) { | 173 for (const auto& sample : expected_state.fifo_samples) { |
172 EXPECT_TRUE(VerifyBusValueAtIndex(fifo->Bus(), sample.index, sample.value)); | 174 EXPECT_TRUE(VerifyBusValueAtIndex(fifo->GetFIFOBusForTest(), |
| 175 sample.index, sample.value)); |
173 } | 176 } |
174 | 177 |
175 // Verify samples from the most recent output bus. | 178 // Verify samples from the most recent output bus. |
176 for (const auto& sample : expected_state.output_samples) { | 179 for (const auto& sample : expected_state.output_samples) { |
177 EXPECT_TRUE( | 180 EXPECT_TRUE( |
178 VerifyBusValueAtIndex(output_bus.Get(), sample.index, sample.value)); | 181 VerifyBusValueAtIndex(output_bus.Get(), sample.index, sample.value)); |
179 } | 182 } |
180 } | 183 } |
181 | 184 |
182 FIFOTestParam g_feature_test_params[] = { | 185 FIFOTestParam g_feature_test_params[] = { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 // - Output bus samples (index, expectedValue) = (0, 0), (143, 0) | 357 // - Output bus samples (index, expectedValue) = (0, 0), (143, 0) |
355 {0, 0, 0, 4, {{0, 0}, {1023, 0}}, {{0, 0}, {143, 0}}}}}; | 358 {0, 0, 0, 4, {{0, 0}, {1023, 0}}, {{0, 0}, {143, 0}}}}}; |
356 | 359 |
357 INSTANTIATE_TEST_CASE_P(PushPullFIFOFeatureTest, | 360 INSTANTIATE_TEST_CASE_P(PushPullFIFOFeatureTest, |
358 PushPullFIFOFeatureTest, | 361 PushPullFIFOFeatureTest, |
359 ::testing::ValuesIn(g_feature_test_params)); | 362 ::testing::ValuesIn(g_feature_test_params)); |
360 | 363 |
361 } // namespace | 364 } // namespace |
362 | 365 |
363 } // namespace blink | 366 } // namespace blink |
OLD | NEW |