Bug 1404997 - P22. Make mConduit release on main thread consistent. r?pehrsons
There's no need for a custom class to perform this task.
MozReview-Commit-ID: JxpDQVM97fl
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.cpp
@@ -627,19 +627,18 @@ MediaPipeline::MediaPipeline(const std::
} else {
mConduit->SetTransmitterTransport(mTransport);
}
}
MediaPipeline::~MediaPipeline()
{
CSFLogInfo(LOGTAG, "Destroying MediaPipeline: %s", mDescription.c_str());
- // MediaSessionConduit insists that it be released on main.
- RUN_ON_THREAD(
- mMainThread, WrapRelease(mConduit.forget()), NS_DISPATCH_NORMAL);
+ NS_ReleaseOnMainThreadSystemGroup("MediaPipeline::mConduit",
+ mConduit.forget());
}
void
MediaPipeline::Shutdown_m()
{
CSFLogInfo(LOGTAG, "%s in %s", mDescription.c_str(), __FUNCTION__);
Stop();
@@ -1330,27 +1329,18 @@ public:
, mActive(false)
, mEnabled(false)
, mDirectConnect(false)
{
}
~PipelineListener()
{
- if (!NS_IsMainThread()) {
- // release conduit on mainthread. Must use forget()!
- nsresult rv =
- NS_DispatchToMainThread(new ConduitDeleteEvent(mConduit.forget()));
- MOZ_ASSERT(!NS_FAILED(rv), "Could not dispatch conduit shutdown to main");
- if (NS_FAILED(rv)) {
- MOZ_CRASH();
- }
- } else {
- mConduit = nullptr;
- }
+ NS_ReleaseOnMainThreadSystemGroup("MediaPipeline::mConduit",
+ mConduit.forget());
if (mConverter) {
mConverter->Shutdown();
}
}
// Dispatches setting the internal TrackID to TRACK_INVALID to the media
// graph thread to keep it in sync with other MediaStreamGraph operations
// like RemoveListener() and AddListener(). The TrackID will be updated on
@@ -2213,24 +2203,18 @@ public:
return SourceMediaStream::NotifyPullPromise::CreateAndResolve(true,
__func__);
});
}
private:
~PipelineListener()
{
- if (!NS_IsMainThread()) {
- // release conduit on mainthread. Must use forget()!
- nsresult rv =
- NS_DispatchToMainThread(new ConduitDeleteEvent(mConduit.forget()));
- MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
- } else {
- mConduit = nullptr;
- }
+ NS_ReleaseOnMainThreadSystemGroup("MediaPipeline::mConduit",
+ mConduit.forget());
}
void NotifyPullImpl(StreamTime aDesiredTime)
{
uint32_t samplesPer10ms = mRate / 100;
// Determine how many frames we need.
// As we get frames from conduit_ at the same rate as the graph's rate,
// the number of frames needed straightfully determined.
--- a/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
+++ b/media/webrtc/signaling/src/mediapipeline/MediaPipeline.h
@@ -309,32 +309,16 @@ private:
// Gets the current time as a DOMHighResTimeStamp
static DOMHighResTimeStamp GetNow();
bool IsRtp(const unsigned char* aData, size_t aLen) const;
// Must be called on the STS thread. Must be called after DetachMedia().
void DetachTransport_s();
};
-class ConduitDeleteEvent : public Runnable
-{
-public:
- explicit ConduitDeleteEvent(already_AddRefed<MediaSessionConduit> aConduit)
- : Runnable("ConduitDeleteEvent")
- , mConduit(aConduit)
- {
- }
-
- /* we exist solely to proxy release of the conduit */
- NS_IMETHOD Run() override { return NS_OK; }
-
-private:
- const RefPtr<MediaSessionConduit> mConduit;
-};
-
// A specialization of pipeline for reading from an input device
// and transmitting to the network.
class MediaPipelineTransmit : public MediaPipeline
{
public:
// Set aRtcpTransport to nullptr to use rtcp-mux
MediaPipelineTransmit(const std::string& aPc,
nsCOMPtr<nsIEventTarget> aMainThread,