Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: media/video/capture/win/video_capture_device_factory_win.cc

Issue 328463002: VideoCaptureDevice Win: Enumerate devices' supported formats when they don't have a DevicePath prop… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rational frame rates. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 int index = 0; 212 int index = 0;
213 ScopedVariant device_id; 213 ScopedVariant device_id;
214 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) { 214 while (enum_moniker->Next(1, moniker.Receive(), NULL) == S_OK) {
215 ScopedComPtr<IPropertyBag> prop_bag; 215 ScopedComPtr<IPropertyBag> prop_bag;
216 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid()); 216 hr = moniker->BindToStorage(0, 0, IID_IPropertyBag, prop_bag.ReceiveVoid());
217 if (FAILED(hr)) { 217 if (FAILED(hr)) {
218 moniker.Release(); 218 moniker.Release();
219 continue; 219 continue;
220 } 220 }
221 221
222 std::string id;
222 device_id.Reset(); 223 device_id.Reset();
223 hr = prop_bag->Read(L"DevicePath", device_id.Receive(), 0); 224 hr = prop_bag->Read(L"DevicePath", device_id.Receive(), 0);
224 if (FAILED(hr)) { 225 if (FAILED(hr) || device_id.type() != VT_BSTR) {
225 DVLOG(1) << "Couldn't read a device's DevicePath."; 226 // If there is no clear DevicePath, try with Description and FriendlyName.
tommi (sloooow) - chröme 2014/06/10 07:36:29 Is fetching the Description before FriendlyName th
mcasas 2014/06/10 15:01:14 The idea/sinppet comes from l.128-l.130 of this fi
226 return; 227 ScopedVariant name;
228 if (SUCCEEDED(prop_bag->Read(L"Description", name.Receive(), 0)) ||
229 SUCCEEDED(prop_bag->Read(L"FriendlyName", name.Receive(), 0))) {
230 id = base::SysWideToUTF8(V_BSTR(&name));
231 }
232 } else {
233 DCHECK_EQ(device_id.type(), VT_BSTR);
234 id = base::SysWideToUTF8(V_BSTR(&device_id));
227 } 235 }
228 if (device.id() == base::SysWideToUTF8(V_BSTR(&device_id))) 236
237 if (device.id() == id)
229 break; 238 break;
230 moniker.Release(); 239 moniker.Release();
231 } 240 }
232 241
233 if (moniker.get()) { 242 if (moniker.get()) {
234 base::win::ScopedComPtr<IBaseFilter> capture_filter; 243 base::win::ScopedComPtr<IBaseFilter> capture_filter;
235 hr = VideoCaptureDeviceWin::GetDeviceFilter(device, 244 hr = VideoCaptureDeviceWin::GetDeviceFilter(device,
236 capture_filter.Receive()); 245 capture_filter.Receive());
237 if (!capture_filter) { 246 if (!capture_filter) {
238 DVLOG(2) << "Failed to create capture filter."; 247 DVLOG(2) << "Failed to create capture filter.";
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( 290 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat(
282 media_type->subtype); 291 media_type->subtype);
283 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN) 292 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN)
284 continue; 293 continue;
285 VIDEOINFOHEADER* h = 294 VIDEOINFOHEADER* h =
286 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); 295 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat);
287 format.frame_size.SetSize(h->bmiHeader.biWidth, 296 format.frame_size.SetSize(h->bmiHeader.biWidth,
288 h->bmiHeader.biHeight); 297 h->bmiHeader.biHeight);
289 // Trust the frame rate from the VIDEOINFOHEADER. 298 // Trust the frame rate from the VIDEOINFOHEADER.
290 format.frame_rate = (h->AvgTimePerFrame > 0) ? 299 format.frame_rate = (h->AvgTimePerFrame > 0) ?
291 static_cast<int>(kSecondsToReferenceTime / h->AvgTimePerFrame) : 300 (kSecondsToReferenceTime / static_cast<float>(h->AvgTimePerFrame)) :
tommi (sloooow) - chröme 2014/06/10 07:36:29 nit: extra parenthesis aren't needed
mcasas 2014/06/10 15:01:14 Done.
292 0; 301 0.0;
302
293 formats->push_back(format); 303 formats->push_back(format);
294 DVLOG(1) << device.name() << " resolution: " 304 DVLOG(1) << device.name() << " resolution: "
295 << format.frame_size.ToString() << ", fps: " << format.frame_rate 305 << format.frame_size.ToString() << ", fps: " << format.frame_rate
296 << ", pixel format: " << format.pixel_format; 306 << ", pixel format: " << format.pixel_format;
297 } 307 }
298 } 308 }
299 } 309 }
300 } 310 }
301 311
302 static void GetDeviceSupportedFormatsMediaFoundation( 312 static void GetDeviceSupportedFormatsMediaFoundation(
(...skipping 26 matching lines...) Expand all
329 } 339 }
330 VideoCaptureFormat capture_format; 340 VideoCaptureFormat capture_format;
331 capture_format.frame_size.SetSize(width, height); 341 capture_format.frame_size.SetSize(width, height);
332 342
333 UINT32 numerator, denominator; 343 UINT32 numerator, denominator;
334 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator); 344 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator);
335 if (FAILED(hr)) { 345 if (FAILED(hr)) {
336 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 346 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr;
337 return; 347 return;
338 } 348 }
339 capture_format.frame_rate = denominator ? numerator / denominator : 0; 349 capture_format.frame_rate = denominator ?
350 numerator / static_cast<float>(denominator) : 0.0f;
340 351
341 GUID type_guid; 352 GUID type_guid;
342 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid); 353 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid);
343 if (FAILED(hr)) { 354 if (FAILED(hr)) {
344 DLOG(ERROR) << "GetGUID: " << std::hex << hr; 355 DLOG(ERROR) << "GetGUID: " << std::hex << hr;
345 return; 356 return;
346 } 357 }
347 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, 358 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid,
348 &capture_format.pixel_format); 359 &capture_format.pixel_format);
349 type.Release(); 360 type.Release();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 const VideoCaptureDevice::Name& device, 438 const VideoCaptureDevice::Name& device,
428 VideoCaptureFormats* formats) { 439 VideoCaptureFormats* formats) {
429 DCHECK(thread_checker_.CalledOnValidThread()); 440 DCHECK(thread_checker_.CalledOnValidThread());
430 if (use_media_foundation_) 441 if (use_media_foundation_)
431 GetDeviceSupportedFormatsMediaFoundation(device, formats); 442 GetDeviceSupportedFormatsMediaFoundation(device, formats);
432 else 443 else
433 GetDeviceSupportedFormatsDirectShow(device, formats); 444 GetDeviceSupportedFormatsDirectShow(device, formats);
434 } 445 }
435 446
436 } // namespace media 447 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698