OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/audio/audio_output_controller.h" | 8 #include "media/audio/audio_output_controller.h" |
9 #include "ppapi/c/pp_completion_callback.h" | 9 #include "ppapi/c/pp_completion_callback.h" |
10 #include "ppapi/c/ppb_audio.h" | 10 #include "ppapi/c/ppb_audio.h" |
11 #include "ppapi/c/ppb_audio_config.h" | 11 #include "ppapi/c/ppb_audio_config.h" |
12 #include "ppapi/c/trusted/ppb_audio_trusted.h" | 12 #include "ppapi/c/trusted/ppb_audio_trusted.h" |
13 #include "ppapi/shared_impl/resource_tracker.h" | 13 #include "ppapi/shared_impl/resource_tracker.h" |
14 #include "ppapi/thunk/enter.h" | 14 #include "ppapi/thunk/enter.h" |
15 #include "ppapi/thunk/ppb_audio_config_api.h" | 15 #include "ppapi/thunk/ppb_audio_config_api.h" |
16 #include "ppapi/thunk/thunk.h" | 16 #include "ppapi/thunk/thunk.h" |
17 #include "webkit/plugins/ppapi/common.h" | 17 #include "webkit/plugins/ppapi/common.h" |
18 #include "webkit/plugins/ppapi/resource_helper.h" | 18 #include "webkit/plugins/ppapi/resource_helper.h" |
19 | 19 |
| 20 using ppapi::ApiCallbackType; |
20 using ppapi::PpapiGlobals; | 21 using ppapi::PpapiGlobals; |
21 using ppapi::thunk::EnterResourceNoLock; | 22 using ppapi::thunk::EnterResourceNoLock; |
22 using ppapi::thunk::PPB_Audio_API; | 23 using ppapi::thunk::PPB_Audio_API; |
23 using ppapi::thunk::PPB_AudioConfig_API; | 24 using ppapi::thunk::PPB_AudioConfig_API; |
24 using ppapi::TrackedCallback; | 25 using ppapi::TrackedCallback; |
25 | 26 |
26 namespace webkit { | 27 namespace webkit { |
27 namespace ppapi { | 28 namespace ppapi { |
28 | 29 |
29 // PPB_Audio_Impl -------------------------------------------------------------- | 30 // PPB_Audio_Impl -------------------------------------------------------------- |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return PP_FALSE; | 107 return PP_FALSE; |
107 if (!playing()) | 108 if (!playing()) |
108 return PP_TRUE; | 109 return PP_TRUE; |
109 if (!audio_->StopPlayback()) | 110 if (!audio_->StopPlayback()) |
110 return PP_FALSE; | 111 return PP_FALSE; |
111 SetStopPlaybackState(); | 112 SetStopPlaybackState(); |
112 return PP_TRUE; | 113 return PP_TRUE; |
113 } | 114 } |
114 | 115 |
115 int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config, | 116 int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config, |
116 PP_CompletionCallback create_callback) { | 117 ApiCallbackType create_callback) { |
117 // Validate the config and keep a reference to it. | 118 // Validate the config and keep a reference to it. |
118 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); | 119 EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true); |
119 if (enter.failed()) | 120 if (enter.failed()) |
120 return PP_ERROR_FAILED; | 121 return PP_ERROR_FAILED; |
121 config_ = config; | 122 config_ = config; |
122 | 123 |
123 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 124 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
124 if (!plugin_delegate) | 125 if (!plugin_delegate) |
125 return PP_ERROR_FAILED; | 126 return PP_ERROR_FAILED; |
126 | 127 |
127 // When the stream is created, we'll get called back on StreamCreated(). | 128 // When the stream is created, we'll get called back on StreamCreated(). |
128 DCHECK(!audio_); | 129 DCHECK(!audio_); |
129 audio_ = plugin_delegate->CreateAudioOutput( | 130 audio_ = plugin_delegate->CreateAudioOutput( |
130 enter.object()->GetSampleRate(), enter.object()->GetSampleFrameCount(), | 131 enter.object()->GetSampleRate(), enter.object()->GetSampleFrameCount(), |
131 this); | 132 this); |
132 if (!audio_) | 133 if (!audio_) |
133 return PP_ERROR_FAILED; | 134 return PP_ERROR_FAILED; |
134 | 135 |
135 // At this point, we are guaranteeing ownership of the completion | 136 // At this point, we are guaranteeing ownership of the completion |
136 // callback. Audio promises to fire the completion callback | 137 // callback. Audio promises to fire the completion callback |
137 // once and only once. | 138 // once and only once. |
138 SetCreateCallback(new TrackedCallback(this, create_callback)); | 139 SetCreateCallback(create_callback); |
139 | 140 |
140 return PP_OK_COMPLETIONPENDING; | 141 return PP_OK_COMPLETIONPENDING; |
141 } | 142 } |
142 | 143 |
143 int32_t PPB_Audio_Impl::GetSyncSocket(int* sync_socket) { | 144 int32_t PPB_Audio_Impl::GetSyncSocket(int* sync_socket) { |
144 return GetSyncSocketImpl(sync_socket); | 145 return GetSyncSocketImpl(sync_socket); |
145 } | 146 } |
146 | 147 |
147 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, | 148 int32_t PPB_Audio_Impl::GetSharedMemory(int* shm_handle, |
148 uint32_t* shm_size) { | 149 uint32_t* shm_size) { |
149 return GetSharedMemoryImpl(shm_handle, shm_size); | 150 return GetSharedMemoryImpl(shm_handle, shm_size); |
150 } | 151 } |
151 | 152 |
152 void PPB_Audio_Impl::OnSetStreamInfo( | 153 void PPB_Audio_Impl::OnSetStreamInfo( |
153 base::SharedMemoryHandle shared_memory_handle, | 154 base::SharedMemoryHandle shared_memory_handle, |
154 size_t shared_memory_size, | 155 size_t shared_memory_size, |
155 base::SyncSocket::Handle socket_handle) { | 156 base::SyncSocket::Handle socket_handle) { |
156 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); | 157 SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle); |
157 } | 158 } |
158 | 159 |
159 } // namespace ppapi | 160 } // namespace ppapi |
160 } // namespace webkit | 161 } // namespace webkit |
OLD | NEW |