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 DVPLOG_IF(2, FAILED(hr)) << "Failed to bind camera filter."; | 71 DVPLOG_IF(2, FAILED(hr)) << "Failed to bind camera filter."; |
73 break; | 72 break; |
74 } | 73 } |
75 } | 74 } |
76 moniker.Release(); | 75 moniker.Release(); |
77 } | 76 } |
78 | 77 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 if (capture_filter_) | 215 if (capture_filter_) |
217 graph_builder_->RemoveFilter(capture_filter_); | 216 graph_builder_->RemoveFilter(capture_filter_); |
218 | 217 |
219 if (mjpg_filter_) | 218 if (mjpg_filter_) |
220 graph_builder_->RemoveFilter(mjpg_filter_); | 219 graph_builder_->RemoveFilter(mjpg_filter_); |
221 } | 220 } |
222 } | 221 } |
223 | 222 |
224 bool VideoCaptureDeviceWin::Init() { | 223 bool VideoCaptureDeviceWin::Init() { |
225 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
226 HRESULT hr = GetDeviceFilter(device_name_, capture_filter_.Receive()); | 225 HRESULT hr = GetDeviceFilter(device_name_.id(), capture_filter_.Receive()); |
227 if (!capture_filter_) { | 226 if (!capture_filter_) { |
228 DVLOG(2) << "Failed to create capture filter."; | 227 DVLOG(2) << "Failed to create capture filter."; |
229 return false; | 228 return false; |
230 } | 229 } |
231 | 230 |
232 output_capture_pin_ = | 231 output_capture_pin_ = |
233 GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE); | 232 GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE); |
234 if (!output_capture_pin_) { | 233 if (!output_capture_pin_) { |
235 DVLOG(2) << "Failed to get capture output pin"; | 234 DVLOG(2) << "Failed to get capture output pin"; |
236 return false; | 235 return false; |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } | 551 } |
553 } | 552 } |
554 | 553 |
555 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { | 554 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { |
556 DCHECK(CalledOnValidThread()); | 555 DCHECK(CalledOnValidThread()); |
557 DVLOG(1) << reason; | 556 DVLOG(1) << reason; |
558 state_ = kError; | 557 state_ = kError; |
559 client_->OnError(reason); | 558 client_->OnError(reason); |
560 } | 559 } |
561 } // namespace media | 560 } // namespace media |
OLD | NEW |