Chromium Code Reviews| 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/CrossThreadFunctional.h" | 9 #include "platform/CrossThreadFunctional.h" |
| 10 #include "platform/WaitableEvent.h" | 10 #include "platform/WaitableEvent.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Base FIFOClient with an extra thread for looping and jitter control. The | 42 // Base FIFOClient with an extra thread for looping and jitter control. The |
| 43 // child class must define a specific task to run on the thread. | 43 // child class must define a specific task to run on the thread. |
| 44 class FIFOClient { | 44 class FIFOClient { |
| 45 public: | 45 public: |
| 46 FIFOClient(PushPullFIFO* fifo, size_t bus_length, size_t jitter_range_ms) | 46 FIFOClient(PushPullFIFO* fifo, size_t bus_length, size_t jitter_range_ms) |
| 47 : fifo_(fifo), | 47 : fifo_(fifo), |
| 48 bus_(AudioBus::Create(fifo->NumberOfChannels(), bus_length)), | 48 bus_(AudioBus::Create(fifo->NumberOfChannels(), bus_length)), |
| 49 client_thread_(Platform::Current()->CreateThread("client thread")), | 49 client_thread_(Platform::Current()->CreateThread("client thread")), |
| 50 done_event_(WTF::MakeUnique<WaitableEvent>()), | |
| 50 jitter_range_ms_(jitter_range_ms) {} | 51 jitter_range_ms_(jitter_range_ms) {} |
| 51 | 52 |
| 52 void Start(double duration_ms, double interval_ms) { | 53 ~FIFOClient() { |
| 54 client_thread_.reset(); | |
|
o1ka
2017/05/08 12:11:56
Why is it needed?
hongchan
2017/05/08 18:19:33
Removed.
| |
| 55 } | |
| 56 | |
| 57 WaitableEvent* Start(double duration_ms, double interval_ms) { | |
| 53 duration_ms_ = duration_ms; | 58 duration_ms_ = duration_ms; |
| 54 interval_ms_ = interval_ms; | 59 interval_ms_ = interval_ms; |
| 55 client_thread_->GetWebTaskRunner()->PostTask( | 60 client_thread_->GetWebTaskRunner()->PostTask( |
| 56 BLINK_FROM_HERE, | 61 BLINK_FROM_HERE, |
| 57 CrossThreadBind(&FIFOClient::RunTaskOnOwnThread, | 62 CrossThreadBind(&FIFOClient::RunTaskOnOwnThread, |
| 58 CrossThreadUnretained(this))); | 63 CrossThreadUnretained(this))); |
| 64 return done_event_.get(); | |
| 59 } | 65 } |
| 60 | 66 |
| 61 virtual void Stop(int callback_counter) = 0; | 67 virtual void Stop(int callback_counter) = 0; |
| 62 virtual void RunTask() = 0; | 68 virtual void RunTask() = 0; |
| 63 | 69 |
| 64 void Pull(size_t frames_to_pull) { | 70 void Pull(size_t frames_to_pull) { |
| 65 fifo_->Pull(bus_.Get(), frames_to_pull); | 71 fifo_->Pull(bus_.Get(), frames_to_pull); |
| 66 } | 72 } |
| 67 | 73 |
| 68 void Push() { | 74 void Push() { |
| 69 fifo_->Push(bus_.Get()); | 75 fifo_->Push(bus_.Get()); |
| 70 } | 76 } |
| 71 | 77 |
| 72 private: | 78 private: |
| 73 void RunTaskOnOwnThread() { | 79 void RunTaskOnOwnThread() { |
| 74 double interval_with_jitter = interval_ms_ | 80 double interval_with_jitter = interval_ms_ |
| 75 + (static_cast<double>(std::rand()) / RAND_MAX) * jitter_range_ms_; | 81 + (static_cast<double>(std::rand()) / RAND_MAX) * jitter_range_ms_; |
| 76 elapsed_ms_ += interval_with_jitter; | 82 elapsed_ms_ += interval_with_jitter; |
| 77 ++counter_; | 83 ++counter_; |
| 78 RunTask(); | 84 RunTask(); |
| 79 if (elapsed_ms_ < duration_ms_) { | 85 if (elapsed_ms_ < duration_ms_) { |
| 80 client_thread_->GetWebTaskRunner()->PostDelayedTask( | 86 client_thread_->GetWebTaskRunner()->PostDelayedTask( |
| 81 BLINK_FROM_HERE, | 87 BLINK_FROM_HERE, |
| 82 CrossThreadBind(&FIFOClient::RunTaskOnOwnThread, | 88 CrossThreadBind(&FIFOClient::RunTaskOnOwnThread, |
| 83 CrossThreadUnretained(this)), | 89 CrossThreadUnretained(this)), |
| 84 interval_with_jitter); | 90 interval_with_jitter); |
| 85 } else { | 91 } else { |
| 86 Stop(counter_); | 92 Stop(counter_); |
| 93 done_event_->Signal(); | |
| 87 } | 94 } |
| 88 } | 95 } |
| 89 | 96 |
| 90 PushPullFIFO* fifo_; | 97 PushPullFIFO* fifo_; |
| 91 RefPtr<AudioBus> bus_; | 98 RefPtr<AudioBus> bus_; |
| 92 std::unique_ptr<WebThread> client_thread_; | 99 std::unique_ptr<WebThread> client_thread_; |
| 100 std::unique_ptr<WaitableEvent> done_event_; | |
| 93 | 101 |
| 94 // Test duration. | 102 // Test duration. |
| 95 double duration_ms_; | 103 double duration_ms_; |
| 96 | 104 |
| 97 // Interval between each callback. | 105 // Interval between each callback. |
| 98 double interval_ms_; | 106 double interval_ms_; |
| 99 | 107 |
| 100 // Jitter added to the regular pushing/pulling interval. | 108 // Jitter added to the regular pushing/pulling interval. |
| 101 // (where j is 0 < j < jitter_range_ms) | 109 // (where j is 0 < j < jitter_range_ms) |
| 102 double jitter_range_ms_; | 110 double jitter_range_ms_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 const double push_interval_ms = | 180 const double push_interval_ms = |
| 173 param.push_buffer_size / sample_rate * 1000; | 181 param.push_buffer_size / sample_rate * 1000; |
| 174 | 182 |
| 175 std::unique_ptr<PushPullFIFO> test_fifo = WTF::WrapUnique( | 183 std::unique_ptr<PushPullFIFO> test_fifo = WTF::WrapUnique( |
| 176 new PushPullFIFO(param.number_of_channels, param.fifo_length)); | 184 new PushPullFIFO(param.number_of_channels, param.fifo_length)); |
| 177 std::unique_ptr<PullClient> pull_client = WTF::WrapUnique(new PullClient( | 185 std::unique_ptr<PullClient> pull_client = WTF::WrapUnique(new PullClient( |
| 178 test_fifo.get(), param.pull_buffer_size, param.pull_jitter_range_ms)); | 186 test_fifo.get(), param.pull_buffer_size, param.pull_jitter_range_ms)); |
| 179 std::unique_ptr<PushClient> push_client = WTF::WrapUnique(new PushClient( | 187 std::unique_ptr<PushClient> push_client = WTF::WrapUnique(new PushClient( |
| 180 test_fifo.get(), param.push_buffer_size, param.push_jitter_range_ms)); | 188 test_fifo.get(), param.push_buffer_size, param.push_jitter_range_ms)); |
| 181 | 189 |
| 182 LOG(INFO) << "PushPullFIFOSmokeTest - Start"; | 190 Vector<WaitableEvent*> done_events; |
| 191 done_events.push_back( | |
| 192 pull_client->Start(param.test_duration_ms, pull_interval_ms)); | |
| 193 done_events.push_back( | |
| 194 push_client->Start(param.test_duration_ms, push_interval_ms)); | |
| 183 | 195 |
| 184 pull_client->Start(param.test_duration_ms, pull_interval_ms); | 196 LOG(INFO) << "PushPullFIFOSmokeTest - Started"; |
| 185 push_client->Start(param.test_duration_ms, push_interval_ms); | 197 |
| 198 // We have to wait both of events to be signaled. | |
| 199 WaitableEvent::WaitMultiple(done_events); | |
| 200 WaitableEvent::WaitMultiple(done_events); | |
| 186 | 201 |
| 187 // If the operation does not cause a crash for the test period, it's passed. | 202 // If the operation does not cause a crash for the test period, it's passed. |
| 188 // Also give a bit more time to finish the tear-down process. | 203 // Also give a bit more time (10ms per iteration) to finish the tear-down |
|
o1ka
2017/05/08 12:11:56
Not sure what tear down process do you mean?
Nothi
hongchan
2017/05/08 18:19:33
Done.
| |
| 189 HoldTestForDuration(param.test_duration_ms + 150); | 204 // process. |
| 205 HoldTestForDuration(10); | |
| 190 } | 206 } |
| 191 | 207 |
| 192 FIFOSmokeTestParam smoke_test_params[] = { | 208 FIFOSmokeTestParam smoke_test_params[] = { |
| 193 // Test case 0 (OSX): 256 Pull, 128 Push, Minimal jitter. | 209 // Test case 0 (OSX): 256 Pull, 128 Push, Minimal jitter. |
| 194 // WebThread's priority is lower than the device thread, so its jitter range | 210 // WebThread's priority is lower than the device thread, so its jitter range |
| 195 // is slightly bigger than the other. | 211 // is slightly bigger than the other. |
| 196 {48000, 2, 8192, 1000, 256, 1, 128, 2}, | 212 {48000, 2, 8192, 1000, 256, 1, 128, 2}, |
| 197 | 213 |
| 198 // Test case 1 (Windows): 441 Pull, 128 Push. Moderate Jitter. | 214 // Test case 1 (Windows): 441 Pull, 128 Push. Moderate Jitter. |
| 199 // Windows' audio callback is known to be ~10ms and UMA data shows the | 215 // Windows' audio callback is known to be ~10ms and UMA data shows the |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 225 {48000, 2, 8192, 10000, 256, 0, 128, 1} | 241 {48000, 2, 8192, 10000, 256, 0, 128, 1} |
| 226 }; | 242 }; |
| 227 | 243 |
| 228 INSTANTIATE_TEST_CASE_P(PushPullFIFOSmokeTest, | 244 INSTANTIATE_TEST_CASE_P(PushPullFIFOSmokeTest, |
| 229 PushPullFIFOSmokeTest, | 245 PushPullFIFOSmokeTest, |
| 230 ::testing::ValuesIn(smoke_test_params)); | 246 ::testing::ValuesIn(smoke_test_params)); |
| 231 | 247 |
| 232 } // namespace | 248 } // namespace |
| 233 | 249 |
| 234 } // namespace blink | 250 } // namespace blink |
| OLD | NEW |