Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/OfflineAudioContext.cpp

Issue 1978403004: Add UMA histograms for WebAudio (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address more review comments. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012, Google Inc. All rights reserved. 2 * Copyright (C) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 17 matching lines...) Expand all
28 #include "bindings/core/v8/ScriptState.h" 28 #include "bindings/core/v8/ScriptState.h"
29 #include "core/dom/DOMException.h" 29 #include "core/dom/DOMException.h"
30 #include "core/dom/Document.h" 30 #include "core/dom/Document.h"
31 #include "core/dom/ExceptionCode.h" 31 #include "core/dom/ExceptionCode.h"
32 #include "core/dom/ExecutionContext.h" 32 #include "core/dom/ExecutionContext.h"
33 #include "modules/webaudio/AudioListener.h" 33 #include "modules/webaudio/AudioListener.h"
34 #include "modules/webaudio/DeferredTaskHandler.h" 34 #include "modules/webaudio/DeferredTaskHandler.h"
35 #include "modules/webaudio/OfflineAudioCompletionEvent.h" 35 #include "modules/webaudio/OfflineAudioCompletionEvent.h"
36 #include "modules/webaudio/OfflineAudioDestinationNode.h" 36 #include "modules/webaudio/OfflineAudioDestinationNode.h"
37 37
38 #include "platform/Histogram.h"
38 #include "platform/audio/AudioUtilities.h" 39 #include "platform/audio/AudioUtilities.h"
39 40
40 namespace blink { 41 namespace blink {
41 42
42 OfflineAudioContext* OfflineAudioContext::create(ExecutionContext* context, unsi gned numberOfChannels, unsigned numberOfFrames, float sampleRate, ExceptionState & exceptionState) 43 OfflineAudioContext* OfflineAudioContext::create(ExecutionContext* context, unsi gned numberOfChannels, unsigned numberOfFrames, float sampleRate, ExceptionState & exceptionState)
43 { 44 {
44 // FIXME: add support for workers. 45 // FIXME: add support for workers.
45 if (!context || !context->isDocument()) { 46 if (!context || !context->isDocument()) {
46 exceptionState.throwDOMException( 47 exceptionState.throwDOMException(
47 NotSupportedError, 48 NotSupportedError,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 84
84 if (!audioContext->destination()) { 85 if (!audioContext->destination()) {
85 exceptionState.throwDOMException( 86 exceptionState.throwDOMException(
86 NotSupportedError, 87 NotSupportedError,
87 "OfflineAudioContext(" + String::number(numberOfChannels) 88 "OfflineAudioContext(" + String::number(numberOfChannels)
88 + ", " + String::number(numberOfFrames) 89 + ", " + String::number(numberOfFrames)
89 + ", " + String::number(sampleRate) 90 + ", " + String::number(sampleRate)
90 + ")"); 91 + ")");
91 } 92 }
92 93
94 DEFINE_STATIC_LOCAL(SparseHistogram, offlineContextChannelCountHistogram,
95 ("WebAudio.OfflineAudioContext.ChannelCount"));
96 DEFINE_STATIC_LOCAL(SparseHistogram, offlineContextLengthHistogram,
97 ("WebAudio.OfflineAudioContext.Length"));
98 DEFINE_STATIC_LOCAL(SparseHistogram, offlineContextSampleRateHistogram,
99 ("WebAudio.OfflineAudioContext.SampleRate"));
100
101 offlineContextChannelCountHistogram.sample(numberOfChannels);
102 // To limit the size of the histogram, record 10*log10(numberOfFrames),
103 // clipping the value at 60 (buffer size of 1 million frames). This
104 // gives 60 entries in the histogram.
105 double histogramValue = 10*log10(numberOfFrames);
106 offlineContextLengthHistogram.sample(clampTo(static_cast<int>(0.5 + histogra mValue), 0, 60));
107
108 // To limit the size of the histogram, record
109 // 40+10*log2(sampleRate/48000), clipping the value to lie between 0
110 // and 60. These limits correspond to a min rate of 3000 and a max of
111 // 192000. This gives 60 entries in the histogram.
112 histogramValue = 40 + 10*log2(sampleRate / 48000);
113 offlineContextSampleRateHistogram.sample(clampTo(static_cast<int>(0.5 + hist ogramValue), 0, 60));
114
93 audioContext->suspendIfNeeded(); 115 audioContext->suspendIfNeeded();
94 return audioContext; 116 return audioContext;
95 } 117 }
96 118
97 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh annels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionState) 119 OfflineAudioContext::OfflineAudioContext(Document* document, unsigned numberOfCh annels, size_t numberOfFrames, float sampleRate, ExceptionState& exceptionState)
98 : AbstractAudioContext(document, numberOfChannels, numberOfFrames, sampleRat e) 120 : AbstractAudioContext(document, numberOfChannels, numberOfFrames, sampleRat e)
99 , m_isRenderingStarted(false) 121 , m_isRenderingStarted(false)
100 , m_totalRenderFrames(numberOfFrames) 122 , m_totalRenderFrames(numberOfFrames)
101 { 123 {
102 // Create a new destination for offline rendering. 124 // Create a new destination for offline rendering.
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // Note that the GraphLock is required before this check. Since this needs 438 // Note that the GraphLock is required before this check. Since this needs
417 // to run on the audio thread, OfflineGraphAutoLocker must be used. 439 // to run on the audio thread, OfflineGraphAutoLocker must be used.
418 if (m_scheduledSuspends.contains(currentSampleFrame())) 440 if (m_scheduledSuspends.contains(currentSampleFrame()))
419 return true; 441 return true;
420 442
421 return false; 443 return false;
422 } 444 }
423 445
424 } // namespace blink 446 } // namespace blink
425 447
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698