| 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_input_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_audio_input_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 const PPB_AudioInput_Impl::DeviceRefDataVector& | 88 const PPB_AudioInput_Impl::DeviceRefDataVector& |
| 89 PPB_AudioInput_Impl::GetDeviceRefData() const { | 89 PPB_AudioInput_Impl::GetDeviceRefData() const { |
| 90 return devices_data_; | 90 return devices_data_; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void PPB_AudioInput_Impl::StreamCreated( | 93 void PPB_AudioInput_Impl::StreamCreated( |
| 94 base::SharedMemoryHandle shared_memory_handle, | 94 base::SharedMemoryHandle shared_memory_handle, |
| 95 size_t shared_memory_size, | 95 size_t shared_memory_size, |
| 96 base::SyncSocket::Handle socket) { | 96 base::SyncSocket::Handle socket) { |
| 97 // TODO(yzshen): Report open failure. | |
| 98 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket); | 97 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket); |
| 99 } | 98 } |
| 100 | 99 |
| 100 void PPB_AudioInput_Impl::StreamCreationFailed() { |
| 101 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, |
| 102 base::SyncSocket::kInvalidHandle); |
| 103 } |
| 104 |
| 101 int32_t PPB_AudioInput_Impl::InternalEnumerateDevices( | 105 int32_t PPB_AudioInput_Impl::InternalEnumerateDevices( |
| 102 PP_Resource* devices, | 106 PP_Resource* devices, |
| 103 PP_CompletionCallback callback) { | 107 PP_CompletionCallback callback) { |
| 104 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 108 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 105 if (!plugin_delegate) | 109 if (!plugin_delegate) |
| 106 return PP_ERROR_FAILED; | 110 return PP_ERROR_FAILED; |
| 107 | 111 |
| 108 devices_ = devices; | 112 devices_ = devices; |
| 109 enumerate_devices_callback_ = new TrackedCallback(this, callback); | 113 enumerate_devices_callback_ = new TrackedCallback(this, callback); |
| 110 plugin_delegate->EnumerateDevices( | 114 plugin_delegate->EnumerateDevices( |
| 111 PP_DEVICETYPE_DEV_AUDIOCAPTURE, | 115 PP_DEVICETYPE_DEV_AUDIOCAPTURE, |
| 112 base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc, | 116 base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc, |
| 113 AsWeakPtr())); | 117 AsWeakPtr())); |
| 114 return PP_OK_COMPLETIONPENDING; | 118 return PP_OK_COMPLETIONPENDING; |
| 115 } | 119 } |
| 116 | 120 |
| 117 int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id, | 121 int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id, |
| 118 PP_AudioSampleRate sample_rate, | 122 PP_AudioSampleRate sample_rate, |
| 119 uint32_t sample_frame_count, | 123 uint32_t sample_frame_count, |
| 120 PP_CompletionCallback callback) { | 124 PP_CompletionCallback callback) { |
| 121 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 125 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 122 if (!plugin_delegate) | 126 if (!plugin_delegate) |
| 123 return PP_ERROR_FAILED; | 127 return PP_ERROR_FAILED; |
| 124 | 128 |
| 125 // TODO(yzshen): Open the device specified by |device_id|. | |
| 126 // When the stream is created, we'll get called back on StreamCreated(). | 129 // When the stream is created, we'll get called back on StreamCreated(). |
| 127 DCHECK(!audio_input_); | 130 DCHECK(!audio_input_); |
| 128 audio_input_ = plugin_delegate->CreateAudioInput( | 131 audio_input_ = plugin_delegate->CreateAudioInput( |
| 129 sample_rate, sample_frame_count, this); | 132 device_id, sample_rate, sample_frame_count, this); |
| 130 if (audio_input_) { | 133 if (audio_input_) { |
| 131 open_callback_ = new TrackedCallback(this, callback); | 134 open_callback_ = new TrackedCallback(this, callback); |
| 132 return PP_OK_COMPLETIONPENDING; | 135 return PP_OK_COMPLETIONPENDING; |
| 133 } else { | 136 } else { |
| 134 return PP_ERROR_FAILED; | 137 return PP_ERROR_FAILED; |
| 135 } | 138 } |
| 136 } | 139 } |
| 137 | 140 |
| 138 PP_Bool PPB_AudioInput_Impl::InternalStartCapture() { | 141 PP_Bool PPB_AudioInput_Impl::InternalStartCapture() { |
| 139 if (!audio_input_) | 142 if (!audio_input_) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 169 const DeviceRefDataVector& devices) { | 172 const DeviceRefDataVector& devices) { |
| 170 devices_data_.clear(); | 173 devices_data_.clear(); |
| 171 if (succeeded) | 174 if (succeeded) |
| 172 devices_data_ = devices; | 175 devices_data_ = devices; |
| 173 | 176 |
| 174 OnEnumerateDevicesComplete(succeeded ? PP_OK : PP_ERROR_FAILED, devices); | 177 OnEnumerateDevicesComplete(succeeded ? PP_OK : PP_ERROR_FAILED, devices); |
| 175 } | 178 } |
| 176 | 179 |
| 177 } // namespace ppapi | 180 } // namespace ppapi |
| 178 } // namespace webkit | 181 } // namespace webkit |
| OLD | NEW |