captureOutputから返されたCMSampleBufferのコピーをAVCaptureAudioDataOutputSampleBufferDelegate
に作成しようとしています。オーディオの深いコピーCMSampleBuffer
私が抱えている問題は、デリゲートメソッドcaptureOutput:didOutputSampleBuffer:fromConnection:
から来るフレームが、長時間にわたってCFArray
に保持された後に削除されてしまうことです。
明らかに、今後の処理のために着信バッファのディープコピーを作成する必要があります。 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を詳細にコピーしますか?あなたの答えには、どんな言葉を使ってもかまいません。
ディープコピーが必要なのは明らかですか? 'CMSampleBufferCreateCopy'を使うとどうなりますか? 'CMSampleBufferCopySampleBufferForRange'は深いコピーを与えますか?さらなる処理のために 'CMSampleBuffer'sが本当に必要ですか?独自の処理をしている場合は、length + pointerが便利です。 –
@RhythmicFistmanはい、 'CMSampleBufferCreateCopy'を使用して、コピーされたサンプルを' CFArray'に1秒以上保持すると、 'didOutputSampleBuffer'が呼び出されるのを止める必要があることは明らかです。この[質問](https://stackoverflow.com/questions/30850676/avcaptureoutput-didoutputsamplebuffer-stops-getting-called)で簡単に再現することができます。私は 'CMSampleBufferCopySampleBufferForRange'で動作をチェックし、あなたを更新します。 –
ああ、大丈夫、その保持バッファがあなたの代理コールバックをブロックすることが重要な情報です。上記のコードの実行可能なバージョンへのリンクがありますか? –