perchco / perchrtc

An iOS WebRTC demo using XirSys servers
MIT License
135 stars 34 forks source link

PHVideoCaptureBridge: Submit frames on WebRTC thread #12

Closed ikonst closed 9 years ago

ikonst commented 9 years ago

Thread affinity checks were introduced in: https://chromium.googlesource.com/external/webrtc/+/e07710cc91b3dccd7fea7df3d99c304f419babda so we can no longer submit frames from the AVFoundation thread.

In debug builds, it will result in an assertion. It’s a shame we have to fling things between threads, since AVFoundation already does all the queueing for us, but such is life.

This fix was essentially lifted from: talk/app/webrtc/objc/avfoundationvideocapturer.mm

ceaglest commented 9 years ago

@ikonst Thanks very much for this fix! It is definitely a shame to have to bounce incoming frames over to the capturer's WebRTC thread, but it sounds like you are correct. This is what I get for not testing against a debug build for r8444.

Assigning myself as the reviewer.

ceaglest commented 9 years ago

@ikonst I reviewed the fix, and everything appears to be in order. Initially, I was concerned about thread safety with the capturer's temporary conversion buffer, but then realized that rtc::Thread's Invoke method is synchronous.

Ideally, once WebRTC supports passing wrapped CVPixelBufferRefs to the downstream components it would be as simple as retaining the buffer and asynchronously notifying the capturer thread rather than blocking here.