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

Unified Diff: content/browser/renderer_host/media/audio_sync_reader.cc

Issue 22886005: Switch audio synchronization from sleep() based to select() based. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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: content/browser/renderer_host/media/audio_sync_reader.cc
diff --git a/content/browser/renderer_host/media/audio_sync_reader.cc b/content/browser/renderer_host/media/audio_sync_reader.cc
index dea8ae2a2075a8b5f7cbfcd0efca8bad86dd1672..4f855c599427c2ce3016282b465c7ef1af27fe70 100644
--- a/content/browser/renderer_host/media/audio_sync_reader.cc
+++ b/content/browser/renderer_host/media/audio_sync_reader.cc
@@ -26,7 +26,10 @@ AudioSyncReader::AudioSyncReader(base::SharedMemory* shared_memory,
mute_audio_(CommandLine::ForCurrentProcess()->HasSwitch(
switches::kMuteAudio)),
renderer_callback_count_(0),
- renderer_missed_callback_count_(0) {
+ renderer_missed_callback_count_(0),
+ // TODO(dalecurtis): Cap it at 20ms?
+ maximum_wait_time_(params.GetBufferDuration() / 2),
henrika (OOO until Aug 14) 2013/08/20 07:50:30 Just checking; what is the unit of GetBufferDurati
DaleCurtis 2013/09/11 01:16:03 base::TimeDelta
+ buffer_index_(0) {
packet_size_ = media::PacketSizeInBytes(shared_memory_->requested_size());
int input_memory_size = 0;
int output_memory_size = AudioBus::CalculateMemorySize(params);
@@ -68,16 +71,15 @@ void AudioSyncReader::UpdatePendingBytes(uint32 bytes) {
if (socket_) {
socket_->Send(&bytes, sizeof(bytes));
+ buffer_index_++;
tommi (sloooow) - chröme 2013/08/20 10:55:57 nit: ++buffer_index_;
DaleCurtis 2013/09/11 01:16:03 Done.
}
}
int AudioSyncReader::Read(bool block, const AudioBus* source, AudioBus* dest) {
++renderer_callback_count_;
- if (!DataReady()) {
+ if (!WaitTillDataReady()) {
++renderer_missed_callback_count_;
-
- if (block)
- WaitTillDataReady();
+ return 0;
}
// Copy optional synchronized live audio input for consumption by renderer
@@ -173,28 +175,36 @@ bool AudioSyncReader::PrepareForeignSocketHandle(
}
#endif
-void AudioSyncReader::WaitTillDataReady() {
+bool AudioSyncReader::WaitTillDataReady() {
+ if (!socket_)
tommi (sloooow) - chröme 2013/08/20 10:55:57 is this something exected or unexpected (i.e. [D]C
DaleCurtis 2013/09/11 01:16:03 Set during Init() and never changed. Checks remov
+ return false;
+
+ size_t bytes_received = 0;
+ uint32 renderer_buffer_index = 0;
+
base::TimeTicks start = base::TimeTicks::Now();
- const base::TimeDelta kMaxWait = base::TimeDelta::FromMilliseconds(20);
-#if defined(OS_WIN)
- // Sleep(0) on Windows lets the other threads run.
- const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(0);
-#else
- // We want to sleep for a bit here, as otherwise a backgrounded renderer won't
- // get enough cpu to send the data and the high priority thread in the browser
- // will use up a core causing even more skips.
- const base::TimeDelta kSleep = base::TimeDelta::FromMilliseconds(2);
-#endif
- base::TimeDelta time_since_start;
do {
- base::PlatformThread::Sleep(kSleep);
- time_since_start = base::TimeTicks::Now() - start;
- } while (!DataReady() && time_since_start < kMaxWait);
+ bytes_received = socket_->Receive(
tommi (sloooow) - chröme 2013/08/20 10:55:57 Since we're using sockets, we should be able to ch
DaleCurtis 2013/08/20 18:27:51 Not sure I follow which "multiple" items you want
tommi (sloooow) - chröme 2013/08/21 12:33:26 Sorry, for some reason I parsed this loop as cycli
+ &renderer_buffer_index, sizeof(renderer_buffer_index),
+ maximum_wait_time_);
DaveMoore 2013/08/19 22:49:43 Does it mean anything (skipping) if something othe
DaleCurtis 2013/08/19 23:08:22 It means we timed out on one or more previous call
+ } while (bytes_received > 0 && renderer_buffer_index != buffer_index_);
+
+ base::TimeDelta time_since_start = base::TimeTicks::Now() - start;
UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioOutputControllerDataNotReady",
time_since_start,
base::TimeDelta::FromMilliseconds(1),
base::TimeDelta::FromMilliseconds(1000),
50);
+
+ // Receive() timed out or another unknown error occurred.
henrika (OOO until Aug 14) 2013/08/20 07:50:30 Could you add some more details about what can cau
DaleCurtis 2013/09/11 01:16:03 Done.
+ if (!bytes_received) {
+ DVLOG(2) << "AudioSyncReader::WaitTillDataReady() timed out.";
+ return false;
+ }
+
+ DCHECK_EQ(bytes_received, sizeof(renderer_buffer_index));
+ DCHECK(DataReady());
+ return true;
}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698