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

Side by Side Diff: content/renderer/pepper/pepper_audio_input_host.cc

Issue 11411047: Introduce PPB_AudioInput_Dev v0.3 and refactor the device enumeration code: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years 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 "content/renderer/pepper/pepper_audio_input_host.h" 5 #include "content/renderer/pepper/pepper_audio_input_host.h"
6 6
7 #include "base/bind.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "build/build_config.h" 8 #include "build/build_config.h"
10 #include "content/public/renderer/renderer_ppapi_host.h" 9 #include "content/public/renderer/renderer_ppapi_host.h"
11 #include "ipc/ipc_message.h" 10 #include "ipc/ipc_message.h"
12 #include "media/audio/shared_memory_util.h" 11 #include "media/audio/shared_memory_util.h"
13 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/host/dispatch_host_message.h" 13 #include "ppapi/host/dispatch_host_message.h"
15 #include "ppapi/host/ppapi_host.h" 14 #include "ppapi/host/ppapi_host.h"
16 #include "ppapi/proxy/ppapi_messages.h" 15 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/proxy/serialized_structs.h" 16 #include "ppapi/proxy/serialized_structs.h"
18 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
20 18
21 namespace content { 19 namespace content {
22 20
23 namespace { 21 namespace {
24 22
25 base::PlatformFile ConvertSyncSocketHandle(const base::SyncSocket& socket) { 23 base::PlatformFile ConvertSyncSocketHandle(const base::SyncSocket& socket) {
26 return socket.handle(); 24 return socket.handle();
27 } 25 }
28 26
29 base::PlatformFile ConvertSharedMemoryHandle( 27 base::PlatformFile ConvertSharedMemoryHandle(
30 const base::SharedMemory& shared_memory) { 28 const base::SharedMemory& shared_memory) {
31 #if defined(OS_POSIX) 29 #if defined(OS_POSIX)
32 return shared_memory.handle().fd; 30 return shared_memory.handle().fd;
33 #elif defined(OS_WIN) 31 #elif defined(OS_WIN)
34 return shared_memory.handle(); 32 return shared_memory.handle();
35 #else 33 #else
36 #error "Platform not supported." 34 #error "Platform not supported."
37 #endif 35 #endif
38 } 36 }
39 37
40 } // namespace 38 } // namespace
41 39
42 PepperAudioInputHost::PepperAudioInputHost( 40 PepperAudioInputHost::PepperAudioInputHost(
43 RendererPpapiHost* host, 41 RendererPpapiHost* host,
44 PP_Instance instance, 42 PP_Instance instance,
45 PP_Resource resource) 43 PP_Resource resource)
46 : ResourceHost(host->GetPpapiHost(), instance, resource), 44 : ResourceHost(host->GetPpapiHost(), instance, resource),
47 renderer_ppapi_host_(host), 45 renderer_ppapi_host_(host),
48 audio_input_(NULL) { 46 audio_input_(NULL),
47 ALLOW_THIS_IN_INITIALIZER_LIST(
48 enumeration_helper_(this, this, PP_DEVICETYPE_DEV_AUDIOCAPTURE)) {
49 } 49 }
50 50
51 PepperAudioInputHost::~PepperAudioInputHost() { 51 PepperAudioInputHost::~PepperAudioInputHost() {
52 Close(); 52 Close();
53 } 53 }
54 54
55 int32_t PepperAudioInputHost::OnResourceMessageReceived( 55 int32_t PepperAudioInputHost::OnResourceMessageReceived(
56 const IPC::Message& msg, 56 const IPC::Message& msg,
57 ppapi::host::HostMessageContext* context) { 57 ppapi::host::HostMessageContext* context) {
58 int32_t result = PP_ERROR_FAILED;
59 if (enumeration_helper_.HandleResourceMessage(msg, context, &result))
60 return result;
61
58 IPC_BEGIN_MESSAGE_MAP(PepperAudioInputHost, msg) 62 IPC_BEGIN_MESSAGE_MAP(PepperAudioInputHost, msg)
59 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(
60 PpapiHostMsg_AudioInput_EnumerateDevices, OnMsgEnumerateDevices)
61 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_AudioInput_Open, OnMsgOpen) 63 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_AudioInput_Open, OnMsgOpen)
62 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_AudioInput_StartOrStop, 64 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_AudioInput_StartOrStop,
63 OnMsgStartOrStop); 65 OnMsgStartOrStop);
64 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_AudioInput_Close, 66 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_AudioInput_Close,
65 OnMsgClose); 67 OnMsgClose);
66 IPC_END_MESSAGE_MAP() 68 IPC_END_MESSAGE_MAP()
67 return PP_ERROR_FAILED; 69 return PP_ERROR_FAILED;
68 } 70 }
69 71
70 void PepperAudioInputHost::StreamCreated( 72 void PepperAudioInputHost::StreamCreated(
71 base::SharedMemoryHandle shared_memory_handle, 73 base::SharedMemoryHandle shared_memory_handle,
72 size_t shared_memory_size, 74 size_t shared_memory_size,
73 base::SyncSocket::Handle socket) { 75 base::SyncSocket::Handle socket) {
74 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket); 76 OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket);
75 } 77 }
76 78
77 void PepperAudioInputHost::StreamCreationFailed() { 79 void PepperAudioInputHost::StreamCreationFailed() {
78 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0, 80 OnOpenComplete(PP_ERROR_FAILED, base::SharedMemory::NULLHandle(), 0,
79 base::SyncSocket::kInvalidHandle); 81 base::SyncSocket::kInvalidHandle);
80 } 82 }
81 83
82 int32_t PepperAudioInputHost::OnMsgEnumerateDevices( 84 webkit::ppapi::PluginDelegate* PepperAudioInputHost::GetPluginDelegate() {
83 ppapi::host::HostMessageContext* context) { 85 webkit::ppapi::PluginInstance* instance =
84 if (enumerate_devices_context_.get()) 86 renderer_ppapi_host_->GetPluginInstance(pp_instance());
85 return PP_ERROR_INPROGRESS; 87 if (instance)
86 88 return instance->delegate();
87 webkit::ppapi::PluginDelegate* plugin_delegate = GetDelegate(); 89 return NULL;
88 if (!plugin_delegate)
89 return PP_ERROR_FAILED;
90
91 enumerate_devices_context_.reset(
92 new ppapi::host::ReplyMessageContext(context->MakeReplyMessageContext()));
93 // Note that the callback may be called synchronously.
94 plugin_delegate->EnumerateDevices(
95 PP_DEVICETYPE_DEV_AUDIOCAPTURE,
96 base::Bind(&PepperAudioInputHost::EnumerateDevicesCallbackFunc,
97 AsWeakPtr()));
98 return PP_OK_COMPLETIONPENDING;
99 } 90 }
100 91
101 int32_t PepperAudioInputHost::OnMsgOpen( 92 int32_t PepperAudioInputHost::OnMsgOpen(
102 ppapi::host::HostMessageContext* context, 93 ppapi::host::HostMessageContext* context,
103 const std::string& device_id, 94 const std::string& device_id,
104 PP_AudioSampleRate sample_rate, 95 PP_AudioSampleRate sample_rate,
105 uint32_t sample_frame_count) { 96 uint32_t sample_frame_count) {
106 if (open_context_.get()) 97 if (open_context_.get())
107 return PP_ERROR_INPROGRESS; 98 return PP_ERROR_INPROGRESS;
108 if (audio_input_) 99 if (audio_input_)
109 return PP_ERROR_FAILED; 100 return PP_ERROR_FAILED;
110 101
111 webkit::ppapi::PluginDelegate* plugin_delegate = GetDelegate(); 102 webkit::ppapi::PluginDelegate* plugin_delegate = GetPluginDelegate();
112 if (!plugin_delegate) 103 if (!plugin_delegate)
113 return PP_ERROR_FAILED; 104 return PP_ERROR_FAILED;
114 105
115 // When it is done, we'll get called back on StreamCreated() or 106 // When it is done, we'll get called back on StreamCreated() or
116 // StreamCreationFailed(). 107 // StreamCreationFailed().
117 audio_input_ = plugin_delegate->CreateAudioInput( 108 audio_input_ = plugin_delegate->CreateAudioInput(
118 device_id, sample_rate, sample_frame_count, this); 109 device_id, sample_rate, sample_frame_count, this);
119 if (audio_input_) { 110 if (audio_input_) {
120 open_context_.reset(new ppapi::host::ReplyMessageContext( 111 open_context_.reset(new ppapi::host::ReplyMessageContext(
121 context->MakeReplyMessageContext())); 112 context->MakeReplyMessageContext()));
(...skipping 14 matching lines...) Expand all
136 audio_input_->StopCapture(); 127 audio_input_->StopCapture();
137 return PP_OK; 128 return PP_OK;
138 } 129 }
139 130
140 int32_t PepperAudioInputHost::OnMsgClose( 131 int32_t PepperAudioInputHost::OnMsgClose(
141 ppapi::host::HostMessageContext* /* context */) { 132 ppapi::host::HostMessageContext* /* context */) {
142 Close(); 133 Close();
143 return PP_OK; 134 return PP_OK;
144 } 135 }
145 136
146 void PepperAudioInputHost::EnumerateDevicesCallbackFunc(
147 int request_id,
148 bool succeeded,
149 const std::vector<ppapi::DeviceRefData>& devices) {
150 DCHECK(enumerate_devices_context_.get());
151
152 webkit::ppapi::PluginDelegate* plugin_delegate = GetDelegate();
153 if (plugin_delegate)
154 plugin_delegate->StopEnumerateDevices(request_id);
155
156 enumerate_devices_context_->params.set_result(
157 succeeded ? PP_OK : PP_ERROR_FAILED);
158 host()->SendReply(
159 *enumerate_devices_context_,
160 PpapiPluginMsg_AudioInput_EnumerateDevicesReply(
161 succeeded ? devices : std::vector<ppapi::DeviceRefData>()));
162 enumerate_devices_context_.reset();
163 }
164
165 void PepperAudioInputHost::OnOpenComplete( 137 void PepperAudioInputHost::OnOpenComplete(
166 int32_t result, 138 int32_t result,
167 base::SharedMemoryHandle shared_memory_handle, 139 base::SharedMemoryHandle shared_memory_handle,
168 size_t shared_memory_size, 140 size_t shared_memory_size,
169 base::SyncSocket::Handle socket_handle) { 141 base::SyncSocket::Handle socket_handle) {
170 // Make sure the handles are cleaned up. 142 // Make sure the handles are cleaned up.
171 base::SyncSocket scoped_socket(socket_handle); 143 base::SyncSocket scoped_socket(socket_handle);
172 base::SharedMemory scoped_shared_memory(shared_memory_handle, false); 144 base::SharedMemory scoped_shared_memory(shared_memory_handle, false);
173 145
174 if (!open_context_.get()) { 146 if (!open_context_.get()) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 audio_input_->ShutDown(); 208 audio_input_->ShutDown();
237 audio_input_ = NULL; 209 audio_input_ = NULL;
238 210
239 if (open_context_.get()) { 211 if (open_context_.get()) {
240 open_context_->params.set_result(PP_ERROR_ABORTED); 212 open_context_->params.set_result(PP_ERROR_ABORTED);
241 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply()); 213 host()->SendReply(*open_context_, PpapiPluginMsg_AudioInput_OpenReply());
242 open_context_.reset(); 214 open_context_.reset();
243 } 215 }
244 } 216 }
245 217
246 webkit::ppapi::PluginDelegate* PepperAudioInputHost::GetDelegate() const {
247 webkit::ppapi::PluginInstance* instance =
248 renderer_ppapi_host_->GetPluginInstance(pp_instance());
249 if (instance)
250 return instance->delegate();
251 return NULL;
252 }
253
254 } // namespace content 218 } // namespace content
255 219
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_audio_input_host.h ('k') | content/renderer/pepper/pepper_device_enumeration_event_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698