Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(943)

Side by Side Diff: webkit/plugins/ppapi/ppb_audio_input_impl.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export AssertLockHeld Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_input_impl.h ('k') | webkit/plugins/ppapi/ppb_broker_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 24 matching lines...) Expand all
35 // static 35 // static
36 PP_Resource PPB_AudioInput_Impl::Create0_1( 36 PP_Resource PPB_AudioInput_Impl::Create0_1(
37 PP_Instance instance, 37 PP_Instance instance,
38 PP_Resource config, 38 PP_Resource config,
39 PPB_AudioInput_Callback audio_input_callback, 39 PPB_AudioInput_Callback audio_input_callback,
40 void* user_data) { 40 void* user_data) {
41 scoped_refptr<PPB_AudioInput_Impl> 41 scoped_refptr<PPB_AudioInput_Impl>
42 audio_input(new PPB_AudioInput_Impl(instance)); 42 audio_input(new PPB_AudioInput_Impl(instance));
43 int32_t result = audio_input->Open( 43 int32_t result = audio_input->Open(
44 "", config, audio_input_callback, user_data, 44 "", config, audio_input_callback, user_data,
45 MakeIgnoredCompletionCallback()); 45 MakeIgnoredCompletionCallback(audio_input.get()));
46 if (result != PP_OK && result != PP_OK_COMPLETIONPENDING) 46 if (result != PP_OK && result != PP_OK_COMPLETIONPENDING)
47 return 0; 47 return 0;
48 return audio_input->GetReference(); 48 return audio_input->GetReference();
49 } 49 }
50 50
51 int32_t PPB_AudioInput_Impl::OpenTrusted( 51 int32_t PPB_AudioInput_Impl::OpenTrusted(
52 const std::string& device_id, 52 const std::string& device_id,
53 PP_Resource config, 53 PP_Resource config,
54 const PP_CompletionCallback& create_callback) { 54 scoped_refptr<TrackedCallback> create_callback) {
55 return CommonOpen(device_id, config, NULL, NULL, create_callback); 55 return CommonOpen(device_id, config, NULL, NULL, create_callback);
56 } 56 }
57 57
58 int32_t PPB_AudioInput_Impl::GetSyncSocket(int* sync_socket) { 58 int32_t PPB_AudioInput_Impl::GetSyncSocket(int* sync_socket) {
59 if (socket_.get()) { 59 if (socket_.get()) {
60 #if defined(OS_POSIX) 60 #if defined(OS_POSIX)
61 *sync_socket = socket_->handle(); 61 *sync_socket = socket_->handle();
62 #elif defined(OS_WIN) 62 #elif defined(OS_WIN)
63 *sync_socket = reinterpret_cast<int>(socket_->handle()); 63 *sync_socket = reinterpret_cast<int>(socket_->handle());
64 #else 64 #else
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket); 97 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket);
98 } 98 }
99 99
100 void PPB_AudioInput_Impl::StreamCreationFailed() { 100 void PPB_AudioInput_Impl::StreamCreationFailed() {
101 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, 101 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0,
102 base::SyncSocket::kInvalidHandle); 102 base::SyncSocket::kInvalidHandle);
103 } 103 }
104 104
105 int32_t PPB_AudioInput_Impl::InternalEnumerateDevices( 105 int32_t PPB_AudioInput_Impl::InternalEnumerateDevices(
106 PP_Resource* devices, 106 PP_Resource* devices,
107 PP_CompletionCallback callback) { 107 scoped_refptr<TrackedCallback> callback) {
108 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); 108 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
109 if (!plugin_delegate) 109 if (!plugin_delegate)
110 return PP_ERROR_FAILED; 110 return PP_ERROR_FAILED;
111 111
112 devices_ = devices; 112 devices_ = devices;
113 enumerate_devices_callback_ = new TrackedCallback(this, callback); 113 enumerate_devices_callback_ = callback;
114 plugin_delegate->EnumerateDevices( 114 plugin_delegate->EnumerateDevices(
115 PP_DEVICETYPE_DEV_AUDIOCAPTURE, 115 PP_DEVICETYPE_DEV_AUDIOCAPTURE,
116 base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc, 116 base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc,
117 AsWeakPtr())); 117 AsWeakPtr()));
118 return PP_OK_COMPLETIONPENDING; 118 return PP_OK_COMPLETIONPENDING;
119 } 119 }
120 120
121 int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id, 121 int32_t PPB_AudioInput_Impl::InternalOpen(
122 PP_AudioSampleRate sample_rate, 122 const std::string& device_id,
123 uint32_t sample_frame_count, 123 PP_AudioSampleRate sample_rate,
124 PP_CompletionCallback callback) { 124 uint32_t sample_frame_count,
125 scoped_refptr<TrackedCallback> 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
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
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_input_impl.h ('k') | webkit/plugins/ppapi/ppb_broker_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698