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 "media/audio/shared_memory_util.h" | 8 #include "media/audio/shared_memory_util.h" |
9 #include "ppapi/shared_impl/ppapi_globals.h" | 9 #include "ppapi/shared_impl/ppapi_globals.h" |
| 10 #include "ppapi/shared_impl/proxy_lock.h" |
10 | 11 |
11 // Hard coded values from PepperPlatformAudioOutputImpl. | 12 // Hard coded values from PepperPlatformAudioOutputImpl. |
12 // TODO(dalecurtis): PPAPI shouldn't hard code these values for all clients. | 13 // TODO(dalecurtis): PPAPI shouldn't hard code these values for all clients. |
13 enum { kChannels = 2, kBytesPerSample = 2 }; | 14 enum { kChannels = 2, kBytesPerSample = 2 }; |
14 | 15 |
15 namespace ppapi { | 16 namespace ppapi { |
16 | 17 |
17 #if defined(OS_NACL) | 18 #if defined(OS_NACL) |
18 namespace { | 19 namespace { |
19 // Because this is static, the function pointers will be NULL initially. | 20 // Because this is static, the function pointers will be NULL initially. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 122 |
122 int result = thread_functions.thread_create(&thread_id_, CallRun, this); | 123 int result = thread_functions.thread_create(&thread_id_, CallRun, this); |
123 DCHECK_EQ(result, 0); | 124 DCHECK_EQ(result, 0); |
124 thread_active_ = true; | 125 thread_active_ = true; |
125 #endif | 126 #endif |
126 } | 127 } |
127 | 128 |
128 void PPB_Audio_Shared::StopThread() { | 129 void PPB_Audio_Shared::StopThread() { |
129 #if !defined(OS_NACL) | 130 #if !defined(OS_NACL) |
130 if (audio_thread_.get()) { | 131 if (audio_thread_.get()) { |
131 audio_thread_->Join(); | 132 // In general, the audio thread should not do Pepper calls, but it might |
| 133 // anyway (for example, our Audio test does CallOnMainThread). If it did |
| 134 // a pepper call which acquires the lock (most of them do), and we try to |
| 135 // shut down the thread and Join it while holding the lock, we would |
| 136 // deadlock. So we give up the lock here so that the thread at least _can_ |
| 137 // make Pepper calls without causing deadlock. |
| 138 CallWhileUnlocked(base::Bind(&base::DelegateSimpleThread::Join, |
| 139 base::Unretained(audio_thread_.get()))); |
132 audio_thread_.reset(); | 140 audio_thread_.reset(); |
133 } | 141 } |
134 #else | 142 #else |
135 if (thread_active_) { | 143 if (thread_active_) { |
136 int result = thread_functions.thread_join(thread_id_); | 144 // See comment above about why we unlock here. |
| 145 int result = CallWhileUnlocked(thread_functions.thread_join, thread_id_); |
137 DCHECK_EQ(0, result); | 146 DCHECK_EQ(0, result); |
138 thread_active_ = false; | 147 thread_active_ = false; |
139 } | 148 } |
140 #endif | 149 #endif |
141 } | 150 } |
142 | 151 |
143 #if defined(OS_NACL) | 152 #if defined(OS_NACL) |
144 // static | 153 // static |
145 void PPB_Audio_Shared::SetThreadFunctions( | 154 void PPB_Audio_Shared::SetThreadFunctions( |
146 const struct PP_ThreadFunctions* functions) { | 155 const struct PP_ThreadFunctions* functions) { |
(...skipping 28 matching lines...) Expand all Loading... |
175 // padding for alignment, there may be more data available than this. We're | 184 // padding for alignment, there may be more data available than this. We're |
176 // relying on AudioSyncReader::Read() to parse this with that in mind. | 185 // relying on AudioSyncReader::Read() to parse this with that in mind. |
177 // Rename these methods to Set/GetActualFrameCount(). | 186 // Rename these methods to Set/GetActualFrameCount(). |
178 media::SetActualDataSizeInBytes( | 187 media::SetActualDataSizeInBytes( |
179 shared_memory_.get(), shared_memory_size_, | 188 shared_memory_.get(), shared_memory_size_, |
180 audio_bus_->frames() * bytes_per_frame); | 189 audio_bus_->frames() * bytes_per_frame); |
181 } | 190 } |
182 } | 191 } |
183 | 192 |
184 } // namespace ppapi | 193 } // namespace ppapi |
OLD | NEW |