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 3 // found in the LICENSE file. 4 5 #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_AUDIO_LATENCY_HINT_H_ 6 #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_AUDIO_LATENCY_HINT_H_ 7 8 #include "base/check_op.h" 9 #include "base/notreached.h" 10 #include "third_party/blink/public/platform/web_string.h" 11 12 namespace blink { 13 14 class WebAudioLatencyHint { 15 public: 16 enum AudioContextLatencyCategory { 17 kCategoryInteractive, 18 kCategoryBalanced, 19 kCategoryPlayback, 20 kCategoryExact 21 }; 22 WebAudioLatencyHint(const WebString & category)23 explicit WebAudioLatencyHint(const WebString& category) { 24 if (category == "interactive") { 25 category_ = kCategoryInteractive; 26 } else if (category == "balanced") { 27 category_ = kCategoryBalanced; 28 } else if (category == "playback") { 29 category_ = kCategoryPlayback; 30 } else { 31 NOTREACHED(); 32 category_ = kCategoryInteractive; 33 } 34 } 35 WebAudioLatencyHint(AudioContextLatencyCategory category)36 explicit WebAudioLatencyHint(AudioContextLatencyCategory category) 37 : category_(category), seconds_(0) {} WebAudioLatencyHint(double seconds)38 explicit WebAudioLatencyHint(double seconds) 39 : category_(kCategoryExact), seconds_(seconds) {} 40 Category()41 AudioContextLatencyCategory Category() const { return category_; } Seconds()42 double Seconds() const { 43 DCHECK_EQ(category_, kCategoryExact); 44 return seconds_; 45 } 46 47 private: 48 AudioContextLatencyCategory category_; 49 double seconds_; 50 }; 51 52 } // namespace blink 53 54 #endif 55