gpt4 book ai didi

objective-c - WebRTC:如何将 RTCVideoEncoderSettings 传递到 RTCVideoEncoder

转载 作者:行者123 更新时间:2023-12-02 04:26:43 25 4
gpt4 key购买 nike

我正在开发一个 webrtc 屏幕共享应用程序。因此我正在使用objective-c webrtc 框架。

现在我在如何传递 RTCVideoEncoderSettings ( http://cocoadocs.org/docsets/GoogleWebRTC/1.1.20266/Classes/RTCVideoEncoderSettings.html ) 方面遇到问题
到编码器 (VP9)。这是我目前拥有的:

public class CustomVideoEncoderFactory : NSObject, RTCVideoEncoderFactory {

var encoder: RTCVideoEncoder?
var preferredCodec: RTCVideoCodecInfo = RTCVideoCodecInfo(name: "VP9")

public func createEncoder(_ info: RTCVideoCodecInfo) -> RTCVideoEncoder? {

let vp9Encoder = RTCVideoEncoderVP9.vp9Encoder()!
// How to pass the RTCVideoEncoderSettings into this encoder???
return vp9Encoder
}

public func supportedCodecs() -> [RTCVideoCodecInfo] {
return [RTCVideoCodecInfo(name: "VP9")]
}

}

有一个方法叫做 startEncodeWithSettings ( http://cocoadocs.org/docsets/GoogleWebRTC/1.1.20266/Protocols/RTCVideoEncoder.html )
但我不确定如何将其与我当前的代码集成。我试图子类化 ( public class CustomVideoEncoder: NSObject, RTCVideoEncoder { ... } ) 没有用。

感谢您的帮助!

最佳答案

好的,我找到了解决方案。事实证明,对于 VP9 和 VP8,缺少 Objective-c 包装。 VP9 和 Vp8 直接链接到原生实现!
因此,如果您使用的是 h264,则只能进行子类化。
要更改 VP9 和 VP8 上的设置,需要修改 C++ 代码中的设置!

自定义编码器工厂的示例:

public class CustomVideoEncoderFactory : NSObject, RTCVideoEncoderFactory {

public func createEncoder(_ info: RTCVideoCodecInfo) -> RTCVideoEncoder? {

let encoder = super.createEncoder(info) // will create the h264 encoder
let customEncoder = CustomVideoEncoder()
self.encoder = customEncoder
return encoder
}

public func supportedCodecs() -> [RTCVideoCodecInfo] {

return [RTCVideoCodecInfo(name: kRTCVideoCodecH264Name)] }}

自定义编码器示例:
public class CustomVideoEncoder: NSObject, RTCVideoEncoder {

public var encoder: RTCVideoEncoder? // ONLY WORKS WITH h264

public func setCallback(_ callback: @escaping RTCVideoEncoderCallback) {

return encoder!.setCallback(callback)
}

public func startEncode(with settings: RTCVideoEncoderSettings, numberOfCores: Int32) -> Int {

// Change settings here !
let res = encoder!.startEncode(with: settings, numberOfCores: numberOfCores)
}

public func release() -> Int {

return encoder!.release()
}

public func encode(_ frame: RTCVideoFrame, codecSpecificInfo info: RTCCodecSpecificInfo?, frameTypes: [NSNumber]) -> Int {

return encoder!.encode(frame, codecSpecificInfo: info, frameTypes: frameTypes)
}

public func setBitrate(_ bitrateKbit: UInt32, framerate: UInt32) -> Int32 {

return encoder!.setBitrate(bitrateKbit, framerate: framerate)
}

public func implementationName() -> String {

return encoder!.implementationName()
}

public func scalingSettings() -> RTCVideoEncoderQpThresholds? {

return encoder!.scalingSettings()
}}

关于objective-c - WebRTC:如何将 RTCVideoEncoderSettings 传递到 RTCVideoEncoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61426109/

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