gpt4 book ai didi

ios - CMVideoFormatDescriptionCreateFromH264ParameterSets抛出“UnsafePointer ”的初始化会导致指针悬空

转载 作者:行者123 更新时间:2023-12-01 18:34:59 25 4
gpt4 key购买 nike

所以以前我打开了Initialization of 'UnsafePointer<Int>' results in a dangling pointer,但是mods说它是重复的。

但是我不认为这是重复的,因为在那篇文章中引用的链接不能轻易地指向解决方案。因此,我必须在3天后重新开一个。我尝试了上一篇文章中@bscothern的回答,但是出现了更多错误。

当前正在使用的代码类似于@bscothern的以下代码,但仍会抛出

无法推断通用参数“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
}

来自先前帖子的原始问题:

所以我有一些代码来创建H264ParameterSets:
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
    }

    关于ios - CMVideoFormatDescriptionCreateFromH264ParameterSets抛出“UnsafePointer <Int>”的初始化会导致指针悬空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61313993/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com