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 "media/capture/video/win/video_capture_device_win.h" | 5 #include "media/capture/video/win/video_capture_device_win.h" |
6 | 6 |
7 #include <ks.h> | 7 #include <ks.h> |
8 #include <ksmedia.h> | 8 #include <ksmedia.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 SetErrorState(FROM_HERE, "Failed to connect the Capture graph.", hr); | 405 SetErrorState(FROM_HERE, "Failed to connect the Capture graph.", hr); |
406 return; | 406 return; |
407 } | 407 } |
408 | 408 |
409 hr = media_control_->Pause(); | 409 hr = media_control_->Pause(); |
410 if (FAILED(hr)) { | 410 if (FAILED(hr)) { |
411 SetErrorState(FROM_HERE, "Failed to pause the Capture device", hr); | 411 SetErrorState(FROM_HERE, "Failed to pause the Capture device", hr); |
412 return; | 412 return; |
413 } | 413 } |
414 | 414 |
415 // Get the format back from the sink filter after the filter have been | |
416 // connected. | |
417 capture_format_ = sink_filter_->ResultingFormat(); | |
418 | |
419 // Start capturing. | 415 // Start capturing. |
420 hr = media_control_->Run(); | 416 hr = media_control_->Run(); |
421 if (FAILED(hr)) { | 417 if (FAILED(hr)) { |
422 SetErrorState(FROM_HERE, "Failed to start the Capture device.", hr); | 418 SetErrorState(FROM_HERE, "Failed to start the Capture device.", hr); |
423 return; | 419 return; |
424 } | 420 } |
425 | 421 |
426 state_ = kCapturing; | 422 state_ = kCapturing; |
427 } | 423 } |
428 | 424 |
(...skipping 20 matching lines...) Expand all Loading... |
449 // DirectShow has other means of capturing still pictures, e.g. connecting a | 445 // DirectShow has other means of capturing still pictures, e.g. connecting a |
450 // SampleGrabber filter to a PIN_CATEGORY_STILL of |capture_filter_|. This | 446 // SampleGrabber filter to a PIN_CATEGORY_STILL of |capture_filter_|. This |
451 // way, however, is not widespread and proves too cumbersome, so we just grab | 447 // way, however, is not widespread and proves too cumbersome, so we just grab |
452 // the next captured frame instead. | 448 // the next captured frame instead. |
453 take_photo_callbacks_.push(std::move(callback)); | 449 take_photo_callbacks_.push(std::move(callback)); |
454 } | 450 } |
455 | 451 |
456 // Implements SinkFilterObserver::SinkFilterObserver. | 452 // Implements SinkFilterObserver::SinkFilterObserver. |
457 void VideoCaptureDeviceWin::FrameReceived(const uint8_t* buffer, | 453 void VideoCaptureDeviceWin::FrameReceived(const uint8_t* buffer, |
458 int length, | 454 int length, |
| 455 const VideoCaptureFormat& format, |
459 base::TimeDelta timestamp) { | 456 base::TimeDelta timestamp) { |
460 if (first_ref_time_.is_null()) | 457 if (first_ref_time_.is_null()) |
461 first_ref_time_ = base::TimeTicks::Now(); | 458 first_ref_time_ = base::TimeTicks::Now(); |
462 | 459 |
463 // There is a chance that the platform does not provide us with the timestamp, | 460 // There is a chance that the platform does not provide us with the timestamp, |
464 // in which case, we use reference time to calculate a timestamp. | 461 // in which case, we use reference time to calculate a timestamp. |
465 if (timestamp == media::kNoTimestamp) | 462 if (timestamp == media::kNoTimestamp) |
466 timestamp = base::TimeTicks::Now() - first_ref_time_; | 463 timestamp = base::TimeTicks::Now() - first_ref_time_; |
467 | 464 |
468 client_->OnIncomingCapturedData(buffer, length, capture_format_, 0, | 465 client_->OnIncomingCapturedData(buffer, length, format, 0, |
469 base::TimeTicks::Now(), timestamp); | 466 base::TimeTicks::Now(), timestamp); |
470 | 467 |
471 while (!take_photo_callbacks_.empty()) { | 468 while (!take_photo_callbacks_.empty()) { |
472 TakePhotoCallback cb = std::move(take_photo_callbacks_.front()); | 469 TakePhotoCallback cb = std::move(take_photo_callbacks_.front()); |
473 take_photo_callbacks_.pop(); | 470 take_photo_callbacks_.pop(); |
474 | 471 |
475 mojom::BlobPtr blob = Blobify(buffer, length, capture_format_); | 472 mojom::BlobPtr blob = Blobify(buffer, length, format); |
476 if (blob) | 473 if (blob) |
477 cb.Run(std::move(blob)); | 474 cb.Run(std::move(blob)); |
478 } | 475 } |
479 } | 476 } |
480 | 477 |
481 bool VideoCaptureDeviceWin::CreateCapabilityMap() { | 478 bool VideoCaptureDeviceWin::CreateCapabilityMap() { |
482 DCHECK(thread_checker_.CalledOnValidThread()); | 479 DCHECK(thread_checker_.CalledOnValidThread()); |
483 ScopedComPtr<IAMStreamConfig> stream_config; | 480 ScopedComPtr<IAMStreamConfig> stream_config; |
484 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); | 481 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); |
485 DLOG_IF_FAILED_WITH_HRESULT( | 482 DLOG_IF_FAILED_WITH_HRESULT( |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 void VideoCaptureDeviceWin::SetErrorState( | 586 void VideoCaptureDeviceWin::SetErrorState( |
590 const tracked_objects::Location& from_here, | 587 const tracked_objects::Location& from_here, |
591 const std::string& reason, | 588 const std::string& reason, |
592 HRESULT hr) { | 589 HRESULT hr) { |
593 DCHECK(thread_checker_.CalledOnValidThread()); | 590 DCHECK(thread_checker_.CalledOnValidThread()); |
594 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); | 591 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); |
595 state_ = kError; | 592 state_ = kError; |
596 client_->OnError(from_here, reason); | 593 client_->OnError(from_here, reason); |
597 } | 594 } |
598 } // namespace media | 595 } // namespace media |
OLD | NEW |