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

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioDestination.cpp

Issue 2858223003: Add TRACE_EVENTX() in WebAudio rendering pipe line (Closed)
Patch Set: Adjusting trace locations Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 16 matching lines...) Expand all
27 */ 27 */
28 28
29 #include "platform/audio/AudioDestination.h" 29 #include "platform/audio/AudioDestination.h"
30 30
31 #include <memory> 31 #include <memory>
32 #include "platform/CrossThreadFunctional.h" 32 #include "platform/CrossThreadFunctional.h"
33 #include "platform/Histogram.h" 33 #include "platform/Histogram.h"
34 #include "platform/WebTaskRunner.h" 34 #include "platform/WebTaskRunner.h"
35 #include "platform/audio/AudioUtilities.h" 35 #include "platform/audio/AudioUtilities.h"
36 #include "platform/audio/PushPullFIFO.h" 36 #include "platform/audio/PushPullFIFO.h"
37 #include "platform/instrumentation/tracing/TraceEvent.h"
37 #include "platform/weborigin/SecurityOrigin.h" 38 #include "platform/weborigin/SecurityOrigin.h"
38 #include "platform/wtf/PtrUtil.h" 39 #include "platform/wtf/PtrUtil.h"
39 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
40 #include "public/platform/WebAudioLatencyHint.h" 41 #include "public/platform/WebAudioLatencyHint.h"
41 #include "public/platform/WebSecurityOrigin.h" 42 #include "public/platform/WebSecurityOrigin.h"
42 #include "public/platform/WebThread.h" 43 #include "public/platform/WebThread.h"
43 44
44 namespace blink { 45 namespace blink {
45 46
46 // FIFO Size. 47 // FIFO Size.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 94
94 AudioDestination::~AudioDestination() { 95 AudioDestination::~AudioDestination() {
95 Stop(); 96 Stop();
96 } 97 }
97 98
98 void AudioDestination::Render(const WebVector<float*>& destination_data, 99 void AudioDestination::Render(const WebVector<float*>& destination_data,
99 size_t number_of_frames, 100 size_t number_of_frames,
100 double delay, 101 double delay,
101 double delay_timestamp, 102 double delay_timestamp,
102 size_t prior_frames_skipped) { 103 size_t prior_frames_skipped) {
104 TRACE_EVENT1("webaudio", "AudioDestination::Render",
105 "callback_buffer_size", number_of_frames);
106
103 // This method is called by AudioDeviceThread. 107 // This method is called by AudioDeviceThread.
104 DCHECK(!IsRenderingThread()); 108 DCHECK(!IsRenderingThread());
105 109
106 CHECK_EQ(destination_data.size(), number_of_output_channels_); 110 CHECK_EQ(destination_data.size(), number_of_output_channels_);
107 CHECK_EQ(number_of_frames, callback_buffer_size_); 111 CHECK_EQ(number_of_frames, callback_buffer_size_);
108 112
109 // Note that this method is called by AudioDeviceThread. If FIFO is not ready, 113 // Note that this method is called by AudioDeviceThread. If FIFO is not ready,
110 // or the requested render size is greater than FIFO size return here. 114 // or the requested render size is greater than FIFO size return here.
111 // (crbug.com/692423) 115 // (crbug.com/692423)
112 if (!fifo_ || fifo_->length() < number_of_frames) 116 if (!fifo_ || fifo_->length() < number_of_frames)
(...skipping 15 matching lines...) Expand all
128 frames_to_render, delay, delay_timestamp, 132 frames_to_render, delay, delay_timestamp,
129 prior_frames_skipped)); 133 prior_frames_skipped));
130 } 134 }
131 } 135 }
132 136
133 void AudioDestination::RequestRenderOnWebThread(size_t frames_requested, 137 void AudioDestination::RequestRenderOnWebThread(size_t frames_requested,
134 size_t frames_to_render, 138 size_t frames_to_render,
135 double delay, 139 double delay,
136 double delay_timestamp, 140 double delay_timestamp,
137 size_t prior_frames_skipped) { 141 size_t prior_frames_skipped) {
142 TRACE_EVENT1("webaudio", "AudioDestination::RequestRenderOnWebThread",
143 "frames_to_render", frames_to_render);
144
138 // This method is called by WebThread. 145 // This method is called by WebThread.
139 DCHECK(IsRenderingThread()); 146 DCHECK(IsRenderingThread());
140 147
141 frames_elapsed_ -= std::min(frames_elapsed_, prior_frames_skipped); 148 frames_elapsed_ -= std::min(frames_elapsed_, prior_frames_skipped);
142 AudioIOPosition output_position; 149 AudioIOPosition output_position;
143 output_position.position = 150 output_position.position =
144 frames_elapsed_ / static_cast<double>(web_audio_device_->SampleRate()) - 151 frames_elapsed_ / static_cast<double>(web_audio_device_->SampleRate()) -
145 delay; 152 delay;
146 output_position.timestamp = delay_timestamp; 153 output_position.timestamp = delay_timestamp;
147 base::TimeTicks received_timestamp = base::TimeTicks::Now(); 154 base::TimeTicks received_timestamp = base::TimeTicks::Now();
(...skipping 21 matching lines...) Expand all
169 } 176 }
170 177
171 frames_elapsed_ += frames_requested; 178 frames_elapsed_ += frames_requested;
172 } 179 }
173 180
174 void AudioDestination::Start() { 181 void AudioDestination::Start() {
175 DCHECK(IsMainThread()); 182 DCHECK(IsMainThread());
176 183
177 // Start the "audio device" after the rendering thread is ready. 184 // Start the "audio device" after the rendering thread is ready.
178 if (web_audio_device_ && !is_playing_) { 185 if (web_audio_device_ && !is_playing_) {
186 TRACE_EVENT0("webaudio", "AudioDestination::Start");
179 rendering_thread_ = 187 rendering_thread_ =
180 Platform::Current()->CreateThread("WebAudio Rendering Thread"); 188 Platform::Current()->CreateThread("WebAudio Rendering Thread");
181 web_audio_device_->Start(); 189 web_audio_device_->Start();
182 is_playing_ = true; 190 is_playing_ = true;
183 } 191 }
184 } 192 }
185 193
186 void AudioDestination::Stop() { 194 void AudioDestination::Stop() {
187 DCHECK(IsMainThread()); 195 DCHECK(IsMainThread());
188 196
189 // This assumes stopping the "audio device" is synchronous and dumping the 197 // This assumes stopping the "audio device" is synchronous and dumping the
190 // rendering thread is safe after that. 198 // rendering thread is safe after that.
191 if (web_audio_device_ && is_playing_) { 199 if (web_audio_device_ && is_playing_) {
200 TRACE_EVENT0("webaudio", "AudioDestination::Stop");
192 web_audio_device_->Stop(); 201 web_audio_device_->Stop();
193 rendering_thread_.reset(); 202 rendering_thread_.reset();
194 is_playing_ = false; 203 is_playing_ = false;
195 } 204 }
196 } 205 }
197 206
198 size_t AudioDestination::CallbackBufferSize() const { 207 size_t AudioDestination::CallbackBufferSize() const {
199 DCHECK(IsMainThread()); 208 DCHECK(IsMainThread());
200 return callback_buffer_size_; 209 return callback_buffer_size_;
201 } 210 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 DCHECK(is_buffer_size_valid); 253 DCHECK(is_buffer_size_valid);
245 return is_buffer_size_valid; 254 return is_buffer_size_valid;
246 } 255 }
247 256
248 bool AudioDestination::IsRenderingThread() { 257 bool AudioDestination::IsRenderingThread() {
249 return static_cast<ThreadIdentifier>(rendering_thread_->ThreadId()) == 258 return static_cast<ThreadIdentifier>(rendering_thread_->ThreadId()) ==
250 CurrentThread(); 259 CurrentThread();
251 } 260 }
252 261
253 } // namespace blink 262 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioDestinationNode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698