| 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/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" | 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/plugins/ppapi/common.h" | 11 #include "webkit/plugins/ppapi/common.h" |
| 12 | 12 |
| 13 namespace webkit { | 13 namespace webkit { |
| 14 namespace ppapi { | 14 namespace ppapi { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // PPB_AudioConfig ------------------------------------------------------------- | 18 // PPB_AudioConfig ------------------------------------------------------------- |
| 19 | 19 |
| 20 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); | 20 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); |
| 21 | 21 |
| 22 PP_Resource CreateStereo16bit(PP_Module module_id, | 22 PP_Resource CreateStereo16bit(PP_Instance instance_id, |
| 23 PP_AudioSampleRate_Dev sample_rate, | 23 PP_AudioSampleRate_Dev sample_rate, |
| 24 uint32_t sample_frame_count) { | 24 uint32_t sample_frame_count) { |
| 25 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); | 25 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 26 if (!module) | 26 if (!instance) |
| 27 return 0; | 27 return 0; |
| 28 | 28 |
| 29 // TODO(brettw): Currently we don't actually check what the hardware | 29 // TODO(brettw): Currently we don't actually check what the hardware |
| 30 // supports, so just allow sample rates of the "guaranteed working" ones. | 30 // supports, so just allow sample rates of the "guaranteed working" ones. |
| 31 if (sample_rate != PP_AUDIOSAMPLERATE_44100 && | 31 if (sample_rate != PP_AUDIOSAMPLERATE_44100 && |
| 32 sample_rate != PP_AUDIOSAMPLERATE_48000) | 32 sample_rate != PP_AUDIOSAMPLERATE_48000) |
| 33 return 0; | 33 return 0; |
| 34 | 34 |
| 35 // 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 |
| 36 // hardware, so just validate the range. | 36 // hardware, so just validate the range. |
| 37 if (RecommendSampleFrameCount(sample_frame_count) != sample_frame_count) | 37 if (RecommendSampleFrameCount(sample_frame_count) != sample_frame_count) |
| 38 return 0; | 38 return 0; |
| 39 | 39 |
| 40 scoped_refptr<PPB_AudioConfig_Impl> config( | 40 scoped_refptr<PPB_AudioConfig_Impl> config( |
| 41 new PPB_AudioConfig_Impl(module, sample_rate, sample_frame_count)); | 41 new PPB_AudioConfig_Impl(instance->module(), sample_rate, |
| 42 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; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 return audio->GetReference(); | 96 return audio->GetReference(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 PP_Bool IsAudio(PP_Resource resource) { | 99 PP_Bool IsAudio(PP_Resource resource) { |
| 99 scoped_refptr<PPB_Audio_Impl> audio = | 100 scoped_refptr<PPB_Audio_Impl> audio = |
| 100 Resource::GetAs<PPB_Audio_Impl>(resource); | 101 Resource::GetAs<PPB_Audio_Impl>(resource); |
| 101 return BoolToPPBool(!!audio); | 102 return BoolToPPBool(!!audio); |
| 102 } | 103 } |
| 103 | 104 |
| 104 PP_Resource GetCurrentConfig(PP_Resource audio_id) { | 105 PP_Resource GetCurrentConfig(PP_Resource audio_id) { |
| 105 scoped_refptr<PPB_Audio_Impl> audio = Resource::GetAs<PPB_Audio_Impl>(audio_id
); | 106 scoped_refptr<PPB_Audio_Impl> audio = |
| 107 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
| 106 return audio ? audio->GetCurrentConfig() : 0; | 108 return audio ? audio->GetCurrentConfig() : 0; |
| 107 } | 109 } |
| 108 | 110 |
| 109 PP_Bool StartPlayback(PP_Resource audio_id) { | 111 PP_Bool StartPlayback(PP_Resource audio_id) { |
| 110 scoped_refptr<PPB_Audio_Impl> audio = | 112 scoped_refptr<PPB_Audio_Impl> audio = |
| 111 Resource::GetAs<PPB_Audio_Impl>(audio_id); | 113 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
| 112 return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE; | 114 return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE; |
| 113 } | 115 } |
| 114 | 116 |
| 115 PP_Bool StopPlayback(PP_Resource audio_id) { | 117 PP_Bool StopPlayback(PP_Resource audio_id) { |
| 116 scoped_refptr<PPB_Audio_Impl> audio = | 118 scoped_refptr<PPB_Audio_Impl> audio = |
| 117 Resource::GetAs<PPB_Audio_Impl>(audio_id); | 119 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
| 118 return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE; | 120 return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE; |
| 119 } | 121 } |
| 120 | 122 |
| 121 const PPB_Audio_Dev ppb_audio = { | 123 const PPB_Audio_Dev ppb_audio = { |
| 122 &Create, | 124 &Create, |
| 123 &IsAudio, | 125 &IsAudio, |
| 124 &GetCurrentConfig, | 126 &GetCurrentConfig, |
| 125 &StartPlayback, | 127 &StartPlayback, |
| 126 &StopPlayback, | 128 &StopPlayback, |
| 127 }; | 129 }; |
| 128 | 130 |
| 129 // PPB_AudioTrusted ------------------------------------------------------------ | 131 // PPB_AudioTrusted ------------------------------------------------------------ |
| 130 | 132 |
| 131 PP_Resource CreateTrusted(PP_Instance instance_id) { | 133 PP_Resource CreateTrusted(PP_Instance instance_id) { |
| 132 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 134 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
| 133 if (!instance) | 135 if (!instance) |
| 134 return 0; | 136 return 0; |
| 135 scoped_refptr<PPB_Audio_Impl> audio(new PPB_Audio_Impl(instance->module(), ins
tance_id)); | 137 scoped_refptr<PPB_Audio_Impl> audio( |
| 138 new PPB_Audio_Impl(instance->module(), instance_id)); |
| 136 return audio->GetReference(); | 139 return audio->GetReference(); |
| 137 } | 140 } |
| 138 | 141 |
| 139 int32_t Open(PP_Resource audio_id, | 142 int32_t Open(PP_Resource audio_id, |
| 140 PP_Resource config_id, | 143 PP_Resource config_id, |
| 141 PP_CompletionCallback created) { | 144 PP_CompletionCallback created) { |
| 142 scoped_refptr<PPB_Audio_Impl> audio = | 145 scoped_refptr<PPB_Audio_Impl> audio = |
| 143 Resource::GetAs<PPB_Audio_Impl>(audio_id); | 146 Resource::GetAs<PPB_Audio_Impl>(audio_id); |
| 144 if (!audio) | 147 if (!audio) |
| 145 return PP_ERROR_BADRESOURCE; | 148 return PP_ERROR_BADRESOURCE; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 // the I/O thread and back, but this extra complexity doesn't seem worth it | 359 // the I/O thread and back, but this extra complexity doesn't seem worth it |
| 357 // just to clean up these handles faster. | 360 // just to clean up these handles faster. |
| 358 } else { | 361 } else { |
| 359 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); | 362 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); |
| 360 } | 363 } |
| 361 } | 364 } |
| 362 | 365 |
| 363 } // namespace ppapi | 366 } // namespace ppapi |
| 364 } // namespace webkit | 367 } // namespace webkit |
| 365 | 368 |
| OLD | NEW |