Bug 1772053 - Enable dynamic code disable mitigations only on Windows 10 1703+ r...
[gecko.git] / dom / media / CanvasCaptureMediaStream.h
blobfaa5972142e5ed32c61b1e6e064b28e3fe51af5e
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/. */
6 #ifndef mozilla_dom_CanvasCaptureMediaStream_h_
7 #define mozilla_dom_CanvasCaptureMediaStream_h_
9 #include "DOMMediaStream.h"
10 #include "mozilla/dom/HTMLCanvasElement.h"
11 #include "PrincipalHandle.h"
13 class nsIPrincipal;
15 namespace mozilla {
16 class DOMMediaStream;
17 class SourceMediaTrack;
19 namespace layers {
20 class Image;
21 } // namespace layers
23 namespace dom {
24 class CanvasCaptureMediaStream;
25 class HTMLCanvasElement;
26 class OutputStreamFrameListener;
29 * The CanvasCaptureMediaStream is a MediaStream subclass that provides a video
30 * track containing frames from a canvas. See an architectural overview below.
32 * ----------------------------------------------------------------------------
33 * === Main Thread === __________________________
34 * | |
35 * | CanvasCaptureMediaStream |
36 * |__________________________|
37 * |
38 * | RequestFrame()
39 * v
40 * ________________________
41 * ________ FrameCaptureRequested? | |
42 * | | ------------------------> | OutputStreamDriver |
43 * | Canvas | SetFrameCapture() | (FrameCaptureListener) |
44 * |________| ------------------------> |________________________|
45 * |
46 * | SetImage() -
47 * | AppendToTrack()
48 * |
49 * v
50 * __________________________
51 * | |
52 * | MTG / SourceMediaTrack |
53 * |__________________________|
54 * ----------------------------------------------------------------------------
58 * Base class for drivers of the output stream.
59 * It is up to each sub class to implement the NewFrame() callback of
60 * FrameCaptureListener.
62 class OutputStreamDriver : public FrameCaptureListener {
63 public:
64 OutputStreamDriver(SourceMediaTrack* aSourceStream,
65 const PrincipalHandle& aPrincipalHandle);
67 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OutputStreamDriver);
70 * Called from js' requestFrame() when it wants the next painted frame to be
71 * explicitly captured.
73 virtual void RequestFrameCapture() = 0;
76 * Sub classes can SetImage() to update the image being appended to the
77 * output stream. It will be appended on the next NotifyPull from MTG.
79 void SetImage(RefPtr<layers::Image>&& aImage, const TimeStamp& aTime);
82 * Ends the track in mSourceStream when we know there won't be any more images
83 * requested for it.
85 void EndTrack();
87 const RefPtr<SourceMediaTrack> mSourceStream;
88 const PrincipalHandle mPrincipalHandle;
90 protected:
91 virtual ~OutputStreamDriver();
94 class CanvasCaptureMediaStream : public DOMMediaStream {
95 public:
96 CanvasCaptureMediaStream(nsPIDOMWindowInner* aWindow,
97 HTMLCanvasElement* aCanvas);
99 NS_DECL_ISUPPORTS_INHERITED
100 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CanvasCaptureMediaStream,
101 DOMMediaStream)
103 nsresult Init(const dom::Optional<double>& aFPS, nsIPrincipal* aPrincipal);
105 JSObject* WrapObject(JSContext* aCx,
106 JS::Handle<JSObject*> aGivenProto) override;
108 // WebIDL
109 HTMLCanvasElement* Canvas() const { return mCanvas; }
110 void RequestFrame();
112 dom::FrameCaptureListener* FrameCaptureListener();
115 * Stops capturing for this stream at mCanvas.
117 void StopCapture();
119 SourceMediaTrack* GetSourceStream() const;
121 protected:
122 ~CanvasCaptureMediaStream();
124 private:
125 RefPtr<HTMLCanvasElement> mCanvas;
126 RefPtr<OutputStreamDriver> mOutputStreamDriver;
129 } // namespace dom
130 } // namespace mozilla
132 #endif /* mozilla_dom_CanvasCaptureMediaStream_h_ */