2015-06-30 125 views
2

我試圖在基於Swift的項目中設置視頻流查看器。Swift iOS AVSampleBufferDisplayLayer設置視頻圖層

我查看以下(目標C),這非常有幫助:How AVSampleBufferDisplayLayer displays H.264

在斯威夫特方面,我有該CMTimebaseCreateWithMasterClock需要CMTimebase相關元素爲類型UnsafeMutablePointer事實難度。有人能夠解釋如何轉換爲此並返回以解決以下代碼部分中的問題。

var controlTimebase : CMTimebase 

var myAllocator : CFAllocator! 

CMTimebaseCreateWithMasterClock(myAllocator, CMClockGetHostTimeClock(), CMTimebase) 

// Problem is here...below is the expected format. 

//CMTimebaseCreateWithMasterClock(allocator: CFAllocator!, masterClock: CMClock!, timebaseOut: UnsafeMutablePointer < Unmanaged <CMTimebase> ? >) 

videoLayer.controlTimebase = controlTimebase 

回答

1

斑點在不同的上下文這裏需要UnsafeMutablePointer語法: CVPixelBufferPool Error (kCVReturnInvalidArgument/-6661)

使用以下似乎愉快地編譯:-)

  var _CMTimebasePointer = UnsafeMutablePointer<Unmanaged<CMTimebase>?>.alloc(1) 
     CMTimebaseCreateWithMasterClock(kCFAllocatorDefault, CMClockGetHostTimeClock(), _CMTimebasePointer) 
     videoLayer.controlTimebase = _CMTimebasePointer.memory?.takeUnretainedValue()