Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
tkent
2017/02/08 22:38:46
2016 -> 2017
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "modules/webaudio/AudioContext.h" | |
| 6 | |
| 7 #include "core/dom/Document.h" | |
| 8 #include "core/testing/DummyPageHolder.h" | |
| 9 #include "platform/testing/TestingPlatformSupport.h" | |
| 10 #include "public/platform/WebAudioDevice.h" | |
| 11 #include "public/platform/WebAudioLatencyHint.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace blink { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class MockWebAudioDevice : public WebAudioDevice { | |
| 19 public: | |
| 20 explicit MockWebAudioDevice(double sampleRate, int framesPerBuffer) | |
| 21 : m_sampleRate(sampleRate), m_framesPerBuffer(framesPerBuffer) {} | |
| 22 ~MockWebAudioDevice() override = default; | |
| 23 | |
| 24 void start() override {} | |
| 25 void stop() override {} | |
| 26 double sampleRate() override { return m_sampleRate; } | |
| 27 int framesPerBuffer() override { return m_framesPerBuffer; } | |
| 28 | |
| 29 private: | |
| 30 double m_sampleRate; | |
| 31 int m_framesPerBuffer; | |
| 32 }; | |
| 33 | |
| 34 class AudioContextTestPlatform : public TestingPlatformSupport { | |
| 35 public: | |
| 36 WebAudioDevice* createAudioDevice(unsigned numberOfInputChannels, | |
| 37 unsigned numberOfChannels, | |
| 38 const WebAudioLatencyHint& latencyHint, | |
| 39 WebAudioDevice::RenderCallback*, | |
| 40 const WebString& deviceId, | |
| 41 const WebSecurityOrigin&) override { | |
| 42 double bufferSize = 0; | |
| 43 switch (latencyHint.category()) { | |
| 44 case WebAudioLatencyHint::kCategoryInteractive: | |
| 45 bufferSize = audioHardwareBufferSize(); | |
| 46 break; | |
| 47 case WebAudioLatencyHint::kCategoryBalanced: | |
| 48 bufferSize = audioHardwareBufferSize() * 2; | |
| 49 break; | |
| 50 case WebAudioLatencyHint::kCategoryPlayback: | |
| 51 bufferSize = audioHardwareBufferSize() * 4; | |
| 52 break; | |
| 53 default: | |
| 54 NOTREACHED(); | |
| 55 break; | |
| 56 } | |
| 57 | |
| 58 return new MockWebAudioDevice(audioHardwareSampleRate(), bufferSize); | |
| 59 } | |
| 60 | |
| 61 double audioHardwareSampleRate() override { return 44100; } | |
| 62 size_t audioHardwareBufferSize() override { return 128; } | |
| 63 }; | |
| 64 | |
| 65 } // anonymous namespace | |
| 66 | |
| 67 class AudioContextTest : public ::testing::Test { | |
| 68 protected: | |
| 69 void SetUp() override { m_dummyPageHolder = DummyPageHolder::create(); } | |
| 70 | |
| 71 void TearDown() override {} | |
|
tkent
2017/02/08 22:38:46
Is this necessary?
| |
| 72 | |
| 73 Document& document() { return m_dummyPageHolder->document(); } | |
| 74 | |
| 75 private: | |
| 76 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; | |
| 77 }; | |
| 78 | |
| 79 TEST_F(AudioContextTest, AudioContextOptions_WebAudioLatencyHint) { | |
| 80 ScopedTestingPlatformSupport<AudioContextTestPlatform> platform; | |
| 81 | |
| 82 AudioContextOptions interactiveOptions; | |
| 83 interactiveOptions.setLatencyHint( | |
| 84 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( | |
| 85 "interactive")); | |
| 86 AudioContext* interactiveContext = | |
| 87 AudioContext::create(document(), interactiveOptions, ASSERT_NO_EXCEPTION); | |
| 88 | |
| 89 AudioContextOptions balancedOptions; | |
| 90 balancedOptions.setLatencyHint( | |
| 91 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( | |
| 92 "balanced")); | |
| 93 AudioContext* balancedContext = | |
| 94 AudioContext::create(document(), balancedOptions, ASSERT_NO_EXCEPTION); | |
| 95 EXPECT_GT(balancedContext->baseLatency(), interactiveContext->baseLatency()); | |
| 96 | |
| 97 AudioContextOptions playbackOptions; | |
| 98 playbackOptions.setLatencyHint( | |
| 99 AudioContextLatencyCategoryOrDouble::fromAudioContextLatencyCategory( | |
| 100 "playback")); | |
| 101 AudioContext* playbackContext = | |
| 102 AudioContext::create(document(), playbackOptions, ASSERT_NO_EXCEPTION); | |
| 103 EXPECT_GT(playbackContext->baseLatency(), balancedContext->baseLatency()); | |
| 104 } | |
| 105 | |
| 106 } // namespace blink | |
| OLD | NEW |