Project import generated by Copybara.

GitOrigin-RevId: afeb9cf5a8c069c0a566d16e1622bbb086170e4d
This commit is contained in:
MediaPipe Team
2020-05-21 13:37:51 -04:00
committed by chuoling
parent b6e680647c
commit b133b0f200
258 changed files with 4146 additions and 5147 deletions
+38 -30
View File
@@ -24,7 +24,7 @@
AVCaptureSession* _session;
AVCaptureDeviceInput* _videoDeviceInput;
AVCaptureVideoDataOutput* _videoDataOutput;
AVCaptureDepthDataOutput* _depthDataOutput;
AVCaptureDepthDataOutput* _depthDataOutput API_AVAILABLE(ios(11.0));
AVCaptureDevice* _currentDevice;
matrix_float3x3 _cameraIntrinsicMatrix;
@@ -177,11 +177,14 @@
[_session removeInput:_videoDeviceInput];
}
AVCaptureDeviceType deviceType = AVCaptureDeviceTypeBuiltInWideAngleCamera;
if (@available(iOS 11.1, *)) {
if (_cameraPosition == AVCaptureDevicePositionFront && _useDepth) {
deviceType = AVCaptureDeviceTypeBuiltInTrueDepthCamera;
}
}
AVCaptureDeviceDiscoverySession* deviceDiscoverySession = [AVCaptureDeviceDiscoverySession
discoverySessionWithDeviceTypes:@[ _cameraPosition == AVCaptureDevicePositionFront &&
_useDepth
? AVCaptureDeviceTypeBuiltInTrueDepthCamera
: AVCaptureDeviceTypeBuiltInWideAngleCamera ]
discoverySessionWithDeviceTypes:@[ deviceType ]
mediaType:AVMediaTypeVideo
position:_cameraPosition];
AVCaptureDevice* videoDevice =
@@ -216,22 +219,25 @@
[_session removeOutput:_depthDataOutput];
}
if (_useDepth) {
// Add Depth Output
_depthDataOutput = [[AVCaptureDepthDataOutput alloc] init];
_depthDataOutput.alwaysDiscardsLateDepthData = YES;
if ([_session canAddOutput:_depthDataOutput]) {
[_session addOutput:_depthDataOutput];
if (@available(iOS 11.1, *)) {
if (_useDepth) {
// Add Depth Output
_depthDataOutput = [[AVCaptureDepthDataOutput alloc] init];
_depthDataOutput.alwaysDiscardsLateDepthData = YES;
if ([_session canAddOutput:_depthDataOutput]) {
[_session addOutput:_depthDataOutput];
AVCaptureConnection* connection =
[_depthDataOutput connectionWithMediaType:AVMediaTypeDepthData];
AVCaptureConnection* connection =
[_depthDataOutput connectionWithMediaType:AVMediaTypeDepthData];
// Set this when we have a handler.
if (self.delegateQueue) {
[_depthDataOutput setDelegate:self callbackQueue:self.delegateQueue];
// Set this when we have a handler.
if (self.delegateQueue) {
[_depthDataOutput setDelegate:self callbackQueue:self.delegateQueue];
}
} else {
_depthDataOutput = nil;
}
} else
_depthDataOutput = nil;
}
}
if (_useCustomOrientation) {
@@ -239,7 +245,7 @@
connection.videoOrientation = _orientation;
}
{
if (@available(iOS 11.0, *)) {
AVCaptureConnection* connection = [_videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
if ([connection isCameraIntrinsicMatrixDeliverySupported]) {
[connection setCameraIntrinsicMatrixDeliveryEnabled:YES];
@@ -265,18 +271,20 @@
- (void)captureOutput:(AVCaptureOutput*)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection*)connection {
if (!_didReadCameraIntrinsicMatrix) {
// Get camera intrinsic matrix.
CFTypeRef cameraIntrinsicData =
CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil);
if (cameraIntrinsicData != nil) {
CFDataRef cfdr = (CFDataRef)cameraIntrinsicData;
matrix_float3x3* intrinsicMatrix = (matrix_float3x3*)(CFDataGetBytePtr(cfdr));
if (intrinsicMatrix != nil) {
_cameraIntrinsicMatrix = *intrinsicMatrix;
if (@available(iOS 11.0, *)) {
if (!_didReadCameraIntrinsicMatrix) {
// Get camera intrinsic matrix.
CFTypeRef cameraIntrinsicData =
CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_CameraIntrinsicMatrix, nil);
if (cameraIntrinsicData != nil) {
CFDataRef cfdr = (CFDataRef)cameraIntrinsicData;
matrix_float3x3* intrinsicMatrix = (matrix_float3x3*)(CFDataGetBytePtr(cfdr));
if (intrinsicMatrix != nil) {
_cameraIntrinsicMatrix = *intrinsicMatrix;
}
}
_didReadCameraIntrinsicMatrix = YES;
}
_didReadCameraIntrinsicMatrix = YES;
}
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
@@ -293,7 +301,7 @@
- (void)depthDataOutput:(AVCaptureDepthDataOutput*)output
didOutputDepthData:(AVDepthData*)depthData
timestamp:(CMTime)timestamp
connection:(AVCaptureConnection*)connection {
connection:(AVCaptureConnection*)connection API_AVAILABLE(ios(11.0)) {
if (depthData.depthDataType != kCVPixelFormatType_DepthFloat32) {
depthData = [depthData depthDataByConvertingToDepthDataType:kCVPixelFormatType_DepthFloat32];
}
+1 -1
View File
@@ -35,7 +35,7 @@
@optional
- (void)processDepthData:(AVDepthData*)depthData
timestamp:(CMTime)timestamp
fromSource:(MPPInputSource*)source;
fromSource:(MPPInputSource*)source API_AVAILABLE(ios(11.0));
@optional
- (void)videoDidPlayToEnd:(CMTime)timestamp;
+3 -1
View File
@@ -51,11 +51,13 @@
_videoPlayer = [AVPlayer playerWithPlayerItem:_videoItem];
_videoPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
__weak typeof(self) weakSelf = self;
_videoEndObserver = [center addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
object:_videoItem
queue:nil
usingBlock:^(NSNotification* note) {
[self playerItemDidPlayToEnd:note];
[weakSelf playerItemDidPlayToEnd:note];
}];
}
return self;
+4
View File
@@ -316,6 +316,10 @@ CVPixelBufferRef CreateCVPixelBufferForImageFramePacket(
pixel_format = kCVPixelFormatType_OneComponent32Float;
break;
case mediapipe::ImageFormat::VEC32F2:
pixel_format = kCVPixelFormatType_TwoComponent32Float;
break;
default:
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
<< "unsupported ImageFrame format: " << image_format;