| 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 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 std::string id_product = unique_id_.substr(pid_location, kVidPidSize); | 309 std::string id_product = unique_id_.substr(pid_location, kVidPidSize); |
| 310 | 310 |
| 311 return id_vendor + ":" + id_product; | 311 return id_vendor + ":" + id_product; |
| 312 } | 312 } |
| 313 | 313 |
| 314 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) | 314 VideoCaptureDeviceMac::VideoCaptureDeviceMac(const Name& device_name) |
| 315 : device_name_(device_name), | 315 : device_name_(device_name), |
| 316 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 316 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 317 state_(kNotInitialized), | 317 state_(kNotInitialized), |
| 318 capture_device_(nil), | 318 capture_device_(nil), |
| 319 first_timestamp_(media::kNoTimestamp()), | |
| 320 weak_factory_(this) { | 319 weak_factory_(this) { |
| 321 } | 320 } |
| 322 | 321 |
| 323 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { | 322 VideoCaptureDeviceMac::~VideoCaptureDeviceMac() { |
| 324 DCHECK(task_runner_->BelongsToCurrentThread()); | 323 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 325 } | 324 } |
| 326 | 325 |
| 327 void VideoCaptureDeviceMac::AllocateAndStart( | 326 void VideoCaptureDeviceMac::AllocateAndStart( |
| 328 const VideoCaptureParams& params, | 327 const VideoCaptureParams& params, |
| 329 std::unique_ptr<VideoCaptureDevice::Client> client) { | 328 std::unique_ptr<VideoCaptureDevice::Client> client) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 base::TimeDelta timestamp) { | 415 base::TimeDelta timestamp) { |
| 417 // This method is safe to call from a device capture thread, i.e. any thread | 416 // This method is safe to call from a device capture thread, i.e. any thread |
| 418 // controlled by AVFoundation. | 417 // controlled by AVFoundation. |
| 419 if (capture_format_.frame_size != frame_format.frame_size) { | 418 if (capture_format_.frame_size != frame_format.frame_size) { |
| 420 ReceiveError(FROM_HERE, | 419 ReceiveError(FROM_HERE, |
| 421 "Captured resolution " + frame_format.frame_size.ToString() + | 420 "Captured resolution " + frame_format.frame_size.ToString() + |
| 422 ", and expected " + capture_format_.frame_size.ToString()); | 421 ", and expected " + capture_format_.frame_size.ToString()); |
| 423 return; | 422 return; |
| 424 } | 423 } |
| 425 | 424 |
| 426 base::TimeTicks aligned_timestamp; | |
| 427 if (timestamp == media::kNoTimestamp()) { | |
| 428 aligned_timestamp = base::TimeTicks::Now(); | |
| 429 } else { | |
| 430 if (first_timestamp_ == media::kNoTimestamp()) { | |
| 431 first_timestamp_ = timestamp; | |
| 432 first_aligned_timestamp_ = base::TimeTicks::Now(); | |
| 433 } | |
| 434 aligned_timestamp = first_aligned_timestamp_ + timestamp - first_timestamp_; | |
| 435 } | |
| 436 client_->OnIncomingCapturedData(video_frame, video_frame_length, frame_format, | 425 client_->OnIncomingCapturedData(video_frame, video_frame_length, frame_format, |
| 437 0, aligned_timestamp); | 426 0, base::TimeTicks::Now(), timestamp); |
| 438 } | 427 } |
| 439 | 428 |
| 440 void VideoCaptureDeviceMac::ReceiveError( | 429 void VideoCaptureDeviceMac::ReceiveError( |
| 441 const tracked_objects::Location& from_here, | 430 const tracked_objects::Location& from_here, |
| 442 const std::string& reason) { | 431 const std::string& reason) { |
| 443 task_runner_->PostTask( | 432 task_runner_->PostTask( |
| 444 FROM_HERE, base::Bind(&VideoCaptureDeviceMac::SetErrorState, | 433 FROM_HERE, base::Bind(&VideoCaptureDeviceMac::SetErrorState, |
| 445 weak_factory_.GetWeakPtr(), from_here, reason)); | 434 weak_factory_.GetWeakPtr(), from_here, reason)); |
| 446 } | 435 } |
| 447 | 436 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 463 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() | 452 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() |
| 464 width:capture_format_.frame_size.width() | 453 width:capture_format_.frame_size.width() |
| 465 frameRate:capture_format_.frame_rate]) { | 454 frameRate:capture_format_.frame_rate]) { |
| 466 ReceiveError(FROM_HERE, "Could not configure capture device."); | 455 ReceiveError(FROM_HERE, "Could not configure capture device."); |
| 467 return false; | 456 return false; |
| 468 } | 457 } |
| 469 return true; | 458 return true; |
| 470 } | 459 } |
| 471 | 460 |
| 472 } // namespace media | 461 } // namespace media |
| OLD | NEW |