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 <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 CoTaskMemFree(mt); | 142 CoTaskMemFree(mt); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace | 146 } // namespace |
| 147 | 147 |
| 148 namespace media { | 148 namespace media { |
| 149 | 149 |
| 150 // static | 150 // static |
| 151 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { | 151 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { |
| 152 Names::iterator it; | |
| 153 | |
| 152 if (VideoCaptureDeviceMFWin::PlatformSupported()) { | 154 if (VideoCaptureDeviceMFWin::PlatformSupported()) { |
| 153 VideoCaptureDeviceMFWin::GetDeviceNames(device_names); | 155 VideoCaptureDeviceMFWin::GetDeviceNames(device_names); |
| 154 } else { | 156 it = device_names->begin(); |
| 155 VideoCaptureDeviceWin::GetDeviceNames(device_names); | 157 for (; it != device_names->end(); ++it) |
| 158 it->capture_api_type = Name::MEDIA_FOUNDATION; | |
| 156 } | 159 } |
| 160 // Retrieve the devices with DirectShow (DS) interface. They might (partially) | |
| 161 // overlap with the MediaFoundation (MF), so the list has to be consolidated. | |
| 162 Names temp_names; | |
| 163 VideoCaptureDeviceWin::GetDeviceNames(&temp_names); | |
| 164 it = device_names->begin(); | |
| 165 | |
| 166 // Merge the DS devices into the MF device list, and next remove | |
| 167 // the duplicates, giving priority to the MF "versions". | |
| 168 device_names->merge(temp_names); | |
| 169 device_names->unique(); | |
| 157 } | 170 } |
| 158 | 171 |
| 159 // static | 172 // static |
| 160 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { | 173 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { |
| 161 VideoCaptureDevice* ret = NULL; | 174 VideoCaptureDevice* ret = NULL; |
| 175 Names::iterator it; | |
|
tommi (sloooow) - chröme
2013/06/26 09:57:27
you shouldn't need to do any enumeration or search
mcasas
2013/07/02 12:28:11
Done.
| |
| 176 Names device_names; | |
| 177 | |
| 178 // We search for the device name in the list of devices that MF Api gives. | |
| 162 if (VideoCaptureDeviceMFWin::PlatformSupported()) { | 179 if (VideoCaptureDeviceMFWin::PlatformSupported()) { |
| 163 scoped_ptr<VideoCaptureDeviceMFWin> device( | 180 VideoCaptureDeviceMFWin::GetDeviceNames(&device_names); |
| 164 new VideoCaptureDeviceMFWin(device_name)); | 181 it = device_names.begin(); |
| 165 if (device->Init()) | 182 for (; it != device_names.end(); ++it) |
| 166 ret = device.release(); | 183 if (*it == device_name) { |
| 167 } else { | 184 DLOG(WARNING) << " MediaFoundation Device: " << device_name.device_name; |
| 168 scoped_ptr<VideoCaptureDeviceWin> device( | 185 scoped_ptr<VideoCaptureDeviceMFWin> device( |
| 169 new VideoCaptureDeviceWin(device_name)); | 186 new VideoCaptureDeviceMFWin(device_name)); |
| 170 if (device->Init()) | 187 if (device->Init()) |
| 171 ret = device.release(); | 188 ret = device.release(); |
| 189 return ret; | |
| 190 } | |
| 172 } | 191 } |
| 192 VideoCaptureDeviceWin::GetDeviceNames(&device_names); | |
| 193 it = device_names.begin(); | |
| 194 for (; it != device_names.end(); ++it) | |
| 195 if (*it == device_name) { | |
| 196 DLOG(WARNING) << " DirectShow Device: " << device_name.device_name; | |
| 197 scoped_ptr<VideoCaptureDeviceWin> device( | |
| 198 new VideoCaptureDeviceWin(device_name)); | |
| 199 if (device->Init()) | |
| 200 ret = device.release(); | |
| 201 return ret; | |
| 202 } | |
| 173 | 203 |
| 204 DLOG(ERROR) << "Couldn't recognize VideoCaptureDevice type!"; | |
| 174 return ret; | 205 return ret; |
| 175 } | 206 } |
| 176 | 207 |
| 177 // static | 208 // static |
| 178 void VideoCaptureDeviceWin::GetDeviceNames(Names* device_names) { | 209 void VideoCaptureDeviceWin::GetDeviceNames(Names* device_names) { |
| 179 DCHECK(device_names); | 210 DCHECK(device_names); |
| 180 | 211 |
| 181 ScopedComPtr<ICreateDevEnum> dev_enum; | 212 ScopedComPtr<ICreateDevEnum> dev_enum; |
| 182 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, | 213 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, |
| 183 CLSCTX_INPROC); | 214 CLSCTX_INPROC); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 capability.color = VideoCaptureCapability::kI420; | 599 capability.color = VideoCaptureCapability::kI420; |
| 569 } else if (media_type->subtype == MEDIASUBTYPE_IYUV) { | 600 } else if (media_type->subtype == MEDIASUBTYPE_IYUV) { |
| 570 // This is identical to kI420. | 601 // This is identical to kI420. |
| 571 capability.color = VideoCaptureCapability::kI420; | 602 capability.color = VideoCaptureCapability::kI420; |
| 572 } else if (media_type->subtype == MEDIASUBTYPE_RGB24) { | 603 } else if (media_type->subtype == MEDIASUBTYPE_RGB24) { |
| 573 capability.color = VideoCaptureCapability::kRGB24; | 604 capability.color = VideoCaptureCapability::kRGB24; |
| 574 } else if (media_type->subtype == MEDIASUBTYPE_YUY2) { | 605 } else if (media_type->subtype == MEDIASUBTYPE_YUY2) { |
| 575 capability.color = VideoCaptureCapability::kYUY2; | 606 capability.color = VideoCaptureCapability::kYUY2; |
| 576 } else if (media_type->subtype == MEDIASUBTYPE_MJPG) { | 607 } else if (media_type->subtype == MEDIASUBTYPE_MJPG) { |
| 577 capability.color = VideoCaptureCapability::kMJPEG; | 608 capability.color = VideoCaptureCapability::kMJPEG; |
| 609 } else if (media_type->subtype == MEDIASUBTYPE_UYVY) { | |
| 610 capability.color = VideoCaptureCapability::kUYVY; | |
| 611 } else if (media_type->subtype == MEDIASUBTYPE_ARGB32) { | |
| 612 capability.color = VideoCaptureCapability::kARGB; | |
| 578 } else { | 613 } else { |
| 579 WCHAR guid_str[128]; | 614 WCHAR guid_str[128]; |
| 580 StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str)); | 615 StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str)); |
| 581 DVLOG(2) << "Device support unknown media type " << guid_str; | 616 DVLOG(2) << "Device support unknown media type " << guid_str; |
| 582 continue; | 617 continue; |
| 583 } | 618 } |
| 584 capabilities_.Add(capability); | 619 capabilities_.Add(capability); |
| 585 } | 620 } |
| 586 DeleteMediaType(media_type); | 621 DeleteMediaType(media_type); |
| 587 media_type = NULL; | 622 media_type = NULL; |
| 588 } | 623 } |
| 589 | 624 |
| 590 return !capabilities_.empty(); | 625 return !capabilities_.empty(); |
| 591 } | 626 } |
| 592 | 627 |
| 593 void VideoCaptureDeviceWin::SetErrorState(const char* reason) { | 628 void VideoCaptureDeviceWin::SetErrorState(const char* reason) { |
| 594 DCHECK(CalledOnValidThread()); | 629 DCHECK(CalledOnValidThread()); |
| 595 DVLOG(1) << reason; | 630 DVLOG(1) << reason; |
| 596 state_ = kError; | 631 state_ = kError; |
| 597 observer_->OnError(); | 632 observer_->OnError(); |
| 598 } | 633 } |
| 599 | |
| 600 } // namespace media | 634 } // namespace media |
| OLD | NEW |