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

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

Issue 149443003: Add GetDeviceSupportedFormats to VideoCaptureDeviceMFWin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: scherkus@ nit Created 6 years, 10 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
OLDNEW
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_mf_win.h" 5 #include "media/video/capture/win/video_capture_device_mf_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/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 Name device(base::SysWideToUTF8(name_w), base::SysWideToUTF8(id_w), 279 Name device(base::SysWideToUTF8(name_w), base::SysWideToUTF8(id_w),
280 Name::MEDIA_FOUNDATION); 280 Name::MEDIA_FOUNDATION);
281 device_names->push_back(device); 281 device_names->push_back(device);
282 } else { 282 } else {
283 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; 283 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr;
284 } 284 }
285 devices[i]->Release(); 285 devices[i]->Release();
286 } 286 }
287 } 287 }
288 288
289 // static
290 void VideoCaptureDeviceMFWin::GetDeviceSupportedFormats(const Name& device,
291 VideoCaptureFormats* formats) {
292 ScopedComPtr<IMFMediaSource> source;
293 if (!CreateVideoCaptureDevice(device.id().c_str(), source.Receive()))
294 return;
295
296 HRESULT hr;
297 base::win::ScopedComPtr<IMFSourceReader> reader;
298 if (FAILED(hr = MFCreateSourceReaderFromMediaSource(source, NULL,
299 reader.Receive()))) {
300 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr;
301 return;
302 }
303
304 DWORD stream_index = 0;
305 ScopedComPtr<IMFMediaType> type;
306 while (SUCCEEDED(hr = reader->GetNativeMediaType(
307 MF_SOURCE_READER_FIRST_VIDEO_STREAM, stream_index, type.Receive()))) {
308 UINT32 width, height;
309 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height);
310 if (FAILED(hr)) {
311 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr;
312 return;
313 }
314 VideoCaptureFormat capture_format;
315 capture_format.frame_size.SetSize(width, height);
316
317 UINT32 numerator, denominator;
318 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator);
319 if (FAILED(hr)) {
320 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr;
321 return;
322 }
323 capture_format.frame_rate = denominator ? numerator / denominator : 0;
324
325 GUID type_guid;
326 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid);
327 if (FAILED(hr)) {
328 DLOG(ERROR) << "GetGUID: " << std::hex << hr;
329 return;
330 }
331 FormatFromGuid(type_guid, &capture_format.pixel_format);
332 type.Release();
333 formats->push_back(capture_format);
334 ++stream_index;
335
336 DVLOG(1) << device.name() << " resolution: "
337 << capture_format.frame_size.ToString() << ", fps: "
338 << capture_format.frame_rate << ", pixel format: "
339 << capture_format.pixel_format;
340 }
341 }
342
289 const std::string VideoCaptureDevice::Name::GetModel() const { 343 const std::string VideoCaptureDevice::Name::GetModel() const {
290 const size_t vid_prefix_size = sizeof(kVidPrefix) - 1; 344 const size_t vid_prefix_size = sizeof(kVidPrefix) - 1;
291 const size_t pid_prefix_size = sizeof(kPidPrefix) - 1; 345 const size_t pid_prefix_size = sizeof(kPidPrefix) - 1;
292 const size_t vid_location = unique_id_.find(kVidPrefix); 346 const size_t vid_location = unique_id_.find(kVidPrefix);
293 if (vid_location == std::string::npos || 347 if (vid_location == std::string::npos ||
294 vid_location + vid_prefix_size + kVidPidSize > unique_id_.size()) { 348 vid_location + vid_prefix_size + kVidPidSize > unique_id_.size()) {
295 return ""; 349 return "";
296 } 350 }
297 const size_t pid_location = unique_id_.find(kPidPrefix); 351 const size_t pid_location = unique_id_.find(kPidPrefix);
298 if (pid_location == std::string::npos || 352 if (pid_location == std::string::npos ||
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 } 485 }
432 } 486 }
433 487
434 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { 488 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) {
435 DLOG(ERROR) << "VideoCaptureDeviceMFWin: " << std::hex << hr; 489 DLOG(ERROR) << "VideoCaptureDeviceMFWin: " << std::hex << hr;
436 if (client_.get()) 490 if (client_.get())
437 client_->OnError(); 491 client_->OnError();
438 } 492 }
439 493
440 } // namespace media 494 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/win/video_capture_device_mf_win.h ('k') | media/video/capture/win/video_capture_device_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698