| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/video_capture/windows/video_capture_ds.h" | 11 #include "webrtc/modules/video_capture/windows/video_capture_ds.h" |
| 12 | 12 |
| 13 #include "webrtc/modules/video_capture/video_capture_config.h" | 13 #include "webrtc/modules/video_capture/video_capture_config.h" |
| 14 #include "webrtc/modules/video_capture/windows/help_functions_ds.h" | 14 #include "webrtc/modules/video_capture/windows/help_functions_ds.h" |
| 15 #include "webrtc/modules/video_capture/windows/sink_filter_ds.h" | 15 #include "webrtc/modules/video_capture/windows/sink_filter_ds.h" |
| 16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 16 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 17 #include "webrtc/system_wrappers/include/trace.h" | 17 #include "webrtc/system_wrappers/include/trace.h" |
| 18 | 18 |
| 19 #include <Dvdmedia.h> // VIDEOINFOHEADER2 | 19 #include <Dvdmedia.h> // VIDEOINFOHEADER2 |
| 20 | 20 |
| 21 namespace webrtc | 21 namespace webrtc |
| 22 { | 22 { |
| 23 namespace videocapturemodule | 23 namespace videocapturemodule |
| 24 { | 24 { |
| 25 VideoCaptureDS::VideoCaptureDS() | 25 VideoCaptureDS::VideoCaptureDS() |
| 26 : _captureFilter(NULL), | 26 : _captureFilter(nullptr), |
| 27 _graphBuilder(NULL), _mediaControl(NULL), _sinkFilter(NULL), | 27 _graphBuilder(nullptr), |
| 28 _inputSendPin(NULL), _outputCapturePin(NULL), _dvFilter(NULL), | 28 _mediaControl(nullptr), |
| 29 _inputDvPin(NULL), _outputDvPin(NULL) | 29 _sinkFilter(nullptr), |
| 30 { | 30 _inputSendPin(nullptr), |
| 31 } | 31 _outputCapturePin(nullptr), |
| 32 _dvFilter(nullptr), |
| 33 _inputDvPin(nullptr), |
| 34 _outputDvPin(nullptr) {} |
| 32 | 35 |
| 33 VideoCaptureDS::~VideoCaptureDS() | 36 VideoCaptureDS::~VideoCaptureDS() |
| 34 { | 37 { |
| 35 if (_mediaControl) | 38 if (_mediaControl) |
| 36 { | 39 { |
| 37 _mediaControl->Stop(); | 40 _mediaControl->Stop(); |
| 38 } | 41 } |
| 39 if (_graphBuilder) | 42 if (_graphBuilder) |
| 40 { | 43 { |
| 41 if (_sinkFilter) | 44 if (_sinkFilter) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 79 |
| 77 _captureFilter = _dsInfo.GetDeviceFilter(deviceUniqueIdUTF8); | 80 _captureFilter = _dsInfo.GetDeviceFilter(deviceUniqueIdUTF8); |
| 78 if (!_captureFilter) | 81 if (!_captureFilter) |
| 79 { | 82 { |
| 80 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 83 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 81 "Failed to create capture filter."); | 84 "Failed to create capture filter."); |
| 82 return -1; | 85 return -1; |
| 83 } | 86 } |
| 84 | 87 |
| 85 // Get the interface for DirectShow's GraphBuilder | 88 // Get the interface for DirectShow's GraphBuilder |
| 86 HRESULT hr = CoCreateInstance(CLSID_FilterGraph, NULL, | 89 HRESULT hr = |
| 87 CLSCTX_INPROC_SERVER, IID_IGraphBuilder, | 90 CoCreateInstance(CLSID_FilterGraph, nullptr, CLSCTX_INPROC_SERVER, |
| 88 (void **) &_graphBuilder); | 91 IID_IGraphBuilder, (void**)&_graphBuilder); |
| 89 if (FAILED(hr)) | 92 if (FAILED(hr)) |
| 90 { | 93 { |
| 91 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 94 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 92 "Failed to create graph builder."); | 95 "Failed to create graph builder."); |
| 93 return -1; | 96 return -1; |
| 94 } | 97 } |
| 95 | 98 |
| 96 hr = _graphBuilder->QueryInterface(IID_IMediaControl, | 99 hr = _graphBuilder->QueryInterface(IID_IMediaControl, |
| 97 (void **) &_mediaControl); | 100 (void **) &_mediaControl); |
| 98 if (FAILED(hr)) | 101 if (FAILED(hr)) |
| 99 { | 102 { |
| 100 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 103 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 101 "Failed to create media control builder."); | 104 "Failed to create media control builder."); |
| 102 return -1; | 105 return -1; |
| 103 } | 106 } |
| 104 hr = _graphBuilder->AddFilter(_captureFilter, CAPTURE_FILTER_NAME); | 107 hr = _graphBuilder->AddFilter(_captureFilter, CAPTURE_FILTER_NAME); |
| 105 if (FAILED(hr)) | 108 if (FAILED(hr)) |
| 106 { | 109 { |
| 107 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 110 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 108 "Failed to add the capture device to the graph."); | 111 "Failed to add the capture device to the graph."); |
| 109 return -1; | 112 return -1; |
| 110 } | 113 } |
| 111 | 114 |
| 112 _outputCapturePin = GetOutputPin(_captureFilter, PIN_CATEGORY_CAPTURE); | 115 _outputCapturePin = GetOutputPin(_captureFilter, PIN_CATEGORY_CAPTURE); |
| 113 | 116 |
| 114 // Create the sink filte used for receiving Captured frames. | 117 // Create the sink filte used for receiving Captured frames. |
| 115 _sinkFilter = new CaptureSinkFilter(SINK_FILTER_NAME, NULL, &hr, | 118 _sinkFilter = new CaptureSinkFilter(SINK_FILTER_NAME, nullptr, &hr, *this); |
| 116 *this); | |
| 117 if (hr != S_OK) | 119 if (hr != S_OK) |
| 118 { | 120 { |
| 119 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 121 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 120 "Failed to create send filter"); | 122 "Failed to create send filter"); |
| 121 return -1; | 123 return -1; |
| 122 } | 124 } |
| 123 _sinkFilter->AddRef(); | 125 _sinkFilter->AddRef(); |
| 124 | 126 |
| 125 hr = _graphBuilder->AddFilter(_sinkFilter, SINK_FILTER_NAME); | 127 hr = _graphBuilder->AddFilter(_sinkFilter, SINK_FILTER_NAME); |
| 126 if (FAILED(hr)) | 128 if (FAILED(hr)) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 _captureDelay = capability.expectedCaptureDelay; | 239 _captureDelay = capability.expectedCaptureDelay; |
| 238 | 240 |
| 239 // Convert it to the windows capability index since they are not nexessary | 241 // Convert it to the windows capability index since they are not nexessary |
| 240 // the same | 242 // the same |
| 241 VideoCaptureCapabilityWindows windowsCapability; | 243 VideoCaptureCapabilityWindows windowsCapability; |
| 242 if (_dsInfo.GetWindowsCapability(capabilityIndex, windowsCapability) != 0) | 244 if (_dsInfo.GetWindowsCapability(capabilityIndex, windowsCapability) != 0) |
| 243 { | 245 { |
| 244 return -1; | 246 return -1; |
| 245 } | 247 } |
| 246 | 248 |
| 247 IAMStreamConfig* streamConfig = NULL; | 249 IAMStreamConfig* streamConfig = nullptr; |
| 248 AM_MEDIA_TYPE *pmt = NULL; | 250 AM_MEDIA_TYPE* pmt = nullptr; |
| 249 VIDEO_STREAM_CONFIG_CAPS caps; | 251 VIDEO_STREAM_CONFIG_CAPS caps; |
| 250 | 252 |
| 251 HRESULT hr = _outputCapturePin->QueryInterface(IID_IAMStreamConfig, | 253 HRESULT hr = _outputCapturePin->QueryInterface(IID_IAMStreamConfig, |
| 252 (void**) &streamConfig); | 254 (void**) &streamConfig); |
| 253 if (hr) | 255 if (hr) |
| 254 { | 256 { |
| 255 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 257 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 256 "Can't get the Capture format settings."); | 258 "Can't get the Capture format settings."); |
| 257 return -1; | 259 return -1; |
| 258 } | 260 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 "Failed to set capture device output format"); | 309 "Failed to set capture device output format"); |
| 308 return -1; | 310 return -1; |
| 309 } | 311 } |
| 310 | 312 |
| 311 if (isDVCamera) | 313 if (isDVCamera) |
| 312 { | 314 { |
| 313 hr = ConnectDVCamera(); | 315 hr = ConnectDVCamera(); |
| 314 } | 316 } |
| 315 else | 317 else |
| 316 { | 318 { |
| 317 hr = _graphBuilder->ConnectDirect(_outputCapturePin, _inputSendPin, | 319 hr = _graphBuilder->ConnectDirect(_outputCapturePin, _inputSendPin, |
| 318 NULL); | 320 nullptr); |
| 319 } | 321 } |
| 320 if (hr != S_OK) | 322 if (hr != S_OK) |
| 321 { | 323 { |
| 322 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 324 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 323 "Failed to connect the Capture graph %d", hr); | 325 "Failed to connect the Capture graph %d", hr); |
| 324 return -1; | 326 return -1; |
| 325 } | 327 } |
| 326 return 0; | 328 return 0; |
| 327 } | 329 } |
| 328 | 330 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 346 return -1; | 348 return -1; |
| 347 } | 349 } |
| 348 return 0; | 350 return 0; |
| 349 } | 351 } |
| 350 HRESULT VideoCaptureDS::ConnectDVCamera() | 352 HRESULT VideoCaptureDS::ConnectDVCamera() |
| 351 { | 353 { |
| 352 HRESULT hr = S_OK; | 354 HRESULT hr = S_OK; |
| 353 | 355 |
| 354 if (!_dvFilter) | 356 if (!_dvFilter) |
| 355 { | 357 { |
| 356 hr = CoCreateInstance(CLSID_DVVideoCodec, NULL, CLSCTX_INPROC, | 358 hr = CoCreateInstance(CLSID_DVVideoCodec, nullptr, CLSCTX_INPROC, |
| 357 IID_IBaseFilter, (void **) &_dvFilter); | 359 IID_IBaseFilter, (void**)&_dvFilter); |
| 358 if (hr != S_OK) | 360 if (hr != S_OK) { |
| 359 { | 361 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 360 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 362 "Failed to create the dv decoder: %x", hr); |
| 361 "Failed to create the dv decoder: %x", hr); | 363 return hr; |
| 362 return hr; | |
| 363 } | 364 } |
| 364 hr = _graphBuilder->AddFilter(_dvFilter, L"VideoDecoderDV"); | 365 hr = _graphBuilder->AddFilter(_dvFilter, L"VideoDecoderDV"); |
| 365 if (hr != S_OK) | 366 if (hr != S_OK) |
| 366 { | 367 { |
| 367 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 368 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 368 "Failed to add the dv decoder to the graph: %x", hr); | 369 "Failed to add the dv decoder to the graph: %x", hr); |
| 369 return hr; | 370 return hr; |
| 370 } | 371 } |
| 371 _inputDvPin = GetInputPin(_dvFilter); | 372 _inputDvPin = GetInputPin(_dvFilter); |
| 372 if (_inputDvPin == NULL) | 373 if (_inputDvPin == nullptr) { |
| 373 { | 374 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 374 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 375 "Failed to get input pin from DV decoder"); |
| 375 "Failed to get input pin from DV decoder"); | 376 return -1; |
| 376 return -1; | |
| 377 } | 377 } |
| 378 _outputDvPin = GetOutputPin(_dvFilter, GUID_NULL); | 378 _outputDvPin = GetOutputPin(_dvFilter, GUID_NULL); |
| 379 if (_outputDvPin == NULL) | 379 if (_outputDvPin == nullptr) { |
| 380 { | 380 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 381 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 381 "Failed to get output pin from DV decoder"); |
| 382 "Failed to get output pin from DV decoder"); | 382 return -1; |
| 383 return -1; | |
| 384 } | 383 } |
| 385 } | 384 } |
| 386 hr = _graphBuilder->ConnectDirect(_outputCapturePin, _inputDvPin, NULL); | 385 hr = _graphBuilder->ConnectDirect(_outputCapturePin, _inputDvPin, nullptr); |
| 387 if (hr != S_OK) | 386 if (hr != S_OK) |
| 388 { | 387 { |
| 389 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 388 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 390 "Failed to connect capture device to the dv devoder: %x", | 389 "Failed to connect capture device to the dv devoder: %x", |
| 391 hr); | 390 hr); |
| 392 return hr; | 391 return hr; |
| 393 } | 392 } |
| 394 | 393 |
| 395 hr = _graphBuilder->ConnectDirect(_outputDvPin, _inputSendPin, NULL); | 394 hr = _graphBuilder->ConnectDirect(_outputDvPin, _inputSendPin, nullptr); |
| 396 if (hr != S_OK) | 395 if (hr != S_OK) |
| 397 { | 396 { |
| 398 if (hr == HRESULT_FROM_WIN32(ERROR_TOO_MANY_OPEN_FILES)) | 397 if (hr == HRESULT_FROM_WIN32(ERROR_TOO_MANY_OPEN_FILES)) |
| 399 { | 398 { |
| 400 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 399 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 401 "Failed to connect the capture device, busy"); | 400 "Failed to connect the capture device, busy"); |
| 402 } | 401 } |
| 403 else | 402 else |
| 404 { | 403 { |
| 405 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, | 404 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, 0, |
| 406 "Failed to connect capture device to the send graph: 0x
%x", | 405 "Failed to connect capture device to the send graph: 0x
%x", |
| 407 hr); | 406 hr); |
| 408 } | 407 } |
| 409 return hr; | 408 return hr; |
| 410 } | 409 } |
| 411 return hr; | 410 return hr; |
| 412 } | 411 } |
| 413 } // namespace videocapturemodule | 412 } // namespace videocapturemodule |
| 414 } // namespace webrtc | 413 } // namespace webrtc |
| OLD | NEW |