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

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

Issue 6279003: Move ppapi audio interface out of dev, but... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_impl.h ('k') | no next file » | 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/plugins/ppapi/ppb_audio_impl.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"
9 #include "ppapi/c/dev/ppb_audio_trusted_dev.h"
10 #include "ppapi/c/pp_completion_callback.h" 8 #include "ppapi/c/pp_completion_callback.h"
9 #include "ppapi/c/ppb_audio.h"
10 #include "ppapi/c/ppb_audio_config.h"
11 #include "ppapi/c/trusted/ppb_audio_trusted.h"
11 #include "webkit/plugins/ppapi/common.h" 12 #include "webkit/plugins/ppapi/common.h"
12 13
13 namespace webkit { 14 namespace webkit {
14 namespace ppapi { 15 namespace ppapi {
15 16
16 namespace { 17 namespace {
17 18
18 // PPB_AudioConfig ------------------------------------------------------------- 19 // PPB_AudioConfig -------------------------------------------------------------
19 20
20 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); 21 uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate,
22 uint32_t requested_sample_frame_count);
21 23
22 PP_Resource CreateStereo16bit(PP_Instance instance_id, 24 PP_Resource CreateStereo16bit(PP_Instance instance_id,
23 PP_AudioSampleRate_Dev sample_rate, 25 PP_AudioSampleRate sample_rate,
24 uint32_t sample_frame_count) { 26 uint32_t sample_frame_count) {
25 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); 27 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
26 if (!instance) 28 if (!instance)
27 return 0; 29 return 0;
28 30
29 // TODO(brettw): Currently we don't actually check what the hardware 31 // TODO(brettw): Currently we don't actually check what the hardware
30 // supports, so just allow sample rates of the "guaranteed working" ones. 32 // supports, so just allow sample rates of the "guaranteed working" ones.
31 if (sample_rate != PP_AUDIOSAMPLERATE_44100 && 33 if (sample_rate != PP_AUDIOSAMPLERATE_44100 &&
32 sample_rate != PP_AUDIOSAMPLERATE_48000) 34 sample_rate != PP_AUDIOSAMPLERATE_48000)
33 return 0; 35 return 0;
34 36
35 // TODO(brettw): Currently we don't actually query to get a value from the 37 // TODO(brettw): Currently we don't actually query to get a value from the
36 // hardware, so just validate the range. 38 // hardware, so just validate the range.
37 if (RecommendSampleFrameCount(sample_frame_count) != sample_frame_count) 39 if (RecommendSampleFrameCount(sample_rate, sample_frame_count) !=
40 sample_frame_count)
38 return 0; 41 return 0;
39 42
40 scoped_refptr<PPB_AudioConfig_Impl> config( 43 scoped_refptr<PPB_AudioConfig_Impl> config(
41 new PPB_AudioConfig_Impl(instance->module(), sample_rate, 44 new PPB_AudioConfig_Impl(instance->module(), sample_rate,
42 sample_frame_count)); 45 sample_frame_count));
43 return config->GetReference(); 46 return config->GetReference();
44 } 47 }
45 48
46 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) { 49 uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate,
50 uint32_t requested_sample_frame_count) {
47 // TODO(brettw) Currently we don't actually query to get a value from the 51 // TODO(brettw) Currently we don't actually query to get a value from the
48 // hardware, so we always return the input for in-range values. 52 // hardware, so we always return the input for in-range values.
49 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) 53 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT)
50 return PP_AUDIOMINSAMPLEFRAMECOUNT; 54 return PP_AUDIOMINSAMPLEFRAMECOUNT;
51 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) 55 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT)
52 return PP_AUDIOMAXSAMPLEFRAMECOUNT; 56 return PP_AUDIOMAXSAMPLEFRAMECOUNT;
53 return requested_sample_frame_count; 57 return requested_sample_frame_count;
54 } 58 }
55 59
56 PP_Bool IsAudioConfig(PP_Resource resource) { 60 PP_Bool IsAudioConfig(PP_Resource resource) {
57 scoped_refptr<PPB_AudioConfig_Impl> config = 61 scoped_refptr<PPB_AudioConfig_Impl> config =
58 Resource::GetAs<PPB_AudioConfig_Impl>(resource); 62 Resource::GetAs<PPB_AudioConfig_Impl>(resource);
59 return BoolToPPBool(!!config); 63 return BoolToPPBool(!!config);
60 } 64 }
61 65
62 PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { 66 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) {
63 scoped_refptr<PPB_AudioConfig_Impl> config = 67 scoped_refptr<PPB_AudioConfig_Impl> config =
64 Resource::GetAs<PPB_AudioConfig_Impl>(config_id); 68 Resource::GetAs<PPB_AudioConfig_Impl>(config_id);
65 return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE; 69 return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE;
66 } 70 }
67 71
68 uint32_t GetSampleFrameCount(PP_Resource config_id) { 72 uint32_t GetSampleFrameCount(PP_Resource config_id) {
69 scoped_refptr<PPB_AudioConfig_Impl> config = 73 scoped_refptr<PPB_AudioConfig_Impl> config =
70 Resource::GetAs<PPB_AudioConfig_Impl>(config_id); 74 Resource::GetAs<PPB_AudioConfig_Impl>(config_id);
71 return config ? config->sample_frame_count() : 0; 75 return config ? config->sample_frame_count() : 0;
72 } 76 }
73 77
74 const PPB_AudioConfig_Dev ppb_audioconfig = { 78 const PPB_AudioConfig ppb_audioconfig = {
75 &CreateStereo16bit, 79 &CreateStereo16bit,
76 &RecommendSampleFrameCount, 80 &RecommendSampleFrameCount,
77 &IsAudioConfig, 81 &IsAudioConfig,
78 &GetSampleRate, 82 &GetSampleRate,
79 &GetSampleFrameCount 83 &GetSampleFrameCount
80 }; 84 };
81 85
82 // PPB_Audio ------------------------------------------------------------------- 86 // PPB_Audio -------------------------------------------------------------------
83 87
84 PP_Resource Create(PP_Instance instance_id, PP_Resource config_id, 88 PP_Resource Create(PP_Instance instance_id, PP_Resource config_id,
(...skipping 28 matching lines...) Expand all
113 Resource::GetAs<PPB_Audio_Impl>(audio_id); 117 Resource::GetAs<PPB_Audio_Impl>(audio_id);
114 return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE; 118 return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE;
115 } 119 }
116 120
117 PP_Bool StopPlayback(PP_Resource audio_id) { 121 PP_Bool StopPlayback(PP_Resource audio_id) {
118 scoped_refptr<PPB_Audio_Impl> audio = 122 scoped_refptr<PPB_Audio_Impl> audio =
119 Resource::GetAs<PPB_Audio_Impl>(audio_id); 123 Resource::GetAs<PPB_Audio_Impl>(audio_id);
120 return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE; 124 return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE;
121 } 125 }
122 126
123 const PPB_Audio_Dev ppb_audio = { 127 const PPB_Audio ppb_audio = {
124 &Create, 128 &Create,
125 &IsAudio, 129 &IsAudio,
126 &GetCurrentConfig, 130 &GetCurrentConfig,
127 &StartPlayback, 131 &StartPlayback,
128 &StopPlayback, 132 &StopPlayback,
129 }; 133 };
130 134
131 // PPB_AudioTrusted ------------------------------------------------------------ 135 // PPB_AudioTrusted ------------------------------------------------------------
132 136
133 PP_Resource CreateTrusted(PP_Instance instance_id) { 137 PP_Resource CreateTrusted(PP_Instance instance_id) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 int32_t GetSharedMemory(PP_Resource audio_id, 170 int32_t GetSharedMemory(PP_Resource audio_id,
167 int* shm_handle, 171 int* shm_handle,
168 uint32_t* shm_size) { 172 uint32_t* shm_size) {
169 scoped_refptr<PPB_Audio_Impl> audio = 173 scoped_refptr<PPB_Audio_Impl> audio =
170 Resource::GetAs<PPB_Audio_Impl>(audio_id); 174 Resource::GetAs<PPB_Audio_Impl>(audio_id);
171 if (audio) 175 if (audio)
172 return audio->GetSharedMemory(shm_handle, shm_size); 176 return audio->GetSharedMemory(shm_handle, shm_size);
173 return PP_ERROR_BADRESOURCE; 177 return PP_ERROR_BADRESOURCE;
174 } 178 }
175 179
176 const PPB_AudioTrusted_Dev ppb_audiotrusted = { 180 const PPB_AudioTrusted ppb_audiotrusted = {
177 &CreateTrusted, 181 &CreateTrusted,
178 &Open, 182 &Open,
179 &GetSyncSocket, 183 &GetSyncSocket,
180 &GetSharedMemory, 184 &GetSharedMemory,
181 }; 185 };
182 186
183 } // namespace 187 } // namespace
184 188
185 // PPB_AudioConfig_Impl -------------------------------------------------------- 189 // PPB_AudioConfig_Impl --------------------------------------------------------
186 190
187 PPB_AudioConfig_Impl::PPB_AudioConfig_Impl( 191 PPB_AudioConfig_Impl::PPB_AudioConfig_Impl(
188 PluginModule* module, 192 PluginModule* module,
189 PP_AudioSampleRate_Dev sample_rate, 193 PP_AudioSampleRate sample_rate,
190 uint32_t sample_frame_count) 194 uint32_t sample_frame_count)
191 : Resource(module), 195 : Resource(module),
192 sample_rate_(sample_rate), 196 sample_rate_(sample_rate),
193 sample_frame_count_(sample_frame_count) { 197 sample_frame_count_(sample_frame_count) {
194 } 198 }
195 199
196 const PPB_AudioConfig_Dev* PPB_AudioConfig_Impl::GetInterface() { 200 const PPB_AudioConfig* PPB_AudioConfig_Impl::GetInterface() {
197 return &ppb_audioconfig; 201 return &ppb_audioconfig;
198 } 202 }
199 203
200 size_t PPB_AudioConfig_Impl::BufferSize() { 204 size_t PPB_AudioConfig_Impl::BufferSize() {
201 // TODO(audio): as more options become available, we'll need to 205 // TODO(audio): as more options become available, we'll need to
202 // have additional code here to correctly calculate the size in 206 // have additional code here to correctly calculate the size in
203 // bytes of an audio buffer. For now, only support two channel 207 // bytes of an audio buffer. For now, only support two channel
204 // int16_t sample buffers. 208 // int16_t sample buffers.
205 const int kChannels = 2; 209 const int kChannels = 2;
206 const int kSizeOfSample = sizeof(int16_t); 210 const int kSizeOfSample = sizeof(int16_t);
(...skipping 20 matching lines...) Expand all
227 audio_ = NULL; 231 audio_ = NULL;
228 232
229 // If the completion callback hasn't fired yet, do so here 233 // If the completion callback hasn't fired yet, do so here
230 // with an error condition. 234 // with an error condition.
231 if (create_callback_pending_) { 235 if (create_callback_pending_) {
232 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED); 236 PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED);
233 create_callback_pending_ = false; 237 create_callback_pending_ = false;
234 } 238 }
235 } 239 }
236 240
237 const PPB_Audio_Dev* PPB_Audio_Impl::GetInterface() { 241 const PPB_Audio* PPB_Audio_Impl::GetInterface() {
238 return &ppb_audio; 242 return &ppb_audio;
239 } 243 }
240 244
241 const PPB_AudioTrusted_Dev* PPB_Audio_Impl::GetTrustedInterface() { 245 const PPB_AudioTrusted* PPB_Audio_Impl::GetTrustedInterface() {
242 return &ppb_audiotrusted; 246 return &ppb_audiotrusted;
243 } 247 }
244 248
245 PPB_Audio_Impl* PPB_Audio_Impl::AsPPB_Audio_Impl() { 249 PPB_Audio_Impl* PPB_Audio_Impl::AsPPB_Audio_Impl() {
246 return this; 250 return this;
247 } 251 }
248 252
249 bool PPB_Audio_Impl::Init(PluginDelegate* plugin_delegate, 253 bool PPB_Audio_Impl::Init(PluginDelegate* plugin_delegate,
250 PP_Resource config_id, 254 PP_Resource config_id,
251 PPB_Audio_Callback callback, void* user_data) { 255 PPB_Audio_Callback callback, void* user_data) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // the I/O thread and back, but this extra complexity doesn't seem worth it 363 // the I/O thread and back, but this extra complexity doesn't seem worth it
360 // just to clean up these handles faster. 364 // just to clean up these handles faster.
361 } else { 365 } else {
362 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); 366 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
363 } 367 }
364 } 368 }
365 369
366 } // namespace ppapi 370 } // namespace ppapi
367 } // namespace webkit 371 } // namespace webkit
368 372
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698