Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" | 5 #import "media/capture/video/mac/video_capture_device_avfoundation_mac.h" |
| 6 | 6 |
| 7 #import <CoreVideo/CoreVideo.h> | 7 #import <CoreVideo/CoreVideo.h> |
| 8 #import <CoreMedia/CoreMedia.h> | |
|
mcasas
2015/11/02 18:59:18
Imports, same as includes, should follow alphabeti
qiangchen
2015/11/02 21:35:47
Done.
| |
| 8 | 9 |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
| 11 #include "media/base/video_capture_types.h" | 12 #include "media/base/video_capture_types.h" |
| 12 #include "media/capture/video/mac/video_capture_device_mac.h" | 13 #include "media/capture/video/mac/video_capture_device_mac.h" |
| 13 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
| 14 | 15 |
| 15 // Prefer MJPEG if frame width or height is larger than this. | 16 // Prefer MJPEG if frame width or height is larger than this. |
| 16 static const int kMjpegWidthThreshold = 640; | 17 static const int kMjpegWidthThreshold = 640; |
| 17 static const int kMjpegHeightThreshold = 480; | 18 static const int kMjpegHeightThreshold = 480; |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame)); | 322 baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame)); |
| 322 frameSize = CVPixelBufferGetHeight(videoFrame) * | 323 frameSize = CVPixelBufferGetHeight(videoFrame) * |
| 323 CVPixelBufferGetBytesPerRow(videoFrame); | 324 CVPixelBufferGetBytesPerRow(videoFrame); |
| 324 } else { | 325 } else { |
| 325 videoFrame = nil; | 326 videoFrame = nil; |
| 326 } | 327 } |
| 327 } | 328 } |
| 328 | 329 |
| 329 { | 330 { |
| 330 base::AutoLock lock(lock_); | 331 base::AutoLock lock(lock_); |
| 332 const CoreMediaGlue::CMTime cm_timestamp = | |
| 333 CoreMediaGlue::CMSampleBufferGetPresentationTimeStamp(sampleBuffer); | |
| 334 base::TimeTicks timestamp; | |
| 335 if ((cm_timestamp.flags & kCMTimeFlags_Valid) && cm_timestamp.timescale) { | |
|
mcasas
2015/11/02 18:59:18
What about
const base::TimeTicks timestamp =
qiangchen
2015/11/02 21:35:47
Done.
But not using CMTimeGetSeconds, because Cor
| |
| 336 timestamp = | |
| 337 base::TimeTicks() + | |
| 338 base::TimeDelta::FromMicroseconds( | |
| 339 cm_timestamp.value * base::TimeTicks::kMicrosecondsPerSecond / | |
| 340 cm_timestamp.timescale); | |
| 341 } else { | |
| 342 timestamp = base::TimeTicks::Now(); | |
| 343 } | |
| 331 if (frameReceiver_ && baseAddress) { | 344 if (frameReceiver_ && baseAddress) { |
| 332 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress), | 345 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress), |
| 333 frameSize, captureFormat, 0, 0); | 346 frameSize, captureFormat, 0, 0, timestamp); |
| 334 } | 347 } |
| 335 } | 348 } |
| 336 | 349 |
| 337 if (videoFrame) | 350 if (videoFrame) |
| 338 CVPixelBufferUnlockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly); | 351 CVPixelBufferUnlockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly); |
| 339 } | 352 } |
| 340 | 353 |
| 341 - (void)onVideoError:(NSNotification*)errorNotification { | 354 - (void)onVideoError:(NSNotification*)errorNotification { |
| 342 NSError* error = base::mac::ObjCCast<NSError>([[errorNotification userInfo] | 355 NSError* error = base::mac::ObjCCast<NSError>([[errorNotification userInfo] |
| 343 objectForKey:AVFoundationGlue::AVCaptureSessionErrorKey()]); | 356 objectForKey:AVFoundationGlue::AVCaptureSessionErrorKey()]); |
| 344 [self sendErrorString:[NSString | 357 [self sendErrorString:[NSString |
| 345 stringWithFormat:@"%@: %@", | 358 stringWithFormat:@"%@: %@", |
| 346 [error localizedDescription], | 359 [error localizedDescription], |
| 347 [error localizedFailureReason]]]; | 360 [error localizedFailureReason]]]; |
| 348 } | 361 } |
| 349 | 362 |
| 350 - (void)sendErrorString:(NSString*)error { | 363 - (void)sendErrorString:(NSString*)error { |
| 351 DLOG(ERROR) << [error UTF8String]; | 364 DLOG(ERROR) << [error UTF8String]; |
| 352 base::AutoLock lock(lock_); | 365 base::AutoLock lock(lock_); |
| 353 if (frameReceiver_) | 366 if (frameReceiver_) |
| 354 frameReceiver_->ReceiveError([error UTF8String]); | 367 frameReceiver_->ReceiveError([error UTF8String]); |
| 355 } | 368 } |
| 356 | 369 |
| 357 @end | 370 @end |
| OLD | NEW |