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

Unified Diff: ppapi/shared_impl/ppb_audio_shared.cc

Issue 240523002: Add test to make sure if PPB_Audio_Shared::StartThread() works. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
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..d042cbc43837a6471527dd954ef5a1bee59377dd 100644
--- a/ppapi/shared_impl/ppb_audio_shared.cc
+++ b/ppapi/shared_impl/ppb_audio_shared.cc
@@ -73,7 +73,7 @@ void PPB_Audio_Shared::SetCallback(const AudioCallbackCombined& callback,
user_data_ = user_data;
}
-void PPB_Audio_Shared::SetStartPlaybackState() {
+bool PPB_Audio_Shared::SetStartPlaybackState() {
DCHECK(!playing_);
#if !defined(OS_NACL)
DCHECK(!audio_thread_.get());
@@ -85,8 +85,15 @@ void PPB_Audio_Shared::SetStartPlaybackState() {
// notify us. This is a common case. In this case, we just set the playing_
// flag and the playback will automatically start when that data is available
// in SetStreamInfo.
+ // If StartThread() returns false, it means no thread creator is set yet.
+ // In such a case, we do not set playing state, because even if SetStreamInfo
+ // is invoked later, we cannot create a thread.
+ // Note that StartThread returns true even if socket doesn't exist as it is
bbudge 2014/04/18 13:34:40 I think this last sentence just repeats the commen
hidehiko 2014/04/18 18:16:30 Acknowledged.
+ // common situation as descibed above.
playing_ = true;
- StartThread();
+ if (!StartThread())
+ playing_ = false;
+ return playing_;
}
void PPB_Audio_Shared::SetStopPlaybackState() {
@@ -127,12 +134,21 @@ void PPB_Audio_Shared::SetStreamInfo(
StartThread();
}
-void PPB_Audio_Shared::StartThread() {
+bool PPB_Audio_Shared::StartThread() {
+#if defined(OS_NACL)
+ // 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 false;
+#endif
+
// Don't start the thread unless all our state is set up correctly.
if (!playing_ || !callback_.IsValid() || !socket_.get() ||
!shared_memory_->memory() || !audio_bus_.get() || !client_buffer_.get() ||
bytes_per_second_ == 0)
- return;
+ return true;
+
// 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.
@@ -144,16 +160,12 @@ void PPB_Audio_Shared::StartThread() {
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;
-
+ DCHECK(!thread_active_);
int result = thread_functions.thread_create(&thread_id_, CallRun, this);
DCHECK_EQ(result, 0);
thread_active_ = true;
#endif
+ return true;
}
void PPB_Audio_Shared::StopThread() {
@@ -183,8 +195,6 @@ void PPB_Audio_Shared::StopThread() {
// 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;
}

Powered by Google App Engine
This is Rietveld 408576698