OLD | NEW |
---|---|
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 Loading... | |
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 | |
tommi (sloooow) - chröme
2014/01/30 13:25:17
// static
mcasas
2014/01/30 16:29:23
Done.
| |
290 void VideoCaptureDeviceMFWin::GetDeviceSupportedFormats(const Name& device, | |
291 VideoCaptureFormats* formats) { | |
292 | |
293 ScopedComPtr<IMFMediaSource> source; | |
294 if (!CreateVideoCaptureDevice(device.id().c_str(), source.Receive())) | |
295 return; | |
296 | |
297 HRESULT hr; | |
298 base::win::ScopedComPtr<IMFSourceReader> reader; | |
299 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.
| |
300 reader.Receive()))) { | |
301 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.
| |
302 } | |
303 | |
304 DWORD stream_index = 0; | |
305 ScopedComPtr<IMFMediaType> type; | |
306 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.
| |
307 UINT32 width, height, numerator, denominator; | |
308 while (SUCCEEDED(hr = reader->GetNativeMediaType( | |
309 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.
| |
310 | |
tommi (sloooow) - chröme
2014/01/30 13:25:17
remove empty line.
mcasas
2014/01/30 16:29:23
Done.
| |
311 VideoCaptureFormat capture_format; | |
tommi (sloooow) - chröme
2014/01/30 13:25:17
define this variable where you need it (smallest s
| |
312 | |
313 if (FAILED(hr = MFGetAttributeSize( | |
314 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.
| |
315 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.
| |
316 return; | |
317 } | |
318 capture_format.frame_size.SetSize(width, height); | |
319 if (FAILED(hr = MFGetAttributeRatio( | |
320 type, MF_MT_FRAME_RATE, &numerator, &denominator))) { | |
321 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.
| |
322 return; | |
323 } | |
324 capture_format.frame_rate = denominator ? numerator/denominator : 0; | |
325 | |
326 if (FAILED(hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid))) { | |
327 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.
| |
328 return; | |
329 } | |
330 FormatFromGuid(type_guid, &capture_format.pixel_format); | |
331 type.Release(); | |
332 formats->push_back(capture_format); | |
333 stream_index++; | |
tommi (sloooow) - chröme
2014/01/30 13:25:17
nit: ++stream_index;
mcasas
2014/01/30 16:29:23
Done.
| |
334 | |
335 DVLOG(1) << device.name() << " resolution: " | |
336 << capture_format.frame_size.ToString() << ", fps: " | |
337 << capture_format.frame_rate << ", pixel format: " | |
338 << capture_format.pixel_format; | |
339 } | |
340 return; | |
tommi (sloooow) - chröme
2014/01/30 13:25:17
remove
mcasas
2014/01/30 16:29:23
Done.
| |
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 Loading... | |
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 |
OLD | NEW |