, 나는 카메라에서 이미지 버퍼를 캡처하고 네트워크를 통해 다른 쪽 끝을 통과해야/코코아, 다음 코드 내가 사용하고캡처 카메라 맥의 버퍼 내 응용 프로그램에서
,
-(void)startVideoSessionInSubThread{
// Create the capture session
pPool = [[NSAutoreleasePool alloc]init];
mCaptureSession = [[QTCaptureSession alloc] init] ;
// Connect inputs and outputs to the session
BOOL success = NO;
NSError *error;
// Find a video device
QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
success = [videoDevice open:&error];
// If a video input device can't be found or opened, try to find and open a muxed input device
if (!success) {
videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeMuxed];
success = [videoDevice open:&error];
}
if (!success) {
videoDevice = nil;
// Handle error
}
if (videoDevice) {
//Add the video device to the session as a device input
mCaptureVideoDeviceInput = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice];
success = [mCaptureSession addInput:mCaptureVideoDeviceInput error:&error];
if (!success) {
// Handle error
}
mCaptureDecompressedVideoOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
[mCaptureDecompressedVideoOutput setPixelBufferAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:320.0], (id)kCVPixelBufferWidthKey,
[NSNumber numberWithDouble:240.0], (id)kCVPixelBufferHeightKey,
[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey,
// kCVPixelFormatType_32BGRA , (id)kCVPixelBufferPixelFormatTypeKey,
nil]];
[mCaptureDecompressedVideoOutput setDelegate:self];
[mCaptureDecompressedVideoOutput setMinimumVideoFrameInterval:0.0333333333333]; // to have video effect, 33 fps
success = [mCaptureSession addOutput:mCaptureDecompressedVideoOutput error:&error];
if (!success) {
[[NSAlert alertWithError:error] runModal];
return;
}
[mCaptureView setCaptureSession:mCaptureSession];
bVideoStart = NO;
[mCaptureSession startRunning];
bVideoStart = NO;
}
}
-(void)startVideoSession{
// start video from different session
[NSThread detachNewThreadSelector:@selector(startVideoSessionInSubThread) toTarget:self withObject:nil];
}
에서 함수 processImageBufferNew의 콜백 함수
// Do something with the buffer
- (void)captureOutput:(QTCaptureOutput *)captureOutput didOutputVideoFrame:(CVImageBufferRef)videoFrame
withSampleBuffer:(QTSampleBuffer *)sampleBuffer
fromConnection:(QTCaptureConnection *)connection
[self processImageBufferNew:videoFrame];
return;
}
내가 큐 그 동기화 큐에 이미지를 추가하고, 이제 별도의 스레드 숨어 읽을 거기 EUE와 버퍼를 처리, 무슨 일이 일어나고 것은
, 난의 컨트롤이 너무 프레임이 매우 느리게되고 큐 크기가 매우 빠르게 증가 보내는 다시 캡처 호출에 매우 자주오고 로그를 참조하면
어떤 제안 디자인에?
내가 가장 오래된 노드와 쿼리 대기열을 별도로 실행하므로 로그를 통해 순차적으로 보낼 수 있으므로 분당 500 개 이상의 노드가 추가되어 그 메모리가 증가합니다 및 cpu 기아.
카메라 프레임을 캡처하는 데 사용해야하는 다른 논리가 있습니까?