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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame)); | 321 baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame)); |
| 322 frameSize = CVPixelBufferGetHeight(videoFrame) * | 322 frameSize = CVPixelBufferGetHeight(videoFrame) * |
| 323 CVPixelBufferGetBytesPerRow(videoFrame); | 323 CVPixelBufferGetBytesPerRow(videoFrame); |
| 324 } else { | 324 } else { |
| 325 videoFrame = nil; | 325 videoFrame = nil; |
| 326 } | 326 } |
| 327 } | 327 } |
| 328 | 328 |
| 329 { | 329 { |
| 330 base::AutoLock lock(lock_); | 330 base::AutoLock lock(lock_); |
| 331 const int microseconds_per_second = 1000000; | |
|
mcasas
2015/10/31 03:24:25
Instead of |microseconds_per_second|, you should u
qiangchen
2015/11/02 18:21:21
Done.
| |
| 332 CoreMediaGlue::CMTime cm_timestamp = | |
| 333 CoreMediaGlue::CMSampleBufferGetPresentationTimeStamp(sampleBuffer); | |
| 334 const base::TimeTicks timestamp = | |
|
mcasas
2015/10/31 03:24:25
At least DCHECK_NE(0, cm_timestamp.timescale);
qiangchen
2015/11/02 18:21:21
Did a fallback code path in case the timestamp is
| |
| 335 base::TimeTicks() + base::TimeDelta::FromMicroseconds( | |
| 336 cm_timestamp.value * microseconds_per_second / | |
| 337 cm_timestamp.timescale); | |
| 331 if (frameReceiver_ && baseAddress) { | 338 if (frameReceiver_ && baseAddress) { |
| 332 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress), | 339 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress), |
| 333 frameSize, captureFormat, 0, 0); | 340 frameSize, captureFormat, 0, 0, timestamp); |
| 334 } | 341 } |
| 335 } | 342 } |
| 336 | 343 |
| 337 if (videoFrame) | 344 if (videoFrame) |
| 338 CVPixelBufferUnlockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly); | 345 CVPixelBufferUnlockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly); |
| 339 } | 346 } |
| 340 | 347 |
| 341 - (void)onVideoError:(NSNotification*)errorNotification { | 348 - (void)onVideoError:(NSNotification*)errorNotification { |
| 342 NSError* error = base::mac::ObjCCast<NSError>([[errorNotification userInfo] | 349 NSError* error = base::mac::ObjCCast<NSError>([[errorNotification userInfo] |
| 343 objectForKey:AVFoundationGlue::AVCaptureSessionErrorKey()]); | 350 objectForKey:AVFoundationGlue::AVCaptureSessionErrorKey()]); |
| 344 [self sendErrorString:[NSString | 351 [self sendErrorString:[NSString |
| 345 stringWithFormat:@"%@: %@", | 352 stringWithFormat:@"%@: %@", |
| 346 [error localizedDescription], | 353 [error localizedDescription], |
| 347 [error localizedFailureReason]]]; | 354 [error localizedFailureReason]]]; |
| 348 } | 355 } |
| 349 | 356 |
| 350 - (void)sendErrorString:(NSString*)error { | 357 - (void)sendErrorString:(NSString*)error { |
| 351 DLOG(ERROR) << [error UTF8String]; | 358 DLOG(ERROR) << [error UTF8String]; |
| 352 base::AutoLock lock(lock_); | 359 base::AutoLock lock(lock_); |
| 353 if (frameReceiver_) | 360 if (frameReceiver_) |
| 354 frameReceiver_->ReceiveError([error UTF8String]); | 361 frameReceiver_->ReceiveError([error UTF8String]); |
| 355 } | 362 } |
| 356 | 363 |
| 357 @end | 364 @end |
| OLD | NEW |