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

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: refactor log message to os independendent 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (FAILED(hr))
189 DLOG(WARNING) << "GetAllocatedString failed: " << std::hex << hr; 189 DPLOG(ERROR) << "Failed to GetAllocatedString";
tommi (sloooow) - chröme 2014/08/27 14:46:18 FYI there's also DPLOG_IF. Here you could remove
magjed_chromium 2014/08/27 17:03:27 Nice. The arguments are reversed though.
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 DPLOG(ERROR) << "Failed to create capture filter";
220 return; 220 return;
221 } 221 }
222 222
223 base::win::ScopedComPtr<IPin> output_capture_pin( 223 base::win::ScopedComPtr<IPin> output_capture_pin(
224 VideoCaptureDeviceWin::GetPin(capture_filter, 224 VideoCaptureDeviceWin::GetPin(capture_filter,
225 PINDIR_OUTPUT, 225 PINDIR_OUTPUT,
226 PIN_CATEGORY_CAPTURE)); 226 PIN_CATEGORY_CAPTURE));
227 if (!output_capture_pin) { 227 if (!output_capture_pin) {
228 DVLOG(2) << "Failed to get capture output pin"; 228 DPLOG(ERROR) << "Failed to get capture output pin";
229 return; 229 return;
230 } 230 }
231 231
232 ScopedComPtr<IAMStreamConfig> stream_config; 232 ScopedComPtr<IAMStreamConfig> stream_config;
233 hr = output_capture_pin.QueryInterface(stream_config.Receive()); 233 hr = output_capture_pin.QueryInterface(stream_config.Receive());
234 if (FAILED(hr)) { 234 if (FAILED(hr)) {
235 DVLOG(2) << "Failed to get IAMStreamConfig interface from " 235 DPLOG(ERROR) << "Failed to get IAMStreamConfig interface from "
236 "capture device"; 236 "capture device";
237 return; 237 return;
238 } 238 }
239 239
240 int count = 0, size = 0; 240 int count = 0, size = 0;
241 hr = stream_config->GetNumberOfCapabilities(&count, &size); 241 hr = stream_config->GetNumberOfCapabilities(&count, &size);
242 if (FAILED(hr)) { 242 if (FAILED(hr)) {
243 DVLOG(2) << "Failed to GetNumberOfCapabilities"; 243 DPLOG(ERROR) << "Failed to GetNumberOfCapabilities";
244 return; 244 return;
245 } 245 }
246 246
247 scoped_ptr<BYTE[]> caps(new BYTE[size]); 247 scoped_ptr<BYTE[]> caps(new BYTE[size]);
248 for (int i = 0; i < count; ++i) { 248 for (int i = 0; i < count; ++i) {
249 VideoCaptureDeviceWin::ScopedMediaType media_type; 249 VideoCaptureDeviceWin::ScopedMediaType media_type;
250 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get()); 250 hr = stream_config->GetStreamCaps(i, media_type.Receive(), caps.get());
251 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED() 251 // GetStreamCaps() may return S_FALSE, so don't use FAILED() or SUCCEED()
252 // macros here since they'll trigger incorrectly. 252 // macros here since they'll trigger incorrectly.
253 if (hr != S_OK) { 253 if (hr != S_OK) {
254 DVLOG(2) << "Failed to GetStreamCaps"; 254 DPLOG(ERROR) << "Failed to GetStreamCaps";
255 return; 255 return;
256 } 256 }
257 257
258 if (media_type->majortype == MEDIATYPE_Video && 258 if (media_type->majortype == MEDIATYPE_Video &&
259 media_type->formattype == FORMAT_VideoInfo) { 259 media_type->formattype == FORMAT_VideoInfo) {
260 VideoCaptureFormat format; 260 VideoCaptureFormat format;
261 format.pixel_format = 261 format.pixel_format =
262 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat( 262 VideoCaptureDeviceWin::TranslateMediaSubtypeToPixelFormat(
263 media_type->subtype); 263 media_type->subtype);
264 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN) 264 if (format.pixel_format == PIXEL_FORMAT_UNKNOWN)
(...skipping 21 matching lines...) Expand all
286 ScopedComPtr<IMFMediaSource> source; 286 ScopedComPtr<IMFMediaSource> source;
287 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(), 287 if (!CreateVideoCaptureDeviceMediaFoundation(device.id().c_str(),
288 source.Receive())) { 288 source.Receive())) {
289 return; 289 return;
290 } 290 }
291 291
292 base::win::ScopedComPtr<IMFSourceReader> reader; 292 base::win::ScopedComPtr<IMFSourceReader> reader;
293 HRESULT hr = 293 HRESULT hr =
294 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive()); 294 MFCreateSourceReaderFromMediaSource(source, NULL, reader.Receive());
295 if (FAILED(hr)) { 295 if (FAILED(hr)) {
296 DLOG(ERROR) << "MFCreateSourceReaderFromMediaSource: " << std::hex << hr; 296 DPLOG(ERROR) << "Failed to MFCreateSourceReaderFromMediaSource";
297 return; 297 return;
298 } 298 }
299 299
300 DWORD stream_index = 0; 300 DWORD stream_index = 0;
301 ScopedComPtr<IMFMediaType> type; 301 ScopedComPtr<IMFMediaType> type;
302 for (hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, 302 for (hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index,
303 type.Receive()); 303 type.Receive());
304 SUCCEEDED(hr); 304 SUCCEEDED(hr);
305 hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index, 305 hr = reader->GetNativeMediaType(kFirstVideoStream, stream_index,
306 type.Receive())) { 306 type.Receive())) {
307 UINT32 width, height; 307 UINT32 width, height;
308 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height); 308 hr = MFGetAttributeSize(type, MF_MT_FRAME_SIZE, &width, &height);
309 if (FAILED(hr)) { 309 if (FAILED(hr)) {
310 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 310 DPLOG(ERROR) << "Failed to MFGetAttributeSize";
311 return; 311 return;
312 } 312 }
313 VideoCaptureFormat capture_format; 313 VideoCaptureFormat capture_format;
314 capture_format.frame_size.SetSize(width, height); 314 capture_format.frame_size.SetSize(width, height);
315 315
316 UINT32 numerator, denominator; 316 UINT32 numerator, denominator;
317 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator); 317 hr = MFGetAttributeRatio(type, MF_MT_FRAME_RATE, &numerator, &denominator);
318 if (FAILED(hr)) { 318 if (FAILED(hr)) {
319 DLOG(ERROR) << "MFGetAttributeSize: " << std::hex << hr; 319 DPLOG(ERROR) << "Failed to MFGetAttributeSize";
320 return; 320 return;
321 } 321 }
322 capture_format.frame_rate = denominator 322 capture_format.frame_rate = denominator
323 ? static_cast<float>(numerator) / denominator : 0.0f; 323 ? static_cast<float>(numerator) / denominator : 0.0f;
324 324
325 GUID type_guid; 325 GUID type_guid;
326 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid); 326 hr = type->GetGUID(MF_MT_SUBTYPE, &type_guid);
327 if (FAILED(hr)) { 327 if (FAILED(hr)) {
328 DLOG(ERROR) << "GetGUID: " << std::hex << hr; 328 DPLOG(ERROR) << "Failed to GetGUID";
329 return; 329 return;
330 } 330 }
331 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid, 331 VideoCaptureDeviceMFWin::FormatFromGuid(type_guid,
332 &capture_format.pixel_format); 332 &capture_format.pixel_format);
333 type.Release(); 333 type.Release();
334 formats->push_back(capture_format); 334 formats->push_back(capture_format);
335 ++stream_index; 335 ++stream_index;
336 336
337 DVLOG(1) << device.name() << " resolution: " 337 DVLOG(1) << device.name() << " resolution: "
338 << capture_format.frame_size.ToString() << ", fps: " 338 << capture_format.frame_size.ToString() << ", fps: "
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 const VideoCaptureDevice::Name& device, 410 const VideoCaptureDevice::Name& device,
411 VideoCaptureFormats* formats) { 411 VideoCaptureFormats* formats) {
412 DCHECK(thread_checker_.CalledOnValidThread()); 412 DCHECK(thread_checker_.CalledOnValidThread());
413 if (use_media_foundation_) 413 if (use_media_foundation_)
414 GetDeviceSupportedFormatsMediaFoundation(device, formats); 414 GetDeviceSupportedFormatsMediaFoundation(device, formats);
415 else 415 else
416 GetDeviceSupportedFormatsDirectShow(device, formats); 416 GetDeviceSupportedFormatsDirectShow(device, formats);
417 } 417 }
418 418
419 } // namespace media 419 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698