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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 switch (latencyHint.category()) { | 43 switch (latencyHint.category()) { |
44 case WebAudioLatencyHint::kCategoryInteractive: | 44 case WebAudioLatencyHint::kCategoryInteractive: |
45 bufferSize = audioHardwareBufferSize(); | 45 bufferSize = audioHardwareBufferSize(); |
46 break; | 46 break; |
47 case WebAudioLatencyHint::kCategoryBalanced: | 47 case WebAudioLatencyHint::kCategoryBalanced: |
48 bufferSize = audioHardwareBufferSize() * 2; | 48 bufferSize = audioHardwareBufferSize() * 2; |
49 break; | 49 break; |
50 case WebAudioLatencyHint::kCategoryPlayback: | 50 case WebAudioLatencyHint::kCategoryPlayback: |
51 bufferSize = audioHardwareBufferSize() * 4; | 51 bufferSize = audioHardwareBufferSize() * 4; |
52 break; | 52 break; |
| 53 case WebAudioLatencyHint::kCategoryExact: |
| 54 bufferSize = std::max( |
| 55 static_cast<double>(audioHardwareBufferSize()), |
| 56 std::min(latencyHint.seconds() * audioHardwareSampleRate(), |
| 57 static_cast<double>(audioHardwareBufferSize() * 4))); |
| 58 break; |
53 default: | 59 default: |
54 NOTREACHED(); | 60 NOTREACHED(); |
55 break; | 61 break; |
56 } | 62 } |
57 | 63 |
58 return new MockWebAudioDevice(audioHardwareSampleRate(), bufferSize); | 64 return new MockWebAudioDevice(audioHardwareSampleRate(), bufferSize); |
59 } | 65 } |
60 | 66 |
61 double audioHardwareSampleRate() override { return 44100; } | 67 double audioHardwareSampleRate() override { return 44100; } |
62 size_t audioHardwareBufferSize() override { return 128; } | 68 size_t audioHardwareBufferSize() override { return 128; } |
(...skipping 29 matching lines...) Expand all Loading... |
92 AudioContext::create(document(), balancedOptions, ASSERT_NO_EXCEPTION); | 98 AudioContext::create(document(), balancedOptions, ASSERT_NO_EXCEPTION); |
93 EXPECT_GT(balancedContext->baseLatency(), interactiveContext->baseLatency()); | 99 EXPECT_GT(balancedContext->baseLatency(), interactiveContext->baseLatency()); |
94 | 100 |
95 AudioContextOptions playbackOptions; | 101 AudioContextOptions playbackOptions; |
96 playbackOptions.setLatencyHint( | 102 playbackOptions.setLatencyHint( |
97 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( | 103 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( |
98 "playback")); | 104 "playback")); |
99 AudioContext* playbackContext = | 105 AudioContext* playbackContext = |
100 AudioContext::create(document(), playbackOptions, ASSERT_NO_EXCEPTION); | 106 AudioContext::create(document(), playbackOptions, ASSERT_NO_EXCEPTION); |
101 EXPECT_GT(playbackContext->baseLatency(), balancedContext->baseLatency()); | 107 EXPECT_GT(playbackContext->baseLatency(), balancedContext->baseLatency()); |
| 108 |
| 109 AudioContextOptions exactTooSmallOptions; |
| 110 exactTooSmallOptions.setLatencyHint( |
| 111 AudioContextLatencyCategoryOrDouble::fromDouble(0.000001)); |
| 112 AudioContext* exactTooSmallContext = AudioContext::create( |
| 113 document(), exactTooSmallOptions, ASSERT_NO_EXCEPTION); |
| 114 EXPECT_EQ(exactTooSmallContext->baseLatency(), |
| 115 interactiveContext->baseLatency()); |
| 116 |
| 117 const double exactLatencySec = 0.01; |
| 118 AudioContextOptions exactOkOptions; |
| 119 exactOkOptions.setLatencyHint( |
| 120 AudioContextLatencyCategoryOrDouble::fromDouble(exactLatencySec)); |
| 121 AudioContext* exactOkContext = |
| 122 AudioContext::create(document(), exactOkOptions, ASSERT_NO_EXCEPTION); |
| 123 EXPECT_EQ(exactOkContext->baseLatency(), exactLatencySec * 2); |
| 124 |
| 125 AudioContextOptions exactTooBigOptions; |
| 126 exactTooBigOptions.setLatencyHint( |
| 127 AudioContextLatencyCategoryOrDouble::fromDouble(1)); |
| 128 AudioContext* exactTooBigContext = |
| 129 AudioContext::create(document(), exactTooBigOptions, ASSERT_NO_EXCEPTION); |
| 130 EXPECT_EQ(exactTooBigContext->baseLatency(), playbackContext->baseLatency()); |
102 } | 131 } |
103 | 132 |
104 } // namespace blink | 133 } // namespace blink |
OLD | NEW |