2012-04-30 07:11:34 +04: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 NSDOMMEDIASTREAM_H_
|
|
|
|
#define NSDOMMEDIASTREAM_H_
|
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
#include "ImageContainer.h"
|
|
|
|
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2012-04-30 07:11:34 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-02-15 12:04:11 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2016-01-26 05:49:01 +03:00
|
|
|
#include "StreamTracks.h"
|
2013-09-06 00:25:17 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2014-05-01 14:50:00 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2015-11-25 07:42:26 +03:00
|
|
|
#include "MediaTrackConstraints.h"
|
2014-10-03 12:18:00 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2016-01-22 07:10:41 +03:00
|
|
|
#include "PrincipalChangeObserver.h"
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
// X11 has a #define for CurrentTime. Unbelievable :-(.
|
2014-10-25 21:24:36 +04:00
|
|
|
// See dom/media/webaudio/AudioContext.h for more fun!
|
2013-02-15 12:04:11 +04:00
|
|
|
#ifdef CurrentTime
|
|
|
|
#undef CurrentTime
|
|
|
|
#endif
|
2012-07-19 13:58:48 +04:00
|
|
|
|
2013-02-15 12:01:58 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-12-08 11:00:12 +03:00
|
|
|
class AbstractThread;
|
2015-06-18 01:21:00 +03:00
|
|
|
class DOMHwMediaStream;
|
2014-09-09 02:17:00 +04:00
|
|
|
class DOMLocalMediaStream;
|
2016-01-05 05:16:21 +03:00
|
|
|
class DOMMediaStream;
|
2013-02-15 12:04:11 +04:00
|
|
|
class MediaStream;
|
2015-09-30 04:31:54 +03:00
|
|
|
class MediaInputPort;
|
2016-04-29 06:45:25 +03:00
|
|
|
class DirectMediaStreamListener;
|
2015-03-31 05:14:00 +03:00
|
|
|
class MediaStreamGraph;
|
2015-09-30 04:31:54 +03:00
|
|
|
class ProcessedMediaStream;
|
2013-02-15 12:04:11 +04:00
|
|
|
|
2016-06-07 17:20:29 +03:00
|
|
|
enum class BlockingMode;
|
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
namespace dom {
|
2013-05-21 23:17:47 +04:00
|
|
|
class AudioNode;
|
2015-05-13 09:04:30 +03:00
|
|
|
class HTMLCanvasElement;
|
2013-04-17 09:18:24 +04:00
|
|
|
class MediaStreamTrack;
|
2016-01-05 05:16:21 +03:00
|
|
|
class MediaStreamTrackSource;
|
2013-04-17 09:18:37 +04:00
|
|
|
class AudioStreamTrack;
|
|
|
|
class VideoStreamTrack;
|
2014-05-23 13:34:14 +04:00
|
|
|
class AudioTrack;
|
|
|
|
class VideoTrack;
|
|
|
|
class AudioTrackList;
|
|
|
|
class VideoTrackList;
|
|
|
|
class MediaTrackListListener;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2013-04-17 09:18:24 +04:00
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
namespace layers {
|
|
|
|
class ImageContainer;
|
|
|
|
class OverlayImage;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace layers
|
2015-06-18 01:21:00 +03:00
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
namespace media {
|
|
|
|
template<typename V, typename E> class Pledge;
|
|
|
|
} // namespace media
|
|
|
|
|
2014-10-03 12:18:00 +04:00
|
|
|
#define NS_DOMMEDIASTREAM_IID \
|
|
|
|
{ 0x8cb65468, 0x66c0, 0x444e, \
|
|
|
|
{ 0x89, 0x9f, 0x89, 0x1d, 0x9e, 0xd2, 0xbe, 0x7c } }
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
class OnTracksAvailableCallback {
|
|
|
|
public:
|
|
|
|
virtual ~OnTracksAvailableCallback() {}
|
|
|
|
virtual void NotifyTracksAvailable(DOMMediaStream* aStream) = 0;
|
|
|
|
};
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
/**
|
|
|
|
* Interface through which a DOMMediaStream can query its producer for a
|
|
|
|
* MediaStreamTrackSource. This will be used whenever a track occurs in the
|
|
|
|
* DOMMediaStream's owned stream that has not yet been created on the main
|
|
|
|
* thread (see DOMMediaStream::CreateOwnDOMTrack).
|
|
|
|
*/
|
|
|
|
class MediaStreamTrackSourceGetter : public nsISupports
|
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(MediaStreamTrackSourceGetter)
|
|
|
|
|
|
|
|
public:
|
|
|
|
MediaStreamTrackSourceGetter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual already_AddRefed<dom::MediaStreamTrackSource>
|
|
|
|
GetMediaStreamTrackSource(TrackID aInputTrackID) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~MediaStreamTrackSourceGetter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-30 07:11:34 +04:00
|
|
|
/**
|
|
|
|
* DOM wrapper for MediaStreams.
|
2015-09-30 04:31:54 +03:00
|
|
|
*
|
|
|
|
* To account for track operations such as clone(), addTrack() and
|
|
|
|
* removeTrack(), a DOMMediaStream wraps three internal (and chained)
|
|
|
|
* MediaStreams:
|
|
|
|
* 1. mInputStream
|
|
|
|
* - Controlled by the owner/source of the DOMMediaStream.
|
|
|
|
* It's a stream of the type indicated by
|
|
|
|
* - DOMMediaStream::CreateSourceStream/CreateTrackUnionStream. A source
|
|
|
|
* typically creates its DOMMediaStream, creates the MediaStreamTracks
|
|
|
|
* owned by said stream, then gets the internal input stream to which it
|
|
|
|
* feeds data for the previously created tracks.
|
|
|
|
* - When necessary it can create tracks on the internal stream only and
|
|
|
|
* their corresponding MediaStreamTracks will be asynchronously created.
|
|
|
|
* 2. mOwnedStream
|
|
|
|
* - A TrackUnionStream containing tracks owned by this stream.
|
|
|
|
* - The internal model of a MediaStreamTrack consists of its owning
|
|
|
|
* DOMMediaStream and the TrackID of the corresponding internal track in
|
|
|
|
* the owning DOMMediaStream's mOwnedStream.
|
|
|
|
* - The owned stream is different from the input stream since a cloned
|
|
|
|
* DOMMediaStream is also the owner of its (cloned) MediaStreamTracks.
|
|
|
|
* - Stopping an original track shall not stop its clone. This is
|
|
|
|
* solved by stopping it at the owned stream, while the clone's owned
|
|
|
|
* stream gets data directly from the original input stream.
|
|
|
|
* - A DOMMediaStream (original or clone) gets all tracks dynamically
|
|
|
|
* added by the source automatically forwarded by having a TRACK_ANY
|
|
|
|
* MediaInputPort set up from the owning DOMMediaStream's input stream
|
|
|
|
* to this DOMMediaStream's owned stream.
|
|
|
|
* 3. mPlaybackStream
|
|
|
|
* - A TrackUnionStream containing the tracks corresponding to the
|
|
|
|
* MediaStreamTracks currently in this DOMMediaStream (per getTracks()).
|
|
|
|
* - Similarly as for mOwnedStream, there's a TRACK_ANY MediaInputPort set
|
|
|
|
* up from the owned stream to the playback stream to allow tracks
|
|
|
|
* dynamically added by the source to be automatically forwarded to any
|
|
|
|
* audio or video sinks.
|
|
|
|
* - MediaStreamTracks added by addTrack() are set up with a MediaInputPort
|
|
|
|
* locked to their internal TrackID, from their owning DOMMediaStream's
|
|
|
|
* owned stream to this playback stream.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* A graphical representation of how tracks are connected in various cases as
|
|
|
|
* follows:
|
|
|
|
*
|
|
|
|
* addTrack()ed case:
|
|
|
|
* DOMStream A
|
|
|
|
* Input Owned Playback
|
|
|
|
* t1 ---------> t1 ------------> t1 <- MediaStreamTrack X
|
|
|
|
* (pointing to t1 in A)
|
|
|
|
* --------> t2 <- MediaStreamTrack Y
|
|
|
|
* / (pointing to t1 in B)
|
|
|
|
* DOMStream B /
|
|
|
|
* Input Owned / Playback
|
|
|
|
* t1 ---------> t1 ------------> t1 <- MediaStreamTrack Y
|
|
|
|
* (pointing to t1 in B)
|
|
|
|
*
|
|
|
|
* removeTrack()ed case:
|
|
|
|
* DOMStream A
|
|
|
|
* Input Owned Playback
|
|
|
|
* t1 ---------> t1 <- No tracks
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* clone()d case:
|
|
|
|
* DOMStream A
|
|
|
|
* Input Owned Playback
|
|
|
|
* t1 ---------> t1 ------------> t1 <- MediaStreamTrack X
|
|
|
|
* \ (pointing to t1 in A)
|
|
|
|
* -----
|
|
|
|
* DOMStream B \
|
|
|
|
* Input \ Owned Playback
|
|
|
|
* -> t1 ------------> t1 <- MediaStreamTrack Y
|
|
|
|
* (pointing to t1 in B)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* addTrack()ed, removeTrack()ed and clone()d case:
|
|
|
|
*
|
|
|
|
* Here we have done the following:
|
|
|
|
* var A = someStreamWithTwoTracks;
|
|
|
|
* var B = someStreamWithOneTrack;
|
|
|
|
* var X = A.getTracks()[0];
|
|
|
|
* var Y = A.getTracks()[1];
|
|
|
|
* var Z = B.getTracks()[0];
|
|
|
|
* A.addTrack(Z);
|
|
|
|
* A.removeTrack(X);
|
|
|
|
* B.removeTrack(Z);
|
|
|
|
* var A' = A.clone();
|
|
|
|
*
|
|
|
|
* DOMStream A
|
|
|
|
* Input Owned Playback
|
|
|
|
* t1 ---------> t1 <- MediaStreamTrack X (removed)
|
|
|
|
* (pointing to t1 in A)
|
|
|
|
* t2 ---------> t2 ------------> t2 <- MediaStreamTrack Y
|
|
|
|
* \ (pointing to t2 in A)
|
|
|
|
* \ ------> t3 <- MediaStreamTrack Z
|
|
|
|
* \ / (pointing to t1 in B)
|
|
|
|
* DOMStream B \ /
|
|
|
|
* Input \ Owned / Playback
|
|
|
|
* t1 ---^-----> t1 --- <- MediaStreamTrack Z (removed)
|
|
|
|
* \ \ (pointing to t1 in B)
|
|
|
|
* \ \
|
|
|
|
* DOMStream A' \ \
|
|
|
|
* Input \ \ Owned Playback
|
|
|
|
* \ -> t1 ------------> t1 <- MediaStreamTrack Y'
|
|
|
|
* \ (pointing to t1 in A')
|
|
|
|
* ----> t2 ------------> t2 <- MediaStreamTrack Z'
|
|
|
|
* (pointing to t2 in A')
|
2012-04-30 07:11:34 +04:00
|
|
|
*/
|
2016-03-16 18:08:43 +03:00
|
|
|
class DOMMediaStream : public DOMEventTargetHelper,
|
|
|
|
public dom::PrincipalChangeObserver<dom::MediaStreamTrack>
|
2012-04-30 07:11:34 +04:00
|
|
|
{
|
2013-02-15 12:01:58 +04:00
|
|
|
friend class DOMLocalMediaStream;
|
2016-01-14 13:34:39 +03:00
|
|
|
friend class dom::MediaStreamTrack;
|
2013-04-17 09:18:24 +04:00
|
|
|
typedef dom::MediaStreamTrack MediaStreamTrack;
|
2013-04-17 09:18:37 +04:00
|
|
|
typedef dom::AudioStreamTrack AudioStreamTrack;
|
|
|
|
typedef dom::VideoStreamTrack VideoStreamTrack;
|
2016-04-06 15:46:56 +03:00
|
|
|
typedef dom::MediaStreamTrackSource MediaStreamTrackSource;
|
2014-05-23 13:34:14 +04:00
|
|
|
typedef dom::AudioTrack AudioTrack;
|
|
|
|
typedef dom::VideoTrack VideoTrack;
|
|
|
|
typedef dom::AudioTrackList AudioTrackList;
|
|
|
|
typedef dom::VideoTrackList VideoTrackList;
|
2012-04-30 07:11:34 +04:00
|
|
|
|
|
|
|
public:
|
2015-09-21 01:45:57 +03:00
|
|
|
typedef dom::MediaTrackConstraints MediaTrackConstraints;
|
2015-09-30 04:32:06 +03:00
|
|
|
|
|
|
|
class TrackListener {
|
|
|
|
public:
|
2016-01-05 05:16:28 +03:00
|
|
|
virtual ~TrackListener() {}
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
/**
|
2016-09-08 14:44:49 +03:00
|
|
|
* Called when the DOMMediaStream has a live track added, either by
|
|
|
|
* script (addTrack()) or the source creating one.
|
2015-09-30 04:32:06 +03:00
|
|
|
*/
|
|
|
|
virtual void
|
2015-10-18 08:24:48 +03:00
|
|
|
NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack) {};
|
2015-09-30 04:32:06 +03:00
|
|
|
|
|
|
|
/**
|
2016-09-08 14:44:49 +03:00
|
|
|
* Called when the DOMMediaStream removes a live track from playback, either
|
|
|
|
* by script (removeTrack(), track.stop()) or the source ending it.
|
2015-09-30 04:32:06 +03:00
|
|
|
*/
|
|
|
|
virtual void
|
2015-10-18 08:24:48 +03:00
|
|
|
NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) {};
|
2016-09-08 14:44:49 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the DOMMediaStream has become active.
|
|
|
|
*/
|
|
|
|
virtual void
|
|
|
|
NotifyActive() {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the DOMMediaStream has become inactive.
|
|
|
|
*/
|
|
|
|
virtual void
|
|
|
|
NotifyInactive() {};
|
2015-09-30 04:32:06 +03:00
|
|
|
};
|
2013-05-03 09:02:55 +04:00
|
|
|
|
2015-10-22 07:36:22 +03:00
|
|
|
/**
|
|
|
|
* TrackPort is a representation of a MediaStreamTrack-MediaInputPort pair
|
|
|
|
* that make up a link between the Owned stream and the Playback stream.
|
|
|
|
*
|
|
|
|
* Semantically, the track is the identifier/key and the port the value of this
|
|
|
|
* connection.
|
|
|
|
*
|
|
|
|
* The input port can be shared between several TrackPorts. This is the case
|
|
|
|
* for DOMMediaStream's mPlaybackPort which forwards all tracks in its
|
|
|
|
* mOwnedStream automatically.
|
|
|
|
*
|
|
|
|
* If the MediaStreamTrack is owned by another DOMMediaStream (called A) than
|
|
|
|
* the one owning the TrackPort (called B), the input port (locked to the
|
|
|
|
* MediaStreamTrack's TrackID) connects A's mOwnedStream to B's mPlaybackStream.
|
|
|
|
*
|
|
|
|
* A TrackPort may never leave the DOMMediaStream it was created in. Internal
|
|
|
|
* use only.
|
|
|
|
*/
|
|
|
|
class TrackPort
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(TrackPort)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(TrackPort)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates MediaInputPort ownership to the TrackPort.
|
|
|
|
*
|
|
|
|
* OWNED - Owned by the TrackPort itself. TrackPort must destroy the
|
|
|
|
* input port when it's destructed.
|
|
|
|
* EXTERNAL - Owned by another entity. It's the caller's responsibility to
|
|
|
|
* ensure the the MediaInputPort outlives the TrackPort.
|
|
|
|
*/
|
|
|
|
enum class InputPortOwnership {
|
|
|
|
OWNED = 1,
|
|
|
|
EXTERNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
TrackPort(MediaInputPort* aInputPort,
|
|
|
|
MediaStreamTrack* aTrack,
|
|
|
|
const InputPortOwnership aOwnership);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~TrackPort();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void DestroyInputPort();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the source stream of the input port.
|
|
|
|
*/
|
|
|
|
MediaStream* GetSource() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the track ID this track is locked to in the source stream of the
|
|
|
|
* input port.
|
|
|
|
*/
|
|
|
|
TrackID GetSourceTrackId() const;
|
|
|
|
|
|
|
|
MediaInputPort* GetInputPort() const { return mInputPort; }
|
|
|
|
MediaStreamTrack* GetTrack() const { return mTrack; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blocks aTrackId from going into mInputPort unless the port has been
|
2016-03-16 18:00:34 +03:00
|
|
|
* destroyed. Returns a pledge that gets resolved when the MediaStreamGraph
|
|
|
|
* has applied the block in the playback stream.
|
2015-10-22 07:36:22 +03:00
|
|
|
*/
|
2016-06-07 17:20:29 +03:00
|
|
|
already_AddRefed<media::Pledge<bool, nsresult>>
|
|
|
|
BlockSourceTrackId(TrackID aTrackId, BlockingMode aBlockingMode);
|
2015-10-22 07:36:22 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
RefPtr<MediaInputPort> mInputPort;
|
|
|
|
RefPtr<MediaStreamTrack> mTrack;
|
|
|
|
|
|
|
|
// Defines if we've been given ownership of the input port or if it's owned
|
|
|
|
// externally. The owner is responsible for destroying the port.
|
|
|
|
const InputPortOwnership mOwnership;
|
|
|
|
};
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
DOMMediaStream(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter);
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2014-10-03 12:18:00 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMMediaStream,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOMMEDIASTREAM_IID)
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const
|
2013-02-15 12:04:11 +04:00
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2013-04-17 09:18:37 +04:00
|
|
|
// WebIDL
|
2015-10-14 20:08:33 +03:00
|
|
|
|
|
|
|
static already_AddRefed<DOMMediaStream>
|
|
|
|
Constructor(const dom::GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static already_AddRefed<DOMMediaStream>
|
|
|
|
Constructor(const dom::GlobalObject& aGlobal,
|
|
|
|
const DOMMediaStream& aStream,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static already_AddRefed<DOMMediaStream>
|
|
|
|
Constructor(const dom::GlobalObject& aGlobal,
|
|
|
|
const dom::Sequence<OwningNonNull<MediaStreamTrack>>& aTracks,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
double CurrentTime();
|
2013-07-24 14:11:35 +04:00
|
|
|
|
2015-02-05 19:03:00 +03:00
|
|
|
void GetId(nsAString& aID) const;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
void GetAudioTracks(nsTArray<RefPtr<AudioStreamTrack> >& aTracks) const;
|
|
|
|
void GetVideoTracks(nsTArray<RefPtr<VideoStreamTrack> >& aTracks) const;
|
|
|
|
void GetTracks(nsTArray<RefPtr<MediaStreamTrack> >& aTracks) const;
|
2016-05-20 14:01:30 +03:00
|
|
|
MediaStreamTrack* GetTrackById(const nsAString& aId) const;
|
2015-09-30 04:32:05 +03:00
|
|
|
void AddTrack(MediaStreamTrack& aTrack);
|
|
|
|
void RemoveTrack(MediaStreamTrack& aTrack);
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-01-22 11:51:37 +03:00
|
|
|
/** Identical to CloneInternal(TrackForwardingOption::EXPLICIT) */
|
|
|
|
already_AddRefed<DOMMediaStream> Clone();
|
|
|
|
|
2016-09-08 14:44:49 +03:00
|
|
|
bool Active() const;
|
|
|
|
|
2016-05-31 10:29:52 +03:00
|
|
|
IMPL_EVENT_HANDLER(addtrack)
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
// NON-WebIDL
|
|
|
|
|
2016-01-22 11:51:37 +03:00
|
|
|
/**
|
|
|
|
* Option to provide to CloneInternal() of which tracks should be forwarded
|
|
|
|
* from the source stream (`this`) to the returned stream clone.
|
|
|
|
*
|
|
|
|
* CURRENT forwards the tracks currently in the source stream's track set.
|
|
|
|
* ALL forwards like EXPLICIT plus any and all future tracks originating
|
|
|
|
* from the same input stream as the source DOMMediaStream (`this`).
|
|
|
|
*/
|
|
|
|
enum class TrackForwardingOption {
|
|
|
|
CURRENT,
|
|
|
|
ALL
|
|
|
|
};
|
|
|
|
already_AddRefed<DOMMediaStream> CloneInternal(TrackForwardingOption aForwarding);
|
|
|
|
|
2016-05-20 14:01:30 +03:00
|
|
|
MediaStreamTrack* GetOwnedTrackById(const nsAString& aId);
|
2016-01-05 05:16:23 +03:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this DOMMediaStream has aTrack in its mPlaybackStream.
|
|
|
|
*/
|
2014-08-14 05:40:54 +04:00
|
|
|
bool HasTrack(const MediaStreamTrack& aTrack) const;
|
2013-04-17 09:18:37 +04:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this DOMMediaStream owns aTrack.
|
|
|
|
*/
|
|
|
|
bool OwnsTrack(const MediaStreamTrack& aTrack) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the corresponding MediaStreamTrack if it's in our mOwnedStream.
|
2016-05-24 14:26:25 +03:00
|
|
|
* aInputTrackID should match the track's TrackID in its input stream,
|
|
|
|
* and aTrackID the TrackID in mOwnedStream.
|
|
|
|
*
|
|
|
|
* When aTrackID is not supplied or set to TRACK_ANY, we return the first
|
|
|
|
* MediaStreamTrack that matches the given input track. Note that there may
|
|
|
|
* be multiple MediaStreamTracks matching the same input track, but that they
|
|
|
|
* in that case all share the same MediaStreamTrackSource.
|
2015-09-30 04:31:54 +03:00
|
|
|
*/
|
2016-01-21 14:05:53 +03:00
|
|
|
MediaStreamTrack* FindOwnedDOMTrack(MediaStream* aInputStream,
|
2016-05-24 14:26:25 +03:00
|
|
|
TrackID aInputTrackID,
|
|
|
|
TrackID aTrackID = TRACK_ANY) const;
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2016-01-05 05:16:25 +03:00
|
|
|
/**
|
|
|
|
* Returns the TrackPort connecting aTrack's input stream to mOwnedStream,
|
|
|
|
* or nullptr if aTrack is not owned by this DOMMediaStream.
|
|
|
|
*/
|
|
|
|
TrackPort* FindOwnedTrackPort(const MediaStreamTrack& aTrack) const;
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
/**
|
|
|
|
* Returns the corresponding MediaStreamTrack if it's in our mPlaybackStream.
|
2016-01-05 05:16:22 +03:00
|
|
|
* aInputTrackID should match the track's TrackID in its owned stream.
|
2015-09-30 04:31:54 +03:00
|
|
|
*/
|
2016-01-21 14:05:53 +03:00
|
|
|
MediaStreamTrack* FindPlaybackDOMTrack(MediaStream* aInputStream,
|
2016-01-05 05:16:22 +03:00
|
|
|
TrackID aInputTrackID) const;
|
2015-09-30 04:31:54 +03:00
|
|
|
|
2015-09-30 04:32:05 +03:00
|
|
|
/**
|
|
|
|
* Returns the TrackPort connecting mOwnedStream to mPlaybackStream for aTrack.
|
|
|
|
*/
|
|
|
|
TrackPort* FindPlaybackTrackPort(const MediaStreamTrack& aTrack) const;
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
MediaStream* GetInputStream() const { return mInputStream; }
|
|
|
|
ProcessedMediaStream* GetOwnedStream() const { return mOwnedStream; }
|
|
|
|
ProcessedMediaStream* GetPlaybackStream() const { return mPlaybackStream; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows a video element to identify this stream as a camera stream, which
|
|
|
|
* needs special treatment.
|
|
|
|
*/
|
|
|
|
virtual MediaStream* GetCameraStream() const { return nullptr; }
|
2013-07-24 14:11:35 +04:00
|
|
|
|
2013-08-24 17:53:11 +04:00
|
|
|
/**
|
2016-01-24 11:05:16 +03:00
|
|
|
* Allows users to get access to media data without going through graph
|
|
|
|
* queuing. Returns a bool to let us know if direct data will be delivered.
|
2013-08-24 17:53:11 +04:00
|
|
|
*/
|
2016-04-29 06:45:25 +03:00
|
|
|
bool AddDirectListener(DirectMediaStreamListener *aListener);
|
|
|
|
void RemoveDirectListener(DirectMediaStreamListener *aListener);
|
2013-08-24 17:53:11 +04:00
|
|
|
|
2014-09-09 02:17:00 +04:00
|
|
|
virtual DOMLocalMediaStream* AsDOMLocalMediaStream() { return nullptr; }
|
2015-06-18 01:21:00 +03:00
|
|
|
virtual DOMHwMediaStream* AsDOMHwMediaStream() { return nullptr; }
|
2014-09-09 02:17:00 +04:00
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
/**
|
|
|
|
* Legacy method that returns true when the playback stream has finished.
|
|
|
|
*/
|
|
|
|
bool IsFinished() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Becomes inactive only when the playback stream has finished.
|
|
|
|
*/
|
|
|
|
void SetInactiveOnFinish();
|
|
|
|
|
2012-04-30 07:11:34 +04:00
|
|
|
/**
|
|
|
|
* Returns a principal indicating who may access this stream. The stream contents
|
|
|
|
* can only be accessed by principals subsuming this principal.
|
|
|
|
*/
|
|
|
|
nsIPrincipal* GetPrincipal() { return mPrincipal; }
|
|
|
|
|
2016-01-26 10:36:52 +03:00
|
|
|
/**
|
|
|
|
* Returns a principal indicating who may access video data of this stream.
|
|
|
|
* The video principal will be a combination of all live video tracks.
|
|
|
|
*/
|
|
|
|
nsIPrincipal* GetVideoPrincipal() { return mVideoPrincipal; }
|
|
|
|
|
2016-03-16 18:08:43 +03:00
|
|
|
// From PrincipalChangeObserver<MediaStreamTrack>.
|
|
|
|
void PrincipalChanged(MediaStreamTrack* aTrack) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a PrincipalChangeObserver to this stream.
|
|
|
|
*
|
|
|
|
* Returns true if it was successfully added.
|
|
|
|
*
|
|
|
|
* Ownership of the PrincipalChangeObserver remains with the caller, and it's
|
|
|
|
* the caller's responsibility to remove the observer before it dies.
|
|
|
|
*/
|
2016-01-22 07:10:41 +03:00
|
|
|
bool AddPrincipalChangeObserver(dom::PrincipalChangeObserver<DOMMediaStream>* aObserver);
|
2016-03-16 18:08:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an added PrincipalChangeObserver from this stream.
|
|
|
|
*
|
|
|
|
* Returns true if it was successfully removed.
|
|
|
|
*/
|
2016-01-22 07:10:41 +03:00
|
|
|
bool RemovePrincipalChangeObserver(dom::PrincipalChangeObserver<DOMMediaStream>* aObserver);
|
2014-05-01 14:50:00 +04:00
|
|
|
|
2015-02-19 20:59:00 +03:00
|
|
|
// Webrtc allows the remote side to name a stream whatever it wants, and we
|
|
|
|
// need to surface this to content.
|
|
|
|
void AssignId(const nsAString& aID) { mID = aID; }
|
|
|
|
|
2013-05-03 09:02:55 +04:00
|
|
|
/**
|
2015-10-14 20:08:33 +03:00
|
|
|
* Create a DOMMediaStream whose underlying input stream is a SourceMediaStream.
|
2013-05-03 09:02:55 +04:00
|
|
|
*/
|
2016-04-25 06:43:27 +03:00
|
|
|
static already_AddRefed<DOMMediaStream> CreateSourceStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter = nullptr);
|
2012-04-30 07:11:40 +04:00
|
|
|
|
2012-07-31 16:17:22 +04:00
|
|
|
/**
|
2015-10-14 20:08:33 +03:00
|
|
|
* Create a DOMMediaStream whose underlying input stream is a TrackUnionStream.
|
2012-07-31 16:17:22 +04:00
|
|
|
*/
|
2016-04-25 06:43:27 +03:00
|
|
|
static already_AddRefed<DOMMediaStream> CreateTrackUnionStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter = nullptr);
|
2012-07-31 16:17:22 +04:00
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
/**
|
2015-10-14 20:08:33 +03:00
|
|
|
* Create an DOMMediaStream whose underlying input stream is an
|
|
|
|
* AudioCaptureStream.
|
2015-07-24 15:28:16 +03:00
|
|
|
*/
|
2016-01-30 20:05:36 +03:00
|
|
|
static already_AddRefed<DOMMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
CreateAudioCaptureStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
MediaStreamGraph* aGraph);
|
2015-07-24 15:28:16 +03:00
|
|
|
|
2013-05-03 09:07:37 +04:00
|
|
|
void SetLogicalStreamStartTime(StreamTime aTime)
|
|
|
|
{
|
|
|
|
mLogicalStreamStartTime = aTime;
|
|
|
|
}
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
/**
|
2016-08-12 14:50:41 +03:00
|
|
|
* Adds a MediaStreamTrack to mTracks and raises "addtrack".
|
2016-05-31 10:29:52 +03:00
|
|
|
*
|
|
|
|
* Note that "addtrack" is raised synchronously and only has an effect if
|
|
|
|
* this MediaStream is already exposed to script. For spec compliance this is
|
|
|
|
* to be called from an async task.
|
2015-09-30 04:31:54 +03:00
|
|
|
*/
|
2016-08-12 14:50:41 +03:00
|
|
|
void AddTrackInternal(MediaStreamTrack* aTrack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called for each track in our owned stream to indicate to JS that we
|
|
|
|
* are carrying that track.
|
|
|
|
*
|
|
|
|
* Pre-creates a MediaStreamTrack and returns it.
|
|
|
|
* It is up to the caller to make sure it is added through AddTrackInternal.
|
|
|
|
*/
|
|
|
|
already_AddRefed<MediaStreamTrack> CreateDOMTrack(TrackID aTrackID,
|
|
|
|
MediaSegment::Type aType,
|
|
|
|
MediaStreamTrackSource* aSource,
|
|
|
|
const MediaTrackConstraints& aConstraints = MediaTrackConstraints());
|
2013-04-17 09:18:24 +04:00
|
|
|
|
2016-01-22 11:27:51 +03:00
|
|
|
/**
|
|
|
|
* Creates a MediaStreamTrack cloned from aTrack, adds it to mTracks and
|
|
|
|
* returns it.
|
|
|
|
* aCloneTrackID is the TrackID the new track will get in mOwnedStream.
|
|
|
|
*/
|
2016-01-05 05:16:26 +03:00
|
|
|
already_AddRefed<MediaStreamTrack> CloneDOMTrack(MediaStreamTrack& aTrack,
|
|
|
|
TrackID aCloneTrackID);
|
2016-01-22 11:27:51 +03:00
|
|
|
|
2015-04-17 12:56:00 +03:00
|
|
|
// When the initial set of tracks has been added, run
|
|
|
|
// aCallback->NotifyTracksAvailable.
|
2013-05-03 09:02:55 +04:00
|
|
|
// It is allowed to do anything, including run script.
|
|
|
|
// aCallback may run immediately during this call if tracks are already
|
|
|
|
// available!
|
|
|
|
// We only care about track additions, we'll fire the notification even if
|
|
|
|
// some of the tracks have been removed.
|
|
|
|
// Takes ownership of aCallback.
|
|
|
|
void OnTracksAvailable(OnTracksAvailableCallback* aCallback);
|
|
|
|
|
2013-07-25 06:07:34 +04:00
|
|
|
/**
|
|
|
|
* Add an nsISupports object that this stream will keep alive as long as
|
2016-06-29 13:27:13 +03:00
|
|
|
* the stream itself is alive.
|
2013-07-25 06:07:34 +04:00
|
|
|
*/
|
|
|
|
void AddConsumerToKeepAlive(nsISupports* aConsumer)
|
|
|
|
{
|
2016-06-29 13:27:13 +03:00
|
|
|
mConsumersToKeepAlive.AppendElement(aConsumer);
|
2013-07-25 06:07:34 +04:00
|
|
|
}
|
|
|
|
|
2016-01-05 05:16:28 +03:00
|
|
|
// Registers a track listener to this MediaStream, for listening to changes
|
|
|
|
// to our track set. The caller must call UnregisterTrackListener before
|
|
|
|
// being destroyed, so we don't hold on to a dead pointer. Main thread only.
|
2015-09-30 04:32:06 +03:00
|
|
|
void RegisterTrackListener(TrackListener* aListener);
|
2016-01-05 05:16:28 +03:00
|
|
|
|
|
|
|
// Unregisters a track listener from this MediaStream. The caller must call
|
|
|
|
// UnregisterTrackListener before being destroyed, so we don't hold on to
|
|
|
|
// a dead pointer. Main thread only.
|
2015-09-30 04:32:06 +03:00
|
|
|
void UnregisterTrackListener(TrackListener* aListener);
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2016-12-08 11:00:12 +03:00
|
|
|
AbstractThread* AbstractMainThread() const { return mAbstractMainThread; }
|
|
|
|
|
2012-04-30 07:11:34 +04:00
|
|
|
protected:
|
2014-06-24 20:36:43 +04:00
|
|
|
virtual ~DOMMediaStream();
|
|
|
|
|
2013-05-01 15:24:16 +04:00
|
|
|
void Destroy();
|
2016-01-05 05:16:20 +03:00
|
|
|
void InitSourceStream(MediaStreamGraph* aGraph);
|
|
|
|
void InitTrackUnionStream(MediaStreamGraph* aGraph);
|
2016-02-01 17:46:34 +03:00
|
|
|
void InitAudioCaptureStream(nsIPrincipal* aPrincipal, MediaStreamGraph* aGraph);
|
2015-10-14 20:08:32 +03:00
|
|
|
|
|
|
|
// Sets up aStream as mInputStream. A producer may append data to a
|
|
|
|
// SourceMediaStream input stream, or connect another stream to a
|
|
|
|
// TrackUnionStream input stream.
|
|
|
|
void InitInputStreamCommon(MediaStream* aStream, MediaStreamGraph* aGraph);
|
|
|
|
|
|
|
|
// Sets up a new TrackUnionStream as mOwnedStream and connects it to
|
|
|
|
// mInputStream with a TRACK_ANY MediaInputPort if available.
|
|
|
|
// If this DOMMediaStream should have an input stream (producing data),
|
|
|
|
// it has to be initiated before the owned stream.
|
|
|
|
void InitOwnedStreamCommon(MediaStreamGraph* aGraph);
|
|
|
|
|
|
|
|
// Sets up a new TrackUnionStream as mPlaybackStream and connects it to
|
|
|
|
// mOwnedStream with a TRACK_ANY MediaInputPort if available.
|
|
|
|
// If this DOMMediaStream should have an owned stream (producer or clone),
|
|
|
|
// it has to be initiated before the playback stream.
|
|
|
|
void InitPlaybackStreamCommon(MediaStreamGraph* aGraph);
|
2015-09-30 04:32:06 +03:00
|
|
|
|
|
|
|
void CheckTracksAvailable();
|
2013-11-23 00:14:29 +04:00
|
|
|
|
2015-02-06 12:38:11 +03:00
|
|
|
// Called when MediaStreamGraph has finished an iteration where tracks were
|
|
|
|
// created.
|
2015-09-30 04:32:06 +03:00
|
|
|
void NotifyTracksCreated();
|
2015-09-25 18:23:31 +03:00
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
// Called when our playback stream has finished in the MediaStreamGraph.
|
|
|
|
void NotifyFinished();
|
|
|
|
|
2016-09-08 14:44:49 +03:00
|
|
|
// Dispatches NotifyActive() to all registered track listeners.
|
|
|
|
void NotifyActive();
|
|
|
|
|
|
|
|
// Dispatches NotifyInactive() to all registered track listeners.
|
|
|
|
void NotifyInactive();
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
// Dispatches NotifyTrackAdded() to all registered track listeners.
|
2015-10-18 08:24:48 +03:00
|
|
|
void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack);
|
2015-09-30 04:32:06 +03:00
|
|
|
|
|
|
|
// Dispatches NotifyTrackRemoved() to all registered track listeners.
|
2015-10-18 08:24:48 +03:00
|
|
|
void NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack);
|
2013-04-17 09:18:24 +04:00
|
|
|
|
2016-05-31 10:29:52 +03:00
|
|
|
// Dispatches "addtrack" or "removetrack".
|
|
|
|
nsresult DispatchTrackEvent(const nsAString& aName,
|
|
|
|
const RefPtr<MediaStreamTrack>& aTrack);
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
class OwnedStreamListener;
|
|
|
|
friend class OwnedStreamListener;
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
class PlaybackStreamListener;
|
|
|
|
friend class PlaybackStreamListener;
|
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
class PlaybackTrackListener;
|
|
|
|
friend class PlaybackTrackListener;
|
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
/**
|
|
|
|
* Block a track in our playback stream. Calls NotifyPlaybackTrackBlocked()
|
|
|
|
* after the MediaStreamGraph has applied the block and the track is no longer
|
|
|
|
* live.
|
|
|
|
*/
|
|
|
|
void BlockPlaybackTrack(TrackPort* aTrack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on main thread after MediaStreamGraph has applied a track block in
|
|
|
|
* our playback stream.
|
|
|
|
*/
|
|
|
|
void NotifyPlaybackTrackBlocked();
|
|
|
|
|
2016-03-16 18:08:43 +03:00
|
|
|
// Recomputes the current principal of this stream based on the set of tracks
|
|
|
|
// it currently contains. PrincipalChangeObservers will be notified only if
|
|
|
|
// the principal changes.
|
|
|
|
void RecomputePrincipal();
|
|
|
|
|
2013-05-03 09:07:37 +04:00
|
|
|
// StreamTime at which the currentTime attribute would return 0.
|
|
|
|
StreamTime mLogicalStreamStartTime;
|
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
// We need this to track our parent object.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
2013-01-04 21:16:32 +04:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
// MediaStreams are owned by the graph, but we tell them when to die,
|
|
|
|
// and they won't die until we let them.
|
|
|
|
|
|
|
|
// This stream contains tracks used as input by us. Cloning happens from this
|
|
|
|
// stream. Tracks may exist in these stream but not in |mOwnedStream| if they
|
|
|
|
// have been stopped.
|
|
|
|
MediaStream* mInputStream;
|
|
|
|
|
|
|
|
// This stream contains tracks owned by us (if we were created directly from
|
|
|
|
// source, or cloned from some other stream). Tracks map to |mOwnedTracks|.
|
|
|
|
ProcessedMediaStream* mOwnedStream;
|
|
|
|
|
|
|
|
// This stream contains tracks currently played by us, despite of owner.
|
|
|
|
// Tracks map to |mTracks|.
|
|
|
|
ProcessedMediaStream* mPlaybackStream;
|
|
|
|
|
|
|
|
// This port connects mInputStream to mOwnedStream. All tracks forwarded.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaInputPort> mOwnedPort;
|
2015-09-30 04:31:54 +03:00
|
|
|
|
|
|
|
// This port connects mOwnedStream to mPlaybackStream. All tracks not
|
|
|
|
// explicitly blocked due to removal are forwarded.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaInputPort> mPlaybackPort;
|
2015-09-30 04:31:54 +03:00
|
|
|
|
|
|
|
// MediaStreamTracks corresponding to tracks in our mOwnedStream.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RefPtr<TrackPort>, 2> mOwnedTracks;
|
2015-09-30 04:31:54 +03:00
|
|
|
|
|
|
|
// MediaStreamTracks corresponding to tracks in our mPlaybackStream.
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RefPtr<TrackPort>, 2> mTracks;
|
2012-10-07 09:34:30 +04:00
|
|
|
|
2016-03-16 18:00:34 +03:00
|
|
|
// Number of MediaStreamTracks that have been removed on main thread but are
|
|
|
|
// waiting to be removed on MediaStreamGraph thread.
|
|
|
|
size_t mTracksPendingRemoval;
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
// The interface through which we can query the stream producer for
|
|
|
|
// track sources.
|
|
|
|
RefPtr<MediaStreamTrackSourceGetter> mTrackSourceGetter;
|
|
|
|
|
2016-06-29 13:27:13 +03:00
|
|
|
// Listener tracking changes to mOwnedStream. We use this to notify the
|
|
|
|
// MediaStreamTracks we own about state changes.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<OwnedStreamListener> mOwnedListener;
|
2016-06-29 13:27:13 +03:00
|
|
|
|
|
|
|
// Listener tracking changes to mPlaybackStream. This drives state changes
|
|
|
|
// in this DOMMediaStream and notifications to mTrackListeners.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PlaybackStreamListener> mPlaybackListener;
|
2013-04-17 09:18:24 +04:00
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
// Listener tracking when live MediaStreamTracks in mTracks end.
|
|
|
|
RefPtr<PlaybackTrackListener> mPlaybackTrackListener;
|
|
|
|
|
2013-05-03 09:02:55 +04:00
|
|
|
nsTArray<nsAutoPtr<OnTracksAvailableCallback> > mRunOnTracksAvailable;
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
// Set to true after MediaStreamGraph has created tracks for mPlaybackStream.
|
2015-02-06 12:38:11 +03:00
|
|
|
bool mTracksCreated;
|
|
|
|
|
2015-02-05 19:03:00 +03:00
|
|
|
nsString mID;
|
|
|
|
|
2016-06-29 13:27:13 +03:00
|
|
|
// Keep these alive while the stream is alive.
|
|
|
|
nsTArray<nsCOMPtr<nsISupports>> mConsumersToKeepAlive;
|
2013-07-25 06:07:34 +04:00
|
|
|
|
2013-05-03 09:02:55 +04:00
|
|
|
bool mNotifiedOfMediaStreamGraphShutdown;
|
2014-04-25 18:30:00 +04:00
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
// The track listeners subscribe to changes in this stream's track set.
|
2016-01-05 05:16:28 +03:00
|
|
|
nsTArray<TrackListener*> mTrackListeners;
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2016-09-08 14:44:49 +03:00
|
|
|
// True if this stream has live tracks.
|
|
|
|
bool mActive;
|
|
|
|
|
2016-09-15 15:18:22 +03:00
|
|
|
// True if this stream only sets mActive to false when its playback stream
|
|
|
|
// finishes. This is a hack to maintain legacy functionality for playing a
|
|
|
|
// HTMLMediaElement::MozCaptureStream(). See bug 1302379.
|
|
|
|
bool mSetInactiveOnFinish;
|
|
|
|
|
2014-04-25 18:30:00 +04:00
|
|
|
private:
|
|
|
|
void NotifyPrincipalChanged();
|
2016-03-16 18:08:43 +03:00
|
|
|
// Principal identifying who may access the collected contents of this stream.
|
2014-04-25 18:30:00 +04:00
|
|
|
// If null, this stream can be used by anyone because it has no content yet.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2016-01-26 10:36:52 +03:00
|
|
|
// Video principal is used by video element as access is requested to its
|
|
|
|
// image data.
|
|
|
|
nsCOMPtr<nsIPrincipal> mVideoPrincipal;
|
2016-01-22 07:10:41 +03:00
|
|
|
nsTArray<dom::PrincipalChangeObserver<DOMMediaStream>*> mPrincipalChangeObservers;
|
2014-12-17 20:03:34 +03:00
|
|
|
CORSMode mCORSMode;
|
2016-12-08 11:00:12 +03:00
|
|
|
const RefPtr<AbstractThread> mAbstractMainThread;
|
2012-04-30 07:11:34 +04:00
|
|
|
};
|
|
|
|
|
2014-10-03 12:18:00 +04:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(DOMMediaStream,
|
|
|
|
NS_DOMMEDIASTREAM_IID)
|
|
|
|
|
|
|
|
#define NS_DOMLOCALMEDIASTREAM_IID \
|
|
|
|
{ 0xb1437260, 0xec61, 0x4dfa, \
|
|
|
|
{ 0x92, 0x54, 0x04, 0x44, 0xe2, 0xb5, 0x94, 0x9c } }
|
|
|
|
|
|
|
|
class DOMLocalMediaStream : public DOMMediaStream
|
2012-10-25 03:21:32 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-01-05 05:16:21 +03:00
|
|
|
explicit DOMLocalMediaStream(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter)
|
|
|
|
: DOMMediaStream(aWindow, aTrackSourceGetter) {}
|
2012-10-25 03:21:32 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-10-03 12:18:00 +04:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_DOMLOCALMEDIASTREAM_IID)
|
2012-10-25 03:21:32 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-02-15 12:04:11 +04:00
|
|
|
|
2015-09-30 04:32:05 +03:00
|
|
|
void Stop();
|
2012-10-25 03:21:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an nsDOMLocalMediaStream whose underlying stream is a SourceMediaStream.
|
|
|
|
*/
|
2013-02-15 12:04:11 +04:00
|
|
|
static already_AddRefed<DOMLocalMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
CreateSourceStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter = nullptr);
|
2012-10-25 03:21:32 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an nsDOMLocalMediaStream whose underlying stream is a TrackUnionStream.
|
|
|
|
*/
|
2013-02-15 12:04:11 +04:00
|
|
|
static already_AddRefed<DOMLocalMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
CreateTrackUnionStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
MediaStreamGraph* aGraph,
|
|
|
|
MediaStreamTrackSourceGetter* aTrackSourceGetter = nullptr);
|
2014-07-09 01:23:16 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~DOMLocalMediaStream();
|
2015-09-30 04:32:06 +03:00
|
|
|
|
|
|
|
void StopImpl();
|
2012-10-25 03:21:32 +04:00
|
|
|
};
|
|
|
|
|
2014-10-03 12:18:00 +04:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(DOMLocalMediaStream,
|
|
|
|
NS_DOMLOCALMEDIASTREAM_IID)
|
|
|
|
|
2013-05-21 23:17:47 +04:00
|
|
|
class DOMAudioNodeMediaStream : public DOMMediaStream
|
|
|
|
{
|
|
|
|
typedef dom::AudioNode AudioNode;
|
|
|
|
public:
|
2016-01-05 05:16:20 +03:00
|
|
|
DOMAudioNodeMediaStream(nsPIDOMWindowInner* aWindow, AudioNode* aNode);
|
2013-05-21 23:17:47 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(DOMAudioNodeMediaStream, DOMMediaStream)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a DOMAudioNodeMediaStream whose underlying stream is a TrackUnionStream.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<DOMAudioNodeMediaStream>
|
2016-04-25 06:43:27 +03:00
|
|
|
CreateTrackUnionStreamAsInput(nsPIDOMWindowInner* aWindow,
|
|
|
|
AudioNode* aNode,
|
|
|
|
MediaStreamGraph* aGraph);
|
2013-05-21 23:17:47 +04:00
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
protected:
|
|
|
|
~DOMAudioNodeMediaStream();
|
|
|
|
|
2013-05-21 23:17:47 +04:00
|
|
|
private:
|
|
|
|
// If this object wraps a stream owned by an AudioNode, we need to ensure that
|
|
|
|
// the node isn't cycle-collected too early.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AudioNode> mStreamNode;
|
2013-05-21 23:17:47 +04:00
|
|
|
};
|
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
class DOMHwMediaStream : public DOMLocalMediaStream
|
|
|
|
{
|
|
|
|
typedef mozilla::gfx::IntSize IntSize;
|
|
|
|
typedef layers::OverlayImage OverlayImage;
|
2016-01-26 13:01:43 +03:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2015-06-18 01:21:00 +03:00
|
|
|
typedef layers::OverlayImage::Data Data;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2016-01-05 05:16:20 +03:00
|
|
|
explicit DOMHwMediaStream(nsPIDOMWindowInner* aWindow);
|
2015-06-18 01:21:00 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
static already_AddRefed<DOMHwMediaStream> CreateHwStream(nsPIDOMWindowInner* aWindow,
|
|
|
|
OverlayImage* aImage = nullptr);
|
2015-06-18 01:21:00 +03:00
|
|
|
virtual DOMHwMediaStream* AsDOMHwMediaStream() override { return this; }
|
|
|
|
int32_t RequestOverlayId();
|
|
|
|
void SetOverlayId(int32_t aOverlayId);
|
2015-06-15 04:11:00 +03:00
|
|
|
void SetImageSize(uint32_t width, uint32_t height);
|
2016-01-26 13:01:43 +03:00
|
|
|
void SetOverlayImage(OverlayImage* aImage);
|
2015-06-18 01:21:00 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~DOMHwMediaStream();
|
|
|
|
|
|
|
|
private:
|
2016-01-26 13:01:43 +03:00
|
|
|
void Init(MediaStream* aStream, OverlayImage* aImage);
|
2015-06-18 01:21:00 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
const int DEFAULT_IMAGE_ID = 0x01;
|
|
|
|
const int DEFAULT_IMAGE_WIDTH = 400;
|
|
|
|
const int DEFAULT_IMAGE_HEIGHT = 300;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<OverlayImage> mOverlayImage;
|
2016-04-12 17:54:41 +03:00
|
|
|
PrincipalHandle mPrincipalHandle;
|
2015-06-18 01:21:00 +03:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2013-02-15 12:01:58 +04:00
|
|
|
|
2012-04-30 07:11:34 +04:00
|
|
|
#endif /* NSDOMMEDIASTREAM_H_ */
|