AVCaptureAudioDataOutputSampleBufferDelegate
의 captureOutput에 의해 반환 된 CMSampleBuffer의 복사본을 만들려고합니다.오디오의 딥 복사
내가 가지고있는 문제는 오랫동안 CFArray
에 유지 한 후 대리인 메서드 captureOutput:didOutputSampleBuffer:fromConnection:
에서 삭제 된 것입니다.
분명히 추가 처리를 위해 들어오는 버퍼의 전체 복사본을 만들어야합니다. CMSampleBufferCreateCopy
은 얕은 사본 만 생성한다는 것도 알고 있습니다.
몇 가지 관련 질문을 SO에했다가 있습니다
- Pulling data from a CMSampleBuffer in order to create a deep copy
- Creating copy of CMSampleBuffer in Swift returns OSStatus -12743 (Invalid Media Format)
- Deep Copy of CMImageBuffer or CVImageBuffer
그러나 그들 중 누구도 12 개 매개 변수를 제대로 CMSampleBufferCreate 기능을 사용하는 나에게 도움이되지 :
CMSampleBufferRef copyBuffer;
CMBlockBufferRef data = CMSampleBufferGetDataBuffer(sampleBuffer);
CMFormatDescriptionRef formatDescription = CMSampleBufferGetFormatDescription(sampleBuffer);
CMItemCount itemCount = CMSampleBufferGetNumSamples(sampleBuffer);
CMTime duration = CMSampleBufferGetDuration(sampleBuffer);
CMTime presentationStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
CMSampleTimingInfo timingInfo;
timingInfo.duration = duration;
timingInfo.presentationTimeStamp = presentationStamp;
timingInfo.decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(sampleBuffer);
size_t sampleSize = CMBlockBufferGetDataLength(data);
CMBlockBufferRef sampleData;
if (CMBlockBufferCopyDataBytes(data, 0, sampleSize, &sampleData) != kCMBlockBufferNoErr) {
VLog(@"error during copying sample buffer");
}
// Here I tried data and sampleData CMBlockBuffer instance, but no success
OSStatus status = CMSampleBufferCreate(kCFAllocatorDefault, data, isDataReady, nil, nil, formatDescription, itemCount, 1, &timingInfo, 1, &sampleSize, ©Buffer);
if (!self.sampleBufferArray) {
self.sampleBufferArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
//EXC_BAD_ACCESS crash when trying to add sampleBuffer to the array
CFArrayAppendValue(self.sampleBufferArray, copyBuffer);
} else {
CFArrayAppendValue(self.sampleBufferArray, copyBuffer);
}
어떻게 오디오 CMSampleBuffer를 완전 복사합니까? 귀하의 답변에 어떤 언어 (신속한/객관적인 -c)라도 자유롭게 사용하십시오.
딥 복사본이 필요합니까? 'CMSampleBufferCreateCopy'를 사용할 때 어떤 일이 발생합니까? 'CMSampleBufferCopySampleBufferForRange'는 깊은 복사본을 줄까요? 추가 처리를 위해'CMSampleBuffer'가 정말로 필요합니까? 자신 만의 처리를하는 경우에는 길이 + 포인터가 더 편리 할 수 있습니다. –
@RhythmicFistman 예,'CMSampleBufferCreateCopy'를 사용하고'CFArray'에 복사 된 샘플을 1 이상 유지하면,'didOutputSampleBuffer'가 호출되는 것을 막을 필요가 있습니다. 이 [질문] (https://stackoverflow.com/questions/30850676/avcaptureoutput-didoutputsamplebuffer-stops-getting-called)을 사용하면 쉽게 재현 할 수 있습니다. 나는'CMSampleBufferCopySampleBufferForRange'로 동작을 점검하고 당신을 업데이트 할 것입니다. –
아, 오케이, 대기 버퍼가 대리인 콜백을 차단한다는 것이 중요한 정보입니다. 위 코드의 실행 가능한 버전에 대한 링크가 있습니까? –