Skip to content

Commit

Permalink
Notify audio host that audio rendering in Pepper plugin is done.
Browse files Browse the repository at this point in the history
BUG=120837
TEST=See bug


Review URL: http://codereview.chromium.org/9921006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132746 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
raymond.liu@intel.com committed Apr 18, 2012
1 parent dc8cba6 commit 3e3715e
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ppapi/shared_impl/ppb_audio_shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,31 @@

#include "base/logging.h"

using base::subtle::Atomic32;

namespace ppapi {

// FIXME: The following two functions (TotalSharedMemorySizeInBytes,
// SetActualDataSizeInBytes) are copied from audio_util.cc.
// Remove these functions once a minimal media library is provided for them.
// code.google.com/p/chromium/issues/detail?id=123203

uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) {
// Need to reserve extra 4 bytes for size of data.
return packet_size + sizeof(Atomic32);
}

void SetActualDataSizeInBytes(base::SharedMemory* shared_memory,
uint32 shared_memory_size,
uint32 actual_data_size) {
char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);

// Set actual data size at the end of the buffer.
base::subtle::Release_Store(reinterpret_cast<volatile Atomic32*>(ptr),
actual_data_size);
}

const int PPB_Audio_Shared::kPauseMark = -1;

PPB_Audio_Shared::PPB_Audio_Shared()
Expand Down Expand Up @@ -66,7 +89,8 @@ void PPB_Audio_Shared::SetStreamInfo(
shared_memory_size_ = shared_memory_size;

if (callback_) {
shared_memory_->Map(shared_memory_size_);
shared_memory_->Map(TotalSharedMemorySizeInBytes(
shared_memory_size_));

// In common case StartPlayback() was called before StreamCreated().
if (playing_)
Expand All @@ -90,6 +114,10 @@ void PPB_Audio_Shared::Run() {
socket_->Receive(&pending_data, sizeof(pending_data)) &&
pending_data != kPauseMark) {
callback_(buffer, shared_memory_size_, user_data_);

// Let the host know we are done.
SetActualDataSizeInBytes(shared_memory_.get(), shared_memory_size_,
shared_memory_size_);
}
}

Expand Down

0 comments on commit 3e3715e

Please sign in to comment.