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"
|
|
|
|
|
2012-04-30 07:11:34 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-02-15 12:04:11 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2013-09-05 21:29:38 +04:00
|
|
|
#include "StreamBuffer.h"
|
2013-09-06 00:25:17 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2014-05-01 14:50:00 +04:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "mozilla/PeerIdentity.h"
|
2014-10-03 12:18:00 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-12-17 20:03:34 +03:00
|
|
|
#include "mozilla/CORSMode.h"
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2012-07-19 13:58:48 +04:00
|
|
|
// GetCurrentTime is defined in winbase.h as zero argument macro forwarding to
|
|
|
|
// GetTickCount() and conflicts with NS_DECL_NSIDOMMEDIASTREAM, containing
|
|
|
|
// currentTime getter.
|
|
|
|
#ifdef GetCurrentTime
|
|
|
|
#undef GetCurrentTime
|
|
|
|
#endif
|
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 {
|
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
class DOMHwMediaStream;
|
2014-09-09 02:17:00 +04:00
|
|
|
class DOMLocalMediaStream;
|
2013-02-15 12:04:11 +04:00
|
|
|
class MediaStream;
|
2014-09-09 02:17:00 +04:00
|
|
|
class MediaEngineSource;
|
2015-09-30 04:31:54 +03:00
|
|
|
class MediaInputPort;
|
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
|
|
|
|
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;
|
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-09-21 01:45:57 +03:00
|
|
|
struct MediaTrackConstraints;
|
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
|
|
|
|
2013-08-24 17:53:11 +04:00
|
|
|
class MediaStreamDirectListener;
|
|
|
|
|
2014-10-03 12:18:00 +04:00
|
|
|
#define NS_DOMMEDIASTREAM_IID \
|
|
|
|
{ 0x8cb65468, 0x66c0, 0x444e, \
|
|
|
|
{ 0x89, 0x9f, 0x89, 0x1d, 0x9e, 0xd2, 0xbe, 0x7c } }
|
|
|
|
|
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
|
|
|
*/
|
2014-10-03 12:18:00 +04:00
|
|
|
class DOMMediaStream : public DOMEventTargetHelper
|
2012-04-30 07:11:34 +04:00
|
|
|
{
|
2015-09-30 04:31:54 +03:00
|
|
|
class TrackPort;
|
2013-02-15 12:01:58 +04:00
|
|
|
friend class DOMLocalMediaStream;
|
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;
|
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 {
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(TrackListener)
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Called when the DOMMediaStream has a new track added, either by
|
|
|
|
* JS (addTrack()) or the source creating one.
|
|
|
|
*/
|
|
|
|
virtual void
|
|
|
|
NotifyTrackAdded(const nsRefPtr<MediaStreamTrack>& aTrack) {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the DOMMediaStream removes a track, either by
|
|
|
|
* JS (removeTrack()) or the source ending it.
|
|
|
|
*/
|
|
|
|
virtual void
|
|
|
|
NotifyTrackRemoved(const nsRefPtr<MediaStreamTrack>& aTrack) {};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~TrackListener() {}
|
|
|
|
};
|
2013-05-03 09:02:55 +04:00
|
|
|
|
2013-04-17 09:18:24 +04:00
|
|
|
DOMMediaStream();
|
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
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
nsIDOMWindow* GetParentObject() const
|
|
|
|
{
|
|
|
|
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-14 20:08:33 +03:00
|
|
|
void GetAudioTracks(nsTArray<nsRefPtr<AudioStreamTrack> >& aTracks) const;
|
|
|
|
void GetVideoTracks(nsTArray<nsRefPtr<VideoStreamTrack> >& aTracks) const;
|
|
|
|
void GetTracks(nsTArray<nsRefPtr<MediaStreamTrack> >& aTracks) 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
|
|
|
|
|
|
|
// NON-WebIDL
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
MediaStreamTrack* FindOwnedDOMTrack(MediaStream* aOwningStream, TrackID aTrackID) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the corresponding MediaStreamTrack if it's in our mPlaybackStream.
|
|
|
|
*/
|
|
|
|
MediaStreamTrack* FindPlaybackDOMTrack(MediaStream* aOwningStream, TrackID aTrackID) const;
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Overridden in DOMLocalMediaStreams to allow getUserMedia to pass
|
|
|
|
* data directly to RTCPeerConnection without going through graph queuing.
|
|
|
|
* Returns a bool to let us know if direct data will be delivered.
|
|
|
|
*/
|
|
|
|
virtual bool AddDirectListener(MediaStreamDirectListener *aListener) { return false; }
|
|
|
|
virtual void RemoveDirectListener(MediaStreamDirectListener *aListener) {}
|
|
|
|
|
2013-08-26 10:07:19 +04:00
|
|
|
/**
|
|
|
|
* Overridden in DOMLocalMediaStreams to allow getUserMedia to disable
|
|
|
|
* media at the SourceMediaStream.
|
|
|
|
*/
|
|
|
|
virtual void SetTrackEnabled(TrackID aTrackID, bool aEnabled);
|
|
|
|
|
2014-08-27 09:03:49 +04:00
|
|
|
virtual void StopTrack(TrackID aTrackID);
|
|
|
|
|
2015-09-21 01:45:57 +03:00
|
|
|
virtual already_AddRefed<dom::Promise>
|
|
|
|
ApplyConstraintsToTrack(TrackID aTrackID,
|
|
|
|
const MediaTrackConstraints& aConstraints,
|
|
|
|
ErrorResult &aRv);
|
|
|
|
|
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
|
|
|
|
2013-02-15 12:04:11 +04:00
|
|
|
bool IsFinished();
|
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; }
|
2014-12-17 20:03:34 +03:00
|
|
|
mozilla::CORSMode GetCORSMode();
|
|
|
|
void SetCORSMode(mozilla::CORSMode aCORSMode);
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2014-05-01 14:50:00 +04:00
|
|
|
/**
|
|
|
|
* These are used in WebRTC. A peerIdentity constrained MediaStream cannot be sent
|
|
|
|
* across the network to anything other than a peer with the provided identity.
|
|
|
|
* If this is set, then mPrincipal should be an instance of nsNullPrincipal.
|
|
|
|
*/
|
|
|
|
PeerIdentity* GetPeerIdentity() const { return mPeerIdentity; }
|
|
|
|
void SetPeerIdentity(PeerIdentity* aPeerIdentity)
|
|
|
|
{
|
|
|
|
mPeerIdentity = aPeerIdentity;
|
|
|
|
}
|
|
|
|
|
2012-04-30 07:11:34 +04:00
|
|
|
/**
|
|
|
|
* Indicate that data will be contributed to this stream from origin aPrincipal.
|
|
|
|
* If aPrincipal is null, this is ignored. Otherwise, from now on the contents
|
|
|
|
* of this stream can only be accessed by principals that subsume aPrincipal.
|
|
|
|
* Returns true if the stream's principal changed.
|
|
|
|
*/
|
|
|
|
bool CombineWithPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
|
2014-05-01 14:50:00 +04:00
|
|
|
/**
|
|
|
|
* This is used in WebRTC to move from a protected state (nsNullPrincipal) to
|
|
|
|
* one where the stream is accessible to script. Don't call this.
|
|
|
|
* CombineWithPrincipal is almost certainly more appropriate.
|
|
|
|
*/
|
2014-04-25 18:30:00 +04:00
|
|
|
void SetPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to learn about dynamic changes in principal occur.
|
|
|
|
* Operations relating to these observers must be confined to the main thread.
|
|
|
|
*/
|
|
|
|
class PrincipalChangeObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void PrincipalChanged(DOMMediaStream* aMediaStream) = 0;
|
|
|
|
};
|
|
|
|
bool AddPrincipalChangeObserver(PrincipalChangeObserver* aObserver);
|
|
|
|
bool RemovePrincipalChangeObserver(PrincipalChangeObserver* aObserver);
|
2014-05-01 14:50:00 +04:00
|
|
|
|
2012-04-30 07:11:40 +04:00
|
|
|
/**
|
2013-05-03 09:02:55 +04:00
|
|
|
* Called when this stream's MediaStreamGraph has been shut down. Normally
|
|
|
|
* MSGs are only shut down when all streams have been removed, so this
|
|
|
|
* will only be called during a forced shutdown due to application exit.
|
2012-04-30 07:11:40 +04:00
|
|
|
*/
|
2013-05-03 09:02:55 +04:00
|
|
|
void NotifyMediaStreamGraphShutdown();
|
2013-07-25 06:07:34 +04:00
|
|
|
/**
|
2015-05-11 17:07:24 +03:00
|
|
|
* Called when the main-thread state of the MediaStream goes to finished.
|
2013-07-25 06:07:34 +04:00
|
|
|
*/
|
2015-05-11 17:07:24 +03:00
|
|
|
void NotifyStreamFinished();
|
2012-10-07 09:34:30 +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
|
|
|
*/
|
2015-03-31 05:14:00 +03:00
|
|
|
static already_AddRefed<DOMMediaStream> CreateSourceStream(nsIDOMWindow* aWindow,
|
2015-08-25 11:16:41 +03:00
|
|
|
MediaStreamGraph* aGraph);
|
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
|
|
|
*/
|
2015-03-31 05:14:00 +03:00
|
|
|
static already_AddRefed<DOMMediaStream> CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
2015-08-25 11:16:41 +03:00
|
|
|
MediaStreamGraph* aGraph);
|
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
|
|
|
*/
|
|
|
|
static already_AddRefed<DOMMediaStream> CreateAudioCaptureStream(
|
2015-08-25 11:16:41 +03:00
|
|
|
nsIDOMWindow* aWindow, 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
|
|
|
/**
|
|
|
|
* Called for each track in our owned stream to indicate to JS that we
|
|
|
|
* are carrying that track.
|
|
|
|
*
|
|
|
|
* Creates a MediaStreamTrack, adds it to mTracks and returns it.
|
|
|
|
*/
|
|
|
|
MediaStreamTrack* CreateOwnDOMTrack(TrackID aTrackID, MediaSegment::Type aType);
|
2013-04-17 09:18:24 +04:00
|
|
|
|
2013-05-03 09:02:55 +04:00
|
|
|
class OnTracksAvailableCallback {
|
|
|
|
public:
|
|
|
|
virtual ~OnTracksAvailableCallback() {}
|
|
|
|
virtual void NotifyTracksAvailable(DOMMediaStream* aStream) = 0;
|
|
|
|
};
|
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
|
|
|
|
* the stream is not finished.
|
|
|
|
*/
|
|
|
|
void AddConsumerToKeepAlive(nsISupports* aConsumer)
|
|
|
|
{
|
|
|
|
if (!IsFinished() && !mNotifiedOfMediaStreamGraphShutdown) {
|
|
|
|
mConsumersToKeepAlive.AppendElement(aConsumer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
void RegisterTrackListener(TrackListener* aListener);
|
|
|
|
void UnregisterTrackListener(TrackListener* aListener);
|
2014-05-23 13:34:14 +04:00
|
|
|
|
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();
|
2015-09-30 04:31:54 +03:00
|
|
|
void InitSourceStream(nsIDOMWindow* aWindow, MediaStreamGraph* aGraph);
|
|
|
|
void InitTrackUnionStream(nsIDOMWindow* aWindow, MediaStreamGraph* aGraph);
|
|
|
|
void InitAudioCaptureStream(nsIDOMWindow* aWindow, 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
|
|
|
|
2015-09-30 04:32:06 +03:00
|
|
|
// Dispatches NotifyTrackAdded() to all registered track listeners.
|
|
|
|
void NotifyTrackAdded(const nsRefPtr<MediaStreamTrack>& aTrack);
|
|
|
|
|
|
|
|
// Dispatches NotifyTrackRemoved() to all registered track listeners.
|
|
|
|
void NotifyTrackRemoved(const nsRefPtr<MediaStreamTrack>& aTrack);
|
2013-04-17 09:18:24 +04:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
// XXX Bug 1124630. Remove with CameraPreviewMediaStream.
|
|
|
|
void CreateAndAddPlaybackStreamListener(MediaStream*);
|
2013-02-15 12:04:11 +04:00
|
|
|
|
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.
|
|
|
|
nsCOMPtr<nsIDOMWindow> 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.
|
|
|
|
nsRefPtr<MediaInputPort> mOwnedPort;
|
|
|
|
|
|
|
|
// This port connects mOwnedStream to mPlaybackStream. All tracks not
|
|
|
|
// explicitly blocked due to removal are forwarded.
|
|
|
|
nsRefPtr<MediaInputPort> mPlaybackPort;
|
|
|
|
|
|
|
|
// MediaStreamTracks corresponding to tracks in our mOwnedStream.
|
|
|
|
nsAutoTArray<nsRefPtr<TrackPort>, 2> mOwnedTracks;
|
|
|
|
|
|
|
|
// MediaStreamTracks corresponding to tracks in our mPlaybackStream.
|
|
|
|
nsAutoTArray<nsRefPtr<TrackPort>, 2> mTracks;
|
2012-10-07 09:34:30 +04:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
nsRefPtr<OwnedStreamListener> mOwnedListener;
|
|
|
|
nsRefPtr<PlaybackStreamListener> mPlaybackListener;
|
2013-04-17 09:18:24 +04:00
|
|
|
|
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;
|
|
|
|
|
2013-07-25 06:07:34 +04:00
|
|
|
// Keep these alive until the stream finishes
|
|
|
|
nsTArray<nsCOMPtr<nsISupports> > mConsumersToKeepAlive;
|
|
|
|
|
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.
|
|
|
|
nsTArray<nsRefPtr<TrackListener>> mTrackListeners;
|
2014-05-23 13:34:14 +04:00
|
|
|
|
2014-04-25 18:30:00 +04:00
|
|
|
private:
|
|
|
|
void NotifyPrincipalChanged();
|
|
|
|
|
|
|
|
// Principal identifying who may access the contents of this stream.
|
|
|
|
// If null, this stream can be used by anyone because it has no content yet.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsTArray<PrincipalChangeObserver*> mPrincipalChangeObservers;
|
|
|
|
// this is used in gUM and WebRTC to identify peers that this stream
|
|
|
|
// is allowed to be sent to
|
|
|
|
nsAutoPtr<PeerIdentity> mPeerIdentity;
|
2014-12-17 20:03:34 +03:00
|
|
|
CORSMode mCORSMode;
|
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:
|
2013-02-15 12:01:58 +04:00
|
|
|
DOMLocalMediaStream() {}
|
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
|
|
|
|
2014-09-09 02:17:00 +04:00
|
|
|
virtual MediaEngineSource* GetMediaEngine(TrackID aTrackID) { return nullptr; }
|
|
|
|
|
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>
|
2015-03-31 05:14:00 +03:00
|
|
|
CreateSourceStream(nsIDOMWindow* aWindow,
|
2015-08-25 11:16:41 +03:00
|
|
|
MediaStreamGraph* aGraph);
|
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>
|
2015-03-31 05:14:00 +03:00
|
|
|
CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
2015-08-25 11:16:41 +03:00
|
|
|
MediaStreamGraph* aGraph);
|
2014-07-09 01:23:16 +04:00
|
|
|
|
2015-07-24 15:28:16 +03:00
|
|
|
/**
|
|
|
|
* Create an nsDOMLocalMediaStream whose underlying stream is an
|
|
|
|
* AudioCaptureStream. */
|
|
|
|
static already_AddRefed<DOMLocalMediaStream> CreateAudioCaptureStream(
|
2015-08-25 11:16:41 +03:00
|
|
|
nsIDOMWindow* aWindow, MediaStreamGraph* aGraph);
|
2015-07-24 15:28:16 +03:00
|
|
|
|
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:
|
2014-09-01 07:50:23 +04:00
|
|
|
explicit DOMAudioNodeMediaStream(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>
|
|
|
|
CreateTrackUnionStream(nsIDOMWindow* aWindow,
|
2015-03-31 05:14:00 +03:00
|
|
|
AudioNode* aNode,
|
2015-08-25 11:16:41 +03:00
|
|
|
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.
|
|
|
|
nsRefPtr<AudioNode> mStreamNode;
|
|
|
|
};
|
|
|
|
|
2015-06-18 01:21:00 +03:00
|
|
|
class DOMHwMediaStream : public DOMLocalMediaStream
|
|
|
|
{
|
|
|
|
typedef mozilla::gfx::IntSize IntSize;
|
|
|
|
typedef layers::ImageContainer ImageContainer;
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
typedef layers::OverlayImage OverlayImage;
|
|
|
|
typedef layers::OverlayImage::Data Data;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
DOMHwMediaStream();
|
|
|
|
|
|
|
|
static already_AddRefed<DOMHwMediaStream> CreateHwStream(nsIDOMWindow* aWindow);
|
|
|
|
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);
|
2015-06-18 01:21:00 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
~DOMHwMediaStream();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void Init(MediaStream* aStream);
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsRefPtr<ImageContainer> mImageContainer;
|
|
|
|
const int DEFAULT_IMAGE_ID = 0x01;
|
|
|
|
const int DEFAULT_IMAGE_WIDTH = 400;
|
|
|
|
const int DEFAULT_IMAGE_HEIGHT = 300;
|
|
|
|
nsRefPtr<OverlayImage> mOverlayImage;
|
|
|
|
Data mImageData;
|
|
|
|
#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_ */
|