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

Side by Side Diff: media/audio/audio_output_controller.cc

Issue 16189009: Reduce wait time for Windows in AudioOutputController:WaitTillDataReady() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make sure histogram names match Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('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/audio/audio_output_controller.h" 5 #include "media/audio/audio_output_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 buffers_state.total_bytes() + frames * params_.GetBytesPerFrame()); 302 buffers_state.total_bytes() + frames * params_.GetBytesPerFrame());
303 303
304 silence_detector_->Scan(dest, frames); 304 silence_detector_->Scan(dest, frames);
305 305
306 AllowEntryToOnMoreIOData(); 306 AllowEntryToOnMoreIOData();
307 return frames; 307 return frames;
308 } 308 }
309 309
310 void AudioOutputController::WaitTillDataReady() { 310 void AudioOutputController::WaitTillDataReady() {
311 // Most of the time the data is ready already. 311 // Most of the time the data is ready already.
312 if (sync_reader_->DataReady()) 312 bool ready = sync_reader_->DataReady();
313 UMA_HISTOGRAM_BOOLEAN("Media.AudioOutputController.DataReady", ready);
DaleCurtis 2013/05/29 18:27:46 Instead of adding this new statistic we should fix
DaveMoore 2013/05/29 18:33:03 Done.
314 if (ready)
313 return; 315 return;
314 316
315 base::TimeTicks start = base::TimeTicks::Now(); 317 base::TimeTicks start = base::TimeTicks::Now();
318 const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20);
316 #if defined(OS_WIN) 319 #if defined(OS_WIN)
317 // Wait for up to 683ms for DataReady(). 683ms was chosen because it's larger 320 // Sleep(0) on windows lets the other threads run.
318 // than the playback time of the WaveOut buffer size using the minimum
319 // supported sample rate: 2048 / 3000 = ~683ms.
320 // TODO(davemoore): We think this can be reduced to 20ms based on
321 // http://crrev.com/180102 but will do that in separate cl for mergability.
322 const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(683);
323 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0); 321 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0);
324 #else 322 #else
325 const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20);
326 // We want to sleep for a bit here, as otherwise a backgrounded renderer won't 323 // We want to sleep for a bit here, as otherwise a backgrounded renderer won't
327 // get enough cpu to send the data and the high priority thread in the browser 324 // get enough cpu to send the data and the high priority thread in the browser
328 // will use up a core causing even more skips. 325 // will use up a core causing even more skips.
329 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2); 326 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2);
330 #endif 327 #endif
331 base::TimeDelta time_since_start; 328 base::TimeDelta time_since_start;
332 do { 329 do {
333 base::PlatformThread::Sleep(kSleep); 330 base::PlatformThread::Sleep(kSleep);
334 time_since_start = base::TimeTicks::Now() - start; 331 time_since_start = base::TimeTicks::Now() - start;
335 } while (!sync_reader_->DataReady() && (time_since_start < kMaxWait)); 332 } while (!sync_reader_->DataReady() && (time_since_start < kMaxWait));
336 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady", 333 UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputController.WaitForDataTime",
337 time_since_start, 334 time_since_start,
338 base::TimeDelta::FromMilliseconds(1), 335 base::TimeDelta::FromMilliseconds(1),
339 base::TimeDelta::FromMilliseconds(1000), 336 base::TimeDelta::FromMilliseconds(1000),
340 50); 337 50);
341 } 338 }
342 339
343 void AudioOutputController::OnError(AudioOutputStream* stream) { 340 void AudioOutputController::OnError(AudioOutputStream* stream) {
344 // Handle error on the audio controller thread. 341 // Handle error on the audio controller thread.
345 message_loop_->PostTask(FROM_HERE, base::Bind( 342 message_loop_->PostTask(FROM_HERE, base::Bind(
346 &AudioOutputController::DoReportError, this)); 343 &AudioOutputController::DoReportError, this));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 DCHECK(base::AtomicRefCountIsZero(&num_allowed_io_)); 439 DCHECK(base::AtomicRefCountIsZero(&num_allowed_io_));
443 base::AtomicRefCountInc(&num_allowed_io_); 440 base::AtomicRefCountInc(&num_allowed_io_);
444 } 441 }
445 442
446 void AudioOutputController::DisallowEntryToOnMoreIOData() { 443 void AudioOutputController::DisallowEntryToOnMoreIOData() {
447 const bool is_zero = !base::AtomicRefCountDec(&num_allowed_io_); 444 const bool is_zero = !base::AtomicRefCountDec(&num_allowed_io_);
448 DCHECK(is_zero); 445 DCHECK(is_zero);
449 } 446 }
450 447
451 } // namespace media 448 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698