Chromium Code Reviews| 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 | |
| 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 (FAILED(hr = MFCreateSourceReaderFromMediaSource(source, NULL, | |
| 300 reader.Receive()))) { | |
| 301 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr; | |
| 302 return; | |
| 303 } | |
| 304 | |
| 305 DWORD stream_index = 0; | |
| 306 ScopedComPtr<IMFMediaType> type; | |
| 307 while (SUCCEEDED(hr = reader->GetNativeMediaType( | |
| 308 MF_SOURCE_READER_FIRST_VIDEO_STREAM, stream_index, type.Receive()))) { | |
| 309 UINT32 width, height; | |
| 310 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); | |
| 311 if (FAILED(hr)) { | |
| 312 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; | |
| 313 return; | |
| 314 } | |
| 315 VideoCaptureFormat capture_format; | |
|
tommi (sloooow) - chröme
2014/01/30 17:39:08
nit: you don't really need this variable until aft
mcasas
2014/01/30 17:52:15
Is used in l.316.
| |
| 316 capture_format.frame_size.SetSize(width, height); | |
| 317 | |
| 318 UINT32 numerator, denominator; | |
| 319 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator); | |
| 320 if (FAILED(hr)) { | |
| 321 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; | |
| 322 return; | |
| 323 } | |
| 324 capture_format.frame_rate = denominator ? numerator/denominator : 0; | |
|
tommi (sloooow) - chröme
2014/01/30 17:39:08
nit: spaces around /
mcasas
2014/01/30 17:52:15
Done.
| |
| 325 | |
| 326 GUID type_guid; | |
| 327 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid); | |
| 328 if (FAILED(hr)) { | |
| 329 DLOG(ERROR) << "GetGUID: " << std::hex << hr; | |
| 330 return; | |
| 331 } | |
| 332 FormatFromGuid(type_guid, &capture_format.pixel_format); | |
| 333 type.Release(); | |
| 334 formats->push_back(capture_format); | |
| 335 ++stream_index; | |
| 336 | |
| 337 DVLOG(1) << device.name() << " resolution: " | |
| 338 << capture_format.frame_size.ToString() << ", fps: " | |
| 339 << capture_format.frame_rate << ", pixel format: " | |
| 340 << capture_format.pixel_format; | |
| 341 } | |
| 342 } | |
| 343 | |
| 289 const std::string VideoCaptureDevice::Name::GetModel() const { | 344 const std::string VideoCaptureDevice::Name::GetModel() const { |
| 290 const size_t vid_prefix_size = sizeof(kVidPrefix) - 1; | 345 const size_t vid_prefix_size = sizeof(kVidPrefix) - 1; |
| 291 const size_t pid_prefix_size = sizeof(kPidPrefix) - 1; | 346 const size_t pid_prefix_size = sizeof(kPidPrefix) - 1; |
| 292 const size_t vid_location = unique_id_.find(kVidPrefix); | 347 const size_t vid_location = unique_id_.find(kVidPrefix); |
| 293 if (vid_location == std::string::npos || | 348 if (vid_location == std::string::npos || |
| 294 vid_location + vid_prefix_size + kVidPidSize > unique_id_.size()) { | 349 vid_location + vid_prefix_size + kVidPidSize > unique_id_.size()) { |
| 295 return ""; | 350 return ""; |
| 296 } | 351 } |
| 297 const size_t pid_location = unique_id_.find(kPidPrefix); | 352 const size_t pid_location = unique_id_.find(kPidPrefix); |
| 298 if (pid_location == std::string::npos || | 353 if (pid_location == std::string::npos || |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 } | 486 } |
| 432 } | 487 } |
| 433 | 488 |
| 434 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { | 489 void VideoCaptureDeviceMFWin::OnError(HRESULT hr) { |
| 435 DLOG(ERROR) << "VideoCaptureDeviceMFWin: " << std::hex << hr; | 490 DLOG(ERROR) << "VideoCaptureDeviceMFWin: " << std::hex << hr; |
| 436 if (client_.get()) | 491 if (client_.get()) |
| 437 client_->OnError(); | 492 client_->OnError(); |
| 438 } | 493 } |
| 439 | 494 |
| 440 } // namespace media | 495 } // namespace media |
| OLD | NEW |