我正在尝试在基于Swift的项目中设置视频流查看器。
我已经回顾了以下(目标C),它非常有帮助:How AVSampleBufferDisplayLayer displays H.264
在Swift上下文中,我很难解决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
答案 0 :(得分:1)
在这里发现了不同上下文中所需的UnsafeMutablePointer语法: CVPixelBufferPool Error ( kCVReturnInvalidArgument/-6661)
使用以下内容似乎可以愉快地编译: - )
var _CMTimebasePointer = UnsafeMutablePointer<Unmanaged<CMTimebase>?>.alloc(1)
CMTimebaseCreateWithMasterClock( kCFAllocatorDefault, CMClockGetHostTimeClock(), _CMTimebasePointer )
videoLayer.controlTimebase = _CMTimebasePointer.memory?.takeUnretainedValue()
答案 1 :(得分:0)
let cmTimebasePointer = UnsafeMutablePointer<CMTimebase?>.allocate(capacity: 1)
let status = CMTimebaseCreateWithMasterClock(allocator: kCFAllocatorDefault, masterClock: CMClockGetHostTimeClock(), timebaseOut: cmTimebasePointer)
videoLayer.controlTimebase = cmTimebasePointer.pointee
if let controlTimeBase = videoLayer.controlTimebase, status == noErr {
CMTimebaseSetTime(controlTimeBase, time: CMTime.zero)
CMTimebaseSetRate(controlTimeBase, rate: 1)
}