tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RTCRtpReceiver.h (7956B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef _RTCRtpReceiver_h_
      6 #define _RTCRtpReceiver_h_
      7 
      8 #include <vector>
      9 
     10 #include "PerformanceRecorder.h"
     11 #include "RTCStatsReport.h"
     12 #include "js/RootingAPI.h"
     13 #include "libwebrtcglue/RtpRtcpConfig.h"
     14 #include "mozilla/Maybe.h"
     15 #include "mozilla/RefPtr.h"
     16 #include "mozilla/StateMirroring.h"
     17 #include "mozilla/dom/RTCRtpCapabilitiesBinding.h"
     18 #include "mozilla/dom/RTCRtpParametersBinding.h"
     19 #include "mozilla/dom/RTCStatsReportBinding.h"
     20 #include "nsISupports.h"
     21 #include "nsTArray.h"
     22 #include "nsWrapperCache.h"
     23 #include "transportbridge/MediaPipeline.h"
     24 
     25 class nsPIDOMWindowInner;
     26 
     27 namespace mozilla {
     28 class MediaSessionConduit;
     29 class MediaTransportHandler;
     30 class JsepTransceiver;
     31 class PeerConnectionImpl;
     32 enum class PrincipalPrivacy : uint8_t;
     33 class RemoteTrackSource;
     34 
     35 namespace dom {
     36 class MediaStreamTrack;
     37 class Promise;
     38 class RTCDtlsTransport;
     39 struct RTCRtpCapabilities;
     40 struct RTCRtpContributingSource;
     41 struct RTCRtpSynchronizationSource;
     42 class RTCRtpTransceiver;
     43 class RTCRtpScriptTransform;
     44 class RTCStatsTimestampMaker;
     45 
     46 class RTCRtpReceiver : public nsISupports,
     47                       public nsWrapperCache,
     48                       public MediaPipelineReceiveControlInterface {
     49 public:
     50  RTCRtpReceiver(nsPIDOMWindowInner* aWindow, PrincipalPrivacy aPrivacy,
     51                 PeerConnectionImpl* aPc,
     52                 MediaTransportHandler* aTransportHandler,
     53                 AbstractThread* aCallThread, nsISerialEventTarget* aStsThread,
     54                 MediaSessionConduit* aConduit, RTCRtpTransceiver* aTransceiver,
     55                 const TrackingId& aTrackingId);
     56 
     57  // nsISupports
     58  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     59  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(RTCRtpReceiver)
     60 
     61  JSObject* WrapObject(JSContext* aCx,
     62                       JS::Handle<JSObject*> aGivenProto) override;
     63 
     64  // webidl
     65  MediaStreamTrack* Track() const { return mTrack; }
     66  RTCDtlsTransport* GetTransport() const;
     67  static void GetCapabilities(const GlobalObject&, const nsAString& aKind,
     68                              Nullable<dom::RTCRtpCapabilities>& aResult);
     69  void GetParameters(RTCRtpReceiveParameters& aParameters) const;
     70  already_AddRefed<Promise> GetStats(ErrorResult& aError);
     71  void GetContributingSources(
     72      nsTArray<dom::RTCRtpContributingSource>& aSources);
     73  void GetSynchronizationSources(
     74      nsTArray<dom::RTCRtpSynchronizationSource>& aSources);
     75  // test-only: insert fake CSRCs and audio levels for testing
     76  void MozInsertAudioLevelForContributingSource(
     77      const uint32_t aSource, const DOMHighResTimeStamp aTimestamp,
     78      const uint32_t aRtpTimestamp, const bool aHasLevel, const uint8_t aLevel);
     79 
     80  RTCRtpScriptTransform* GetTransform() const { return mTransform; }
     81 
     82  void SetTransform(RTCRtpScriptTransform* aTransform, ErrorResult& aError);
     83 
     84  nsPIDOMWindowInner* GetParentObject() const;
     85  nsTArray<RefPtr<RTCStatsPromise>> GetStatsInternal(
     86      bool aSkipIceStats = false);
     87  Nullable<DOMHighResTimeStamp> GetJitterBufferTarget(
     88      ErrorResult& aError) const {
     89    return mJitterBufferTarget.isSome() ? Nullable(mJitterBufferTarget.value())
     90                                        : Nullable<DOMHighResTimeStamp>();
     91  }
     92  void SetJitterBufferTarget(const Nullable<DOMHighResTimeStamp>& aTargetMs,
     93                             ErrorResult& aError);
     94 
     95  void Shutdown();
     96  void BreakCycles();
     97  void Unlink();
     98  // Terminal state, reached through stopping RTCRtpTransceiver.
     99  void Stop();
    100  bool HasTrack(const dom::MediaStreamTrack* aTrack) const;
    101  void SyncToJsep(JsepTransceiver& aJsepTransceiver) const;
    102  void SyncFromJsep(const JsepTransceiver& aJsepTransceiver);
    103  const std::vector<std::string>& GetStreamIds() const { return mStreamIds; }
    104 
    105  struct StreamAssociation {
    106    RefPtr<MediaStreamTrack> mTrack;
    107    std::string mStreamId;
    108  };
    109 
    110  struct TrackEventInfo {
    111    RefPtr<RTCRtpReceiver> mReceiver;
    112    std::vector<std::string> mStreamIds;
    113  };
    114 
    115  struct StreamAssociationChanges {
    116    std::vector<RefPtr<RTCRtpReceiver>> mReceiversToMute;
    117    std::vector<StreamAssociation> mStreamAssociationsRemoved;
    118    std::vector<StreamAssociation> mStreamAssociationsAdded;
    119    std::vector<TrackEventInfo> mTrackEvents;
    120  };
    121 
    122  // This is called when we set an answer (ie; when the transport is finalized).
    123  void UpdateTransport();
    124  void UpdateConduit();
    125 
    126  // This is called when we set a remote description; may be an offer or answer.
    127  void UpdateStreams(StreamAssociationChanges* aChanges);
    128 
    129  // Called when the privacy-needed state changes on the fly, as a result of
    130  // ALPN negotiation.
    131  void UpdatePrincipalPrivacy(PrincipalPrivacy aPrivacy);
    132 
    133  // Called by FrameTransformerProxy
    134  void RequestKeyFrame();
    135 
    136  void OnRtcpBye();
    137  void OnRtcpTimeout();
    138 
    139  void SetTrackMuteFromRemoteSdp();
    140  void OnRtpPacket();
    141  void UpdateUnmuteBlockingState();
    142  void UpdateReceiveTrackMute();
    143 
    144  Canonical<Ssrc>& CanonicalSsrc() { return mSsrc; }
    145  Canonical<Ssrc>& CanonicalVideoRtxSsrc() { return mVideoRtxSsrc; }
    146  Canonical<RtpExtList>& CanonicalLocalRtpExtensions() {
    147    return mLocalRtpExtensions;
    148  }
    149 
    150  Canonical<std::vector<AudioCodecConfig>>& CanonicalAudioCodecs() {
    151    return mAudioCodecs;
    152  }
    153 
    154  Canonical<std::vector<VideoCodecConfig>>& CanonicalVideoCodecs() {
    155    return mVideoCodecs;
    156  }
    157 
    158  Canonical<Maybe<RtpRtcpConfig>>& CanonicalVideoRtpRtcpConfig() {
    159    return mVideoRtpRtcpConfig;
    160  }
    161 
    162  Canonical<bool>& CanonicalReceiving() override { return mReceiving; }
    163 
    164  Canonical<RefPtr<FrameTransformerProxy>>& CanonicalFrameTransformerProxy() {
    165    return mFrameTransformerProxy;
    166  }
    167 
    168  const RTCStatsTimestampMaker* GetTimestampMaker() const;
    169 
    170  Maybe<gfx::IntSize> ReceivingSize() const;
    171 
    172 private:
    173  virtual ~RTCRtpReceiver();
    174 
    175  void UpdateVideoConduit();
    176  void UpdateAudioConduit();
    177 
    178  std::string GetMid() const;
    179  JsepTransceiver& GetJsepTransceiver();
    180  const JsepTransceiver& GetJsepTransceiver() const;
    181 
    182  WatchManager<RTCRtpReceiver> mWatchManager;
    183  nsCOMPtr<nsPIDOMWindowInner> mWindow;
    184  RefPtr<PeerConnectionImpl> mPc;
    185  bool mHaveStartedReceiving = false;
    186  bool mHaveSetupTransport = false;
    187  RefPtr<AbstractThread> mCallThread;
    188  nsCOMPtr<nsISerialEventTarget> mStsThread;
    189  RefPtr<dom::MediaStreamTrack> mTrack;
    190  RefPtr<RemoteTrackSource> mTrackSource;
    191  RefPtr<MediaPipelineReceive> mPipeline;
    192  RefPtr<MediaTransportHandler> mTransportHandler;
    193  RefPtr<RTCRtpTransceiver> mTransceiver;
    194  RefPtr<RTCRtpScriptTransform> mTransform;
    195  // This is [[AssociatedRemoteMediaStreams]], basically. We do not keep the
    196  // streams themselves here, because that would require this object to know
    197  // where the stream list for the whole RTCPeerConnection lives..
    198  std::vector<std::string> mStreamIds;
    199  bool mRemoteSetSendBit = false;
    200  Watchable<bool> mReceiveTrackMute{true, "RTCRtpReceiver::mReceiveTrackMute"};
    201  // This corresponds to the [[Receptive]] slot on RTCRtpTransceiver.
    202  // Its only purpose is suppressing unmute events if true.
    203  bool mReceptive = false;
    204  // This is the [[JitterBufferTarget]] internal slot.
    205  Maybe<DOMHighResTimeStamp> mJitterBufferTarget;
    206  // Houses [[ReceiveCodecs]]
    207  RTCRtpReceiveParameters mParameters;
    208 
    209  MediaEventListener mRtcpByeListener;
    210  MediaEventListener mRtcpTimeoutListener;
    211  MediaEventListener mUnmuteListener;
    212 
    213  Canonical<Ssrc> mSsrc;
    214  Canonical<Ssrc> mVideoRtxSsrc;
    215  Canonical<RtpExtList> mLocalRtpExtensions;
    216  Canonical<std::vector<AudioCodecConfig>> mAudioCodecs;
    217  Canonical<std::vector<VideoCodecConfig>> mVideoCodecs;
    218  Canonical<Maybe<RtpRtcpConfig>> mVideoRtpRtcpConfig;
    219  Canonical<bool> mReceiving;
    220  Canonical<RefPtr<FrameTransformerProxy>> mFrameTransformerProxy;
    221 
    222  Mirror<Maybe<gfx::IntSize>> mReceivingSize;
    223 };
    224 
    225 }  // namespace dom
    226 }  // namespace mozilla
    227 #endif  // _RTCRtpReceiver_h_