Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 125 |
| 126 // Verify Create(...) using AudioParameters works as advertised. | 126 // Verify Create(...) using AudioParameters works as advertised. |
| 127 TEST_F(AudioBusTest, CreateUsingAudioParameters) { | 127 TEST_F(AudioBusTest, CreateUsingAudioParameters) { |
| 128 std::unique_ptr<AudioBus> bus = AudioBus::Create( | 128 std::unique_ptr<AudioBus> bus = AudioBus::Create( |
| 129 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, | 129 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, |
| 130 kSampleRate, 32, kFrameCount)); | 130 kSampleRate, 32, kFrameCount)); |
| 131 VerifyChannelAndFrameCount(bus.get()); | 131 VerifyChannelAndFrameCount(bus.get()); |
| 132 VerifyReadWriteAndAlignment(bus.get()); | 132 VerifyReadWriteAndAlignment(bus.get()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // Verify CreateWrapper(...) method works as advertised. | |
| 136 TEST_F(AudioBusTest, CreateWrapper) { | |
| 137 std::unique_ptr<AudioBus> bus = AudioBus::CreateWrapper(kChannels); | |
| 138 EXPECT_EQ(kChannels, bus->channels()); | |
| 139 EXPECT_EQ(0, bus->frames()); | |
| 140 } | |
| 141 | |
| 135 // Verify an AudioBus created via wrapping a vector works as advertised. | 142 // Verify an AudioBus created via wrapping a vector works as advertised. |
| 136 TEST_F(AudioBusTest, WrapVector) { | 143 TEST_F(AudioBusTest, WrapVector) { |
| 137 data_.reserve(kChannels); | 144 data_.reserve(kChannels); |
| 138 for (int i = 0; i < kChannels; ++i) { | 145 for (int i = 0; i < kChannels; ++i) { |
| 139 data_.push_back(static_cast<float*>(base::AlignedAlloc( | 146 data_.push_back(static_cast<float*>(base::AlignedAlloc( |
| 140 sizeof(*data_[i]) * kFrameCount, AudioBus::kChannelAlignment))); | 147 sizeof(*data_[i]) * kFrameCount, AudioBus::kChannelAlignment))); |
| 141 } | 148 } |
| 142 | 149 |
| 143 std::unique_ptr<AudioBus> bus = AudioBus::WrapVector(kFrameCount, data_); | 150 std::unique_ptr<AudioBus> bus = AudioBus::WrapVector(kFrameCount, data_); |
| 144 VerifyChannelAndFrameCount(bus.get()); | 151 VerifyChannelAndFrameCount(bus.get()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 165 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), kTestValue); | 172 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), kTestValue); |
| 166 VerifyChannelAndFrameCount(bus.get()); | 173 VerifyChannelAndFrameCount(bus.get()); |
| 167 VerifyReadWriteAndAlignment(bus.get()); | 174 VerifyReadWriteAndAlignment(bus.get()); |
| 168 | 175 |
| 169 // Verify the channel vectors lie within the provided memory block. | 176 // Verify the channel vectors lie within the provided memory block. |
| 170 EXPECT_GE(bus->channel(0), data.get()); | 177 EXPECT_GE(bus->channel(0), data.get()); |
| 171 EXPECT_LT(bus->channel(bus->channels() - 1) + bus->frames(), | 178 EXPECT_LT(bus->channel(bus->channels() - 1) + bus->frames(), |
| 172 data.get() + data_size / sizeof(*data.get())); | 179 data.get() + data_size / sizeof(*data.get())); |
| 173 } | 180 } |
| 174 | 181 |
| 182 // Verify SetChannelData(...) method works as advertised. | |
| 183 TEST_F(AudioBusTest, SetChannelData) { | |
| 184 data_.reserve(kChannels); | |
| 185 for (int i = 0; i < kChannels; ++i) { | |
| 186 data_.push_back(static_cast<float*>( | |
| 187 base::AlignedAlloc(sizeof(*data_[i]), AudioBus::kChannelAlignment))); | |
| 188 } | |
| 189 std::unique_ptr<AudioBus> bus = AudioBus::CreateWrapper(kChannels); | |
| 190 for (int i = 0; i < bus->channels(); ++i) | |
| 191 bus->SetChannelData(i, data_[i]); | |
| 192 | |
| 193 for (int i = 0; i < bus->channels(); ++i) | |
| 194 EXPECT_EQ(bus->channel(i), data_[i]); | |
|
chfremer
2017/04/27 16:55:14
Would it make sense to add
VerifyReadWriteAndAli
Chandan
2017/04/27 18:43:07
With number of frames in this test being always ze
chfremer
2017/04/27 20:19:36
Hmm, I feel that for the cases where AudioBus itse
Chandan
2017/04/28 06:07:29
Sure. I will add Alignment verification for this t
chfremer
2017/04/28 16:39:48
Not needed for the tests involving AudioBus::Creat
| |
| 195 } | |
| 196 | |
| 197 // Verify set_frames(...) method works as advertised. | |
| 198 TEST_F(AudioBusTest, SetFrames) { | |
| 199 std::unique_ptr<AudioBus> bus = AudioBus::CreateWrapper(kChannels); | |
| 200 bus->set_frames(kFrameCount); | |
| 201 EXPECT_EQ(kFrameCount, bus->frames()); | |
|
chfremer
2017/04/27 16:55:14
Would it make sense to add
VerifyReadWriteAndAli
Chandan
2017/04/27 18:43:07
With no channel data allocated in this test, verif
chfremer
2017/04/27 20:19:36
True. I guess, when I added the TODO for adding te
Chandan
2017/04/28 06:07:29
By 'everything' you mean read/write/alignment?
Im
chfremer
2017/04/28 16:39:48
Sorry about my vague language. Yes I meant read/wr
Chandan
2017/05/02 09:27:06
Right. With the new test in place, these 3 individ
| |
| 202 } | |
| 203 | |
| 175 // Simulate a shared memory transfer and verify results. | 204 // Simulate a shared memory transfer and verify results. |
| 176 TEST_F(AudioBusTest, CopyTo) { | 205 TEST_F(AudioBusTest, CopyTo) { |
| 177 // Create one bus with AudioParameters and the other through direct values to | 206 // Create one bus with AudioParameters and the other through direct values to |
| 178 // test for parity between the Create() functions. | 207 // test for parity between the Create() functions. |
| 179 AudioParameters params( | 208 AudioParameters params( |
| 180 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, 32, | 209 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, 32, |
| 181 kFrameCount); | 210 kFrameCount); |
| 182 std::unique_ptr<AudioBus> bus1 = AudioBus::Create(kChannels, kFrameCount); | 211 std::unique_ptr<AudioBus> bus1 = AudioBus::Create(kChannels, kFrameCount); |
| 183 std::unique_ptr<AudioBus> bus2 = AudioBus::Create(params); | 212 std::unique_ptr<AudioBus> bus2 = AudioBus::Create(params); |
| 184 | 213 |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 | 688 |
| 660 // Verify zero volume case. | 689 // Verify zero volume case. |
| 661 bus->Scale(0); | 690 bus->Scale(0); |
| 662 for (int i = 0; i < bus->channels(); ++i) { | 691 for (int i = 0; i < bus->channels(); ++i) { |
| 663 SCOPED_TRACE("Zero Scale"); | 692 SCOPED_TRACE("Zero Scale"); |
| 664 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), 0); | 693 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), 0); |
| 665 } | 694 } |
| 666 } | 695 } |
| 667 | 696 |
| 668 } // namespace media | 697 } // namespace media |
| OLD | NEW |