미리보기가 실행되는 동안 스틸 이미지 캡처뿐만 아니라 라이브 미리보기도 수행하는 비디오 앱이 있습니다. 앱이로드 될 때 미리 생성 된 4 개의 텍스처를 사용하고 있습니다. 나는 세 개의 스레드를 통해 텍스쳐에 접근하고있다.스레드 간 프레임 버퍼 공유
실시간 미리보기 작업을 수행하려면 captureOutput
메서드가 FBO_OUT
이라는 프레임 버퍼에 결과를 저장할 수 있도록 공유 그룹 (아래 참조)을 만들어야했습니다. 그런 다음 화면에 표시하려면 presentRenderbuffer
으로 전화하기 위해 FBO_OUT
에 액세스해야했습니다. 공유 그룹을 사용하지 않으면 방금 횡설수설이 생깁니다.
#define SHAREGROUP_CONTEXT [[[appDelegate mainViewController] oglView] offscreenContext]
if ([EAGLContext currentContext] != SHAREGROUP_CONTEXT) {
NSLog(@"setting context");
glFlush();
[EAGLContext setCurrentContext:SHAREGROUP_CONTEXT];
}
@synchronized(SHAREGROUP_CONTEXT)
{
/* process pixels */
}
glFlush(); // at end of method
이 문제를 잘 작동, 지금 정지 영상을 촬영 한 후 같은 일을 시도하고 있다는 점이다 :
CAEAGLLayer* eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = YES;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking,
kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat,
nil];
oglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
offscreenContext = [[EAGLContext alloc] initWithAPI:[oglContext API] sharegroup:oglContext.sharegroup];
if (!oglContext || ![EAGLContext setCurrentContext:oglContext]) {
NSLog(@"Problem with OpenGL context.");
[self release];
return nil;
}
는 주기적으로 captureOutput
내부에이 코드를 호출 할 필요가 그러나 나는 다시 내가 시도했다하더라도 횡설수설을 받고있는 중이 야, captureStillImageAsynchronouslyFromConnection
블록을 통해 (미리보기가 여전히 실행되는 동안은)이 :
AVCaptureConnection *sic = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self stillImageOutput] connections]];
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:sic
completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error)
{
@synchronized(SHAREGROUP_CONTEXT)
{
/* generate new textures to process the imageDataSampleBuffer and cry */
}
이 문제가 재치 것 같다 h 컨텍스트 및 스레딩.
'@ synchronized'를 사용하여 액세스 권한을 잠그면 성능이 저하 될 수 있습니다 (http://perpendiculo.us/?p=133). NSLock은 훨씬 적은 오버 헤드를 가지며 pthread 뮤텍스는 훨씬 더 저렴합니다. 과거에 OpenGL 응용 프로그램에서 많은 성능을 소비하는 잠금을 보았으므로 이것이 추가 될 수 있습니다. 또한 단일 와이드 디스패치 대기열을 사용하고 단일 리소스 (컨텍스트와 같은)에 액세스하는 모든 작업을 해당 대기열로 보내도록 계획 할 수 있습니다. 이것은이 공유 리소스에 대한 안전한 액세스를 보장 할 수있는 잠금없는 방법이며 최근에 내가 선호하는 방법이었습니다. –