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_win.h" | 5 #include "media/video/capture/win/video_capture_device_win.h" |
6 | 6 |
7 #include <ks.h> | 7 #include <ks.h> |
8 #include <ksmedia.h> | 8 #include <ksmedia.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 DVLOG(2) << "Device (also) supports an unknown media type " << guid_str; | 171 DVLOG(2) << "Device (also) supports an unknown media type " << guid_str; |
172 #endif | 172 #endif |
173 return PIXEL_FORMAT_UNKNOWN; | 173 return PIXEL_FORMAT_UNKNOWN; |
174 } | 174 } |
175 | 175 |
176 void VideoCaptureDeviceWin::ScopedMediaType::Free() { | 176 void VideoCaptureDeviceWin::ScopedMediaType::Free() { |
177 if (!media_type_) | 177 if (!media_type_) |
178 return; | 178 return; |
179 | 179 |
180 DeleteMediaType(media_type_); | 180 DeleteMediaType(media_type_); |
181 media_type_= NULL; | 181 media_type_ = NULL; |
182 } | 182 } |
183 | 183 |
184 AM_MEDIA_TYPE** VideoCaptureDeviceWin::ScopedMediaType::Receive() { | 184 AM_MEDIA_TYPE** VideoCaptureDeviceWin::ScopedMediaType::Receive() { |
185 DCHECK(!media_type_); | 185 DCHECK(!media_type_); |
186 return &media_type_; | 186 return &media_type_; |
187 } | 187 } |
188 | 188 |
189 // Release the format block for a media type. | 189 // Release the format block for a media type. |
190 // http://msdn.microsoft.com/en-us/library/dd375432(VS.85).aspx | 190 // http://msdn.microsoft.com/en-us/library/dd375432(VS.85).aspx |
191 void VideoCaptureDeviceWin::ScopedMediaType::FreeMediaType(AM_MEDIA_TYPE* mt) { | 191 void VideoCaptureDeviceWin::ScopedMediaType::FreeMediaType(AM_MEDIA_TYPE* mt) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 scoped_ptr<VideoCaptureDevice::Client> client) { | 312 scoped_ptr<VideoCaptureDevice::Client> client) { |
313 DCHECK(CalledOnValidThread()); | 313 DCHECK(CalledOnValidThread()); |
314 if (state_ != kIdle) | 314 if (state_ != kIdle) |
315 return; | 315 return; |
316 | 316 |
317 client_ = client.Pass(); | 317 client_ = client.Pass(); |
318 | 318 |
319 // Get the camera capability that best match the requested format. | 319 // Get the camera capability that best match the requested format. |
320 const CapabilityWin found_capability = | 320 const CapabilityWin found_capability = |
321 GetBestMatchedCapability(params.requested_format, capabilities_); | 321 GetBestMatchedCapability(params.requested_format, capabilities_); |
322 VideoCaptureFormat format = found_capability.supported_format; | |
323 | 322 |
324 // Reduce the frame rate if the requested frame rate is lower | 323 // Reduce the frame rate if the requested frame rate is lower |
325 // than the capability. | 324 // than the capability. |
326 format.frame_rate = | 325 float frame_rate = std::min(found_capability.supported_format.frame_rate, |
327 std::min(format.frame_rate, params.requested_format.frame_rate); | 326 params.requested_format.frame_rate); |
328 | 327 |
329 ScopedComPtr<IAMStreamConfig> stream_config; | 328 ScopedComPtr<IAMStreamConfig> stream_config; |
330 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); | 329 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); |
331 if (FAILED(hr)) { | 330 if (FAILED(hr)) { |
332 SetErrorState("Can't get the Capture format settings"); | 331 SetErrorState("Can't get the Capture format settings"); |
333 return; | 332 return; |
334 } | 333 } |
335 | 334 |
336 int count = 0, size = 0; | 335 int count = 0, size = 0; |
337 hr = stream_config->GetNumberOfCapabilities(&count, &size); | 336 hr = stream_config->GetNumberOfCapabilities(&count, &size); |
(...skipping 10 matching lines...) Expand all Loading... |
348 // FAILED macro can't be used. | 347 // FAILED macro can't be used. |
349 hr = stream_config->GetStreamCaps( | 348 hr = stream_config->GetStreamCaps( |
350 found_capability.stream_index, media_type.Receive(), caps.get()); | 349 found_capability.stream_index, media_type.Receive(), caps.get()); |
351 if (hr != S_OK) { | 350 if (hr != S_OK) { |
352 SetErrorState("Failed to get capture device capabilities"); | 351 SetErrorState("Failed to get capture device capabilities"); |
353 return; | 352 return; |
354 } | 353 } |
355 if (media_type->formattype == FORMAT_VideoInfo) { | 354 if (media_type->formattype == FORMAT_VideoInfo) { |
356 VIDEOINFOHEADER* h = | 355 VIDEOINFOHEADER* h = |
357 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 356 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
358 if (format.frame_rate > 0) | 357 if (frame_rate > 0) |
359 h->AvgTimePerFrame = kSecondsToReferenceTime / format.frame_rate; | 358 h->AvgTimePerFrame = kSecondsToReferenceTime / frame_rate; |
360 } | 359 } |
361 // Set the sink filter to request this format. | 360 // Set the sink filter to request this format. |
362 sink_filter_->SetRequestedMediaFormat(format); | 361 sink_filter_->SetRequestedMediaFormat( |
| 362 found_capability.supported_format.pixel_format, frame_rate, |
| 363 found_capability.info_header); |
363 // Order the capture device to use this format. | 364 // Order the capture device to use this format. |
364 hr = stream_config->SetFormat(media_type.get()); | 365 hr = stream_config->SetFormat(media_type.get()); |
365 if (FAILED(hr)) { | 366 if (FAILED(hr)) { |
366 // TODO(grunell): Log the error. http://crbug.com/405016. | 367 // TODO(grunell): Log the error. http://crbug.com/405016. |
367 SetErrorState("Failed to set capture device output format"); | 368 SetErrorState("Failed to set capture device output format"); |
368 return; | 369 return; |
369 } | 370 } |
370 | 371 |
371 SetAntiFlickerInCaptureFilter(); | 372 SetAntiFlickerInCaptureFilter(); |
372 | 373 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 time_per_frame = *std::min_element(max_fps.get(), | 509 time_per_frame = *std::min_element(max_fps.get(), |
509 max_fps.get() + list_size); | 510 max_fps.get() + list_size); |
510 } | 511 } |
511 } | 512 } |
512 | 513 |
513 format.frame_rate = | 514 format.frame_rate = |
514 (time_per_frame > 0) | 515 (time_per_frame > 0) |
515 ? (kSecondsToReferenceTime / static_cast<float>(time_per_frame)) | 516 ? (kSecondsToReferenceTime / static_cast<float>(time_per_frame)) |
516 : 0.0; | 517 : 0.0; |
517 | 518 |
518 capabilities_.emplace_back(stream_index, format); | 519 capabilities_.emplace_back(stream_index, format, h->bmiHeader); |
519 } | 520 } |
520 } | 521 } |
521 | 522 |
522 return !capabilities_.empty(); | 523 return !capabilities_.empty(); |
523 } | 524 } |
524 | 525 |
525 // Set the power line frequency removal in |capture_filter_| if available. | 526 // Set the power line frequency removal in |capture_filter_| if available. |
526 void VideoCaptureDeviceWin::SetAntiFlickerInCaptureFilter() { | 527 void VideoCaptureDeviceWin::SetAntiFlickerInCaptureFilter() { |
527 const int power_line_frequency = GetPowerLineFrequencyForLocation(); | 528 const int power_line_frequency = GetPowerLineFrequencyForLocation(); |
528 if (power_line_frequency != kPowerLine50Hz && | 529 if (power_line_frequency != kPowerLine50Hz && |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 return E_FAIL; | 612 return E_FAIL; |
612 return S_OK; | 613 return S_OK; |
613 } | 614 } |
614 | 615 |
615 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { | 616 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { |
616 DCHECK(CalledOnValidThread()); | 617 DCHECK(CalledOnValidThread()); |
617 state_ = kError; | 618 state_ = kError; |
618 client_->OnError(reason); | 619 client_->OnError(reason); |
619 } | 620 } |
620 } // namespace media | 621 } // namespace media |
OLD | NEW |