2015-05-13 09:04:30 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_CanvasCaptureMediaStream_h_
|
|
|
|
#define mozilla_dom_CanvasCaptureMediaStream_h_
|
|
|
|
|
2015-05-25 13:33:00 +03:00
|
|
|
#include "DOMMediaStream.h"
|
2015-09-17 07:36:57 +03:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2015-05-25 13:33:00 +03:00
|
|
|
#include "StreamBuffer.h"
|
|
|
|
|
2016-04-06 15:56:44 +03:00
|
|
|
class nsIPrincipal;
|
|
|
|
|
2015-05-13 09:04:30 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class DOMMediaStream;
|
2015-05-13 09:04:41 +03:00
|
|
|
class MediaStreamListener;
|
|
|
|
class SourceMediaStream;
|
|
|
|
|
|
|
|
namespace layers {
|
|
|
|
class Image;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2015-05-13 09:04:30 +03:00
|
|
|
|
|
|
|
namespace dom {
|
2015-05-13 09:04:41 +03:00
|
|
|
class CanvasCaptureMediaStream;
|
2015-05-13 09:04:30 +03:00
|
|
|
class HTMLCanvasElement;
|
2015-09-17 07:36:57 +03:00
|
|
|
class OutputStreamFrameListener;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The CanvasCaptureMediaStream is a MediaStream subclass that provides a video
|
|
|
|
* track containing frames from a canvas. See an architectural overview below.
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
* === Main Thread === __________________________
|
|
|
|
* | |
|
|
|
|
* | CanvasCaptureMediaStream |
|
|
|
|
* |__________________________|
|
|
|
|
* |
|
|
|
|
* | RequestFrame()
|
|
|
|
* v
|
|
|
|
* ________________________
|
|
|
|
* ________ FrameCaptureRequested? | |
|
|
|
|
* | | ------------------------> | OutputStreamDriver |
|
|
|
|
* | Canvas | SetFrameCapture() | (FrameCaptureListener) |
|
|
|
|
* |________| ------------------------> |________________________|
|
|
|
|
* |
|
|
|
|
* | SetImage()
|
|
|
|
* v
|
|
|
|
* ___________________
|
|
|
|
* | StreamListener |
|
|
|
|
* ---------------------------------------| (All image access |----------------
|
|
|
|
* === MediaStreamGraph Thread === | Mutex Guarded) |
|
|
|
|
* |___________________|
|
|
|
|
* ^ |
|
|
|
|
* NotifyPull() | | AppendToTrack()
|
|
|
|
* | v
|
|
|
|
* ___________________________
|
|
|
|
* | |
|
|
|
|
* | MSG / SourceMediaStream |
|
|
|
|
* |___________________________|
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Base class for drivers of the output stream.
|
|
|
|
* It is up to each sub class to implement the NewFrame() callback of
|
|
|
|
* FrameCaptureListener.
|
|
|
|
*/
|
|
|
|
class OutputStreamDriver : public FrameCaptureListener
|
2015-05-13 09:04:41 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-09-17 07:36:57 +03:00
|
|
|
OutputStreamDriver(SourceMediaStream* aSourceStream,
|
2016-04-06 15:56:44 +03:00
|
|
|
const TrackID& aTrackId,
|
|
|
|
const PrincipalHandle& aPrincipalHandle);
|
2015-05-13 09:04:41 +03:00
|
|
|
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(OutputStreamDriver);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sub classes can SetImage() to update the image being appended to the
|
|
|
|
* output stream. It will be appended on the next NotifyPull from MSG.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
void SetImage(const RefPtr<layers::Image>& aImage);
|
2015-05-13 09:04:41 +03:00
|
|
|
|
|
|
|
/*
|
2015-09-17 07:36:57 +03:00
|
|
|
* Makes sure any internal resources this driver is holding that may create
|
|
|
|
* reference cycles are released.
|
2015-05-13 09:04:41 +03:00
|
|
|
*/
|
2015-09-17 07:36:57 +03:00
|
|
|
virtual void Forget() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~OutputStreamDriver();
|
|
|
|
class StreamListener;
|
2015-05-13 09:04:41 +03:00
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceMediaStream> mSourceStream;
|
|
|
|
RefPtr<StreamListener> mStreamListener;
|
2015-05-13 09:04:41 +03:00
|
|
|
};
|
|
|
|
|
2015-09-17 07:36:57 +03:00
|
|
|
class CanvasCaptureMediaStream : public DOMMediaStream
|
2015-05-13 09:04:30 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-01-05 05:16:20 +03:00
|
|
|
CanvasCaptureMediaStream(nsPIDOMWindowInner* aWindow, HTMLCanvasElement* aCanvas);
|
2015-05-13 09:04:30 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CanvasCaptureMediaStream, DOMMediaStream)
|
|
|
|
|
2016-04-06 15:56:44 +03:00
|
|
|
nsresult Init(const dom::Optional<double>& aFPS, const TrackID& aTrackId,
|
|
|
|
nsIPrincipal* aPrincipal);
|
2015-05-13 09:04:30 +03:00
|
|
|
|
2016-01-18 06:50:29 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2015-05-13 09:04:30 +03:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
HTMLCanvasElement* Canvas() const { return mCanvas; }
|
|
|
|
void RequestFrame();
|
2015-09-17 07:36:57 +03:00
|
|
|
dom::FrameCaptureListener* FrameCaptureListener();
|
2015-05-13 09:04:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a CanvasCaptureMediaStream whose underlying stream is a SourceMediaStream.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<CanvasCaptureMediaStream>
|
2016-01-30 20:05:36 +03:00
|
|
|
CreateSourceStream(nsPIDOMWindowInner* aWindow,
|
2015-05-13 09:04:30 +03:00
|
|
|
HTMLCanvasElement* aCanvas);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~CanvasCaptureMediaStream();
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HTMLCanvasElement> mCanvas;
|
|
|
|
RefPtr<OutputStreamDriver> mOutputStreamDriver;
|
2015-05-13 09:04:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* mozilla_dom_CanvasCaptureMediaStream_h_ */
|