| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/proxy/ppb_audio_config_proxy.h" | 5 #include "ppapi/proxy/ppb_audio_config_proxy.h" |
| 6 | 6 |
| 7 #include "ppapi/c/ppb_audio_config.h" | 7 #include "ppapi/c/ppb_audio_config.h" |
| 8 #include "ppapi/proxy/plugin_dispatcher.h" | 8 #include "ppapi/proxy/plugin_dispatcher.h" |
| 9 #include "ppapi/proxy/plugin_resource.h" | 9 #include "ppapi/proxy/plugin_resource.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
| 11 | 11 |
| 12 namespace pp { | 12 namespace pp { |
| 13 namespace proxy { | 13 namespace proxy { |
| 14 | 14 |
| 15 class AudioConfig : public PluginResource { | 15 class AudioConfig : public PluginResource { |
| 16 public: | 16 public: |
| 17 AudioConfig(PP_Instance instance, | 17 AudioConfig(PP_Instance instance, |
| 18 SerializedResource resource, |
| 18 PP_AudioSampleRate sample_rate, | 19 PP_AudioSampleRate sample_rate, |
| 19 uint32_t sample_frame_count) | 20 uint32_t sample_frame_count) |
| 20 : PluginResource(instance), | 21 : PluginResource(instance, resource), |
| 21 sample_rate_(sample_rate), | 22 sample_rate_(sample_rate), |
| 22 sample_frame_count_(sample_frame_count) { | 23 sample_frame_count_(sample_frame_count) { |
| 23 } | 24 } |
| 24 virtual ~AudioConfig() {} | 25 virtual ~AudioConfig() {} |
| 25 | 26 |
| 26 // Resource overrides. | 27 // Resource overrides. |
| 27 virtual AudioConfig* AsAudioConfig() { return this; } | 28 virtual AudioConfig* AsAudioConfig() { return this; } |
| 28 | 29 |
| 29 PP_AudioSampleRate sample_rate() const { return sample_rate_; } | 30 PP_AudioSampleRate sample_rate() const { return sample_rate_; } |
| 30 uint32_t sample_frame_count() const { return sample_frame_count_; } | 31 uint32_t sample_frame_count() const { return sample_frame_count_; } |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 PP_AudioSampleRate sample_rate_; | 34 PP_AudioSampleRate sample_rate_; |
| 34 uint32_t sample_frame_count_; | 35 uint32_t sample_frame_count_; |
| 35 | 36 |
| 36 DISALLOW_COPY_AND_ASSIGN(AudioConfig); | 37 DISALLOW_COPY_AND_ASSIGN(AudioConfig); |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 PP_Resource CreateStereo16bit(PP_Instance instance, | 42 PP_Resource CreateStereo16bit(PP_Instance instance, |
| 42 PP_AudioSampleRate sample_rate, | 43 PP_AudioSampleRate sample_rate, |
| 43 uint32_t sample_frame_count) { | 44 uint32_t sample_frame_count) { |
| 44 PP_Resource result = 0; | 45 SerializedResource resource; |
| 45 PluginDispatcher::GetForInstance(instance)->Send( | 46 PluginDispatcher::GetForInstance(instance)->Send( |
| 46 new PpapiHostMsg_PPBAudioConfig_Create( | 47 new PpapiHostMsg_PPBAudioConfig_Create( |
| 47 INTERFACE_ID_PPB_AUDIO_CONFIG, instance, | 48 INTERFACE_ID_PPB_AUDIO_CONFIG, instance, |
| 48 static_cast<int32_t>(sample_rate), sample_frame_count, | 49 static_cast<int32_t>(sample_rate), sample_frame_count, |
| 49 &result)); | 50 &resource)); |
| 50 if (!result) | 51 if (!resource.is_null()) |
| 51 return 0; | 52 return 0; |
| 52 | 53 |
| 53 linked_ptr<AudioConfig> object( | 54 linked_ptr<AudioConfig> object( |
| 54 new AudioConfig(instance, sample_rate, sample_frame_count)); | 55 new AudioConfig(instance, resource, sample_rate, sample_frame_count)); |
| 55 PluginResourceTracker::GetInstance()->AddResource(result, object); | 56 return PluginResourceTracker::GetInstance()->AddResource(object); |
| 56 return result; | |
| 57 } | 57 } |
| 58 | 58 |
| 59 uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, | 59 uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, |
| 60 uint32_t requested_sample_frame_count) { | 60 uint32_t requested_sample_frame_count) { |
| 61 // TODO(brettw) Currently we don't actually query to get a value from the | 61 // TODO(brettw) Currently we don't actually query to get a value from the |
| 62 // hardware, so we always return the input for in-range values. | 62 // hardware, so we always return the input for in-range values. |
| 63 // | 63 // |
| 64 // Danger: this code is duplicated in the audio config implementation. | 64 // Danger: this code is duplicated in the audio config implementation. |
| 65 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) | 65 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) |
| 66 return PP_AUDIOMINSAMPLEFRAMECOUNT; | 66 return PP_AUDIOMINSAMPLEFRAMECOUNT; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount, | 122 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount, |
| 123 OnMsgRecommendSampleFrameCount) | 123 OnMsgRecommendSampleFrameCount) |
| 124 IPC_MESSAGE_UNHANDLED(handled = false) | 124 IPC_MESSAGE_UNHANDLED(handled = false) |
| 125 IPC_END_MESSAGE_MAP() | 125 IPC_END_MESSAGE_MAP() |
| 126 return handled; | 126 return handled; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void PPB_AudioConfig_Proxy::OnMsgCreateStereo16Bit(PP_Instance instance, | 129 void PPB_AudioConfig_Proxy::OnMsgCreateStereo16Bit(PP_Instance instance, |
| 130 int32_t sample_rate, | 130 int32_t sample_rate, |
| 131 uint32_t sample_frame_count, | 131 uint32_t sample_frame_count, |
| 132 PP_Resource* result) { | 132 SerializedResource* result) { |
| 133 *result = ppb_audio_config_target()->CreateStereo16Bit( | 133 result->set_host_resource(ppb_audio_config_target()->CreateStereo16Bit( |
| 134 instance, static_cast<PP_AudioSampleRate>(sample_rate), | 134 instance, static_cast<PP_AudioSampleRate>(sample_rate), |
| 135 sample_frame_count); | 135 sample_frame_count)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void PPB_AudioConfig_Proxy::OnMsgRecommendSampleFrameCount( | 138 void PPB_AudioConfig_Proxy::OnMsgRecommendSampleFrameCount( |
| 139 int32_t sample_rate, | 139 int32_t sample_rate, |
| 140 uint32_t requested_sample_frame_count, | 140 uint32_t requested_sample_frame_count, |
| 141 uint32_t* result) { | 141 uint32_t* result) { |
| 142 *result = ppb_audio_config_target()->RecommendSampleFrameCount( | 142 *result = ppb_audio_config_target()->RecommendSampleFrameCount( |
| 143 static_cast<PP_AudioSampleRate>(sample_rate), | 143 static_cast<PP_AudioSampleRate>(sample_rate), |
| 144 requested_sample_frame_count); | 144 requested_sample_frame_count); |
| 145 } | 145 } |
| 146 | 146 |
| 147 } // namespace proxy | 147 } // namespace proxy |
| 148 } // namespace pp | 148 } // namespace pp |
| OLD | NEW |