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

Side by Side Diff: content/browser/renderer_host/media/video_capture_host.cc

Issue 2395163002: VideoCapture: migrate VideoCapture renderer-->host messages to mojo, part 2 (Closed)
Patch Set: rockot@s comments on renaming and return types Created 4 years, 2 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
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/browser/renderer_host/media/video_capture_host.h" 5 #include "content/browser/renderer_host/media/video_capture_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 29 matching lines...) Expand all
40 controllers_.erase(it++); 40 controllers_.erase(it++);
41 } 41 }
42 } 42 }
43 } 43 }
44 44
45 void VideoCaptureHost::OnDestruct() const { 45 void VideoCaptureHost::OnDestruct() const {
46 BrowserThread::DeleteOnIOThread::Destruct(this); 46 BrowserThread::DeleteOnIOThread::Destruct(this);
47 } 47 }
48 48
49 void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) { 49 void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) {
50 DVLOG(1) << "VideoCaptureHost::OnError"; 50 DVLOG(1) << __func__;
51 DCHECK_CURRENTLY_ON(BrowserThread::IO); 51 DCHECK_CURRENTLY_ON(BrowserThread::IO);
52 BrowserThread::PostTask( 52 BrowserThread::PostTask(
53 BrowserThread::IO, FROM_HERE, 53 BrowserThread::IO, FROM_HERE,
54 base::Bind(&VideoCaptureHost::DoError, this, controller_id)); 54 base::Bind(&VideoCaptureHost::DoError, this, controller_id));
55 } 55 }
56 56
57 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id, 57 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id,
58 base::SharedMemoryHandle handle, 58 base::SharedMemoryHandle handle,
59 int length, 59 int length,
60 int buffer_id) { 60 int buffer_id) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 Send(new VideoCaptureMsg_StateChanged(controller_id, 135 Send(new VideoCaptureMsg_StateChanged(controller_id,
136 VIDEO_CAPTURE_STATE_ENDED)); 136 VIDEO_CAPTURE_STATE_ENDED));
137 DeleteVideoCaptureController(controller_id, false); 137 DeleteVideoCaptureController(controller_id, false);
138 } 138 }
139 139
140 /////////////////////////////////////////////////////////////////////////////// 140 ///////////////////////////////////////////////////////////////////////////////
141 // IPC Messages handler. 141 // IPC Messages handler.
142 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message) { 142 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message) {
143 bool handled = true; 143 bool handled = true;
144 IPC_BEGIN_MESSAGE_MAP(VideoCaptureHost, message) 144 IPC_BEGIN_MESSAGE_MAP(VideoCaptureHost, message)
145 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture)
146 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Resume, OnResumeCapture)
147 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, 145 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady,
148 OnRendererFinishedWithBuffer) 146 OnRendererFinishedWithBuffer)
149 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, 147 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats,
150 OnGetDeviceSupportedFormats) 148 OnGetDeviceSupportedFormats)
151 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse, 149 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse,
152 OnGetDeviceFormatsInUse) 150 OnGetDeviceFormatsInUse)
153 IPC_MESSAGE_UNHANDLED(handled = false) 151 IPC_MESSAGE_UNHANDLED(handled = false)
154 IPC_END_MESSAGE_MAP() 152 IPC_END_MESSAGE_MAP()
155 153
156 return handled; 154 return handled;
157 } 155 }
158 156
159 void VideoCaptureHost::OnStartCapture(int device_id,
160 media::VideoCaptureSessionId session_id,
161 const media::VideoCaptureParams& params) {
162 DCHECK_CURRENTLY_ON(BrowserThread::IO);
163 DVLOG(1) << "VideoCaptureHost::OnStartCapture:"
164 << " session_id=" << session_id << ", device_id=" << device_id
165 << ", format="
166 << media::VideoCaptureFormat::ToString(params.requested_format)
167 << "@" << params.requested_format.frame_rate << " ("
168 << (params.resolution_change_policy ==
169 media::RESOLUTION_POLICY_FIXED_RESOLUTION
170 ? "fixed resolution"
171 : (params.resolution_change_policy ==
172 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO
173 ? "fixed aspect ratio"
174 : "variable resolution")) << ")";
175 VideoCaptureControllerID controller_id(device_id);
176 if (controllers_.find(controller_id) != controllers_.end()) {
177 Send(new VideoCaptureMsg_StateChanged(device_id,
178 VIDEO_CAPTURE_STATE_ERROR));
179 return;
180 }
181
182 controllers_[controller_id] = base::WeakPtr<VideoCaptureController>();
183 media_stream_manager_->video_capture_manager()->StartCaptureForClient(
184 session_id,
185 params,
186 PeerHandle(),
187 controller_id,
188 this,
189 base::Bind(&VideoCaptureHost::OnControllerAdded, this, device_id));
190 }
191
192 void VideoCaptureHost::OnResumeCapture(
193 int device_id,
194 media::VideoCaptureSessionId session_id,
195 const media::VideoCaptureParams& params) {
196 DVLOG(1) << __func__ << " " << device_id;
197 DCHECK_CURRENTLY_ON(BrowserThread::IO);
198
199 VideoCaptureControllerID controller_id(device_id);
200 auto it = controllers_.find(controller_id);
201 if (it == controllers_.end() || !it->second)
202 return;
203
204 media_stream_manager_->video_capture_manager()->ResumeCaptureForClient(
205 session_id, params, it->second.get(), controller_id, this);
206 Send(new VideoCaptureMsg_StateChanged(device_id,
207 VIDEO_CAPTURE_STATE_RESUMED));
208 }
209
210 void VideoCaptureHost::OnRendererFinishedWithBuffer( 157 void VideoCaptureHost::OnRendererFinishedWithBuffer(
211 int device_id, 158 int device_id,
212 int buffer_id, 159 int buffer_id,
213 const gpu::SyncToken& sync_token, 160 const gpu::SyncToken& sync_token,
214 double consumer_resource_utilization) { 161 double consumer_resource_utilization) {
215 DCHECK_CURRENTLY_ON(BrowserThread::IO); 162 DCHECK_CURRENTLY_ON(BrowserThread::IO);
216 163
217 VideoCaptureControllerID controller_id(device_id); 164 VideoCaptureControllerID controller_id(device_id);
218 auto it = controllers_.find(controller_id); 165 auto it = controllers_.find(controller_id);
219 if (it != controllers_.end()) { 166 if (it != controllers_.end()) {
(...skipping 30 matching lines...) Expand all
250 media::VideoCaptureFormats formats_in_use; 197 media::VideoCaptureFormats formats_in_use;
251 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( 198 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse(
252 session_id, &formats_in_use)) { 199 session_id, &formats_in_use)) {
253 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" 200 DVLOG(1) << "Could not retrieve device format(s) in use for device_id="
254 << device_id << " session_id=" << session_id; 201 << device_id << " session_id=" << session_id;
255 } 202 }
256 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, 203 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id,
257 formats_in_use)); 204 formats_in_use));
258 } 205 }
259 206
207 void VideoCaptureHost::Start(int32_t device_id,
208 int32_t session_id,
209 const media::VideoCaptureParams& params) {
210 DVLOG(1) << __func__ << " session_id=" << session_id
211 << ", device_id=" << device_id << ", format="
212 << media::VideoCaptureFormat::ToString(params.requested_format);
213 DCHECK_CURRENTLY_ON(BrowserThread::IO);
214 const VideoCaptureControllerID controller_id(device_id);
215 if (controllers_.find(controller_id) != controllers_.end()) {
216 Send(new VideoCaptureMsg_StateChanged(device_id,
217 VIDEO_CAPTURE_STATE_ERROR));
218 return;
219 }
220
221 controllers_[controller_id] = base::WeakPtr<VideoCaptureController>();
222 media_stream_manager_->video_capture_manager()->StartCaptureForClient(
223 session_id,
224 params,
225 PeerHandle(),
226 controller_id,
227 this,
228 base::Bind(&VideoCaptureHost::OnControllerAdded, this, device_id));
229 }
230
260 void VideoCaptureHost::Stop(int32_t device_id) { 231 void VideoCaptureHost::Stop(int32_t device_id) {
261 DVLOG(1) << __func__ << " " << device_id; 232 DVLOG(1) << __func__ << " " << device_id;
262 DCHECK_CURRENTLY_ON(BrowserThread::IO); 233 DCHECK_CURRENTLY_ON(BrowserThread::IO);
263 234
264 VideoCaptureControllerID controller_id(device_id); 235 VideoCaptureControllerID controller_id(device_id);
265 236
266 Send(new VideoCaptureMsg_StateChanged(device_id, 237 Send(new VideoCaptureMsg_StateChanged(device_id,
267 VIDEO_CAPTURE_STATE_STOPPED)); 238 VIDEO_CAPTURE_STATE_STOPPED));
268 DeleteVideoCaptureController(controller_id, false); 239 DeleteVideoCaptureController(controller_id, false);
269 } 240 }
270 241
271 void VideoCaptureHost::Pause(int32_t device_id) { 242 void VideoCaptureHost::Pause(int32_t device_id) {
272 DVLOG(1) << __func__ << " " << device_id; 243 DVLOG(1) << __func__ << " " << device_id;
273 DCHECK_CURRENTLY_ON(BrowserThread::IO); 244 DCHECK_CURRENTLY_ON(BrowserThread::IO);
274 245
275 VideoCaptureControllerID controller_id(device_id); 246 VideoCaptureControllerID controller_id(device_id);
276 auto it = controllers_.find(controller_id); 247 auto it = controllers_.find(controller_id);
277 if (it == controllers_.end() || !it->second) 248 if (it == controllers_.end() || !it->second)
278 return; 249 return;
279 250
280 media_stream_manager_->video_capture_manager()->PauseCaptureForClient( 251 media_stream_manager_->video_capture_manager()->PauseCaptureForClient(
281 it->second.get(), controller_id, this); 252 it->second.get(), controller_id, this);
282 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED)); 253 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED));
283 } 254 }
284 255
256 void VideoCaptureHost::Resume(int32_t device_id,
257 int32_t session_id,
258 const media::VideoCaptureParams& params) {
259 DVLOG(1) << __func__ << " " << device_id;
260 DCHECK_CURRENTLY_ON(BrowserThread::IO);
261
262 VideoCaptureControllerID controller_id(device_id);
263 auto it = controllers_.find(controller_id);
264 if (it == controllers_.end() || !it->second)
265 return;
266
267 media_stream_manager_->video_capture_manager()->ResumeCaptureForClient(
268 session_id, params, it->second.get(), controller_id, this);
269 Send(new VideoCaptureMsg_StateChanged(device_id,
270 VIDEO_CAPTURE_STATE_RESUMED));
271 }
272
285 void VideoCaptureHost::RequestRefreshFrame(int32_t device_id) { 273 void VideoCaptureHost::RequestRefreshFrame(int32_t device_id) {
286 DVLOG(1) << __func__ << " " << device_id; 274 DVLOG(1) << __func__ << " " << device_id;
287 DCHECK_CURRENTLY_ON(BrowserThread::IO); 275 DCHECK_CURRENTLY_ON(BrowserThread::IO);
288 276
289 VideoCaptureControllerID controller_id(device_id); 277 VideoCaptureControllerID controller_id(device_id);
290 auto it = controllers_.find(controller_id); 278 auto it = controllers_.find(controller_id);
291 if (it == controllers_.end()) 279 if (it == controllers_.end())
292 return; 280 return;
293 281
294 if (VideoCaptureController* controller = it->second.get()) { 282 if (VideoCaptureController* controller = it->second.get()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 return; 319 return;
332 320
333 if (it->second) { 321 if (it->second) {
334 media_stream_manager_->video_capture_manager()->StopCaptureForClient( 322 media_stream_manager_->video_capture_manager()->StopCaptureForClient(
335 it->second.get(), controller_id, this, on_error); 323 it->second.get(), controller_id, this, on_error);
336 } 324 }
337 controllers_.erase(it); 325 controllers_.erase(it);
338 } 326 }
339 327
340 } // namespace content 328 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698