| 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 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 if (device_name_.capture_api_type() == Name::AVFOUNDATION) | 374 if (device_name_.capture_api_type() == Name::AVFOUNDATION) |
| 375 LogMessage("Using AVFoundation for device: " + device_name_.name()); | 375 LogMessage("Using AVFoundation for device: " + device_name_.name()); |
| 376 else | 376 else |
| 377 LogMessage("Using QTKit for device: " + device_name_.name()); | 377 LogMessage("Using QTKit for device: " + device_name_.name()); |
| 378 NSString* deviceId = | 378 NSString* deviceId = |
| 379 [NSString stringWithUTF8String:device_name_.id().c_str()]; | 379 [NSString stringWithUTF8String:device_name_.id().c_str()]; |
| 380 | 380 |
| 381 [capture_device_ setFrameReceiver:this]; | 381 [capture_device_ setFrameReceiver:this]; |
| 382 | 382 |
| 383 if (![capture_device_ setCaptureDevice:deviceId]) { | 383 if (![capture_device_ setCaptureDevice:deviceId]) { |
| 384 SetErrorState("Could not open capture device."); | 384 SetErrorState(FROM_HERE, "Could not open capture device."); |
| 385 return; | 385 return; |
| 386 } | 386 } |
| 387 | 387 |
| 388 capture_format_.frame_size = resolution; | 388 capture_format_.frame_size = resolution; |
| 389 capture_format_.frame_rate = | 389 capture_format_.frame_rate = |
| 390 std::max(kMinFrameRate, | 390 std::max(kMinFrameRate, |
| 391 std::min(params.requested_format.frame_rate, kMaxFrameRate)); | 391 std::min(params.requested_format.frame_rate, kMaxFrameRate)); |
| 392 // Leave the pixel format selection to AVFoundation/QTKit. The pixel format | 392 // Leave the pixel format selection to AVFoundation/QTKit. The pixel format |
| 393 // will be passed to |ReceiveFrame|. | 393 // will be passed to |ReceiveFrame|. |
| 394 capture_format_.pixel_format = PIXEL_FORMAT_UNKNOWN; | 394 capture_format_.pixel_format = PIXEL_FORMAT_UNKNOWN; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 415 std::string model_id = device_model.substr(kVidPidSize + 1); | 415 std::string model_id = device_model.substr(kVidPidSize + 1); |
| 416 int vendor_id_as_int, model_id_as_int; | 416 int vendor_id_as_int, model_id_as_int; |
| 417 if (base::HexStringToInt(base::StringPiece(vendor_id), &vendor_id_as_int) && | 417 if (base::HexStringToInt(base::StringPiece(vendor_id), &vendor_id_as_int) && |
| 418 base::HexStringToInt(base::StringPiece(model_id), &model_id_as_int)) { | 418 base::HexStringToInt(base::StringPiece(model_id), &model_id_as_int)) { |
| 419 SetAntiFlickerInUsbDevice(vendor_id_as_int, model_id_as_int, | 419 SetAntiFlickerInUsbDevice(vendor_id_as_int, model_id_as_int, |
| 420 GetPowerLineFrequency(params)); | 420 GetPowerLineFrequency(params)); |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 if (![capture_device_ startCapture]) { | 424 if (![capture_device_ startCapture]) { |
| 425 SetErrorState("Could not start capture device."); | 425 SetErrorState(FROM_HERE, "Could not start capture device."); |
| 426 return; | 426 return; |
| 427 } | 427 } |
| 428 | 428 |
| 429 state_ = kCapturing; | 429 state_ = kCapturing; |
| 430 } | 430 } |
| 431 | 431 |
| 432 void VideoCaptureDeviceMac::StopAndDeAllocate() { | 432 void VideoCaptureDeviceMac::StopAndDeAllocate() { |
| 433 DCHECK(task_runner_->BelongsToCurrentThread()); | 433 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 434 DCHECK(state_ == kCapturing || state_ == kError) << state_; | 434 DCHECK(state_ == kCapturing || state_ == kError) << state_; |
| 435 | 435 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return; | 523 return; |
| 524 } | 524 } |
| 525 } | 525 } |
| 526 | 526 |
| 527 // QTKit capture source can change resolution if someone else reconfigures the | 527 // QTKit capture source can change resolution if someone else reconfigures the |
| 528 // camera, and that is fine: http://crbug.com/353620. In AVFoundation, this | 528 // camera, and that is fine: http://crbug.com/353620. In AVFoundation, this |
| 529 // should not happen, it should resize internally. | 529 // should not happen, it should resize internally. |
| 530 if (!AVFoundationGlue::IsAVFoundationSupported()) { | 530 if (!AVFoundationGlue::IsAVFoundationSupported()) { |
| 531 capture_format_.frame_size = frame_format.frame_size; | 531 capture_format_.frame_size = frame_format.frame_size; |
| 532 } else if (capture_format_.frame_size != frame_format.frame_size) { | 532 } else if (capture_format_.frame_size != frame_format.frame_size) { |
| 533 ReceiveError("Captured resolution " + frame_format.frame_size.ToString() + | 533 ReceiveError(FROM_HERE, |
| 534 ", and expected " + capture_format_.frame_size.ToString()); | 534 "Captured resolution " + frame_format.frame_size.ToString() + |
| 535 ", and expected " + capture_format_.frame_size.ToString()); |
| 535 return; | 536 return; |
| 536 } | 537 } |
| 537 | 538 |
| 538 client_->OnIncomingCapturedData(video_frame, video_frame_length, frame_format, | 539 client_->OnIncomingCapturedData(video_frame, video_frame_length, frame_format, |
| 539 0, base::TimeTicks::Now()); | 540 0, base::TimeTicks::Now()); |
| 540 } | 541 } |
| 541 | 542 |
| 542 void VideoCaptureDeviceMac::ReceiveError(const std::string& reason) { | 543 void VideoCaptureDeviceMac::ReceiveError( |
| 543 task_runner_->PostTask(FROM_HERE, | 544 const tracked_objects::Location& from_here, |
| 544 base::Bind(&VideoCaptureDeviceMac::SetErrorState, | 545 const std::string& reason) { |
| 545 weak_factory_.GetWeakPtr(), reason)); | 546 task_runner_->PostTask( |
| 547 FROM_HERE, base::Bind(&VideoCaptureDeviceMac::SetErrorState, |
| 548 weak_factory_.GetWeakPtr(), from_here, reason)); |
| 546 } | 549 } |
| 547 | 550 |
| 548 void VideoCaptureDeviceMac::SetErrorState(const std::string& reason) { | 551 void VideoCaptureDeviceMac::SetErrorState( |
| 552 const tracked_objects::Location& from_here, |
| 553 const std::string& reason) { |
| 549 DCHECK(task_runner_->BelongsToCurrentThread()); | 554 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 550 state_ = kError; | 555 state_ = kError; |
| 551 client_->OnError(reason); | 556 client_->OnError(from_here, reason); |
| 552 } | 557 } |
| 553 | 558 |
| 554 void VideoCaptureDeviceMac::LogMessage(const std::string& message) { | 559 void VideoCaptureDeviceMac::LogMessage(const std::string& message) { |
| 555 DCHECK(task_runner_->BelongsToCurrentThread()); | 560 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 556 if (client_) | 561 if (client_) |
| 557 client_->OnLog(message); | 562 client_->OnLog(message); |
| 558 } | 563 } |
| 559 | 564 |
| 560 bool VideoCaptureDeviceMac::UpdateCaptureResolution() { | 565 bool VideoCaptureDeviceMac::UpdateCaptureResolution() { |
| 561 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() | 566 if (![capture_device_ setCaptureHeight:capture_format_.frame_size.height() |
| 562 width:capture_format_.frame_size.width() | 567 width:capture_format_.frame_size.width() |
| 563 frameRate:capture_format_.frame_rate]) { | 568 frameRate:capture_format_.frame_rate]) { |
| 564 ReceiveError("Could not configure capture device."); | 569 ReceiveError(FROM_HERE, "Could not configure capture device."); |
| 565 return false; | 570 return false; |
| 566 } | 571 } |
| 567 return true; | 572 return true; |
| 568 } | 573 } |
| 569 | 574 |
| 570 } // namespace media | 575 } // namespace media |
| OLD | NEW |