From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/webrtc/jsapi/RTCRtpReceiver.h | 198 ++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 dom/media/webrtc/jsapi/RTCRtpReceiver.h (limited to 'dom/media/webrtc/jsapi/RTCRtpReceiver.h') diff --git a/dom/media/webrtc/jsapi/RTCRtpReceiver.h b/dom/media/webrtc/jsapi/RTCRtpReceiver.h new file mode 100644 index 0000000000..2c050bceb1 --- /dev/null +++ b/dom/media/webrtc/jsapi/RTCRtpReceiver.h @@ -0,0 +1,198 @@ +/* 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/StateMirroring.h" +#include "mozilla/Maybe.h" +#include "js/RootingAPI.h" +#include "libwebrtcglue/RtpRtcpConfig.h" +#include "nsTArray.h" +#include "mozilla/dom/RTCRtpCapabilitiesBinding.h" +#include "mozilla/dom/RTCStatsReportBinding.h" +#include "PerformanceRecorder.h" +#include "RTCStatsReport.h" +#include "transportbridge/MediaPipeline.h" +#include + +class nsPIDOMWindowInner; + +namespace mozilla { +class MediaSessionConduit; +class MediaTransportHandler; +class JsepTransceiver; +class PeerConnectionImpl; +enum class PrincipalPrivacy : uint8_t; +class RemoteTrackSource; + +namespace dom { +class MediaStreamTrack; +class Promise; +class RTCDtlsTransport; +struct RTCRtpCapabilities; +struct RTCRtpContributingSource; +struct RTCRtpSynchronizationSource; +class RTCRtpTransceiver; + +class RTCRtpReceiver : public nsISupports, + public nsWrapperCache, + public MediaPipelineReceiveControlInterface { + public: + RTCRtpReceiver(nsPIDOMWindowInner* aWindow, PrincipalPrivacy aPrivacy, + PeerConnectionImpl* aPc, + MediaTransportHandler* aTransportHandler, + AbstractThread* aCallThread, nsISerialEventTarget* aStsThread, + MediaSessionConduit* aConduit, RTCRtpTransceiver* aTransceiver, + const TrackingId& aTrackingId); + + // nsISupports + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(RTCRtpReceiver) + + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + // webidl + MediaStreamTrack* Track() const { return mTrack; } + RTCDtlsTransport* GetTransport() const; + static void GetCapabilities(const GlobalObject&, const nsAString& aKind, + Nullable& aResult); + already_AddRefed GetStats(ErrorResult& aError); + void GetContributingSources( + nsTArray& aSources); + void GetSynchronizationSources( + nsTArray& aSources); + // 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( + bool aSkipIceStats = false); + Nullable GetJitterBufferTarget( + ErrorResult& aError) const { + return mJitterBufferTarget.isSome() ? Nullable(mJitterBufferTarget.value()) + : Nullable(); + } + void SetJitterBufferTarget(const Nullable& aTargetMs, + ErrorResult& aError); + + void Shutdown(); + void BreakCycles(); + // Terminal state, reached through stopping RTCRtpTransceiver. + void Stop(); + bool HasTrack(const dom::MediaStreamTrack* aTrack) const; + void SyncToJsep(JsepTransceiver& aJsepTransceiver) const; + void SyncFromJsep(const JsepTransceiver& aJsepTransceiver); + const std::vector& GetStreamIds() const { return mStreamIds; } + + struct StreamAssociation { + RefPtr mTrack; + std::string mStreamId; + }; + + struct TrackEventInfo { + RefPtr mReceiver; + std::vector mStreamIds; + }; + + struct StreamAssociationChanges { + std::vector> mReceiversToMute; + 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(); + void UpdateConduit(); + + // This is called when we set a remote description; may be an offer or answer. + void UpdateStreams(StreamAssociationChanges* aChanges); + + // Called when the privacy-needed state changes on the fly, as a result of + // ALPN negotiation. + void UpdatePrincipalPrivacy(PrincipalPrivacy aPrivacy); + + void OnRtcpBye(); + void OnRtcpTimeout(); + + void SetTrackMuteFromRemoteSdp(); + void OnRtpPacket(); + void UpdateUnmuteBlockingState(); + void UpdateReceiveTrackMute(); + + AbstractCanonical* CanonicalSsrc() { return &mSsrc; } + AbstractCanonical* CanonicalVideoRtxSsrc() { return &mVideoRtxSsrc; } + AbstractCanonical* CanonicalLocalRtpExtensions() { + return &mLocalRtpExtensions; + } + + AbstractCanonical>* CanonicalAudioCodecs() { + return &mAudioCodecs; + } + + AbstractCanonical>* CanonicalVideoCodecs() { + return &mVideoCodecs; + } + AbstractCanonical>* CanonicalVideoRtpRtcpConfig() { + return &mVideoRtpRtcpConfig; + } + AbstractCanonical* CanonicalReceiving() override { return &mReceiving; } + + private: + virtual ~RTCRtpReceiver(); + + void UpdateVideoConduit(); + void UpdateAudioConduit(); + + std::string GetMid() const; + JsepTransceiver& GetJsepTransceiver(); + const JsepTransceiver& GetJsepTransceiver() const; + + WatchManager mWatchManager; + nsCOMPtr mWindow; + RefPtr mPc; + bool mHaveStartedReceiving = false; + bool mHaveSetupTransport = false; + RefPtr mCallThread; + nsCOMPtr mStsThread; + RefPtr mTrack; + RefPtr mTrackSource; + RefPtr mPipeline; + RefPtr mTransportHandler; + RefPtr mTransceiver; + // 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; + Watchable mReceiveTrackMute{true, "RTCRtpReceiver::mReceiveTrackMute"}; + // This corresponds to the [[Receptive]] slot on RTCRtpTransceiver. + // Its only purpose is suppressing unmute events if true. + bool mReceptive = false; + // This is the [[JitterBufferTarget]] internal slot. + Maybe mJitterBufferTarget; + + MediaEventListener mRtcpByeListener; + MediaEventListener mRtcpTimeoutListener; + MediaEventListener mUnmuteListener; + + Canonical mSsrc; + Canonical mVideoRtxSsrc; + Canonical mLocalRtpExtensions; + Canonical> mAudioCodecs; + Canonical> mVideoCodecs; + Canonical> mVideoRtpRtcpConfig; + Canonical mReceiving; +}; + +} // namespace dom +} // namespace mozilla +#endif // _RTCRtpReceiver_h_ -- cgit v1.2.3