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

Unified Diff: ppapi/shared_impl/ppb_audio_shared.cc

Issue 200283002: Fix the crash for the AudioShared. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@open_resource3
Patch Set: Created 6 years, 9 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
diff --git a/ppapi/shared_impl/ppb_audio_shared.cc b/ppapi/shared_impl/ppb_audio_shared.cc
index ced11466970c6e2ba26eb9d87fb3f1c94d49993b..b448011974cf9bbc9930ee48aa2f4b98b07f9223 100644
--- a/ppapi/shared_impl/ppb_audio_shared.cc
+++ b/ppapi/shared_impl/ppb_audio_shared.cc
@@ -5,18 +5,18 @@
#include "ppapi/shared_impl/ppb_audio_shared.h"
#include "base/logging.h"
+#include "ppapi/nacl_irt/irt_ppapi.h"
#include "ppapi/shared_impl/ppapi_globals.h"
#include "ppapi/shared_impl/ppb_audio_config_shared.h"
#include "ppapi/shared_impl/proxy_lock.h"
namespace ppapi {
-#if defined(OS_NACL)
namespace {
+bool thread_functions_set = false;
// Because this is static, the function pointers will be NULL initially.
PP_ThreadFunctions thread_functions;
}
-#endif // defined(OS_NACL)
AudioCallbackCombined::AudioCallbackCombined()
: callback_1_0_(NULL), callback_(NULL) {}
@@ -50,10 +50,8 @@ void AudioCallbackCombined::Run(void* sample_buffer,
PPB_Audio_Shared::PPB_Audio_Shared()
: playing_(false),
shared_memory_size_(0),
-#if defined(OS_NACL)
thread_id_(0),
thread_active_(false),
-#endif
user_data_(NULL),
client_buffer_size_bytes_(0),
bytes_per_second_(0),
@@ -77,9 +75,8 @@ void PPB_Audio_Shared::SetStartPlaybackState() {
DCHECK(!playing_);
#if !defined(OS_NACL)
DCHECK(!audio_thread_.get());
-#else
- DCHECK(!thread_active_);
#endif
+ DCHECK(!thread_active_);
// 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_
@@ -138,21 +135,25 @@ void PPB_Audio_Shared::StartThread() {
// start up quickly enough.
memset(shared_memory_->memory(), 0, shared_memory_size_);
memset(client_buffer_.get(), 0, client_buffer_size_bytes_);
+
+ if (thread_functions_set) {
Mark Seaborn 2014/03/20 23:23:30 PPB_Audio is meant to fail under NaCl (for both SF
hidehiko 2014/04/21 14:47:40 Done.
+ // 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;
+ return;
+ }
+
#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
}
@@ -169,22 +170,22 @@ void PPB_Audio_Shared::StopThread() {
base::Unretained(audio_thread_.get())));
audio_thread_.reset();
}
-#else
+#endif
if (thread_active_) {
// See comment above about why we unlock here.
int result = CallWhileUnlocked(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_set);
DCHECK(thread_functions.thread_create == NULL);
DCHECK(thread_functions.thread_join == NULL);
+ thread_functions_set = true;
thread_functions = *functions;
}
@@ -193,7 +194,6 @@ 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 = 0;
« 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