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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 for (size_t i = 0; | 61 for (size_t i = 0; |
62 i < arraysize(kPropertyNames) && name.type() != VT_BSTR; ++i) { | 62 i < arraysize(kPropertyNames) && name.type() != VT_BSTR; ++i) { |
63 prop_bag->Read(kPropertyNames[i], name.Receive(), 0); | 63 prop_bag->Read(kPropertyNames[i], name.Receive(), 0); |
64 } | 64 } |
65 if (name.type() == VT_BSTR) { | 65 if (name.type() == VT_BSTR) { |
66 std::string device_path(base::SysWideToUTF8(V_BSTR(&name))); | 66 std::string device_path(base::SysWideToUTF8(V_BSTR(&name))); |
67 if (device_path.compare(device_name.id()) == 0) { | 67 if (device_path.compare(device_name.id()) == 0) { |
68 // We have found the requested device | 68 // We have found the requested device |
69 hr = moniker->BindToObject(0, 0, IID_IBaseFilter, | 69 hr = moniker->BindToObject(0, 0, IID_IBaseFilter, |
70 capture_filter.ReceiveVoid()); | 70 capture_filter.ReceiveVoid()); |
71 DVPLOG_IF(2, FAILED(hr)) << "Failed to bind camera filter."; | 71 DPLOG_IF(ERROR, FAILED(hr)) << "Failed to bind camera filter"; |
72 break; | 72 break; // TODO(magjed): Should we return E_FAIL here instead of break? |
tommi (sloooow) - chröme
2014/08/28 08:48:46
well, we certainly shouldn't return if |hr| indica
magjed_chromium
2014/08/28 14:50:39
Done.
| |
73 } | 73 } |
74 } | 74 } |
75 moniker.Release(); | 75 moniker.Release(); |
76 } | 76 } |
77 | 77 |
78 *filter = capture_filter.Detach(); | 78 *filter = capture_filter.Detach(); |
79 if (!*filter && SUCCEEDED(hr)) | 79 if (!*filter && SUCCEEDED(hr)) |
80 hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); | 80 hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND); |
81 | 81 |
82 return hr; | 82 return hr; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 | 217 |
218 if (mjpg_filter_) | 218 if (mjpg_filter_) |
219 graph_builder_->RemoveFilter(mjpg_filter_); | 219 graph_builder_->RemoveFilter(mjpg_filter_); |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 bool VideoCaptureDeviceWin::Init() { | 223 bool VideoCaptureDeviceWin::Init() { |
224 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
225 HRESULT hr = GetDeviceFilter(device_name_, capture_filter_.Receive()); | 225 HRESULT hr = GetDeviceFilter(device_name_, capture_filter_.Receive()); |
226 if (!capture_filter_) { | 226 if (!capture_filter_) { |
227 DVLOG(2) << "Failed to create capture filter."; | 227 DPLOG(ERROR) << "Failed to create capture filter"; |
tommi (sloooow) - chröme
2014/08/28 08:48:46
FWIW - all the 'P's in the DPLOG() here are pretty
| |
228 return false; | 228 return false; |
229 } | 229 } |
230 | 230 |
231 output_capture_pin_ = | 231 output_capture_pin_ = |
232 GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE); | 232 GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE); |
233 if (!output_capture_pin_) { | 233 if (!output_capture_pin_) { |
234 DVLOG(2) << "Failed to get capture output pin"; | 234 DPLOG(ERROR) << "Failed to get capture output pin"; |
235 return false; | 235 return false; |
236 } | 236 } |
237 | 237 |
238 // Create the sink filter used for receiving Captured frames. | 238 // Create the sink filter used for receiving Captured frames. |
239 sink_filter_ = new SinkFilter(this); | 239 sink_filter_ = new SinkFilter(this); |
240 if (sink_filter_ == NULL) { | 240 if (sink_filter_ == NULL) { |
241 DVLOG(2) << "Failed to create send filter"; | 241 DPLOG(ERROR) << "Failed to create send filter"; |
242 return false; | 242 return false; |
243 } | 243 } |
244 | 244 |
245 input_sink_pin_ = sink_filter_->GetPin(0); | 245 input_sink_pin_ = sink_filter_->GetPin(0); |
246 | 246 |
247 hr = graph_builder_.CreateInstance(CLSID_FilterGraph, NULL, | 247 hr = graph_builder_.CreateInstance(CLSID_FilterGraph, NULL, |
248 CLSCTX_INPROC_SERVER); | 248 CLSCTX_INPROC_SERVER); |
249 if (FAILED(hr)) { | 249 if (FAILED(hr)) { |
250 DVLOG(2) << "Failed to create graph builder."; | 250 DPLOG(ERROR) << "Failed to create graph builder"; |
251 return false; | 251 return false; |
252 } | 252 } |
253 | 253 |
254 hr = graph_builder_.QueryInterface(media_control_.Receive()); | 254 hr = graph_builder_.QueryInterface(media_control_.Receive()); |
255 if (FAILED(hr)) { | 255 if (FAILED(hr)) { |
256 DVLOG(2) << "Failed to create media control builder."; | 256 DPLOG(ERROR) << "Failed to create media control builder"; |
257 return false; | 257 return false; |
258 } | 258 } |
259 | 259 |
260 hr = graph_builder_->AddFilter(capture_filter_, NULL); | 260 hr = graph_builder_->AddFilter(capture_filter_, NULL); |
261 if (FAILED(hr)) { | 261 if (FAILED(hr)) { |
262 DVLOG(2) << "Failed to add the capture device to the graph."; | 262 DPLOG(ERROR) << "Failed to add the capture device to the graph"; |
263 return false; | 263 return false; |
264 } | 264 } |
265 | 265 |
266 hr = graph_builder_->AddFilter(sink_filter_, NULL); | 266 hr = graph_builder_->AddFilter(sink_filter_, NULL); |
267 if (FAILED(hr)) { | 267 if (FAILED(hr)) { |
268 DVLOG(2)<< "Failed to add the send filter to the graph."; | 268 DPLOG(ERROR)<< "Failed to add the send filter to the graph"; |
269 return false; | 269 return false; |
270 } | 270 } |
271 | 271 |
272 return CreateCapabilityMap(); | 272 return CreateCapabilityMap(); |
273 } | 273 } |
274 | 274 |
275 void VideoCaptureDeviceWin::AllocateAndStart( | 275 void VideoCaptureDeviceWin::AllocateAndStart( |
276 const VideoCaptureParams& params, | 276 const VideoCaptureParams& params, |
277 scoped_ptr<VideoCaptureDevice::Client> client) { | 277 scoped_ptr<VideoCaptureDevice::Client> client) { |
278 DCHECK(CalledOnValidThread()); | 278 DCHECK(CalledOnValidThread()); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 int length) { | 431 int length) { |
432 client_->OnIncomingCapturedData( | 432 client_->OnIncomingCapturedData( |
433 buffer, length, capture_format_, 0, base::TimeTicks::Now()); | 433 buffer, length, capture_format_, 0, base::TimeTicks::Now()); |
434 } | 434 } |
435 | 435 |
436 bool VideoCaptureDeviceWin::CreateCapabilityMap() { | 436 bool VideoCaptureDeviceWin::CreateCapabilityMap() { |
437 DCHECK(CalledOnValidThread()); | 437 DCHECK(CalledOnValidThread()); |
438 ScopedComPtr<IAMStreamConfig> stream_config; | 438 ScopedComPtr<IAMStreamConfig> stream_config; |
439 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); | 439 HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); |
440 if (FAILED(hr)) { | 440 if (FAILED(hr)) { |
441 DVLOG(2) << "Failed to get IAMStreamConfig interface from " | 441 DPLOG(ERROR) << "Failed to get IAMStreamConfig interface from " |
442 "capture device"; | 442 "capture device"; |
443 return false; | 443 return false; |
444 } | 444 } |
445 | 445 |
446 // Get interface used for getting the frame rate. | 446 // Get interface used for getting the frame rate. |
447 ScopedComPtr<IAMVideoControl> video_control; | 447 ScopedComPtr<IAMVideoControl> video_control; |
448 hr = capture_filter_.QueryInterface(video_control.Receive()); | 448 hr = capture_filter_.QueryInterface(video_control.Receive()); |
449 DVLOG_IF(2, FAILED(hr)) << "IAMVideoControl Interface NOT SUPPORTED"; | 449 DPLOG_IF(WARNING, FAILED(hr)) << "IAMVideoControl Interface NOT SUPPORTED"; |
450 | 450 |
451 int count = 0, size = 0; | 451 int count = 0, size = 0; |
452 hr = stream_config->GetNumberOfCapabilities(&count, &size); | 452 hr = stream_config->GetNumberOfCapabilities(&count, &size); |
453 if (FAILED(hr)) { | 453 if (FAILED(hr)) { |
454 DVLOG(2) << "Failed to GetNumberOfCapabilities"; | 454 DPLOG(ERROR) << "Failed to GetNumberOfCapabilities"; |
455 return false; | 455 return false; |
456 } | 456 } |
457 | 457 |
458 scoped_ptr<BYTE[]> caps(new BYTE[size]); | 458 scoped_ptr<BYTE[]> caps(new BYTE[size]); |
459 for (int i = 0; i < count; ++i) { | 459 for (int i = 0; i < count; ++i) { |
460 ScopedMediaType media_type; | 460 ScopedMediaType media_type; |
461 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); | 461 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); |
462 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() | 462 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() |
463 // macros here since they'll trigger incorrectly. | 463 // macros here since they'll trigger incorrectly. |
464 if (hr != S_OK) { | 464 if (hr != S_OK) { |
465 DVLOG(2) << "Failed to GetStreamCaps"; | 465 DPLOG(ERROR) << "Failed to GetStreamCaps"; |
466 return false; | 466 return false; |
467 } | 467 } |
468 | 468 |
469 if (media_type->majortype == MEDIATYPE_Video && | 469 if (media_type->majortype == MEDIATYPE_Video && |
470 media_type->formattype == FORMAT_VideoInfo) { | 470 media_type->formattype == FORMAT_VideoInfo) { |
471 VideoCaptureCapabilityWin capability(i); | 471 VideoCaptureCapabilityWin capability(i); |
472 capability.supported_format.pixel_format = | 472 capability.supported_format.pixel_format = |
473 TranslateMediaSubtypeToPixelFormat(media_type->subtype); | 473 TranslateMediaSubtypeToPixelFormat(media_type->subtype); |
474 if (capability.supported_format.pixel_format == PIXEL_FORMAT_UNKNOWN) | 474 if (capability.supported_format.pixel_format == PIXEL_FORMAT_UNKNOWN) |
475 continue; | 475 continue; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 (type_support & KSPROPERTY_SUPPORT_SET)) { | 537 (type_support & KSPROPERTY_SUPPORT_SET)) { |
538 KSPROPERTY_VIDEOPROCAMP_S data = {}; | 538 KSPROPERTY_VIDEOPROCAMP_S data = {}; |
539 data.Property.Set = PROPSETID_VIDCAP_VIDEOPROCAMP; | 539 data.Property.Set = PROPSETID_VIDCAP_VIDEOPROCAMP; |
540 data.Property.Id = KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY; | 540 data.Property.Id = KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY; |
541 data.Property.Flags = KSPROPERTY_TYPE_SET; | 541 data.Property.Flags = KSPROPERTY_TYPE_SET; |
542 data.Value = (power_line_frequency == kPowerLine50Hz) ? 1 : 2; | 542 data.Value = (power_line_frequency == kPowerLine50Hz) ? 1 : 2; |
543 data.Flags = KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL; | 543 data.Flags = KSPROPERTY_VIDEOPROCAMP_FLAGS_MANUAL; |
544 hr = ks_propset->Set(PROPSETID_VIDCAP_VIDEOPROCAMP, | 544 hr = ks_propset->Set(PROPSETID_VIDCAP_VIDEOPROCAMP, |
545 KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY, | 545 KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY, |
546 &data, sizeof(data), &data, sizeof(data)); | 546 &data, sizeof(data), &data, sizeof(data)); |
547 DVLOG_IF(ERROR, FAILED(hr)) << "Anti-flicker setting failed."; | 547 DPLOG_IF(ERROR, FAILED(hr)) << "Anti-flicker setting failed"; |
548 DVLOG_IF(2, SUCCEEDED(hr)) << "Anti-flicker set correctly."; | 548 DVLOG_IF(2, SUCCEEDED(hr)) << "Anti-flicker set correctly."; |
549 } else { | 549 } else { |
550 DVLOG(2) << "Anti-flicker setting not supported."; | 550 DVLOG(2) << "Anti-flicker setting not supported."; |
551 } | 551 } |
552 } | 552 } |
553 | 553 |
554 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { | 554 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { |
555 DCHECK(CalledOnValidThread()); | 555 DCHECK(CalledOnValidThread()); |
556 DVLOG(1) << reason; | |
557 state_ = kError; | 556 state_ = kError; |
558 client_->OnError(reason); | 557 client_->OnError(reason); |
559 } | 558 } |
560 } // namespace media | 559 } // namespace media |
OLD | NEW |