不支持的 IOSurface 格式:0x26424741 在 scenekit 中使用 twilio 视频

Unsupported IOSurface format: 0x26424741 using twilio video in scenekit

我正在使用 twilio 发送视频并在场景包中将该视频用作纹理。但问题是它在 iPhone X 上工作正常,但它在 iPhone XR 和 XS 上给出了这个错误 Unsupported IOSurface format: 0x26424741

这就是我正在做的事情:

获取视频:

func subscribed(to videoTrack: TVIRemoteVideoTrack, publication: TVIRemoteVideoTrackPublication, for participant: TVIRemoteParticipant) {
    print("Participant \(participant.identity) added a video track.")
    let remoteView = TVIVideoView.init(frame: UIWindow().frame,
                                       delegate:self)
    videoTrack.addRenderer(remoteView!)
    delegate.participantAdded(with: remoteView!)
}

代表:

func participantAdded(with videoView: UIView) {
    sceneView.addVideo(with: videoView)
}

并将视频添加到平面:

func addVideo(with view: UIView){
    videoPlane.geometry?.firstMaterial?.diffuse.contents = view
}

问题实际上出在 remoteViewrenderingType 上。对于较旧的设备,使用 metal 很好,但较新的设备需要 openGLES。我不知道为什么,但这是解决办法。

I used this solution to find out the device type.

接下来我决定使用哪个renderingType

var renderingType: VideoView.RenderingType {
    get{
        let device = UIDevice()
        switch device.type{
        case .iPhoneXS:
            return .openGLES
        case .iPhoneXR:
            return .openGLES
        case .iPhoneXSMax:
            return .openGLES
        default:
            return .metal
        }
    }
}

并用它来初始化 remoteView

func didSubscribeToVideoTrack(videoTrack: RemoteVideoTrack, publication: RemoteVideoTrackPublication, participant: RemoteParticipant) {
    print("Participant \(participant.identity) added a video track.")
    let remoteView = VideoView.init(frame: UIWindow().frame,
                                    delegate:self,
                                    renderingType: renderingType)
    videoTrack.addRenderer(remoteView!)
    delegate.participantAddedVideo(for: participant.identity, with: remoteView!)
}