Project import generated by Copybara.
GitOrigin-RevId: 852dfb05d450167899c0dd5ef7c45622a12e865b
This commit is contained in:
committed by
Hadon Nash
parent
d144e564d8
commit
de4fbc10e6
@@ -34,6 +34,9 @@
|
||||
/// Whether to rotate video buffers with device rotation.
|
||||
@property(nonatomic) BOOL autoRotateBuffers;
|
||||
|
||||
/// The camera intrinsic matrix.
|
||||
@property(nonatomic, readonly) matrix_float3x3 cameraIntrinsicMatrix;
|
||||
|
||||
/// The capture session.
|
||||
@property(nonatomic, readonly) AVCaptureSession *session;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
AVCaptureDeviceInput* _videoDeviceInput;
|
||||
AVCaptureVideoDataOutput* _videoDataOutput;
|
||||
AVCaptureDepthDataOutput* _depthDataOutput;
|
||||
AVCaptureDevice *_currentDevice;
|
||||
AVCaptureDevice* _currentDevice;
|
||||
|
||||
matrix_float3x3 _cameraIntrinsicMatrix;
|
||||
OSType _pixelFormatType;
|
||||
@@ -50,8 +50,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setDelegate:(id<MPPInputSourceDelegate>)delegate
|
||||
queue:(dispatch_queue_t)queue {
|
||||
- (void)setDelegate:(id<MPPInputSourceDelegate>)delegate queue:(dispatch_queue_t)queue {
|
||||
[super setDelegate:delegate queue:queue];
|
||||
// Note that _depthDataOutput and _videoDataOutput may not have been created yet. In that case,
|
||||
// this message to nil is ignored, and the delegate will be set later by setupCamera.
|
||||
@@ -157,9 +156,7 @@
|
||||
- (void)setPixelFormatType:(OSType)pixelFormatType {
|
||||
_pixelFormatType = pixelFormatType;
|
||||
if ([self isRunning]) {
|
||||
_videoDataOutput.videoSettings = @{
|
||||
(id)kCVPixelBufferPixelFormatTypeKey : @(_pixelFormatType)
|
||||
};
|
||||
_videoDataOutput.videoSettings = @{(id)kCVPixelBufferPixelFormatTypeKey : @(_pixelFormatType)};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,10 +178,10 @@
|
||||
}
|
||||
|
||||
AVCaptureDeviceDiscoverySession* deviceDiscoverySession = [AVCaptureDeviceDiscoverySession
|
||||
discoverySessionWithDeviceTypes:@[
|
||||
_cameraPosition == AVCaptureDevicePositionFront && _useDepth ?
|
||||
AVCaptureDeviceTypeBuiltInTrueDepthCamera :
|
||||
AVCaptureDeviceTypeBuiltInWideAngleCamera]
|
||||
discoverySessionWithDeviceTypes:@[ _cameraPosition == AVCaptureDevicePositionFront &&
|
||||
_useDepth
|
||||
? AVCaptureDeviceTypeBuiltInTrueDepthCamera
|
||||
: AVCaptureDeviceTypeBuiltInWideAngleCamera ]
|
||||
mediaType:AVMediaTypeVideo
|
||||
position:_cameraPosition];
|
||||
AVCaptureDevice* videoDevice =
|
||||
@@ -211,9 +208,7 @@
|
||||
// kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange,
|
||||
// kCVPixelFormatType_420YpCbCr8BiPlanarFullRange,
|
||||
// kCVPixelFormatType_32BGRA.
|
||||
_videoDataOutput.videoSettings = @{
|
||||
(id)kCVPixelBufferPixelFormatTypeKey : @(_pixelFormatType)
|
||||
};
|
||||
_videoDataOutput.videoSettings = @{(id)kCVPixelBufferPixelFormatTypeKey : @(_pixelFormatType)};
|
||||
}
|
||||
|
||||
// Remove Old Depth Depth
|
||||
@@ -229,14 +224,13 @@
|
||||
[_session addOutput:_depthDataOutput];
|
||||
|
||||
AVCaptureConnection* connection =
|
||||
[_depthDataOutput connectionWithMediaType:AVMediaTypeDepthData];
|
||||
[_depthDataOutput connectionWithMediaType:AVMediaTypeDepthData];
|
||||
|
||||
// Set this when we have a handler.
|
||||
if (self.delegateQueue) {
|
||||
[_depthDataOutput setDelegate:self callbackQueue:self.delegateQueue];
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
_depthDataOutput = nil;
|
||||
}
|
||||
|
||||
@@ -269,15 +263,8 @@
|
||||
|
||||
// Receives frames from the camera. Invoked on self.frameHandlerQueue.
|
||||
- (void)captureOutput:(AVCaptureOutput*)captureOutput
|
||||
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
||||
fromConnection:(AVCaptureConnection*)connection {
|
||||
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
|
||||
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
|
||||
if ([self.delegate respondsToSelector:@selector(processVideoFrame:timestamp:fromSource:)]) {
|
||||
[self.delegate processVideoFrame:imageBuffer timestamp:timestamp fromSource:self];
|
||||
} else if ([self.delegate respondsToSelector:@selector(processVideoFrame:fromSource:)]) {
|
||||
[self.delegate processVideoFrame:imageBuffer fromSource:self];
|
||||
}
|
||||
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
||||
fromConnection:(AVCaptureConnection*)connection {
|
||||
if (!_didReadCameraIntrinsicMatrix) {
|
||||
// Get camera intrinsic matrix.
|
||||
CFTypeRef cameraIntrinsicData =
|
||||
@@ -291,15 +278,22 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
|
||||
}
|
||||
_didReadCameraIntrinsicMatrix = YES;
|
||||
}
|
||||
CVPixelBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
|
||||
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
|
||||
if ([self.delegate respondsToSelector:@selector(processVideoFrame:timestamp:fromSource:)]) {
|
||||
[self.delegate processVideoFrame:imageBuffer timestamp:timestamp fromSource:self];
|
||||
} else if ([self.delegate respondsToSelector:@selector(processVideoFrame:fromSource:)]) {
|
||||
[self.delegate processVideoFrame:imageBuffer fromSource:self];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - AVCaptureDepthDataOutputDelegate methods
|
||||
|
||||
// Receives depth frames from the camera. Invoked on self.frameHandlerQueue.
|
||||
- (void)depthDataOutput:(AVCaptureDepthDataOutput *)output
|
||||
didOutputDepthData:(AVDepthData *)depthData
|
||||
- (void)depthDataOutput:(AVCaptureDepthDataOutput*)output
|
||||
didOutputDepthData:(AVDepthData*)depthData
|
||||
timestamp:(CMTime)timestamp
|
||||
connection:(AVCaptureConnection *)connection {
|
||||
connection:(AVCaptureConnection*)connection {
|
||||
if (depthData.depthDataType != kCVPixelFormatType_DepthFloat32) {
|
||||
depthData = [depthData depthDataByConvertingToDepthDataType:kCVPixelFormatType_DepthFloat32];
|
||||
}
|
||||
|
||||
@@ -312,6 +312,10 @@ CVPixelBufferRef CreateCVPixelBufferForImageFramePacket(
|
||||
pixel_format = kCVPixelFormatType_OneComponent8;
|
||||
break;
|
||||
|
||||
case mediapipe::ImageFormat::VEC32F1:
|
||||
pixel_format = kCVPixelFormatType_OneComponent32Float;
|
||||
break;
|
||||
|
||||
default:
|
||||
return ::mediapipe::UnknownErrorBuilder(MEDIAPIPE_LOC)
|
||||
<< "unsupported ImageFrame format: " << image_format;
|
||||
|
||||
Reference in New Issue
Block a user