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: merge conflicts? 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 hr = devices[i]->GetAllocatedString( 192 hr = devices[i]->GetAllocatedString(
193 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id, 193 MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &id,
194 &id_size); 194 &id_size);
195 if (SUCCEEDED(hr)) { 195 if (SUCCEEDED(hr)) {
196 device_names->push_back(Name( 196 device_names->push_back(Name(
197 base::SysWideToUTF8(std::wstring(name, name_size)), 197 base::SysWideToUTF8(std::wstring(name, name_size)),
198 base::SysWideToUTF8(std::wstring(id, id_size)), 198 base::SysWideToUTF8(std::wstring(id, id_size)),
199 Name::MEDIA_FOUNDATION)); 199 Name::MEDIA_FOUNDATION));
200 } 200 }
201 } 201 }
202 if (FAILED(hr)) 202 DLOG_IF(ERROR, FAILED(hr)) << "GetAllocatedString failed: "
203 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; 203 << logging::SystemErrorCodeToString(hr);
204 devices[i]->Release(); 204 devices[i]->Release();
205 } 205 }
206 } 206 }
207 207
208 static void GetDeviceSupportedFormatsDirectShow(const Name& device, 208 static void GetDeviceSupportedFormatsDirectShow(const Name& device,
209 VideoCaptureFormats* formats) { 209 VideoCaptureFormats* formats) {
210 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name(); 210 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name();
211 ScopedComPtr<ICreateDevEnum> dev_enum; 211 ScopedComPtr<ICreateDevEnum> dev_enum;
212 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, 212 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL,
213 CLSCTX_INPROC); 213 CLSCTX_INPROC);
214 if (FAILED(hr)) 214 if (FAILED(hr))
215 return; 215 return;
216 216
217 ScopedComPtr<IEnumMoniker> enum_moniker; 217 ScopedComPtr<IEnumMoniker> enum_moniker;
218 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, 218 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
219 enum_moniker.Receive(), 0); 219 enum_moniker.Receive(), 0);
220 // CreateClassEnumerator returns S_FALSE on some Windows OS when no camera 220 // CreateClassEnumerator returns S_FALSE on some Windows OS when no camera
221 // exists. Therefore the FAILED macro can't be used. 221 // exists. Therefore the FAILED macro can't be used.
222 if (hr != S_OK) 222 if (hr != S_OK)
223 return; 223 return;
224 224
225 // Walk the capture devices. No need to check for device presence again, that 225 // Walk the capture devices. No need to check for device presence again, that
226 // is caught in GetDeviceFilter(). "google camera adapter" and old VFW devices 226 // is caught in GetDeviceFilter(). "google camera adapter" and old VFW devices
227 // are already skipped in the previous GetDeviceNames() enumeration. 227 // are already skipped in the previous GetDeviceNames() enumeration.
228 base::win::ScopedComPtr<IBaseFilter> capture_filter; 228 base::win::ScopedComPtr<IBaseFilter> capture_filter;
229 hr = VideoCaptureDeviceWin::GetDeviceFilter(device, 229 hr = VideoCaptureDeviceWin::GetDeviceFilter(device,
230 capture_filter.Receive()); 230 capture_filter.Receive());
231 if (!capture_filter) { 231 if (!capture_filter) {
232 DVLOG(2) << "Failed to create capture filter."; 232 DLOG(ERROR) << "Failed to create capture filter: "
233 << logging::SystemErrorCodeToString(hr);
233 return; 234 return;
234 } 235 }
235 236
236 base::win::ScopedComPtr<IPin> output_capture_pin( 237 base::win::ScopedComPtr<IPin> output_capture_pin(
237 VideoCaptureDeviceWin::GetPin(capture_filter, 238 VideoCaptureDeviceWin::GetPin(capture_filter,
238 PINDIR_OUTPUT, 239 PINDIR_OUTPUT,
239 PIN_CATEGORY_CAPTURE)); 240 PIN_CATEGORY_CAPTURE));
240 if (!output_capture_pin) { 241 if (!output_capture_pin) {
241 DVLOG(2) << "Failed to get capture output pin"; 242 DLOG(ERROR) << "Failed to get capture output pin";
242 return; 243 return;
243 } 244 }
244 245
245 ScopedComPtr<IAMStreamConfig> stream_config; 246 ScopedComPtr<IAMStreamConfig> stream_config;
246 hr = output_capture_pin.QueryInterface(stream_config.Receive()); 247 hr = output_capture_pin.QueryInterface(stream_config.Receive());
247 if (FAILED(hr)) { 248 if (FAILED(hr)) {
248 DVLOG(2) << "Failed to get IAMStreamConfig interface from " 249 DLOG(ERROR) << "Failed to get IAMStreamConfig interface from "
249 "capture device"; 250 "capture device: " << logging::SystemErrorCodeToString(hr);
250 return; 251 return;
251 } 252 }
252 253
253 int count = 0, size = 0; 254 int count = 0, size = 0;
254 hr = stream_config->GetNumberOfCapabilities(&count, &size); 255 hr = stream_config->GetNumberOfCapabilities(&count, &size);
255 if (FAILED(hr)) { 256 if (FAILED(hr)) {
256 DVLOG(2) << "Failed to GetNumberOfCapabilities"; 257 DLOG(ERROR) << "GetNumberOfCapabilities failed: "
258 << logging::SystemErrorCodeToString(hr);
257 return; 259 return;
258 } 260 }
259 261
260 scoped_ptr<BYTE[]> caps(new BYTE[size]); 262 scoped_ptr<BYTE[]> caps(new BYTE[size]);
261 for (int i = 0; i < count; ++i) { 263 for (int i = 0; i < count; ++i) {
262 VideoCaptureDeviceWin::ScopedMediaType media_type; 264 VideoCaptureDeviceWin::ScopedMediaType media_type;
263 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); 265 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get());
264 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() 266 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED()
265 // macros here since they'll trigger incorrectly. 267 // macros here since they'll trigger incorrectly.
266 if (hr != S_OK) { 268 if (hr != S_OK) {
267 DVLOG(2) << "Failed to GetStreamCaps"; 269 DLOG(ERROR) << "GetStreamCaps failed: "
270 << logging::SystemErrorCodeToString(hr);
268 return; 271 return;
269 } 272 }
270 273
271 if (media_type->majortype == MEDIATYPE_Video && 274 if (media_type->majortype == MEDIATYPE_Video &&
272 media_type->formattype == FORMAT_VideoInfo) { 275 media_type->formattype == FORMAT_VideoInfo) {
273 VideoCaptureFormat format; 276 VideoCaptureFormat format;
274 format.pixel_format = 277 format.pixel_format =
275 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( 278 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat(
276 media_type->subtype); 279 media_type->subtype);
277 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN) 280 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN)
(...skipping 21 matching lines...) Expand all
299 ScopedComPtr<IMFMediaSource> source; 302 ScopedComPtr<IMFMediaSource> source;
300 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), 303 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(),
301 source.Receive())) { 304 source.Receive())) {
302 return; 305 return;
303 } 306 }
304 307
305 base::win::ScopedComPtr<IMFSourceReader> reader; 308 base::win::ScopedComPtr<IMFSourceReader> reader;
306 HRESULT hr = 309 HRESULT hr =
307 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive()); 310 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive());
308 if (FAILED(hr)) { 311 if (FAILED(hr)) {
309 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr; 312 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource failed: "
313 << logging::SystemErrorCodeToString(hr);
310 return; 314 return;
311 } 315 }
312 316
313 DWORD stream_index = 0; 317 DWORD stream_index = 0;
314 ScopedComPtr<IMFMediaType> type; 318 ScopedComPtr<IMFMediaType> type;
315 while (SUCCEEDED(reader->GetNativeMediaType( 319 while (SUCCEEDED(reader->GetNativeMediaType(
316 kFirstVideoStream, stream_index, type.Receive()))) { 320 kFirstVideoStream, stream_index, type.Receive()))) {
317 UINT32 width, height; 321 UINT32 width, height;
318 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); 322 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height);
319 if (FAILED(hr)) { 323 if (FAILED(hr)) {
320 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 324 DLOG(ERROR) << "MFGetAttributeSize failed: "
325 << logging::SystemErrorCodeToString(hr);
321 return; 326 return;
322 } 327 }
323 VideoCaptureFormat capture_format; 328 VideoCaptureFormat capture_format;
324 capture_format.frame_size.SetSize(width, height); 329 capture_format.frame_size.SetSize(width, height);
325 330
326 UINT32 numerator, denominator; 331 UINT32 numerator, denominator;
327 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator); 332 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator);
328 if (FAILED(hr)) { 333 if (FAILED(hr)) {
329 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 334 DLOG(ERROR) << "MFGetAttributeSize failed: "
335 << logging::SystemErrorCodeToString(hr);
330 return; 336 return;
331 } 337 }
332 capture_format.frame_rate = denominator 338 capture_format.frame_rate = denominator
333 ? static_cast<float>(numerator) / denominator : 0.0f; 339 ? static_cast<float>(numerator) / denominator : 0.0f;
334 340
335 GUID type_guid; 341 GUID type_guid;
336 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid); 342 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid);
337 if (FAILED(hr)) { 343 if (FAILED(hr)) {
338 DLOG(ERROR) << "GetGUID: " << std::hex << hr; 344 DLOG(ERROR) << "GetGUID failed: "
345 << logging::SystemErrorCodeToString(hr);
339 return; 346 return;
340 } 347 }
341 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, 348 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid,
342 &capture_format.pixel_format); 349 &capture_format.pixel_format);
343 type.Release(); 350 type.Release();
344 formats->push_back(capture_format); 351 formats->push_back(capture_format);
345 ++stream_index; 352 ++stream_index;
346 353
347 DVLOG(1) << device.name() << " resolution: " 354 DVLOG(1) << device.name() << " resolution: "
348 << capture_format.frame_size.ToString() << ", fps: " 355 << capture_format.frame_size.ToString() << ", fps: "
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 const Name& device, 425 const Name& device,
419 VideoCaptureFormats* formats) { 426 VideoCaptureFormats* formats) {
420 DCHECK(thread_checker_.CalledOnValidThread()); 427 DCHECK(thread_checker_.CalledOnValidThread());
421 if (use_media_foundation_) 428 if (use_media_foundation_)
422 GetDeviceSupportedFormatsMediaFoundation(device, formats); 429 GetDeviceSupportedFormatsMediaFoundation(device, formats);
423 else 430 else
424 GetDeviceSupportedFormatsDirectShow(device, formats); 431 GetDeviceSupportedFormatsDirectShow(device, formats);
425 } 432 }
426 433
427 } // namespace media 434 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/mac/video_capture_device_mac.mm ('k') | media/video/capture/win/video_capture_device_mf_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698