【问题标题】:Using WebRTC to send an iOS devices’ screen capture using ReplayKit使用 WebRTC 通过 ReplayKit 发送 iOS 设备的屏幕截图
【发布时间】:2018-05-10 07:08:44
【问题描述】:

我们想通过 WebRTC 使用 ReplayKit 发送 iOS 设备的屏幕截图。 ReplayKit 有一个 processSampleBuffer 回调,它提供 CMSampleBuffer。

但这就是我们卡住的地方,我们似乎无法将 CMSampleBuffer 发送到连接的对等方。 我们尝试从 sampleBuffer 中创建 pixelBuffer,然后创建 RTCVideoFrame。

我们还从 RTCPeerConnectionFactory 中提取了 RTCVideoSource,然后使用 RTCVideoCapturer 并将其流式传输到 localVideoSource。

知道我们做错了什么吗?

var peerConnectionFactory: RTCPeerConnectionFactory?

override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
 switch sampleBufferType {
           case RPSampleBufferType.video:

        // create the CVPixelBuffer
        let pixelBuffer:CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!;

        // create the RTCVideoFrame
        var videoFrame:RTCVideoFrame?;
        let timestamp = NSDate().timeIntervalSince1970 * 1000
        videoFrame = RTCVideoFrame(pixelBuffer: pixelBuffer, rotation: RTCVideoRotation._0, timeStampNs: Int64(timestamp))

        // connect the video frames to the WebRTC
        let localVideoSource = self.peerConnectionFactory!.videoSource()
        let videoCapturer = RTCVideoCapturer()
        localVideoSource.capturer(videoCapturer, didCapture: videoFrame!)

        let videoTrack : RTCVideoTrack =   self.peerConnectionFactory!.videoTrack(with: localVideoSource, trackId: "100”)

        let mediaStream: RTCMediaStream = (self.peerConnectionFactory?.mediaStream(withStreamId: “1"))!
        mediaStream.addVideoTrack(videoTrack)
        self.newPeerConnection!.add(mediaStream)

        break
    }
}

【问题讨论】:

  • 到目前为止你找到解决办法了吗

标签: ios webrtc screensharing replaykit apprtc


【解决方案1】:

这是一个实现的好主意,您只需在 sn-p 中使用的方法中渲染 RTCVideoFrame,所有其他对象将初始化超大方法,这是最好的方法.为了更好地理解,我给你一个sn-p。

    var peerConnectionFactory: RTCPeerConnectionFactory?
    var localVideoSource: RTCVideoSource?
    var videoCapturer: RTCVideoCapturer?
    func setupVideoCapturer(){
          // localVideoSource and videoCapturer will use 
            localVideoSource = self.peerConnectionFactory!.videoSource() 
            videoCapturer = RTCVideoCapturer()
    //      localVideoSource.capturer(videoCapturer, didCapture: videoFrame!)

            let videoTrack : RTCVideoTrack =   self.peerConnectionFactory!.videoTrack(with: localVideoSource, trackId: "100”)

            let mediaStream: RTCMediaStream = (self.peerConnectionFactory?.mediaStream(withStreamId: “1"))!
            mediaStream.addVideoTrack(videoTrack)
            self.newPeerConnection!.add(mediaStream)
        }


 override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
     switch sampleBufferType {
               case RPSampleBufferType.video:

            // create the CVPixelBuffer
            let pixelBuffer:CVPixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!;

            // create the RTCVideoFrame
            var videoFrame:RTCVideoFrame?;
            let timestamp = NSDate().timeIntervalSince1970 * 1000
            videoFrame = RTCVideoFrame(pixelBuffer: pixelBuffer, rotation: RTCVideoRotation._0, timeStampNs: Int64(timestamp))
            // connect the video frames to the WebRTC
            localVideoSource.capturer(videoCapturer, didCapture: videoFrame!)

            break
        }
    }

希望这会对你有所帮助。

【讨论】:

  • 音频怎么样? RTCVideoTrack 仅适用于视频样本。谁能帮我解决音频 sn-p 问题?
  • 我试过了,但是我检查了我们不能用现有的框架来做。我们可以通过使用源代码自定义 SDK 来实现这一点。我就是用这种方式做到的。
  • 你能指导我的步骤吗?如果你能分享 webrtc.framework 和一个像上面这样的 sn-p 音频,那将是很大的帮助!可能会回答我的问题stackoverflow.com/questions/54470143/…
  • 嗨,Sumit,如果可能的话,你能回答一下步骤吗?
  • 我尝试了同样的方法,但我没有收到网络上的视频。您能否分享您的方法@sumitmeena @replies?非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-16
  • 1970-01-01
  • 2011-05-04
  • 1970-01-01
相关资源
最近更新 更多