Skip to content

Commit

Permalink
Bug 1616937: Remove main thread parameters/members. r=mjf
Browse files Browse the repository at this point in the history
This ability to set the main thread has never been used, and in many cases is
not possible due to things being cycle collected (and therefore
main-thread-only).

Differential Revision: https://phabricator.services.mozilla.com/D142382
  • Loading branch information
docfaraday committed Apr 5, 2022
1 parent d15909a commit 571c7af
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 107 deletions.
8 changes: 4 additions & 4 deletions dom/media/webrtc/jsapi/PeerConnectionImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3644,10 +3644,10 @@ nsresult PeerConnectionImpl::AddTransceiver(
aSharedWebrtcState);
}

RefPtr<TransceiverImpl> transceiver = new TransceiverImpl(
mWindow, PrivacyNeeded(), GetHandle(), mTransportHandler,
aJsepTransceiver, GetMainThreadSerialEventTarget(), mSTSThread.get(),
aSendTrack, mCall.get(), aIdGenerator);
RefPtr<TransceiverImpl> transceiver =
new TransceiverImpl(mWindow, PrivacyNeeded(), GetHandle(),
mTransportHandler, aJsepTransceiver, mSTSThread.get(),
aSendTrack, mCall.get(), aIdGenerator);

if (!transceiver->IsValid()) {
return NS_ERROR_FAILURE;
Expand Down
33 changes: 16 additions & 17 deletions dom/media/webrtc/jsapi/RTCRtpReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ static already_AddRefed<dom::MediaStreamTrack> CreateTrack(
name(AbstractThread::MainThread(), val, \
"RTCRtpReceiver::" #name " (Canonical)")

RTCRtpReceiver::RTCRtpReceiver(
nsPIDOMWindowInner* aWindow, bool aPrivacyNeeded,
const std::string& aPCHandle, MediaTransportHandler* aTransportHandler,
JsepTransceiver* aJsepTransceiver, nsISerialEventTarget* aMainThread,
AbstractThread* aCallThread, nsISerialEventTarget* aStsThread,
MediaSessionConduit* aConduit, TransceiverImpl* aTransceiverImpl)
RTCRtpReceiver::RTCRtpReceiver(nsPIDOMWindowInner* aWindow, bool aPrivacyNeeded,
const std::string& aPCHandle,
MediaTransportHandler* aTransportHandler,
JsepTransceiver* aJsepTransceiver,
AbstractThread* aCallThread,
nsISerialEventTarget* aStsThread,
MediaSessionConduit* aConduit,
TransceiverImpl* aTransceiverImpl)
: mWindow(aWindow),
mPCHandle(aPCHandle),
mJsepTransceiver(aJsepTransceiver),
mMainThread(aMainThread),
mCallThread(aCallThread),
mStsThread(aStsThread),
mTransportHandler(aTransportHandler),
Expand All @@ -116,20 +117,18 @@ RTCRtpReceiver::RTCRtpReceiver(
if (Preferences::GetBool("media.peerconnection.mute_on_bye_or_timeout",
false)) {
mRtcpByeListener = aConduit->RtcpByeEvent().Connect(
mMainThread, this, &RTCRtpReceiver::OnRtcpBye);
GetMainThreadSerialEventTarget(), this, &RTCRtpReceiver::OnRtcpBye);
mRtcpTimeoutListener = aConduit->RtcpTimeoutEvent().Connect(
mMainThread, this, &RTCRtpReceiver::OnRtcpTimeout);
GetMainThreadSerialEventTarget(), this, &RTCRtpReceiver::OnRtcpTimeout);
}
if (aConduit->type() == MediaSessionConduit::AUDIO) {
mPipeline = new MediaPipelineReceiveAudio(
mPCHandle, aTransportHandler, mMainThread.get(), aCallThread,
mStsThread.get(), *aConduit->AsAudioSessionConduit(), mTrack,
principalHandle);
mPCHandle, aTransportHandler, aCallThread, mStsThread.get(),
*aConduit->AsAudioSessionConduit(), mTrack, principalHandle);
} else {
mPipeline = new MediaPipelineReceiveVideo(
mPCHandle, aTransportHandler, mMainThread.get(), aCallThread,
mStsThread.get(), *aConduit->AsVideoSessionConduit(), mTrack,
principalHandle);
mPCHandle, aTransportHandler, aCallThread, mStsThread.get(),
*aConduit->AsVideoSessionConduit(), mTrack, principalHandle);
}
}

