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

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

Issue 2889393003: Lazy initialization of the rendering thread in OfflineAudioContext (Closed)
Patch Set: Change thread creation location and add layout test 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
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 "cannot call startRendering more than once")); 205 "cannot call startRendering more than once"));
206 } 206 }
207 207
208 DCHECK(!is_rendering_started_); 208 DCHECK(!is_rendering_started_);
209 209
210 complete_resolver_ = ScriptPromiseResolver::Create(script_state); 210 complete_resolver_ = ScriptPromiseResolver::Create(script_state);
211 211
212 // Start rendering and return the promise. 212 // Start rendering and return the promise.
213 is_rendering_started_ = true; 213 is_rendering_started_ = true;
214 SetContextState(kRunning); 214 SetContextState(kRunning);
215 DestinationHandler().InitializeOfflineRenderThread();
215 DestinationHandler().StartRendering(); 216 DestinationHandler().StartRendering();
216 217
217 return complete_resolver_->Promise(); 218 return complete_resolver_->Promise();
218 } 219 }
219 220
220 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* script_state) { 221 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* script_state) {
221 LOG(FATAL) << "This CANNOT be called on OfflineAudioContext; this is only to " 222 LOG(FATAL) << "This CANNOT be called on OfflineAudioContext; this is only to "
222 "implement the pure virtual interface from BaseAudioContext."; 223 "implement the pure virtual interface from BaseAudioContext.";
223 return ScriptPromise(); 224 return ScriptPromise();
224 } 225 }
225 226
226 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* script_state, 227 ScriptPromise OfflineAudioContext::suspendContext(ScriptState* script_state,
227 double when) { 228 double when) {
228 DCHECK(IsMainThread()); 229 DCHECK(IsMainThread());
229 230
230 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 231 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
231 ScriptPromise promise = resolver->Promise(); 232 ScriptPromise promise = resolver->Promise();
232 233
233 // The render thread does not exist; reject the promise.
234 if (!DestinationHandler().OfflineRenderThread()) {
Raymond Toy 2017/05/23 17:05:01 What happened before if I try to suspend a context
hongchan 2017/05/23 18:10:38 A good catch. My mistake. I forgot to revert this
Raymond Toy 2017/05/23 18:14:41 In that case, we want to include a test for this w
235 resolver->Reject(DOMException::Create(kInvalidStateError,
236 "the rendering is already finished"));
237 return promise;
238 }
239
240 // The specified suspend time is negative; reject the promise. 234 // The specified suspend time is negative; reject the promise.
241 if (when < 0) { 235 if (when < 0) {
242 resolver->Reject(DOMException::Create( 236 resolver->Reject(DOMException::Create(
243 kInvalidStateError, 237 kInvalidStateError,
244 "negative suspend time (" + String::Number(when) + ") is not allowed")); 238 "negative suspend time (" + String::Number(when) + ") is not allowed"));
245 return promise; 239 return promise;
246 } 240 }
247 241
248 // Quantize (to the lower boundary) the suspend time by the render quantum. 242 // Quantize (to the lower boundary) the suspend time by the render quantum.
249 size_t frame = when * sampleRate(); 243 size_t frame = when * sampleRate();
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 446
453 // Note that the GraphLock is required before this check. Since this needs 447 // Note that the GraphLock is required before this check. Since this needs
454 // to run on the audio thread, OfflineGraphAutoLocker must be used. 448 // to run on the audio thread, OfflineGraphAutoLocker must be used.
455 if (scheduled_suspends_.Contains(CurrentSampleFrame())) 449 if (scheduled_suspends_.Contains(CurrentSampleFrame()))
456 return true; 450 return true;
457 451
458 return false; 452 return false;
459 } 453 }
460 454
461 } // namespace blink 455 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698