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

Side by Side Diff: webkit/plugins/ppapi/ppb_audio_impl.cc

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

Powered by Google App Engine
This is Rietveld 408576698