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

Side by Side Diff: media/filters/audio_renderer_impl.cc

Issue 363093003: Always run AudioRendererImpl's flush callback asynchronously. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/media_unittests.gtest_mac.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/audio_renderer_impl.h" 5 #include "media/filters/audio_renderer_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Flush() may have been called while underflowed/not fully buffered. 178 // Flush() may have been called while underflowed/not fully buffered.
179 if (buffering_state_ != BUFFERING_HAVE_NOTHING) 179 if (buffering_state_ != BUFFERING_HAVE_NOTHING)
180 SetBufferingState_Locked(BUFFERING_HAVE_NOTHING); 180 SetBufferingState_Locked(BUFFERING_HAVE_NOTHING);
181 181
182 earliest_end_time_ = now_cb_.Run(); 182 earliest_end_time_ = now_cb_.Run();
183 splicer_->Reset(); 183 splicer_->Reset();
184 if (buffer_converter_) 184 if (buffer_converter_)
185 buffer_converter_->Reset(); 185 buffer_converter_->Reset();
186 algorithm_->FlushBuffers(); 186 algorithm_->FlushBuffers();
187 } 187 }
188 base::ResetAndReturn(&flush_cb_).Run(); 188
189 // Changes in buffering state are always posted. Flush callback must only be
190 // run after buffering state has been set back to nothing.
191 task_runner_->PostTask(FROM_HERE, base::ResetAndReturn(&flush_cb_));
189 } 192 }
190 193
191 void AudioRendererImpl::Stop(const base::Closure& callback) { 194 void AudioRendererImpl::Stop(const base::Closure& callback) {
192 DVLOG(1) << __FUNCTION__; 195 DVLOG(1) << __FUNCTION__;
193 DCHECK(task_runner_->BelongsToCurrentThread()); 196 DCHECK(task_runner_->BelongsToCurrentThread());
194 DCHECK(!callback.is_null()); 197 DCHECK(!callback.is_null());
195 198
196 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing 199 // TODO(scherkus): Consider invalidating |weak_factory_| and replacing
197 // task-running guards that check |state_| with DCHECK(). 200 // task-running guards that check |state_| with DCHECK().
198 201
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 DCHECK(!buffering_state_cb.is_null()); 253 DCHECK(!buffering_state_cb.is_null());
251 DCHECK(!ended_cb.is_null()); 254 DCHECK(!ended_cb.is_null());
252 DCHECK(!error_cb.is_null()); 255 DCHECK(!error_cb.is_null());
253 DCHECK_EQ(kUninitialized, state_); 256 DCHECK_EQ(kUninitialized, state_);
254 DCHECK(sink_); 257 DCHECK(sink_);
255 258
256 state_ = kInitializing; 259 state_ = kInitializing;
257 260
258 init_cb_ = init_cb; 261 init_cb_ = init_cb;
259 time_cb_ = time_cb; 262 time_cb_ = time_cb;
260 // Callback can be run from audio callback thread in Render(). 263 buffering_state_cb_ = buffering_state_cb;
261 buffering_state_cb_ = BindToCurrentLoop(buffering_state_cb);
262 ended_cb_ = ended_cb; 264 ended_cb_ = ended_cb;
263 error_cb_ = error_cb; 265 error_cb_ = error_cb;
264 266
265 expecting_config_changes_ = stream->SupportsConfigChanges(); 267 expecting_config_changes_ = stream->SupportsConfigChanges();
266 if (!expecting_config_changes_) { 268 if (!expecting_config_changes_) {
267 // The actual buffer size is controlled via the size of the AudioBus 269 // The actual buffer size is controlled via the size of the AudioBus
268 // provided to Render(), so just choose something reasonable here for looks. 270 // provided to Render(), so just choose something reasonable here for looks.
269 int buffer_size = stream->audio_decoder_config().samples_per_second() / 100; 271 int buffer_size = stream->audio_decoder_config().samples_per_second() / 100;
270 audio_parameters_.Reset( 272 audio_parameters_.Reset(
271 AudioParameters::AUDIO_PCM_LOW_LATENCY, 273 AudioParameters::AUDIO_PCM_LOW_LATENCY,
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 CHECK(splicer_->AddInput(buffer_converter_->GetNextBuffer())); 723 CHECK(splicer_->AddInput(buffer_converter_->GetNextBuffer()));
722 } 724 }
723 725
724 void AudioRendererImpl::SetBufferingState_Locked( 726 void AudioRendererImpl::SetBufferingState_Locked(
725 BufferingState buffering_state) { 727 BufferingState buffering_state) {
726 DVLOG(1) << __FUNCTION__ << " : " << buffering_state_ << " -> " 728 DVLOG(1) << __FUNCTION__ << " : " << buffering_state_ << " -> "
727 << buffering_state; 729 << buffering_state;
728 DCHECK_NE(buffering_state_, buffering_state); 730 DCHECK_NE(buffering_state_, buffering_state);
729 lock_.AssertAcquired(); 731 lock_.AssertAcquired();
730 buffering_state_ = buffering_state; 732 buffering_state_ = buffering_state;
731 buffering_state_cb_.Run(buffering_state_); 733
734 task_runner_->PostTask(FROM_HERE,
735 base::Bind(buffering_state_cb_, buffering_state_));
732 } 736 }
733 737
734 } // namespace media 738 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/gtest_exclude/media_unittests.gtest_mac.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698