Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(609)

Side by Side Diff: media/capture/video/mac/video_capture_device_avfoundation_mac.mm

Issue 1421583007: Mac Video Capture: Sending the timestamps provided by the driver to the capture pipeline (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Alignment Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/mac/coremedia_glue.mm ('k') | media/capture/video/mac/video_capture_device_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <CoreMedia/CoreMedia.h>
7 #import <CoreVideo/CoreVideo.h> 8 #import <CoreVideo/CoreVideo.h>
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"
12 #include "media/base/timestamp_constants.h"
11 #include "media/base/video_capture_types.h" 13 #include "media/base/video_capture_types.h"
12 #include "media/capture/video/mac/video_capture_device_mac.h" 14 #include "media/capture/video/mac/video_capture_device_mac.h"
13 #include "ui/gfx/geometry/size.h" 15 #include "ui/gfx/geometry/size.h"
14 16
15 // Prefer MJPEG if frame width or height is larger than this. 17 // Prefer MJPEG if frame width or height is larger than this.
16 static const int kMjpegWidthThreshold = 640; 18 static const int kMjpegWidthThreshold = 640;
17 static const int kMjpegHeightThreshold = 480; 19 static const int kMjpegHeightThreshold = 480;
18 20
19 // This function translates Mac Core Video pixel formats to Chromium pixel 21 // This function translates Mac Core Video pixel formats to Chromium pixel
20 // formats. 22 // formats.
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame)); 323 baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame));
322 frameSize = CVPixelBufferGetHeight(videoFrame) * 324 frameSize = CVPixelBufferGetHeight(videoFrame) *
323 CVPixelBufferGetBytesPerRow(videoFrame); 325 CVPixelBufferGetBytesPerRow(videoFrame);
324 } else { 326 } else {
325 videoFrame = nil; 327 videoFrame = nil;
326 } 328 }
327 } 329 }
328 330
329 { 331 {
330 base::AutoLock lock(lock_); 332 base::AutoLock lock(lock_);
333 const CoreMediaGlue::CMTime cm_timestamp =
334 CoreMediaGlue::CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
335 const base::TimeDelta timestamp =
336 CMTIME_IS_VALID(cm_timestamp)
337 ? base::TimeDelta::FromMicroseconds(
338 cm_timestamp.value * base::TimeTicks::kMicrosecondsPerSecond /
339 cm_timestamp.timescale)
340 : media::kNoTimestamp();
341
331 if (frameReceiver_ && baseAddress) { 342 if (frameReceiver_ && baseAddress) {
332 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress), 343 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress),
333 frameSize, captureFormat, 0, 0); 344 frameSize, captureFormat, 0, 0, timestamp);
334 } 345 }
335 } 346 }
336 347
337 if (videoFrame) 348 if (videoFrame)
338 CVPixelBufferUnlockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly); 349 CVPixelBufferUnlockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly);
339 } 350 }
340 351
341 - (void)onVideoError:(NSNotification*)errorNotification { 352 - (void)onVideoError:(NSNotification*)errorNotification {
342 NSError* error = base::mac::ObjCCast<NSError>([[errorNotification userInfo] 353 NSError* error = base::mac::ObjCCast<NSError>([[errorNotification userInfo]
343 objectForKey:AVFoundationGlue::AVCaptureSessionErrorKey()]); 354 objectForKey:AVFoundationGlue::AVCaptureSessionErrorKey()]);
344 [self sendErrorString:[NSString 355 [self sendErrorString:[NSString
345 stringWithFormat:@"%@: %@", 356 stringWithFormat:@"%@: %@",
346 [error localizedDescription], 357 [error localizedDescription],
347 [error localizedFailureReason]]]; 358 [error localizedFailureReason]]];
348 } 359 }
349 360
350 - (void)sendErrorString:(NSString*)error { 361 - (void)sendErrorString:(NSString*)error {
351 DLOG(ERROR) << [error UTF8String]; 362 DLOG(ERROR) << [error UTF8String];
352 base::AutoLock lock(lock_); 363 base::AutoLock lock(lock_);
353 if (frameReceiver_) 364 if (frameReceiver_)
354 frameReceiver_->ReceiveError([error UTF8String]); 365 frameReceiver_->ReceiveError([error UTF8String]);
355 } 366 }
356 367
357 @end 368 @end
OLDNEW
« no previous file with comments | « media/base/mac/coremedia_glue.mm ('k') | media/capture/video/mac/video_capture_device_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698