OLD | NEW |
---|---|
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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "content/browser/browser_main_loop.h" | 10 #include "content/browser/browser_main_loop.h" |
11 #include "content/browser/renderer_host/media/media_stream_manager.h" | 11 #include "content/browser/renderer_host/media/media_stream_manager.h" |
12 #include "content/browser/renderer_host/media/video_capture_manager.h" | 12 #include "content/browser/renderer_host/media/video_capture_manager.h" |
13 #include "content/common/media/encoded_video_capture_messages.h" | |
13 #include "content/common/media/video_capture_messages.h" | 14 #include "content/common/media/video_capture_messages.h" |
15 #include "media/video/video_encode_types.h" | |
14 | 16 |
15 namespace content { | 17 namespace content { |
16 | 18 |
17 struct VideoCaptureHost::Entry { | 19 struct VideoCaptureHost::Entry { |
18 Entry(VideoCaptureController* controller) | 20 Entry(VideoCaptureController* controller) |
19 : controller(controller) {} | 21 : controller(controller), |
22 encoded(false) {} | |
20 | 23 |
21 ~Entry() {} | 24 ~Entry() {} |
22 | 25 |
23 scoped_refptr<VideoCaptureController> controller; | 26 scoped_refptr<VideoCaptureController> controller; |
27 bool encoded; | |
24 }; | 28 }; |
25 | 29 |
26 VideoCaptureHost::VideoCaptureHost() {} | 30 VideoCaptureHost::VideoCaptureHost() {} |
27 | 31 |
28 VideoCaptureHost::~VideoCaptureHost() {} | 32 VideoCaptureHost::~VideoCaptureHost() {} |
29 | 33 |
30 void VideoCaptureHost::OnChannelClosing() { | 34 void VideoCaptureHost::OnChannelClosing() { |
31 BrowserMessageFilter::OnChannelClosing(); | 35 BrowserMessageFilter::OnChannelClosing(); |
32 | 36 |
33 // Since the IPC channel is gone, close all requested VideCaptureDevices. | 37 // Since the IPC channel is gone, close all requested VideCaptureDevices. |
(...skipping 16 matching lines...) Expand all Loading... | |
50 | 54 |
51 // Implements VideoCaptureControllerEventHandler. | 55 // Implements VideoCaptureControllerEventHandler. |
52 void VideoCaptureHost::OnError(const VideoCaptureControllerID& controller_id) { | 56 void VideoCaptureHost::OnError(const VideoCaptureControllerID& controller_id) { |
53 DVLOG(1) << "VideoCaptureHost::OnError"; | 57 DVLOG(1) << "VideoCaptureHost::OnError"; |
54 BrowserThread::PostTask( | 58 BrowserThread::PostTask( |
55 BrowserThread::IO, FROM_HERE, | 59 BrowserThread::IO, FROM_HERE, |
56 base::Bind(&VideoCaptureHost::DoHandleErrorOnIOThread, | 60 base::Bind(&VideoCaptureHost::DoHandleErrorOnIOThread, |
57 this, controller_id)); | 61 this, controller_id)); |
58 } | 62 } |
59 | 63 |
60 void VideoCaptureHost::OnBufferCreated( | |
61 const VideoCaptureControllerID& controller_id, | |
62 base::SharedMemoryHandle handle, | |
63 int length, | |
64 int buffer_id) { | |
65 BrowserThread::PostTask( | |
66 BrowserThread::IO, FROM_HERE, | |
67 base::Bind(&VideoCaptureHost::DoSendNewBufferOnIOThread, | |
68 this, controller_id, handle, length, buffer_id)); | |
69 } | |
70 | |
71 void VideoCaptureHost::OnBufferReady( | 64 void VideoCaptureHost::OnBufferReady( |
72 const VideoCaptureControllerID& controller_id, | 65 const VideoCaptureControllerID& controller_id, |
73 int buffer_id, | 66 int buffer_id, |
74 base::Time timestamp) { | 67 size_t data_size, |
68 base::Time timestamp, | |
69 bool key_frame) { | |
75 BrowserThread::PostTask( | 70 BrowserThread::PostTask( |
76 BrowserThread::IO, FROM_HERE, | 71 BrowserThread::IO, FROM_HERE, |
77 base::Bind(&VideoCaptureHost::DoSendFilledBufferOnIOThread, | 72 base::Bind(&VideoCaptureHost::DoSendFilledBufferOnIOThread, |
78 this, controller_id, buffer_id, timestamp)); | 73 this, controller_id, buffer_id, data_size, timestamp, |
74 key_frame)); | |
79 } | 75 } |
80 | 76 |
81 void VideoCaptureHost::OnFrameInfo( | 77 void VideoCaptureHost::OnFrameInfo( |
82 const VideoCaptureControllerID& controller_id, | 78 const VideoCaptureControllerID& controller_id, |
83 int width, | 79 const media::VideoCaptureParams& params, |
84 int height, | 80 const std::vector<base::SharedMemoryHandle>& buffers, |
85 int frame_per_second) { | 81 size_t buffer_size) { |
86 BrowserThread::PostTask( | 82 BrowserThread::PostTask( |
87 BrowserThread::IO, FROM_HERE, | 83 BrowserThread::IO, FROM_HERE, |
88 base::Bind(&VideoCaptureHost::DoSendFrameInfoOnIOThread, | 84 base::Bind(&VideoCaptureHost::DoSendFrameInfoOnIOThread, |
89 this, controller_id, width, height, frame_per_second)); | 85 this, |
86 controller_id, | |
87 params, | |
88 buffers, | |
89 buffer_size)); | |
90 } | |
91 | |
92 void VideoCaptureHost::OnEncodedFrameInfo( | |
93 const VideoCaptureControllerID& controller_id, | |
94 const media::VideoEncodingParameters& params, | |
95 const std::vector<base::SharedMemoryHandle>& buffers, | |
96 size_t buffer_size) { | |
97 BrowserThread::PostTask( | |
98 BrowserThread::IO, FROM_HERE, | |
99 base::Bind(&VideoCaptureHost::DoSendEncodedFrameInfoOnIOThread, | |
100 this, | |
101 controller_id, | |
102 params, | |
103 buffers, | |
104 buffer_size)); | |
105 } | |
106 | |
107 void VideoCaptureHost::OnBitstreamConfigChanged( | |
108 const VideoCaptureControllerID& controller_id, | |
109 const media::RuntimeVideoEncodingParameters& params) { | |
110 BrowserThread::PostTask( | |
111 BrowserThread::IO, FROM_HERE, | |
112 base::Bind(&VideoCaptureHost::DoBitstreamConfigChangedOnIOThread, | |
113 this, | |
114 controller_id, | |
115 params)); | |
90 } | 116 } |
91 | 117 |
92 void VideoCaptureHost::OnEnded(const VideoCaptureControllerID& controller_id) { | 118 void VideoCaptureHost::OnEnded(const VideoCaptureControllerID& controller_id) { |
93 DVLOG(1) << "VideoCaptureHost::OnEnded"; | 119 DVLOG(1) << "VideoCaptureHost::OnEnded"; |
94 BrowserThread::PostTask( | 120 BrowserThread::PostTask( |
95 BrowserThread::IO, FROM_HERE, | 121 BrowserThread::IO, FROM_HERE, |
96 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); | 122 base::Bind(&VideoCaptureHost::DoEndedOnIOThread, this, controller_id)); |
97 } | 123 } |
98 | 124 |
99 void VideoCaptureHost::DoSendNewBufferOnIOThread( | |
100 const VideoCaptureControllerID& controller_id, | |
101 base::SharedMemoryHandle handle, | |
102 int length, | |
103 int buffer_id) { | |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
105 | |
106 if (entries_.find(controller_id) == entries_.end()) | |
107 return; | |
108 | |
109 Send(new VideoCaptureMsg_NewBuffer(controller_id.device_id, handle, | |
110 length, buffer_id)); | |
111 } | |
112 | |
113 void VideoCaptureHost::DoSendFilledBufferOnIOThread( | 125 void VideoCaptureHost::DoSendFilledBufferOnIOThread( |
114 const VideoCaptureControllerID& controller_id, | 126 const VideoCaptureControllerID& controller_id, |
115 int buffer_id, base::Time timestamp) { | 127 int buffer_id, size_t size, base::Time timestamp, bool key_frame) { |
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
117 | 129 |
118 if (entries_.find(controller_id) == entries_.end()) | 130 EntryMap::iterator iter = entries_.find(controller_id); |
131 if (iter == entries_.end()) | |
119 return; | 132 return; |
120 | 133 |
121 Send(new VideoCaptureMsg_BufferReady(controller_id.device_id, buffer_id, | 134 if (iter->second->encoded) { |
122 timestamp)); | 135 media::BufferEncodingMetadata metadata; |
136 metadata.timestamp = timestamp; | |
137 metadata.key_frame = key_frame; | |
138 Send(new EncodedVideoCaptureMsg_BitstreamReady(controller_id.device_id, | |
139 buffer_id, | |
140 size, | |
141 metadata)); | |
142 } else { | |
143 Send(new VideoCaptureMsg_BufferReady(controller_id.device_id, buffer_id, | |
144 timestamp)); | |
145 } | |
123 } | 146 } |
124 | 147 |
125 void VideoCaptureHost::DoHandleErrorOnIOThread( | 148 void VideoCaptureHost::DoHandleErrorOnIOThread( |
126 const VideoCaptureControllerID& controller_id) { | 149 const VideoCaptureControllerID& controller_id) { |
127 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 150 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
128 | 151 |
129 if (entries_.find(controller_id) == entries_.end()) | 152 EntryMap::iterator iter = entries_.find(controller_id); |
153 if (iter == entries_.end()) | |
130 return; | 154 return; |
131 | 155 |
156 if (iter->second->encoded) { | |
157 Send(new EncodedVideoCaptureHostMsg_DestroyBitstream( | |
158 controller_id.device_id)); | |
hshi1
2013/06/20 22:51:02
How can browser send EncodedVideoCaptureHostMsg to
sheu
2013/08/22 22:40:31
Done.
| |
159 } else { | |
160 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | |
161 VIDEO_CAPTURE_STATE_ERROR)); | |
162 } | |
163 DeleteVideoCaptureControllerOnIOThread(controller_id); | |
164 } | |
165 | |
166 void VideoCaptureHost::DoSendFrameInfoOnIOThread( | |
167 const VideoCaptureControllerID& controller_id, | |
168 const media::VideoCaptureParams& params, | |
169 const std::vector<base::SharedMemoryHandle>& buffers, | |
170 size_t buffer_size) { | |
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
172 | |
173 EntryMap::iterator iter = entries_.find(controller_id); | |
174 if (iter == entries_.end()) | |
175 return; | |
176 | |
177 DCHECK(!iter->second->encoded); | |
178 Send(new VideoCaptureMsg_DeviceInfo(controller_id.device_id, params)); | |
132 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 179 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, |
133 VIDEO_CAPTURE_STATE_ERROR)); | 180 VIDEO_CAPTURE_STATE_STARTED)); |
134 DeleteVideoCaptureControllerOnIOThread(controller_id); | 181 for (size_t i = 0; i < buffers.size(); ++i) { |
182 Send(new VideoCaptureMsg_NewBuffer(controller_id.device_id, | |
183 buffers[i], | |
184 buffer_size, | |
185 i)); | |
186 } | |
187 } | |
188 | |
189 void VideoCaptureHost::DoSendEncodedFrameInfoOnIOThread( | |
190 const VideoCaptureControllerID& controller_id, | |
191 const media::VideoEncodingParameters& params, | |
192 const std::vector<base::SharedMemoryHandle>& buffers, | |
193 size_t buffer_size) { | |
194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
195 | |
196 EntryMap::iterator iter = entries_.find(controller_id); | |
197 if (iter == entries_.end()) | |
198 return; | |
199 | |
200 DCHECK(iter->second->encoded); | |
201 Send(new EncodedVideoCaptureMsg_BitstreamCreated(controller_id.device_id, | |
202 params, | |
203 buffers, | |
204 buffer_size)); | |
135 } | 205 } |
136 | 206 |
137 void VideoCaptureHost::DoEndedOnIOThread( | 207 void VideoCaptureHost::DoEndedOnIOThread( |
138 const VideoCaptureControllerID& controller_id) { | 208 const VideoCaptureControllerID& controller_id) { |
139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
140 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; | 210 DVLOG(1) << "VideoCaptureHost::DoEndedOnIOThread"; |
141 if (entries_.find(controller_id) == entries_.end()) | 211 |
212 EntryMap::iterator iter = entries_.find(controller_id); | |
213 if (iter == entries_.end()) | |
142 return; | 214 return; |
143 | 215 |
144 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | 216 if (iter->second->encoded) { |
145 VIDEO_CAPTURE_STATE_ENDED)); | 217 Send(new EncodedVideoCaptureHostMsg_DestroyBitstream( |
218 controller_id.device_id)); | |
219 } else { | |
220 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | |
221 VIDEO_CAPTURE_STATE_ENDED)); | |
222 } | |
146 DeleteVideoCaptureControllerOnIOThread(controller_id); | 223 DeleteVideoCaptureControllerOnIOThread(controller_id); |
147 } | 224 } |
148 | 225 |
149 void VideoCaptureHost::DoSendFrameInfoOnIOThread( | 226 void VideoCaptureHost::DoBitstreamConfigChangedOnIOThread( |
150 const VideoCaptureControllerID& controller_id, | 227 const VideoCaptureControllerID& controller_id, |
151 int width, int height, int frame_per_second) { | 228 const media::RuntimeVideoEncodingParameters& params) { |
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
153 | 230 |
154 if (entries_.find(controller_id) == entries_.end()) | 231 EntryMap::iterator iter = entries_.find(controller_id); |
232 if (iter == entries_.end()) | |
155 return; | 233 return; |
156 | 234 if (!iter->second->encoded) |
157 media::VideoCaptureParams params; | 235 return; |
158 params.width = width; | 236 Send(new EncodedVideoCaptureMsg_BitstreamConfigChanged( |
159 params.height = height; | 237 controller_id.device_id, |
160 params.frame_per_second = frame_per_second; | 238 params)); |
161 Send(new VideoCaptureMsg_DeviceInfo(controller_id.device_id, params)); | |
162 Send(new VideoCaptureMsg_StateChanged(controller_id.device_id, | |
163 VIDEO_CAPTURE_STATE_STARTED)); | |
164 } | 239 } |
165 | 240 |
166 /////////////////////////////////////////////////////////////////////////////// | 241 /////////////////////////////////////////////////////////////////////////////// |
167 // IPC Messages handler. | 242 // IPC Messages handler. |
168 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, | 243 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, |
169 bool* message_was_ok) { | 244 bool* message_was_ok) { |
170 bool handled = true; | 245 bool handled = true; |
171 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) | 246 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) |
172 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) | 247 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) |
173 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) | 248 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) |
174 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) | 249 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) |
175 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer) | 250 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer) |
251 IPC_MESSAGE_HANDLER(EncodedVideoCaptureHostMsg_GetCapabilities, | |
252 OnGetCapabilities) | |
253 IPC_MESSAGE_HANDLER(EncodedVideoCaptureHostMsg_CreateBitstream, | |
254 OnCreateBitstream) | |
255 IPC_MESSAGE_HANDLER(EncodedVideoCaptureHostMsg_DestroyBitstream, | |
256 OnDestroyBitstream) | |
257 IPC_MESSAGE_HANDLER(EncodedVideoCaptureHostMsg_TryConfigureBitstream, | |
258 OnTryConfigureBitstream) | |
259 IPC_MESSAGE_HANDLER(EncodedVideoCaptureHostMsg_BitstreamBufferConsumed, | |
260 OnBitstreamBufferConsumed) | |
176 IPC_MESSAGE_UNHANDLED(handled = false) | 261 IPC_MESSAGE_UNHANDLED(handled = false) |
177 IPC_END_MESSAGE_MAP_EX() | 262 IPC_END_MESSAGE_MAP_EX() |
178 | 263 |
179 return handled; | 264 return handled; |
180 } | 265 } |
181 | 266 |
182 void VideoCaptureHost::OnStartCapture(int device_id, | 267 void VideoCaptureHost::OnStartCapture(int device_id, |
183 const media::VideoCaptureParams& params) { | 268 const media::VideoCaptureParams& params) { |
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
185 DVLOG(1) << "VideoCaptureHost::OnStartCapture, device_id " << device_id | 270 DVLOG(1) << "VideoCaptureHost::OnStartCapture, device_id " << device_id |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 VIDEO_CAPTURE_STATE_ERROR)); | 308 VIDEO_CAPTURE_STATE_ERROR)); |
224 delete it->second; | 309 delete it->second; |
225 entries_.erase(controller_id); | 310 entries_.erase(controller_id); |
226 return; | 311 return; |
227 } | 312 } |
228 | 313 |
229 it->second->controller = controller; | 314 it->second->controller = controller; |
230 controller->StartCapture(controller_id, this, peer_handle(), params); | 315 controller->StartCapture(controller_id, this, peer_handle(), params); |
231 } | 316 } |
232 | 317 |
318 void VideoCaptureHost::OnPauseCapture(int device_id) { | |
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
320 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; | |
321 // Not used. | |
Ami GONE FROM CHROMIUM
2013/06/18 18:35:55
NOTREACHED?
piman
2013/06/19 18:33:51
Not NOTREACHED since it can be reached by a malici
| |
322 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); | |
323 } | |
324 | |
233 void VideoCaptureHost::OnStopCapture(int device_id) { | 325 void VideoCaptureHost::OnStopCapture(int device_id) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
235 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | 327 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; |
236 | 328 |
237 VideoCaptureControllerID controller_id(device_id); | 329 VideoCaptureControllerID controller_id(device_id); |
238 | 330 |
239 Send(new VideoCaptureMsg_StateChanged(device_id, | 331 Send(new VideoCaptureMsg_StateChanged(device_id, |
240 VIDEO_CAPTURE_STATE_STOPPED)); | 332 VIDEO_CAPTURE_STATE_STOPPED)); |
241 DeleteVideoCaptureControllerOnIOThread(controller_id); | 333 DeleteVideoCaptureControllerOnIOThread(controller_id); |
242 } | 334 } |
243 | 335 |
244 void VideoCaptureHost::OnPauseCapture(int device_id) { | |
245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
246 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; | |
247 // Not used. | |
248 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); | |
249 } | |
250 | |
251 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { | 336 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { |
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
253 | 338 |
254 VideoCaptureControllerID controller_id(device_id); | 339 VideoCaptureControllerID controller_id(device_id); |
255 EntryMap::iterator it = entries_.find(controller_id); | 340 EntryMap::iterator it = entries_.find(controller_id); |
256 if (it != entries_.end()) { | 341 if (it != entries_.end()) { |
257 scoped_refptr<VideoCaptureController> controller = it->second->controller; | 342 scoped_refptr<VideoCaptureController> controller = it->second->controller; |
258 if (controller.get()) | 343 if (controller.get()) |
259 controller->ReturnBuffer(controller_id, this, buffer_id); | 344 controller->ReturnBuffer(controller_id, this, buffer_id); |
260 } | 345 } |
261 } | 346 } |
262 | 347 |
348 void VideoCaptureHost::OnGetCapabilities( | |
349 int device_id, | |
350 const media::VideoCaptureSessionId& session_id) { | |
351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
352 DVLOG(1) << "VideoCaptureHost::OnGetCapabilities, session_id " << session_id; | |
353 GetVideoCaptureManager()->RequestEncodingCapabilities( | |
354 session_id, | |
355 base::Bind(&VideoCaptureHost::OnEncodingCapabilitiesFound, | |
356 this, | |
357 device_id)); | |
358 } | |
359 | |
360 void VideoCaptureHost::OnEncodingCapabilitiesFound( | |
361 int device_id, | |
362 const media::VideoEncodingCapabilities& capabilities) { | |
363 BrowserThread::PostTask( | |
364 BrowserThread::IO, FROM_HERE, | |
365 base::Bind(&VideoCaptureHost::DoEncodingCapabilitiesFoundOnIOThread, | |
366 this, device_id, capabilities)); | |
367 } | |
368 | |
369 void VideoCaptureHost::DoEncodingCapabilitiesFoundOnIOThread( | |
370 int device_id, | |
371 const media::VideoEncodingCapabilities& capabilities) { | |
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
373 Send(new EncodedVideoCaptureMsg_CapabilitiesAvailable(device_id, | |
374 capabilities)); | |
375 } | |
376 | |
377 void VideoCaptureHost::OnCreateBitstream( | |
378 int device_id, | |
379 const media::VideoCaptureSessionId& session_id, | |
380 const media::VideoEncodingParameters& params) { | |
381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
382 DVLOG(1) << "VideoCaptureHost::OnCreateBitstream, device_id " << device_id | |
383 << ", session_id " << session_id; | |
384 media::VideoCaptureParams cap_params; | |
385 memset(&cap_params, 0, sizeof(cap_params)); | |
386 cap_params.width = params.resolution.width(); | |
387 cap_params.height = params.resolution.height(); | |
388 cap_params.session_id = session_id; | |
389 | |
390 VideoCaptureControllerID controller_id(device_id); | |
391 DCHECK(entries_.find(controller_id) == entries_.end()); | |
piman
2013/06/19 18:33:51
This data comes from the untrusted renderer.
This
sheu
2013/08/22 22:40:31
Done. Fixed also for OnStartCapture.
| |
392 Entry* entry = new Entry(NULL); | |
393 entry->encoded = true; | |
394 entries_[controller_id] = entry; | |
395 GetVideoCaptureManager()->AddController( | |
396 cap_params, this, base::Bind(&VideoCaptureHost::OnControllerAdded, this, | |
397 device_id, cap_params)); | |
398 } | |
399 | |
400 void VideoCaptureHost::OnDestroyBitstream(int device_id) { | |
401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
402 DVLOG(1) << "VideoCaptureHost::OnDestroyBitstream, device_id " << device_id; | |
403 // Proxy over to OnStopCapture. | |
404 OnStopCapture(device_id); | |
405 } | |
406 | |
407 void VideoCaptureHost::OnTryConfigureBitstream( | |
408 int device_id, | |
409 const media::RuntimeVideoEncodingParameters& params) { | |
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
411 DVLOG(1) << "VideoCaptureHost::OnTryConfigureBitstream, device_id " | |
412 << device_id; | |
413 | |
414 VideoCaptureControllerID controller_id(device_id); | |
415 EntryMap::iterator it = entries_.find(controller_id); | |
416 if (it != entries_.end()) { | |
417 scoped_refptr<VideoCaptureController> controller = it->second->controller; | |
418 if (controller.get()) | |
419 controller->TryConfigureEncodedBitstream(params); | |
420 } | |
421 } | |
422 | |
423 void VideoCaptureHost::OnBitstreamBufferConsumed(int device_id, int buffer_id) { | |
424 // Proxy over to OnReceiveEmptyBuffer. | |
425 OnReceiveEmptyBuffer(device_id, buffer_id); | |
426 } | |
427 | |
263 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( | 428 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( |
264 const VideoCaptureControllerID& controller_id) { | 429 const VideoCaptureControllerID& controller_id) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
266 | 431 |
267 EntryMap::iterator it = entries_.find(controller_id); | 432 EntryMap::iterator it = entries_.find(controller_id); |
268 if (it == entries_.end()) | 433 if (it == entries_.end()) |
269 return; | 434 return; |
270 | 435 |
271 VideoCaptureController* controller = it->second->controller.get(); | 436 VideoCaptureController* controller = it->second->controller.get(); |
272 if (controller) { | 437 if (controller) { |
273 controller->StopCapture(controller_id, this); | 438 controller->StopCapture(controller_id, this); |
274 GetVideoCaptureManager()->RemoveController(controller, this); | 439 GetVideoCaptureManager()->RemoveController(controller, this); |
275 } | 440 } |
276 delete it->second; | 441 delete it->second; |
277 entries_.erase(controller_id); | 442 entries_.erase(controller_id); |
278 } | 443 } |
279 | 444 |
280 VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { | 445 VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { |
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
282 return BrowserMainLoop::GetMediaStreamManager()->video_capture_manager(); | 447 return BrowserMainLoop::GetMediaStreamManager()->video_capture_manager(); |
283 } | 448 } |
284 | 449 |
285 } // namespace content | 450 } // namespace content |
OLD | NEW |