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/glue/plugins/pepper_audio.h" | 5 #include "webkit/glue/plugins/pepper_audio.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 "webkit/glue/plugins/pepper_common.h" |
10 | 11 |
11 namespace pepper { | 12 namespace pepper { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // PPB_AudioConfig ------------------------------------------------------------- | 16 // PPB_AudioConfig ------------------------------------------------------------- |
16 | 17 |
17 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); | 18 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count); |
18 | 19 |
19 PP_Resource CreateStereo16bit(PP_Module module_id, | 20 PP_Resource CreateStereo16bit(PP_Module module_id, |
(...skipping 23 matching lines...) Expand all Loading... |
43 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) { | 44 uint32_t RecommendSampleFrameCount(uint32_t requested_sample_frame_count) { |
44 // TODO(brettw) Currently we don't actually query to get a value from the | 45 // TODO(brettw) Currently we don't actually query to get a value from the |
45 // hardware, so we always return the input for in-range values. | 46 // hardware, so we always return the input for in-range values. |
46 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) | 47 if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) |
47 return PP_AUDIOMINSAMPLEFRAMECOUNT; | 48 return PP_AUDIOMINSAMPLEFRAMECOUNT; |
48 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) | 49 if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) |
49 return PP_AUDIOMAXSAMPLEFRAMECOUNT; | 50 return PP_AUDIOMAXSAMPLEFRAMECOUNT; |
50 return requested_sample_frame_count; | 51 return requested_sample_frame_count; |
51 } | 52 } |
52 | 53 |
53 bool IsAudioConfig(PP_Resource resource) { | 54 PP_Bool IsAudioConfig(PP_Resource resource) { |
54 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(resource); | 55 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(resource); |
55 return !!config; | 56 return BoolToPPBool(!!config); |
56 } | 57 } |
57 | 58 |
58 PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { | 59 PP_AudioSampleRate_Dev GetSampleRate(PP_Resource config_id) { |
59 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id); | 60 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id); |
60 return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE; | 61 return config ? config->sample_rate() : PP_AUDIOSAMPLERATE_NONE; |
61 } | 62 } |
62 | 63 |
63 uint32_t GetSampleFrameCount(PP_Resource config_id) { | 64 uint32_t GetSampleFrameCount(PP_Resource config_id) { |
64 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id); | 65 scoped_refptr<AudioConfig> config = Resource::GetAs<AudioConfig>(config_id); |
65 return config ? config->sample_frame_count() : 0; | 66 return config ? config->sample_frame_count() : 0; |
(...skipping 14 matching lines...) Expand all Loading... |
80 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 81 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
81 if (!instance) | 82 if (!instance) |
82 return 0; | 83 return 0; |
83 // TODO(neb): Require callback to be present for untrusted plugins. | 84 // TODO(neb): Require callback to be present for untrusted plugins. |
84 scoped_refptr<Audio> audio(new Audio(instance->module())); | 85 scoped_refptr<Audio> audio(new Audio(instance->module())); |
85 if (!audio->Init(instance->delegate(), config_id, callback, user_data)) | 86 if (!audio->Init(instance->delegate(), config_id, callback, user_data)) |
86 return 0; | 87 return 0; |
87 return audio->GetReference(); | 88 return audio->GetReference(); |
88 } | 89 } |
89 | 90 |
90 bool IsAudio(PP_Resource resource) { | 91 PP_Bool IsAudio(PP_Resource resource) { |
91 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(resource); | 92 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(resource); |
92 return !!audio; | 93 return BoolToPPBool(!!audio); |
93 } | 94 } |
94 | 95 |
95 PP_Resource GetCurrentConfiguration(PP_Resource audio_id) { | 96 PP_Resource GetCurrentConfiguration(PP_Resource audio_id) { |
96 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 97 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); |
97 return audio ? audio->GetCurrentConfiguration() : 0; | 98 return audio ? audio->GetCurrentConfiguration() : 0; |
98 } | 99 } |
99 | 100 |
100 bool StartPlayback(PP_Resource audio_id) { | 101 PP_Bool StartPlayback(PP_Resource audio_id) { |
101 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 102 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); |
102 return audio ? audio->StartPlayback() : false; | 103 return audio ? BoolToPPBool(audio->StartPlayback()) : PP_FALSE; |
103 } | 104 } |
104 | 105 |
105 bool StopPlayback(PP_Resource audio_id) { | 106 PP_Bool StopPlayback(PP_Resource audio_id) { |
106 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); | 107 scoped_refptr<Audio> audio = Resource::GetAs<Audio>(audio_id); |
107 return audio ? audio->StopPlayback() : false; | 108 return audio ? BoolToPPBool(audio->StopPlayback()) : PP_FALSE; |
108 } | 109 } |
109 | 110 |
110 const PPB_Audio_Dev ppb_audio = { | 111 const PPB_Audio_Dev ppb_audio = { |
111 &Create, | 112 &Create, |
112 &IsAudio, | 113 &IsAudio, |
113 &GetCurrentConfiguration, | 114 &GetCurrentConfiguration, |
114 &StartPlayback, | 115 &StartPlayback, |
115 &StopPlayback, | 116 &StopPlayback, |
116 }; | 117 }; |
117 | 118 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 pending_data >= 0) { | 271 pending_data >= 0) { |
271 // Exit the thread on pause. | 272 // Exit the thread on pause. |
272 if (pending_data < 0) | 273 if (pending_data < 0) |
273 return; | 274 return; |
274 callback_(buffer, buffer_size_in_bytes, user_data_); | 275 callback_(buffer, buffer_size_in_bytes, user_data_); |
275 } | 276 } |
276 } | 277 } |
277 | 278 |
278 } // namespace pepper | 279 } // namespace pepper |
279 | 280 |
OLD | NEW |