#include "media/video/capture/mac/video_capture_device_mac.h"
#include "media/video/capture/video_capture_device.h"
#include "media/video/capture/video_capture_types.h"
+#include "ui/gfx/size.h"
@implementation VideoCaptureDeviceQTKit
#pragma mark Public methods
-- (id)initWithFrameReceiver:(media::VideoCaptureDeviceMac *)frameReceiver {
+- (id)initWithFrameReceiver:(media::VideoCaptureDeviceMac*)frameReceiver {
self = [super init];
if (self) {
frameReceiver_ = frameReceiver;
[super dealloc];
}
-- (void)setFrameReceiver:(media::VideoCaptureDeviceMac *)frameReceiver {
+- (void)setFrameReceiver:(media::VideoCaptureDeviceMac*)frameReceiver {
[lock_ lock];
frameReceiver_ = frameReceiver;
[lock_ unlock];
}
-- (BOOL)setCaptureDevice:(NSString *)deviceId {
+- (BOOL)setCaptureDevice:(NSString*)deviceId {
if (deviceId) {
// Set the capture device.
if (captureDeviceInput_) {
QTCaptureDecompressedVideoOutput *output =
[[captureSession_ outputs] objectAtIndex:0];
- // The old capture dictionary is used to retrieve the initial pixel
- // format, which must be maintained.
- NSDictionary *oldCaptureDictionary = [output pixelBufferAttributes];
-
- // Set up desired output properties.
- NSDictionary *captureDictionary =
- [NSDictionary dictionaryWithObjectsAndKeys:
- [NSNumber numberWithDouble:width],
- (id)kCVPixelBufferWidthKey,
- [NSNumber numberWithDouble:height],
- (id)kCVPixelBufferHeightKey,
- [oldCaptureDictionary
- valueForKey:(id)kCVPixelBufferPixelFormatTypeKey],
- (id)kCVPixelBufferPixelFormatTypeKey,
- nil];
- [output setPixelBufferAttributes:captureDictionary];
+ // Set up desired output properties. The old capture dictionary is used to
+ // retrieve the initial pixel format, which must be maintained.
+ NSDictionary* videoSettingsDictionary = @{
+ (id)kCVPixelBufferWidthKey : @(width),
+ (id)kCVPixelBufferHeightKey : @(height),
+ (id)kCVPixelBufferPixelFormatTypeKey : [[output pixelBufferAttributes]
+ valueForKey:(id)kCVPixelBufferPixelFormatTypeKey]
+ };
+ [output setPixelBufferAttributes:videoSettingsDictionary];
[output setMinimumVideoFrameInterval:(NSTimeInterval)1/(float)frameRate];
return YES;
}
// |captureOutput| is called by the capture device to deliver a new frame.
-- (void)captureOutput:(QTCaptureOutput *)captureOutput
+- (void)captureOutput:(QTCaptureOutput*)captureOutput
didOutputVideoFrame:(CVImageBufferRef)videoFrame
- withSampleBuffer:(QTSampleBuffer *)sampleBuffer
- fromConnection:(QTCaptureConnection *)connection {
+ withSampleBuffer:(QTSampleBuffer*)sampleBuffer
+ fromConnection:(QTCaptureConnection*)connection {
[lock_ lock];
if(!frameReceiver_) {
[lock_ unlock];
size_t frameSize = bytesPerRow * frameHeight;
// TODO(shess): bytesPerRow may not correspond to frameWidth_*2,
- // but VideoCaptureController::OnIncomingCapturedFrame() requires
+ // but VideoCaptureController::OnIncomingCapturedData() requires
// it to do so. Plumbing things through is intrusive, for now
// just deliver an adjusted buffer.
// TODO(nick): This workaround could probably be eliminated by using
addressToPass = adjustedAddress;
frameSize = frameHeight * expectedBytesPerRow;
}
- media::VideoCaptureCapability captureCapability;
- captureCapability.width = frameWidth;
- captureCapability.height = frameHeight;
- captureCapability.frame_rate = frameRate_;
- captureCapability.color = media::PIXEL_FORMAT_UYVY;
+
+ media::VideoCaptureFormat captureFormat(gfx::Size(frameWidth, frameHeight),
+ frameRate_,
+ media::PIXEL_FORMAT_UYVY);
// The aspect ratio dictionary is often missing, in which case we report
// a pixel aspect ratio of 0:0.
}
// Deliver the captured video frame.
- frameReceiver_->ReceiveFrame(addressToPass, frameSize, captureCapability,
+ frameReceiver_->ReceiveFrame(addressToPass, frameSize, captureFormat,
aspectNumerator, aspectDenominator);
CVPixelBufferUnlockBaseAddress(videoFrame, kLockFlags);
[lock_ unlock];
}
-- (void)handleNotification:(NSNotification *)errorNotification {
- NSError * error = (NSError *)[[errorNotification userInfo]
+- (void)handleNotification:(NSNotification*)errorNotification {
+ NSError * error = (NSError*)[[errorNotification userInfo]
objectForKey:QTCaptureSessionErrorKey];
- frameReceiver_->ReceiveError([[error localizedDescription] UTF8String]);
+ NSString* str_error =
+ [NSString stringWithFormat:@"%@: %@",
+ [error localizedDescription],
+ [error localizedFailureReason]];
+
+ frameReceiver_->ReceiveError([str_error UTF8String]);
}
@end