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

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: Remove histogram change as asked 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 | 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 // 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (sync_reader_->DataReady())
313 return; 313 return;
314 314
315 base::TimeTicks start = base::TimeTicks::Now(); 315 base::TimeTicks start = base::TimeTicks::Now();
316 const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20);
316 #if defined(OS_WIN) 317 #if defined(OS_WIN)
317 // Wait for up to 683ms for DataReady(). 683ms was chosen because it's larger 318 // 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); 319 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0);
324 #else 320 #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 321 // 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 322 // 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. 323 // will use up a core causing even more skips.
329 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2); 324 const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2);
330 #endif 325 #endif
331 base::TimeDelta time_since_start; 326 base::TimeDelta time_since_start;
332 do { 327 do {
333 base::PlatformThread::Sleep(kSleep); 328 base::PlatformThread::Sleep(kSleep);
334 time_since_start = base::TimeTicks::Now() - start; 329 time_since_start = base::TimeTicks::Now() - start;
335 } while (!sync_reader_->DataReady() && (time_since_start < kMaxWait)); 330 } while (!sync_reader_->DataReady() && (time_since_start < kMaxWait));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 DCHECK(base::AtomicRefCountIsZero(&num_allowed_io_)); 437 DCHECK(base::AtomicRefCountIsZero(&num_allowed_io_));
443 base::AtomicRefCountInc(&num_allowed_io_); 438 base::AtomicRefCountInc(&num_allowed_io_);
444 } 439 }
445 440
446 void AudioOutputController::DisallowEntryToOnMoreIOData() { 441 void AudioOutputController::DisallowEntryToOnMoreIOData() {
447 const bool is_zero = !base::AtomicRefCountDec(&num_allowed_io_); 442 const bool is_zero = !base::AtomicRefCountDec(&num_allowed_io_);
448 DCHECK(is_zero); 443 DCHECK(is_zero);
449 } 444 }
450 445
451 } // namespace media 446 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698