Bug 1208371 - Don't dispatch conduit destruction to main thread when not needed. r?bwc
In case MediaPipeline gets destructed on main thread we cannot dispatch
to main thread. In this case, destroy the conduits directly.
The easiest way to test this that I have found is to shut Firefox down
in the middle of a PeerConnection mochitest, when the PeerConnection is
still active.
MozReview-Commit-ID: 3gLhtIKTkx1
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -446,16 +446,23 @@ public:
#if !defined(MOZILLA_EXTERNAL_LINKAGE)
, last_img_(-1)
#endif // MOZILLA_INTERNAL_API
{
}
~PipelineListener()
{
+ if (NS_IsMainThread()) {
+ // This would happen if the cycle collector is destructing us, in which
+ // case it'd be too late to dispatch something to main thread anyway.
+ conduit_ = nullptr;
+ return;
+ }
+
// release conduit on mainthread. Must use forget()!
nsresult rv = NS_DispatchToMainThread(new
ConduitDeleteEvent(conduit_.forget()));
MOZ_ASSERT(!NS_FAILED(rv),"Could not dispatch conduit shutdown to main");
if (NS_FAILED(rv)) {
MOZ_CRASH();
}
}
@@ -608,16 +615,23 @@ class MediaPipelineReceiveAudio : public
class PipelineListener : public GenericReceiveListener {
public:
PipelineListener(SourceMediaStream * source, TrackID track_id,
const RefPtr<MediaSessionConduit>& conduit,
bool queue_track);
~PipelineListener()
{
+ if (NS_IsMainThread()) {
+ // This would happen if the cycle collector is destructing us, in which
+ // case it'd be too late to dispatch something to main thread anyway.
+ conduit_ = nullptr;
+ return;
+ }
+
// release conduit on mainthread. Must use forget()!
nsresult rv = NS_DispatchToMainThread(new
ConduitDeleteEvent(conduit_.forget()));
MOZ_ASSERT(!NS_FAILED(rv),"Could not dispatch conduit shutdown to main");
if (NS_FAILED(rv)) {
MOZ_CRASH();
}
}