/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef _RTCRtpReceiver_h_ #define _RTCRtpReceiver_h_ #include "nsISupports.h" #include "nsWrapperCache.h" #include "mozilla/RefPtr.h" #include "mozilla/Maybe.h" #include "js/RootingAPI.h" #include "nsTArray.h" #include "mozilla/dom/RTCStatsReportBinding.h" #include "RTCStatsReport.h" #include "libwebrtcglue/RtcpEventObserver.h" #include class nsPIDOMWindowInner; namespace mozilla { class MediaPipelineReceive; class MediaSessionConduit; class MediaTransportHandler; class JsepTransceiver; class TransceiverImpl; namespace dom { class MediaStreamTrack; class Promise; class RTCDtlsTransport; struct RTCRtpContributingSource; struct RTCRtpSynchronizationSource; class RTCRtpReceiver : public nsISupports, public nsWrapperCache, public RtcpEventObserver { public: explicit RTCRtpReceiver(nsPIDOMWindowInner* aWindow, bool aPrivacyNeeded, const std::string& aPCHandle, MediaTransportHandler* aTransportHandler, JsepTransceiver* aJsepTransceiver, nsISerialEventTarget* aMainThread, nsISerialEventTarget* aStsThread, MediaSessionConduit* aConduit, TransceiverImpl* aTransceiverImpl); // nsISupports NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(RTCRtpReceiver) JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; // webidl MediaStreamTrack* Track() const { return mTrack; } RTCDtlsTransport* GetTransport() const; already_AddRefed GetStats(); void GetContributingSources( nsTArray& aSources); void GetSynchronizationSources( nsTArray& aSources); // test-only: called from simulcast mochitests. void MozAddRIDExtension(unsigned short aExtensionId); void MozAddRIDFilter(const nsAString& aRid); // test-only: insert fake CSRCs and audio levels for testing void MozInsertAudioLevelForContributingSource( const uint32_t aSource, const DOMHighResTimeStamp aTimestamp, const uint32_t aRtpTimestamp, const bool aHasLevel, const uint8_t aLevel); nsPIDOMWindowInner* GetParentObject() const; nsTArray> GetStatsInternal(); void Shutdown(); void Stop(); void Start(); bool HasTrack(const dom::MediaStreamTrack* aTrack) const; struct StreamAssociation { RefPtr mTrack; std::string mStreamId; }; struct TrackEventInfo { RefPtr mReceiver; std::vector mStreamIds; }; struct StreamAssociationChanges { std::vector> mTracksToMute; std::vector mStreamAssociationsRemoved; std::vector mStreamAssociationsAdded; std::vector mTrackEvents; }; // This is called when we set an answer (ie; when the transport is finalized). void UpdateTransport(); nsresult UpdateConduit(); // This is called when we set a remote description; may be an offer or answer. void UpdateStreams(StreamAssociationChanges* aChanges); void OnRtcpBye() override; void OnRtcpTimeout() override; void SetReceiveTrackMuted(bool aMuted); private: virtual ~RTCRtpReceiver(); nsresult UpdateVideoConduit(); nsresult UpdateAudioConduit(); std::string GetMid() const; nsCOMPtr mWindow; const std::string mPCHandle; RefPtr mJsepTransceiver; bool mHaveStartedReceiving = false; bool mHaveSetupTransport = false; nsCOMPtr mMainThread; nsCOMPtr mStsThread; RefPtr mTrack; RefPtr mPipeline; RefPtr mTransportHandler; RefPtr mTransceiverImpl; // This is [[AssociatedRemoteMediaStreams]], basically. We do not keep the // streams themselves here, because that would require this object to know // where the stream list for the whole RTCPeerConnection lives.. std::vector mStreamIds; bool mRemoteSetSendBit = false; }; } // namespace dom } // namespace mozilla #endif // _RTCRtpReceiver_h_