2017-02-07 20 views
2

使用下列在我的應用程序,它是安靜的執行罰款,一次又一次畫上一個GLKView一個CIImage直到我使用的是iOS < = 10.1從AVCaptureOutput -didOutputSampleBuffer收到代碼。*自從更新到iOS 10.2後,無法在GLKView上繪製CIImage幾幀後?

更新設備到iOS 9.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; 
} 

這裏是imgur鏈路導致VM跟蹤和OpenGL ES器械的http://imgur.com/a/u6Vyo。它易於理解。謝謝。

+0

如果繞過CIFilter相關處理會發生什麼情況? –

+0

好吧,我通過像素緩衝區,因爲它是glkview它沒有崩潰或有任何影響。但爲什麼發生這種事? – khunshan

回答

1

你的GLKView渲染實現看起來不錯,這個問題似乎來自你在將它轉換成CIImage後在PixelBuffer上做的處理量。

另外,您共享的Imgur鏈接顯示GLKView無法正確準備VideoTexture對象,很可能是由於每次迭代都會創建內存過載。您需要優化此CIFilter處理。

+0

這是否意味着我永遠不能使用一些過濾器。我看着CIFunhouse他們正在實施幾乎所有的核心圖像過濾器,但.....困惑。 – khunshan

+0

如果您的PixelBuffer的分辨率與CIFunhouse中的相​​同,請檢查您的PixelBuffer的分辨率,每張CIFilter無法以每秒24或30幀應用,因此不適用於更高分辨率的視頻,特別是去年或倒數第二次年的iOS設備。 –

+0

我可以將所有過濾器置於工作狀態。我應該縮小還是使用低預設? – khunshan