tor-browser

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

WebrtcCallWrapper.h (3940B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_WEBRTCCALLWRAPPER_H_
      8 #define DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_WEBRTCCALLWRAPPER_H_
      9 
     10 #include <set>
     11 
     12 #include "SystemTime.h"
     13 #include "domstubs.h"
     14 #include "jsapi/RTCStatsReport.h"
     15 #include "nsISupportsImpl.h"
     16 
     17 // libwebrtc includes
     18 #include "api/video/builtin_video_bitrate_allocator_factory.h"
     19 #include "call/call.h"
     20 #include "call/call_config.h"
     21 
     22 namespace mozilla {
     23 class AbstractThread;
     24 class MediaSessionConduit;
     25 class SharedWebrtcState;
     26 class WebrtcEnvironmentWrapper;
     27 
     28 namespace media {
     29 class ShutdownBlockingTicket;
     30 }
     31 
     32 // Wrap the webrtc.org Call class adding mozilla add/ref support.
     33 class WebrtcCallWrapper {
     34 public:
     35  typedef webrtc::CallConfig Config;
     36 
     37  static RefPtr<WebrtcCallWrapper> Create(
     38      RefPtr<WebrtcEnvironmentWrapper> aEnvWrapper,
     39      const dom::RTCStatsTimestampMaker& aTimestampMaker,
     40      UniquePtr<media::ShutdownBlockingTicket> aShutdownTicket,
     41      const RefPtr<SharedWebrtcState>& aSharedState);
     42 
     43  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebrtcCallWrapper)
     44 
     45  // Don't allow copying/assigning.
     46  WebrtcCallWrapper(const WebrtcCallWrapper&) = delete;
     47  void operator=(const WebrtcCallWrapper&) = delete;
     48 
     49  void SetCall(UniquePtr<webrtc::Call> aCall);
     50 
     51  webrtc::Call* Call() const;
     52 
     53  void UnsetRemoteSSRC(uint32_t aSsrc);
     54 
     55  // Idempotent.
     56  void RegisterConduit(MediaSessionConduit* conduit);
     57 
     58  // Idempotent.
     59  void UnregisterConduit(MediaSessionConduit* conduit);
     60 
     61  // Allow destroying the Call instance on the Call worker thread.
     62  //
     63  // Note that shutdown is blocked until the Call instance is destroyed.
     64  //
     65  // This CallWrapper is designed to be sharable, and is held by several objects
     66  // that are cycle-collectable. TaskQueueWrapper that the Call instances use
     67  // for worker threads are based off SharedThreadPools, and will block
     68  // xpcom-shutdown-threads until destroyed. The Call instance however will hold
     69  // on to its worker threads until destruction.
     70  //
     71  // If the last ref to this CallWrapper is held to cycle collector shutdown we
     72  // end up in a deadlock where cycle collector shutdown is required to destroy
     73  // the SharedThreadPool that is blocking xpcom-shutdown-threads from finishing
     74  // and triggering cycle collector shutdown.
     75  //
     76  // It would be nice to have the invariant where this class is immutable to the
     77  // degree that mCall is const, but given the above that is not possible.
     78  void Destroy();
     79 
     80  const dom::RTCStatsTimestampMaker& GetTimestampMaker() const;
     81 
     82 protected:
     83  virtual ~WebrtcCallWrapper();
     84 
     85  WebrtcCallWrapper(RefPtr<SharedWebrtcState> aSharedState,
     86                    UniquePtr<webrtc::VideoBitrateAllocatorFactory>
     87                        aVideoBitrateAllocatorFactory,
     88                    RefPtr<WebrtcEnvironmentWrapper> aEnvWrapper,
     89                    const dom::RTCStatsTimestampMaker& aTimestampMaker,
     90                    UniquePtr<media::ShutdownBlockingTicket> aShutdownTicket);
     91 
     92  const RefPtr<SharedWebrtcState> mSharedState;
     93 
     94  // Allows conduits to know about one another, to avoid remote SSRC
     95  // collisions.
     96  std::set<RefPtr<MediaSessionConduit>> mConduits;
     97  RTCStatsTimestampMakerRealtimeClock mClock;
     98  UniquePtr<media::ShutdownBlockingTicket> mShutdownTicket;
     99 
    100 public:
    101  const RefPtr<AbstractThread> mCallThread;
    102  const RefPtr<webrtc::AudioDecoderFactory> mAudioDecoderFactory;
    103  const UniquePtr<webrtc::VideoBitrateAllocatorFactory>
    104      mVideoBitrateAllocatorFactory;
    105  const RefPtr<WebrtcEnvironmentWrapper> mEnvWrapper;
    106 
    107 protected:
    108  // Call worker thread only.
    109  UniquePtr<webrtc::Call> mCall;
    110 };
    111 
    112 }  // namespace mozilla
    113 
    114 #endif