現象
動画のsample bufferを独自作成されたqueueでエンコードしてますが、たまにencoderリセットしたあとエンコード走るとVTCompressionSessionEncodeFrame
でdeadlockになって、statusも返ってこないまあまあ死んでしまう
code
-(void)append:(CMSampleBufferRef)sb
{
CFRetain(sb);
dispatch_async(queue, ^{
.....
// ここでdead lock,statusも返ってこない
auto s = VTCompressionSessionEncodeFrame(mImpl.mSession, cr, CMSampleBufferGetPresentationTimeStamp(sb), CMSampleBufferGetDuration(sb), nullptr, nullptr, &flags);
if (s) {
NSLog(@"encode status %d", (int)s);
}
// samplebuffer解放
CFRelease(sb);
});
}
原因
encoder session解放処理をエンコード処理と同じqueueで処理してなかったから。
修正
-(void)invalidateSession
{
dispatch_async(queue, ^{
if (mSession) {
VTCompressionSessionInvalidate(mSession);
}
});
}