Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "platform/audio/PushPullFIFO.h" | |
| 6 | |
| 7 #include "platform/audio/AudioUtilities.h" | |
| 8 #include "platform/testing/TestingPlatformSupport.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 #include "wtf/PtrUtil.h" | |
| 11 #include <memory> | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 void fillBusWithValue(AudioBus* targetBus, float value) { | |
| 18 for (unsigned c = 0; c < targetBus->numberOfChannels(); ++c) { | |
| 19 float* busChannel = targetBus->channel(c)->mutableData(); | |
| 20 std::fill(busChannel, busChannel + targetBus->channel(c)->length(), value); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 void fillBusWithIncrementalIndex(AudioBus* targetBus) { | |
|
Raymond Toy
2017/01/23 17:52:25
What does "IncrementalIndex" mean here?
hongchan
2017/01/23 19:37:36
[0, 1, 2, 3, 4, 5, 6, .... ]
You can call it a ra
Raymond Toy
2017/01/23 21:53:53
The name is not very informative because there's n
hongchan
2017/01/26 22:33:18
Done.
| |
| 25 for (unsigned c = 0; c < targetBus->numberOfChannels(); ++c) { | |
| 26 float* busChannel = targetBus->channel(c)->mutableData(); | |
| 27 for (unsigned i = 0; i < targetBus->channel(c)->length(); ++i) | |
| 28 busChannel[i] = i; | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 bool verifyBusValueAtIndex(AudioBus* targetBus, int index, float value) { | |
| 33 for (unsigned c = 0; c < targetBus->numberOfChannels(); ++c) { | |
| 34 float* busChannel = targetBus->channel(c)->mutableData(); | |
| 35 if (busChannel[index] != value) { | |
| 36 LOG(ERROR) << "[FAIL] index = " << index | |
| 37 << " value = " << busChannel[index]; | |
| 38 return false; | |
| 39 } | |
| 40 } | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 struct PushPullFIFOTestParam { | |
| 45 PushPullFIFOTestParam(size_t fifoSize, | |
| 46 unsigned numberOfChannels, | |
| 47 size_t framesAvailable, | |
| 48 size_t framesToPush, | |
| 49 size_t framesToPull, | |
| 50 unsigned expectedReadIndex, | |
| 51 float expectedValueAtReadIndex, | |
| 52 unsigned expectedWriteIndex, | |
| 53 float expectedValueAtWriteIndex) | |
| 54 : fifoSize(fifoSize), | |
| 55 numberOfChannels(numberOfChannels), | |
| 56 framesAvailable(framesAvailable), | |
| 57 framesToPush(framesToPush), | |
| 58 framesToPull(framesToPull), | |
| 59 expectedReadIndex(expectedReadIndex), | |
| 60 expectedValueAtReadIndex(expectedValueAtReadIndex), | |
| 61 expectedWriteIndex(expectedWriteIndex), | |
| 62 expectedValueAtWriteIndex(expectedValueAtWriteIndex) {} | |
| 63 ~PushPullFIFOTestParam() {} | |
| 64 | |
| 65 const size_t fifoSize; | |
| 66 const unsigned numberOfChannels; | |
| 67 const size_t framesAvailable; | |
| 68 const size_t framesToPush; | |
| 69 const size_t framesToPull; | |
| 70 const unsigned expectedReadIndex; | |
| 71 const float expectedValueAtReadIndex; | |
| 72 const unsigned expectedWriteIndex; | |
| 73 const float expectedValueAtWriteIndex; | |
| 74 }; | |
| 75 | |
| 76 std::ostream& operator<<(std::ostream& out, | |
| 77 const PushPullFIFOTestParam& param) { | |
| 78 out << "fifoSze=" << param.fifoSize | |
| 79 << " numberOfChannels=" << param.numberOfChannels | |
| 80 << " framesAvailable=" << param.framesAvailable | |
| 81 << " framesToPush=" << param.framesToPush | |
| 82 << " framesToPull=" << param.framesToPull | |
| 83 << " expectedReadIndex=" << param.expectedReadIndex | |
| 84 << " expectedValueAtReadIndex=" << param.expectedValueAtReadIndex | |
| 85 << " expectedWriteIndex=" << param.expectedWriteIndex | |
| 86 << " expectedValueAtWriteIndex=" << param.expectedValueAtWriteIndex; | |
| 87 return out; | |
| 88 } | |
| 89 | |
| 90 class PushPullFIFOTest | |
| 91 : public ::testing::TestWithParam<PushPullFIFOTestParam> {}; | |
| 92 | |
| 93 TEST_P(PushPullFIFOTest, BasicOperation) { | |
| 94 std::unique_ptr<PushPullFIFO> fifo = WTF::wrapUnique( | |
| 95 new PushPullFIFO(GetParam().numberOfChannels, GetParam().fifoSize)); | |
| 96 | |
| 97 // Simulates existing frames in the FIFO. These frames are initialized with | |
| 98 // -1. | |
| 99 RefPtr<AudioBus> existingBus = | |
| 100 AudioBus::create(GetParam().numberOfChannels, GetParam().framesAvailable); | |
| 101 fillBusWithValue(existingBus.get(), -1); | |
| 102 fifo->push(existingBus.get()); | |
| 103 | |
| 104 // Then push data with given length. The content of input bus is a series of | |
| 105 // incremental index. | |
|
Raymond Toy
2017/01/23 17:52:25
"incremental index"? This is just basically a lin
hongchan
2017/01/23 19:37:35
See the comment above.
| |
| 106 RefPtr<AudioBus> inputBus = | |
| 107 AudioBus::create(GetParam().numberOfChannels, GetParam().framesToPush); | |
| 108 fillBusWithIncrementalIndex(inputBus.get()); | |
| 109 fifo->push(inputBus.get()); | |
| 110 | |
| 111 // Lastly, pull the data from FIFO to reach the state required by the test | |
| 112 // parameter. | |
|
Raymond Toy
2017/01/23 17:52:25
"test parameter" -> |framesToPull| argument. Or s
hongchan
2017/01/23 19:37:36
Done.
hongchan
2017/01/26 22:33:18
This is sort of a combination of push and pull. So
| |
| 113 RefPtr<AudioBus> outputBus = | |
| 114 AudioBus::create(GetParam().numberOfChannels, GetParam().framesToPull); | |
| 115 fifo->pull(outputBus.get(), GetParam().framesToPull); | |
| 116 | |
| 117 // Verify the position of current indexes and their values. | |
| 118 EXPECT_EQ(true, | |
| 119 verifyBusValueAtIndex(fifo->bus(), GetParam().expectedReadIndex, | |
| 120 GetParam().expectedValueAtReadIndex)); | |
| 121 EXPECT_EQ(true, | |
| 122 verifyBusValueAtIndex(fifo->bus(), GetParam().expectedWriteIndex, | |
| 123 GetParam().expectedValueAtWriteIndex)); | |
| 124 } | |
|
Raymond Toy
2017/01/23 17:52:25
Should there be some checks on the values of the r
hongchan
2017/01/23 19:37:36
For that, I will have to add some methods to the c
Raymond Toy
2017/01/23 21:53:53
Oh. I was kind of expecting this to already be ava
hongchan
2017/01/23 22:28:36
Based on quick offline discussion, the test looks
| |
| 125 | |
| 126 INSTANTIATE_TEST_CASE_P( | |
| 127 PushPullFIFOTest, | |
| 128 PushPullFIFOTest, | |
| 129 ::testing::Values( | |
| 130 PushPullFIFOTestParam(8192, 2, 128, 256, 128, 128, 0, 384, 0))); | |
| 131 | |
| 132 } // namespace | |
| 133 | |
| 134 } // namespace blink | |
| OLD | NEW |