| 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/capture/video/mac/video_capture_device_mac.h" | 5 #include "media/capture/video/mac/video_capture_device_mac.h" |
| 6 | 6 |
| 7 #include <IOKit/IOCFPlugIn.h> | 7 #include <IOKit/IOCFPlugIn.h> |
| 8 #include <IOKit/usb/IOUSBLib.h> | 8 #include <IOKit/usb/IOUSBLib.h> |
| 9 #include <IOKit/usb/USBSpec.h> | 9 #include <IOKit/usb/USBSpec.h> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/mac/scoped_ioobject.h" | 14 #include "base/mac/scoped_ioobject.h" |
| 15 #include "base/mac/scoped_ioplugininterface.h" | 15 #include "base/mac/scoped_ioplugininterface.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 20 #import "media/base/mac/avfoundation_glue.h" | 20 #import "media/base/mac/avfoundation_glue.h" |
| 21 #include "media/base/timestamp_constants.h" |
| 21 #import "media/capture/video/mac/platform_video_capturing_mac.h" | 22 #import "media/capture/video/mac/platform_video_capturing_mac.h" |
| 22 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" | 23 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" |
| 23 #import "media/capture/video/mac/video_capture_device_qtkit_mac.h" | 24 #import "media/capture/video/mac/video_capture_device_qtkit_mac.h" |
| 24 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 25 | 26 |
| 26 @implementation DeviceNameAndTransportType | 27 @implementation DeviceNameAndTransportType |
| 27 | 28 |
| 28 - (id)initWithName:(NSString*)deviceName transportType:(int32_t)transportType { | 29 - (id)initWithName:(NSString*)deviceName transportType:(int32_t)transportType { |
| 29 if (self = [super init]) { | 30 if (self = [super init]) { |
| 30 deviceName_.reset([deviceName copy]); | 31 deviceName_.reset([deviceName copy]); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 338 |
| 338 return id_vendor + ":" + id_product; | 339 return id_vendor + ":" + id_product; |
| 339 } | 340 } |
| 340 | 341 |
| 341 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) | 342 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) |
| 342 : device_name_(device_name), | 343 : device_name_(device_name), |
| 343 tried_to_square_pixels_(false), | 344 tried_to_square_pixels_(false), |
| 344 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 345 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 345 state_(kNotInitialized), | 346 state_(kNotInitialized), |
| 346 capture_device_(nil), | 347 capture_device_(nil), |
| 348 first_timestamp_(media::kNoTimestamp()), |
| 347 weak_factory_(this) { | 349 weak_factory_(this) { |
| 348 // Avoid reconfiguring AVFoundation or blacklisted devices. | 350 // Avoid reconfiguring AVFoundation or blacklisted devices. |
| 349 final_resolution_selected_ = AVFoundationGlue::IsAVFoundationSupported() || | 351 final_resolution_selected_ = AVFoundationGlue::IsAVFoundationSupported() || |
| 350 device_name.is_blacklisted(); | 352 device_name.is_blacklisted(); |
| 351 } | 353 } |
| 352 | 354 |
| 353 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { | 355 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { |
| 354 DCHECK(task_runner_->BelongsToCurrentThread()); | 356 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 355 [capture_device_ release]; | 357 [capture_device_ release]; |
| 356 } | 358 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 return false; | 459 return false; |
| 458 | 460 |
| 459 state_ = kIdle; | 461 state_ = kIdle; |
| 460 return true; | 462 return true; |
| 461 } | 463 } |
| 462 | 464 |
| 463 void VideoCaptureDeviceMac::ReceiveFrame(const uint8* video_frame, | 465 void VideoCaptureDeviceMac::ReceiveFrame(const uint8* video_frame, |
| 464 int video_frame_length, | 466 int video_frame_length, |
| 465 const VideoCaptureFormat& frame_format, | 467 const VideoCaptureFormat& frame_format, |
| 466 int aspect_numerator, | 468 int aspect_numerator, |
| 467 int aspect_denominator) { | 469 int aspect_denominator, |
| 470 base::TimeDelta timestamp) { |
| 468 // This method is safe to call from a device capture thread, i.e. any thread | 471 // This method is safe to call from a device capture thread, i.e. any thread |
| 469 // controlled by QTKit/AVFoundation. | 472 // controlled by QTKit/AVFoundation. |
| 470 if (!final_resolution_selected_) { | 473 if (!final_resolution_selected_) { |
| 471 DCHECK(!AVFoundationGlue::IsAVFoundationSupported()); | 474 DCHECK(!AVFoundationGlue::IsAVFoundationSupported()); |
| 472 if (capture_format_.frame_size.width() > kVGA.width || | 475 if (capture_format_.frame_size.width() > kVGA.width || |
| 473 capture_format_.frame_size.height() > kVGA.height) { | 476 capture_format_.frame_size.height() > kVGA.height) { |
| 474 // We are requesting HD. Make sure that the picture is good, otherwise | 477 // We are requesting HD. Make sure that the picture is good, otherwise |
| 475 // drop down to VGA. | 478 // drop down to VGA. |
| 476 bool change_to_vga = false; | 479 bool change_to_vga = false; |
| 477 if (frame_format.frame_size.width() < | 480 if (frame_format.frame_size.width() < |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // camera, and that is fine: http://crbug.com/353620. In AVFoundation, this | 531 // camera, and that is fine: http://crbug.com/353620. In AVFoundation, this |
| 529 // should not happen, it should resize internally. | 532 // should not happen, it should resize internally. |
| 530 if (!AVFoundationGlue::IsAVFoundationSupported()) { | 533 if (!AVFoundationGlue::IsAVFoundationSupported()) { |
| 531 capture_format_.frame_size = frame_format.frame_size; | 534 capture_format_.frame_size = frame_format.frame_size; |
| 532 } else if (capture_format_.frame_size != frame_format.frame_size) { | 535 } else if (capture_format_.frame_size != frame_format.frame_size) { |
| 533 ReceiveError("Captured resolution " + frame_format.frame_size.ToString() + | 536 ReceiveError("Captured resolution " + frame_format.frame_size.ToString() + |
| 534 ", and expected " + capture_format_.frame_size.ToString()); | 537 ", and expected " + capture_format_.frame_size.ToString()); |
| 535 return; | 538 return; |
| 536 } | 539 } |
| 537 | 540 |
| 541 base::TimeTicks aligned_timestamp; |
| 542 if (timestamp == media::kNoTimestamp()) { |
| 543 aligned_timestamp = base::TimeTicks::Now(); |
| 544 } else { |
| 545 if (first_timestamp_ == media::kNoTimestamp()) { |
| 546 first_timestamp_ = timestamp; |
| 547 first_aligned_timestamp_ = base::TimeTicks::Now(); |
| 548 } |
| 549 aligned_timestamp = first_aligned_timestamp_ + timestamp - first_timestamp_; |
| 550 } |
| 538 client_->OnIncomingCapturedData(video_frame, video_frame_length, frame_format, | 551 client_->OnIncomingCapturedData(video_frame, video_frame_length, frame_format, |
| 539 0, base::TimeTicks::Now()); | 552 0, aligned_timestamp); |
| 540 } | 553 } |
| 541 | 554 |
| 542 void VideoCaptureDeviceMac::ReceiveError(const std::string& reason) { | 555 void VideoCaptureDeviceMac::ReceiveError(const std::string& reason) { |
| 543 task_runner_->PostTask(FROM_HERE, | 556 task_runner_->PostTask(FROM_HERE, |
| 544 base::Bind(&VideoCaptureDeviceMac::SetErrorState, | 557 base::Bind(&VideoCaptureDeviceMac::SetErrorState, |
| 545 weak_factory_.GetWeakPtr(), reason)); | 558 weak_factory_.GetWeakPtr(), reason)); |
| 546 } | 559 } |
| 547 | 560 |
| 548 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { | 561 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { |
| 549 DCHECK(task_runner_->BelongsToCurrentThread()); | 562 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 561 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() | 574 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() |
| 562 width:capture_format_.frame_size.width() | 575 width:capture_format_.frame_size.width() |
| 563 frameRate:capture_format_.frame_rate]) { | 576 frameRate:capture_format_.frame_rate]) { |
| 564 ReceiveError("Could not configure capture device."); | 577 ReceiveError("Could not configure capture device."); |
| 565 return false; | 578 return false; |
| 566 } | 579 } |
| 567 return true; | 580 return true; |
| 568 } | 581 } |
| 569 | 582 |
| 570 } // namespace media | 583 } // namespace media |
| OLD | NEW |