设置 CMSampleBuffer 示例附件 (Swift)
Set CMSampleBuffer samples attachment (Swift)
我正在尝试为 CMSampleBuffer
中的每个示例设置 kCMSampleAttachmentKey_DisplayImmediately
。
到目前为止,我已经尝试获取字典(Dictionary<NSObject, AnyObject>
、NSDictionary
、CFDictionary
),并在 CMSampleBuffer
及其附件上调用了 CMSetAttachment
.
我使用 CMSampleBufferGetSampleAttachmentsArray
.
来检索附件
知道如何在 Swift 中设置这些标志吗?
这是适用于 Swift 4(应该适用于 3)的解决方案(可能远非完美)。
func setSampleBufferAttachments(_ sampleBuffer: CMSampleBuffer) {
let attachments: CFArray! = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true)
let dictionary = unsafeBitCast(CFArrayGetValueAtIndex(attachments, 0),
to: CFMutableDictionary.self)
let key = Unmanaged.passUnretained(kCMSampleAttachmentKey_DisplayImmediately).toOpaque()
let value = Unmanaged.passUnretained(kCFBooleanTrue).toOpaque()
CFDictionarySetValue(dictionary, key, value)
}
我正在尝试为 CMSampleBuffer
中的每个示例设置 kCMSampleAttachmentKey_DisplayImmediately
。
到目前为止,我已经尝试获取字典(Dictionary<NSObject, AnyObject>
、NSDictionary
、CFDictionary
),并在 CMSampleBuffer
及其附件上调用了 CMSetAttachment
.
我使用 CMSampleBufferGetSampleAttachmentsArray
.
知道如何在 Swift 中设置这些标志吗?
这是适用于 Swift 4(应该适用于 3)的解决方案(可能远非完美)。
func setSampleBufferAttachments(_ sampleBuffer: CMSampleBuffer) {
let attachments: CFArray! = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true)
let dictionary = unsafeBitCast(CFArrayGetValueAtIndex(attachments, 0),
to: CFMutableDictionary.self)
let key = Unmanaged.passUnretained(kCMSampleAttachmentKey_DisplayImmediately).toOpaque()
let value = Unmanaged.passUnretained(kCFBooleanTrue).toOpaque()
CFDictionarySetValue(dictionary, key, value)
}