OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_audio.h" | 5 #include "webkit/plugins/ppapi/ppb_audio_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/dev/ppb_audio_dev.h" | 8 #include "ppapi/c/dev/ppb_audio_dev.h" |
9 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" | 9 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" |
10 #include "ppapi/c/pp_completion_callback.h" | 10 #include "ppapi/c/pp_completion_callback.h" |
11 #include "webkit/glue/plugins/pepper_common.h" | 11 #include "webkit/plugins/ppapi/common.h" |
12 | 12 |
13 namespace pepper { | 13 namespace webkit { |
| 14 namespace plugins { |
| 15 namespace ppapi { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // PPB_AudioConfig ------------------------------------------------------------- | 19 // PPB_AudioConfig ------------------------------------------------------------- |
18 | 20 |
19 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); | 21 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); |
20 | 22 |
21 PP_Resource CreateStereo16bit(PP_Module module_id, | 23 PP_Resource CreateStereo16bit(PP_Module module_id, |
22 PP_AudioSampleRate_Dev sample_rate, | 24 PP_AudioSampleRate_Dev sample_rate, |
23 uint32_t sample_frame_count) { | 25 uint32_t sample_frame_count) { |
24 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); | 26 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); |
25 if (!module) | 27 if (!module) |
26 return 0; | 28 return 0; |
27 | 29 |
28 // TODO(brettw): Currently we don't actually check what the hardware | 30 // TODO(brettw): Currently we don't actually check what the hardware |
29 // supports, so just allow sample rates of the "guaranteed working" ones. | 31 // supports, so just allow sample rates of the "guaranteed working" ones. |
30 if (sample_rate != PP_AUDIOSAMPLERATE_44100 && | 32 if (sample_rate != PP_AUDIOSAMPLERATE_44100 && |
31 sample_rate != PP_AUDIOSAMPLERATE_48000) | 33 sample_rate != PP_AUDIOSAMPLERATE_48000) |
32 return 0; | 34 return 0; |
33 | 35 |
34 // TODO(brettw): Currently we don't actually query to get a value from the | 36 // TODO(brettw): Currently we don't actually query to get a value from the |
35 // hardware, so just validate the range. | 37 // hardware, so just validate the range. |
36 if (RecommendSampleFrameCount(sample_frame_count) != sample_frame_count) | 38 if (RecommendSampleFrameCount(sample_frame_count) != sample_frame_count) |
37 return 0; | 39 return 0; |
38 | 40 |
39 scoped_refptr<AudioConfig> config(new AudioConfig(module, | 41 scoped_refptr<PPB_AudioConfig_Impl> config( |
40 sample_rate, | 42 new PPB_AudioConfig_Impl(module, sample_rate, sample_frame_count)); |
41 sample_frame_count)); | |
42 return config->GetReference(); | 43 return config->GetReference(); |
43 } | 44 } |
44 | 45 |
45 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) { | 46 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) { |
46 // TODO(brettw) Currently we don't actually query to get a value from the | 47 // TODO(brettw) Currently we don't actually query to get a value from the |
47 // hardware, so we always return the input for in-range values. | 48 // hardware, so we always return the input for in-range values. |
48 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) | 49 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) |
49 return PP_AUDIOMINSAMPLEFRAMECOUNT; | 50 return PP_AUDIOMINSAMPLEFRAMECOUNT; |
50 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) | 51 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) |
51 return PP_AUDIOMAXSAMPLEFRAMECOUNT; | 52 return PP_AUDIOMAXSAMPLEFRAMECOUNT; |
52 return requested_sample_frame_count; | 53 return requested_sample_frame_count; |
53 } | 54 } |
54 | 55 |
55 PP_Bool IsAudioConfig(PP_Resource resource) { | 56 PP_Bool IsAudioConfig(PP_Resource resource) { |
56 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(resource); | 57 scoped_refptr<PPB_AudioConfig_Impl> config = |
| 58 Resource::GetAs<PPB_AudioConfig_Impl>(resource); |
57 return BoolToPPBool(!!config); | 59 return BoolToPPBool(!!config); |
58 } | 60 } |
59 | 61 |
60 PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { | 62 PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { |
61 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id); | 63 scoped_refptr<PPB_AudioConfig_Impl> config = |
| 64 Resource::GetAs<PPB_AudioConfig_Impl>(config_id); |
62 return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE; | 65 return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE; |
63 } | 66 } |
64 | 67 |
65 uint32_t GetSampleFrameCount(PP_Resource config_id) { | 68 uint32_t GetSampleFrameCount(PP_Resource config_id) { |
66 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id); | 69 scoped_refptr<PPB_AudioConfig_Impl> config = |
| 70 Resource::GetAs<PPB_AudioConfig_Impl>(config_id); |
67 return config ? config->sample_frame_count() : 0; | 71 return config ? config->sample_frame_count() : 0; |
68 } | 72 } |
69 | 73 |
70 const PPB_AudioConfig_Dev ppb_audioconfig = { | 74 const PPB_AudioConfig_Dev ppb_audioconfig = { |
71 &CreateStereo16bit, | 75 &CreateStereo16bit, |
72 &RecommendSampleFrameCount, | 76 &RecommendSampleFrameCount, |
73 &IsAudioConfig, | 77 &IsAudioConfig, |
74 &GetSampleRate, | 78 &GetSampleRate, |
75 &GetSampleFrameCount | 79 &GetSampleFrameCount |
76 }; | 80 }; |
77 | 81 |
78 // PPB_Audio ------------------------------------------------------------------- | 82 // PPB_Audio ------------------------------------------------------------------- |
79 | 83 |
80 PP_Resource Create(PP_Instance instance_id, PP_Resource config_id, | 84 PP_Resource Create(PP_Instance instance_id, PP_Resource config_id, |
81 PPB_Audio_Callback user_callback, void* user_data) { | 85 PPB_Audio_Callback user_callback, void* user_data) { |
82 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 86 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
83 if (!instance) | 87 if (!instance) |
84 return 0; | 88 return 0; |
85 if (!user_callback) | 89 if (!user_callback) |
86 return 0; | 90 return 0; |
87 scoped_refptr<Audio> audio(new Audio(instance->module(), instance_id)); | 91 scoped_refptr<PPB_Audio_Impl> audio( |
| 92 new PPB_Audio_Impl(instance->module(), instance_id)); |
88 if (!audio->Init(instance->delegate(), config_id, | 93 if (!audio->Init(instance->delegate(), config_id, |
89 user_callback, user_data)) | 94 user_callback, user_data)) |
90 return 0; | 95 return 0; |
91 return audio->GetReference(); | 96 return audio->GetReference(); |
92 } | 97 } |
93 | 98 |
94 PP_Bool IsAudio(PP_Resource resource) { | 99 PP_Bool IsAudio(PP_Resource resource) { |
95 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(resource); | 100 scoped_refptr<PPB_Audio_Impl> audio = |
| 101 Resource::GetAs<PPB_Audio_Impl>(resource); |
96 return BoolToPPBool(!!audio); | 102 return BoolToPPBool(!!audio); |
97 } | 103 } |
98 | 104 |
99 PP_Resource GetCurrentConfig(PP_Resource audio_id) { | 105 PP_Resource GetCurrentConfig(PP_Resource audio_id) { |
100 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 106 scoped_refptr<PPB_Audio_Impl> audio = Resource::GetAs<PPB_Audio_Impl>(audio_id
); |
101 return audio ? audio->GetCurrentConfig() : 0; | 107 return audio ? audio->GetCurrentConfig() : 0; |
102 } | 108 } |
103 | 109 |
104 PP_Bool StartPlayback(PP_Resource audio_id) { | 110 PP_Bool StartPlayback(PP_Resource audio_id) { |
105 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 111 scoped_refptr<PPB_Audio_Impl> audio = |
| 112 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
106 return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE; | 113 return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE; |
107 } | 114 } |
108 | 115 |
109 PP_Bool StopPlayback(PP_Resource audio_id) { | 116 PP_Bool StopPlayback(PP_Resource audio_id) { |
110 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 117 scoped_refptr<PPB_Audio_Impl> audio = |
| 118 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
111 return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE; | 119 return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE; |
112 } | 120 } |
113 | 121 |
114 const PPB_Audio_Dev ppb_audio = { | 122 const PPB_Audio_Dev ppb_audio = { |
115 &Create, | 123 &Create, |
116 &IsAudio, | 124 &IsAudio, |
117 &GetCurrentConfig, | 125 &GetCurrentConfig, |
118 &StartPlayback, | 126 &StartPlayback, |
119 &StopPlayback, | 127 &StopPlayback, |
120 }; | 128 }; |
121 | 129 |
122 // PPB_AudioTrusted ------------------------------------------------------------ | 130 // PPB_AudioTrusted ------------------------------------------------------------ |
123 | 131 |
124 PP_Resource CreateTrusted(PP_Instance instance_id) { | 132 PP_Resource CreateTrusted(PP_Instance instance_id) { |
125 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 133 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
126 if (!instance) | 134 if (!instance) |
127 return 0; | 135 return 0; |
128 scoped_refptr<Audio> audio(new Audio(instance->module(), instance_id)); | 136 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance->module(), ins
tance_id)); |
129 return audio->GetReference(); | 137 return audio->GetReference(); |
130 } | 138 } |
131 | 139 |
132 int32_t Open(PP_Resource audio_id, | 140 int32_t Open(PP_Resource audio_id, |
133 PP_Resource config_id, | 141 PP_Resource config_id, |
134 PP_CompletionCallback created) { | 142 PP_CompletionCallback created) { |
135 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 143 scoped_refptr<PPB_Audio_Impl> audio = |
| 144 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
136 if (!audio) | 145 if (!audio) |
137 return PP_ERROR_BADRESOURCE; | 146 return PP_ERROR_BADRESOURCE; |
138 if (!created.func) | 147 if (!created.func) |
139 return PP_ERROR_BADARGUMENT; | 148 return PP_ERROR_BADARGUMENT; |
140 PP_Instance instance_id = audio->pp_instance(); | 149 PP_Instance instance_id = audio->pp_instance(); |
141 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 150 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
142 if (!instance) | 151 if (!instance) |
143 return PP_ERROR_FAILED; | 152 return PP_ERROR_FAILED; |
144 return audio->Open(instance->delegate(), config_id, created); | 153 return audio->Open(instance->delegate(), config_id, created); |
145 } | 154 } |
146 | 155 |
147 int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) { | 156 int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) { |
148 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 157 scoped_refptr<PPB_Audio_Impl> audio = |
| 158 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
149 if (audio) | 159 if (audio) |
150 return audio->GetSyncSocket(sync_socket); | 160 return audio->GetSyncSocket(sync_socket); |
151 return PP_ERROR_BADRESOURCE; | 161 return PP_ERROR_BADRESOURCE; |
152 } | 162 } |
153 | 163 |
154 int32_t GetSharedMemory(PP_Resource audio_id, | 164 int32_t GetSharedMemory(PP_Resource audio_id, |
155 int* shm_handle, | 165 int* shm_handle, |
156 uint32_t* shm_size) { | 166 uint32_t* shm_size) { |
157 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 167 scoped_refptr<PPB_Audio_Impl> audio = |
| 168 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
158 if (audio) | 169 if (audio) |
159 return audio->GetSharedMemory(shm_handle, shm_size); | 170 return audio->GetSharedMemory(shm_handle, shm_size); |
160 return PP_ERROR_BADRESOURCE; | 171 return PP_ERROR_BADRESOURCE; |
161 } | 172 } |
162 | 173 |
163 const PPB_AudioTrusted_Dev ppb_audiotrusted = { | 174 const PPB_AudioTrusted_Dev ppb_audiotrusted = { |
164 &CreateTrusted, | 175 &CreateTrusted, |
165 &Open, | 176 &Open, |
166 &GetSyncSocket, | 177 &GetSyncSocket, |
167 &GetSharedMemory, | 178 &GetSharedMemory, |
168 }; | 179 }; |
169 | 180 |
170 } // namespace | 181 } // namespace |
171 | 182 |
172 // AudioConfig ----------------------------------------------------------------- | 183 // PPB_AudioConfig_Impl -------------------------------------------------------- |
173 | 184 |
174 AudioConfig::AudioConfig(PluginModule* module, | 185 PPB_AudioConfig_Impl::PPB_AudioConfig_Impl( |
175 PP_AudioSampleRate_Dev sample_rate, | 186 PluginModule* module, |
176 uint32_t sample_frame_count) | 187 PP_AudioSampleRate_Dev sample_rate, |
| 188 uint32_t sample_frame_count) |
177 : Resource(module), | 189 : Resource(module), |
178 sample_rate_(sample_rate), | 190 sample_rate_(sample_rate), |
179 sample_frame_count_(sample_frame_count) { | 191 sample_frame_count_(sample_frame_count) { |
180 } | 192 } |
181 | 193 |
182 const PPB_AudioConfig_Dev* AudioConfig::GetInterface() { | 194 const PPB_AudioConfig_Dev* PPB_AudioConfig_Impl::GetInterface() { |
183 return &ppb_audioconfig; | 195 return &ppb_audioconfig; |
184 } | 196 } |
185 | 197 |
186 size_t AudioConfig::BufferSize() { | 198 size_t PPB_AudioConfig_Impl::BufferSize() { |
187 // TODO(audio): as more options become available, we'll need to | 199 // TODO(audio): as more options become available, we'll need to |
188 // have additional code here to correctly calculate the size in | 200 // have additional code here to correctly calculate the size in |
189 // bytes of an audio buffer. For now, only support two channel | 201 // bytes of an audio buffer. For now, only support two channel |
190 // int16_t sample buffers. | 202 // int16_t sample buffers. |
191 const int kChannels = 2; | 203 const int kChannels = 2; |
192 const int kSizeOfSample = sizeof(int16_t); | 204 const int kSizeOfSample = sizeof(int16_t); |
193 return static_cast<size_t>(sample_frame_count_ * kSizeOfSample * kChannels); | 205 return static_cast<size_t>(sample_frame_count_ * kSizeOfSample * kChannels); |
194 } | 206 } |
195 | 207 |
196 AudioConfig* AudioConfig::AsAudioConfig() { | 208 PPB_AudioConfig_Impl* PPB_AudioConfig_Impl::AsAudioConfig() { |
197 return this; | 209 return this; |
198 } | 210 } |
199 | 211 |
200 // Audio ----------------------------------------------------------------------- | 212 // PPB_Audio_Impl -------------------------------------------------------------- |
201 | 213 |
202 Audio::Audio(PluginModule* module, PP_Instance instance_id) | 214 PPB_Audio_Impl::PPB_Audio_Impl(PluginModule* module, PP_Instance instance_id) |
203 : Resource(module), | 215 : Resource(module), |
204 pp_instance_(instance_id), | 216 pp_instance_(instance_id), |
205 audio_(NULL), | 217 audio_(NULL), |
206 create_callback_pending_(false) { | 218 create_callback_pending_(false) { |
207 create_callback_ = PP_MakeCompletionCallback(NULL, NULL); | 219 create_callback_ = PP_MakeCompletionCallback(NULL, NULL); |
208 } | 220 } |
209 | 221 |
210 Audio::~Audio() { | 222 PPB_Audio_Impl::~PPB_Audio_Impl() { |
211 // Calling ShutDown() makes sure StreamCreated cannot be called anymore. | 223 // Calling ShutDown() makes sure StreamCreated cannot be called anymore. |
212 audio_->ShutDown(); | 224 audio_->ShutDown(); |
213 audio_ = NULL; | 225 audio_ = NULL; |
214 | 226 |
215 // If the completion callback hasn't fired yet, do so here | 227 // If the completion callback hasn't fired yet, do so here |
216 // with an error condition. | 228 // with an error condition. |
217 if (create_callback_pending_) { | 229 if (create_callback_pending_) { |
218 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED); | 230 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED); |
219 create_callback_pending_ = false; | 231 create_callback_pending_ = false; |
220 } | 232 } |
221 } | 233 } |
222 | 234 |
223 const PPB_Audio_Dev* Audio::GetInterface() { | 235 const PPB_Audio_Dev* PPB_Audio_Impl::GetInterface() { |
224 return &ppb_audio; | 236 return &ppb_audio; |
225 } | 237 } |
226 | 238 |
227 const PPB_AudioTrusted_Dev* Audio::GetTrustedInterface() { | 239 const PPB_AudioTrusted_Dev* PPB_Audio_Impl::GetTrustedInterface() { |
228 return &ppb_audiotrusted; | 240 return &ppb_audiotrusted; |
229 } | 241 } |
230 | 242 |
231 Audio* Audio::AsAudio() { | 243 PPB_Audio_Impl* PPB_Audio_Impl::AsAudio() { |
232 return this; | 244 return this; |
233 } | 245 } |
234 | 246 |
235 bool Audio::Init(PluginDelegate* plugin_delegate, | 247 bool PPB_Audio_Impl::Init(PluginDelegate* plugin_delegate, |
236 PP_Resource config_id, | 248 PP_Resource config_id, |
237 PPB_Audio_Callback callback, void* user_data) { | 249 PPB_Audio_Callback callback, void* user_data) { |
238 CHECK(!audio_); | 250 CHECK(!audio_); |
239 config_ = Resource::GetAs<AudioConfig>(config_id); | 251 config_ = Resource::GetAs<PPB_AudioConfig_Impl>(config_id); |
240 if (!config_) | 252 if (!config_) |
241 return false; | 253 return false; |
242 SetCallback(callback, user_data); | 254 SetCallback(callback, user_data); |
243 | 255 |
244 // When the stream is created, we'll get called back on StreamCreated(). | 256 // When the stream is created, we'll get called back on StreamCreated(). |
245 audio_ = plugin_delegate->CreateAudio(config_->sample_rate(), | 257 audio_ = plugin_delegate->CreateAudio(config_->sample_rate(), |
246 config_->sample_frame_count(), | 258 config_->sample_frame_count(), |
247 this); | 259 this); |
248 return audio_ != NULL; | 260 return audio_ != NULL; |
249 } | 261 } |
250 | 262 |
251 PP_Resource Audio::GetCurrentConfig() { | 263 PP_Resource PPB_Audio_Impl::GetCurrentConfig() { |
252 return config_->GetReference(); | 264 return config_->GetReference(); |
253 } | 265 } |
254 | 266 |
255 bool Audio::StartPlayback() { | 267 bool PPB_Audio_Impl::StartPlayback() { |
256 if (playing()) | 268 if (playing()) |
257 return true; | 269 return true; |
258 SetStartPlaybackState(); | 270 SetStartPlaybackState(); |
259 return audio_->StartPlayback(); | 271 return audio_->StartPlayback(); |
260 } | 272 } |
261 | 273 |
262 bool Audio::StopPlayback() { | 274 bool PPB_Audio_Impl::StopPlayback() { |
263 if (!playing()) | 275 if (!playing()) |
264 return true; | 276 return true; |
265 if (!audio_->StopPlayback()) | 277 if (!audio_->StopPlayback()) |
266 return false; | 278 return false; |
267 SetStopPlaybackState(); | 279 SetStopPlaybackState(); |
268 return true; | 280 return true; |
269 } | 281 } |
270 | 282 |
271 int32_t Audio::Open(PluginDelegate* plugin_delegate, | 283 int32_t PPB_Audio_Impl::Open(PluginDelegate* plugin_delegate, |
272 PP_Resource config_id, | 284 PP_Resource config_id, |
273 PP_CompletionCallback create_callback) { | 285 PP_CompletionCallback create_callback) { |
274 DCHECK(!audio_); | 286 DCHECK(!audio_); |
275 config_ = Resource::GetAs<AudioConfig>(config_id); | 287 config_ = Resource::GetAs<PPB_AudioConfig_Impl>(config_id); |
276 if (!config_) | 288 if (!config_) |
277 return PP_ERROR_BADRESOURCE; | 289 return PP_ERROR_BADRESOURCE; |
278 | 290 |
279 // When the stream is created, we'll get called back on StreamCreated(). | 291 // When the stream is created, we'll get called back on StreamCreated(). |
280 audio_ = plugin_delegate->CreateAudio(config_->sample_rate(), | 292 audio_ = plugin_delegate->CreateAudio(config_->sample_rate(), |
281 config_->sample_frame_count(), | 293 config_->sample_frame_count(), |
282 this); | 294 this); |
283 if (!audio_) | 295 if (!audio_) |
284 return PP_ERROR_FAILED; | 296 return PP_ERROR_FAILED; |
285 | 297 |
286 // At this point, we are guaranteeing ownership of the completion | 298 // At this point, we are guaranteeing ownership of the completion |
287 // callback. Audio promises to fire the completion callback | 299 // callback. Audio promises to fire the completion callback |
288 // once and only once. | 300 // once and only once. |
289 create_callback_ = create_callback; | 301 create_callback_ = create_callback; |
290 create_callback_pending_ = true; | 302 create_callback_pending_ = true; |
291 return PP_ERROR_WOULDBLOCK; | 303 return PP_ERROR_WOULDBLOCK; |
292 } | 304 } |
293 | 305 |
294 int32_t Audio::GetSyncSocket(int* sync_socket) { | 306 int32_t PPB_Audio_Impl::GetSyncSocket(int* sync_socket) { |
295 if (socket_for_create_callback_.get()) { | 307 if (socket_for_create_callback_.get()) { |
296 #if defined(OS_POSIX) | 308 #if defined(OS_POSIX) |
297 *sync_socket = socket_for_create_callback_->handle(); | 309 *sync_socket = socket_for_create_callback_->handle(); |
298 #elif defined(OS_WIN) | 310 #elif defined(OS_WIN) |
299 *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle()); | 311 *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle()); |
300 #else | 312 #else |
301 #error "Platform not supported." | 313 #error "Platform not supported." |
302 #endif | 314 #endif |
303 return PP_OK; | 315 return PP_OK; |
304 } | 316 } |
305 return PP_ERROR_FAILED; | 317 return PP_ERROR_FAILED; |
306 } | 318 } |
307 | 319 |
308 int32_t Audio::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { | 320 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, uint32_t* shm_size) { |
309 if (shared_memory_for_create_callback_.get()) { | 321 if (shared_memory_for_create_callback_.get()) { |
310 #if defined(OS_POSIX) | 322 #if defined(OS_POSIX) |
311 *shm_handle = shared_memory_for_create_callback_->handle().fd; | 323 *shm_handle = shared_memory_for_create_callback_->handle().fd; |
312 #elif defined(OS_WIN) | 324 #elif defined(OS_WIN) |
313 *shm_handle = reinterpret_cast<int>( | 325 *shm_handle = reinterpret_cast<int>( |
314 shared_memory_for_create_callback_->handle()); | 326 shared_memory_for_create_callback_->handle()); |
315 #else | 327 #else |
316 #error "Platform not supported." | 328 #error "Platform not supported." |
317 #endif | 329 #endif |
318 *shm_size = shared_memory_size_for_create_callback_; | 330 *shm_size = shared_memory_size_for_create_callback_; |
319 return PP_OK; | 331 return PP_OK; |
320 } | 332 } |
321 return PP_ERROR_FAILED; | 333 return PP_ERROR_FAILED; |
322 } | 334 } |
323 | 335 |
324 void Audio::StreamCreated(base::SharedMemoryHandle shared_memory_handle, | 336 void PPB_Audio_Impl::StreamCreated( |
325 size_t shared_memory_size, | 337 base::SharedMemoryHandle shared_memory_handle, |
326 base::SyncSocket::Handle socket_handle) { | 338 size_t shared_memory_size, |
| 339 base::SyncSocket::Handle socket_handle) { |
327 if (create_callback_pending_) { | 340 if (create_callback_pending_) { |
328 // Trusted side of proxy can specify a callback to recieve handles. In | 341 // Trusted side of proxy can specify a callback to recieve handles. In |
329 // this case we don't need to map any data or start the thread since it | 342 // this case we don't need to map any data or start the thread since it |
330 // will be handled by the proxy. | 343 // will be handled by the proxy. |
331 shared_memory_for_create_callback_.reset( | 344 shared_memory_for_create_callback_.reset( |
332 new base::SharedMemory(shared_memory_handle, false)); | 345 new base::SharedMemory(shared_memory_handle, false)); |
333 shared_memory_size_for_create_callback_ = shared_memory_size; | 346 shared_memory_size_for_create_callback_ = shared_memory_size; |
334 socket_for_create_callback_.reset(new base::SyncSocket(socket_handle)); | 347 socket_for_create_callback_.reset(new base::SyncSocket(socket_handle)); |
335 | 348 |
336 PP_RunCompletionCallback(&create_callback_, 0); | 349 PP_RunCompletionCallback(&create_callback_, 0); |
337 create_callback_pending_ = false; | 350 create_callback_pending_ = false; |
338 | 351 |
339 // It might be nice to close the handles here to free up some system | 352 // It might be nice to close the handles here to free up some system |
340 // resources, but we can't since there's a race condition. The handles must | 353 // resources, but we can't since there's a race condition. The handles must |
341 // be valid until they're sent over IPC, which is done from the I/O thread | 354 // be valid until they're sent over IPC, which is done from the I/O thread |
342 // which will often get done after this code executes. We could do | 355 // which will often get done after this code executes. We could do |
343 // something more elaborate like an ACK from the plugin or post a task to | 356 // something more elaborate like an ACK from the plugin or post a task to |
344 // the I/O thread and back, but this extra complexity doesn't seem worth it | 357 // the I/O thread and back, but this extra complexity doesn't seem worth it |
345 // just to clean up these handles faster. | 358 // just to clean up these handles faster. |
346 } else { | 359 } else { |
347 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); | 360 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); |
348 } | 361 } |
349 } | 362 } |
350 | 363 |
351 } // namespace pepper | 364 } // namespace ppapi |
| 365 } // namespace plugins |
| 366 } // namespace webkit |
| 367 |
OLD | NEW |