Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: media/video/capture/win/video_capture_device_win.cc

Issue 218673002: Fix video capture bug in a utility function, GetPin, and how it was being used. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Change GetPin to just return the object since the return value wasn't being used Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 hr = ks_property->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0, 95 hr = ks_property->Get(AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, NULL, 0,
96 &pin_category, sizeof(pin_category), &return_value); 96 &pin_category, sizeof(pin_category), &return_value);
97 if (SUCCEEDED(hr) && (return_value == sizeof(pin_category))) { 97 if (SUCCEEDED(hr) && (return_value == sizeof(pin_category))) {
98 found = (pin_category == category); 98 found = (pin_category == category);
99 } 99 }
100 } 100 }
101 return found; 101 return found;
102 } 102 }
103 103
104 // Finds a IPin on a IBaseFilter given the direction an category. 104 // Finds a IPin on a IBaseFilter given the direction an category.
105 HRESULT GetPin(IBaseFilter* filter, PIN_DIRECTION pin_dir, REFGUID category, 105 ScopedComPtr<IPin> GetPin(IBaseFilter* filter, PIN_DIRECTION pin_dir,
106 IPin** pin) { 106 REFGUID category) {
107 DCHECK(pin); 107 ScopedComPtr<IPin> pin;
108 ScopedComPtr<IEnumPins> pin_emum; 108 ScopedComPtr<IEnumPins> pin_emum;
109 HRESULT hr = filter->EnumPins(pin_emum.Receive()); 109 HRESULT hr = filter->EnumPins(pin_emum.Receive());
110 if (pin_emum == NULL) 110 if (pin_emum == NULL)
111 return hr; 111 return pin;
112 112
113 // Get first unconnected pin. 113 // Get first unconnected pin.
114 hr = pin_emum->Reset(); // set to first pin 114 hr = pin_emum->Reset(); // set to first pin
115 while ((hr = pin_emum->Next(1, pin, NULL)) == S_OK) { 115 while ((hr = pin_emum->Next(1, pin.Receive(), NULL)) == S_OK) {
116 PIN_DIRECTION this_pin_dir = static_cast<PIN_DIRECTION>(-1); 116 PIN_DIRECTION this_pin_dir = static_cast<PIN_DIRECTION>(-1);
117 hr = (*pin)->QueryDirection(&this_pin_dir); 117 hr = pin->QueryDirection(&this_pin_dir);
118 if (pin_dir == this_pin_dir) { 118 if (pin_dir == this_pin_dir) {
119 if (category == GUID_NULL || PinMatchesCategory(*pin, category)) 119 if (category == GUID_NULL || PinMatchesCategory(pin, category))
120 return S_OK; 120 return pin;
121 } 121 }
122 (*pin)->Release(); 122 pin.Release();
123 } 123 }
124 124
125 return E_FAIL; 125 DCHECK(!pin);
126 return pin;
126 } 127 }
127 128
128 // Release the format block for a media type. 129 // Release the format block for a media type.
129 // http://msdn.microsoft.com/en-us/library/dd375432(VS.85).aspx 130 // http://msdn.microsoft.com/en-us/library/dd375432(VS.85).aspx
130 void FreeMediaType(AM_MEDIA_TYPE* mt) { 131 void FreeMediaType(AM_MEDIA_TYPE* mt) {
131 if (mt->cbFormat != 0) { 132 if (mt->cbFormat != 0) {
132 CoTaskMemFree(mt->pbFormat); 133 CoTaskMemFree(mt->pbFormat);
133 mt->cbFormat = 0; 134 mt->cbFormat = 0;
134 mt->pbFormat = NULL; 135 mt->pbFormat = NULL;
135 } 136 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 } 377 }
377 378
378 if (moniker.get()) { 379 if (moniker.get()) {
379 base::win::ScopedComPtr<IBaseFilter> capture_filter; 380 base::win::ScopedComPtr<IBaseFilter> capture_filter;
380 hr = GetDeviceFilter(device, capture_filter.Receive()); 381 hr = GetDeviceFilter(device, capture_filter.Receive());
381 if (!capture_filter) { 382 if (!capture_filter) {
382 DVLOG(2) << "Failed to create capture filter."; 383 DVLOG(2) << "Failed to create capture filter.";
383 return; 384 return;
384 } 385 }
385 386
386 base::win::ScopedComPtr<IPin> output_capture_pin; 387 base::win::ScopedComPtr<IPin> output_capture_pin(
387 hr = GetPin(capture_filter, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE, 388 GetPin(capture_filter, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE));
388 output_capture_pin.Receive());
389 if (!output_capture_pin) { 389 if (!output_capture_pin) {
390 DVLOG(2) << "Failed to get capture output pin"; 390 DVLOG(2) << "Failed to get capture output pin";
391 return; 391 return;
392 } 392 }
393 393
394 ScopedComPtr<IAMStreamConfig> stream_config; 394 ScopedComPtr<IAMStreamConfig> stream_config;
395 hr = output_capture_pin.QueryInterface(stream_config.Receive()); 395 hr = output_capture_pin.QueryInterface(stream_config.Receive());
396 if (FAILED(hr)) { 396 if (FAILED(hr)) {
397 DVLOG(2) << "Failed to get IAMStreamConfig interface from " 397 DVLOG(2) << "Failed to get IAMStreamConfig interface from "
398 "capture device"; 398 "capture device";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 465 }
466 466
467 bool VideoCaptureDeviceWin::Init() { 467 bool VideoCaptureDeviceWin::Init() {
468 DCHECK(CalledOnValidThread()); 468 DCHECK(CalledOnValidThread());
469 HRESULT hr = GetDeviceFilter(device_name_, capture_filter_.Receive()); 469 HRESULT hr = GetDeviceFilter(device_name_, capture_filter_.Receive());
470 if (!capture_filter_) { 470 if (!capture_filter_) {
471 DVLOG(2) << "Failed to create capture filter."; 471 DVLOG(2) << "Failed to create capture filter.";
472 return false; 472 return false;
473 } 473 }
474 474
475 hr = GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE, 475 output_capture_pin_ =
476 output_capture_pin_.Receive()); 476 GetPin(capture_filter_, PINDIR_OUTPUT, PIN_CATEGORY_CAPTURE);
477 if (!output_capture_pin_) { 477 if (!output_capture_pin_) {
478 DVLOG(2) << "Failed to get capture output pin"; 478 DVLOG(2) << "Failed to get capture output pin";
479 return false; 479 return false;
480 } 480 }
481 481
482 // Create the sink filter used for receiving Captured frames. 482 // Create the sink filter used for receiving Captured frames.
483 sink_filter_ = new SinkFilter(this); 483 sink_filter_ = new SinkFilter(this);
484 if (sink_filter_ == NULL) { 484 if (sink_filter_ == NULL) {
485 DVLOG(2) << "Failed to create send filter"; 485 DVLOG(2) << "Failed to create send filter";
486 return false; 486 return false;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 } 572 }
573 573
574 if (FAILED(hr)) 574 if (FAILED(hr))
575 SetErrorState("Failed to set capture device output format"); 575 SetErrorState("Failed to set capture device output format");
576 576
577 if (format.pixel_format == PIXEL_FORMAT_MJPEG && !mjpg_filter_.get()) { 577 if (format.pixel_format == PIXEL_FORMAT_MJPEG && !mjpg_filter_.get()) {
578 // Create MJPG filter if we need it. 578 // Create MJPG filter if we need it.
579 hr = mjpg_filter_.CreateInstance(CLSID_MjpegDec, NULL, CLSCTX_INPROC); 579 hr = mjpg_filter_.CreateInstance(CLSID_MjpegDec, NULL, CLSCTX_INPROC);
580 580
581 if (SUCCEEDED(hr)) { 581 if (SUCCEEDED(hr)) {
582 GetPin(mjpg_filter_, PINDIR_INPUT, GUID_NULL, input_mjpg_pin_.Receive()); 582 input_mjpg_pin_ = GetPin(mjpg_filter_, PINDIR_INPUT, GUID_NULL);
583 GetPin(mjpg_filter_, PINDIR_OUTPUT, GUID_NULL, 583 output_mjpg_pin_ = GetPin(mjpg_filter_, PINDIR_OUTPUT, GUID_NULL);
584 output_mjpg_pin_.Receive());
585 hr = graph_builder_->AddFilter(mjpg_filter_, NULL); 584 hr = graph_builder_->AddFilter(mjpg_filter_, NULL);
586 } 585 }
587 586
588 if (FAILED(hr)) { 587 if (FAILED(hr)) {
589 mjpg_filter_.Release(); 588 mjpg_filter_.Release();
590 input_mjpg_pin_.Release(); 589 input_mjpg_pin_.Release();
591 output_mjpg_pin_.Release(); 590 output_mjpg_pin_.Release();
592 } 591 }
593 } 592 }
594 593
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 return !capabilities_.empty(); 749 return !capabilities_.empty();
751 } 750 }
752 751
753 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) { 752 void VideoCaptureDeviceWin::SetErrorState(const std::string& reason) {
754 DCHECK(CalledOnValidThread()); 753 DCHECK(CalledOnValidThread());
755 DVLOG(1) << reason; 754 DVLOG(1) << reason;
756 state_ = kError; 755 state_ = kError;
757 client_->OnError(reason); 756 client_->OnError(reason);
758 } 757 }
759 } // namespace media 758 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698