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

Unified Diff: media/audio/audio_output_controller.cc

Issue 8229013: Fix problem when we did not play beginning of HTML5 audio stream in low latency mode. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/audio_output_controller.cc
===================================================================
--- media/audio/audio_output_controller.cc (revision 104827)
+++ media/audio/audio_output_controller.cc (working copy)
@@ -13,6 +13,10 @@
// Signal a pause in low-latency mode.
const int AudioOutputController::kPauseMark = -1;
+// Polling-related constants.
+const int AudioOutputController::kPollNumAttempts = 3;
+const int AudioOutputController::kPollPauseInMilliseconds = 3;
+
AudioOutputController::AudioOutputController(EventHandler* handler,
uint32 capacity,
SyncReader* sync_reader)
@@ -23,7 +27,8 @@
buffer_(0, capacity),
pending_request_(false),
sync_reader_(sync_reader),
- message_loop_(NULL) {
+ message_loop_(NULL),
+ number_polling_attempts_left_(0) {
}
AudioOutputController::~AudioOutputController() {
@@ -173,6 +178,42 @@
return;
state_ = kPlaying;
+ if (LowLatencyMode()) {
+ // Ask for first packet.
+ sync_reader_->UpdatePendingBytes(0);
+
+ // Cannot start stream immediately, should give renderer some time
+ // to deliver data.
+ number_polling_attempts_left_ = kPollNumAttempts;
+ message_loop_->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&AudioOutputController::DoPollIfDataReady, this),
+ kPollPauseInMilliseconds);
+ } else
+ StartStream();
+}
+
+void AudioOutputController::DoPollIfDataReady() {
acolwell GONE FROM CHROMIUM 2011/10/12 20:14:03 PollAndStartIfDataReady() might be a little more c
enal1 2011/10/13 00:39:22 Done.
+ DCHECK_EQ(message_loop_, MessageLoop::current());
+
+ // Being paranoic: do nothing if we were stopped/paused
+ // after DoPlay() but before DoStartStream().
+ if (state_ != kPlaying)
+ return;
+
+ if (--number_polling_attempts_left_ == 0 || sync_reader_->DataReady())
+ StartStream();
+ else {
+ message_loop_->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&AudioOutputController::DoPollIfDataReady, this),
+ kPollPauseInMilliseconds);
+ }
+}
+
+void AudioOutputController::StartStream() {
+ DCHECK_EQ(message_loop_, MessageLoop::current());
+
// We start the AudioOutputStream lazily.
stream_->Start(this);

Powered by Google App Engine
This is Rietveld 408576698