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

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

Issue 860333003: Mac Video Capture: Add support for pixel format NV12 for AVFoundation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mcasas@ comments Created 5 years, 10 months 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 | « no previous file | no next file » | 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/video/capture/mac/video_capture_device_avfoundation_mac.h" 5 #import "media/video/capture/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"
11 #include "media/base/mac/corevideo_glue.h"
11 #include "media/video/capture/mac/video_capture_device_mac.h" 12 #include "media/video/capture/mac/video_capture_device_mac.h"
12 #include "ui/gfx/geometry/size.h" 13 #include "ui/gfx/geometry/size.h"
13 14
14 // Prefer MJPEG if frame width or height is larger than this. 15 // Prefer MJPEG if frame width or height is larger than this.
15 static const int kMjpegWidthThreshold = 640; 16 static const int kMjpegWidthThreshold = 640;
16 static const int kMjpegHeightThreshold = 480; 17 static const int kMjpegHeightThreshold = 480;
17 18
18 // This function translates Mac Core Video pixel formats to Chromium pixel 19 // This function translates Mac Core Video pixel formats to Chromium pixel
19 // formats. Chromium pixel formats are sorted in order of preference. 20 // formats. Chromium pixel formats are sorted in order of preference.
20 media::VideoPixelFormat FourCCToChromiumPixelFormat(FourCharCode code) { 21 media::VideoPixelFormat FourCCToChromiumPixelFormat(FourCharCode code) {
21 switch (code) { 22 switch (code) {
22 case kCVPixelFormatType_422YpCbCr8: 23 case kCVPixelFormatType_422YpCbCr8:
23 return media::PIXEL_FORMAT_UYVY; 24 return media::PIXEL_FORMAT_UYVY;
24 case CoreMediaGlue::kCMPixelFormat_422YpCbCr8_yuvs: 25 case CoreMediaGlue::kCMPixelFormat_422YpCbCr8_yuvs:
25 return media::PIXEL_FORMAT_YUY2; 26 return media::PIXEL_FORMAT_YUY2;
26 case CoreMediaGlue::kCMVideoCodecType_JPEG_OpenDML: 27 case CoreMediaGlue::kCMVideoCodecType_JPEG_OpenDML:
27 return media::PIXEL_FORMAT_MJPEG; 28 return media::PIXEL_FORMAT_MJPEG;
29 case CoreVideoGlue::kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
30 return media::PIXEL_FORMAT_NV12;
28 default: 31 default:
29 return media::PIXEL_FORMAT_UNKNOWN; 32 return media::PIXEL_FORMAT_UNKNOWN;
30 } 33 }
31 } 34 }
32 35
33 @implementation VideoCaptureDeviceAVFoundation 36 @implementation VideoCaptureDeviceAVFoundation
34 37
35 #pragma mark Class methods 38 #pragma mark Class methods
36 39
37 + (void)getDeviceNames:(NSMutableDictionary*)deviceNames { 40 + (void)getDeviceNames:(NSMutableDictionary*)deviceNames {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 blockBuffer, 0, &lengthAtOffset, &frameSize, &baseAddress); 308 blockBuffer, 0, &lengthAtOffset, &frameSize, &baseAddress);
306 // Expect the MJPEG data to be available as a contiguous reference, i.e. 309 // Expect the MJPEG data to be available as a contiguous reference, i.e.
307 // not covered by multiple memory blocks. 310 // not covered by multiple memory blocks.
308 CHECK_EQ(lengthAtOffset, frameSize); 311 CHECK_EQ(lengthAtOffset, frameSize);
309 } 312 }
310 } else { 313 } else {
311 videoFrame = CoreMediaGlue::CMSampleBufferGetImageBuffer(sampleBuffer); 314 videoFrame = CoreMediaGlue::CMSampleBufferGetImageBuffer(sampleBuffer);
312 // Lock the frame and calculate frame size. 315 // Lock the frame and calculate frame size.
313 if (CVPixelBufferLockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly) == 316 if (CVPixelBufferLockBaseAddress(videoFrame, kCVPixelBufferLock_ReadOnly) ==
314 kCVReturnSuccess) { 317 kCVReturnSuccess) {
315 baseAddress = static_cast<char*>(CVPixelBufferGetBaseAddress(videoFrame)); 318 baseAddress = static_cast<char*>(
316 frameSize = CVPixelBufferGetHeight(videoFrame) * 319 CVPixelBufferGetPlaneCount(videoFrame) == 0
317 CVPixelBufferGetBytesPerRow(videoFrame); 320 ? CVPixelBufferGetBaseAddress(videoFrame)
321 : CVPixelBufferGetBaseAddressOfPlane(videoFrame, 0));
322 // Chromium expects the data to be tightly packed, i.e. no row padding
323 // and the planes should follow consecutively.
324 switch (captureFormat.pixel_format) {
325 case media::PIXEL_FORMAT_YUY2:
326 case media::PIXEL_FORMAT_UYVY:
327 CHECK_EQ(CVPixelBufferGetBytesPerRow(videoFrame),
328 static_cast<size_t>(2 * captureFormat.frame_size.width()));
329 frameSize = captureFormat.frame_size.GetArea() * 16 / 8; // 16bpp.
330 break;
331 case media::PIXEL_FORMAT_NV12:
332 CHECK_EQ(CVPixelBufferGetBytesPerRowOfPlane(videoFrame, 0),
333 static_cast<size_t>(captureFormat.frame_size.width()));
334 CHECK_EQ(CVPixelBufferGetBytesPerRowOfPlane(videoFrame, 1),
335 static_cast<size_t>(captureFormat.frame_size.width()));
336 CHECK_EQ(CVPixelBufferGetBaseAddressOfPlane(videoFrame, 1),
337 baseAddress + captureFormat.frame_size.GetArea());
338 frameSize = captureFormat.frame_size.GetArea() * 12 / 8; // 12bpp.
339 break;
340 default:
341 NOTREACHED();
342 }
318 } else { 343 } else {
319 videoFrame = nil; 344 videoFrame = nil;
320 } 345 }
321 } 346 }
322 347
323 { 348 {
324 base::AutoLock lock(lock_); 349 base::AutoLock lock(lock_);
325 if (frameReceiver_ && baseAddress) { 350 if (frameReceiver_ && baseAddress) {
326 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress), 351 frameReceiver_->ReceiveFrame(reinterpret_cast<uint8_t*>(baseAddress),
327 frameSize, captureFormat, 0, 0); 352 frameSize, captureFormat, 0, 0);
(...skipping 14 matching lines...) Expand all
342 } 367 }
343 368
344 - (void)sendErrorString:(NSString*)error { 369 - (void)sendErrorString:(NSString*)error {
345 DLOG(ERROR) << [error UTF8String]; 370 DLOG(ERROR) << [error UTF8String];
346 base::AutoLock lock(lock_); 371 base::AutoLock lock(lock_);
347 if (frameReceiver_) 372 if (frameReceiver_)
348 frameReceiver_->ReceiveError([error UTF8String]); 373 frameReceiver_->ReceiveError([error UTF8String]);
349 } 374 }
350 375
351 @end 376 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698