Define CMSampleBuffer (Swift) sample attachment

I am trying to install kCMSampleAttachmentKey_DisplayImmediatelyfor each of my samples in CMSampleBuffer.

So far I have tried to get dictionaries ( Dictionary<NSObject, AnyObject>, NSDictionary, CFDictionary), and called CMSetAttachmentas CMSampleBufferwell as on investments.

For receiving attachments I use CMSampleBufferGetSampleAttachmentsArray.

Any ideas how I can set these flags in Swift?

+4
source share
1 answer

Here's a solution (possibly far from perfect) that works with Swift 4 (should work with 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)
}
+1
source

All Articles