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

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

Issue 2393483002: Revert of VideoCapture: migrate VideoCapture renderer-->host messages to mojo, part 1 (Closed)
Patch Set: 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"
11 #include "content/browser/browser_main_loop.h" 11 #include "content/browser/browser_main_loop.h"
12 #include "content/browser/renderer_host/media/media_stream_manager.h" 12 #include "content/browser/renderer_host/media/media_stream_manager.h"
13 #include "content/browser/renderer_host/media/video_capture_manager.h" 13 #include "content/browser/renderer_host/media/video_capture_manager.h"
14 #include "content/common/media/video_capture_messages.h" 14 #include "content/common/media/video_capture_messages.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager) 18 VideoCaptureHost::VideoCaptureHost(MediaStreamManager* media_stream_manager)
19 : BrowserMessageFilter(VideoCaptureMsgStart), 19 : BrowserMessageFilter(VideoCaptureMsgStart),
20 BrowserAssociatedInterface(this, this),
21 media_stream_manager_(media_stream_manager) { 20 media_stream_manager_(media_stream_manager) {
22 DCHECK_CURRENTLY_ON(BrowserThread::UI); 21 DCHECK_CURRENTLY_ON(BrowserThread::UI);
23 } 22 }
24 23
25 VideoCaptureHost::~VideoCaptureHost() {} 24 VideoCaptureHost::~VideoCaptureHost() {}
26 25
27 void VideoCaptureHost::OnChannelClosing() { 26 void VideoCaptureHost::OnChannelClosing() {
28 // Since the IPC sender is gone, close all requested VideoCaptureDevices. 27 // Since the IPC sender is gone, close all requested VideoCaptureDevices.
29 for (auto it = controllers_.begin(); it != controllers_.end(); ) { 28 for (EntryMap::iterator it = entries_.begin(); it != entries_.end(); ) {
30 const base::WeakPtr<VideoCaptureController>& controller = it->second; 29 const base::WeakPtr<VideoCaptureController>& controller = it->second;
31 if (controller) { 30 if (controller) {
32 const VideoCaptureControllerID controller_id(it->first); 31 const VideoCaptureControllerID controller_id(it->first);
33 media_stream_manager_->video_capture_manager()->StopCaptureForClient( 32 media_stream_manager_->video_capture_manager()->StopCaptureForClient(
34 controller.get(), controller_id, this, false); 33 controller.get(), controller_id, this, false);
35 ++it; 34 ++it;
36 } else { 35 } else {
37 // Remove the entry for this controller_id so that when the controller 36 // Remove the entry for this controller_id so that when the controller
38 // is added, the controller will be notified to stop for this client 37 // is added, the controller will be notified to stop for this client
39 // in DoControllerAdded. 38 // in DoControllerAdded.
40 controllers_.erase(it++); 39 entries_.erase(it++);
41 } 40 }
42 } 41 }
43 } 42 }
44 43
45 void VideoCaptureHost::OnDestruct() const { 44 void VideoCaptureHost::OnDestruct() const {
46 BrowserThread::DeleteOnIOThread::Destruct(this); 45 BrowserThread::DeleteOnIOThread::Destruct(this);
47 } 46 }
48 47
48 ///////////////////////////////////////////////////////////////////////////////
49
50 // Implements VideoCaptureControllerEventHandler.
49 void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) { 51 void VideoCaptureHost::OnError(VideoCaptureControllerID controller_id) {
50 DVLOG(1) << "VideoCaptureHost::OnError"; 52 DVLOG(1) << "VideoCaptureHost::OnError";
51 DCHECK_CURRENTLY_ON(BrowserThread::IO); 53 DCHECK_CURRENTLY_ON(BrowserThread::IO);
52 BrowserThread::PostTask( 54 BrowserThread::PostTask(
53 BrowserThread::IO, FROM_HERE, 55 BrowserThread::IO, FROM_HERE,
54 base::Bind(&VideoCaptureHost::DoError, this, controller_id)); 56 base::Bind(&VideoCaptureHost::DoError, this, controller_id));
55 } 57 }
56 58
57 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id, 59 void VideoCaptureHost::OnBufferCreated(VideoCaptureControllerID controller_id,
58 base::SharedMemoryHandle handle, 60 base::SharedMemoryHandle handle,
59 int length, 61 int length,
60 int buffer_id) { 62 int buffer_id) {
61 DCHECK_CURRENTLY_ON(BrowserThread::IO); 63 DCHECK_CURRENTLY_ON(BrowserThread::IO);
62 if (controllers_.find(controller_id) == controllers_.end()) 64 if (entries_.find(controller_id) == entries_.end())
63 return; 65 return;
64 66
65 Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id)); 67 Send(new VideoCaptureMsg_NewBuffer(controller_id, handle, length, buffer_id));
66 } 68 }
67 69
68 void VideoCaptureHost::OnBufferCreated2( 70 void VideoCaptureHost::OnBufferCreated2(
69 VideoCaptureControllerID controller_id, 71 VideoCaptureControllerID controller_id,
70 const std::vector<gfx::GpuMemoryBufferHandle>& handles, 72 const std::vector<gfx::GpuMemoryBufferHandle>& handles,
71 const gfx::Size& size, 73 const gfx::Size& size,
72 int buffer_id) { 74 int buffer_id) {
73 DCHECK_CURRENTLY_ON(BrowserThread::IO); 75 DCHECK_CURRENTLY_ON(BrowserThread::IO);
74 if (controllers_.find(controller_id) == controllers_.end()) 76 if (entries_.find(controller_id) == entries_.end())
75 return; 77 return;
76 78
77 Send(new VideoCaptureMsg_NewBuffer2(controller_id, handles, size, buffer_id)); 79 Send(new VideoCaptureMsg_NewBuffer2(controller_id, handles, size, buffer_id));
78 } 80 }
79 81
80 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id, 82 void VideoCaptureHost::OnBufferDestroyed(VideoCaptureControllerID controller_id,
81 int buffer_id) { 83 int buffer_id) {
82 DCHECK_CURRENTLY_ON(BrowserThread::IO); 84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
83 if (controllers_.find(controller_id) == controllers_.end()) 85 if (entries_.find(controller_id) == entries_.end())
84 return; 86 return;
85 87
86 Send(new VideoCaptureMsg_FreeBuffer(controller_id, buffer_id)); 88 Send(new VideoCaptureMsg_FreeBuffer(controller_id, buffer_id));
87 } 89 }
88 90
89 void VideoCaptureHost::OnBufferReady( 91 void VideoCaptureHost::OnBufferReady(
90 VideoCaptureControllerID controller_id, 92 VideoCaptureControllerID controller_id,
91 int buffer_id, 93 int buffer_id,
92 const scoped_refptr<media::VideoFrame>& video_frame) { 94 const scoped_refptr<media::VideoFrame>& video_frame) {
93 DCHECK_CURRENTLY_ON(BrowserThread::IO); 95 DCHECK_CURRENTLY_ON(BrowserThread::IO);
94 if (controllers_.find(controller_id) == controllers_.end()) 96 if (entries_.find(controller_id) == entries_.end())
95 return; 97 return;
96 98
97 VideoCaptureMsg_BufferReady_Params params; 99 VideoCaptureMsg_BufferReady_Params params;
98 params.device_id = controller_id; 100 params.device_id = controller_id;
99 params.buffer_id = buffer_id; 101 params.buffer_id = buffer_id;
100 params.timestamp = video_frame->timestamp(); 102 params.timestamp = video_frame->timestamp();
101 video_frame->metadata()->MergeInternalValuesInto(&params.metadata); 103 video_frame->metadata()->MergeInternalValuesInto(&params.metadata);
102 params.pixel_format = video_frame->format(); 104 params.pixel_format = video_frame->format();
103 params.storage_type = video_frame->storage_type(); 105 params.storage_type = video_frame->storage_type();
104 params.coded_size = video_frame->coded_size(); 106 params.coded_size = video_frame->coded_size();
105 params.visible_rect = video_frame->visible_rect(); 107 params.visible_rect = video_frame->visible_rect();
106 108
107 Send(new VideoCaptureMsg_BufferReady(params)); 109 Send(new VideoCaptureMsg_BufferReady(params));
108 } 110 }
109 111
110 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) { 112 void VideoCaptureHost::OnEnded(VideoCaptureControllerID controller_id) {
111 DVLOG(1) << "VideoCaptureHost::OnEnded"; 113 DVLOG(1) << "VideoCaptureHost::OnEnded";
112 DCHECK_CURRENTLY_ON(BrowserThread::IO); 114 DCHECK_CURRENTLY_ON(BrowserThread::IO);
113 BrowserThread::PostTask( 115 BrowserThread::PostTask(
114 BrowserThread::IO, FROM_HERE, 116 BrowserThread::IO, FROM_HERE,
115 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id)); 117 base::Bind(&VideoCaptureHost::DoEnded, this, controller_id));
116 } 118 }
117 119
118 void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) { 120 void VideoCaptureHost::DoError(VideoCaptureControllerID controller_id) {
119 DVLOG(1) << "VideoCaptureHost::DoError"; 121 DVLOG(1) << "VideoCaptureHost::DoError";
120 DCHECK_CURRENTLY_ON(BrowserThread::IO); 122 DCHECK_CURRENTLY_ON(BrowserThread::IO);
121 if (controllers_.find(controller_id) == controllers_.end()) 123 if (entries_.find(controller_id) == entries_.end())
122 return; 124 return;
123 125
124 Send(new VideoCaptureMsg_StateChanged(controller_id, 126 Send(new VideoCaptureMsg_StateChanged(controller_id,
125 VIDEO_CAPTURE_STATE_ERROR)); 127 VIDEO_CAPTURE_STATE_ERROR));
126 DeleteVideoCaptureController(controller_id, true); 128 DeleteVideoCaptureController(controller_id, true);
127 } 129 }
128 130
129 void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) { 131 void VideoCaptureHost::DoEnded(VideoCaptureControllerID controller_id) {
130 DVLOG(1) << "VideoCaptureHost::DoEnded"; 132 DVLOG(1) << "VideoCaptureHost::DoEnded";
131 DCHECK_CURRENTLY_ON(BrowserThread::IO); 133 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132 if (controllers_.find(controller_id) == controllers_.end()) 134 if (entries_.find(controller_id) == entries_.end())
133 return; 135 return;
134 136
135 Send(new VideoCaptureMsg_StateChanged(controller_id, 137 Send(new VideoCaptureMsg_StateChanged(controller_id,
136 VIDEO_CAPTURE_STATE_ENDED)); 138 VIDEO_CAPTURE_STATE_ENDED));
137 DeleteVideoCaptureController(controller_id, false); 139 DeleteVideoCaptureController(controller_id, false);
138 } 140 }
139 141
140 /////////////////////////////////////////////////////////////////////////////// 142 ///////////////////////////////////////////////////////////////////////////////
141 // IPC Messages handler. 143 // IPC Messages handler.
142 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message) { 144 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message) {
143 bool handled = true; 145 bool handled = true;
144 IPC_BEGIN_MESSAGE_MAP(VideoCaptureHost, message) 146 IPC_BEGIN_MESSAGE_MAP(VideoCaptureHost, message)
145 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) 147 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture)
148 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture)
146 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Resume, OnResumeCapture) 149 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Resume, OnResumeCapture)
150 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_RequestRefreshFrame,
151 OnRequestRefreshFrame)
152 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture)
147 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, 153 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady,
148 OnRendererFinishedWithBuffer) 154 OnRendererFinishedWithBuffer)
149 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats, 155 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceSupportedFormats,
150 OnGetDeviceSupportedFormats) 156 OnGetDeviceSupportedFormats)
151 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse, 157 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_GetDeviceFormatsInUse,
152 OnGetDeviceFormatsInUse) 158 OnGetDeviceFormatsInUse)
153 IPC_MESSAGE_UNHANDLED(handled = false) 159 IPC_MESSAGE_UNHANDLED(handled = false)
154 IPC_END_MESSAGE_MAP() 160 IPC_END_MESSAGE_MAP()
155 161
156 return handled; 162 return handled;
157 } 163 }
158 164
159 void VideoCaptureHost::OnStartCapture(int device_id, 165 void VideoCaptureHost::OnStartCapture(int device_id,
160 media::VideoCaptureSessionId session_id, 166 media::VideoCaptureSessionId session_id,
161 const media::VideoCaptureParams& params) { 167 const media::VideoCaptureParams& params) {
162 DCHECK_CURRENTLY_ON(BrowserThread::IO); 168 DCHECK_CURRENTLY_ON(BrowserThread::IO);
163 DVLOG(1) << "VideoCaptureHost::OnStartCapture:" 169 DVLOG(1) << "VideoCaptureHost::OnStartCapture:"
164 << " session_id=" << session_id << ", device_id=" << device_id 170 << " session_id=" << session_id << ", device_id=" << device_id
165 << ", format=" 171 << ", format="
166 << media::VideoCaptureFormat::ToString(params.requested_format) 172 << media::VideoCaptureFormat::ToString(params.requested_format)
167 << "@" << params.requested_format.frame_rate << " (" 173 << "@" << params.requested_format.frame_rate << " ("
168 << (params.resolution_change_policy == 174 << (params.resolution_change_policy ==
169 media::RESOLUTION_POLICY_FIXED_RESOLUTION 175 media::RESOLUTION_POLICY_FIXED_RESOLUTION
170 ? "fixed resolution" 176 ? "fixed resolution"
171 : (params.resolution_change_policy == 177 : (params.resolution_change_policy ==
172 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO 178 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO
173 ? "fixed aspect ratio" 179 ? "fixed aspect ratio"
174 : "variable resolution")) << ")"; 180 : "variable resolution")) << ")";
175 VideoCaptureControllerID controller_id(device_id); 181 VideoCaptureControllerID controller_id(device_id);
176 if (controllers_.find(controller_id) != controllers_.end()) { 182 if (entries_.find(controller_id) != entries_.end()) {
177 Send(new VideoCaptureMsg_StateChanged(device_id, 183 Send(new VideoCaptureMsg_StateChanged(device_id,
178 VIDEO_CAPTURE_STATE_ERROR)); 184 VIDEO_CAPTURE_STATE_ERROR));
179 return; 185 return;
180 } 186 }
181 187
182 controllers_[controller_id] = base::WeakPtr<VideoCaptureController>(); 188 entries_[controller_id] = base::WeakPtr<VideoCaptureController>();
183 media_stream_manager_->video_capture_manager()->StartCaptureForClient( 189 media_stream_manager_->video_capture_manager()->StartCaptureForClient(
184 session_id, 190 session_id,
185 params, 191 params,
186 PeerHandle(), 192 PeerHandle(),
187 controller_id, 193 controller_id,
188 this, 194 this,
189 base::Bind(&VideoCaptureHost::OnControllerAdded, this, device_id)); 195 base::Bind(&VideoCaptureHost::OnControllerAdded, this, device_id));
190 } 196 }
191 197
198 void VideoCaptureHost::OnControllerAdded(
199 int device_id,
200 const base::WeakPtr<VideoCaptureController>& controller) {
201 DCHECK_CURRENTLY_ON(BrowserThread::IO);
202 VideoCaptureControllerID controller_id(device_id);
203 EntryMap::iterator it = entries_.find(controller_id);
204 if (it == entries_.end()) {
205 if (controller) {
206 media_stream_manager_->video_capture_manager()->StopCaptureForClient(
207 controller.get(), controller_id, this, false);
208 }
209 return;
210 }
211
212 if (!controller) {
213 Send(new VideoCaptureMsg_StateChanged(device_id,
214 VIDEO_CAPTURE_STATE_ERROR));
215 entries_.erase(controller_id);
216 return;
217 }
218
219 DCHECK(!it->second);
220 it->second = controller;
221 }
222
223 void VideoCaptureHost::OnStopCapture(int device_id) {
224 DCHECK_CURRENTLY_ON(BrowserThread::IO);
225 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id;
226
227 VideoCaptureControllerID controller_id(device_id);
228
229 Send(new VideoCaptureMsg_StateChanged(device_id,
230 VIDEO_CAPTURE_STATE_STOPPED));
231 DeleteVideoCaptureController(controller_id, false);
232 }
233
234 void VideoCaptureHost::OnPauseCapture(int device_id) {
235 DCHECK_CURRENTLY_ON(BrowserThread::IO);
236 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id;
237
238 VideoCaptureControllerID controller_id(device_id);
239 EntryMap::iterator it = entries_.find(controller_id);
240 if (it == entries_.end() || !it->second)
241 return;
242
243 media_stream_manager_->video_capture_manager()->PauseCaptureForClient(
244 it->second.get(), controller_id, this);
245 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED));
246 }
247
192 void VideoCaptureHost::OnResumeCapture( 248 void VideoCaptureHost::OnResumeCapture(
193 int device_id, 249 int device_id,
194 media::VideoCaptureSessionId session_id, 250 media::VideoCaptureSessionId session_id,
195 const media::VideoCaptureParams& params) { 251 const media::VideoCaptureParams& params) {
196 DVLOG(1) << __func__ << " " << device_id;
197 DCHECK_CURRENTLY_ON(BrowserThread::IO); 252 DCHECK_CURRENTLY_ON(BrowserThread::IO);
253 DVLOG(1) << "VideoCaptureHost::OnResumeCapture, device_id " << device_id;
198 254
199 VideoCaptureControllerID controller_id(device_id); 255 VideoCaptureControllerID controller_id(device_id);
200 auto it = controllers_.find(controller_id); 256 EntryMap::iterator it = entries_.find(controller_id);
201 if (it == controllers_.end() || !it->second) 257 if (it == entries_.end() || !it->second)
202 return; 258 return;
203 259
204 media_stream_manager_->video_capture_manager()->ResumeCaptureForClient( 260 media_stream_manager_->video_capture_manager()->ResumeCaptureForClient(
205 session_id, params, it->second.get(), controller_id, this); 261 session_id, params, it->second.get(), controller_id, this);
206 Send(new VideoCaptureMsg_StateChanged(device_id, 262 Send(new VideoCaptureMsg_StateChanged(device_id,
207 VIDEO_CAPTURE_STATE_RESUMED)); 263 VIDEO_CAPTURE_STATE_RESUMED));
208 } 264 }
209 265
266 void VideoCaptureHost::OnRequestRefreshFrame(int device_id) {
267 DCHECK_CURRENTLY_ON(BrowserThread::IO);
268 DVLOG(1) << "VideoCaptureHost::OnRequestRefreshFrame, device_id "
269 << device_id;
270
271 VideoCaptureControllerID controller_id(device_id);
272 EntryMap::iterator it = entries_.find(controller_id);
273 if (it == entries_.end())
274 return;
275
276 if (VideoCaptureController* controller = it->second.get()) {
277 media_stream_manager_->video_capture_manager()
278 ->RequestRefreshFrameForClient(controller);
279 }
280 }
281
210 void VideoCaptureHost::OnRendererFinishedWithBuffer( 282 void VideoCaptureHost::OnRendererFinishedWithBuffer(
211 int device_id, 283 int device_id,
212 int buffer_id, 284 int buffer_id,
213 const gpu::SyncToken& sync_token, 285 const gpu::SyncToken& sync_token,
214 double consumer_resource_utilization) { 286 double consumer_resource_utilization) {
215 DCHECK_CURRENTLY_ON(BrowserThread::IO); 287 DCHECK_CURRENTLY_ON(BrowserThread::IO);
216 288
217 VideoCaptureControllerID controller_id(device_id); 289 VideoCaptureControllerID controller_id(device_id);
218 auto it = controllers_.find(controller_id); 290 EntryMap::iterator it = entries_.find(controller_id);
219 if (it != controllers_.end()) { 291 if (it != entries_.end()) {
220 const base::WeakPtr<VideoCaptureController>& controller = it->second; 292 const base::WeakPtr<VideoCaptureController>& controller = it->second;
221 if (controller) { 293 if (controller) {
222 controller->ReturnBuffer(controller_id, this, buffer_id, sync_token, 294 controller->ReturnBuffer(controller_id, this, buffer_id, sync_token,
223 consumer_resource_utilization); 295 consumer_resource_utilization);
224 } 296 }
225 } 297 }
226 } 298 }
227 299
228 void VideoCaptureHost::OnGetDeviceSupportedFormats( 300 void VideoCaptureHost::OnGetDeviceSupportedFormats(
229 int device_id, 301 int device_id,
230 media::VideoCaptureSessionId session_id) { 302 media::VideoCaptureSessionId capture_session_id) {
231 DVLOG(1) << __func__ << " " << device_id;
232 DCHECK_CURRENTLY_ON(BrowserThread::IO); 303 DCHECK_CURRENTLY_ON(BrowserThread::IO);
304 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormats, capture_session_id "
305 << capture_session_id;
233 media::VideoCaptureFormats device_supported_formats; 306 media::VideoCaptureFormats device_supported_formats;
234 if (!media_stream_manager_->video_capture_manager() 307 if (!media_stream_manager_->video_capture_manager()
235 ->GetDeviceSupportedFormats(session_id, 308 ->GetDeviceSupportedFormats(capture_session_id,
236 &device_supported_formats)) { 309 &device_supported_formats)) {
237 DLOG(WARNING) 310 DLOG(WARNING)
238 << "Could not retrieve device supported formats for device_id=" 311 << "Could not retrieve device supported formats for device_id="
239 << device_id << " session_id=" << session_id; 312 << device_id << " capture_session_id=" << capture_session_id;
240 } 313 }
241 Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated( 314 Send(new VideoCaptureMsg_DeviceSupportedFormatsEnumerated(
242 device_id, device_supported_formats)); 315 device_id, device_supported_formats));
243 } 316 }
244 317
245 void VideoCaptureHost::OnGetDeviceFormatsInUse( 318 void VideoCaptureHost::OnGetDeviceFormatsInUse(
246 int device_id, 319 int device_id,
247 media::VideoCaptureSessionId session_id) { 320 media::VideoCaptureSessionId capture_session_id) {
248 DVLOG(1) << __func__ << " " << device_id;
249 DCHECK_CURRENTLY_ON(BrowserThread::IO); 321 DCHECK_CURRENTLY_ON(BrowserThread::IO);
322 DVLOG(1) << "VideoCaptureHost::OnGetDeviceFormatsInUse, capture_session_id "
323 << capture_session_id;
250 media::VideoCaptureFormats formats_in_use; 324 media::VideoCaptureFormats formats_in_use;
251 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse( 325 if (!media_stream_manager_->video_capture_manager()->GetDeviceFormatsInUse(
252 session_id, &formats_in_use)) { 326 capture_session_id, &formats_in_use)) {
253 DVLOG(1) << "Could not retrieve device format(s) in use for device_id=" 327 DVLOG(1) << "Could not retrieve device format(s) in use for device_id="
254 << device_id << " session_id=" << session_id; 328 << device_id << " capture_session_id=" << capture_session_id;
255 } 329 }
256 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id, 330 Send(new VideoCaptureMsg_DeviceFormatsInUseReceived(device_id,
257 formats_in_use)); 331 formats_in_use));
258 } 332 }
259 333
260 void VideoCaptureHost::StopCapture(int32_t device_id) {
261 DVLOG(1) << __func__ << " " << device_id;
262 DCHECK_CURRENTLY_ON(BrowserThread::IO);
263
264 VideoCaptureControllerID controller_id(device_id);
265
266 Send(new VideoCaptureMsg_StateChanged(device_id,
267 VIDEO_CAPTURE_STATE_STOPPED));
268 DeleteVideoCaptureController(controller_id, false);
269 }
270
271 void VideoCaptureHost::PauseCapture(int32_t device_id) {
272 DVLOG(1) << __func__ << " " << device_id;
273 DCHECK_CURRENTLY_ON(BrowserThread::IO);
274
275 VideoCaptureControllerID controller_id(device_id);
276 auto it = controllers_.find(controller_id);
277 if (it == controllers_.end() || !it->second)
278 return;
279
280 media_stream_manager_->video_capture_manager()->PauseCaptureForClient(
281 it->second.get(), controller_id, this);
282 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_PAUSED));
283 }
284
285 void VideoCaptureHost::RequestRefreshFrame(int32_t device_id) {
286 DVLOG(1) << __func__ << " " << device_id;
287 DCHECK_CURRENTLY_ON(BrowserThread::IO);
288
289 VideoCaptureControllerID controller_id(device_id);
290 auto it = controllers_.find(controller_id);
291 if (it == controllers_.end())
292 return;
293
294 if (VideoCaptureController* controller = it->second.get()) {
295 media_stream_manager_->video_capture_manager()
296 ->RequestRefreshFrameForClient(controller);
297 }
298 }
299
300 void VideoCaptureHost::OnControllerAdded(
301 int device_id,
302 const base::WeakPtr<VideoCaptureController>& controller) {
303 DCHECK_CURRENTLY_ON(BrowserThread::IO);
304 VideoCaptureControllerID controller_id(device_id);
305 auto it = controllers_.find(controller_id);
306 if (it == controllers_.end()) {
307 if (controller) {
308 media_stream_manager_->video_capture_manager()->StopCaptureForClient(
309 controller.get(), controller_id, this, false);
310 }
311 return;
312 }
313
314 if (!controller) {
315 Send(new VideoCaptureMsg_StateChanged(device_id,
316 VIDEO_CAPTURE_STATE_ERROR));
317 controllers_.erase(controller_id);
318 return;
319 }
320
321 DCHECK(!it->second);
322 it->second = controller;
323 }
324
325 void VideoCaptureHost::DeleteVideoCaptureController( 334 void VideoCaptureHost::DeleteVideoCaptureController(
326 VideoCaptureControllerID controller_id, bool on_error) { 335 VideoCaptureControllerID controller_id, bool on_error) {
327 DCHECK_CURRENTLY_ON(BrowserThread::IO); 336 DCHECK_CURRENTLY_ON(BrowserThread::IO);
328 337
329 auto it = controllers_.find(controller_id); 338 EntryMap::iterator it = entries_.find(controller_id);
330 if (it == controllers_.end()) 339 if (it == entries_.end())
331 return; 340 return;
332 341
333 if (it->second) { 342 if (it->second) {
334 media_stream_manager_->video_capture_manager()->StopCaptureForClient( 343 media_stream_manager_->video_capture_manager()->StopCaptureForClient(
335 it->second.get(), controller_id, this, on_error); 344 it->second.get(), controller_id, this, on_error);
336 } 345 }
337 controllers_.erase(it); 346 entries_.erase(it);
338 } 347 }
339 348
340 } // namespace content 349 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698