WebRTC icon indicating copy to clipboard operation
WebRTC copied to clipboard

macOS version crashes after a few seconds of sending video frames

Open ldenoue opened this issue 2 years ago • 12 comments

image

I am using a custom video capturer that creates RTCVideoFrame(s) from a CGImage converted to a CVPixelBuffer (to initialize the RTCVideoFrame):

func processSampleBuffer(_ pixelBuffer: CVPixelBuffer) {
        let rtcpixelBuffer = RTCCVPixelBuffer(pixelBuffer: pixelBuffer)
        let timeStampSeconds = CACurrentMediaTime()
        let timeStampNs = lroundf(Float(timeStampSeconds * Double(NSEC_PER_SEC)))
        let videoFrame = RTCVideoFrame(buffer: rtcpixelBuffer, rotation: RTCVideoRotation._0, timeStampNs: Int64(timeStampNs))
        if let videoCapturer = videoCapturer {
            videoCapturer.delegate?.capturer(videoCapturer, didCapture: videoFrame)
        }
    }

After a few seconds (might happen when the video resolution changes to 640x360) but not sure, then I get this crash (hard to debug for me).

Any idea? By the way, a very similar code works great using your iOS demo sample. Do you have a macOS version of that sample?

Laurent

ldenoue avatar Jun 08 '22 15:06 ldenoue

Follow up: if I limit my frame sizes I send to max 540 pixels (in either width or height), then it runs fine. Have others seen issues? Do you know if we can force h264 to be used by the encoder to make sure it's using the GPU?

ldenoue avatar Jun 08 '22 16:06 ldenoue

More info: specifying "VP8" (or "VP9") as the preferred encoder solves the issue. Not sure why H264 fails on MacOS.

private static let factory: RTCPeerConnectionFactory = {
        RTCInitializeSSL()
        // from https://stackoverflow.com/questions/66198164/how-to-enable-vp8-on-ios-webrtc
        let videoEncoderFactory = RTCDefaultVideoEncoderFactory()
        for codec in videoEncoderFactory.supportedCodecs() {
           print(codec.name)
           print(codec.parameters)
        }
        videoEncoderFactory.preferredCodec = RTCVideoCodecInfo(name: "VP8")
        //videoEncoderFactory.preferredCodec = RTCVideoCodecInfo(name: "H264", parameters: ["profile-level-id" : "42e01f"])
        let videoDecoderFactory = RTCDefaultVideoDecoderFactory()
        return RTCPeerConnectionFactory(encoderFactory: videoEncoderFactory, decoderFactory: videoDecoderFactory)
    }()

ldenoue avatar Jun 08 '22 18:06 ldenoue

@ldenoue I've been using version M96 on a production app for a few months with H264 with no issues (on iOS however)... until a few weeks ago where the H264 encoder started to fail. By using VP8, we were able to push a new working version while trying to understand the problem with H264. On our part, it seems to coincide with the release of iOS 15.5. Which version of macOS are you using ? The latest ? I was hoping that the latest version of webRTC fixes this issue but haven't succeeded (yet) in compiling it for iOS. @stasel is working on having this new version (M102) available, I believe (https://github.com/stasel/WebRTC/issues/36).

anthonynevo avatar Jun 14 '22 07:06 anthonynevo

@anthonynevo I'm on macOS Monterey 12.4 (21F79) and iOS 15.4.1 (on iOS H264 works).

ldenoue avatar Jun 14 '22 08:06 ldenoue

Can you try to reproduce the issue on the latest WebRTC version M103? Maybe it was fixed by the WebRTC folks

stasel avatar Jun 22 '22 21:06 stasel

I updated my package to use the latest 103.0.0 but it still does not work unless I explicitly specify VP8 in videoEncoderFactory.preferredCodec = RTCVideoCodecInfo(name: "VP8")

ldenoue avatar Jun 23 '22 09:06 ldenoue

Im having exactly the same problem w/ M103... crash in h264 encode on macOS, same app working fine on iOS. The backtrace is very similar

it appears to be a message send to a zombie object. running with zombies enabled seems to confirm:

2022-07-28 00:52:24.429719-0700 video-eo-eo[9790:191435] *** -[Not A Type _cfTypeID]: message sent to deallocated instance 0x1178732c0

mikewoodworth avatar Jul 28 '22 07:07 mikewoodworth

Still reproduce, even set VP8 doesn't help.

zSoNz avatar Oct 24 '22 13:10 zSoNz

I have a fix, trying to figure out how to submit to webrtc now, if anyone is interested in building from source I can send a diff

mikewoodworth avatar Oct 24 '22 15:10 mikewoodworth

I have a fix, trying to figure out how to submit to webrtc now, if anyone is interested in building from source I can send a diff

Yes please 😩

zSoNz avatar Oct 24 '22 16:10 zSoNz

videoEncoderFactory.preferredCodec = RTCVideoCodecInfo(name: "VP8")

any updates?

I have a fix, trying to figure out how to submit to webrtc now, if anyone is interested in building from source I can send a diff

can u send?

danilaplee avatar Nov 27 '22 15:11 danilaplee

my bug report is here, the fix is submitted, you can fine it linked in the comments. hopefully it will land soon. https://bugs.chromium.org/p/webrtc/issues/detail?id=14688

mikewoodworth avatar Dec 08 '22 10:12 mikewoodworth