1

I have a problem like in this question: Why AVSampleBufferDisplayLayer stops showing CMSampleBuffers taken from AVCaptureVideoDataOutput's delegate?

And tried advice from this question.

But when I pasted this code:

let attachments: CFArray = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true)!;

    print(CFArrayGetCount(attachments)) // printing 1

    let dict = CFArrayGetValueAtIndex(attachments, 0) as! CFMutableDictionary;

    CFDictionarySetValue(dict,
                         unsafeBitCast(kCMSampleAttachmentKey_DisplayImmediately, to: UnsafeRawPointer.self),
                         unsafeBitCast(kCFBooleanTrue, to: UnsafeRawPointer.self));

App crashes while casting to CFMutableDictionary.

What am I doing wrong?

Community
  • 1
  • 1
  • Don't use CFArray/CFDictionary in Swift. CFArray is toll-free bridged to NSArray, which can be bridged to a Swift Array. – Martin R Apr 28 '17 at 17:21
  • @MartinR But if he really wanted to do it, he could use your answer at http://stackoverflow.com/a/33310021/341994, right? – matt Apr 28 '17 at 17:21
  • Btw, this looks quite similar: http://stackoverflow.com/questions/40780419/how-to-use-cfdictionarysetvalue-in-swift. – Martin R Apr 28 '17 at 17:22
  • By the way, @MartinR, I have an example of using your technique with CFDictionary, just to prove it can be done (though no one in his right mind would ever do it): https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch23p829imageIO/ch36p1084imageIO/ViewController.swift – matt Apr 28 '17 at 17:27
  • @matt: `unsafeBitCast(obj, to: UnsafeRawPointer.self)` as in this question should work as well for *objects*. My guess is that the above code crashes because a *boolean* is forcefully converted to a pointer. – Martin R Apr 28 '17 at 17:33
  • @Евгения: Doesn't this http://stackoverflow.com/a/40780970/1187415 do exactly what you want? – Martin R Apr 28 '17 at 17:39
  • @MartinR Yes, thanks, it solved this problem, but initial problem is still not solved :( – Evgeniya Tveritinova Apr 28 '17 at 18:21
  • Here's solution: http://stackoverflow.com/questions/43687169/ios-ignoring-enqueuesamplebuffer-because-status-is-failed – Evgeniya Tveritinova May 06 '17 at 20:11

0 Answers0