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

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

Issue 9705056: PepperPlatformAudioInputImpl: support audio input device selection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_)
140 return PP_FALSE; 143 return PP_FALSE;
141 SetStartCaptureState(); 144 SetStartCaptureState();
142 return BoolToPPBool(audio_input_->StartCapture()); 145 audio_input_->StartCapture();
146 return PP_TRUE;
143 } 147 }
144 148
145 PP_Bool PPB_AudioInput_Impl::InternalStopCapture() { 149 PP_Bool PPB_AudioInput_Impl::InternalStopCapture() {
146 if (!audio_input_) 150 if (!audio_input_)
147 return PP_FALSE; 151 return PP_FALSE;
148 if (!audio_input_->StopCapture()) 152 audio_input_->StopCapture();
149 return PP_FALSE;
150 SetStopCaptureState(); 153 SetStopCaptureState();
151 return PP_TRUE; 154 return PP_TRUE;
152 } 155 }
153 156
154 void PPB_AudioInput_Impl::InternalClose() { 157 void PPB_AudioInput_Impl::InternalClose() {
155 // Calling ShutDown() makes sure StreamCreated() cannot be called anymore and 158 // Calling ShutDown() makes sure StreamCreated() cannot be called anymore and
156 // releases the audio data associated with the pointer. Note however, that 159 // releases the audio data associated with the pointer. Note however, that
157 // until ShutDown() returns, StreamCreated() may still be called. This will be 160 // until ShutDown() returns, StreamCreated() may still be called. This will be
158 // OK since OnOpenComplete() will clean up the handles and do nothing else in 161 // OK since OnOpenComplete() will clean up the handles and do nothing else in
159 // that case. 162 // that case.
160 if (audio_input_) { 163 if (audio_input_) {
161 audio_input_->ShutDown(); 164 audio_input_->ShutDown();
162 audio_input_ = NULL; 165 audio_input_ = NULL;
163 } 166 }
164 } 167 }
165 168
166 void PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc( 169 void PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc(
167 int request_id, 170 int request_id,
168 bool succeeded, 171 bool succeeded,
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
OLDNEW
« webkit/plugins/ppapi/plugin_delegate.h ('K') | « webkit/plugins/ppapi/ppb_audio_input_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698