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

Unified Diff: content/renderer/media/audio_device.cc

Issue 8909006: Fix start/stop of html5 audio stream and race condition when pausing. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/audio_device.cc
===================================================================
--- content/renderer/media/audio_device.cc (revision 113847)
+++ content/renderer/media/audio_device.cc (working copy)
@@ -287,10 +287,7 @@
audio_thread_->SetThreadPriority(base::kThreadPriority_RealtimeAudio);
base::SharedMemory shared_memory(shared_memory_handle_, false);
- shared_memory.Map(memory_length_);
- // Allow the client to pre-populate the buffer.
- FireRenderCallback(reinterpret_cast<int16*>(shared_memory.memory()));
-
+ shared_memory.Map(media::TotalSharedMemorySizeInBytes(memory_length_));
base::SyncSocket socket(socket_handle_);
no longer working on chromium 2011/12/16 12:21:13 I am actually thinking about the opposite solution
enal1 2011/12/16 16:48:23 I believe I answered once. Pre-buffering does not
int pending_data;
@@ -301,6 +298,7 @@
socket.Receive(&pending_data, sizeof(pending_data))) {
if (pending_data == media::AudioOutputController::kPauseMark) {
memset(shared_memory.memory(), 0, memory_length_);
+ media::SetActualDataSizeInBytes(&shared_memory, memory_length_, 0);
continue;
} else if (pending_data < 0) {
break;
@@ -308,16 +306,24 @@
// Convert the number of pending bytes in the render buffer
// into milliseconds.
audio_delay_milliseconds_ = pending_data / bytes_per_ms;
- FireRenderCallback(reinterpret_cast<int16*>(shared_memory.memory()));
+ size_t num_frames = FireRenderCallback(
+ reinterpret_cast<int16*>(shared_memory.memory()));
+ // Let the host know we are done.
henrika (OOO until Aug 14) 2011/12/16 10:52:17 Shouldn't comments have an empty line above when t
enal1 2011/12/16 16:48:23 Done.
+ media::SetActualDataSizeInBytes(&shared_memory,
+ memory_length_,
+ num_frames * channels_ * sizeof(int16));
}
}
-void AudioDevice::FireRenderCallback(int16* data) {
+size_t AudioDevice::FireRenderCallback(int16* data) {
TRACE_EVENT0("audio", "AudioDevice::FireRenderCallback");
+ size_t num_frames = 0;
if (callback_) {
// Update the audio-delay measurement then ask client to render audio.
- callback_->Render(audio_data_, buffer_size_, audio_delay_milliseconds_);
+ num_frames = callback_->Render(audio_data_,
+ buffer_size_,
+ audio_delay_milliseconds_);
// Interleave, scale, and clip to int16.
// TODO(crogers): avoid converting to integer here, and pass the data
@@ -327,6 +333,7 @@
data,
buffer_size_);
}
+ return num_frames;
}
void AudioDevice::ShutDownAudioThread() {

Powered by Google App Engine
This is Rietveld 408576698