Làm thế nào để sử dụng "CFRetain (sampleBuffer)" và "CFRelease (sampleBuffer)" trong Swift? CFRetain is unavailable: Core Foundation objectes are automatically memory managed.
Làm thế nào để sử dụng "CFRetain (sampleBuffer)" trong Swift?
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
[self appendVideoSampleBuffer:sampleBuffer];
}
- (void)appendVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer
{
dispatch_async(_writingQueue, ^{
CFRetain(sampleBuffer);
[_videoInput appendSampleBuffer:sampleBuffer];
CFRelease(sampleBuffer);
});
}
Nếu bạn cần phải tham khảo đối tượng CMSampleBuffer ngoài phạm vi của phương pháp này, bạn phải CFRetain nó và sau đó CFRelease nó khi bạn đã kết thúc với nó. (Apple Document)
Bạn có _need_ để "tham chiếu đối tượng CMSampleBuffer bên ngoài phạm vi của phương pháp này" không? –
Có, tôi muốn 'appendSampleBuffer' trong' _writingQueue '. – Limon
'appendSampleBuffer:' làm gì với bộ đệm? Liệu nó sao chép nội dung của nó vào một số bộ nhớ khác mà nó sở hữu, hay nó sử dụng nó như là-là? Trong trường hợp đầu tiên, cặp giữ/giải phóng của bạn không cần thiết tôi nghĩ. –