相机分队列渲染

This commit is contained in:
Wang.Renzhu 2022-08-02 19:20:10 +08:00
parent fbf31f0104
commit 673794bea7
10 changed files with 111 additions and 86 deletions

View File

@ -50,9 +50,11 @@
@property (nonatomic, weak) id<OlaMTLCameraRenderViewDelegate> cameraDelegate; @property (nonatomic, weak) id<OlaMTLCameraRenderViewDelegate> cameraDelegate;
@property (nonatomic) dispatch_queue_t displayRenderQueue; @property (nonatomic) dispatch_queue_t displayRenderQueue;
@property (nonatomic) dispatch_queue_t offlineRenderQueue;
/// 原始相机纹理 可以快速读取 /// 原始相机纹理 可以快速读取
@property (nonatomic, readonly, strong) OlaShareTexture *cameraTexture; @property (nonatomic, readonly, strong) OlaShareTexture *cameraTexture;
@property (nonatomic, readonly, strong) OlaShareTexture *halfCameraTexture;
@property (nonatomic, readonly, strong) OlaShareTexture *shareTexture; @property (nonatomic, readonly, strong) OlaShareTexture *shareTexture;
/// 不带后处理的相机渲染的原始纹理 /// 不带后处理的相机渲染的原始纹理

View File

@ -12,7 +12,7 @@
#import <OpenGLES/EAGL.h> #import <OpenGLES/EAGL.h>
#import <OpenGLES/ES3/gl.h> #import <OpenGLES/ES3/gl.h>
static const NSUInteger MaxFramesInFlight = 3; static const NSUInteger MaxFramesInFlight = 1;
static size_t const kOlaDynamicTextureByteAlignment = 16; static size_t const kOlaDynamicTextureByteAlignment = 16;
NS_INLINE size_t QAAlignSize(size_t size) NS_INLINE size_t QAAlignSize(size_t size)
@ -52,7 +52,7 @@ NS_INLINE size_t QAAlignSize(size_t size)
_shareTexture = nil; _shareTexture = nil;
_cameraTexture = nil; _cameraTexture = nil;
_halfCameraTexture = nil;
} }
- (instancetype)initWithFrame:(CGRect)frame - (instancetype)initWithFrame:(CGRect)frame
@ -104,6 +104,11 @@ NS_INLINE size_t QAAlignSize(size_t size)
metalPixelFormat:self.colorPixelFormat metalPixelFormat:self.colorPixelFormat
size:textureSize]; size:textureSize];
_halfCameraTexture = [[OlaShareTexture alloc] initWithMetalDevice:self.device
openGLContext:self.openGLContext
metalPixelFormat:self.colorPixelFormat
size:CGSizeMake(textureSize.width * 0.25, textureSize.height * 0.25)];
_mtlRender = [[OlaMTLCameraRender alloc] initWithRenderSize:textureSize _mtlRender = [[OlaMTLCameraRender alloc] initWithRenderSize:textureSize
device:self.device device:self.device
cameraTexture:self.cameraTexture cameraTexture:self.cameraTexture
@ -118,6 +123,7 @@ NS_INLINE size_t QAAlignSize(size_t size)
self.displayFrameRenderingSemaphore = dispatch_semaphore_create(MaxFramesInFlight); self.displayFrameRenderingSemaphore = dispatch_semaphore_create(MaxFramesInFlight);
self.displayRenderQueue = dispatch_queue_create("Ola.ios.displayRenderQueue", self.displayRenderQueue = dispatch_queue_create("Ola.ios.displayRenderQueue",
interactive); interactive);
self.offlineRenderQueue = dispatch_queue_create("Ola.ios.offlineRenderQueue", interactive);
self.cameraFrameRenderingSemaphore = dispatch_semaphore_create(1); self.cameraFrameRenderingSemaphore = dispatch_semaphore_create(1);
} }
@ -209,6 +215,10 @@ NS_INLINE size_t QAAlignSize(size_t size)
[strongSelf.mtlRender renderToShareTexture:strongSelf.shareTexture.metalTexture [strongSelf.mtlRender renderToShareTexture:strongSelf.shareTexture.metalTexture
commandBuffer:commandBuffer commandBuffer:commandBuffer
frameTime:strongSelf.frameTime]; frameTime:strongSelf.frameTime];
[strongSelf.mtlRender renderToTexture:strongSelf.halfCameraTexture.metalTexture
from:strongSelf.cameraTexture.metalTexture commandBuffer:commandBuffer
textureCoordinate:strongSelf.mtlRender.noRotationBuffer];
[commandBuffer commit]; [commandBuffer commit];
commandBuffer = [strongSelf.mtlRender.commandQueue commandBuffer]; commandBuffer = [strongSelf.mtlRender.commandQueue commandBuffer];
@ -234,14 +244,13 @@ NS_INLINE size_t QAAlignSize(size_t size)
[EAGLContext setCurrentContext:strongSelf.openGLContext]; [EAGLContext setCurrentContext:strongSelf.openGLContext];
[strongSelf.cameraDelegate draw:strongSelf.frameTime]; [strongSelf.cameraDelegate draw:strongSelf.frameTime];
[strongSelf.cameraDelegate bgraCameraTextureReady:strongSelf.cameraTexture
onScreenTexture:strongSelf.shareTexture
frameTime:strongSelf.frameTime * 1000];
IOSurfaceID surfaceId = [strongSelf.cameraDelegate externalRender:strongSelf.frameTime IOSurfaceID surfaceId = [strongSelf.cameraDelegate externalRender:strongSelf.frameTime
targetTexture:strongSelf.cameraTexture targetTexture:strongSelf.cameraTexture
commandBuffer:commandBuffer]; commandBuffer:commandBuffer];
[strongSelf.cameraDelegate bgraCameraTextureReady:strongSelf.halfCameraTexture
onScreenTexture:strongSelf.shareTexture
frameTime:strongSelf.frameTime * 1000];
if (surfaceId != -1) { if (surfaceId != -1) {
//这里渲染surfaceId //这里渲染surfaceId
IOSurfaceRef ioSurface = IOSurfaceLookup(surfaceId); IOSurfaceRef ioSurface = IOSurfaceLookup(surfaceId);
@ -320,14 +329,14 @@ NS_INLINE size_t QAAlignSize(size_t size)
}; };
CFRetain(pixelbuffer); CFRetain(pixelbuffer);
dispatch_async(self.displayRenderQueue, ^{ dispatch_async(self.offlineRenderQueue, ^{
if (weakSelf == nil) { if (weakSelf == nil) {
CFRelease(pixelbuffer); CFRelease(pixelbuffer);
return; return;
} }
__strong OlaMTLCameraRenderView *strongSelf = weakSelf; __strong OlaMTLCameraRenderView *strongSelf = weakSelf;
[strongSelf.mtlRender renderToCameraTextureWithPixelBuffer:pixelbuffer completedHandler:renderCompleted]; [strongSelf.mtlRender renderToCameraTextureWithPixelBuffer:pixelbuffer completedHandler:renderCompleted];
CFRelease(pixelbuffer); CFRelease(pixelbuffer);
}); });
} }
@ -351,7 +360,7 @@ NS_INLINE size_t QAAlignSize(size_t size)
}; };
CFRetain(sampleBuffer); CFRetain(sampleBuffer);
dispatch_async(self.displayRenderQueue, ^{ dispatch_async(self.offlineRenderQueue, ^{
if (weakSelf == nil) { if (weakSelf == nil) {
CFRelease(sampleBuffer); CFRelease(sampleBuffer);
return; return;
@ -359,8 +368,9 @@ NS_INLINE size_t QAAlignSize(size_t size)
__strong OlaMTLCameraRenderView *strongSelf = weakSelf; __strong OlaMTLCameraRenderView *strongSelf = weakSelf;
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
[strongSelf.mtlRender renderToCameraTextureWithPixelBuffer:pixelBuffer completedHandler:renderCompleted]; [strongSelf.mtlRender renderToCameraTextureWithPixelBuffer:pixelBuffer completedHandler:renderCompleted];
CFRelease(sampleBuffer); CFRelease(sampleBuffer);
}); });
} }

