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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 ScopedComPtr<IAMStreamConfig> stream_config; | 297 ScopedComPtr<IAMStreamConfig> stream_config; |
298 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); | 298 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); |
299 if (FAILED(hr)) { | 299 if (FAILED(hr)) { |
300 SetErrorState("Can't get the Capture format settings"); | 300 SetErrorState("Can't get the Capture format settings"); |
301 return; | 301 return; |
302 } | 302 } |
303 | 303 |
304 int count = 0, size = 0; | 304 int count = 0, size = 0; |
305 hr = stream_config->GetNumberOfCapabilities(&count, &size); | 305 hr = stream_config->GetNumberOfCapabilities(&count, &size); |
306 if (FAILED(hr)) { | 306 if (FAILED(hr)) { |
307 DVLOG(2) << "Failed to GetNumberOfCapabilities"; | 307 SetErrorState("Failed to GetNumberOfCapabilities"); |
308 return; | 308 return; |
309 } | 309 } |
310 | 310 |
311 scoped_ptr<BYTE[]> caps(new BYTE[size]); | 311 scoped_ptr<BYTE[]> caps(new BYTE[size]); |
312 ScopedMediaType media_type; | 312 ScopedMediaType media_type; |
313 | 313 |
314 // Get the windows capability from the capture device. | 314 // Get the windows capability from the capture device. |
315 hr = stream_config->GetStreamCaps( | 315 hr = stream_config->GetStreamCaps( |
316 found_capability.stream_index, media_type.Receive(), caps.get()); | 316 found_capability.stream_index, media_type.Receive(), caps.get()); |
317 if (SUCCEEDED(hr)) { | 317 if (SUCCEEDED(hr)) { |
318 if (media_type->formattype == FORMAT_VideoInfo) { | 318 if (media_type->formattype == FORMAT_VideoInfo) { |
319 VIDEOINFOHEADER* h = | 319 VIDEOINFOHEADER* h = |
320 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); | 320 reinterpret_cast<VIDEOINFOHEADER*>(media_type->pbFormat); |
321 if (format.frame_rate > 0) | 321 if (format.frame_rate > 0) |
322 h->AvgTimePerFrame = kSecondsToReferenceTime / format.frame_rate; | 322 h->AvgTimePerFrame = kSecondsToReferenceTime / format.frame_rate; |
323 } | 323 } |
324 // Set the sink filter to request this format. | 324 // Set the sink filter to request this format. |
325 sink_filter_->SetRequestedMediaFormat(format); | 325 sink_filter_->SetRequestedMediaFormat(format); |
326 // Order the capture device to use this format. | 326 // Order the capture device to use this format. |
327 hr = stream_config->SetFormat(media_type.get()); | 327 hr = stream_config->SetFormat(media_type.get()); |
328 } | 328 } |
329 | 329 |
330 if (FAILED(hr)) | 330 if (FAILED(hr)) |
DaleCurtis
2014/08/14 18:04:13
Should this go with the hr = in the if() above? an
Henrik Grunell
2014/08/15 06:26:37
Yes it seems so. I'll adress this in a follow-up.
Henrik Grunell
2014/08/19 06:56:37
FTR, https://codereview.chromium.org/482413002/
| |
331 SetErrorState("Failed to set capture device output format"); | 331 SetErrorState("Failed to set capture device output format"); |
332 | 332 |
333 if (format.pixel_format == PIXEL_FORMAT_MJPEG && !mjpg_filter_.get()) { | 333 if (format.pixel_format == PIXEL_FORMAT_MJPEG && !mjpg_filter_.get()) { |
334 // Create MJPG filter if we need it. | 334 // Create MJPG filter if we need it. |
335 hr = mjpg_filter_.CreateInstance(CLSID_MjpegDec, NULL, CLSCTX_INPROC); | 335 hr = mjpg_filter_.CreateInstance(CLSID_MjpegDec, NULL, CLSCTX_INPROC); |
336 | 336 |
337 if (SUCCEEDED(hr)) { | 337 if (SUCCEEDED(hr)) { |
338 input_mjpg_pin_ = GetPin(mjpg_filter_, PINDIR_INPUT, GUID_NULL); | 338 input_mjpg_pin_ = GetPin(mjpg_filter_, PINDIR_INPUT, GUID_NULL); |
339 output_mjpg_pin_ = GetPin(mjpg_filter_, PINDIR_OUTPUT, GUID_NULL); | 339 output_mjpg_pin_ = GetPin(mjpg_filter_, PINDIR_OUTPUT, GUID_NULL); |
340 hr = graph_builder_->AddFilter(mjpg_filter_, NULL); | 340 hr = graph_builder_->AddFilter(mjpg_filter_, NULL); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 } | 544 } |
545 } | 545 } |
546 | 546 |
547 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { | 547 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { |
548 DCHECK(CalledOnValidThread()); | 548 DCHECK(CalledOnValidThread()); |
549 DVLOG(1) << reason; | 549 DVLOG(1) << reason; |
550 state_ = kError; | 550 state_ = kError; |
551 client_->OnError(reason); | 551 client_->OnError(reason); |
552 } | 552 } |
553 } // namespace media | 553 } // namespace media |
OLD | NEW |