我已经使用 webrtc 流实现了屏幕共享。我使用 RPKit 进行屏幕共享。屏幕共享在 iPhone11 手机上工作,但相同的代码在 iPhone6s 手机上不工作。两部手机都有相同的 iOS 版本(iOS 13.4)。我想在每台 iOS 设备上展示它。请帮助我。请参考以下代码:
func startScreenShare() {
let screenSharefactory = self.connectionFactory
let screenShare_Stream = screenSharefactory.mediaStream(withStreamId : "videostream")
let videoCapturer = RTCVideoCapturer()
let videoSource : RTCVideoSource = screenSharefactory.videoSource()
self.captureController?.stopCapture()
self.peerConnection?.remove(stream)
RPScreenRecorder.shared().startCapture(handler: { (cmSampleBuffer, rpSampleType, error) in
switch rpSampleType {
case RPSampleBufferType.video:
// create the CVPixelBuffer
guard let pixelBuffer: CVImageBuffer = CMSampleBufferGetImageBuffer(cmSampleBuffer) else {
break
}
let rtcpixelBuffer = RTCCVPixelBuffer(pixelBuffer: pixelBuffer)
let timeStampNs: Int64 = Int64(CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(cmSampleBuffer)) * 1000000000)
let videoFrame = RTCVideoFrame(buffer: rtcpixelBuffer, rotation: RTCVideoRotation._0, timeStampNs: timeStampNs)
videoSource.capturer(videoCapturer, didCapture: videoFrame)
let screenShare_VideoTrack = screenSharefactory.videoTrack(with : videoSource, trackId : "videotrack")
screenShare_VideoTrack.isEnabled = true
screenShare_Stream.addVideoTrack(screenShare_VideoTrack)
case RPSampleBufferType.audioApp:
break
case RPSampleBufferType.audioMic:
// let audioTrack = screenSharefactory.audioTrack(withTrackId : String.random())
// audioTrack.isEnabled = true
// screenShare_Stream.addAudioTrack(audioTrack)
break
default:
print("sample has no matching type")
}
if self.peerConnection != nil
{
self.peerConnection?.add(screenShare_Stream)
}
})
}