Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_factory_win.h" | 5 #include "media/video/capture/win/video_capture_device_factory_win.h" |
| 6 | 6 |
| 7 #include <mfapi.h> | 7 #include <mfapi.h> |
| 8 #include <mferror.h> | 8 #include <mferror.h> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 } | 160 } |
| 161 | 161 |
| 162 static void GetDeviceNamesMediaFoundation( | 162 static void GetDeviceNamesMediaFoundation( |
| 163 VideoCaptureDevice::Names* device_names) { | 163 VideoCaptureDevice::Names* device_names) { |
| 164 DVLOG(1) << " GetDeviceNamesMediaFoundation"; | 164 DVLOG(1) << " GetDeviceNamesMediaFoundation"; |
| 165 ScopedCoMem<IMFActivate*> devices; | 165 ScopedCoMem<IMFActivate*> devices; |
| 166 UINT32 count; | 166 UINT32 count; |
| 167 if (!EnumerateVideoDevicesMediaFoundation(&devices, &count)) | 167 if (!EnumerateVideoDevicesMediaFoundation(&devices, &count)) |
| 168 return; | 168 return; |
| 169 | 169 |
| 170 HRESULT hr; | |
| 171 for (UINT32 i = 0; i < count; ++i) { | 170 for (UINT32 i = 0; i < count; ++i) { |
| 172 UINT32 name_size, id_size; | 171 ScopedCoMem<wchar_t> name; |
| 173 ScopedCoMem<wchar_t> name, id; | 172 UINT32 name_size; |
|
ddorwin
2014/07/08 18:17:50
nit: initialize? ditto for id_size.
Peter Kasting
2014/07/08 18:39:14
I'm happy to do so if you like; there's no need to
| |
| 174 if (SUCCEEDED(hr = devices[i]->GetAllocatedString( | 173 HRESULT hr = devices[i]->GetAllocatedString( |
| 175 MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &name, &name_size)) && | 174 MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME, &name, &name_size); |
| 176 SUCCEEDED(hr = devices[i]->GetAllocatedString( | 175 if (SUCCEEDED(hr)) { |
| 177 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id, | 176 ScopedCoMem<wchar_t> id; |
| 178 &id_size))) { | 177 UINT32 id_size; |
| 179 std::wstring name_w(name, name_size), id_w(id, id_size); | 178 hr = devices[i]->GetAllocatedString( |
| 180 VideoCaptureDevice::Name device(base::SysWideToUTF8(name_w), | 179 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id, |
| 181 base::SysWideToUTF8(id_w), | 180 &id_size); |
| 182 VideoCaptureDevice::Name::MEDIA_FOUNDATION); | 181 if (SUCCEEDED(hr)) { |
| 183 device_names->push_back(device); | 182 device_names->push_back(VideoCaptureDevice::Name( |
| 184 } else { | 183 base::SysWideToUTF8(std::wstring(name, name_size)), |
| 184 base::SysWideToUTF8(std::wstring(id, id_size)), | |
| 185 VideoCaptureDevice::Name::MEDIA_FOUNDATION)); | |
| 186 } | |
| 187 } | |
| 188 if (FAILED(hr)) | |
| 185 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; | 189 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; |
| 186 } | |
| 187 devices[i]->Release(); | 190 devices[i]->Release(); |
| 188 } | 191 } |
| 189 } | 192 } |
| 190 | 193 |
| 191 static void GetDeviceSupportedFormatsDirectShow( | 194 static void GetDeviceSupportedFormatsDirectShow( |
| 192 const VideoCaptureDevice::Name& device, | 195 const VideoCaptureDevice::Name& device, |
| 193 VideoCaptureFormats* formats) { | 196 VideoCaptureFormats* formats) { |
| 194 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name(); | 197 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name(); |
| 195 ScopedComPtr<ICreateDevEnum> dev_enum; | 198 ScopedComPtr<ICreateDevEnum> dev_enum; |
| 196 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, | 199 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 static void GetDeviceSupportedFormatsMediaFoundation( | 282 static void GetDeviceSupportedFormatsMediaFoundation( |
| 280 const VideoCaptureDevice::Name& device, | 283 const VideoCaptureDevice::Name& device, |
| 281 VideoCaptureFormats* formats) { | 284 VideoCaptureFormats* formats) { |
| 282 DVLOG(1) << "GetDeviceSupportedFormatsMediaFoundation for " << device.name(); | 285 DVLOG(1) << "GetDeviceSupportedFormatsMediaFoundation for " << device.name(); |
| 283 ScopedComPtr<IMFMediaSource> source; | 286 ScopedComPtr<IMFMediaSource> source; |
| 284 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), | 287 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), |
| 285 source.Receive())) { | 288 source.Receive())) { |
| 286 return; | 289 return; |
| 287 } | 290 } |
| 288 | 291 |
| 289 HRESULT hr; | |
| 290 base::win::ScopedComPtr<IMFSourceReader> reader; | 292 base::win::ScopedComPtr<IMFSourceReader> reader; |
| 291 if (FAILED(hr = MFCreateSourceReaderFromMediaSource(source, NULL, | 293 HRESULT hr = |
| 292 reader.Receive()))) { | 294 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive()); |
| 295 if (FAILED(hr)) { | |
| 293 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr; | 296 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr; |
| 294 return; | 297 return; |
| 295 } | 298 } |
| 296 | 299 |
| 297 DWORD stream_index = 0; | 300 DWORD stream_index = 0; |
| 298 ScopedComPtr<IMFMediaType> type; | 301 ScopedComPtr<IMFMediaType> type; |
| 299 while (SUCCEEDED(hr = reader->GetNativeMediaType( | 302 for (hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, |
| 300 MF_SOURCE_READER_FIRST_VIDEO_STREAM, stream_index, type.Receive()))) { | 303 type.Receive()); |
| 304 SUCCEEDED(hr); | |
| 305 hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, | |
| 306 type.Receive())) { | |
| 301 UINT32 width, height; | 307 UINT32 width, height; |
| 302 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); | 308 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); |
| 303 if (FAILED(hr)) { | 309 if (FAILED(hr)) { |
| 304 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; | 310 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; |
| 305 return; | 311 return; |
| 306 } | 312 } |
| 307 VideoCaptureFormat capture_format; | 313 VideoCaptureFormat capture_format; |
| 308 capture_format.frame_size.SetSize(width, height); | 314 capture_format.frame_size.SetSize(width, height); |
| 309 | 315 |
| 310 UINT32 numerator, denominator; | 316 UINT32 numerator, denominator; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 DCHECK(PlatformSupportsMediaFoundation()); | 379 DCHECK(PlatformSupportsMediaFoundation()); |
| 374 device.reset(new VideoCaptureDeviceMFWin(device_name)); | 380 device.reset(new VideoCaptureDeviceMFWin(device_name)); |
| 375 DVLOG(1) << " MediaFoundation Device: " << device_name.name(); | 381 DVLOG(1) << " MediaFoundation Device: " << device_name.name(); |
| 376 ScopedComPtr<IMFMediaSource> source; | 382 ScopedComPtr<IMFMediaSource> source; |
| 377 if (!CreateVideoCaptureDeviceMediaFoundation(device_name.id().c_str(), | 383 if (!CreateVideoCaptureDeviceMediaFoundation(device_name.id().c_str(), |
| 378 source.Receive())) { | 384 source.Receive())) { |
| 379 return scoped_ptr<VideoCaptureDevice>(); | 385 return scoped_ptr<VideoCaptureDevice>(); |
| 380 } | 386 } |
| 381 if (!static_cast<VideoCaptureDeviceMFWin*>(device.get())->Init(source)) | 387 if (!static_cast<VideoCaptureDeviceMFWin*>(device.get())->Init(source)) |
| 382 device.reset(); | 388 device.reset(); |
| 383 } else if (device_name.capture_api_type() == | 389 } else { |
| 384 VideoCaptureDevice::Name::DIRECT_SHOW) { | 390 DCHECK_EQ(VideoCaptureDevice::Name::DIRECT_SHOW, |
|
ddorwin
2014/07/08 18:17:50
nit: media/ code prefers "var, const" for code exc
Peter Kasting
2014/07/08 18:39:14
Done.
| |
| 391 device_name.capture_api_type()); | |
| 385 device.reset(new VideoCaptureDeviceWin(device_name)); | 392 device.reset(new VideoCaptureDeviceWin(device_name)); |
| 386 DVLOG(1) << " DirectShow Device: " << device_name.name(); | 393 DVLOG(1) << " DirectShow Device: " << device_name.name(); |
| 387 if (!static_cast<VideoCaptureDeviceWin*>(device.get())->Init()) | 394 if (!static_cast<VideoCaptureDeviceWin*>(device.get())->Init()) |
| 388 device.reset(); | 395 device.reset(); |
| 389 } else { | |
| 390 NOTREACHED() << " Couldn't recognize VideoCaptureDevice type"; | |
| 391 } | 396 } |
| 392 return device.Pass(); | 397 return device.Pass(); |
| 393 } | 398 } |
| 394 | 399 |
| 395 void VideoCaptureDeviceFactoryWin::GetDeviceNames( | 400 void VideoCaptureDeviceFactoryWin::GetDeviceNames( |
| 396 VideoCaptureDevice::Names* device_names) { | 401 VideoCaptureDevice::Names* device_names) { |
| 397 DCHECK(thread_checker_.CalledOnValidThread()); | 402 DCHECK(thread_checker_.CalledOnValidThread()); |
| 398 if (use_media_foundation_) | 403 if (use_media_foundation_) |
| 399 GetDeviceNamesMediaFoundation(device_names); | 404 GetDeviceNamesMediaFoundation(device_names); |
| 400 else | 405 else |
| 401 GetDeviceNamesDirectShow(device_names); | 406 GetDeviceNamesDirectShow(device_names); |
| 402 } | 407 } |
| 403 | 408 |
| 404 void VideoCaptureDeviceFactoryWin::GetDeviceSupportedFormats( | 409 void VideoCaptureDeviceFactoryWin::GetDeviceSupportedFormats( |
| 405 const VideoCaptureDevice::Name& device, | 410 const VideoCaptureDevice::Name& device, |
| 406 VideoCaptureFormats* formats) { | 411 VideoCaptureFormats* formats) { |
| 407 DCHECK(thread_checker_.CalledOnValidThread()); | 412 DCHECK(thread_checker_.CalledOnValidThread()); |
| 408 if (use_media_foundation_) | 413 if (use_media_foundation_) |
| 409 GetDeviceSupportedFormatsMediaFoundation(device, formats); | 414 GetDeviceSupportedFormatsMediaFoundation(device, formats); |
| 410 else | 415 else |
| 411 GetDeviceSupportedFormatsDirectShow(device, formats); | 416 GetDeviceSupportedFormatsDirectShow(device, formats); |
| 412 } | 417 } |
| 413 | 418 |
| 414 } // namespace media | 419 } // namespace media |
| OLD | NEW |