Expand Down Expand Up @@ -542,7 +541,7 @@ void RTCRtpReceiver::GetSynchronizationSources(
nsPIDOMWindowInner* RTCRtpReceiver::GetParentObject() const { return mWindow; }

void RTCRtpReceiver::Shutdown() {
ASSERT_ON_THREAD(mMainThread);
MOZ_ASSERT(NS_IsMainThread());
if (mPipeline) {
mPipeline->Shutdown();
mPipeline = nullptr;
Expand All @@ -554,7 +553,7 @@ void RTCRtpReceiver::Shutdown() {
}

void RTCRtpReceiver::UpdateTransport() {
ASSERT_ON_THREAD(mMainThread);
MOZ_ASSERT(NS_IsMainThread());
if (!mHaveSetupTransport) {
mPipeline->SetLevel(mJsepTransceiver->GetLevel());
mHaveSetupTransport = true;
Expand Down
4 changes: 1 addition & 3 deletions dom/media/webrtc/jsapi/RTCRtpReceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class RTCRtpReceiver : public nsISupports, public nsWrapperCache {
RTCRtpReceiver(nsPIDOMWindowInner* aWindow, bool aPrivacyNeeded,
const std::string& aPCHandle,
MediaTransportHandler* aTransportHandler,
JsepTransceiver* aJsepTransceiver,
nsISerialEventTarget* aMainThread, AbstractThread* aCallThread,
JsepTransceiver* aJsepTransceiver, AbstractThread* aCallThread,
nsISerialEventTarget* aStsThread,
MediaSessionConduit* aConduit,
TransceiverImpl* aTransceiverImpl);
Expand Down Expand Up @@ -132,7 +131,6 @@ class RTCRtpReceiver : public nsISupports, public nsWrapperCache {
const RefPtr<JsepTransceiver> mJsepTransceiver;
bool mHaveStartedReceiving = false;
bool mHaveSetupTransport = false;
nsCOMPtr<nsISerialEventTarget> mMainThread;
RefPtr<AbstractThread> mCallThread;
nsCOMPtr<nsISerialEventTarget> mStsThread;
RefPtr<dom::MediaStreamTrack> mTrack;
Expand Down
8 changes: 4 additions & 4 deletions dom/media/webrtc/jsapi/RTCRtpSender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ LazyLogModule gSenderLog("RTCRtpSender");
RTCRtpSender::RTCRtpSender(
nsPIDOMWindowInner* aWindow, const std::string& aPCHandle,
MediaTransportHandler* aTransportHandler, JsepTransceiver* aJsepTransceiver,
nsISerialEventTarget* aMainThread, AbstractThread* aCallThread,
nsISerialEventTarget* aStsThread, MediaSessionConduit* aConduit,
dom::MediaStreamTrack* aTrack, TransceiverImpl* aTransceiverImpl)
AbstractThread* aCallThread, nsISerialEventTarget* aStsThread,
MediaSessionConduit* aConduit, dom::MediaStreamTrack* aTrack,
TransceiverImpl* aTransceiverImpl)
: mWindow(aWindow),
mPCHandle(aPCHandle),
mJsepTransceiver(aJsepTransceiver),
Expand All @@ -55,7 +55,7 @@ RTCRtpSender::RTCRtpSender(
INIT_CANONICAL(mVideoCodecMode, webrtc::VideoCodecMode::kRealtimeVideo),
INIT_CANONICAL(mCname, std::string()) {
mPipeline = new MediaPipelineTransmit(
mPCHandle, aTransportHandler, aMainThread, aCallThread, aStsThread,
mPCHandle, aTransportHandler, aCallThread, aStsThread,
aConduit->type() == MediaSessionConduit::VIDEO, aConduit);

if (aConduit->type() == MediaSessionConduit::AUDIO) {
Expand Down
3 changes: 1 addition & 2 deletions dom/media/webrtc/jsapi/RTCRtpSender.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class RTCRtpSender : public nsISupports, public nsWrapperCache {
public:
RTCRtpSender(nsPIDOMWindowInner* aWindow, const std::string& aPCHandle,
MediaTransportHandler* aTransportHandler,
JsepTransceiver* aJsepTransceiver,
nsISerialEventTarget* aMainThread, AbstractThread* aCallThread,
JsepTransceiver* aJsepTransceiver, AbstractThread* aCallThread,
nsISerialEventTarget* aStsThread, MediaSessionConduit* aConduit,
dom::MediaStreamTrack* aTrack,
TransceiverImpl* aTransceiverImpl);
Expand Down
21 changes: 10 additions & 11 deletions dom/media/webrtc/jsapi/TransceiverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,13 @@ NS_INTERFACE_MAP_END
TransceiverImpl::TransceiverImpl(
nsPIDOMWindowInner* aWindow, bool aPrivacyNeeded,
const std::string& aPCHandle, MediaTransportHandler* aTransportHandler,
JsepTransceiver* aJsepTransceiver, nsISerialEventTarget* aMainThread,
nsISerialEventTarget* aStsThread, dom::MediaStreamTrack* aSendTrack,
WebrtcCallWrapper* aCallWrapper, RTCStatsIdGenerator* aIdGenerator)
JsepTransceiver* aJsepTransceiver, nsISerialEventTarget* aStsThread,
dom::MediaStreamTrack* aSendTrack, WebrtcCallWrapper* aCallWrapper,
RTCStatsIdGenerator* aIdGenerator)
: mWindow(aWindow),
mPCHandle(aPCHandle),
mTransportHandler(aTransportHandler),
mJsepTransceiver(aJsepTransceiver),
mMainThread(aMainThread),
mStsThread(aStsThread),
mCallWrapper(aCallWrapper),
mIdGenerator(aIdGenerator),
Expand All @@ -173,11 +172,11 @@ TransceiverImpl::TransceiverImpl(

mReceiver = new RTCRtpReceiver(
aWindow, aPrivacyNeeded, aPCHandle, aTransportHandler, aJsepTransceiver,
aMainThread, mCallWrapper->mCallThread, aStsThread, mConduit, this);
mCallWrapper->mCallThread, aStsThread, mConduit, this);

mSender = new RTCRtpSender(
aWindow, aPCHandle, aTransportHandler, aJsepTransceiver, aMainThread,
mCallWrapper->mCallThread, aStsThread, mConduit, aSendTrack, this);
mSender = new RTCRtpSender(aWindow, aPCHandle, aTransportHandler,
aJsepTransceiver, mCallWrapper->mCallThread,
aStsThread, mConduit, aSendTrack, this);

if (mConduit) {
InitConduitControl();
Expand Down Expand Up @@ -213,8 +212,8 @@ void TransceiverImpl::RollbackToStableDtlsTransport() {

void TransceiverImpl::UpdateDtlsTransportState(const std::string& aTransportId,
TransportLayer::State aState) {
if (!mMainThread->IsOnCurrentThread()) {
mMainThread->Dispatch(
if (!GetMainThreadEventTarget()->IsOnCurrentThread()) {
GetMainThreadEventTarget()->Dispatch(
WrapRunnable(this, &TransceiverImpl::UpdateDtlsTransportState,
aTransportId, aState),
NS_DISPATCH_NORMAL);
Expand Down Expand Up @@ -828,7 +827,7 @@ void TransceiverImpl::Stop() {
auto conduit = std::move(mConduit);
(conduit ? conduit->Shutdown()
: GenericPromise::CreateAndResolve(true, __func__))
->Then(mMainThread, __func__,
->Then(GetMainThreadSerialEventTarget(), __func__,
[sender = mSender, receiver = mReceiver]() mutable {
// Shutdown pipelines when conduits are guaranteed shut down,
// so that all packets sent from conduits can be delivered.
Expand Down
15 changes: 8 additions & 7 deletions dom/media/webrtc/jsapi/TransceiverImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ class TransceiverImpl : public nsISupports,
/**
* |aSendTrack| might or might not be set.
*/
TransceiverImpl(
nsPIDOMWindowInner* aWindow, bool aPrivacyNeeded,
const std::string& aPCHandle, MediaTransportHandler* aTransportHandler,
JsepTransceiver* aJsepTransceiver, nsISerialEventTarget* aMainThread,
nsISerialEventTarget* aStsThread, dom::MediaStreamTrack* aSendTrack,
WebrtcCallWrapper* aCallWrapper, RTCStatsIdGenerator* aIdGenerator);
TransceiverImpl(nsPIDOMWindowInner* aWindow, bool aPrivacyNeeded,
const std::string& aPCHandle,
MediaTransportHandler* aTransportHandler,
JsepTransceiver* aJsepTransceiver,
nsISerialEventTarget* aStsThread,
dom::MediaStreamTrack* aSendTrack,
WebrtcCallWrapper* aCallWrapper,
RTCStatsIdGenerator* aIdGenerator);

bool IsValid() const { return !!mConduit; }

Expand Down Expand Up @@ -175,7 +177,6 @@ class TransceiverImpl : public nsISupports,
const std::string mPCHandle;
RefPtr<MediaTransportHandler> mTransportHandler;
const RefPtr<JsepTransceiver> mJsepTransceiver;
nsCOMPtr<nsISerialEventTarget> mMainThread;
nsCOMPtr<nsISerialEventTarget> mStsThread;
// state for webrtc.org that is shared between all transceivers
RefPtr<WebrtcCallWrapper> mCallWrapper;
Expand Down
Loading

0 comments on commit 571c7af

Please sign in to comment.