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

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

Issue 489183003: Log error messages in windows video capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: syntax error : missing ')' Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_factory_win.h" 5 #include "media/video/capture/win/video_capture_device_factory_win.h"
6 6
7 #include <mfapi.h> 7 #include <mfapi.h>
8 #include <mferror.h> 8 #include <mferror.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 hr = devices[i]->GetAllocatedString( 178 hr = devices[i]->GetAllocatedString(
179 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id, 179 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id,
180 &id_size); 180 &id_size);
181 if (SUCCEEDED(hr)) { 181 if (SUCCEEDED(hr)) {
182 device_names->push_back(VideoCaptureDevice::Name( 182 device_names->push_back(VideoCaptureDevice::Name(
183 base::SysWideToUTF8(std::wstring(name, name_size)), 183 base::SysWideToUTF8(std::wstring(name, name_size)),
184 base::SysWideToUTF8(std::wstring(id, id_size)), 184 base::SysWideToUTF8(std::wstring(id, id_size)),
185 VideoCaptureDevice::Name::MEDIA_FOUNDATION)); 185 VideoCaptureDevice::Name::MEDIA_FOUNDATION));
186 } 186 }
187 } 187 }
188 if (FAILED(hr)) 188 DLOG_IF(ERROR, FAILED(hr)) << "GetAllocatedString failed: "
189 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; 189 << logging::SystemErrorCodeToString(hr);
tommi (sloooow) - chröme 2014/08/30 17:39:33 nit: it might also be good to include the numeric
magjed_chromium 2014/09/01 08:34:14 See message.
190 devices[i]->Release(); 190 devices[i]->Release();
191 } 191 }
192 } 192 }
193 193
194 static void GetDeviceSupportedFormatsDirectShow( 194 static void GetDeviceSupportedFormatsDirectShow(
195 const VideoCaptureDevice::Name& device, 195 const VideoCaptureDevice::Name& device,
196 VideoCaptureFormats* formats) { 196 VideoCaptureFormats* formats) {
197 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name(); 197 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name();
198 ScopedComPtr<ICreateDevEnum> dev_enum; 198 ScopedComPtr<ICreateDevEnum> dev_enum;
199 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, 199 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL,
200 CLSCTX_INPROC); 200 CLSCTX_INPROC);
201 if (FAILED(hr)) 201 if (FAILED(hr))
202 return; 202 return;
203 203
204 ScopedComPtr<IEnumMoniker> enum_moniker; 204 ScopedComPtr<IEnumMoniker> enum_moniker;
205 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, 205 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
206 enum_moniker.Receive(), 0); 206 enum_moniker.Receive(), 0);
207 // CreateClassEnumerator returns S_FALSE on some Windows OS when no camera 207 // CreateClassEnumerator returns S_FALSE on some Windows OS when no camera
208 // exists. Therefore the FAILED macro can't be used. 208 // exists. Therefore the FAILED macro can't be used.
209 if (hr != S_OK) 209 if (hr != S_OK)
210 return; 210 return;
211 211
212 // Walk the capture devices. No need to check for device presence again, that 212 // Walk the capture devices. No need to check for device presence again, that
213 // is caught in GetDeviceFilter(). "google camera adapter" and old VFW devices 213 // is caught in GetDeviceFilter(). "google camera adapter" and old VFW devices
214 // are already skipped in the previous GetDeviceNames() enumeration. 214 // are already skipped in the previous GetDeviceNames() enumeration.
215 base::win::ScopedComPtr<IBaseFilter> capture_filter; 215 base::win::ScopedComPtr<IBaseFilter> capture_filter;
216 hr = VideoCaptureDeviceWin::GetDeviceFilter(device, 216 hr = VideoCaptureDeviceWin::GetDeviceFilter(device,
217 capture_filter.Receive()); 217 capture_filter.Receive());
218 if (!capture_filter) { 218 if (!capture_filter) {
219 DVLOG(2) << "Failed to create capture filter."; 219 DLOG(ERROR) << "Failed to create capture filter: "
220 << logging::SystemErrorCodeToString(hr);
220 return; 221 return;
221 } 222 }
222 223
223 base::win::ScopedComPtr<IPin> output_capture_pin( 224 base::win::ScopedComPtr<IPin> output_capture_pin(
224 VideoCaptureDeviceWin::GetPin(capture_filter, 225 VideoCaptureDeviceWin::GetPin(capture_filter,
225 PINDIR_OUTPUT, 226 PINDIR_OUTPUT,
226 PIN_CATEGORY_CAPTURE)); 227 PIN_CATEGORY_CAPTURE));
227 if (!output_capture_pin) { 228 if (!output_capture_pin) {
228 DVLOG(2) << "Failed to get capture output pin"; 229 DLOG(ERROR) << "Failed to get capture output pin";
229 return; 230 return;
230 } 231 }
231 232
232 ScopedComPtr<IAMStreamConfig> stream_config; 233 ScopedComPtr<IAMStreamConfig> stream_config;
233 hr = output_capture_pin.QueryInterface(stream_config.Receive()); 234 hr = output_capture_pin.QueryInterface(stream_config.Receive());
234 if (FAILED(hr)) { 235 if (FAILED(hr)) {
235 DVLOG(2) << "Failed to get IAMStreamConfig interface from " 236 DLOG(ERROR) << "Failed to get IAMStreamConfig interface from "
236 "capture device"; 237 "capture device: " << logging::SystemErrorCodeToString(hr);
237 return; 238 return;
238 } 239 }
239 240
240 int count = 0, size = 0; 241 int count = 0, size = 0;
241 hr = stream_config->GetNumberOfCapabilities(&count, &size); 242 hr = stream_config->GetNumberOfCapabilities(&count, &size);
242 if (FAILED(hr)) { 243 if (FAILED(hr)) {
243 DVLOG(2) << "Failed to GetNumberOfCapabilities"; 244 DLOG(ERROR) << "GetNumberOfCapabilities failed: "
245 << logging::SystemErrorCodeToString(hr);
244 return; 246 return;
245 } 247 }
246 248
247 scoped_ptr<BYTE[]> caps(new BYTE[size]); 249 scoped_ptr<BYTE[]> caps(new BYTE[size]);
248 for (int i = 0; i < count; ++i) { 250 for (int i = 0; i < count; ++i) {
249 VideoCaptureDeviceWin::ScopedMediaType media_type; 251 VideoCaptureDeviceWin::ScopedMediaType media_type;
250 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); 252 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get());
251 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() 253 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED()
252 // macros here since they'll trigger incorrectly. 254 // macros here since they'll trigger incorrectly.
253 if (hr != S_OK) { 255 if (hr != S_OK) {
254 DVLOG(2) << "Failed to GetStreamCaps"; 256 DLOG(ERROR) << "GetStreamCaps failed: "
257 << logging::SystemErrorCodeToString(hr);
255 return; 258 return;
256 } 259 }
257 260
258 if (media_type->majortype == MEDIATYPE_Video && 261 if (media_type->majortype == MEDIATYPE_Video &&
259 media_type->formattype == FORMAT_VideoInfo) { 262 media_type->formattype == FORMAT_VideoInfo) {
260 VideoCaptureFormat format; 263 VideoCaptureFormat format;
261 format.pixel_format = 264 format.pixel_format =
262 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( 265 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat(
263 media_type->subtype); 266 media_type->subtype);
264 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN) 267 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN)
(...skipping 21 matching lines...) Expand all
286 ScopedComPtr<IMFMediaSource> source; 289 ScopedComPtr<IMFMediaSource> source;
287 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), 290 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(),
288 source.Receive())) { 291 source.Receive())) {
289 return; 292 return;
290 } 293 }
291 294
292 base::win::ScopedComPtr<IMFSourceReader> reader; 295 base::win::ScopedComPtr<IMFSourceReader> reader;
293 HRESULT hr = 296 HRESULT hr =
294 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive()); 297 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive());
295 if (FAILED(hr)) { 298 if (FAILED(hr)) {
296 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr; 299 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource failed: "
300 << logging::SystemErrorCodeToString(hr);
297 return; 301 return;
298 } 302 }
299 303
300 DWORD stream_index = 0; 304 DWORD stream_index = 0;
301 ScopedComPtr<IMFMediaType> type; 305 ScopedComPtr<IMFMediaType> type;
302 for (hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, 306 for (hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index,
303 type.Receive()); 307 type.Receive());
304 SUCCEEDED(hr); 308 SUCCEEDED(hr);
305 hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, 309 hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index,
306 type.Receive())) { 310 type.Receive())) {
307 UINT32 width, height; 311 UINT32 width, height;
308 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); 312 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height);
309 if (FAILED(hr)) { 313 if (FAILED(hr)) {
310 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 314 DLOG(ERROR) << "MFGetAttributeSize failed: "
315 << logging::SystemErrorCodeToString(hr);
311 return; 316 return;
312 } 317 }
313 VideoCaptureFormat capture_format; 318 VideoCaptureFormat capture_format;
314 capture_format.frame_size.SetSize(width, height); 319 capture_format.frame_size.SetSize(width, height);
315 320
316 UINT32 numerator, denominator; 321 UINT32 numerator, denominator;
317 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator); 322 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator);
318 if (FAILED(hr)) { 323 if (FAILED(hr)) {
319 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 324 DLOG(ERROR) << "MFGetAttributeSize failed: "
325 << logging::SystemErrorCodeToString(hr);
320 return; 326 return;
321 } 327 }
322 capture_format.frame_rate = denominator 328 capture_format.frame_rate = denominator
323 ? static_cast<float>(numerator) / denominator : 0.0f; 329 ? static_cast<float>(numerator) / denominator : 0.0f;
324 330
325 GUID type_guid; 331 GUID type_guid;
326 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid); 332 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid);
327 if (FAILED(hr)) { 333 if (FAILED(hr)) {
328 DLOG(ERROR) << "GetGUID: " << std::hex << hr; 334 DLOG(ERROR) << "GetGUID failed: "
335 << logging::SystemErrorCodeToString(hr);
329 return; 336 return;
330 } 337 }
331 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, 338 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid,
332 &capture_format.pixel_format); 339 &capture_format.pixel_format);
333 type.Release(); 340 type.Release();
334 formats->push_back(capture_format); 341 formats->push_back(capture_format);
335 ++stream_index; 342 ++stream_index;
336 343
337 DVLOG(1) << device.name() << " resolution: " 344 DVLOG(1) << device.name() << " resolution: "
338 << capture_format.frame_size.ToString() << ", fps: " 345 << capture_format.frame_size.ToString() << ", fps: "
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 const VideoCaptureDevice::Name& device, 417 const VideoCaptureDevice::Name& device,
411 VideoCaptureFormats* formats) { 418 VideoCaptureFormats* formats) {
412 DCHECK(thread_checker_.CalledOnValidThread()); 419 DCHECK(thread_checker_.CalledOnValidThread());
413 if (use_media_foundation_) 420 if (use_media_foundation_)
414 GetDeviceSupportedFormatsMediaFoundation(device, formats); 421 GetDeviceSupportedFormatsMediaFoundation(device, formats);
415 else 422 else
416 GetDeviceSupportedFormatsDirectShow(device, formats); 423 GetDeviceSupportedFormatsDirectShow(device, formats);
417 } 424 }
418 425
419 } // namespace media 426 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698