summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 18:27:16 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-14 18:27:16 +0000
commit9e517e179fe14e79ebf1ce0a4617af1483d4a088 (patch)
treedbcd0ae180b8374f3d0ba39e32d5a7386cf8d2c5
parent74a5fec1709b6c1621ced52ddecf54004d8d09c0 (diff)
downloadchromium_src-9e517e179fe14e79ebf1ce0a4617af1483d4a088.zip
chromium_src-9e517e179fe14e79ebf1ce0a4617af1483d4a088.tar.gz
chromium_src-9e517e179fe14e79ebf1ce0a4617af1483d4a088.tar.bz2
Looping for audio / video
Fixed the looping problem with audio / video. BUG=39478 TEST=audio plays with looping Review URL: http://codereview.chromium.org/1620010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44502 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/audio_renderer_host.cc6
-rw-r--r--chrome/renderer/media/audio_renderer_impl.cc15
-rw-r--r--media/audio/mac/audio_output_mac.cc28
3 files changed, 36 insertions, 13 deletions
diff --git a/chrome/browser/renderer_host/audio_renderer_host.cc b/chrome/browser/renderer_host/audio_renderer_host.cc
index 10e9c77..9019c50 100644
--- a/chrome/browser/renderer_host/audio_renderer_host.cc
+++ b/chrome/browser/renderer_host/audio_renderer_host.cc
@@ -368,9 +368,13 @@ void AudioRendererHost::IPCAudioSource::NotifyPacketReady(
}
outstanding_request_ = false;
+
+ // Don't write to push source and submit a new request if the last one
+ // replied with no data. This is likely due to data is depleted in the
+ // renderer process.
// If reported size is greater than capacity of the shared memory, we have
// an error.
- if (decoded_packet_size <= decoded_packet_size_) {
+ if (decoded_packet_size && decoded_packet_size <= decoded_packet_size_) {
bool ok = push_source_.Write(
static_cast<char*>(shared_memory_.memory()), decoded_packet_size);
diff --git a/chrome/renderer/media/audio_renderer_impl.cc b/chrome/renderer/media/audio_renderer_impl.cc
index 4325798..396ceeb 100644
--- a/chrome/renderer/media/audio_renderer_impl.cc
+++ b/chrome/renderer/media/audio_renderer_impl.cc
@@ -330,15 +330,12 @@ void AudioRendererImpl::NotifyPacketReadyTask() {
uint32 filled = FillBuffer(static_cast<uint8*>(shared_memory_->memory()),
shared_memory_size_,
request_delay);
- // TODO(hclam): we should try to fill in the buffer as much as possible.
- if (filled > 0) {
- pending_request_ = false;
- request_delay_ = base::TimeDelta();
- request_timestamp_ = base::Time();
- // Then tell browser process we are done filling into the buffer.
- filter_->Send(
- new ViewHostMsg_NotifyAudioPacketReady(0, stream_id_, filled));
- }
+ pending_request_ = false;
+ request_delay_ = base::TimeDelta();
+ request_timestamp_ = base::Time();
+ // Then tell browser process we are done filling into the buffer.
+ filter_->Send(
+ new ViewHostMsg_NotifyAudioPacketReady(0, stream_id_, filled));
}
}
diff --git a/media/audio/mac/audio_output_mac.cc b/media/audio/mac/audio_output_mac.cc
index f3cce4f..57c76cb 100644
--- a/media/audio/mac/audio_output_mac.cc
+++ b/media/audio/mac/audio_output_mac.cc
@@ -9,6 +9,16 @@
#include "media/audio/audio_util.h"
#include "media/audio/mac/audio_manager_mac.h"
+namespace {
+
+// A custom data structure to store information an AudioQueue buffer.
+struct AudioQueueUserData {
+ AudioQueueUserData() : empty_buffer(false) {}
+ bool empty_buffer;
+};
+
+} // namespace
+
// Overview of operation:
// 1) An object of PCMQueueOutAudioOutputStream is created by the AudioManager
// factory: audio_man->MakeAudioStream(). This just fills some structure.
@@ -98,6 +108,8 @@ bool PCMQueueOutAudioOutputStream::Open(uint32 packet_size) {
HandleError(err);
return false;
}
+ // Allocate memory for user data.
+ buffer_[ix]->mUserData = new AudioQueueUserData();
}
// Set initial volume here.
err = AudioQueueSetParameter(audio_queue_, kAudioQueueParam_Volume, 1.0);
@@ -115,6 +127,9 @@ void PCMQueueOutAudioOutputStream::Close() {
OSStatus err = 0;
for (uint32 ix = 0; ix != kNumBuffers; ++ix) {
if (buffer_[ix]) {
+ // Free user data.
+ delete static_cast<AudioQueueUserData*>(buffer_[ix]->mUserData);
+ // Free AudioQueue buffer.
err = AudioQueueFreeBuffer(audio_queue_, buffer_[ix]);
if (err != noErr) {
HandleError(err);
@@ -199,7 +214,8 @@ void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this,
return;
// Adjust the number of pending bytes by subtracting the amount played.
- audio_stream->pending_bytes_ -= buffer->mAudioDataByteSize;
+ if (!static_cast<AudioQueueUserData*>(buffer->mUserData)->empty_buffer)
+ audio_stream->pending_bytes_ -= buffer->mAudioDataByteSize;
uint32 capacity = buffer->mAudioDataBytesCapacity;
uint32 filled = source->OnMoreData(audio_stream, buffer->mAudioData,
capacity, audio_stream->pending_bytes_);
@@ -211,10 +227,13 @@ void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this,
CHECK(audio_stream->silence_bytes_ <= static_cast<int>(capacity));
filled = audio_stream->silence_bytes_;
memset(buffer->mAudioData, 0, filled);
+ static_cast<AudioQueueUserData*>(buffer->mUserData)->empty_buffer = true;
} else if (filled > capacity) {
// User probably overran our buffer.
audio_stream->HandleError(0);
return;
+ } else {
+ static_cast<AudioQueueUserData*>(buffer->mUserData)->empty_buffer = false;
}
// Handle channel order for 5.1 audio.
@@ -229,8 +248,11 @@ void PCMQueueOutAudioOutputStream::RenderCallback(void* p_this,
}
buffer->mAudioDataByteSize = filled;
- // Incremnet bytes by amount filled into audio buffer.
- audio_stream->pending_bytes_ += filled;
+
+ // Incremnet bytes by amount filled into audio buffer if this is not a
+ // silence buffer.
+ if (!static_cast<AudioQueueUserData*>(buffer->mUserData)->empty_buffer)
+ audio_stream->pending_bytes_ += filled;
if (NULL == queue)
return;
// Queue the audio data to the audio driver.