CMVideoFormatDescriptionGetCleanAperture() swift error

我们两清 提交于 2019-12-14 04:20:07

问题


I can't get the CMVideoFormatDescriptionGetCleanAperture() function to work. Using

var videoDescriptionRef = port.formatDescription as CMVideoFormatDescriptionRef
var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(videoDescriptionRef, true)

or

var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(port.formatDescription, true)

gives me the following errors, respectively:

Cannot convert expression's type 'CMVideoFormatDescriptionRef' to type 'CMVideoFormatDescriptionRef'

And the second is

Could not find an overlad for '__conversion' that accepts the supplied arguments

Does anyone know how to fix these or can anyone point out any errors in getting the format description for retrieving the clean aperture?


回答1:


CMFormatDescription itself does not have a member takeUnretainedValue. It is a member of Unmanaged<T>. You need to define an unmanaged variable first, get a value into it and then you retain it.

As I do not know how you created port.formatDescription, here is an example where formatDescription is created from PPS/SPS from an AVC video.

// create the receiving unmanaged variable
var formatDescription: Unmanaged<CMVideoFormatDescription>?

// call the not annotated method, this method will fill in formatDescription which is Unmanaged<T>
let result = CMVideoFormatDescriptionCreateFromH264ParameterSets(nil, UInt(parameterSets.count), parameterSets, parameterSetSizes, 4, &formatDescription)

// check result, yada yada yada before continuing

// now we can actually retain the value
let formatDescriptionRef = formatDescription!.takeUnretainedValue() as CMVideoFormatDescriptionRef

// and we can do what ever we want with it in Swift without caring anymore. 
var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(formatDescriptionRef, 1)
  1. Create an unmanaged type
  2. Use this unmanaged type in an not annotated method
  3. Retain the value
  4. Work with it without thinking about how you created it.

So adjust your code where you create the port.formatDescription as a Unmanaged and you should be good.




回答2:


Try to use .takeUnretainedValue() like this:

var videoDescription : CMVideoFormatDescription = port.formatDescription.takeUnretainedValue()
var cleanAperture = CMVideoFormatDescriptionGetCleanAperture(videoDescription, true)


来源:https://stackoverflow.com/questions/24395265/cmvideoformatdescriptiongetcleanaperture-swift-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!