| 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 number_of_input_channels, | 36 WebAudioDevice* CreateAudioDevice(unsigned number_of_input_channels, |
| 37 unsigned number_of_channels, | 37 unsigned number_of_channels, |
| 38 const WebAudioLatencyHint& latency_hint, | 38 const WebAudioLatencyHint& latency_hint, |
| 39 WebAudioDevice::RenderCallback*, | 39 WebAudioDevice::RenderCallback*, |
| 40 const WebString& device_id, | 40 const WebString& device_id, |
| 41 const WebSecurityOrigin&) override { | 41 const WebSecurityOrigin&) override { |
| 42 double buffer_size = 0; | 42 double buffer_size = 0; |
| 43 const double interactive_size = AudioHardwareBufferSize(); |
| 44 const double balanced_size = AudioHardwareBufferSize() * 2; |
| 45 const double playback_size = AudioHardwareBufferSize() * 4; |
| 43 switch (latency_hint.Category()) { | 46 switch (latency_hint.Category()) { |
| 44 case WebAudioLatencyHint::kCategoryInteractive: | 47 case WebAudioLatencyHint::kCategoryInteractive: |
| 45 buffer_size = AudioHardwareBufferSize(); | 48 buffer_size = interactive_size; |
| 46 break; | 49 break; |
| 47 case WebAudioLatencyHint::kCategoryBalanced: | 50 case WebAudioLatencyHint::kCategoryBalanced: |
| 48 buffer_size = AudioHardwareBufferSize() * 2; | 51 buffer_size = balanced_size; |
| 49 break; | 52 break; |
| 50 case WebAudioLatencyHint::kCategoryPlayback: | 53 case WebAudioLatencyHint::kCategoryPlayback: |
| 51 buffer_size = AudioHardwareBufferSize() * 4; | 54 buffer_size = playback_size; |
| 55 break; |
| 56 case WebAudioLatencyHint::kCategoryExact: |
| 57 buffer_size = |
| 58 clampTo(latency_hint.Seconds() * AudioHardwareSampleRate(), |
| 59 static_cast<double>(AudioHardwareBufferSize()), |
| 60 static_cast<double>(playback_size)); |
| 52 break; | 61 break; |
| 53 default: | 62 default: |
| 54 NOTREACHED(); | 63 NOTREACHED(); |
| 55 break; | 64 break; |
| 56 } | 65 } |
| 57 | 66 |
| 58 return new MockWebAudioDevice(AudioHardwareSampleRate(), buffer_size); | 67 return new MockWebAudioDevice(AudioHardwareSampleRate(), buffer_size); |
| 59 } | 68 } |
| 60 | 69 |
| 61 double AudioHardwareSampleRate() override { return 44100; } | 70 double AudioHardwareSampleRate() override { return 44100; } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 EXPECT_GT(balanced_context->baseLatency(), | 102 EXPECT_GT(balanced_context->baseLatency(), |
| 94 interactive_context->baseLatency()); | 103 interactive_context->baseLatency()); |
| 95 | 104 |
| 96 AudioContextOptions playback_options; | 105 AudioContextOptions playback_options; |
| 97 playback_options.setLatencyHint( | 106 playback_options.setLatencyHint( |
| 98 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( | 107 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( |
| 99 "playback")); | 108 "playback")); |
| 100 AudioContext* playback_context = AudioContext::Create( | 109 AudioContext* playback_context = AudioContext::Create( |
| 101 GetDocument(), playback_options, ASSERT_NO_EXCEPTION); | 110 GetDocument(), playback_options, ASSERT_NO_EXCEPTION); |
| 102 EXPECT_GT(playback_context->baseLatency(), balanced_context->baseLatency()); | 111 EXPECT_GT(playback_context->baseLatency(), balanced_context->baseLatency()); |
| 112 |
| 113 AudioContextOptions exact_too_small_options; |
| 114 exact_too_small_options.setLatencyHint( |
| 115 AudioContextLatencyCategoryOrDouble::fromDouble( |
| 116 interactive_context->baseLatency() / 2)); |
| 117 AudioContext* exact_too_small_context = AudioContext::Create( |
| 118 GetDocument(), exact_too_small_options, ASSERT_NO_EXCEPTION); |
| 119 EXPECT_EQ(exact_too_small_context->baseLatency(), |
| 120 interactive_context->baseLatency()); |
| 121 |
| 122 const double exact_latency_sec = |
| 123 (interactive_context->baseLatency() + playback_context->baseLatency()) / |
| 124 2; |
| 125 AudioContextOptions exact_ok_options; |
| 126 exact_ok_options.setLatencyHint( |
| 127 AudioContextLatencyCategoryOrDouble::fromDouble(exact_latency_sec)); |
| 128 AudioContext* exact_ok_context = AudioContext::Create( |
| 129 GetDocument(), exact_ok_options, ASSERT_NO_EXCEPTION); |
| 130 EXPECT_EQ(exact_ok_context->baseLatency(), exact_latency_sec); |
| 131 |
| 132 AudioContextOptions exact_too_big_options; |
| 133 exact_too_big_options.setLatencyHint( |
| 134 AudioContextLatencyCategoryOrDouble::fromDouble( |
| 135 playback_context->baseLatency() * 2)); |
| 136 AudioContext* exact_too_big_context = AudioContext::Create( |
| 137 GetDocument(), exact_too_big_options, ASSERT_NO_EXCEPTION); |
| 138 EXPECT_EQ(exact_too_big_context->baseLatency(), |
| 139 playback_context->baseLatency()); |
| 103 } | 140 } |
| 104 | 141 |
| 105 } // namespace blink | 142 } // namespace blink |
| OLD | NEW |