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" |
11 #include "base/sync_socket.h" | 11 #include "base/sync_socket.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
14 #include "ppapi/shared_impl/ppb_device_ref_shared.h" | 14 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
15 #include "ppapi/shared_impl/tracked_callback.h" | 15 #include "ppapi/shared_impl/tracked_callback.h" |
16 #include "webkit/plugins/ppapi/common.h" | 16 #include "webkit/plugins/ppapi/common.h" |
17 #include "webkit/plugins/ppapi/resource_helper.h" | 17 #include "webkit/plugins/ppapi/resource_helper.h" |
18 | 18 |
| 19 using ppapi::ApiCallbackType; |
19 using ppapi::TrackedCallback; | 20 using ppapi::TrackedCallback; |
20 | 21 |
21 namespace webkit { | 22 namespace webkit { |
22 namespace ppapi { | 23 namespace ppapi { |
23 | 24 |
24 // PPB_AudioInput_Impl --------------------------------------------------------- | 25 // PPB_AudioInput_Impl --------------------------------------------------------- |
25 | 26 |
26 PPB_AudioInput_Impl::PPB_AudioInput_Impl(PP_Instance instance) | 27 PPB_AudioInput_Impl::PPB_AudioInput_Impl(PP_Instance instance) |
27 : ::ppapi::PPB_AudioInput_Shared(instance), | 28 : ::ppapi::PPB_AudioInput_Shared(instance), |
28 audio_input_(NULL) { | 29 audio_input_(NULL) { |
29 } | 30 } |
30 | 31 |
31 PPB_AudioInput_Impl::~PPB_AudioInput_Impl() { | 32 PPB_AudioInput_Impl::~PPB_AudioInput_Impl() { |
32 Close(); | 33 Close(); |
33 } | 34 } |
34 | 35 |
35 // static | 36 // static |
36 PP_Resource PPB_AudioInput_Impl::Create0_1( | 37 PP_Resource PPB_AudioInput_Impl::Create0_1( |
37 PP_Instance instance, | 38 PP_Instance instance, |
38 PP_Resource config, | 39 PP_Resource config, |
39 PPB_AudioInput_Callback audio_input_callback, | 40 PPB_AudioInput_Callback audio_input_callback, |
40 void* user_data) { | 41 void* user_data) { |
41 scoped_refptr<PPB_AudioInput_Impl> | 42 scoped_refptr<PPB_AudioInput_Impl> |
42 audio_input(new PPB_AudioInput_Impl(instance)); | 43 audio_input(new PPB_AudioInput_Impl(instance)); |
43 int32_t result = audio_input->Open( | 44 int32_t result = audio_input->Open( |
44 "", config, audio_input_callback, user_data, | 45 "", config, audio_input_callback, user_data, |
45 MakeIgnoredCompletionCallback()); | 46 MakeIgnoredCompletionCallback(audio_input.get())); |
46 if (result != PP_OK && result != PP_OK_COMPLETIONPENDING) | 47 if (result != PP_OK && result != PP_OK_COMPLETIONPENDING) |
47 return 0; | 48 return 0; |
48 return audio_input->GetReference(); | 49 return audio_input->GetReference(); |
49 } | 50 } |
50 | 51 |
51 int32_t PPB_AudioInput_Impl::OpenTrusted( | 52 int32_t PPB_AudioInput_Impl::OpenTrusted( |
52 const std::string& device_id, | 53 const std::string& device_id, |
53 PP_Resource config, | 54 PP_Resource config, |
54 const PP_CompletionCallback& create_callback) { | 55 ApiCallbackType create_callback) { |
55 return CommonOpen(device_id, config, NULL, NULL, create_callback); | 56 return CommonOpen(device_id, config, NULL, NULL, create_callback); |
56 } | 57 } |
57 | 58 |
58 int32_t PPB_AudioInput_Impl::GetSyncSocket(int* sync_socket) { | 59 int32_t PPB_AudioInput_Impl::GetSyncSocket(int* sync_socket) { |
59 if (socket_.get()) { | 60 if (socket_.get()) { |
60 #if defined(OS_POSIX) | 61 #if defined(OS_POSIX) |
61 *sync_socket = socket_->handle(); | 62 *sync_socket = socket_->handle(); |
62 #elif defined(OS_WIN) | 63 #elif defined(OS_WIN) |
63 *sync_socket = reinterpret_cast<int>(socket_->handle()); | 64 *sync_socket = reinterpret_cast<int>(socket_->handle()); |
64 #else | 65 #else |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket); | 98 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket); |
98 } | 99 } |
99 | 100 |
100 void PPB_AudioInput_Impl::StreamCreationFailed() { | 101 void PPB_AudioInput_Impl::StreamCreationFailed() { |
101 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, | 102 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, |
102 base::SyncSocket::kInvalidHandle); | 103 base::SyncSocket::kInvalidHandle); |
103 } | 104 } |
104 | 105 |
105 int32_t PPB_AudioInput_Impl::InternalEnumerateDevices( | 106 int32_t PPB_AudioInput_Impl::InternalEnumerateDevices( |
106 PP_Resource* devices, | 107 PP_Resource* devices, |
107 PP_CompletionCallback callback) { | 108 ApiCallbackType callback) { |
108 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 109 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
109 if (!plugin_delegate) | 110 if (!plugin_delegate) |
110 return PP_ERROR_FAILED; | 111 return PP_ERROR_FAILED; |
111 | 112 |
112 devices_ = devices; | 113 devices_ = devices; |
113 enumerate_devices_callback_ = new TrackedCallback(this, callback); | 114 enumerate_devices_callback_ = callback; |
114 plugin_delegate->EnumerateDevices( | 115 plugin_delegate->EnumerateDevices( |
115 PP_DEVICETYPE_DEV_AUDIOCAPTURE, | 116 PP_DEVICETYPE_DEV_AUDIOCAPTURE, |
116 base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc, | 117 base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc, |
117 AsWeakPtr())); | 118 AsWeakPtr())); |
118 return PP_OK_COMPLETIONPENDING; | 119 return PP_OK_COMPLETIONPENDING; |
119 } | 120 } |
120 | 121 |
121 int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id, | 122 int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id, |
122 PP_AudioSampleRate sample_rate, | 123 PP_AudioSampleRate sample_rate, |
123 uint32_t sample_frame_count, | 124 uint32_t sample_frame_count, |
124 PP_CompletionCallback callback) { | 125 ApiCallbackType callback) { |
125 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 126 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
126 if (!plugin_delegate) | 127 if (!plugin_delegate) |
127 return PP_ERROR_FAILED; | 128 return PP_ERROR_FAILED; |
128 | 129 |
129 // When the stream is created, we'll get called back on StreamCreated(). | 130 // When the stream is created, we'll get called back on StreamCreated(). |
130 DCHECK(!audio_input_); | 131 DCHECK(!audio_input_); |
131 audio_input_ = plugin_delegate->CreateAudioInput( | 132 audio_input_ = plugin_delegate->CreateAudioInput( |
132 device_id, sample_rate, sample_frame_count, this); | 133 device_id, sample_rate, sample_frame_count, this); |
133 if (audio_input_) { | 134 if (audio_input_) { |
134 open_callback_ = new TrackedCallback(this, callback); | 135 open_callback_ = callback; |
135 return PP_OK_COMPLETIONPENDING; | 136 return PP_OK_COMPLETIONPENDING; |
136 } else { | 137 } else { |
137 return PP_ERROR_FAILED; | 138 return PP_ERROR_FAILED; |
138 } | 139 } |
139 } | 140 } |
140 | 141 |
141 PP_Bool PPB_AudioInput_Impl::InternalStartCapture() { | 142 PP_Bool PPB_AudioInput_Impl::InternalStartCapture() { |
142 if (!audio_input_) | 143 if (!audio_input_) |
143 return PP_FALSE; | 144 return PP_FALSE; |
144 SetStartCaptureState(); | 145 SetStartCaptureState(); |
(...skipping 27 matching lines...) Expand all Loading... |
172 const DeviceRefDataVector& devices) { | 173 const DeviceRefDataVector& devices) { |
173 devices_data_.clear(); | 174 devices_data_.clear(); |
174 if (succeeded) | 175 if (succeeded) |
175 devices_data_ = devices; | 176 devices_data_ = devices; |
176 | 177 |
177 OnEnumerateDevicesComplete(succeeded ? PP_OK : PP_ERROR_FAILED, devices); | 178 OnEnumerateDevicesComplete(succeeded ? PP_OK : PP_ERROR_FAILED, devices); |
178 } | 179 } |
179 | 180 |
180 } // namespace ppapi | 181 } // namespace ppapi |
181 } // namespace webkit | 182 } // namespace webkit |
OLD | NEW |