| 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> |
| 11 #include <list> | 11 #include <list> |
| 12 | 12 |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/win/scoped_co_mem.h" | 14 #include "base/win/scoped_co_mem.h" |
| 15 #include "base/win/scoped_variant.h" | 15 #include "base/win/scoped_variant.h" |
| 16 #include "media/video/capture/win/video_capture_device_mf_win.h" | 16 #include "media/video/capture/win/video_capture_device_mf_win.h" |
| 17 | 17 |
| 18 using base::win::ScopedCoMem; | 18 using base::win::ScopedCoMem; |
| 19 using base::win::ScopedComPtr; | 19 using base::win::ScopedComPtr; |
| 20 using base::win::ScopedVariant; | 20 using base::win::ScopedVariant; |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 | 23 |
| 24 // Finds and creates a DirectShow Video Capture filter matching the device_name. | 24 // Finds and creates a DirectShow Video Capture filter matching the device_name. |
| 25 // static | 25 // static |
| 26 HRESULT VideoCaptureDeviceWin::GetDeviceFilter( | 26 HRESULT VideoCaptureDeviceWin::GetDeviceFilter(const std::string& device_id, |
| 27 const VideoCaptureDevice::Name& device_name, | 27 IBaseFilter** filter) { |
| 28 IBaseFilter** filter) { | |
| 29 DCHECK(filter); | 28 DCHECK(filter); |
| 30 | 29 |
| 31 ScopedComPtr<ICreateDevEnum> dev_enum; | 30 ScopedComPtr<ICreateDevEnum> dev_enum; |
| 32 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, | 31 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, |
| 33 CLSCTX_INPROC); | 32 CLSCTX_INPROC); |
| 34 if (FAILED(hr)) | 33 if (FAILED(hr)) |
| 35 return hr; | 34 return hr; |
| 36 | 35 |
| 37 ScopedComPtr<IEnumMoniker> enum_moniker; | 36 ScopedComPtr<IEnumMoniker> enum_moniker; |
| 38 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, | 37 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 58 static const wchar_t* kPropertyNames[] = { | 57 static const wchar_t* kPropertyNames[] = { |
| 59 L"DevicePath", L"Description", L"FriendlyName" | 58 L"DevicePath", L"Description", L"FriendlyName" |
| 60 }; | 59 }; |
| 61 ScopedVariant name; | 60 ScopedVariant name; |
| 62 for (size_t i = 0; | 61 for (size_t i = 0; |
| 63 i < arraysize(kPropertyNames) && name.type() != VT_BSTR; ++i) { | 62 i < arraysize(kPropertyNames) && name.type() != VT_BSTR; ++i) { |
| 64 prop_bag->Read(kPropertyNames[i], name.Receive(), 0); | 63 prop_bag->Read(kPropertyNames[i], name.Receive(), 0); |
| 65 } | 64 } |
| 66 if (name.type() == VT_BSTR) { | 65 if (name.type() == VT_BSTR) { |
| 67 std::string device_path(base::SysWideToUTF8(V_BSTR(&name))); | 66 std::string device_path(base::SysWideToUTF8(V_BSTR(&name))); |
| 68 if (device_path.compare(device_name.id()) == 0) { | 67 if (device_path.compare(device_id) == 0) { |
| 69 // We have found the requested device | 68 // We have found the requested device |
| 70 hr = moniker->BindToObject(0, 0, IID_IBaseFilter, | 69 hr = moniker->BindToObject(0, 0, IID_IBaseFilter, |
| 71 capture_filter.ReceiveVoid()); | 70 capture_filter.ReceiveVoid()); |
| 72 DLOG_IF(ERROR, FAILED(hr)) << "Failed to bind camera filter: " | 71 DLOG_IF(ERROR, FAILED(hr)) << "Failed to bind camera filter: " |
| 73 << logging::SystemErrorCodeToString(hr); | 72 << logging::SystemErrorCodeToString(hr); |
| 74 break; | 73 break; |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 moniker.Release(); | 76 moniker.Release(); |
| 78 } | 77 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 if (capture_filter_) | 216 if (capture_filter_) |
| 218 graph_builder_->RemoveFilter(capture_filter_); | 217 graph_builder_->RemoveFilter(capture_filter_); |
| 219 | 218 |
| 220 if (mjpg_filter_) | 219 if (mjpg_filter_) |
| 221 graph_builder_->RemoveFilter(mjpg_filter_); | 220 graph_builder_->RemoveFilter(mjpg_filter_); |
| 222 } | 221 } |
| 223 } | 222 } |
| 224 | 223 |
| 225 bool VideoCaptureDeviceWin::Init() { | 224 bool VideoCaptureDeviceWin::Init() { |
| 226 DCHECK(CalledOnValidThread()); | 225 DCHECK(CalledOnValidThread()); |
| 227 HRESULT hr = GetDeviceFilter(device_name_, capture_filter_.Receive()); | 226 HRESULT hr = GetDeviceFilter(device_name_.id(), capture_filter_.Receive()); |
| 228 if (!capture_filter_) { | 227 if (!capture_filter_) { |
| 229 DLOG(ERROR) << "Failed to create capture filter: " | 228 DLOG(ERROR) << "Failed to create capture filter: " |
| 230 << logging::SystemErrorCodeToString(hr); | 229 << logging::SystemErrorCodeToString(hr); |
| 231 return false; | 230 return false; |
| 232 } | 231 } |
| 233 | 232 |
| 234 output_capture_pin_ = | 233 output_capture_pin_ = |
| 235 GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE); | 234 GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE); |
| 236 if (!output_capture_pin_) { | 235 if (!output_capture_pin_) { |
| 237 DLOG(ERROR) << "Failed to get capture output pin"; | 236 DLOG(ERROR) << "Failed to get capture output pin"; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 DVLOG(2) << "Anti-flicker setting not supported."; | 560 DVLOG(2) << "Anti-flicker setting not supported."; |
| 562 } | 561 } |
| 563 } | 562 } |
| 564 | 563 |
| 565 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { | 564 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { |
| 566 DCHECK(CalledOnValidThread()); | 565 DCHECK(CalledOnValidThread()); |
| 567 state_ = kError; | 566 state_ = kError; |
| 568 client_->OnError(reason); | 567 client_->OnError(reason); |
| 569 } | 568 } |
| 570 } // namespace media | 569 } // namespace media |
| OLD | NEW |