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

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: mcasas@s comments 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 DPLOG_IF(ERROR, FAILED(hr)) << "Failed to GetAllocatedString";
189 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr;
190 devices[i]->Release(); 189 devices[i]->Release();
191 } 190 }
192 } 191 }
193 192
194 static void GetDeviceSupportedFormatsDirectShow( 193 static void GetDeviceSupportedFormatsDirectShow(
195 const VideoCaptureDevice::Name& device, 194 const VideoCaptureDevice::Name& device,
196 VideoCaptureFormats* formats) { 195 VideoCaptureFormats* formats) {
197 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name(); 196 DVLOG(1) << "GetDeviceSupportedFormatsDirectShow for " << device.name();
198 ScopedComPtr<ICreateDevEnum> dev_enum; 197 ScopedComPtr<ICreateDevEnum> dev_enum;
199 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL, 198 HRESULT hr = dev_enum.CreateInstance(CLSID_SystemDeviceEnum, NULL,
200 CLSCTX_INPROC); 199 CLSCTX_INPROC);
201 if (FAILED(hr)) 200 if (FAILED(hr))
202 return; 201 return;
203 202
204 ScopedComPtr<IEnumMoniker> enum_moniker; 203 ScopedComPtr<IEnumMoniker> enum_moniker;
205 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, 204 hr = dev_enum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory,
206 enum_moniker.Receive(), 0); 205 enum_moniker.Receive(), 0);
207 // CreateClassEnumerator returns S_FALSE on some Windows OS when no camera 206 // CreateClassEnumerator returns S_FALSE on some Windows OS when no camera
208 // exists. Therefore the FAILED macro can't be used. 207 // exists. Therefore the FAILED macro can't be used.
209 if (hr != S_OK) 208 if (hr != S_OK)
210 return; 209 return;
211 210
212 // Walk the capture devices. No need to check for device presence again, that 211 // 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 212 // is caught in GetDeviceFilter(). "google camera adapter" and old VFW devices
214 // are already skipped in the previous GetDeviceNames() enumeration. 213 // are already skipped in the previous GetDeviceNames() enumeration.
215 base::win::ScopedComPtr<IBaseFilter> capture_filter; 214 base::win::ScopedComPtr<IBaseFilter> capture_filter;
216 hr = VideoCaptureDeviceWin::GetDeviceFilter(device, 215 hr = VideoCaptureDeviceWin::GetDeviceFilter(device,
217 capture_filter.Receive()); 216 capture_filter.Receive());
218 if (!capture_filter) { 217 if (!capture_filter) {
219 DVLOG(2) << "Failed to create capture filter."; 218 DPLOG(ERROR) << "Failed to create capture filter";
220 return; 219 return;
221 } 220 }
222 221
223 base::win::ScopedComPtr<IPin> output_capture_pin( 222 base::win::ScopedComPtr<IPin> output_capture_pin(
224 VideoCaptureDeviceWin::GetPin(capture_filter, 223 VideoCaptureDeviceWin::GetPin(capture_filter,
225 PINDIR_OUTPUT, 224 PINDIR_OUTPUT,
226 PIN_CATEGORY_CAPTURE)); 225 PIN_CATEGORY_CAPTURE));
227 if (!output_capture_pin) { 226 if (!output_capture_pin) {
228 DVLOG(2) << "Failed to get capture output pin"; 227 DPLOG(ERROR) << "Failed to get capture output pin";
229 return; 228 return;
230 } 229 }
231 230
232 ScopedComPtr<IAMStreamConfig> stream_config; 231 ScopedComPtr<IAMStreamConfig> stream_config;
233 hr = output_capture_pin.QueryInterface(stream_config.Receive()); 232 hr = output_capture_pin.QueryInterface(stream_config.Receive());
234 if (FAILED(hr)) { 233 if (FAILED(hr)) {
235 DVLOG(2) << "Failed to get IAMStreamConfig interface from " 234 DPLOG(ERROR) << "Failed to get IAMStreamConfig interface from "
236 "capture device"; 235 "capture device";
237 return; 236 return;
238 } 237 }
239 238
240 int count = 0, size = 0; 239 int count = 0, size = 0;
241 hr = stream_config->GetNumberOfCapabilities(&count, &size); 240 hr = stream_config->GetNumberOfCapabilities(&count, &size);
242 if (FAILED(hr)) { 241 if (FAILED(hr)) {
243 DVLOG(2) << "Failed to GetNumberOfCapabilities"; 242 DPLOG(ERROR) << "Failed to GetNumberOfCapabilities";
244 return; 243 return;
245 } 244 }
246 245
247 scoped_ptr<BYTE[]> caps(new BYTE[size]); 246 scoped_ptr<BYTE[]> caps(new BYTE[size]);
248 for (int i = 0; i < count; ++i) { 247 for (int i = 0; i < count; ++i) {
249 VideoCaptureDeviceWin::ScopedMediaType media_type; 248 VideoCaptureDeviceWin::ScopedMediaType media_type;
250 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); 249 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get());
251 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() 250 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED()
252 // macros here since they'll trigger incorrectly. 251 // macros here since they'll trigger incorrectly.
253 if (hr != S_OK) { 252 if (hr != S_OK) {
254 DVLOG(2) << "Failed to GetStreamCaps"; 253 DPLOG(ERROR) << "Failed to GetStreamCaps";
255 return; 254 return;
256 } 255 }
257 256
258 if (media_type->majortype == MEDIATYPE_Video && 257 if (media_type->majortype == MEDIATYPE_Video &&
259 media_type->formattype == FORMAT_VideoInfo) { 258 media_type->formattype == FORMAT_VideoInfo) {
260 VideoCaptureFormat format; 259 VideoCaptureFormat format;
261 format.pixel_format = 260 format.pixel_format =
262 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( 261 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat(
263 media_type->subtype); 262 media_type->subtype);
264 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN) 263 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN)
(...skipping 21 matching lines...) Expand all
286 ScopedComPtr<IMFMediaSource> source; 285 ScopedComPtr<IMFMediaSource> source;
287 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), 286 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(),
288 source.Receive())) { 287 source.Receive())) {
289 return; 288 return;
290 } 289 }
291 290
292 base::win::ScopedComPtr<IMFSourceReader> reader; 291 base::win::ScopedComPtr<IMFSourceReader> reader;
293 HRESULT hr = 292 HRESULT hr =
294 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive()); 293 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive());
295 if (FAILED(hr)) { 294 if (FAILED(hr)) {
296 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr; 295 DPLOG(ERROR) << "Failed to MFCreateSourceReaderFromMediaSource";
297 return; 296 return;
298 } 297 }
299 298
300 DWORD stream_index = 0; 299 DWORD stream_index = 0;
301 ScopedComPtr<IMFMediaType> type; 300 ScopedComPtr<IMFMediaType> type;
302 for (hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, 301 for (hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index,
303 type.Receive()); 302 type.Receive());
304 SUCCEEDED(hr); 303 SUCCEEDED(hr);
305 hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, 304 hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index,
306 type.Receive())) { 305 type.Receive())) {
307 UINT32 width, height; 306 UINT32 width, height;
308 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); 307 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height);
309 if (FAILED(hr)) { 308 if (FAILED(hr)) {
310 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 309 DPLOG(ERROR) << "Failed to MFGetAttributeSize";
311 return; 310 return;
312 } 311 }
313 VideoCaptureFormat capture_format; 312 VideoCaptureFormat capture_format;
314 capture_format.frame_size.SetSize(width, height); 313 capture_format.frame_size.SetSize(width, height);
315 314
316 UINT32 numerator, denominator; 315 UINT32 numerator, denominator;
317 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator); 316 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator);
318 if (FAILED(hr)) { 317 if (FAILED(hr)) {
319 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 318 DPLOG(ERROR) << "Failed to MFGetAttributeSize";
320 return; 319 return;
321 } 320 }
322 capture_format.frame_rate = denominator 321 capture_format.frame_rate = denominator
323 ? static_cast<float>(numerator) / denominator : 0.0f; 322 ? static_cast<float>(numerator) / denominator : 0.0f;
324 323
325 GUID type_guid; 324 GUID type_guid;
326 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid); 325 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid);
327 if (FAILED(hr)) { 326 if (FAILED(hr)) {
328 DLOG(ERROR) << "GetGUID: " << std::hex << hr; 327 DPLOG(ERROR) << "Failed to GetGUID";
329 return; 328 return;
330 } 329 }
331 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, 330 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid,
332 &capture_format.pixel_format); 331 &capture_format.pixel_format);
333 type.Release(); 332 type.Release();
334 formats->push_back(capture_format); 333 formats->push_back(capture_format);
335 ++stream_index; 334 ++stream_index;
336 335
337 DVLOG(1) << device.name() << " resolution: " 336 DVLOG(1) << device.name() << " resolution: "
338 << capture_format.frame_size.ToString() << ", fps: " 337 << capture_format.frame_size.ToString() << ", fps: "
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 const VideoCaptureDevice::Name& device, 409 const VideoCaptureDevice::Name& device,
411 VideoCaptureFormats* formats) { 410 VideoCaptureFormats* formats) {
412 DCHECK(thread_checker_.CalledOnValidThread()); 411 DCHECK(thread_checker_.CalledOnValidThread());
413 if (use_media_foundation_) 412 if (use_media_foundation_)
414 GetDeviceSupportedFormatsMediaFoundation(device, formats); 413 GetDeviceSupportedFormatsMediaFoundation(device, formats);
415 else 414 else
416 GetDeviceSupportedFormatsDirectShow(device, formats); 415 GetDeviceSupportedFormatsDirectShow(device, formats);
417 } 416 }
418 417
419 } // namespace media 418 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698