Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement RTCPeerConnectionFactory(encoderFactory, decoderFactory) using getSupportedVideoEncoder to enable VP8 and VP9 #416

Merged
merged 7 commits into from
Oct 29, 2019
29 changes: 25 additions & 4 deletions src/iosrtcPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,38 @@ class iosrtcPlugin : CDVPlugin {
//RTCSetMinDebugLogLevel(RTCLoggingSeverity.warning)

// Create a RTCPeerConnectionFactory.
self.rtcPeerConnectionFactory = RTCPeerConnectionFactory()

self.initPeerConnectionFactory();
// Create a PluginGetUserMedia instance.
self.pluginGetUserMedia = PluginGetUserMedia(
rtcPeerConnectionFactory: rtcPeerConnectionFactory
)

// Create a PluginRTCAudioController instance.
PluginRTCAudioController.initAudioDevices()

self.audioOutputController = PluginRTCAudioController()

}

private func initPeerConnectionFactory() {
let encoderFactory = RTCDefaultVideoEncoderFactory()
let decoderFactory = RTCDefaultVideoDecoderFactory()
encoderFactory.preferredCodec = getSupportedVideoEncoder(factory: encoderFactory)

self.rtcPeerConnectionFactory = RTCPeerConnectionFactory(
encoderFactory: encoderFactory,
decoderFactory: decoderFactory
)
}

private func getSupportedVideoEncoder(factory: RTCDefaultVideoEncoderFactory) -> RTCVideoCodecInfo {
let supportedCodecs: [RTCVideoCodecInfo] = RTCDefaultVideoEncoderFactory.supportedCodecs()
if supportedCodecs.contains(RTCVideoCodecInfo.init(name: kRTCH264CodecName)){
return RTCVideoCodecInfo.init(name: kRTCH264CodecName)
} else if supportedCodecs.contains(RTCVideoCodecInfo.init(name: kRTCVp9CodecName)) {
return RTCVideoCodecInfo.init(name: kRTCVp9CodecName)
} else {
return RTCVideoCodecInfo.init(name: kRTCVp8CodecName)
}
}

@objc(onReset) override func onReset() {
Expand Down