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 "ppapi/proxy/ppb_audio_config_proxy.h" | 5 #include "ppapi/proxy/ppb_audio_config_proxy.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_audio_config_dev.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_AudioSampleRate_Dev sample_rate, uint32_t sample_frame_count) | 17 AudioConfig(PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) |
18 : sample_rate_(sample_rate), | 18 : sample_rate_(sample_rate), |
19 sample_frame_count_(sample_frame_count) { | 19 sample_frame_count_(sample_frame_count) { |
20 } | 20 } |
21 virtual ~AudioConfig() {} | 21 virtual ~AudioConfig() {} |
22 | 22 |
23 // Resource overrides. | 23 // Resource overrides. |
24 virtual AudioConfig* AsAudioConfig() { return this; } | 24 virtual AudioConfig* AsAudioConfig() { return this; } |
25 | 25 |
26 PP_AudioSampleRate_Dev sample_rate() const { return sample_rate_; } | 26 PP_AudioSampleRate sample_rate() const { return sample_rate_; } |
27 uint32_t sample_frame_count() const { return sample_frame_count_; } | 27 uint32_t sample_frame_count() const { return sample_frame_count_; } |
28 | 28 |
29 private: | 29 private: |
30 PP_AudioSampleRate_Dev sample_rate_; | 30 PP_AudioSampleRate sample_rate_; |
31 uint32_t sample_frame_count_; | 31 uint32_t sample_frame_count_; |
32 | 32 |
33 DISALLOW_COPY_AND_ASSIGN(AudioConfig); | 33 DISALLOW_COPY_AND_ASSIGN(AudioConfig); |
34 }; | 34 }; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 PP_Resource CreateStereo16bit(PP_Module module_id, | 38 PP_Resource CreateStereo16bit(PP_Module module_id, |
39 PP_AudioSampleRate_Dev sample_rate, | 39 PP_AudioSampleRate sample_rate, |
40 uint32_t sample_frame_count) { | 40 uint32_t sample_frame_count) { |
41 PP_Resource result = 0; | 41 PP_Resource result = 0; |
42 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudioConfig_Create( | 42 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBAudioConfig_Create( |
43 INTERFACE_ID_PPB_AUDIO_CONFIG, module_id, | 43 INTERFACE_ID_PPB_AUDIO_CONFIG, module_id, |
44 static_cast<int32_t>(sample_rate), sample_frame_count, | 44 static_cast<int32_t>(sample_rate), sample_frame_count, |
45 &result)); | 45 &result)); |
46 if (!result) | 46 if (!result) |
47 return 0; | 47 return 0; |
48 | 48 |
49 linked_ptr<AudioConfig> object( | 49 linked_ptr<AudioConfig> object( |
50 new AudioConfig(sample_rate, sample_frame_count)); | 50 new AudioConfig(sample_rate, sample_frame_count)); |
51 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( | 51 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( |
52 result, object); | 52 result, object); |
53 return result; | 53 return result; |
54 } | 54 } |
55 | 55 |
56 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) { | 56 uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, |
| 57 uint32_t requested_sample_frame_count) { |
57 uint32_t result = 0; | 58 uint32_t result = 0; |
58 PluginDispatcher::Get()->Send( | 59 PluginDispatcher::Get()->Send( |
59 new PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount( | 60 new PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount( |
60 INTERFACE_ID_PPB_AUDIO_CONFIG, requested_sample_frame_count, | 61 INTERFACE_ID_PPB_AUDIO_CONFIG, static_cast<int32_t>(sample_rate), |
61 &result)); | 62 requested_sample_frame_count, &result)); |
62 return result; | 63 return result; |
63 } | 64 } |
64 | 65 |
65 PP_Bool IsAudioConfig(PP_Resource resource) { | 66 PP_Bool IsAudioConfig(PP_Resource resource) { |
66 AudioConfig* object = PluginResource::GetAs<AudioConfig>(resource); | 67 AudioConfig* object = PluginResource::GetAs<AudioConfig>(resource); |
67 return BoolToPPBool(!!object); | 68 return BoolToPPBool(!!object); |
68 } | 69 } |
69 | 70 |
70 PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { | 71 PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { |
71 AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id); | 72 AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id); |
72 if (!object) | 73 if (!object) |
73 return PP_AUDIOSAMPLERATE_NONE; | 74 return PP_AUDIOSAMPLERATE_NONE; |
74 return object->sample_rate(); | 75 return object->sample_rate(); |
75 } | 76 } |
76 | 77 |
77 uint32_t GetSampleFrameCount(PP_Resource config_id) { | 78 uint32_t GetSampleFrameCount(PP_Resource config_id) { |
78 AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id); | 79 AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id); |
79 if (!object) | 80 if (!object) |
80 return 0; | 81 return 0; |
81 return object->sample_frame_count(); | 82 return object->sample_frame_count(); |
82 } | 83 } |
83 | 84 |
84 const PPB_AudioConfig_Dev audio_config_interface = { | 85 const PPB_AudioConfig audio_config_interface = { |
85 &CreateStereo16bit, | 86 &CreateStereo16bit, |
86 &RecommendSampleFrameCount, | 87 &RecommendSampleFrameCount, |
87 &IsAudioConfig, | 88 &IsAudioConfig, |
88 &GetSampleRate, | 89 &GetSampleRate, |
89 &GetSampleFrameCount | 90 &GetSampleFrameCount |
90 }; | 91 }; |
91 | 92 |
92 } // namespace | 93 } // namespace |
93 | 94 |
94 PPB_AudioConfig_Proxy::PPB_AudioConfig_Proxy(Dispatcher* dispatcher, | 95 PPB_AudioConfig_Proxy::PPB_AudioConfig_Proxy(Dispatcher* dispatcher, |
(...skipping 22 matching lines...) Expand all Loading... |
117 IPC_MESSAGE_UNHANDLED(handled = false) | 118 IPC_MESSAGE_UNHANDLED(handled = false) |
118 IPC_END_MESSAGE_MAP() | 119 IPC_END_MESSAGE_MAP() |
119 return handled; | 120 return handled; |
120 } | 121 } |
121 | 122 |
122 void PPB_AudioConfig_Proxy::OnMsgCreateStereo16Bit(PP_Module module, | 123 void PPB_AudioConfig_Proxy::OnMsgCreateStereo16Bit(PP_Module module, |
123 int32_t sample_rate, | 124 int32_t sample_rate, |
124 uint32_t sample_frame_count, | 125 uint32_t sample_frame_count, |
125 PP_Resource* result) { | 126 PP_Resource* result) { |
126 *result = ppb_audio_config_target()->CreateStereo16Bit( | 127 *result = ppb_audio_config_target()->CreateStereo16Bit( |
127 module, static_cast<PP_AudioSampleRate_Dev>(sample_rate), | 128 module, static_cast<PP_AudioSampleRate>(sample_rate), |
128 sample_frame_count); | 129 sample_frame_count); |
129 } | 130 } |
130 | 131 |
131 void PPB_AudioConfig_Proxy::OnMsgRecommendSampleFrameCount( | 132 void PPB_AudioConfig_Proxy::OnMsgRecommendSampleFrameCount( |
132 uint32_t requested, | 133 int32_t sample_rate, |
| 134 uint32_t requested_sample_frame_count, |
133 uint32_t* result) { | 135 uint32_t* result) { |
134 *result = ppb_audio_config_target()->RecommendSampleFrameCount(requested); | 136 *result = ppb_audio_config_target()->RecommendSampleFrameCount( |
| 137 static_cast<PP_AudioSampleRate>(sample_rate), |
| 138 requested_sample_frame_count); |
135 } | 139 } |
136 | 140 |
137 } // namespace proxy | 141 } // namespace proxy |
138 } // namespace pp | 142 } // namespace pp |
OLD | NEW |