Chromium Code Reviews| 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> | |
| 8 #include <ksmedia.h> | |
| 9 | |
| 7 #include <algorithm> | 10 #include <algorithm> |
| 8 #include <list> | 11 #include <list> |
| 9 | 12 |
| 10 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 11 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/win/metro.h" | 16 #include "base/win/metro.h" |
| 14 #include "base/win/scoped_co_mem.h" | 17 #include "base/win/scoped_co_mem.h" |
| 15 #include "base/win/scoped_variant.h" | 18 #include "base/win/scoped_variant.h" |
| 16 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 hr = graph_builder_->AddFilter(mjpg_filter_, NULL); | 587 hr = graph_builder_->AddFilter(mjpg_filter_, NULL); |
| 585 } | 588 } |
| 586 | 589 |
| 587 if (FAILED(hr)) { | 590 if (FAILED(hr)) { |
| 588 mjpg_filter_.Release(); | 591 mjpg_filter_.Release(); |
| 589 input_mjpg_pin_.Release(); | 592 input_mjpg_pin_.Release(); |
| 590 output_mjpg_pin_.Release(); | 593 output_mjpg_pin_.Release(); |
| 591 } | 594 } |
| 592 } | 595 } |
| 593 | 596 |
| 597 SetAntiFlickerInCaptureFilter(); | |
| 598 | |
| 594 if (format.pixel_format == PIXEL_FORMAT_MJPEG && mjpg_filter_.get()) { | 599 if (format.pixel_format == PIXEL_FORMAT_MJPEG && mjpg_filter_.get()) { |
| 595 // Connect the camera to the MJPEG decoder. | 600 // Connect the camera to the MJPEG decoder. |
| 596 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_mjpg_pin_, | 601 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_mjpg_pin_, |
| 597 NULL); | 602 NULL); |
| 598 // Connect the MJPEG filter to the Capture filter. | 603 // Connect the MJPEG filter to the Capture filter. |
| 599 hr += graph_builder_->ConnectDirect(output_mjpg_pin_, input_sink_pin_, | 604 hr += graph_builder_->ConnectDirect(output_mjpg_pin_, input_sink_pin_, |
| 600 NULL); | 605 NULL); |
| 601 } else { | 606 } else { |
| 602 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_sink_pin_, | 607 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_sink_pin_, |
| 603 NULL); | 608 NULL); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 | 747 |
| 743 capability.supported_format.pixel_format = | 748 capability.supported_format.pixel_format = |
| 744 TranslateMediaSubtypeToPixelFormat(media_type->subtype); | 749 TranslateMediaSubtypeToPixelFormat(media_type->subtype); |
| 745 capabilities_.Add(capability); | 750 capabilities_.Add(capability); |
| 746 } | 751 } |
| 747 } | 752 } |
| 748 | 753 |
| 749 return !capabilities_.empty(); | 754 return !capabilities_.empty(); |
| 750 } | 755 } |
| 751 | 756 |
| 757 // Set the power line frequency removal in |capture_filter_| if available. | |
| 758 void VideoCaptureDeviceWin::SetAntiFlickerInCaptureFilter() { | |
| 759 HRESULT hr; | |
|
tommi (sloooow) - chröme
2014/04/22 14:55:27
nit: define where you need it
mcasas
2014/04/23 17:04:46
Done.
| |
| 760 const int power_line_frequency = GetPowerLineFrequencyForLocation(); | |
| 761 if (power_line_frequency == kPowerLine50Hz || | |
| 762 power_line_frequency == kPowerLine60Hz) { | |
|
tommi (sloooow) - chröme
2014/04/22 14:55:27
nit: could also turn this into an early return to
mcasas
2014/04/23 17:04:46
Done.
| |
| 763 ScopedComPtr<IKsPropertySet> ks_propset; | |
| 764 DWORD type_support = 0; | |
| 765 if (SUCCEEDED(hr = ks_propset.QueryFrom(capture_filter_)) && | |
| 766 SUCCEEDED(hr = ks_propset->QuerySupported(PROPSETID_VIDCAP_VIDEOPROCAMP, | |
| 767 KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY, | |
|
tommi (sloooow) - chröme
2014/04/22 14:55:27
not sure about this indent... think it should be:
mcasas
2014/04/23 17:04:46
Done.
| |
| 768 &type_support)) && | |
| 769 (type_support & KSPROPERTY_SUPPORT_SET)) { | |
| 770 KSPROPERTY_VIDEOPROCAMP_S data = {}; | |
| 771 data.Property.Set = PROPSETID_VIDCAP_VIDEOPROCAMP; | |
| 772 data.Property.Id = KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY; | |
| 773 data.Property.Flags = KSPROPERTY_TYPE_SET; | |
| 774 data.Value = (power_line_frequency == kPowerLine50Hz) ? 1 : 2; | |
| 775 data.Flags = KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL; | |
| 776 hr = ks_propset->Set(PROPSETID_VIDCAP_VIDEOPROCAMP, | |
| 777 KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY, | |
| 778 &data, sizeof(data), &data, sizeof(data)); | |
| 779 DVLOG_IF(2, FAILED(hr)) << "Anti-flicker setting failed."; | |
|
tommi (sloooow) - chröme
2014/04/22 14:55:27
DLOG_IF(ERROR, FAILED(hr)) ?
mcasas
2014/04/23 17:04:46
Done.
| |
| 780 DVLOG_IF(2, SUCCEEDED(hr)) << "Anti-flicker set correctly."; | |
| 781 } else { | |
| 782 DVLOG(2) << "Anti-flicker setting not supported."; | |
| 783 } | |
| 784 } | |
| 785 } | |
| 786 | |
| 752 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { | 787 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { |
| 753 DCHECK(CalledOnValidThread()); | 788 DCHECK(CalledOnValidThread()); |
| 754 DVLOG(1) << reason; | 789 DVLOG(1) << reason; |
| 755 state_ = kError; | 790 state_ = kError; |
| 756 client_->OnError(reason); | 791 client_->OnError(reason); |
| 757 } | 792 } |
| 758 } // namespace media | 793 } // namespace media |
| OLD | NEW |