tor-browser

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

WebrtcVideoCodecFactory.h (4448B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
      4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_WEBRTCVIDEOCODECFACTORY_H_
      7 #define DOM_MEDIA_WEBRTC_LIBWEBRTCGLUE_WEBRTCVIDEOCODECFACTORY_H_
      8 
      9 #include "MediaEventSource.h"
     10 #include "PerformanceRecorder.h"
     11 #include "api/video_codecs/video_decoder_factory.h"
     12 #include "api/video_codecs/video_encoder_factory.h"
     13 
     14 namespace mozilla {
     15 class GmpPluginNotifierInterface {
     16  virtual void DisconnectAll() = 0;
     17  virtual MediaEventSource<uint64_t>& CreatedGmpPluginEvent() = 0;
     18  virtual MediaEventSource<uint64_t>& ReleasedGmpPluginEvent() = 0;
     19 };
     20 
     21 class GmpPluginNotifier : public GmpPluginNotifierInterface {
     22 public:
     23  explicit GmpPluginNotifier(nsCOMPtr<nsISerialEventTarget> aOwningThread)
     24      : mOwningThread(std::move(aOwningThread)),
     25        mCreatedGmpPluginEvent(mOwningThread),
     26        mReleasedGmpPluginEvent(mOwningThread) {}
     27 
     28  ~GmpPluginNotifier() = default;
     29 
     30  void DisconnectAll() override {
     31    MOZ_ASSERT(mOwningThread->IsOnCurrentThread());
     32    mCreatedGmpPluginEvent.DisconnectAll();
     33    mReleasedGmpPluginEvent.DisconnectAll();
     34  }
     35 
     36  MediaEventSource<uint64_t>& CreatedGmpPluginEvent() override {
     37    return mCreatedGmpPluginEvent;
     38  }
     39 
     40  MediaEventSource<uint64_t>& ReleasedGmpPluginEvent() override {
     41    return mReleasedGmpPluginEvent;
     42  }
     43 
     44 protected:
     45  const nsCOMPtr<nsISerialEventTarget> mOwningThread;
     46  MediaEventForwarder<uint64_t> mCreatedGmpPluginEvent;
     47  MediaEventForwarder<uint64_t> mReleasedGmpPluginEvent;
     48 };
     49 
     50 class WebrtcVideoDecoderFactory : public GmpPluginNotifier,
     51                                  public webrtc::VideoDecoderFactory {
     52 public:
     53  WebrtcVideoDecoderFactory(nsCOMPtr<nsISerialEventTarget> aOwningThread,
     54                            std::string aPCHandle, TrackingId aTrackingId)
     55      : GmpPluginNotifier(std::move(aOwningThread)),
     56        mPCHandle(std::move(aPCHandle)),
     57        mTrackingId(std::move(aTrackingId)) {}
     58 
     59  std::vector<webrtc::SdpVideoFormat> GetSupportedFormats() const override {
     60    MOZ_CRASH("Unexpected call");
     61    return std::vector<webrtc::SdpVideoFormat>();
     62  }
     63 
     64  std::unique_ptr<webrtc::VideoDecoder> Create(
     65      const webrtc::Environment& env,
     66      const webrtc::SdpVideoFormat& format) override;
     67 
     68 private:
     69  const std::string mPCHandle;
     70  const TrackingId mTrackingId;
     71 };
     72 
     73 class WebrtcVideoEncoderFactory : public GmpPluginNotifierInterface,
     74                                  public webrtc::VideoEncoderFactory {
     75  class InternalFactory : public GmpPluginNotifier,
     76                          public webrtc::VideoEncoderFactory {
     77   public:
     78    InternalFactory(nsCOMPtr<nsISerialEventTarget> aOwningThread,
     79                    std::string aPCHandle)
     80        : GmpPluginNotifier(std::move(aOwningThread)),
     81          mPCHandle(std::move(aPCHandle)) {}
     82 
     83    std::vector<webrtc::SdpVideoFormat> GetSupportedFormats() const override {
     84      MOZ_CRASH("Unexpected call");
     85      return std::vector<webrtc::SdpVideoFormat>();
     86    }
     87 
     88    std::unique_ptr<webrtc::VideoEncoder> Create(
     89        const webrtc::Environment& env,
     90        const webrtc::SdpVideoFormat& format) override;
     91 
     92    bool Supports(const webrtc::SdpVideoFormat& aFormat);
     93 
     94   private:
     95    const std::string mPCHandle;
     96  };
     97 
     98 public:
     99  explicit WebrtcVideoEncoderFactory(
    100      nsCOMPtr<nsISerialEventTarget> aOwningThread, std::string aPCHandle)
    101      : mInternalFactory(MakeUnique<InternalFactory>(std::move(aOwningThread),
    102                                                     std::move(aPCHandle))) {}
    103 
    104  std::vector<webrtc::SdpVideoFormat> GetSupportedFormats() const override {
    105    MOZ_CRASH("Unexpected call");
    106    return std::vector<webrtc::SdpVideoFormat>();
    107  }
    108 
    109  std::unique_ptr<webrtc::VideoEncoder> Create(
    110      const webrtc::Environment& env,
    111      const webrtc::SdpVideoFormat& format) override;
    112 
    113  void DisconnectAll() override { mInternalFactory->DisconnectAll(); }
    114 
    115  MediaEventSource<uint64_t>& CreatedGmpPluginEvent() override {
    116    return mInternalFactory->CreatedGmpPluginEvent();
    117  }
    118  MediaEventSource<uint64_t>& ReleasedGmpPluginEvent() override {
    119    return mInternalFactory->ReleasedGmpPluginEvent();
    120  }
    121 
    122 private:
    123  const UniquePtr<InternalFactory> mInternalFactory;
    124 };
    125 }  // namespace mozilla
    126 
    127 #endif