Commit 63038c90 authored by mcasas's avatar mcasas Committed by Commit bot

Video Capture Device Win: cleanup error logging

While writing other code, I found out that the error logging
in VCDWin is cumbersome: it is too verbose on Init() and
doesn't dump the HRESULT while capturing.

So: This CL adds a macro DLOG_IF_WITH_HRESULT() that logs
an error message _and_ the stringified HRESULT. It also
sends an HRESULT to SetErrorMessage() to dump it on
stdout.

In my experience, all these loggings are only used
by developers to try and guess what goes wrong in Win
bots when those fail, so the less release code they take
up the better.

BUG=405016, 648490

Review-Url: https://codereview.chromium.org/2365533004
Cr-Commit-Position: refs/heads/master@{#420493}
parent 63903481
...@@ -24,6 +24,17 @@ using base::win::ScopedVariant; ...@@ -24,6 +24,17 @@ using base::win::ScopedVariant;
namespace media { namespace media {
#if DCHECK_IS_ON()
#define DLOG_IF_FAILED_WITH_HRESULT(message, hr) \
{ \
DLOG_IF(ERROR, FAILED(hr)) << (message) << ": " \
<< logging::SystemErrorCodeToString(hr); \
}
#else
#define DLOG_IF_FAILED_WITH_HRESULT(message, hr) \
{}
#endif
// Check if a Pin matches a category. // Check if a Pin matches a category.
bool PinMatchesCategory(IPin* pin, REFGUID category) { bool PinMatchesCategory(IPin* pin, REFGUID category) {
DCHECK(pin); DCHECK(pin);
...@@ -242,12 +253,9 @@ bool VideoCaptureDeviceWin::Init() { ...@@ -242,12 +253,9 @@ bool VideoCaptureDeviceWin::Init() {
HRESULT hr; HRESULT hr;
hr = GetDeviceFilter(device_descriptor_.device_id, capture_filter_.Receive()); hr = GetDeviceFilter(device_descriptor_.device_id, capture_filter_.Receive());
DLOG_IF_FAILED_WITH_HRESULT("Failed to create capture filter", hr);
if (!capture_filter_.get()) { if (!capture_filter_.get())
DLOG(ERROR) << "Failed to create capture filter: "
<< logging::SystemErrorCodeToString(hr);
return false; return false;
}
output_capture_pin_ = GetPin(capture_filter_.get(), PINDIR_OUTPUT, output_capture_pin_ = GetPin(capture_filter_.get(), PINDIR_OUTPUT,
PIN_CATEGORY_CAPTURE, GUID_NULL); PIN_CATEGORY_CAPTURE, GUID_NULL);
...@@ -267,54 +275,43 @@ bool VideoCaptureDeviceWin::Init() { ...@@ -267,54 +275,43 @@ bool VideoCaptureDeviceWin::Init() {
hr = graph_builder_.CreateInstance(CLSID_FilterGraph, NULL, hr = graph_builder_.CreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER); CLSCTX_INPROC_SERVER);
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT("Failed to create capture filter", hr);
DLOG(ERROR) << "Failed to create graph builder: " if (FAILED(hr))
<< logging::SystemErrorCodeToString(hr);
return false; return false;
}
hr = capture_graph_builder_.CreateInstance(CLSID_CaptureGraphBuilder2, NULL, hr = capture_graph_builder_.CreateInstance(CLSID_CaptureGraphBuilder2, NULL,
CLSCTX_INPROC); CLSCTX_INPROC);
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT("Failed to create the Capture Graph Builder", hr);
DLOG(ERROR) << "Failed to create the Capture Graph Builder: " if (FAILED(hr))
<< logging::SystemErrorCodeToString(hr);
return false; return false;
}
hr = capture_graph_builder_->SetFiltergraph(graph_builder_.get()); hr = capture_graph_builder_->SetFiltergraph(graph_builder_.get());
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT("Failed to give graph to capture graph builder",
DLOG(ERROR) << "Failed to give graph to capture graph builder: " hr);
<< logging::SystemErrorCodeToString(hr); if (FAILED(hr))
return false; return false;
}
hr = graph_builder_.QueryInterface(media_control_.Receive()); hr = graph_builder_.QueryInterface(media_control_.Receive());
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT("Failed to create media control builder", hr);
DLOG(ERROR) << "Failed to create media control builder: " if (FAILED(hr))
<< logging::SystemErrorCodeToString(hr);
return false; return false;
}
hr = graph_builder_->AddFilter(capture_filter_.get(), NULL); hr = graph_builder_->AddFilter(capture_filter_.get(), NULL);
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT("Failed to add the capture device to the graph",
DLOG(ERROR) << "Failed to add the capture device to the graph: " hr);
<< logging::SystemErrorCodeToString(hr); if (FAILED(hr))
return false; return false;
}
hr = graph_builder_->AddFilter(sink_filter_.get(), NULL); hr = graph_builder_->AddFilter(sink_filter_.get(), NULL);
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT("Failed to add the sink filter to the graph", hr);
DLOG(ERROR) << "Failed to add the sink filter to the graph: " if (FAILED(hr))
<< logging::SystemErrorCodeToString(hr);
return false; return false;
}
// The following code builds the upstream portions of the graph, // The following code builds the upstream portions of the graph, for example
// for example if a capture device uses a Windows Driver Model (WDM) // if a capture device uses a Windows Driver Model (WDM) driver, the graph may
// driver, the graph may require certain filters upstream from the // require certain filters upstream from the WDM Video Capture filter, such as
// WDM Video Capture filter, such as a TV Tuner filter or an Analog // a TV Tuner filter or an Analog Video Crossbar filter. We try using the more
// Video Crossbar filter. We try using the more prevalent // prevalent MEDIATYPE_Interleaved first.
// MEDIATYPE_Interleaved first.
base::win::ScopedComPtr<IAMStreamConfig> stream_config; base::win::ScopedComPtr<IAMStreamConfig> stream_config;
hr = capture_graph_builder_->FindInterface( hr = capture_graph_builder_->FindInterface(
...@@ -324,8 +321,7 @@ bool VideoCaptureDeviceWin::Init() { ...@@ -324,8 +321,7 @@ bool VideoCaptureDeviceWin::Init() {
hr = capture_graph_builder_->FindInterface( hr = capture_graph_builder_->FindInterface(
&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, capture_filter_.get(), &PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, capture_filter_.get(),
IID_IAMStreamConfig, (void**)stream_config.Receive()); IID_IAMStreamConfig, (void**)stream_config.Receive());
DLOG_IF(ERROR, FAILED(hr)) << "Failed to find CapFilter:IAMStreamConfig: " DLOG_IF_FAILED_WITH_HRESULT("Failed to find CapFilter:IAMStreamConfig", hr);
<< logging::SystemErrorCodeToString(hr);
} }
return CreateCapabilityMap(); return CreateCapabilityMap();
...@@ -353,14 +349,14 @@ void VideoCaptureDeviceWin::AllocateAndStart( ...@@ -353,14 +349,14 @@ void VideoCaptureDeviceWin::AllocateAndStart(
ScopedComPtr<IAMStreamConfig> stream_config; ScopedComPtr<IAMStreamConfig> stream_config;
HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive());
if (FAILED(hr)) { if (FAILED(hr)) {
SetErrorState(FROM_HERE, "Can't get the Capture format settings"); SetErrorState(FROM_HERE, "Can't get the Capture format settings", hr);
return; return;
} }
int count = 0, size = 0; int count = 0, size = 0;
hr = stream_config->GetNumberOfCapabilities(&count, &size); hr = stream_config->GetNumberOfCapabilities(&count, &size);
if (FAILED(hr)) { if (FAILED(hr)) {
SetErrorState(FROM_HERE, "Failed to GetNumberOfCapabilities"); SetErrorState(FROM_HERE, "Failed to GetNumberOfCapabilities", hr);
return; return;
} }
...@@ -373,7 +369,7 @@ void VideoCaptureDeviceWin::AllocateAndStart( ...@@ -373,7 +369,7 @@ void VideoCaptureDeviceWin::AllocateAndStart(
hr = stream_config->GetStreamCaps(found_capability.stream_index, hr = stream_config->GetStreamCaps(found_capability.stream_index,
media_type.Receive(), caps.get()); media_type.Receive(), caps.get());
if (hr != S_OK) { if (hr != S_OK) {
SetErrorState(FROM_HERE, "Failed to get capture device capabilities"); SetErrorState(FROM_HERE, "Failed to get capture device capabilities", hr);
return; return;
} }
if (media_type->formattype == FORMAT_VideoInfo) { if (media_type->formattype == FORMAT_VideoInfo) {
...@@ -389,8 +385,7 @@ void VideoCaptureDeviceWin::AllocateAndStart( ...@@ -389,8 +385,7 @@ void VideoCaptureDeviceWin::AllocateAndStart(
// Order the capture device to use this format. // Order the capture device to use this format.
hr = stream_config->SetFormat(media_type.get()); hr = stream_config->SetFormat(media_type.get());
if (FAILED(hr)) { if (FAILED(hr)) {
// TODO(grunell): Log the error. http://crbug.com/405016. SetErrorState(FROM_HERE, "Failed to set capture device output format", hr);
SetErrorState(FROM_HERE, "Failed to set capture device output format");
return; return;
} }
...@@ -407,15 +402,13 @@ void VideoCaptureDeviceWin::AllocateAndStart( ...@@ -407,15 +402,13 @@ void VideoCaptureDeviceWin::AllocateAndStart(
} }
if (FAILED(hr)) { if (FAILED(hr)) {
SetErrorState(FROM_HERE, "Failed to connect the Capture graph."); SetErrorState(FROM_HERE, "Failed to connect the Capture graph.", hr);
return; return;
} }
hr = media_control_->Pause(); hr = media_control_->Pause();
if (FAILED(hr)) { if (FAILED(hr)) {
SetErrorState( SetErrorState(FROM_HERE, "Failed to pause the Capture device", hr);
FROM_HERE,
"Failed to pause the Capture device, is it already occupied?");
return; return;
} }
...@@ -426,7 +419,7 @@ void VideoCaptureDeviceWin::AllocateAndStart( ...@@ -426,7 +419,7 @@ void VideoCaptureDeviceWin::AllocateAndStart(
// Start capturing. // Start capturing.
hr = media_control_->Run(); hr = media_control_->Run();
if (FAILED(hr)) { if (FAILED(hr)) {
SetErrorState(FROM_HERE, "Failed to start the Capture device."); SetErrorState(FROM_HERE, "Failed to start the Capture device.", hr);
return; return;
} }
...@@ -440,7 +433,7 @@ void VideoCaptureDeviceWin::StopAndDeAllocate() { ...@@ -440,7 +433,7 @@ void VideoCaptureDeviceWin::StopAndDeAllocate() {
HRESULT hr = media_control_->Stop(); HRESULT hr = media_control_->Stop();
if (FAILED(hr)) { if (FAILED(hr)) {
SetErrorState(FROM_HERE, "Failed to stop the capture graph."); SetErrorState(FROM_HERE, "Failed to stop the capture graph.", hr);
return; return;
} }
...@@ -489,25 +482,20 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() { ...@@ -489,25 +482,20 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
ScopedComPtr<IAMStreamConfig> stream_config; ScopedComPtr<IAMStreamConfig> stream_config;
HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive()); HRESULT hr = output_capture_pin_.QueryInterface(stream_config.Receive());
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT(
DPLOG(ERROR) << "Failed to get IAMStreamConfig interface from " "Failed to get IAMStreamConfig from capture device", hr);
"capture device: " << logging::SystemErrorCodeToString(hr); if (FAILED(hr))
return false; return false;
}
// Get interface used for getting the frame rate. // Get interface used for getting the frame rate.
ScopedComPtr<IAMVideoControl> video_control; ScopedComPtr<IAMVideoControl> video_control;
hr = capture_filter_.QueryInterface(video_control.Receive()); hr = capture_filter_.QueryInterface(video_control.Receive());
DLOG_IF(WARNING, FAILED(hr)) << "IAMVideoControl Interface NOT SUPPORTED: "
<< logging::SystemErrorCodeToString(hr);
int count = 0, size = 0; int count = 0, size = 0;
hr = stream_config->GetNumberOfCapabilities(&count, &size); hr = stream_config->GetNumberOfCapabilities(&count, &size);
if (FAILED(hr)) { DLOG_IF_FAILED_WITH_HRESULT("Failed to GetNumberOfCapabilities", hr);
DLOG(ERROR) << "Failed to GetNumberOfCapabilities: " if (FAILED(hr))
<< logging::SystemErrorCodeToString(hr);
return false; return false;
}
std::unique_ptr<BYTE[]> caps(new BYTE[size]); std::unique_ptr<BYTE[]> caps(new BYTE[size]);
for (int stream_index = 0; stream_index < count; ++stream_index) { for (int stream_index = 0; stream_index < count; ++stream_index) {
...@@ -517,8 +505,7 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() { ...@@ -517,8 +505,7 @@ bool VideoCaptureDeviceWin::CreateCapabilityMap() {
// GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED()
// macros here since they'll trigger incorrectly. // macros here since they'll trigger incorrectly.
if (hr != S_OK) { if (hr != S_OK) {
DLOG(ERROR) << "Failed to GetStreamCaps: " DLOG(ERROR) << "Failed to GetStreamCaps";
<< logging::SystemErrorCodeToString(hr);
return false; return false;
} }
...@@ -595,18 +582,16 @@ void VideoCaptureDeviceWin::SetAntiFlickerInCaptureFilter( ...@@ -595,18 +582,16 @@ void VideoCaptureDeviceWin::SetAntiFlickerInCaptureFilter(
hr = ks_propset->Set(PROPSETID_VIDCAP_VIDEOPROCAMP, hr = ks_propset->Set(PROPSETID_VIDCAP_VIDEOPROCAMP,
KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY, &data, KSPROPERTY_VIDEOPROCAMP_POWERLINE_FREQUENCY, &data,
sizeof(data), &data, sizeof(data)); sizeof(data), &data, sizeof(data));
DLOG_IF(ERROR, FAILED(hr)) << "Anti-flicker setting failed: " DLOG_IF_FAILED_WITH_HRESULT("Anti-flicker setting failed", hr);
<< logging::SystemErrorCodeToString(hr);
DVLOG_IF(2, SUCCEEDED(hr)) << "Anti-flicker set correctly.";
} else {
DVLOG(2) << "Anti-flicker setting not supported.";
} }
} }
void VideoCaptureDeviceWin::SetErrorState( void VideoCaptureDeviceWin::SetErrorState(
const tracked_objects::Location& from_here, const tracked_objects::Location& from_here,
const std::string& reason) { const std::string& reason,
HRESULT hr) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
DLOG_IF_FAILED_WITH_HRESULT(reason, hr);
state_ = kError; state_ = kError;
client_->OnError(from_here, reason); client_->OnError(from_here, reason);
} }
......
...@@ -93,7 +93,8 @@ class VideoCaptureDeviceWin : public VideoCaptureDevice, ...@@ -93,7 +93,8 @@ class VideoCaptureDeviceWin : public VideoCaptureDevice,
bool CreateCapabilityMap(); bool CreateCapabilityMap();
void SetAntiFlickerInCaptureFilter(const VideoCaptureParams& params); void SetAntiFlickerInCaptureFilter(const VideoCaptureParams& params);
void SetErrorState(const tracked_objects::Location& from_here, void SetErrorState(const tracked_objects::Location& from_here,
const std::string& reason); const std::string& reason,
HRESULT hr);
const VideoCaptureDeviceDescriptor device_descriptor_; const VideoCaptureDeviceDescriptor device_descriptor_;
InternalState state_; InternalState state_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment