简体   繁体   English

更新到 iOS 10.2 后几帧后无法在 GLKView 上绘制 CIImage?

[英]Unable to draw CIImage on GLKView after few frames since updated to iOS 10.2?

Using following code in my application which was performing quiet fine to draw a CIImage on a GLKView again and again as recieved from AVCaptureOutput -didOutputSampleBuffer until I was using iOS <= 10.1.*在我的应用程序中使用以下代码,在我使用 iOS <= 10.1.* 之前,从 AVCaptureOutput -didOutputSampleBuffer收到一次又一次地在 GLKView 上绘制 CIImage

After updating device to iOS 10.2.1 it has stopped working.将设备更新到 iOS 10.2.1 后,它已停止工作。 I am calling it for few frames the app just crashes with low memory warning.我在几帧内调用它,该应用程序因内存不足警告而崩溃。 Whereas with iOS 10.1.1 and below I smoothly runs the app even on older device like iPhone 5S.而在 iOS 10.1.1 及以下版本中,即使在 iPhone 5S 等较旧的设备上,我也能顺利运行该应用程序。

[_glkView bindDrawable];  

if (self.eaglContext != [EAGLContext currentContext])  
[EAGLContext setCurrentContext:self.eaglContext];  

glClearColor(0.0, 0.0, 0.0, 1.0);  
glClear(GL_COLOR_BUFFER_BIT);  

glEnable(GL_BLEND);  
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);  

if (ciImage) {  
    [_ciContext drawImage:ciImage inRect:gvRect fromRect:dRect];  
}  

[_glkView display];  

This is how I am making the CIImage.这就是我制作 CIImage 的方式。

- (CIImage*)ciImageFromPixelBuffer:(CVPixelBufferRef)pixelBuffer ofSampleBuffer:(CMSampleBufferRef)sampleBuffer {
CIImage *croppedImage           = nil;

CFDictionaryRef attachments     = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage                = [CIImage imageWithCVPixelBuffer:pixelBuffer options:(NSDictionary *)attachments];

if (attachments)
    CFRelease(attachments);

croppedImage = ciImage;


    CIFilter *scaleFilter = [CIFilter filterWithName:@"CILanczosScaleTransform"];
    [scaleFilter setValue:croppedImage forKey:@"inputImage"];
    [scaleFilter setValue:[NSNumber numberWithFloat:self.zoom_Resize_Factor == 1 ? 0.25 : 0.5] forKey:@"inputScale"];
    [scaleFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputAspectRatio"];
    croppedImage = [scaleFilter valueForKey:@"outputImage"];


    NSDictionary *options = @{(id)kCIImageAutoAdjustRedEye : @(false)};

    NSArray *adjustments = [ciImage autoAdjustmentFiltersWithOptions:options];
    for (CIFilter *filter in adjustments) {
        [filter setValue:croppedImage forKey:kCIInputImageKey];
        croppedImage = filter.outputImage;
    }

CIFilter *selectedFilter = [VideoFilterFactory getFilterWithType:self.selectedFilterType]; //This line needs to be removed from here

croppedImage = [VideoFilterFactory applyFilter:selectedFilter OnImage:croppedImage];

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

return croppedImage;
}

Here is imgur link http://imgur.com/a/u6Vyo of VM Tracker and OpenGL ES instruments result.这是VM Tracker 和 OpenGL ES 仪器结果的imgur 链接http://imgur.com/a/u6Vyo Incase it eases to understand.以防万一它易于理解。 Thanks.谢谢。

Your GLKView rendering implementation looks fine, the issue seems to be coming from the amount of processing you're doing on PixelBuffer after converting it into CIImage.您的 GLKView 渲染实现看起来不错,问题似乎来自您在将 PixelBuffer 转换为 CIImage 后对它进行的处理量。

Also the Imgur link you shared shows that GLKView is unable to prepare VideoTexture object correctly, most probably due to the memory overload being created in each iteration.此外,您共享的 Imgur 链接显示 GLKView 无法正确准备 VideoTexture 对象,很可能是由于在每次迭代中创建的内存过载。 You need to optimise this CIFilter Processing.您需要优化此 CIFilter 处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM