自更新到 iOS 10.2 后几帧后无法在 GLKView 上绘制 CIImage?
Unable to draw CIImage on GLKView after few frames since updated to iOS 10.2?
在我的应用程序中使用以下代码,在我使用 iOS <= 10.1.*
将设备更新到 iOS 10.2.1 后,它已停止工作。我调用它的几帧应用程序只是因内存不足警告而崩溃。而使用 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];
这就是我制作 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;
}
这是 VM Tracker 和 OpenGL ES 仪器结果的图像 link http://imgur.com/a/u6Vyo。万一它易于理解。谢谢。
您的 GLKView 渲染实现看起来不错,问题似乎出在将 PixelBuffer 转换为 CIImage 后的处理量。
此外,您分享的 Imgur link 显示 GLKView 无法正确准备 VideoTexture 对象,这很可能是由于在每次迭代中创建的内存过载。您需要优化此 CIFilter 处理。
在我的应用程序中使用以下代码,在我使用 iOS <= 10.1.*
将设备更新到 iOS 10.2.1 后,它已停止工作。我调用它的几帧应用程序只是因内存不足警告而崩溃。而使用 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];
这就是我制作 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;
}
这是 VM Tracker 和 OpenGL ES 仪器结果的图像 link http://imgur.com/a/u6Vyo。万一它易于理解。谢谢。
您的 GLKView 渲染实现看起来不错,问题似乎出在将 PixelBuffer 转换为 CIImage 后的处理量。
此外,您分享的 Imgur link 显示 GLKView 无法正确准备 VideoTexture 对象,这很可能是由于在每次迭代中创建的内存过载。您需要优化此 CIFilter 处理。