Closed Bug 1047442 Opened 10 years ago Closed 10 years ago

Locking assumption in webrtc.org Encoded() callback invalid with async codecs

Categories

(Core :: WebRTC: Audio/Video, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34
Tracking Status
firefox32 --- wontfix
firefox33 --- fixed
firefox34 --- fixed
b2g-v2.0 --- fixed
b2g-v2.1 --- fixed

People

(Reporter: jesup, Assigned: jesup)

References

(Blocks 1 open bug)

Details

(Keywords: crash)

Attachments

(2 files)

The webrtc.org code for encoding via video_sender.cc/AddFrame and generic_encoder assumes that the Encoded() callback will happen from *within* the Encode() call (i.e. with the video_sender's _sendCritSect locked). This is invalid for any codec that calls Encoded() asynchronously, such as GMP codecs. This causes on windows (if IPC issues are bypassed) crashes (rarely; minutes or many minutes into a call) in media_optimization from within Encoded().
This works (4 hours in Linux and Win32 no crashes) but I prefer to find a solution that avoids the Sync dispatch, and so avoids adding threads
Note: the dangerous deadlock here leading to the extra thread is that the caller to Encode() holds the _sendCritSect, and if GMPThread is in Encoded() and tries to grab _sendCritSect it will stall, and thus never service the sender's Encode() runnable. The obvious solution to avoiding an extra thread (not having the Encode() call block on GMPThread) means we need to transfer the frame-to-be-encoded to a shared-mem-backed-i420 frame, and send that to GMPThread asynchronously. This fails since we can't allocate Shmems for use with GMP except on, you guessed it, GMPThread! We can't even ask GMPThread for some, since it may not be servicing requests. Grrr. Perhaps more work in the caller could relax the restriction somehow. I don't seem to be able to drop the critsect before calling Encode() safely (tried that)
Attachment #8466234 - Flags: review?(pkerr)
Attachment #8466235 - Flags: review?(pkerr)
Attachment #8466235 - Flags: review?(pkerr) → review+
Attachment #8466234 - Flags: review?(pkerr) → review+
Comment on attachment 8466234 [details] [diff] [review] reacquire _sendCritSect within webrtc Encoded() callback (upstream patch) For both patches: Approval Request Comment [Feature/regressing bug #]: openh264/GMP [User impact if declined]: random crashes (especially on windows) and UAFs [Describe test coverage new/current, TBPL]: Thread-order issues can't generally be tested in tbpl, and this may require long calls to hit (5-20 minutes). On nightly for some time now; tested in multiple 6-hour-plus calls on Windows. [Risks and why]: moderately low risk; we're modifying locking code, but the locking required is fairly clear. The additional thread is annoying, but needed to avoid deadlocks. [String/UUID change made/needed]: none.
Attachment #8466234 - Flags: approval-mozilla-aurora?
Attachment #8466235 - Flags: approval-mozilla-aurora?
Attachment #8466234 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Attachment #8466235 - Flags: approval-mozilla-aurora? → approval-mozilla-aurora+
Comment on attachment 8466234 [details] [diff] [review] reacquire _sendCritSect within webrtc Encoded() callback (upstream patch) Review of attachment 8466234 [details] [diff] [review]: ----------------------------------------------------------------- While we haven't identified a guaranteed regression yet, 2.0 OMX encoders appear to have the same problem (since we call Encoded() on another thread).
Attachment #8466234 - Flags: approval-mozilla-b2g32?
Randell, I was trying to cherry pick these patches to the FFOS v2.0 branch to see if they fix bug 1052169. They don't apply cleanly. Can I get your help by rebasing them? I can try it myself but maybe it'll be trivial for you.
Flags: needinfo?(rjesup)
Attachment #8466234 - Flags: approval-mozilla-b2g32? → approval-mozilla-b2g32+
(In reply to Diego Wilson [:diego] from comment #10) > Randell, > > I was trying to cherry pick these patches to the FFOS v2.0 branch to see if > they fix bug 1052169. They don't apply cleanly. Can I get your help by > rebasing them? > > I can try it myself but maybe it'll be trivial for you. spoke offline with :jesup, diego was able to apply the patch cleanly, we're now waiting for results to confirm this fixes report in 1052169
Flags: needinfo?(rjesup)
Whiteboard: [webrtc-uplift]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: