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

Unified Diff: ppapi/shared_impl/ppb_audio_shared.cc

Issue 10809079: Modify the PPB_Audio_Shared code for NaCl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « ppapi/shared_impl/ppb_audio_shared.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/ppb_audio_shared.cc
===================================================================
--- ppapi/shared_impl/ppb_audio_shared.cc (revision 148266)
+++ ppapi/shared_impl/ppb_audio_shared.cc (working copy)
@@ -11,6 +11,13 @@
namespace ppapi {
+#if defined(OS_NACL)
+namespace {
+// Because this is static, the function pointers will be NULL initially.
+PP_ThreadFunctions thread_functions;
+}
+#endif // defined(OS_NACL)
+
// 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.
@@ -37,6 +44,10 @@
PPB_Audio_Shared::PPB_Audio_Shared()
: playing_(false),
shared_memory_size_(0),
+#if defined(OS_NACL)
+ thread_id_(0),
+ thread_active_(false),
+#endif
callback_(NULL),
user_data_(NULL) {
}
@@ -53,8 +64,11 @@
void PPB_Audio_Shared::SetStartPlaybackState() {
DCHECK(!playing_);
+#if !defined(OS_NACL)
DCHECK(!audio_thread_.get());
-
+#else
+ DCHECK(!thread_active_);
+#endif
// If the socket doesn't exist, that means that the plugin has started before
// the browser has had a chance to create all the shared memory info and
// notify us. This is a common case. In this case, we just set the playing_
@@ -91,22 +105,62 @@
// Don't start the thread unless all our state is set up correctly.
if (!playing_ || !callback_ || !socket_.get() || !shared_memory_->memory())
return;
+ // Clear contents of shm buffer before starting audio thread. This will
+ // prevent a burst of static if for some reason the audio thread doesn't
+ // start up quickly enough.
+ memset(shared_memory_->memory(), 0, shared_memory_size_);
+#if !defined(OS_NACL)
DCHECK(!audio_thread_.get());
audio_thread_.reset(new base::DelegateSimpleThread(
this, "plugin_audio_thread"));
audio_thread_->Start();
+#else
+ // Use NaCl's special API for IRT code that creates threads that call back
+ // into user code.
+ if (NULL == thread_functions.thread_create ||
+ NULL == thread_functions.thread_join)
+ return;
+
+ int result = thread_functions.thread_create(&thread_id_, CallRun, this);
+ DCHECK_EQ(result, 0);
+ thread_active_ = true;
+#endif
}
void PPB_Audio_Shared::StopThread() {
// Shut down the socket to escape any hanging |Receive|s.
if (socket_.get())
socket_->Shutdown();
+ #if !defined(OS_NACL)
if (audio_thread_.get()) {
audio_thread_->Join();
audio_thread_.reset();
}
+#else
+ if (thread_active_) {
+ int result = thread_functions.thread_join(thread_id_);
+ DCHECK_EQ(0, result);
+ thread_active_ = false;
+ }
+#endif
}
+#if defined(OS_NACL)
+// static
+void PPB_Audio_Shared::SetThreadFunctions(
+ const struct PP_ThreadFunctions* functions) {
+ DCHECK(thread_functions.thread_create == NULL);
+ DCHECK(thread_functions.thread_join == NULL);
+ thread_functions = *functions;
+}
+
+// static
+void PPB_Audio_Shared::CallRun(void* self) {
+ PPB_Audio_Shared* audio = static_cast<PPB_Audio_Shared*>(self);
+ audio->Run();
+}
+#endif
+
void PPB_Audio_Shared::Run() {
int pending_data;
void* buffer = shared_memory_->memory();
« no previous file with comments | « ppapi/shared_impl/ppb_audio_shared.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698