OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_win.h" | 5 #include "media/video/capture/win/video_capture_device_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 375 } |
376 // Set the sink filter to request this capability. | 376 // Set the sink filter to request this capability. |
377 sink_filter_->SetRequestedMediaCapability(capability); | 377 sink_filter_->SetRequestedMediaCapability(capability); |
378 // Order the capture device to use this capability. | 378 // Order the capture device to use this capability. |
379 hr = stream_config->SetFormat(pmt); | 379 hr = stream_config->SetFormat(pmt); |
380 } | 380 } |
381 | 381 |
382 if (FAILED(hr)) | 382 if (FAILED(hr)) |
383 SetErrorState("Failed to set capture device output format"); | 383 SetErrorState("Failed to set capture device output format"); |
384 | 384 |
385 if (capability.color == VideoCaptureCapability::kMJPEG && | 385 if (capability.color == PIXEL_FORMAT_MJPEG && |
386 !mjpg_filter_.get()) { | 386 !mjpg_filter_.get()) { |
387 // Create MJPG filter if we need it. | 387 // Create MJPG filter if we need it. |
388 hr = mjpg_filter_.CreateInstance(CLSID_MjpegDec, NULL, CLSCTX_INPROC); | 388 hr = mjpg_filter_.CreateInstance(CLSID_MjpegDec, NULL, CLSCTX_INPROC); |
389 | 389 |
390 if (SUCCEEDED(hr)) { | 390 if (SUCCEEDED(hr)) { |
391 GetPin(mjpg_filter_, PINDIR_INPUT, GUID_NULL, input_mjpg_pin_.Receive()); | 391 GetPin(mjpg_filter_, PINDIR_INPUT, GUID_NULL, input_mjpg_pin_.Receive()); |
392 GetPin(mjpg_filter_, PINDIR_OUTPUT, GUID_NULL, | 392 GetPin(mjpg_filter_, PINDIR_OUTPUT, GUID_NULL, |
393 output_mjpg_pin_.Receive()); | 393 output_mjpg_pin_.Receive()); |
394 hr = graph_builder_->AddFilter(mjpg_filter_, NULL); | 394 hr = graph_builder_->AddFilter(mjpg_filter_, NULL); |
395 } | 395 } |
396 | 396 |
397 if (FAILED(hr)) { | 397 if (FAILED(hr)) { |
398 mjpg_filter_.Release(); | 398 mjpg_filter_.Release(); |
399 input_mjpg_pin_.Release(); | 399 input_mjpg_pin_.Release(); |
400 output_mjpg_pin_.Release(); | 400 output_mjpg_pin_.Release(); |
401 } | 401 } |
402 } | 402 } |
403 | 403 |
404 if (capability.color == VideoCaptureCapability::kMJPEG && | 404 if (capability.color == PIXEL_FORMAT_MJPEG && |
405 mjpg_filter_.get()) { | 405 mjpg_filter_.get()) { |
406 // Connect the camera to the MJPEG decoder. | 406 // Connect the camera to the MJPEG decoder. |
407 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_mjpg_pin_, | 407 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_mjpg_pin_, |
408 NULL); | 408 NULL); |
409 // Connect the MJPEG filter to the Capture filter. | 409 // Connect the MJPEG filter to the Capture filter. |
410 hr += graph_builder_->ConnectDirect(output_mjpg_pin_, input_sink_pin_, | 410 hr += graph_builder_->ConnectDirect(output_mjpg_pin_, input_sink_pin_, |
411 NULL); | 411 NULL); |
412 } else { | 412 } else { |
413 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_sink_pin_, | 413 hr = graph_builder_->ConnectDirect(output_capture_pin_, input_sink_pin_, |
414 NULL); | 414 NULL); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 capability.frame_rate = (time_per_frame > 0) ? | 574 capability.frame_rate = (time_per_frame > 0) ? |
575 static_cast<int>(kSecondsToReferenceTime / time_per_frame) : 0; | 575 static_cast<int>(kSecondsToReferenceTime / time_per_frame) : 0; |
576 } | 576 } |
577 // DirectShow works at the moment only on integer frame_rate but the | 577 // DirectShow works at the moment only on integer frame_rate but the |
578 // best capability matching class works on rational frame rates. | 578 // best capability matching class works on rational frame rates. |
579 capability.frame_rate_numerator = capability.frame_rate; | 579 capability.frame_rate_numerator = capability.frame_rate; |
580 capability.frame_rate_denominator = 1; | 580 capability.frame_rate_denominator = 1; |
581 | 581 |
582 // We can't switch MEDIATYPE :~(. | 582 // We can't switch MEDIATYPE :~(. |
583 if (media_type->subtype == kMediaSubTypeI420) { | 583 if (media_type->subtype == kMediaSubTypeI420) { |
584 capability.color = VideoCaptureCapability::kI420; | 584 capability.color = PIXEL_FORMAT_I420; |
585 } else if (media_type->subtype == MEDIASUBTYPE_IYUV) { | 585 } else if (media_type->subtype == MEDIASUBTYPE_IYUV) { |
586 // This is identical to kI420. | 586 // This is identical to PIXEL_FORMAT_I420. |
587 capability.color = VideoCaptureCapability::kI420; | 587 capability.color = PIXEL_FORMAT_I420; |
588 } else if (media_type->subtype == MEDIASUBTYPE_RGB24) { | 588 } else if (media_type->subtype == MEDIASUBTYPE_RGB24) { |
589 capability.color = VideoCaptureCapability::kRGB24; | 589 capability.color = PIXEL_FORMAT_RGB24; |
590 } else if (media_type->subtype == MEDIASUBTYPE_YUY2) { | 590 } else if (media_type->subtype == MEDIASUBTYPE_YUY2) { |
591 capability.color = VideoCaptureCapability::kYUY2; | 591 capability.color = PIXEL_FORMAT_YUY2; |
592 } else if (media_type->subtype == MEDIASUBTYPE_MJPG) { | 592 } else if (media_type->subtype == MEDIASUBTYPE_MJPG) { |
593 capability.color = VideoCaptureCapability::kMJPEG; | 593 capability.color = PIXEL_FORMAT_MJPEG; |
594 } else if (media_type->subtype == MEDIASUBTYPE_UYVY) { | 594 } else if (media_type->subtype == MEDIASUBTYPE_UYVY) { |
595 capability.color = VideoCaptureCapability::kUYVY; | 595 capability.color = PIXEL_FORMAT_UYVY; |
596 } else if (media_type->subtype == MEDIASUBTYPE_ARGB32) { | 596 } else if (media_type->subtype == MEDIASUBTYPE_ARGB32) { |
597 capability.color = VideoCaptureCapability::kARGB; | 597 capability.color = PIXEL_FORMAT_ARGB; |
598 } else { | 598 } else { |
599 WCHAR guid_str[128]; | 599 WCHAR guid_str[128]; |
600 StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str)); | 600 StringFromGUID2(media_type->subtype, guid_str, arraysize(guid_str)); |
601 DVLOG(2) << "Device supports (also) an unknown media type " << guid_str; | 601 DVLOG(2) << "Device supports (also) an unknown media type " << guid_str; |
602 continue; | 602 continue; |
603 } | 603 } |
604 capabilities_.Add(capability); | 604 capabilities_.Add(capability); |
605 } | 605 } |
606 DeleteMediaType(media_type); | 606 DeleteMediaType(media_type); |
607 media_type = NULL; | 607 media_type = NULL; |
608 } | 608 } |
609 | 609 |
610 return !capabilities_.empty(); | 610 return !capabilities_.empty(); |
611 } | 611 } |
612 | 612 |
613 void VideoCaptureDeviceWin::SetErrorState(const char* reason) { | 613 void VideoCaptureDeviceWin::SetErrorState(const char* reason) { |
614 DCHECK(CalledOnValidThread()); | 614 DCHECK(CalledOnValidThread()); |
615 DVLOG(1) << reason; | 615 DVLOG(1) << reason; |
616 state_ = kError; | 616 state_ = kError; |
617 observer_->OnError(); | 617 observer_->OnError(); |
618 } | 618 } |
619 } // namespace media | 619 } // namespace media |
OLD | NEW |