| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/shared_impl/ppb_audio_shared.h" | 5 #include "ppapi/shared_impl/ppb_audio_shared.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/shared_impl/ppapi_globals.h" | 8 #include "ppapi/shared_impl/ppapi_globals.h" |
| 9 #include "ppapi/shared_impl/ppb_audio_config_shared.h" | 9 #include "ppapi/shared_impl/ppb_audio_config_shared.h" |
| 10 #include "ppapi/shared_impl/proxy_lock.h" | 10 #include "ppapi/shared_impl/proxy_lock.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 memset(shared_memory_->memory(), 0, shared_memory_size_); | 139 memset(shared_memory_->memory(), 0, shared_memory_size_); |
| 140 memset(client_buffer_.get(), 0, client_buffer_size_bytes_); | 140 memset(client_buffer_.get(), 0, client_buffer_size_bytes_); |
| 141 #if !defined(OS_NACL) | 141 #if !defined(OS_NACL) |
| 142 DCHECK(!audio_thread_.get()); | 142 DCHECK(!audio_thread_.get()); |
| 143 audio_thread_.reset( | 143 audio_thread_.reset( |
| 144 new base::DelegateSimpleThread(this, "plugin_audio_thread")); | 144 new base::DelegateSimpleThread(this, "plugin_audio_thread")); |
| 145 audio_thread_->Start(); | 145 audio_thread_->Start(); |
| 146 #else | 146 #else |
| 147 // Use NaCl's special API for IRT code that creates threads that call back | 147 // Use NaCl's special API for IRT code that creates threads that call back |
| 148 // into user code. | 148 // into user code. |
| 149 if (NULL == thread_functions.thread_create || | 149 if (!IsThreadFunctionReady()) |
| 150 NULL == thread_functions.thread_join) | |
| 151 return; | 150 return; |
| 152 | 151 |
| 152 DCHECK(!thread_active_); |
| 153 int result = thread_functions.thread_create(&thread_id_, CallRun, this); | 153 int result = thread_functions.thread_create(&thread_id_, CallRun, this); |
| 154 DCHECK_EQ(result, 0); | 154 DCHECK_EQ(result, 0); |
| 155 thread_active_ = true; | 155 thread_active_ = true; |
| 156 #endif | 156 #endif |
| 157 } | 157 } |
| 158 | 158 |
| 159 void PPB_Audio_Shared::StopThread() { | 159 void PPB_Audio_Shared::StopThread() { |
| 160 #if !defined(OS_NACL) | 160 #if !defined(OS_NACL) |
| 161 if (audio_thread_.get()) { | 161 if (audio_thread_.get()) { |
| 162 // In general, the audio thread should not do Pepper calls, but it might | 162 // In general, the audio thread should not do Pepper calls, but it might |
| 163 // anyway (for example, our Audio test does CallOnMainThread). If it did | 163 // anyway (for example, our Audio test does CallOnMainThread). If it did |
| 164 // a pepper call which acquires the lock (most of them do), and we try to | 164 // a pepper call which acquires the lock (most of them do), and we try to |
| 165 // shut down the thread and Join it while holding the lock, we would | 165 // shut down the thread and Join it while holding the lock, we would |
| 166 // deadlock. So we give up the lock here so that the thread at least _can_ | 166 // deadlock. So we give up the lock here so that the thread at least _can_ |
| 167 // make Pepper calls without causing deadlock. | 167 // make Pepper calls without causing deadlock. |
| 168 CallWhileUnlocked(base::Bind(&base::DelegateSimpleThread::Join, | 168 CallWhileUnlocked(base::Bind(&base::DelegateSimpleThread::Join, |
| 169 base::Unretained(audio_thread_.get()))); | 169 base::Unretained(audio_thread_.get()))); |
| 170 audio_thread_.reset(); | 170 audio_thread_.reset(); |
| 171 } | 171 } |
| 172 #else | 172 #else |
| 173 if (thread_active_) { | 173 if (thread_active_) { |
| 174 // See comment above about why we unlock here. | 174 // See comment above about why we unlock here. |
| 175 int result = CallWhileUnlocked(thread_functions.thread_join, thread_id_); | 175 int result = CallWhileUnlocked(thread_functions.thread_join, thread_id_); |
| 176 DCHECK_EQ(0, result); | 176 DCHECK_EQ(0, result); |
| 177 thread_active_ = false; | 177 thread_active_ = false; |
| 178 } | 178 } |
| 179 #endif | 179 #endif |
| 180 } | 180 } |
| 181 | 181 |
| 182 // static |
| 183 bool PPB_Audio_Shared::IsThreadFunctionReady() { |
| 184 #if defined(OS_NACL) |
| 185 if (thread_functions.thread_create == NULL || |
| 186 thread_functions.thread_join == NULL) |
| 187 return false; |
| 188 #endif |
| 189 return true; |
| 190 } |
| 191 |
| 182 #if defined(OS_NACL) | 192 #if defined(OS_NACL) |
| 183 // static | 193 // static |
| 184 void PPB_Audio_Shared::SetThreadFunctions( | 194 void PPB_Audio_Shared::SetThreadFunctions( |
| 185 const struct PP_ThreadFunctions* functions) { | 195 const struct PP_ThreadFunctions* functions) { |
| 186 DCHECK(thread_functions.thread_create == NULL); | |
| 187 DCHECK(thread_functions.thread_join == NULL); | |
| 188 thread_functions = *functions; | 196 thread_functions = *functions; |
| 189 } | 197 } |
| 190 | 198 |
| 191 // static | 199 // static |
| 192 void PPB_Audio_Shared::CallRun(void* self) { | 200 void PPB_Audio_Shared::CallRun(void* self) { |
| 193 PPB_Audio_Shared* audio = static_cast<PPB_Audio_Shared*>(self); | 201 PPB_Audio_Shared* audio = static_cast<PPB_Audio_Shared*>(self); |
| 194 audio->Run(); | 202 audio->Run(); |
| 195 } | 203 } |
| 196 #endif | 204 #endif |
| 197 | 205 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 218 // Let the other end know which buffer we just filled. The buffer index is | 226 // Let the other end know which buffer we just filled. The buffer index is |
| 219 // used to ensure the other end is getting the buffer it expects. For more | 227 // used to ensure the other end is getting the buffer it expects. For more |
| 220 // details on how this works see AudioSyncReader::WaitUntilDataIsReady(). | 228 // details on how this works see AudioSyncReader::WaitUntilDataIsReady(). |
| 221 size_t bytes_sent = socket_->Send(&buffer_index_, sizeof(buffer_index_)); | 229 size_t bytes_sent = socket_->Send(&buffer_index_, sizeof(buffer_index_)); |
| 222 if (bytes_sent != sizeof(buffer_index_)) | 230 if (bytes_sent != sizeof(buffer_index_)) |
| 223 break; | 231 break; |
| 224 } | 232 } |
| 225 } | 233 } |
| 226 | 234 |
| 227 } // namespace ppapi | 235 } // namespace ppapi |
| OLD | NEW |