背景
视频播放中,使用VideoToolBox进行硬解码,再使用OpenGL进行渲染。
使用了AVSampleBufferDisplayLayer和VideoToolBox两种方式。前者解码无需我们关心,只需要传入CMSampleBufferRef即可,后者需要自行解码。
对于AVSampleBufferDisplayLayer会设置kCMSampleAttachmentKey_DisplayImmediately
CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, YES);
CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, 0);
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
这段代码在使用VideoToolBox解码时,会在CMSampleBufferGetSampleAttachmentsArray阻塞。导致解码线程无法加入新的任务。