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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.h

Issue 2913303002: Avoid unsafe heap access from audio thread. (Closed)
Patch Set: fix comment spelling Created 3 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) 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 * 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // When a source node has no more processing to do (has finished playing), 266 // When a source node has no more processing to do (has finished playing),
267 // this method tells the context to release the corresponding node. 267 // this method tells the context to release the corresponding node.
268 void NotifySourceNodeFinishedProcessing(AudioHandler*); 268 void NotifySourceNodeFinishedProcessing(AudioHandler*);
269 269
270 // Called at the start of each render quantum. 270 // Called at the start of each render quantum.
271 void HandlePreRenderTasks(const AudioIOPosition& output_position); 271 void HandlePreRenderTasks(const AudioIOPosition& output_position);
272 272
273 // Called at the end of each render quantum. 273 // Called at the end of each render quantum.
274 void HandlePostRenderTasks(); 274 void HandlePostRenderTasks();
275 275
276 // Called periodically at the end of each render quantum to release
277 // finished source nodes. Updates m_finishedSourceNodes with nodes
278 // to be deleted. Returns true if any node needs deletion. Must be
279 // run from the audio thread.
280 bool ReleaseFinishedSourceNodes();
281
282 // The finished source nodes found by |releaseFinishedSourceNodes|
283 // will be removed on the main thread, which is done here.
284 void RemoveFinishedSourceNodes(bool needs_removal);
285
286 // Keeps track of the number of connections made. 276 // Keeps track of the number of connections made.
287 void IncrementConnectionCount() { 277 void IncrementConnectionCount() {
288 DCHECK(IsMainThread()); 278 DCHECK(IsMainThread());
289 connection_count_++; 279 connection_count_++;
290 } 280 }
291 281
292 unsigned ConnectionCount() const { return connection_count_; } 282 unsigned ConnectionCount() const { return connection_count_; }
293 283
294 DeferredTaskHandler& GetDeferredTaskHandler() const { 284 DeferredTaskHandler& GetDeferredTaskHandler() const {
295 return *deferred_task_handler_; 285 return *deferred_task_handler_;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 kAutoplayStatusCount 396 kAutoplayStatusCount
407 }; 397 };
408 398
409 bool is_cleared_; 399 bool is_cleared_;
410 void Clear(); 400 void Clear();
411 401
412 // When the context goes away, there might still be some sources which 402 // When the context goes away, there might still be some sources which
413 // haven't finished playing. Make sure to release them here. 403 // haven't finished playing. Make sure to release them here.
414 void ReleaseActiveSourceNodes(); 404 void ReleaseActiveSourceNodes();
415 405
416 // Actually remove the nodes noted for deletion by
417 // releaseFinishedSourceNodes. Must be run from the main thread,
418 // and must not be run with the context lock.
419 void RemoveFinishedSourceNodesOnMainThread();
420
421 // Returns the Document wich wich the instance is associated. 406 // Returns the Document wich wich the instance is associated.
422 Document* GetDocument() const; 407 Document* GetDocument() const;
423 408
424 // Returns the AutoplayPolicy currently applying to this instance. 409 // Returns the AutoplayPolicy currently applying to this instance.
425 AutoplayPolicy::Type GetAutoplayPolicy() const; 410 AutoplayPolicy::Type GetAutoplayPolicy() const;
426 411
427 // Returns whether the autoplay requirements are fulfilled. 412 // Returns whether the autoplay requirements are fulfilled.
428 bool AreAutoplayRequirementsFulfilled() const; 413 bool AreAutoplayRequirementsFulfilled() const;
429 414
430 // Listener for the PannerNodes 415 // Listener for the PannerNodes
431 Member<AudioListener> listener_; 416 Member<AudioListener> listener_;
432 417
433 // Only accessed in the audio thread. 418 // Accessed by audio thread and main thread, coordinated using
419 // the associated mutex.
420 //
434 // These raw pointers are safe because AudioSourceNodes in 421 // These raw pointers are safe because AudioSourceNodes in
435 // m_activeSourceNodes own them. 422 // active_source_nodes_ own them.
423 Mutex finished_source_handlers_mutex_;
436 Vector<AudioHandler*> finished_source_handlers_; 424 Vector<AudioHandler*> finished_source_handlers_;
437 425
438 // List of source nodes. This is either accessed when the graph lock is 426 // List of source nodes. This is either accessed when the graph lock is
439 // held, or on the main thread when the audio thread has finished. 427 // held, or on the main thread when the audio thread has finished.
440 // Oilpan: This Vector holds connection references. We must call 428 // Oilpan: This Vector holds connection references. We must call
441 // AudioHandler::makeConnection when we add an AudioNode to this, and must 429 // AudioHandler::makeConnection when we add an AudioNode to this, and must
442 // call AudioHandler::breakConnection() when we remove an AudioNode from 430 // call AudioHandler::breakConnection() when we remove an AudioNode from
443 // this. 431 // this.
444 HeapVector<Member<AudioNode>> active_source_nodes_; 432 HeapVector<Member<AudioNode>> active_source_nodes_;
445 433
446 // The main thread controls m_activeSourceNodes, all updates and additions
447 // are performed by it. When the audio thread marks a source node as finished,
448 // the nodes are added to |m_finishedSourceNodes| and scheduled for removal
449 // from |m_activeSourceNodes| by the main thread.
450 HashSet<UntracedMember<AudioNode>> finished_source_nodes_;
451
452 // FIXME(dominicc): Move these to AudioContext because only 434 // FIXME(dominicc): Move these to AudioContext because only
453 // it creates these Promises. 435 // it creates these Promises.
454 // Handle Promises for resume() and suspend() 436 // Handle Promises for resume() and suspend()
455 void ResolvePromisesForResume(); 437 void ResolvePromisesForResume();
456 void ResolvePromisesForResumeOnMainThread(); 438
439 void PerformCleanupOnMainThread();
440 void ScheduleMainThreadCleanup();
457 441
458 // When the context is going away, reject any pending script promise 442 // When the context is going away, reject any pending script promise
459 // resolvers. 443 // resolvers.
460 virtual void RejectPendingResolvers(); 444 virtual void RejectPendingResolvers();
461 445
462 // Record the current autoplay status and clear it. 446 // Record the current autoplay status and clear it.
463 void RecordAutoplayStatus(); 447 void RecordAutoplayStatus();
464 448
465 // True if we're in the process of resolving promises for resume(). Resolving 449 // True if we're in the process of resolving promises for resume(). Resolving
466 // can take some time and the audio context process loop is very fast, so we 450 // can take some time and the audio context process loop is very fast, so we
467 // don't want to call resolve an excessive number of times. 451 // don't want to call resolve an excessive number of times.
468 bool is_resolving_resume_promises_; 452 bool is_resolving_resume_promises_;
469 453
454 // Set to |true| by the audio thread when it posts a main-thread task to
455 // perform delayed state sync'ing updates that needs to be done on the main
456 // thread. Cleared by the main thread task once it has run.
457 bool has_posted_cleanup_task_;
458
470 // Whether a user gesture is required to start this AudioContext. 459 // Whether a user gesture is required to start this AudioContext.
471 bool user_gesture_required_; 460 bool user_gesture_required_;
472 461
473 unsigned connection_count_; 462 unsigned connection_count_;
474 463
475 // Graph locking. 464 // Graph locking.
476 RefPtr<DeferredTaskHandler> deferred_task_handler_; 465 RefPtr<DeferredTaskHandler> deferred_task_handler_;
477 466
478 // The state of the BaseAudioContext. 467 // The state of the BaseAudioContext.
479 AudioContextState context_state_; 468 AudioContextState context_state_;
(...skipping 28 matching lines...) Expand all
508 // It is somewhat arbitrary and could be increased if necessary. 497 // It is somewhat arbitrary and could be increased if necessary.
509 enum { kMaxNumberOfChannels = 32 }; 498 enum { kMaxNumberOfChannels = 32 };
510 499
511 Optional<AutoplayStatus> autoplay_status_; 500 Optional<AutoplayStatus> autoplay_status_;
512 AudioIOPosition output_position_; 501 AudioIOPosition output_position_;
513 }; 502 };
514 503
515 } // namespace blink 504 } // namespace blink
516 505
517 #endif // BaseAudioContext_h 506 #endif // BaseAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698