| 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/video/capture/win/video_capture_device_win.h" | 5 #include "media/video/capture/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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); | 415 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); |
| 416 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() | 416 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() |
| 417 // macros here since they'll trigger incorrectly. | 417 // macros here since they'll trigger incorrectly. |
| 418 if (hr != S_OK) { | 418 if (hr != S_OK) { |
| 419 DVLOG(2) << "Failed to GetStreamCaps"; | 419 DVLOG(2) << "Failed to GetStreamCaps"; |
| 420 return; | 420 return; |
| 421 } | 421 } |
| 422 | 422 |
| 423 if (media_type->majortype == MEDIATYPE_Video && | 423 if (media_type->majortype == MEDIATYPE_Video && |
| 424 media_type->formattype == FORMAT_VideoInfo) { | 424 media_type->formattype == FORMAT_VideoInfo) { |
| 425 VideoCaptureFormat format; |
| 426 format.pixel_format = |
| 427 TranslateMediaSubtypeToPixelFormat(media_type->subtype); |
| 428 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN) |
| 429 continue; |
| 425 VIDEOINFOHEADER* h = | 430 VIDEOINFOHEADER* h = |
| 426 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 431 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
| 427 VideoCaptureFormat format; | |
| 428 format.frame_size.SetSize(h->bmiHeader.biWidth, | 432 format.frame_size.SetSize(h->bmiHeader.biWidth, |
| 429 h->bmiHeader.biHeight); | 433 h->bmiHeader.biHeight); |
| 430 // Trust the frame rate from the VIDEOINFOHEADER. | 434 // Trust the frame rate from the VIDEOINFOHEADER. |
| 431 format.frame_rate = (h->AvgTimePerFrame > 0) ? | 435 format.frame_rate = (h->AvgTimePerFrame > 0) ? |
| 432 static_cast<int>(kSecondsToReferenceTime / h->AvgTimePerFrame) : | 436 static_cast<int>(kSecondsToReferenceTime / h->AvgTimePerFrame) : |
| 433 0; | 437 0; |
| 434 format.pixel_format = | |
| 435 TranslateMediaSubtypeToPixelFormat(media_type->subtype); | |
| 436 formats->push_back(format); | 438 formats->push_back(format); |
| 437 DVLOG(1) << device.name() << " resolution: " | 439 DVLOG(1) << device.name() << " resolution: " |
| 438 << format.frame_size.ToString() << ", fps: " << format.frame_rate | 440 << format.frame_size.ToString() << ", fps: " << format.frame_rate |
| 439 << ", pixel format: " << format.pixel_format; | 441 << ", pixel format: " << format.pixel_format; |
| 440 } | 442 } |
| 441 } | 443 } |
| 442 } | 444 } |
| 443 } | 445 } |
| 444 | 446 |
| 445 VideoCaptureDeviceWin::VideoCaptureDeviceWin(const Name& device_name) | 447 VideoCaptureDeviceWin::VideoCaptureDeviceWin(const Name& device_name) |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() | 700 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() |
| 699 // macros here since they'll trigger incorrectly. | 701 // macros here since they'll trigger incorrectly. |
| 700 if (hr != S_OK) { | 702 if (hr != S_OK) { |
| 701 DVLOG(2) << "Failed to GetStreamCaps"; | 703 DVLOG(2) << "Failed to GetStreamCaps"; |
| 702 return false; | 704 return false; |
| 703 } | 705 } |
| 704 | 706 |
| 705 if (media_type->majortype == MEDIATYPE_Video && | 707 if (media_type->majortype == MEDIATYPE_Video && |
| 706 media_type->formattype == FORMAT_VideoInfo) { | 708 media_type->formattype == FORMAT_VideoInfo) { |
| 707 VideoCaptureCapabilityWin capability(i); | 709 VideoCaptureCapabilityWin capability(i); |
| 710 capability.supported_format.pixel_format = |
| 711 TranslateMediaSubtypeToPixelFormat(media_type->subtype); |
| 712 if (capability.supported_format.pixel_format == PIXEL_FORMAT_UNKNOWN) |
| 713 continue; |
| 714 |
| 708 VIDEOINFOHEADER* h = | 715 VIDEOINFOHEADER* h = |
| 709 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 716 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
| 710 capability.supported_format.frame_size.SetSize(h->bmiHeader.biWidth, | 717 capability.supported_format.frame_size.SetSize(h->bmiHeader.biWidth, |
| 711 h->bmiHeader.biHeight); | 718 h->bmiHeader.biHeight); |
| 712 | 719 |
| 713 // Try to get a better |time_per_frame| from IAMVideoControl. If not, use | 720 // Try to get a better |time_per_frame| from IAMVideoControl. If not, use |
| 714 // the value from VIDEOINFOHEADER. | 721 // the value from VIDEOINFOHEADER. |
| 715 REFERENCE_TIME time_per_frame = h->AvgTimePerFrame; | 722 REFERENCE_TIME time_per_frame = h->AvgTimePerFrame; |
| 716 if (video_control) { | 723 if (video_control) { |
| 717 ScopedCoMem<LONGLONG> max_fps; | 724 ScopedCoMem<LONGLONG> max_fps; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 738 capability.supported_format.frame_rate = | 745 capability.supported_format.frame_rate = |
| 739 (time_per_frame > 0) | 746 (time_per_frame > 0) |
| 740 ? static_cast<int>(kSecondsToReferenceTime / time_per_frame) | 747 ? static_cast<int>(kSecondsToReferenceTime / time_per_frame) |
| 741 : 0; | 748 : 0; |
| 742 | 749 |
| 743 // DirectShow works at the moment only on integer frame_rate but the | 750 // DirectShow works at the moment only on integer frame_rate but the |
| 744 // best capability matching class works on rational frame rates. | 751 // best capability matching class works on rational frame rates. |
| 745 capability.frame_rate_numerator = capability.supported_format.frame_rate; | 752 capability.frame_rate_numerator = capability.supported_format.frame_rate; |
| 746 capability.frame_rate_denominator = 1; | 753 capability.frame_rate_denominator = 1; |
| 747 | 754 |
| 748 capability.supported_format.pixel_format = | |
| 749 TranslateMediaSubtypeToPixelFormat(media_type->subtype); | |
| 750 capabilities_.Add(capability); | 755 capabilities_.Add(capability); |
| 751 } | 756 } |
| 752 } | 757 } |
| 753 | 758 |
| 754 return !capabilities_.empty(); | 759 return !capabilities_.empty(); |
| 755 } | 760 } |
| 756 | 761 |
| 757 // Set the power line frequency removal in |capture_filter_| if available. | 762 // Set the power line frequency removal in |capture_filter_| if available. |
| 758 void VideoCaptureDeviceWin::SetAntiFlickerInCaptureFilter() { | 763 void VideoCaptureDeviceWin::SetAntiFlickerInCaptureFilter() { |
| 759 const int power_line_frequency = GetPowerLineFrequencyForLocation(); | 764 const int power_line_frequency = GetPowerLineFrequencyForLocation(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 784 } | 789 } |
| 785 } | 790 } |
| 786 | 791 |
| 787 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { | 792 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { |
| 788 DCHECK(CalledOnValidThread()); | 793 DCHECK(CalledOnValidThread()); |
| 789 DVLOG(1) << reason; | 794 DVLOG(1) << reason; |
| 790 state_ = kError; | 795 state_ = kError; |
| 791 client_->OnError(reason); | 796 client_->OnError(reason); |
| 792 } | 797 } |
| 793 } // namespace media | 798 } // namespace media |
| OLD | NEW |