| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, | 77 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, |
| 78 enum_moniker.Receive(), 0); | 78 enum_moniker.Receive(), 0); |
| 79 // CreateClassEnumerator returns S_FALSE on some Windows OS | 79 // CreateClassEnumerator returns S_FALSE on some Windows OS |
| 80 // when no camera exist. Therefore the FAILED macro can't be used. | 80 // when no camera exist. Therefore the FAILED macro can't be used. |
| 81 if (hr != S_OK) | 81 if (hr != S_OK) |
| 82 return hr; | 82 return hr; |
| 83 | 83 |
| 84 ScopedComPtr<IBaseFilter> capture_filter; | 84 ScopedComPtr<IBaseFilter> capture_filter; |
| 85 for (ScopedComPtr<IMoniker> moniker; | 85 for (ScopedComPtr<IMoniker> moniker; |
| 86 enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK; | 86 enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK; |
| 87 moniker.Release()) { | 87 moniker.Reset()) { |
| 88 ScopedComPtr<IPropertyBag> prop_bag; | 88 ScopedComPtr<IPropertyBag> prop_bag; |
| 89 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); | 89 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); |
| 90 if (FAILED(hr)) | 90 if (FAILED(hr)) |
| 91 continue; | 91 continue; |
| 92 | 92 |
| 93 // Find |device_id| via DevicePath, Description or FriendlyName, whichever | 93 // Find |device_id| via DevicePath, Description or FriendlyName, whichever |
| 94 // is available first and is a VT_BSTR (i.e. String) type. | 94 // is available first and is a VT_BSTR (i.e. String) type. |
| 95 static const wchar_t* kPropertyNames[] = { | 95 static const wchar_t* kPropertyNames[] = { |
| 96 L"DevicePath", L"Description", L"FriendlyName"}; | 96 L"DevicePath", L"Description", L"FriendlyName"}; |
| 97 | 97 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 while ((hr = pin_enum->Next(1, pin.Receive(), NULL)) == S_OK) { | 140 while ((hr = pin_enum->Next(1, pin.Receive(), NULL)) == S_OK) { |
| 141 PIN_DIRECTION this_pin_dir = static_cast<PIN_DIRECTION>(-1); | 141 PIN_DIRECTION this_pin_dir = static_cast<PIN_DIRECTION>(-1); |
| 142 hr = pin->QueryDirection(&this_pin_dir); | 142 hr = pin->QueryDirection(&this_pin_dir); |
| 143 if (pin_dir == this_pin_dir) { | 143 if (pin_dir == this_pin_dir) { |
| 144 if ((category == GUID_NULL || PinMatchesCategory(pin.get(), category)) && | 144 if ((category == GUID_NULL || PinMatchesCategory(pin.get(), category)) && |
| 145 (major_type == GUID_NULL || | 145 (major_type == GUID_NULL || |
| 146 PinMatchesMajorType(pin.get(), major_type))) { | 146 PinMatchesMajorType(pin.get(), major_type))) { |
| 147 return pin; | 147 return pin; |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 pin.Release(); | 150 pin.Reset(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 DCHECK(!pin.get()); | 153 DCHECK(!pin.get()); |
| 154 return pin; | 154 return pin; |
| 155 } | 155 } |
| 156 | 156 |
| 157 // static | 157 // static |
| 158 VideoPixelFormat | 158 VideoPixelFormat |
| 159 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( | 159 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( |
| 160 const GUID& sub_type) { | 160 const GUID& sub_type) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 if (sink_filter_.get()) { | 241 if (sink_filter_.get()) { |
| 242 graph_builder_->RemoveFilter(sink_filter_.get()); | 242 graph_builder_->RemoveFilter(sink_filter_.get()); |
| 243 sink_filter_ = NULL; | 243 sink_filter_ = NULL; |
| 244 } | 244 } |
| 245 | 245 |
| 246 if (capture_filter_.get()) | 246 if (capture_filter_.get()) |
| 247 graph_builder_->RemoveFilter(capture_filter_.get()); | 247 graph_builder_->RemoveFilter(capture_filter_.get()); |
| 248 } | 248 } |
| 249 | 249 |
| 250 if (capture_graph_builder_.get()) | 250 if (capture_graph_builder_.get()) |
| 251 capture_graph_builder_.Release(); | 251 capture_graph_builder_.Reset(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool VideoCaptureDeviceWin::Init() { | 254 bool VideoCaptureDeviceWin::Init() { |
| 255 DCHECK(thread_checker_.CalledOnValidThread()); | 255 DCHECK(thread_checker_.CalledOnValidThread()); |
| 256 HRESULT hr; | 256 HRESULT hr; |
| 257 | 257 |
| 258 hr = GetDeviceFilter(device_descriptor_.device_id, capture_filter_.Receive()); | 258 hr = GetDeviceFilter(device_descriptor_.device_id, capture_filter_.Receive()); |
| 259 DLOG_IF_FAILED_WITH_HRESULT("Failed to create capture filter", hr); | 259 DLOG_IF_FAILED_WITH_HRESULT("Failed to create capture filter", hr); |
| 260 if (!capture_filter_.get()) | 260 if (!capture_filter_.get()) |
| 261 return false; | 261 return false; |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 void VideoCaptureDeviceWin::SetErrorState( | 590 void VideoCaptureDeviceWin::SetErrorState( |
| 591 const tracked_objects::Location& from_here, | 591 const tracked_objects::Location& from_here, |
| 592 const std::string& reason, | 592 const std::string& reason, |
| 593 HRESULT hr) { | 593 HRESULT hr) { |
| 594 DCHECK(thread_checker_.CalledOnValidThread()); | 594 DCHECK(thread_checker_.CalledOnValidThread()); |
| 595 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); | 595 DLOG_IF_FAILED_WITH_HRESULT(reason, hr); |
| 596 state_ = kError; | 596 state_ = kError; |
| 597 client_->OnError(from_here, reason); | 597 client_->OnError(from_here, reason); |
| 598 } | 598 } |
| 599 } // namespace media | 599 } // namespace media |
| OLD | NEW |