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

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

Issue 11348166: Always wait for DataReady() on Windows WaveOut. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: The comment is law. Timeout. Created 8 years 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 | « media/audio/audio_output_controller.h ('k') | media/audio/win/waveout_output_win.cc » ('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/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
11 #include "base/threading/platform_thread.h" 11 #include "base/threading/platform_thread.h"
12 #include "base/threading/thread_restrictions.h" 12 #include "base/threading/thread_restrictions.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "build/build_config.h"
14 #include "media/audio/shared_memory_util.h" 15 #include "media/audio/shared_memory_util.h"
15 16
16 using base::Time; 17 using base::Time;
17 using base::TimeDelta; 18 using base::TimeDelta;
18 using base::WaitableEvent; 19 using base::WaitableEvent;
19 20
20 namespace media { 21 namespace media {
21 22
22 // Polling-related constants. 23 // Polling-related constants.
23 const int AudioOutputController::kPollNumAttempts = 3; 24 const int AudioOutputController::kPollNumAttempts = 3;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 313 }
313 } 314 }
314 315
315 int frames = sync_reader_->Read(source, dest); 316 int frames = sync_reader_->Read(source, dest);
316 sync_reader_->UpdatePendingBytes( 317 sync_reader_->UpdatePendingBytes(
317 buffers_state.total_bytes() + frames * params_.GetBytesPerFrame()); 318 buffers_state.total_bytes() + frames * params_.GetBytesPerFrame());
318 return frames; 319 return frames;
319 } 320 }
320 321
321 void AudioOutputController::WaitTillDataReady() { 322 void AudioOutputController::WaitTillDataReady() {
322 if (!sync_reader_->DataReady()) { 323 #if defined(OS_WIN) || defined(OS_MAC)
323 // In the different place we use different mechanism to poll, get max 324 base::Time start = base::Time::Now();
324 // polling delay from constants used there. 325 // Wait for up to 1.5 seconds for DataReady(). 1.5 seconds was chosen because
325 const base::TimeDelta kMaxPollingDelay = TimeDelta::FromMilliseconds( 326 // it's larger than the playback time of the WaveOut buffer size using the
326 kPollNumAttempts * kPollPauseInMilliseconds); 327 // minimum supported sample rate: 4096 / 3000 = ~1.4 seconds. Even a client
327 Time start_time = Time::Now(); 328 // expecting real time playout should be able to fill in this time.
328 do { 329 const base::TimeDelta max_wait = base::TimeDelta::FromMilliseconds(1500);
scherkus (not reviewing) 2012/11/21 22:46:55 s/max_wait/kMaxWait/
DaleCurtis 2012/11/21 22:50:15 Done.
329 base::PlatformThread::Sleep(TimeDelta::FromMilliseconds(1)); 330 while (!sync_reader_->DataReady() &&
330 } while (!sync_reader_->DataReady() && 331 ((base::Time::Now() - start) < max_wait)) {
331 Time::Now() - start_time < kMaxPollingDelay); 332 base::PlatformThread::YieldCurrentThread();
332 } 333 }
334 #else
335 // WaitTillDataReady() is deprecated and should not be used.
scherkus (not reviewing) 2012/11/21 22:46:55 make this a string?
DaleCurtis 2012/11/21 22:50:15 I think it's unncessary and just adds string bloat
336 CHECK(false);
337 #endif
333 } 338 }
334 339
335 void AudioOutputController::OnError(AudioOutputStream* stream, int code) { 340 void AudioOutputController::OnError(AudioOutputStream* stream, int code) {
336 // Handle error on the audio controller thread. 341 // Handle error on the audio controller thread.
337 message_loop_->PostTask(FROM_HERE, base::Bind( 342 message_loop_->PostTask(FROM_HERE, base::Bind(
338 &AudioOutputController::DoReportError, this, code)); 343 &AudioOutputController::DoReportError, this, code));
339 } 344 }
340 345
341 void AudioOutputController::DoStopCloseAndClearStream(WaitableEvent* done) { 346 void AudioOutputController::DoStopCloseAndClearStream(WaitableEvent* done) {
342 DCHECK(message_loop_->BelongsToCurrentThread()); 347 DCHECK(message_loop_->BelongsToCurrentThread());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 case kPausedWhenStarting: 391 case kPausedWhenStarting:
387 case kPaused: 392 case kPaused:
388 // From the outside these three states are equivalent. 393 // From the outside these three states are equivalent.
389 return; 394 return;
390 default: 395 default:
391 NOTREACHED() << "Invalid original state."; 396 NOTREACHED() << "Invalid original state.";
392 } 397 }
393 } 398 }
394 399
395 } // namespace media 400 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_controller.h ('k') | media/audio/win/waveout_output_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698