LCOV - code coverage report
Current view: top level - dom/media - CanvasCaptureMediaStream.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 4 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 mozilla_dom_CanvasCaptureMediaStream_h_
       7             : #define mozilla_dom_CanvasCaptureMediaStream_h_
       8             : 
       9             : #include "DOMMediaStream.h"
      10             : #include "mozilla/dom/HTMLCanvasElement.h"
      11             : #include "StreamTracks.h"
      12             : 
      13             : class nsIPrincipal;
      14             : 
      15             : namespace mozilla {
      16             : class DOMMediaStream;
      17             : class MediaStreamListener;
      18             : class SourceMediaStream;
      19             : 
      20             : namespace layers {
      21             : class Image;
      22             : } // namespace layers
      23             : 
      24             : namespace dom {
      25             : class CanvasCaptureMediaStream;
      26             : class HTMLCanvasElement;
      27             : class OutputStreamFrameListener;
      28             : 
      29             : /*
      30             :  * The CanvasCaptureMediaStream is a MediaStream subclass that provides a video
      31             :  * track containing frames from a canvas. See an architectural overview below.
      32             :  *
      33             :  * ----------------------------------------------------------------------------
      34             :  *     === Main Thread ===              __________________________
      35             :  *                                     |                          |
      36             :  *                                     | CanvasCaptureMediaStream |
      37             :  *                                     |__________________________|
      38             :  *                                                  |
      39             :  *                                                  | RequestFrame()
      40             :  *                                                  v
      41             :  *                                       ________________________
      42             :  *  ________   FrameCaptureRequested?   |                        |
      43             :  * |        | ------------------------> |   OutputStreamDriver   |
      44             :  * | Canvas |  SetFrameCapture()        | (FrameCaptureListener) |
      45             :  * |________| ------------------------> |________________________|
      46             :  *                                                  |
      47             :  *                                                  | SetImage()
      48             :  *                                                  v
      49             :  *                                         ___________________
      50             :  *                                        |   StreamListener  |
      51             :  * ---------------------------------------| (All image access |----------------
      52             :  *     === MediaStreamGraph Thread ===    |   Mutex Guarded)  |
      53             :  *                                        |___________________|
      54             :  *                                              ^       |
      55             :  *                                 NotifyPull() |       | AppendToTrack()
      56             :  *                                              |       v
      57             :  *                                      ___________________________
      58             :  *                                     |                           |
      59             :  *                                     |  MSG / SourceMediaStream  |
      60             :  *                                     |___________________________|
      61             :  * ----------------------------------------------------------------------------
      62             :  */
      63             : 
      64             : /*
      65             :  * Base class for drivers of the output stream.
      66             :  * It is up to each sub class to implement the NewFrame() callback of
      67             :  * FrameCaptureListener.
      68             :  */
      69             : class OutputStreamDriver : public FrameCaptureListener
      70             : {
      71             : public:
      72             :   OutputStreamDriver(SourceMediaStream* aSourceStream,
      73             :                      const TrackID& aTrackId,
      74             :                      const PrincipalHandle& aPrincipalHandle);
      75             : 
      76           0 :   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OutputStreamDriver);
      77             : 
      78             :   /*
      79             :    * Sub classes can SetImage() to update the image being appended to the
      80             :    * output stream. It will be appended on the next NotifyPull from MSG.
      81             :    */
      82             :   void SetImage(const RefPtr<layers::Image>& aImage, const TimeStamp& aTime);
      83             : 
      84             :   /*
      85             :    * Makes sure any internal resources this driver is holding that may create
      86             :    * reference cycles are released.
      87             :    */
      88           0 :   virtual void Forget() {}
      89             : 
      90             : protected:
      91             :   virtual ~OutputStreamDriver();
      92             :   class StreamListener;
      93             : 
      94             : private:
      95             :   RefPtr<SourceMediaStream> mSourceStream;
      96             :   RefPtr<StreamListener> mStreamListener;
      97             : };
      98             : 
      99             : class CanvasCaptureMediaStream : public DOMMediaStream
     100             : {
     101             : public:
     102             :   CanvasCaptureMediaStream(nsPIDOMWindowInner* aWindow, HTMLCanvasElement* aCanvas);
     103             : 
     104             :   NS_DECL_ISUPPORTS_INHERITED
     105           0 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CanvasCaptureMediaStream, DOMMediaStream)
     106             : 
     107             :   nsresult Init(const dom::Optional<double>& aFPS, const TrackID& aTrackId,
     108             :                 nsIPrincipal* aPrincipal);
     109             : 
     110             :   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
     111             : 
     112             :   // WebIDL
     113           0 :   HTMLCanvasElement* Canvas() const { return mCanvas; }
     114             :   void RequestFrame();
     115             : 
     116             :   dom::FrameCaptureListener* FrameCaptureListener();
     117             : 
     118             :   /**
     119             :    * Stops capturing for this stream at mCanvas.
     120             :    */
     121             :   void StopCapture();
     122             : 
     123             :   /**
     124             :    * Create a CanvasCaptureMediaStream whose underlying stream is a SourceMediaStream.
     125             :    */
     126             :   static already_AddRefed<CanvasCaptureMediaStream>
     127             :   CreateSourceStream(nsPIDOMWindowInner* aWindow,
     128             :                      HTMLCanvasElement* aCanvas);
     129             : 
     130             : protected:
     131             :   ~CanvasCaptureMediaStream();
     132             : 
     133             : private:
     134             :   RefPtr<HTMLCanvasElement> mCanvas;
     135             :   RefPtr<OutputStreamDriver> mOutputStreamDriver;
     136             : };
     137             : 
     138             : } // namespace dom
     139             : } // namespace mozilla
     140             : 
     141             : #endif /* mozilla_dom_CanvasCaptureMediaStream_h_ */

Generated by: LCOV version 1.13