CMVideo格式描述创建从H264参数集抛出初始化'UnsafePointer<Int>'结果悬空指针



所以之前我打开了';UnsafePointer<Int>#39;结果是一个悬空的指针,但mods说这是一个重复的指针。

然而,我不认为这是一个重复的问题,因为那篇文章中提到的链接不容易指向解决方案。因此,我必须在3天后打开一个新的。我在上一篇文章中尝试了@bsothern的回答,但更多的错误出现了。

目前使用的代码如下所示,来自@bsothern,它仍然抛出

无法推断出通用参数"R">

var formatDesc: CMVideoFormatDescription?
func createH264FormatDescription(SPS: Array<UInt8>, PPS: Array<UInt8>) -> OSStatus {
if formatDesc != nil { formatDesc = nil }
let status = SPS.withUnsafeBufferPointer { SPS in
PPS.withUnsafeBufferPointer { PPS in
let paramSet = [SPS.baseAddress!, PPS.baseAddress!]
let paramSizes = [SPS.count, PPS.count]
return paramSet.withUnsafeBufferPointer { paramSet in
paramSizes.withUnsafeBufferPointer { paramSizes in
CMVideoFormatDescriptionCreateFromH264ParameterSets(allocator: kCFAllocatorDefault, parameterSetCount: 2, parameterSetPointers: paramSet.baseAddress!, parameterSetSizes: paramSizes.baseAddress!, nalUnitHeaderLength: 4, formatDescriptionOut: &formatDesc)
}
}
}
}
return status
}

上一篇文章的原始问题:

所以我有一些代码来创建H264ParameterSet,比如:

var formatDesc: CMVideoFormatDescription?
func createH264FormatDescription(SPS: Array<UInt8>, PPS: Array<UInt8>) -> OSStatus {
if formatDesc != nil { formatDesc = nil }
let paramSet = [UnsafePointer<UInt8>(SPS), UnsafePointer<UInt8>(PPS)]
let paramPointers = UnsafePointer<UnsafePointer<UInt8>>(paramSet)
let paramSizes = UnsafePointer<Int>([SPS.count, PPS.count])
let status = CMVideoFormatDescriptionCreateFromH264ParameterSets(allocator: kCFAllocatorDefault, parameterSetCount: 2, parameterSetPointers: paramPointers, parameterSetSizes: paramSizes, nalUnitHeaderLength: 4, formatDescriptionOut: &formatDesc)
return status
}

从Xcode 11.4开始,我收到了UnsafePointer((的警告,这在以前似乎没有发生过:

Initialization of UnsafePointer<UInt8> results in a dangling pointer
Initialization of UnsafePointer<UnsafePointer<UInt8>> results in a dangling pointer
Initialization of UnsafePointer<Int> results in a dangling pointer

我不知道我们为什么看到这个?如何删除警告?提前感谢。

当您发现一些错误消息,如:Generic parameter 'R' could not be inferred时,可能有两个原因。

  • 某个地方存在一些与类型相关的错误,因此Swift无法推断出该上下文中的实际类型R
  • 这个表达式比Swift推断的类型要复杂一点

在情况1中,您需要找到导致问题的实际错误所在。

在案例2中,您可以添加一些显式的类型注释来帮助Swift推断类型。

请试试这样的东西:

var formatDesc: CMVideoFormatDescription?
func createH264FormatDescription(SPS sps: Array<UInt8>, PPS pps: Array<UInt8>) -> OSStatus {
if formatDesc != nil { formatDesc = nil }
let status = sps.withUnsafeBufferPointer { spsBP->OSStatus in //<- Specify return type explicitly.
pps.withUnsafeBufferPointer { ppsBP in
let paramSet = [spsBP.baseAddress!, ppsBP.baseAddress!]
let paramSizes = [spsBP.count, ppsBP.count]
return paramSet.withUnsafeBufferPointer { paramSetBP in
paramSizes.withUnsafeBufferPointer { paramSizesBP in
CMVideoFormatDescriptionCreateFromH264ParameterSets(allocator: kCFAllocatorDefault, parameterSetCount: 2, parameterSetPointers: paramSetBP.baseAddress!, parameterSetSizes: paramSizesBP.baseAddress!, nalUnitHeaderLength: 4, formatDescriptionOut: &formatDesc)
}
}
}
}
return status
}

相关内容

  • 没有找到相关文章

最新更新