View File

@ -25,11 +25,11 @@ namespace Opipe
void FaceMeshCallFrameDelegate::outputPixelbuffer(OlaGraph *graph, CVPixelBufferRef pixelbuffer, void FaceMeshCallFrameDelegate::outputPixelbuffer(OlaGraph *graph, CVPixelBufferRef pixelbuffer,
const std::string &streamName, int64_t timestamp) const std::string &streamName, int64_t timestamp)
{ {
_imp->currentDispatch()->runSync([&] { // _imp->currentDispatch()->runSync([&] {
IOSurfaceRef surface = CVPixelBufferGetIOSurface(pixelbuffer); // IOSurfaceRef surface = CVPixelBufferGetIOSurface(pixelbuffer);
IOSurfaceID surfaceId = IOSurfaceGetID(surface); // IOSurfaceID surfaceId = IOSurfaceGetID(surface);
Log("Opipe", "streamName %s timeStamp:%ld iosurfaceid:%d", streamName.c_str(), timestamp, surfaceId); // Log("Opipe", "streamName %s timeStamp:%ld iosurfaceid:%d", streamName.c_str(), timestamp, surfaceId);
}); // });
} }
#endif #endif

View File

@ -249,7 +249,7 @@ namespace Opipe
{ {
Vector2 point1 = _positionAt(362); Vector2 point1 = _positionAt(362);
Vector2 point2 = _positionAt(263); Vector2 point2 = _positionAt(263);
Vector2 point3 = _positionAt(417); Vector2 point3 = _positionAt(168);
Vector2 center = point1.getCenter(point2); Vector2 center = point1.getCenter(point2);
float distance = center.distance(point3); float distance = center.distance(point3);
addPoint(center, distance / 2, distance / 2, 0.3, 1, 0.0f, 0.0f, 1); addPoint(center, distance / 2, distance / 2, 0.3, 1, 0.0f, 0.0f, 1);
@ -259,7 +259,7 @@ namespace Opipe
{ {
Vector2 point1 = _positionAt(33); Vector2 point1 = _positionAt(33);
Vector2 point2 = _positionAt(133); Vector2 point2 = _positionAt(133);
Vector2 point3 = _positionAt(193); Vector2 point3 = _positionAt(168);
Vector2 center = point1.getCenter(point2); Vector2 center = point1.getCenter(point2);
float distance = center.distance(point3); float distance = center.distance(point3);
addPoint(center, distance / 2, distance / 2, 0.3, 1, 0.0f, 0.0f, 1); addPoint(center, distance / 2, distance / 2, 0.3, 1, 0.0f, 0.0f, 1);

View File

@ -67,33 +67,42 @@ namespace Opipe {
} }
_lutFilter = LUTFilter::create(context); _lutFilter = LUTFilter::create(context);
_unSharpMaskFilter = UnSharpMaskFilter::create(context); _unSharpMaskFilter = UnSharpMaskFilter::create(context);
_unSharpMaskFilter->addTarget(_lutFilter, 0);
_faceDistortFilter = FaceDistortionFilter::create(context); _faceDistortFilter = FaceDistortionFilter::create(context);
_bilateralAdjustFilter = BilateralAdjustFilter::create(context); _bilateralAdjustFilter = BilateralAdjustFilter::create(context);
addFilter(_bilateralAdjustFilter);
_lookUpGroupFilter = FilterGroup::create(context);
_lookUpGroupFilter->addFilter(_unSharpMaskFilter);
_alphaBlendFilter = AlphaBlendFilter::create(context); _alphaBlendFilter = AlphaBlendFilter::create(context);
_bilateralFilter = BilateralFilter::create(context); _bilateralFilter = BilateralFilter::create(context);
_lookUpGroupFilter = FilterGroup::create(context);
addFilter(_bilateralAdjustFilter);
addFilter(_bilateralFilter); addFilter(_bilateralFilter);
_unSharpMaskFilter->addTarget(_lutFilter, 0);
_lookUpGroupFilter->addFilter(_unSharpMaskFilter);
_lookUpGroupFilter->setTerminalFilter(_lutFilter);
_bilateralAdjustFilter->addTarget(_lookUpGroupFilter)->addTarget(_alphaBlendFilter, 1); _bilateralAdjustFilter->addTarget(_lookUpGroupFilter)->addTarget(_alphaBlendFilter, 1);
_bilateralFilter->addTarget(_bilateralAdjustFilter, 1)->addTarget(_alphaBlendFilter, 0); _bilateralFilter->addTarget(_bilateralAdjustFilter, 1)->addTarget(_alphaBlendFilter, 0);
_alphaBlendFilter->setMix(0.8); _alphaBlendFilter->setMix(0.8);
_bilateralAdjustFilter->setOpacityLimit(0.6); _bilateralAdjustFilter->setOpacityLimit(0.6);
_bilateralFilter->setDistanceNormalizationFactor(2.746); _bilateralFilter->setDistanceNormalizationFactor(2.746);
_bilateralFilter->setTexelSpacingMultiplier(2.7); _bilateralFilter->setTexelSpacingMultiplier(2.7);
_unSharpMaskFilter->setBlurRadiusInPixel(4.0f, true); _unSharpMaskFilter->setBlurRadiusInPixel(4.0f, true);
_unSharpMaskFilter->setBlurRadiusInPixel(2.0f, false); _unSharpMaskFilter->setBlurRadiusInPixel(2.0f, false);
_unSharpMaskFilter->setIntensity(1.365); _unSharpMaskFilter->setIntensity(1.365);
_alphaBlendFilter->addTarget(_faceDistortFilter); _alphaBlendFilter->addTarget(_faceDistortFilter);
setTerminalFilter(_faceDistortFilter); setTerminalFilter(_faceDistortFilter);
@ -120,12 +129,7 @@ namespace Opipe {
registerProperty("skin", 0.0f, "磨皮 0.0 - 1.0", registerProperty("skin", 0.0f, "磨皮 0.0 - 1.0",
[this](float skin) { [this](float skin) {
if (skin == 0.0) { _bilateralAdjustFilter->setOpacityLimit(skin);
_bilateralAdjustFilter->setEnable(false);
} else {
_bilateralAdjustFilter->setEnable(true);
_bilateralAdjustFilter->setOpacityLimit(skin);
}
}); });
registerProperty("whiten", 0.0f, "美白 0.0 - 1.0", registerProperty("whiten", 0.0f, "美白 0.0 - 1.0",

View File

@ -18,7 +18,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="vhS-oS-Fej"> <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="vhS-oS-Fej">
<rect key="frame" x="55" y="632" width="304" height="31"/> <rect key="frame" x="55" y="532" width="304" height="31"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="300" id="YLm-AJ-oyY"/> <constraint firstAttribute="width" constant="300" id="YLm-AJ-oyY"/>
</constraints> </constraints>
@ -27,7 +27,7 @@
</connections> </connections>
</slider> </slider>
<slider opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="Qqv-lK-sGM"> <slider opaque="NO" tag="1" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="Qqv-lK-sGM">
<rect key="frame" x="55" y="703" width="304" height="31"/> <rect key="frame" x="55" y="603" width="304" height="31"/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="300" id="RfD-NJ-btk"/> <constraint firstAttribute="width" constant="300" id="RfD-NJ-btk"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="YrT-Ue-dTy"/> <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="YrT-Ue-dTy"/>
@ -37,31 +37,31 @@
</connections> </connections>
</slider> </slider>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="美白磨皮" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="S8B-AB-YC8"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="美白磨皮" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="S8B-AB-YC8">
<rect key="frame" x="172" y="601" width="70" height="21"/> <rect key="frame" x="172" y="501" width="70" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="瘦脸" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Xqq-mI-Nvq"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="瘦脸" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Xqq-mI-Nvq">
<rect key="frame" x="189.5" y="672" width="35" height="21"/> <rect key="frame" x="189.5" y="572" width="35" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="大眼" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vgF-XJ-zVO"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="大眼" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vgF-XJ-zVO">
<rect key="frame" x="189.5" y="743" width="35" height="21"/> <rect key="frame" x="189.5" y="643" width="35" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="整形-缩鼻翼" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mom-9E-xEB"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="整形-缩鼻翼" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Mom-9E-xEB">
<rect key="frame" x="159.5" y="814" width="95" height="20.5"/> <rect key="frame" x="159.5" y="714" width="95" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<slider opaque="NO" tag="2" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="wEp-us-rWn"> <slider opaque="NO" tag="2" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="wEp-us-rWn">
<rect key="frame" x="55" y="774" width="304" height="31"/> <rect key="frame" x="55" y="674" width="304" height="31"/>
<constraints> <constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="SU3-lS-UVj"/> <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="SU3-lS-UVj"/>
<constraint firstAttribute="width" constant="300" id="d1T-V2-Y4S"/> <constraint firstAttribute="width" constant="300" id="d1T-V2-Y4S"/>
@ -71,7 +71,7 @@
</connections> </connections>
</slider> </slider>
<slider opaque="NO" tag="3" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="axw-O5-vck"> <slider opaque="NO" tag="3" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="axw-O5-vck">
<rect key="frame" x="55" y="844.5" width="304" height="31"/> <rect key="frame" x="55" y="744.5" width="304" height="31"/>
<constraints> <constraints>
<constraint firstAttribute="width" relation="lessThanOrEqual" constant="300" id="cWo-IZ-VC0"/> <constraint firstAttribute="width" relation="lessThanOrEqual" constant="300" id="cWo-IZ-VC0"/>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="goO-a8-B8f"/> <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="300" id="goO-a8-B8f"/>
@ -93,7 +93,7 @@
<constraint firstItem="Mom-9E-xEB" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="TYW-Gr-uFp"/> <constraint firstItem="Mom-9E-xEB" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="TYW-Gr-uFp"/>
<constraint firstItem="vgF-XJ-zVO" firstAttribute="top" secondItem="Qqv-lK-sGM" secondAttribute="bottom" constant="10" id="VIL-NW-R20"/> <constraint firstItem="vgF-XJ-zVO" firstAttribute="top" secondItem="Qqv-lK-sGM" secondAttribute="bottom" constant="10" id="VIL-NW-R20"/>
<constraint firstItem="axw-O5-vck" firstAttribute="top" secondItem="Mom-9E-xEB" secondAttribute="bottom" constant="10" id="Vcm-Ek-dn6"/> <constraint firstItem="axw-O5-vck" firstAttribute="top" secondItem="Mom-9E-xEB" secondAttribute="bottom" constant="10" id="Vcm-Ek-dn6"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="vhS-oS-Fej" secondAttribute="bottom" constant="200" id="cTV-Ue-aqY"/> <constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="vhS-oS-Fej" secondAttribute="bottom" constant="300" id="cTV-Ue-aqY"/>
<constraint firstItem="Xqq-mI-Nvq" firstAttribute="top" secondItem="vhS-oS-Fej" secondAttribute="bottom" constant="10" id="d5V-Bk-AdN"/> <constraint firstItem="Xqq-mI-Nvq" firstAttribute="top" secondItem="vhS-oS-Fej" secondAttribute="bottom" constant="10" id="d5V-Bk-AdN"/>
<constraint firstItem="axw-O5-vck" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="dS4-8m-TsB"/> <constraint firstItem="axw-O5-vck" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="dS4-8m-TsB"/>
<constraint firstItem="Xqq-mI-Nvq" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="elq-CK-DpX"/> <constraint firstItem="Xqq-mI-Nvq" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="elq-CK-DpX"/>

View File

@ -269,6 +269,7 @@ AVCaptureAudioDataOutputSampleBufferDelegate> {
targetTexture:(OlaShareTexture *)targetTexture targetTexture:(OlaShareTexture *)targetTexture
commandBuffer:(id<MTLCommandBuffer>)buffer commandBuffer:(id<MTLCommandBuffer>)buffer
{ {
// [[OlaFaceUnity sharedInstance] processVideoFrame:targetTexture.renderTarget timeStamp:frameTime];
FaceTextureInfo inputTexture; FaceTextureInfo inputTexture;
inputTexture.width = targetTexture.size.width; inputTexture.width = targetTexture.size.width;
inputTexture.height = targetTexture.size.height; inputTexture.height = targetTexture.size.height;

View File

@ -50,27 +50,29 @@
- (FaceTextureInfo)render:(FaceTextureInfo)inputTexture - (FaceTextureInfo)render:(FaceTextureInfo)inputTexture
{ {
@autoreleasepool { TextureInfo rs;
TextureInfo rs; rs.ioSurfaceId = inputTexture.ioSurfaceId;
rs.ioSurfaceId = inputTexture.ioSurfaceId; rs.width = inputTexture.width;
if (_face_module) { rs.height = inputTexture.height;
TextureInfo input; rs.textureId = inputTexture.textureId;
input.width = inputTexture.width; rs.frameTime = inputTexture.frameTime;
input.height = inputTexture.height; if (_face_module) {
input.ioSurfaceId = inputTexture.ioSurfaceId; TextureInfo input;
input.textureId = inputTexture.textureId; input.width = inputTexture.width;
input.frameTime = inputTexture.frameTime; input.height = inputTexture.height;
input.ioSurfaceId = inputTexture.ioSurfaceId;
rs = _face_module->renderTexture(input); input.textureId = inputTexture.textureId;
} input.frameTime = inputTexture.frameTime;
FaceTextureInfo result;
result.width = rs.width; rs = _face_module->renderTexture(input);
result.height = rs.height;
result.ioSurfaceId = rs.ioSurfaceId;
result.textureId = rs.textureId;
result.frameTime = rs.frameTime;
return result;
} }
FaceTextureInfo result;
result.width = rs.width;
result.height = rs.height;
result.ioSurfaceId = rs.ioSurfaceId;
result.textureId = rs.textureId;
result.frameTime = rs.frameTime;
return result;
} }

View File

@ -19,29 +19,35 @@ namespace Opipe
const mediapipe::Packet &packet) const mediapipe::Packet &packet)
{ {
OlaGraph *graph = (OlaGraph *)wrapperVoid; OlaGraph *graph = (OlaGraph *)wrapperVoid;
if (graph->_delegate.expired())
{
return;
}
graph->_delegate.lock()->outputPacket(graph, packet, streamName);
if (packetType == MPPPacketTypeRaw)
{
graph->_delegate.lock()->outputPacket(graph, packet, packetType, streamName);
}
#if defined(__APPLE__) #if defined(__APPLE__)
else if (packetType == MPPPacketTypePixelBuffer || @autoreleasepool {
packetType == MPPPacketTypeImage) #endif
{ if (graph->_delegate.expired())
graph->_framesInFlight--; {
CVPixelBufferRef pixelBuffer; return;
if (packetType == MPPPacketTypePixelBuffer) }
pixelBuffer = mediapipe::GetCVPixelBufferRef(packet.Get<mediapipe::GpuBuffer>());
else
pixelBuffer = packet.Get<mediapipe::Image>().GetCVPixelBufferRef();
graph->_delegate.lock()->outputPixelbuffer(graph, pixelBuffer, streamName, packet.Timestamp().Value()); graph->_delegate.lock()->outputPacket(graph, packet, streamName);
if (packetType == MPPPacketTypeRaw)
{
graph->_delegate.lock()->outputPacket(graph, packet, packetType, streamName);
} else if (packetType == MPPPacketTypeImageFrame) {
graph->_framesInFlight--;
}
#if defined(__APPLE__)
else if (packetType == MPPPacketTypePixelBuffer ||
packetType == MPPPacketTypeImage)
{
graph->_framesInFlight--;
CVPixelBufferRef pixelBuffer;
if (packetType == MPPPacketTypePixelBuffer)
pixelBuffer = mediapipe::GetCVPixelBufferRef(packet.Get<mediapipe::GpuBuffer>());
else
pixelBuffer = packet.Get<mediapipe::Image>().GetCVPixelBufferRef();
graph->_delegate.lock()->outputPixelbuffer(graph, pixelBuffer, streamName, packet.Timestamp().Value());
}
} }
#endif #endif