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

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

Issue 2889393003: Lazy initialization of the rendering thread in OfflineAudioContext (Closed)
Patch Set: Adjusting number of contexts for timed-out trybots 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
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/OfflineAudioDestinationNode.h ('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) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, 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 28 matching lines...) Expand all
39 #include "platform/wtf/PtrUtil.h" 39 #include "platform/wtf/PtrUtil.h"
40 #include "public/platform/Platform.h" 40 #include "public/platform/Platform.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 OfflineAudioDestinationHandler::OfflineAudioDestinationHandler( 44 OfflineAudioDestinationHandler::OfflineAudioDestinationHandler(
45 AudioNode& node, 45 AudioNode& node,
46 AudioBuffer* render_target) 46 AudioBuffer* render_target)
47 : AudioDestinationHandler(node), 47 : AudioDestinationHandler(node),
48 render_target_(render_target), 48 render_target_(render_target),
49 render_thread_(
50 Platform::Current()->CreateThread("offline audio renderer")),
51 frames_processed_(0), 49 frames_processed_(0),
52 frames_to_process_(0), 50 frames_to_process_(0),
53 is_rendering_started_(false), 51 is_rendering_started_(false),
54 should_suspend_(false) { 52 should_suspend_(false) {
55 render_bus_ = AudioBus::Create(render_target->numberOfChannels(), 53 render_bus_ = AudioBus::Create(render_target->numberOfChannels(),
56 AudioUtilities::kRenderQuantumFrames); 54 AudioUtilities::kRenderQuantumFrames);
57 frames_to_process_ = render_target_->length(); 55 frames_to_process_ = render_target_->length();
58 56
59 // Node-specific defaults. 57 // Node-specific defaults.
60 channel_count_ = render_target_->numberOfChannels(); 58 channel_count_ = render_target_->numberOfChannels();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 void OfflineAudioDestinationHandler::StopRendering() { 129 void OfflineAudioDestinationHandler::StopRendering() {
132 // offline audio rendering CANNOT BE stopped by JavaScript. 130 // offline audio rendering CANNOT BE stopped by JavaScript.
133 NOTREACHED(); 131 NOTREACHED();
134 } 132 }
135 133
136 size_t OfflineAudioDestinationHandler::CallbackBufferSize() const { 134 size_t OfflineAudioDestinationHandler::CallbackBufferSize() const {
137 // The callback buffer size has no meaning for an offline context. 135 // The callback buffer size has no meaning for an offline context.
138 NOTREACHED(); 136 NOTREACHED();
139 return 0; 137 return 0;
140 } 138 }
141 WebThread* OfflineAudioDestinationHandler::OfflineRenderThread() {
142 DCHECK(render_thread_);
143 139
144 return render_thread_.get(); 140 void OfflineAudioDestinationHandler::InitializeOfflineRenderThread() {
141 DCHECK(IsMainThread());
142 render_thread_ = Platform::Current()->CreateThread("offline audio renderer");
145 } 143 }
146 144
147 void OfflineAudioDestinationHandler::StartOfflineRendering() { 145 void OfflineAudioDestinationHandler::StartOfflineRendering() {
148 DCHECK(!IsMainThread()); 146 DCHECK(!IsMainThread());
149 147
150 DCHECK(render_bus_); 148 DCHECK(render_bus_);
151 if (!render_bus_) 149 if (!render_bus_)
152 return; 150 return;
153 151
154 bool is_audio_context_initialized = Context()->IsDestinationInitialized(); 152 bool is_audio_context_initialized = Context()->IsDestinationInitialized();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 244 }
247 245
248 void OfflineAudioDestinationHandler::NotifySuspend(size_t frame) { 246 void OfflineAudioDestinationHandler::NotifySuspend(size_t frame) {
249 DCHECK(IsMainThread()); 247 DCHECK(IsMainThread());
250 248
251 if (Context()) 249 if (Context())
252 Context()->ResolveSuspendOnMainThread(frame); 250 Context()->ResolveSuspendOnMainThread(frame);
253 } 251 }
254 252
255 void OfflineAudioDestinationHandler::NotifyComplete() { 253 void OfflineAudioDestinationHandler::NotifyComplete() {
254 DCHECK(IsMainThread());
255
256 // Nullify the rendering thread to save the system resource.
257 render_thread_.reset();
258
256 // The OfflineAudioContext might be gone. 259 // The OfflineAudioContext might be gone.
257 if (Context()) 260 if (Context())
258 Context()->FireCompletionEvent(); 261 Context()->FireCompletionEvent();
259 } 262 }
260 263
261 bool OfflineAudioDestinationHandler::RenderIfNotSuspended( 264 bool OfflineAudioDestinationHandler::RenderIfNotSuspended(
262 AudioBus* source_bus, 265 AudioBus* source_bus,
263 AudioBus* destination_bus, 266 AudioBus* destination_bus,
264 size_t number_of_frames) { 267 size_t number_of_frames) {
265 // We don't want denormals slowing down any of the audio processing 268 // We don't want denormals slowing down any of the audio processing
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 SetHandler(OfflineAudioDestinationHandler::Create(*this, render_target)); 344 SetHandler(OfflineAudioDestinationHandler::Create(*this, render_target));
342 } 345 }
343 346
344 OfflineAudioDestinationNode* OfflineAudioDestinationNode::Create( 347 OfflineAudioDestinationNode* OfflineAudioDestinationNode::Create(
345 BaseAudioContext* context, 348 BaseAudioContext* context,
346 AudioBuffer* render_target) { 349 AudioBuffer* render_target) {
347 return new OfflineAudioDestinationNode(*context, render_target); 350 return new OfflineAudioDestinationNode(*context, render_target);
348 } 351 }
349 352
350 } // namespace blink 353 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/OfflineAudioDestinationNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698