Chromium Code Reviews| Index: media/video/capture/win/video_capture_device_win.cc |
| diff --git a/media/video/capture/win/video_capture_device_win.cc b/media/video/capture/win/video_capture_device_win.cc |
| index bd0446c9459717c4a358ad8e49bdf9b2b8bd7088..6a37253f9948e49a45aa71b992954fde7df79db4 100644 |
| --- a/media/video/capture/win/video_capture_device_win.cc |
| +++ b/media/video/capture/win/video_capture_device_win.cc |
| @@ -17,6 +17,15 @@ using base::win::ScopedVariant; |
| namespace { |
| +enum DeviceDriverType { |
| + kDirectShow, // DirectShow driver type |
|
tommi (sloooow) - chröme
2013/06/24 11:09:27
Some style issues but since we're switching on the
mcasas
2013/06/25 07:04:36
Done.
|
| + kMF, // Media Foundation type |
| +}; |
| +// Type of Device Driver (DirectShow, MediaFoundation) map and attribute. |
| +typedef std::map<std::string, DeviceDriverType> DeviceDriverTypeMap; |
| +DeviceDriverTypeMap device_driver_type_; |
|
tommi (sloooow) - chröme
2013/06/24 11:09:27
sorry, no global variables that require constructi
mcasas
2013/06/25 07:04:36
All right, quote our conversation later on, it sho
|
| + |
|
tommi (sloooow) - chröme
2013/06/24 11:09:27
nit: one empty line
mcasas
2013/06/25 07:04:36
Done.
|
| + |
| // Finds and creates a DirectShow Video Capture filter matching the device_name. |
| HRESULT GetDeviceFilter(const media::VideoCaptureDevice::Name& device_name, |
| IBaseFilter** filter) { |
| @@ -149,28 +158,60 @@ namespace media { |
| // static |
| void VideoCaptureDevice::GetDeviceNames(Names* device_names) { |
| + Names::iterator it; |
| + |
| if (VideoCaptureDeviceMFWin::PlatformSupported()) { |
| VideoCaptureDeviceMFWin::GetDeviceNames(device_names); |
| - } else { |
| - VideoCaptureDeviceWin::GetDeviceNames(device_names); |
| + it = device_names->begin(); |
| + for (; it != device_names->end(); ++it) |
| + device_driver_type_[it->unique_id] = kMF; |
|
tommi (sloooow) - chröme
2013/06/24 11:09:27
instead of the global map, what do you think about
mcasas
2013/06/25 07:04:36
I added the Capture Api type to VideoCaptureDevice
|
| + } |
| + // Retrieve the devices with DirectShow interface. They might (partially) |
| + // overlap, so the list has to be consolidated. |
| + Names temp_names; |
| + VideoCaptureDeviceWin::GetDeviceNames(&temp_names); |
| + |
| + // We need to merge the DS devices into the MF device list, and next remove |
| + // the duplicates, giving priority to the MF "versions". |
| + device_names->merge(temp_names); |
| + device_names->unique(); |
| + |
| + it = device_names->begin(); |
| + // Walk the device_names list and mark those not found in device_driver_ |
| + for (; it != device_names->end(); ++it) { |
| + if (device_driver_type_.find(it->unique_id) == device_driver_type_.end()) |
| + device_driver_type_[it->unique_id] = kDirectShow; |
| + } |
| + |
| + it = device_names->begin(); |
| + for (; it != device_names->end(); ++it) { |
| + DLOG(WARNING) |
| + << " Device " << it->unique_id << " is of type" |
| + << ((device_driver_type_[it->unique_id] == kMF) ? "MediaFoundation" |
| + : "DirectShow"); |
| } |
| } |
| // static |
| VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { |
| VideoCaptureDevice* ret = NULL; |
| - if (VideoCaptureDeviceMFWin::PlatformSupported()) { |
| + if (device_driver_type_.find(device_name.unique_id) != |
| + device_driver_type_.end()) |
| + return ret; |
| + |
| + if (device_driver_type_[device_name.unique_id] == kMF) { |
| scoped_ptr<VideoCaptureDeviceMFWin> device( |
| new VideoCaptureDeviceMFWin(device_name)); |
| if (device->Init()) |
| ret = device.release(); |
| - } else { |
| + } else if (device_driver_type_[device_name.unique_id] == kDirectShow) { |
| scoped_ptr<VideoCaptureDeviceWin> device( |
| new VideoCaptureDeviceWin(device_name)); |
| if (device->Init()) |
| ret = device.release(); |
| + } else { |
| + DLOG(ERROR) << "Couldn't recognize VideoCaptureDevice type!"; |
| } |
| - |
| return ret; |
| } |
| @@ -575,6 +616,10 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() { |
| capability.color = VideoCaptureCapability::kYUY2; |
| } else if (media_type->subtype == MEDIASUBTYPE_MJPG) { |
| capability.color = VideoCaptureCapability::kMJPEG; |
| + } else if (media_type->subtype == MEDIASUBTYPE_UYVY) { |
| + capability.color = VideoCaptureCapability::kUYVY; |
| + } else if (media_type->subtype == MEDIASUBTYPE_ARGB32) { |
| + capability.color = VideoCaptureCapability::kARGB; |
| } else { |
| WCHAR guid_str[128]; |
| StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str)); |
| @@ -596,5 +641,4 @@ void VideoCaptureDeviceWin::SetErrorState(const char* reason) { |
| state_ = kError; |
| observer_->OnError(); |
| } |
| - |
| } // namespace media |