Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/webrtc/MediaEngineTabVideoSource.h
Line
Count
Source (jump to first uncovered line)
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
#include "MediaEngine.h"
6
#include "ImageContainer.h"
7
#include "nsITimer.h"
8
#include "mozilla/Mutex.h"
9
#include "mozilla/UniquePtr.h"
10
#include "nsITabSource.h"
11
12
namespace mozilla {
13
14
class MediaEngineTabVideoSource : public MediaEngineSource
15
{
16
public:
17
  MediaEngineTabVideoSource();
18
19
  nsString GetName() const override;
20
  nsCString GetUUID() const override;
21
22
  bool GetScary() const override
23
0
  {
24
0
    return true;
25
0
  }
26
27
  dom::MediaSourceEnum GetMediaSource() const override
28
0
  {
29
0
    return dom::MediaSourceEnum::Browser;
30
0
  }
31
32
  nsresult Allocate(const dom::MediaTrackConstraints &aConstraints,
33
                    const MediaEnginePrefs &aPrefs,
34
                    const nsString& aDeviceId,
35
                    const ipc::PrincipalInfo& aPrincipalInfo,
36
                    AllocationHandle** aOutHandle,
37
                    const char** aOutBadConstraint) override;
38
  nsresult Deallocate(const RefPtr<const AllocationHandle>& aHandle) override;
39
  nsresult SetTrack(const RefPtr<const AllocationHandle>& aHandle,
40
                    const RefPtr<SourceMediaStream>& aStream,
41
                    TrackID aTrackID,
42
                    const PrincipalHandle& aPrincipal) override;
43
  nsresult Start(const RefPtr<const AllocationHandle>& aHandle) override;
44
  nsresult Reconfigure(const RefPtr<AllocationHandle>& aHandle,
45
                       const dom::MediaTrackConstraints& aConstraints,
46
                       const MediaEnginePrefs& aPrefs,
47
                       const nsString& aDeviceId,
48
                       const char** aOutBadConstraint) override;
49
  nsresult FocusOnSelectedSource(const RefPtr<const AllocationHandle>& aHandle) override;
50
  nsresult Stop(const RefPtr<const AllocationHandle>& aHandle) override;
51
52
  void Pull(const RefPtr<const AllocationHandle>& aHandle,
53
            const RefPtr<SourceMediaStream>& aStream,
54
            TrackID aTrackID,
55
            StreamTime aDesiredTime,
56
            const PrincipalHandle& aPrincipalHandle) override;
57
58
  uint32_t GetBestFitnessDistance(
59
    const nsTArray<const NormalizedConstraintSet*>& aConstraintSets,
60
    const nsString& aDeviceId) const override
61
0
  {
62
0
    return 0;
63
0
  }
64
65
  void Draw();
66
67
  class StartRunnable : public Runnable {
68
  public:
69
    explicit StartRunnable(MediaEngineTabVideoSource *videoSource)
70
      : Runnable("MediaEngineTabVideoSource::StartRunnable")
71
      , mVideoSource(videoSource)
72
0
    {}
73
    NS_IMETHOD Run() override;
74
    RefPtr<MediaEngineTabVideoSource> mVideoSource;
75
  };
76
77
  class StopRunnable : public Runnable {
78
  public:
79
    explicit StopRunnable(MediaEngineTabVideoSource *videoSource)
80
      : Runnable("MediaEngineTabVideoSource::StopRunnable")
81
      , mVideoSource(videoSource)
82
0
    {}
83
    NS_IMETHOD Run() override;
84
    RefPtr<MediaEngineTabVideoSource> mVideoSource;
85
  };
86
87
  class InitRunnable : public Runnable {
88
  public:
89
    explicit InitRunnable(MediaEngineTabVideoSource *videoSource)
90
      : Runnable("MediaEngineTabVideoSource::InitRunnable")
91
      , mVideoSource(videoSource)
92
0
    {}
93
    NS_IMETHOD Run() override;
94
    RefPtr<MediaEngineTabVideoSource> mVideoSource;
95
  };
96
97
  class DestroyRunnable : public Runnable {
98
  public:
99
    explicit DestroyRunnable(MediaEngineTabVideoSource* videoSource)
100
      : Runnable("MediaEngineTabVideoSource::DestroyRunnable")
101
      , mVideoSource(videoSource)
102
0
    {}
103
    NS_IMETHOD Run() override;
104
    RefPtr<MediaEngineTabVideoSource> mVideoSource;
105
  };
106
107
protected:
108
0
  ~MediaEngineTabVideoSource() {}
109
110
private:
111
  int32_t mBufWidthMax = 0;
112
  int32_t mBufHeightMax = 0;
113
  int64_t mWindowId = 0;
114
  bool mScrollWithPage = 0;
115
  int32_t mViewportOffsetX = 0;
116
  int32_t mViewportOffsetY = 0;
117
  int32_t mViewportWidth = 0;
118
  int32_t mViewportHeight = 0;
119
  int32_t mTimePerFrame = 0;
120
  UniquePtr<unsigned char[]> mData;
121
  size_t mDataSize = 0;
122
  nsCOMPtr<nsPIDOMWindowOuter> mWindow;
123
  // If this is set, we will run despite mWindow == nullptr.
124
  bool mBlackedoutWindow = false;
125
  // Current state of this source.
126
  // Written on owning thread *and* under mMutex.
127
  // Can be read on owning thread *or* under mMutex.
128
  MediaEngineSourceState mState = kReleased;
129
  // mStream and mTrackID are set in SetTrack() to keep track of what to end
130
  // in Deallocate().
131
  // Owning thread only.
132
  RefPtr<SourceMediaStream> mStream;
133
  TrackID mTrackID = TRACK_NONE;
134
  // mImage and mImageSize is Protected by mMutex.
135
  RefPtr<layers::SourceSurfaceImage> mImage;
136
  gfx::IntSize mImageSize;
137
  nsCOMPtr<nsITimer> mTimer;
138
  Mutex mMutex;
139
  nsCOMPtr<nsITabSource> mTabSource;
140
};
141
142
} // namespace mozilla