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_source_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) {} | |
sheu
2013/06/12 08:06:21
Second most hack-ish part of this CL, but I don't
| |
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 EncodedVideoSourceMsg_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 EncodedVideoSourceHostMsg_DestroyBitstream( | |
158 controller_id.device_id)); | |
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 EncodedVideoSourceMsg_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 EncodedVideoSourceHostMsg_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 EncodedVideoSourceMsg_BitstreamConfigChanged(controller_id.device_id, |
159 params.height = height; | 237 params)); |
160 params.frame_per_second = frame_per_second; | |
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 } | 238 } |
165 | 239 |
166 /////////////////////////////////////////////////////////////////////////////// | 240 /////////////////////////////////////////////////////////////////////////////// |
167 // IPC Messages handler. | 241 // IPC Messages handler. |
168 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, | 242 bool VideoCaptureHost::OnMessageReceived(const IPC::Message& message, |
169 bool* message_was_ok) { | 243 bool* message_was_ok) { |
170 bool handled = true; | 244 bool handled = true; |
171 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) | 245 IPC_BEGIN_MESSAGE_MAP_EX(VideoCaptureHost, message, *message_was_ok) |
172 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) | 246 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Start, OnStartCapture) |
173 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) | 247 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Pause, OnPauseCapture) |
174 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) | 248 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_Stop, OnStopCapture) |
175 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer) | 249 IPC_MESSAGE_HANDLER(VideoCaptureHostMsg_BufferReady, OnReceiveEmptyBuffer) |
250 IPC_MESSAGE_HANDLER(EncodedVideoSourceHostMsg_GetCapability, | |
251 OnGetCapability) | |
252 IPC_MESSAGE_HANDLER(EncodedVideoSourceHostMsg_CreateBitstream, | |
253 OnCreateBitstream) | |
254 IPC_MESSAGE_HANDLER(EncodedVideoSourceHostMsg_DestroyBitstream, | |
255 OnDestroyBitstream) | |
256 IPC_MESSAGE_HANDLER(EncodedVideoSourceHostMsg_TryConfigureBitstream, | |
257 OnTryConfigureBitstream) | |
258 IPC_MESSAGE_HANDLER(EncodedVideoSourceHostMsg_BitstreamBufferConsumed, | |
259 OnBitstreamBufferConsumed) | |
176 IPC_MESSAGE_UNHANDLED(handled = false) | 260 IPC_MESSAGE_UNHANDLED(handled = false) |
177 IPC_END_MESSAGE_MAP_EX() | 261 IPC_END_MESSAGE_MAP_EX() |
178 | 262 |
179 return handled; | 263 return handled; |
180 } | 264 } |
181 | 265 |
182 void VideoCaptureHost::OnStartCapture(int device_id, | 266 void VideoCaptureHost::OnStartCapture(int device_id, |
183 const media::VideoCaptureParams& params) { | 267 const media::VideoCaptureParams& params) { |
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
185 DVLOG(1) << "VideoCaptureHost::OnStartCapture, device_id " << device_id | 269 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)); | 307 VIDEO_CAPTURE_STATE_ERROR)); |
224 delete it->second; | 308 delete it->second; |
225 entries_.erase(controller_id); | 309 entries_.erase(controller_id); |
226 return; | 310 return; |
227 } | 311 } |
228 | 312 |
229 it->second->controller = controller; | 313 it->second->controller = controller; |
230 controller->StartCapture(controller_id, this, peer_handle(), params); | 314 controller->StartCapture(controller_id, this, peer_handle(), params); |
231 } | 315 } |
232 | 316 |
317 void VideoCaptureHost::OnPauseCapture(int device_id) { | |
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
319 DVLOG(1) << "VideoCaptureHost::OnPauseCapture, device_id " << device_id; | |
320 // Not used. | |
321 Send(new VideoCaptureMsg_StateChanged(device_id, VIDEO_CAPTURE_STATE_ERROR)); | |
322 } | |
323 | |
233 void VideoCaptureHost::OnStopCapture(int device_id) { | 324 void VideoCaptureHost::OnStopCapture(int device_id) { |
234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
235 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; | 326 DVLOG(1) << "VideoCaptureHost::OnStopCapture, device_id " << device_id; |
236 | 327 |
237 VideoCaptureControllerID controller_id(device_id); | 328 VideoCaptureControllerID controller_id(device_id); |
238 | 329 |
239 Send(new VideoCaptureMsg_StateChanged(device_id, | 330 Send(new VideoCaptureMsg_StateChanged(device_id, |
240 VIDEO_CAPTURE_STATE_STOPPED)); | 331 VIDEO_CAPTURE_STATE_STOPPED)); |
241 DeleteVideoCaptureControllerOnIOThread(controller_id); | 332 DeleteVideoCaptureControllerOnIOThread(controller_id); |
242 } | 333 } |
243 | 334 |
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) { | 335 void VideoCaptureHost::OnReceiveEmptyBuffer(int device_id, int buffer_id) { |
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
253 | 337 |
254 VideoCaptureControllerID controller_id(device_id); | 338 VideoCaptureControllerID controller_id(device_id); |
255 EntryMap::iterator it = entries_.find(controller_id); | 339 EntryMap::iterator it = entries_.find(controller_id); |
256 if (it != entries_.end()) { | 340 if (it != entries_.end()) { |
257 scoped_refptr<VideoCaptureController> controller = it->second->controller; | 341 scoped_refptr<VideoCaptureController> controller = it->second->controller; |
258 if (controller.get()) | 342 if (controller.get()) |
259 controller->ReturnBuffer(controller_id, this, buffer_id); | 343 controller->ReturnBuffer(controller_id, this, buffer_id); |
260 } | 344 } |
261 } | 345 } |
262 | 346 |
347 void VideoCaptureHost::OnGetCapability( | |
348 const media::VideoCaptureSessionId& session_id) { | |
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
350 DVLOG(1) << "VideoCaptureHost::OnGetCapability, session_id " << session_id; | |
351 GetVideoCaptureManager()->RequestEncodingCapability( | |
352 session_id, | |
353 base::Bind(&VideoCaptureHost::OnEncodingCapabilityFound, | |
354 this, | |
355 session_id)); | |
356 } | |
357 | |
358 void VideoCaptureHost::OnEncodingCapabilityFound( | |
359 const media::VideoCaptureSessionId& session_id, | |
360 const media::VideoEncodingCapability& capability) { | |
361 BrowserThread::PostTask( | |
362 BrowserThread::IO, FROM_HERE, | |
363 base::Bind(&VideoCaptureHost::DoEncodingCapabilityFoundOnIOThread, | |
364 this, session_id, capability)); | |
365 } | |
366 | |
367 void VideoCaptureHost::DoEncodingCapabilityFoundOnIOThread( | |
368 const media::VideoCaptureSessionId& session_id, | |
369 const media::VideoEncodingCapability& capability) { | |
370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
371 Send(new EncodedVideoSourceMsg_CapabilityAvailable(session_id, capability)); | |
372 } | |
373 | |
374 void VideoCaptureHost::OnCreateBitstream( | |
375 int device_id, | |
376 const media::VideoCaptureSessionId& session_id, | |
377 const media::VideoEncodingParameters& params) { | |
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
379 DVLOG(1) << "VideoCaptureHost::OnCreateBitstream, device_id " << device_id | |
380 << ", session_id " << session_id; | |
381 media::VideoCaptureParams cap_params; | |
382 memset(&cap_params, 0, sizeof(cap_params)); | |
383 cap_params.width = params.resolution.width(); | |
384 cap_params.height = params.resolution.height(); | |
385 cap_params.frame_per_second = params.frames_per_second; | |
386 cap_params.session_id = session_id; | |
387 | |
388 VideoCaptureControllerID controller_id(device_id); | |
389 DCHECK(entries_.find(controller_id) == entries_.end()); | |
390 Entry* entry = new Entry(NULL); | |
391 entry->encoded = true; | |
392 entries_[controller_id] = entry; | |
393 GetVideoCaptureManager()->AddController( | |
394 cap_params, this, base::Bind(&VideoCaptureHost::OnControllerAdded, this, | |
395 device_id, cap_params)); | |
396 } | |
397 | |
398 void VideoCaptureHost::OnDestroyBitstream(int device_id) { | |
399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
400 DVLOG(1) << "VideoCaptureHost::OnDestroyBitstream, device_id " << device_id; | |
401 // Proxy over to OnStopCapture. | |
402 OnStopCapture(device_id); | |
403 } | |
404 | |
405 void VideoCaptureHost::OnTryConfigureBitstream( | |
406 int device_id, | |
407 const media::RuntimeVideoEncodingParameters& params) { | |
408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
409 DVLOG(1) << "VideoCaptureHost::OnTryConfigureBitstream, device_id " | |
410 << device_id; | |
411 | |
412 VideoCaptureControllerID controller_id(device_id); | |
413 EntryMap::iterator it = entries_.find(controller_id); | |
414 if (it != entries_.end()) { | |
415 scoped_refptr<VideoCaptureController> controller = it->second->controller; | |
416 if (controller.get()) | |
417 controller->TryConfigureEncodedBitstream(params); | |
418 } | |
419 } | |
420 | |
421 void VideoCaptureHost::OnBitstreamBufferConsumed(int device_id, int buffer_id) { | |
422 // Proxy over to OnReceiveEmptyBuffer. | |
423 OnReceiveEmptyBuffer(device_id, buffer_id); | |
424 } | |
425 | |
263 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( | 426 void VideoCaptureHost::DeleteVideoCaptureControllerOnIOThread( |
264 const VideoCaptureControllerID& controller_id) { | 427 const VideoCaptureControllerID& controller_id) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 428 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
266 | 429 |
267 EntryMap::iterator it = entries_.find(controller_id); | 430 EntryMap::iterator it = entries_.find(controller_id); |
268 if (it == entries_.end()) | 431 if (it == entries_.end()) |
269 return; | 432 return; |
270 | 433 |
271 VideoCaptureController* controller = it->second->controller.get(); | 434 VideoCaptureController* controller = it->second->controller.get(); |
272 if (controller) { | 435 if (controller) { |
273 controller->StopCapture(controller_id, this); | 436 controller->StopCapture(controller_id, this); |
274 GetVideoCaptureManager()->RemoveController(controller, this); | 437 GetVideoCaptureManager()->RemoveController(controller, this); |
275 } | 438 } |
276 delete it->second; | 439 delete it->second; |
277 entries_.erase(controller_id); | 440 entries_.erase(controller_id); |
278 } | 441 } |
279 | 442 |
280 VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { | 443 VideoCaptureManager* VideoCaptureHost::GetVideoCaptureManager() { |
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
282 return BrowserMainLoop::GetMediaStreamManager()->video_capture_manager(); | 445 return BrowserMainLoop::GetMediaStreamManager()->video_capture_manager(); |
283 } | 446 } |
284 | 447 |
285 } // namespace content | 448 } // namespace content |
OLD | NEW |