DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
/* 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/. */

#include "MediaEngine.h"
#include "ImageContainer.h"
#include "nsITimer.h"
#include "mozilla/Mutex.h"
#include "mozilla/UniquePtr.h"
#include "nsITabSource.h"

namespace mozilla {

namespace layers {
class ImageContainer;
}

class MediaEngineTabVideoSource : public MediaEngineSource {
 public:
  MediaEngineTabVideoSource();

  nsString GetName() const override;
  nsCString GetUUID() const override;
  nsString GetGroupId() const override;

  bool GetScary() const override { return true; }

  dom::MediaSourceEnum GetMediaSource() const override {
    return dom::MediaSourceEnum::Browser;
  }

  nsresult Allocate(const dom::MediaTrackConstraints& aConstraints,
                    const MediaEnginePrefs& aPrefs,
                    const ipc::PrincipalInfo& aPrincipalInfo,
                    const char** aOutBadConstraint) override;
  nsresult Deallocate() override;
  void SetTrack(const RefPtr<SourceMediaStream>& aStream, TrackID aTrackID,
                const PrincipalHandle& aPrincipal) override;
  nsresult Start() override;
  nsresult Reconfigure(const dom::MediaTrackConstraints& aConstraints,
                       const MediaEnginePrefs& aPrefs,
                       const char** aOutBadConstraint) override;
  nsresult FocusOnSelectedSource() override;
  nsresult Stop() override;

  void GetSettings(dom::MediaTrackSettings& aOutSettings) const override;

  void Draw();

  class StartRunnable : public Runnable {
   public:
    StartRunnable(MediaEngineTabVideoSource* videoSource,
                  SourceMediaStream* aStream, TrackID aTrackID,
                  const PrincipalHandle& aPrincipal)
        : Runnable("MediaEngineTabVideoSource::StartRunnable"),
          mVideoSource(videoSource),
          mStream(aStream),
          mTrackID(aTrackID),
          mPrincipal(aPrincipal) {}
    NS_IMETHOD Run() override;
    const RefPtr<MediaEngineTabVideoSource> mVideoSource;
    const RefPtr<SourceMediaStream> mStream;
    const TrackID mTrackID;
    const PrincipalHandle mPrincipal;
  };

  class StopRunnable : public Runnable {
   public:
    explicit StopRunnable(MediaEngineTabVideoSource* videoSource)
        : Runnable("MediaEngineTabVideoSource::StopRunnable"),
          mVideoSource(videoSource) {}
    NS_IMETHOD Run() override;
    const RefPtr<MediaEngineTabVideoSource> mVideoSource;
  };

  class InitRunnable : public Runnable {
   public:
    InitRunnable(MediaEngineTabVideoSource* videoSource,
                 SourceMediaStream* aStream, TrackID aTrackID,
                 const PrincipalHandle& aPrincipal)
        : Runnable("MediaEngineTabVideoSource::InitRunnable"),
          mVideoSource(videoSource),
          mStream(aStream),
          mTrackID(aTrackID),
          mPrincipal(aPrincipal) {}
    NS_IMETHOD Run() override;
    const RefPtr<MediaEngineTabVideoSource> mVideoSource;
    const RefPtr<SourceMediaStream> mStream;
    const TrackID mTrackID;
    const PrincipalHandle mPrincipal;
  };

  class DestroyRunnable : public Runnable {
   public:
    explicit DestroyRunnable(MediaEngineTabVideoSource* videoSource)
        : Runnable("MediaEngineTabVideoSource::DestroyRunnable"),
          mVideoSource(videoSource) {}
    NS_IMETHOD Run() override;
    const RefPtr<MediaEngineTabVideoSource> mVideoSource;
  };

 protected:
  ~MediaEngineTabVideoSource() = default;

 private:
  // These are accessed only on main thread.
  int32_t mBufWidthMax = 0;
  int32_t mBufHeightMax = 0;
  int64_t mWindowId = 0;
  bool mScrollWithPage = false;
  int32_t mViewportOffsetX = 0;
  int32_t mViewportOffsetY = 0;
  int32_t mViewportWidth = 0;
  int32_t mViewportHeight = 0;
  int32_t mTimePerFrame = 0;
  RefPtr<layers::ImageContainer> mImageContainer;
  // The current settings of this source.
  // Members are main thread only.
  const RefPtr<media::Refcountable<dom::MediaTrackSettings>> mSettings;

  nsCOMPtr<nsPIDOMWindowOuter> mWindow;
  nsCOMPtr<nsITimer> mTimer;
  nsCOMPtr<nsITabSource> mTabSource;
  RefPtr<SourceMediaStream> mStreamMain;
  TrackID mTrackIDMain = TRACK_NONE;
  PrincipalHandle mPrincipalHandleMain = PRINCIPAL_HANDLE_NONE;
  // If this is set, we will run despite mWindow == nullptr.
  bool mBlackedoutWindow = false;

  // Current state of this source. Accessed on owning thread only.
  MediaEngineSourceState mState = kReleased;
  // mStream and mTrackID are set in SetTrack() to keep track of what to end
  // in Deallocate(). Owning thread only.
  RefPtr<SourceMediaStream> mStream;
  TrackID mTrackID = TRACK_NONE;
  PrincipalHandle mPrincipalHandle = PRINCIPAL_HANDLE_NONE;
};

}  // namespace mozilla