| 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 "modules/webaudio/AudioContext.h" | 5 #include "modules/webaudio/AudioContext.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
| 9 #include "platform/testing/TestingPlatformSupport.h" | 9 #include "platform/testing/TestingPlatformSupport.h" |
| 10 #include "public/platform/WebAudioDevice.h" | 10 #include "public/platform/WebAudioDevice.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 class AudioContextTestPlatform : public TestingPlatformSupport { | 34 class AudioContextTestPlatform : public TestingPlatformSupport { |
| 35 public: | 35 public: |
| 36 WebAudioDevice* createAudioDevice(unsigned numberOfInputChannels, | 36 WebAudioDevice* createAudioDevice(unsigned numberOfInputChannels, |
| 37 unsigned numberOfChannels, | 37 unsigned numberOfChannels, |
| 38 const WebAudioLatencyHint& latencyHint, | 38 const WebAudioLatencyHint& latencyHint, |
| 39 WebAudioDevice::RenderCallback*, | 39 WebAudioDevice::RenderCallback*, |
| 40 const WebString& deviceId, | 40 const WebString& deviceId, |
| 41 const WebSecurityOrigin&) override { | 41 const WebSecurityOrigin&) override { |
| 42 double bufferSize = 0; | 42 double bufferSize = 0; |
| 43 const double interactiveSize = audioHardwareBufferSize(); |
| 44 const double balancedSize = audioHardwareBufferSize() * 2; |
| 45 const double playbackSize = audioHardwareBufferSize() * 4; |
| 43 switch (latencyHint.category()) { | 46 switch (latencyHint.category()) { |
| 44 case WebAudioLatencyHint::kCategoryInteractive: | 47 case WebAudioLatencyHint::kCategoryInteractive: |
| 45 bufferSize = audioHardwareBufferSize(); | 48 bufferSize = interactiveSize; |
| 46 break; | 49 break; |
| 47 case WebAudioLatencyHint::kCategoryBalanced: | 50 case WebAudioLatencyHint::kCategoryBalanced: |
| 48 bufferSize = audioHardwareBufferSize() * 2; | 51 bufferSize = balancedSize; |
| 49 break; | 52 break; |
| 50 case WebAudioLatencyHint::kCategoryPlayback: | 53 case WebAudioLatencyHint::kCategoryPlayback: |
| 51 bufferSize = audioHardwareBufferSize() * 4; | 54 bufferSize = playbackSize; |
| 55 break; |
| 56 case WebAudioLatencyHint::kCategoryExact: |
| 57 bufferSize = clampTo(latencyHint.seconds() * audioHardwareSampleRate(), |
| 58 static_cast<double>(audioHardwareBufferSize()), |
| 59 static_cast<double>(playbackSize)); |
| 52 break; | 60 break; |
| 53 default: | 61 default: |
| 54 NOTREACHED(); | 62 NOTREACHED(); |
| 55 break; | 63 break; |
| 56 } | 64 } |
| 57 | 65 |
| 58 return new MockWebAudioDevice(audioHardwareSampleRate(), bufferSize); | 66 return new MockWebAudioDevice(audioHardwareSampleRate(), bufferSize); |
| 59 } | 67 } |
| 60 | 68 |
| 61 double audioHardwareSampleRate() override { return 44100; } | 69 double audioHardwareSampleRate() override { return 44100; } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 92 AudioContext::create(document(), balancedOptions, ASSERT_NO_EXCEPTION); | 100 AudioContext::create(document(), balancedOptions, ASSERT_NO_EXCEPTION); |
| 93 EXPECT_GT(balancedContext->baseLatency(), interactiveContext->baseLatency()); | 101 EXPECT_GT(balancedContext->baseLatency(), interactiveContext->baseLatency()); |
| 94 | 102 |
| 95 AudioContextOptions playbackOptions; | 103 AudioContextOptions playbackOptions; |
| 96 playbackOptions.setLatencyHint( | 104 playbackOptions.setLatencyHint( |
| 97 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( | 105 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( |
| 98 "playback")); | 106 "playback")); |
| 99 AudioContext* playbackContext = | 107 AudioContext* playbackContext = |
| 100 AudioContext::create(document(), playbackOptions, ASSERT_NO_EXCEPTION); | 108 AudioContext::create(document(), playbackOptions, ASSERT_NO_EXCEPTION); |
| 101 EXPECT_GT(playbackContext->baseLatency(), balancedContext->baseLatency()); | 109 EXPECT_GT(playbackContext->baseLatency(), balancedContext->baseLatency()); |
| 110 |
| 111 AudioContextOptions exactTooSmallOptions; |
| 112 exactTooSmallOptions.setLatencyHint( |
| 113 AudioContextLatencyCategoryOrDouble::fromDouble( |
| 114 interactiveContext->baseLatency() / 4)); |
| 115 AudioContext* exactTooSmallContext = AudioContext::create( |
| 116 document(), exactTooSmallOptions, ASSERT_NO_EXCEPTION); |
| 117 EXPECT_EQ(exactTooSmallContext->baseLatency(), |
| 118 interactiveContext->baseLatency()); |
| 119 |
| 120 const double exactLatencySec = |
| 121 (interactiveContext->baseLatency() + playbackContext->baseLatency()) / 4; |
| 122 AudioContextOptions exactOkOptions; |
| 123 exactOkOptions.setLatencyHint( |
| 124 AudioContextLatencyCategoryOrDouble::fromDouble(exactLatencySec)); |
| 125 AudioContext* exactOkContext = |
| 126 AudioContext::create(document(), exactOkOptions, ASSERT_NO_EXCEPTION); |
| 127 EXPECT_EQ(exactOkContext->baseLatency(), exactLatencySec * 2); |
| 128 |
| 129 AudioContextOptions exactTooBigOptions; |
| 130 exactTooBigOptions.setLatencyHint( |
| 131 AudioContextLatencyCategoryOrDouble::fromDouble( |
| 132 playbackContext->baseLatency() * 2)); |
| 133 AudioContext* exactTooBigContext = |
| 134 AudioContext::create(document(), exactTooBigOptions, ASSERT_NO_EXCEPTION); |
| 135 EXPECT_EQ(exactTooBigContext->baseLatency(), playbackContext->baseLatency()); |
| 102 } | 136 } |
| 103 | 137 |
| 104 } // namespace blink | 138 } // namespace blink |
| OLD | NEW |