1

我在我的应用程序中使用 Replay Kit 2(广播上传扩展)进行屏幕共享。

它在 iPhone 上运行良好,但几秒钟后出现错误,因为当我在 iPAD 上运行它时,它超过了 50 MB 的内存限制。

问题是因为 iPAD 的分辨率很高。由于服务器端的限制,我也必须使用 vp8,所以不能使用 H264。

在将 CMSampleBuffer 发送到服务器之前,我尝试将其分辨率最小化,但内存仍然以相同的速度增加并停止。

   func didCapture(_ sampleBuffer: CMSampleBuffer){

   if CMSampleBufferGetNumSamples(sampleBuffer) != 1 || 
   !CMSampleBufferIsValid(sampleBuffer) || 
      !CMSampleBufferDataIsReady(sampleBuffer) {
        return
     }

    let rtcPixelBuffer = RTCCVPixelBuffer(pixelBuffer: pixelBuffer)
    rtcPixelBuffer.toI420()

  //  let value = rtcPixelBuffer.cropAndScale(to: CVPixelBuffer, withTempBuffer: <#T##UnsafeMutablePointer<UInt8>#>)

    let timeStampNs = Int64(CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) * Double(NSEC_PER_SEC))
    let videoFrame = RTCVideoFrame(buffer: rtcPixelBuffer , rotation: ._0, timeStampNs: timeStampNs)

    delegate?.capturer(self, didCapture: videoFrame)

}

4

0 回答 0