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_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { | 108 media::VideoCaptureDevice::EventHandler* video_capture_receiver) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
110 device_loop_->PostTask( | 110 device_loop_->PostTask( |
111 FROM_HERE, | 111 FROM_HERE, |
112 base::Bind(&VideoCaptureManager::OnStart, this, capture_params, | 112 base::Bind(&VideoCaptureManager::OnStart, this, capture_params, |
113 video_capture_receiver)); | 113 video_capture_receiver)); |
114 } | 114 } |
115 | 115 |
116 void VideoCaptureManager::Stop( | 116 void VideoCaptureManager::Stop( |
117 const media::VideoCaptureSessionId& capture_session_id, | 117 const media::VideoCaptureSessionId& capture_session_id, |
118 base::Closure stopped_cb) { | 118 const base::Closure& stopped_cb) { |
119 DVLOG(1) << "VideoCaptureManager::Stop, id " << capture_session_id; | 119 DVLOG(1) << "VideoCaptureManager::Stop, id " << capture_session_id; |
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
121 device_loop_->PostTask( | 121 device_loop_->PostTask( |
122 FROM_HERE, | 122 FROM_HERE, |
123 base::Bind(&VideoCaptureManager::OnStop, this, capture_session_id, | 123 base::Bind(&VideoCaptureManager::OnStop, this, capture_session_id, |
124 stopped_cb)); | 124 stopped_cb)); |
125 } | 125 } |
126 | 126 |
| 127 void VideoCaptureManager::TryConfigureEncodedBitstream( |
| 128 const media::VideoCaptureSessionId& session_id, |
| 129 const media::RuntimeVideoEncodingParameters& params) { |
| 130 device_loop_->PostTask( |
| 131 FROM_HERE, |
| 132 base::Bind( |
| 133 &VideoCaptureManager::OnTryConfigureEncodedBitstream, |
| 134 this, |
| 135 session_id, |
| 136 params)); |
| 137 } |
| 138 |
127 void VideoCaptureManager::UseFakeDevice() { | 139 void VideoCaptureManager::UseFakeDevice() { |
128 use_fake_device_ = true; | 140 use_fake_device_ = true; |
129 } | 141 } |
130 | 142 |
131 void VideoCaptureManager::OnEnumerateDevices(MediaStreamType stream_type) { | 143 void VideoCaptureManager::OnEnumerateDevices(MediaStreamType stream_type) { |
132 DCHECK(IsOnDeviceThread()); | 144 DCHECK(IsOnDeviceThread()); |
133 | 145 |
134 media::VideoCaptureDevice::Names device_names; | 146 media::VideoCaptureDevice::Names device_names; |
135 GetAvailableDevices(stream_type, &device_names); | 147 GetAvailableDevices(stream_type, &device_names); |
136 | 148 |
(...skipping 24 matching lines...) Expand all Loading... |
161 PostOnOpened(device.device.type, capture_session_id); | 173 PostOnOpened(device.device.type, capture_session_id); |
162 return; | 174 return; |
163 } | 175 } |
164 | 176 |
165 // Open the device. | 177 // Open the device. |
166 media::VideoCaptureDevice::Name vc_device_name; | 178 media::VideoCaptureDevice::Name vc_device_name; |
167 vc_device_name.device_name = device.device.name; | 179 vc_device_name.device_name = device.device.name; |
168 vc_device_name.unique_id = device.device.id; | 180 vc_device_name.unique_id = device.device.id; |
169 | 181 |
170 if (use_fake_device_) { | 182 if (use_fake_device_) { |
| 183 const bool encoded_capture = |
| 184 (device.device.type == MEDIA_SCREEN_ENCODED_VIDEO_CAPTURE); |
171 video_capture_device = | 185 video_capture_device = |
172 media::FakeVideoCaptureDevice::Create(vc_device_name); | 186 media::FakeVideoCaptureDevice::Create(vc_device_name, encoded_capture); |
173 } else { | 187 } else { |
174 switch (device.device.type) { | 188 switch (device.device.type) { |
175 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 189 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
176 video_capture_device = | 190 video_capture_device = |
177 media::VideoCaptureDevice::Create(vc_device_name); | 191 media::VideoCaptureDevice::Create(vc_device_name); |
178 break; | 192 break; |
179 } | 193 } |
180 case MEDIA_TAB_VIDEO_CAPTURE: { | 194 case MEDIA_TAB_VIDEO_CAPTURE: { |
181 video_capture_device = WebContentsVideoCaptureDevice::Create( | 195 video_capture_device = WebContentsVideoCaptureDevice::Create( |
182 vc_device_name.unique_id); | 196 vc_device_name.unique_id); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Possible errors are signaled to video_capture_receiver by | 284 // Possible errors are signaled to video_capture_receiver by |
271 // video_capture_device. video_capture_receiver to perform actions. | 285 // video_capture_device. video_capture_receiver to perform actions. |
272 video_capture_device->Allocate(capture_params.width, capture_params.height, | 286 video_capture_device->Allocate(capture_params.width, capture_params.height, |
273 capture_params.frame_per_second, | 287 capture_params.frame_per_second, |
274 video_capture_receiver); | 288 video_capture_receiver); |
275 video_capture_device->Start(); | 289 video_capture_device->Start(); |
276 } | 290 } |
277 | 291 |
278 void VideoCaptureManager::OnStop( | 292 void VideoCaptureManager::OnStop( |
279 const media::VideoCaptureSessionId capture_session_id, | 293 const media::VideoCaptureSessionId capture_session_id, |
280 base::Closure stopped_cb) { | 294 const base::Closure& stopped_cb) { |
281 DCHECK(IsOnDeviceThread()); | 295 DCHECK(IsOnDeviceThread()); |
282 DVLOG(1) << "VideoCaptureManager::OnStop, id " << capture_session_id; | 296 DVLOG(1) << "VideoCaptureManager::OnStop, id " << capture_session_id; |
283 | 297 |
284 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); | 298 VideoCaptureDevices::iterator it = devices_.find(capture_session_id); |
285 if (it != devices_.end()) { | 299 if (it != devices_.end()) { |
286 media::VideoCaptureDevice* video_capture_device = it->second.capture_device; | 300 media::VideoCaptureDevice* video_capture_device = it->second.capture_device; |
287 // Possible errors are signaled to video_capture_receiver by | 301 // Possible errors are signaled to video_capture_receiver by |
288 // video_capture_device. video_capture_receiver to perform actions. | 302 // video_capture_device. video_capture_receiver to perform actions. |
289 video_capture_device->Stop(); | 303 video_capture_device->Stop(); |
290 video_capture_device->DeAllocate(); | 304 video_capture_device->DeAllocate(); |
291 Controllers::iterator cit = controllers_.find(video_capture_device); | 305 Controllers::iterator cit = controllers_.find(video_capture_device); |
292 if (cit != controllers_.end()) { | 306 if (cit != controllers_.end()) { |
293 cit->second->ready_to_delete = true; | 307 cit->second->ready_to_delete = true; |
294 if (cit->second->handlers.empty()) { | 308 if (cit->second->handlers.empty()) { |
295 delete cit->second; | 309 delete cit->second; |
296 controllers_.erase(cit); | 310 controllers_.erase(cit); |
297 } | 311 } |
298 } | 312 } |
299 } | 313 } |
300 | 314 |
301 if (!stopped_cb.is_null()) | 315 if (!stopped_cb.is_null()) |
302 stopped_cb.Run(); | 316 stopped_cb.Run(); |
303 | 317 |
304 if (capture_session_id == kStartOpenSessionId) { | 318 if (capture_session_id == kStartOpenSessionId) { |
305 // This device was opened from Start(), not Open(). Close it! | 319 // This device was opened from Start(), not Open(). Close it! |
306 OnClose(capture_session_id); | 320 OnClose(capture_session_id); |
307 } | 321 } |
308 } | 322 } |
309 | 323 |
| 324 void VideoCaptureManager::OnTryConfigureEncodedBitstream( |
| 325 const media::VideoCaptureSessionId& session_id, |
| 326 const media::RuntimeVideoEncodingParameters& params) { |
| 327 DCHECK(IsOnDeviceThread()); |
| 328 media::VideoCaptureDevice* video_capture_device = |
| 329 GetDeviceInternal(session_id); |
| 330 if (!video_capture_device) |
| 331 return; |
| 332 video_capture_device->TryConfigureEncodedBitstream(params); |
| 333 } |
| 334 |
310 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 335 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
311 int capture_session_id) { | 336 int capture_session_id) { |
312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
313 if (!listener_) { | 338 if (!listener_) { |
314 // Listener has been removed. | 339 // Listener has been removed. |
315 return; | 340 return; |
316 } | 341 } |
317 listener_->Opened(stream_type, capture_session_id); | 342 listener_->Opened(stream_type, capture_session_id); |
318 } | 343 } |
319 | 344 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 void VideoCaptureManager::GetAvailableDevices( | 422 void VideoCaptureManager::GetAvailableDevices( |
398 MediaStreamType stream_type, | 423 MediaStreamType stream_type, |
399 media::VideoCaptureDevice::Names* device_names) { | 424 media::VideoCaptureDevice::Names* device_names) { |
400 DCHECK(IsOnDeviceThread()); | 425 DCHECK(IsOnDeviceThread()); |
401 | 426 |
402 switch (stream_type) { | 427 switch (stream_type) { |
403 case MEDIA_DEVICE_VIDEO_CAPTURE: | 428 case MEDIA_DEVICE_VIDEO_CAPTURE: |
404 if (!use_fake_device_) { | 429 if (!use_fake_device_) { |
405 media::VideoCaptureDevice::GetDeviceNames(device_names); | 430 media::VideoCaptureDevice::GetDeviceNames(device_names); |
406 } else { | 431 } else { |
407 media::FakeVideoCaptureDevice::GetDeviceNames(device_names); | 432 media::FakeVideoCaptureDevice::GetDeviceNames(device_names, false); |
408 } | 433 } |
409 break; | 434 break; |
410 | 435 |
411 case MEDIA_SCREEN_VIDEO_CAPTURE: | 436 case MEDIA_SCREEN_VIDEO_CAPTURE: |
412 device_names->clear(); | 437 device_names->clear(); |
413 break; | 438 break; |
414 | 439 |
| 440 case MEDIA_SCREEN_ENCODED_VIDEO_CAPTURE: |
| 441 device_names->clear(); |
| 442 break; |
| 443 |
415 default: | 444 default: |
416 NOTREACHED(); | 445 NOTREACHED(); |
417 break; | 446 break; |
418 } | 447 } |
419 } | 448 } |
420 | 449 |
421 bool VideoCaptureManager::DeviceOpened( | 450 bool VideoCaptureManager::DeviceOpened( |
422 const media::VideoCaptureDevice::Name& device_name) { | 451 const media::VideoCaptureDevice::Name& device_name) { |
423 DCHECK(IsOnDeviceThread()); | 452 DCHECK(IsOnDeviceThread()); |
424 | 453 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // We've found the device! | 486 // We've found the device! |
458 return true; | 487 return true; |
459 } | 488 } |
460 } | 489 } |
461 return false; | 490 return false; |
462 } | 491 } |
463 | 492 |
464 void VideoCaptureManager::AddController( | 493 void VideoCaptureManager::AddController( |
465 const media::VideoCaptureParams& capture_params, | 494 const media::VideoCaptureParams& capture_params, |
466 VideoCaptureControllerEventHandler* handler, | 495 VideoCaptureControllerEventHandler* handler, |
467 base::Callback<void(VideoCaptureController*)> added_cb) { | 496 const base::Callback<void(VideoCaptureController*)>& added_cb) { |
468 DCHECK(handler); | 497 DCHECK(handler); |
469 device_loop_->PostTask( | 498 device_loop_->PostTask( |
470 FROM_HERE, | 499 FROM_HERE, |
471 base::Bind(&VideoCaptureManager::DoAddControllerOnDeviceThread, | 500 base::Bind(&VideoCaptureManager::DoAddControllerOnDeviceThread, |
472 this, capture_params, handler, added_cb)); | 501 this, capture_params, handler, added_cb)); |
473 } | 502 } |
474 | 503 |
475 void VideoCaptureManager::DoAddControllerOnDeviceThread( | 504 void VideoCaptureManager::DoAddControllerOnDeviceThread( |
476 const media::VideoCaptureParams capture_params, | 505 const media::VideoCaptureParams capture_params, |
477 VideoCaptureControllerEventHandler* handler, | 506 VideoCaptureControllerEventHandler* handler, |
478 base::Callback<void(VideoCaptureController*)> added_cb) { | 507 const base::Callback<void(VideoCaptureController*)>& added_cb) { |
479 DCHECK(IsOnDeviceThread()); | 508 DCHECK(IsOnDeviceThread()); |
480 | 509 |
481 media::VideoCaptureDevice* video_capture_device = | 510 media::VideoCaptureDevice* video_capture_device = |
482 GetDeviceInternal(capture_params.session_id); | 511 GetDeviceInternal(capture_params.session_id); |
483 scoped_refptr<VideoCaptureController> controller; | 512 scoped_refptr<VideoCaptureController> controller; |
484 if (video_capture_device) { | 513 if (video_capture_device) { |
485 Controllers::iterator cit = controllers_.find(video_capture_device); | 514 Controllers::iterator cit = controllers_.find(video_capture_device); |
486 if (cit == controllers_.end()) { | 515 if (cit == controllers_.end()) { |
487 controller = new VideoCaptureController(this); | 516 controller = new VideoCaptureController(this); |
488 controllers_[video_capture_device] = | 517 controllers_[video_capture_device] = |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 552 } |
524 if (handlers.empty() && cit->second->ready_to_delete) { | 553 if (handlers.empty() && cit->second->ready_to_delete) { |
525 delete cit->second; | 554 delete cit->second; |
526 controllers_.erase(cit); | 555 controllers_.erase(cit); |
527 } | 556 } |
528 return; | 557 return; |
529 } | 558 } |
530 } | 559 } |
531 } | 560 } |
532 | 561 |
| 562 void VideoCaptureManager::RequestEncodingCapabilities( |
| 563 const media::VideoCaptureSessionId& session_id, |
| 564 const base::Callback<void( |
| 565 const media::VideoEncodingCapabilities&)>& caps_cb) { |
| 566 device_loop_->PostTask( |
| 567 FROM_HERE, |
| 568 base::Bind( |
| 569 &VideoCaptureManager::DoRequestEncodingCapabilitiesOnDeviceThread, |
| 570 this, |
| 571 session_id, |
| 572 caps_cb)); |
| 573 } |
| 574 |
| 575 void VideoCaptureManager::DoRequestEncodingCapabilitiesOnDeviceThread( |
| 576 const media::VideoCaptureSessionId& session_id, |
| 577 const base::Callback<void( |
| 578 const media::VideoEncodingCapabilities&)>& caps_cb) { |
| 579 DCHECK(IsOnDeviceThread()); |
| 580 media::VideoCaptureDevice* video_capture_device = |
| 581 GetDeviceInternal(session_id); |
| 582 if (!video_capture_device) |
| 583 return; |
| 584 caps_cb.Run(video_capture_device->GetEncodingCapabilities()); |
| 585 } |
| 586 |
533 media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal( | 587 media::VideoCaptureDevice* VideoCaptureManager::GetDeviceInternal( |
534 int capture_session_id) { | 588 int capture_session_id) { |
535 DCHECK(IsOnDeviceThread()); | 589 DCHECK(IsOnDeviceThread()); |
536 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); | 590 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); |
537 if (dit != devices_.end()) { | 591 if (dit != devices_.end()) { |
538 return dit->second.capture_device; | 592 return dit->second.capture_device; |
539 } | 593 } |
540 | 594 |
541 // Solution for not using MediaStreamManager. | 595 // Solution for not using MediaStreamManager. |
542 // This session id won't be returned by Open(). | 596 // This session id won't be returned by Open(). |
(...skipping 13 matching lines...) Expand all Loading... |
556 | 610 |
557 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); | 611 VideoCaptureDevices::iterator dit = devices_.find(capture_session_id); |
558 if (dit != devices_.end()) { | 612 if (dit != devices_.end()) { |
559 return dit->second.capture_device; | 613 return dit->second.capture_device; |
560 } | 614 } |
561 } | 615 } |
562 return NULL; | 616 return NULL; |
563 } | 617 } |
564 | 618 |
565 } // namespace content | 619 } // namespace content |
OLD | NEW |