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

Unified 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: Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: media/video/capture/win/video_capture_device_mf_win.cc
diff --git a/media/video/capture/win/video_capture_device_mf_win.cc b/media/video/capture/win/video_capture_device_mf_win.cc
index f4007fab81283da8033f5668ad8e9e6a6db2813d..ce20fde98b365d4f307e725547c10bd669bb5969 100644
--- a/media/video/capture/win/video_capture_device_mf_win.cc
+++ b/media/video/capture/win/video_capture_device_mf_win.cc
@@ -286,6 +286,60 @@ void VideoCaptureDeviceMFWin::GetDeviceNames(Names* device_names) {
}
}
+//static
tommi (sloooow) - chröme 2014/01/30 13:25:17 // static
mcasas 2014/01/30 16:29:23 Done.
+void VideoCaptureDeviceMFWin::GetDeviceSupportedFormats(const Name& device,
+ VideoCaptureFormats* formats) {
+
+ ScopedComPtr<IMFMediaSource> source;
+ if (!CreateVideoCaptureDevice(device.id().c_str(), source.Receive()))
+ return;
+
+ HRESULT hr;
+ base::win::ScopedComPtr<IMFSourceReader> reader;
+ if (!SUCCEEDED(hr = MFCreateSourceReaderFromMediaSource(source, NULL,
tommi (sloooow) - chröme 2014/01/30 13:25:17 instead of "if (!SUCCEEDED" use "if (FAILED"
mcasas 2014/01/30 16:29:23 Done.
+ reader.Receive()))) {
+ DLOG(WARNING) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr;
tommi (sloooow) - chröme 2014/01/30 13:25:17 you must bail out at this point. If MFCreateSourc
mcasas 2014/01/30 16:29:23 Done.
+ }
+
+ DWORD stream_index = 0;
+ ScopedComPtr<IMFMediaType> type;
+ GUID type_guid;
tommi (sloooow) - chröme 2014/01/30 13:25:17 For these variable definitions (type_guid, width,
mcasas 2014/01/30 16:29:23 Moved closest to their use.
+ UINT32 width, height, numerator, denominator;
+ while (SUCCEEDED(hr = reader->GetNativeMediaType(
+ MF_SOURCE_READER_FIRST_VIDEO_STREAM, stream_index, type.Receive()))) {
tommi (sloooow) - chröme 2014/01/30 13:25:17 strange indent
mcasas 2014/01/30 16:29:23 Done.
+
tommi (sloooow) - chröme 2014/01/30 13:25:17 remove empty line.
mcasas 2014/01/30 16:29:23 Done.
+ VideoCaptureFormat capture_format;
tommi (sloooow) - chröme 2014/01/30 13:25:17 define this variable where you need it (smallest s
+
+ if (FAILED(hr = MFGetAttributeSize(
+ type, MF_MT_FRAME_SIZE, &width, &height))) {
tommi (sloooow) - chröme 2014/01/30 13:25:17 I would prefer to format this as: if (FAILED(
mcasas 2014/01/30 16:29:23 Done.
+ DLOG(WARNING) << "MFGetAttributeSize: " << std::hex << hr;
tommi (sloooow) - chröme 2014/01/30 13:25:17 DLOG(ERROR)
mcasas 2014/01/30 16:29:23 Done.
+ return;
+ }
+ capture_format.frame_size.SetSize(width, height);
+ if (FAILED(hr = MFGetAttributeRatio(
+ type, MF_MT_FRAME_RATE, &numerator, &denominator))) {
+ DLOG(WARNING) << "MFGetAttributeSize: " << std::hex << hr;
tommi (sloooow) - chröme 2014/01/30 13:25:17 DLOG(ERROR)
mcasas 2014/01/30 16:29:23 Done.
+ return;
+ }
+ capture_format.frame_rate = denominator ? numerator/denominator : 0;
+
+ if (FAILED(hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid))) {
+ DLOG(WARNING) << "GetGUID: " << std::hex << hr;
tommi (sloooow) - chröme 2014/01/30 13:25:17 DLOG(ERROR)
mcasas 2014/01/30 16:29:23 Done.
+ return;
+ }
+ FormatFromGuid(type_guid, &capture_format.pixel_format);
+ type.Release();
+ formats->push_back(capture_format);
+ stream_index++;
tommi (sloooow) - chröme 2014/01/30 13:25:17 nit: ++stream_index;
mcasas 2014/01/30 16:29:23 Done.
+
+ DVLOG(1) << device.name() << " resolution: "
+ << capture_format.frame_size.ToString() << ", fps: "
+ << capture_format.frame_rate << ", pixel format: "
+ << capture_format.pixel_format;
+ }
+ return;
tommi (sloooow) - chröme 2014/01/30 13:25:17 remove
mcasas 2014/01/30 16:29:23 Done.
+}
+
const std::string VideoCaptureDevice::Name::GetModel() const {
const size_t vid_prefix_size = sizeof(kVidPrefix) - 1;
const size_t pid_prefix_size = sizeof(kPidPrefix) - 1;

Powered by Google App Engine
This is Rietveld 408576698