Sil*_*ium 5 objective-c webrtc swift
我正在开发一个 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")]
}
Run Code Online (Sandbox Code Playgroud)
}
有一种名为 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)] }}
Run Code Online (Sandbox Code Playgroud)
自定义编码器的示例:
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()
}}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
373 次 |
| 最近记录: |