tor-browser

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

FrameTransformer.h (3518B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      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
      5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef MOZILLA_DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_FRAMETRANSFORMER_H_
      8 #define MOZILLA_DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_FRAMETRANSFORMER_H_
      9 
     10 #include <map>
     11 
     12 #include "api/frame_transformer_interface.h"
     13 #include "jsapi/RTCRtpScriptTransformer.h"
     14 #include "libwebrtcglue/FrameTransformerProxy.h"
     15 #include "mozilla/Mutex.h"
     16 #include "nsISupportsImpl.h"
     17 
     18 namespace mozilla {
     19 
     20 // There is one of these per RTCRtpSender and RTCRtpReceiver, for its entire
     21 // lifetime. SetProxy is used to activate/deactivate it. In the inactive state
     22 // (the default), this is just a synchronous passthrough.
     23 class FrameTransformer : public webrtc::FrameTransformerInterface {
     24 public:
     25  explicit FrameTransformer(bool aVideo);
     26  virtual ~FrameTransformer();
     27 
     28  // This is set when RTCRtpSender/Receiver.transform is set, and unset when
     29  // RTCRtpSender/Receiver.transform is unset.
     30  void SetProxy(FrameTransformerProxy* aProxy);
     31 
     32  // If no proxy is set (ie; RTCRtpSender/Receiver.transform is not set), this
     33  // synchronously calls OnTransformedFrame with no modifcation. If a proxy is
     34  // set, we send the frame to it, and eventually that frame should come back
     35  // to OnTransformedFrame.
     36  void Transform(
     37      std::unique_ptr<webrtc::TransformableFrameInterface> aFrame) override;
     38  void OnTransformedFrame(
     39      std::unique_ptr<webrtc::TransformableFrameInterface> aFrame);
     40 
     41  // When libwebrtc uses the same callback for all ssrcs
     42  // (right now, this is used for audio, but we do not care in this class)
     43  void RegisterTransformedFrameCallback(
     44      webrtc::scoped_refptr<webrtc::TransformedFrameCallback> aCallback)
     45      override;
     46  void UnregisterTransformedFrameCallback() override;
     47 
     48  // When libwebrtc uses a different callback for each ssrc
     49  // (right now, this is used for video, but we do not care in this class)
     50  void RegisterTransformedFrameSinkCallback(
     51      webrtc::scoped_refptr<webrtc::TransformedFrameCallback> aCallback,
     52      uint32_t aSsrc) override;
     53  void UnregisterTransformedFrameSinkCallback(uint32_t aSsrc) override;
     54 
     55  bool IsVideo() const { return mVideo; }
     56 
     57 private:
     58  const bool mVideo;
     59  Mutex mCallbacksMutex;
     60  // Written on a libwebrtc thread, read on the worker thread.
     61  webrtc::scoped_refptr<webrtc::TransformedFrameCallback> mCallback
     62      MOZ_GUARDED_BY(mCallbacksMutex);
     63  std::map<uint32_t, webrtc::scoped_refptr<webrtc::TransformedFrameCallback>>
     64      mCallbacksBySsrc MOZ_GUARDED_BY(mCallbacksMutex);
     65 
     66  Mutex mProxyMutex;
     67  // Written on the call thread, read on a libwebrtc/gmp/mediadataencoder/call
     68  // thread (which one depends on the media type and direction). Right now,
     69  // these are:
     70  // Send video: VideoStreamEncoder::encoder_queue_,
     71  //    WebrtcMediaDataEncoder::mTaskQueue, or GMP encoder thread.
     72  // Recv video: Call::worker_thread_
     73  // Send audio: ChannelSend::encoder_queue_
     74  // Recv audio: ChannelReceive::worker_thread_
     75  // This should have little to no lock contention
     76  // This corresponds to the RTCRtpScriptTransform/RTCRtpScriptTransformer.
     77  RefPtr<FrameTransformerProxy> mProxy MOZ_GUARDED_BY(mProxyMutex);
     78 };  // FrameTransformer
     79 
     80 }  // namespace mozilla
     81 
     82 #endif  // MOZILLA_DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_FRAMETRANSFORMER_H_