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"
|
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"
|
2018-03-01 20:00:12 +03:00
|
|
|
#include "mozilla/RelativeTimeline.h"
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2013-02-15 12:01:58 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
2016-12-08 11:00:12 +03:00
|
|
|
class AbstractThread;
|
2016-01-05 05:16:21 +03:00
|
|
|
class DOMMediaStream;
|
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 {
|
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;
|
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
|
|
|
|
2014-10-03 12:18:00 +04:00
|
|
|
#define NS_DOMMEDIASTREAM_IID \
|
2018-11-19 16:25:37 +03:00
|
|
|
{ \
|
2014-10-03 12:18:00 +04:00
|
|
|
0x8cb65468, 0x66c0, 0x444e, { \
|
|
|
|
0x89, 0x9f, 0x89, 0x1d, 0x9e, 0xd2, 0xbe, 0x7c \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2016-01-05 05:16:21 +03:00
|
|
|
/**
|
2019-07-31 10:58:17 +03:00
|
|
|
* DOMMediaStream is the implementation of the js-exposed MediaStream interface.
|
2015-09-30 04:31:54 +03:00
|
|
|
*
|
2019-07-31 10:58:17 +03:00
|
|
|
* This is a thin main-thread class grouping MediaStreamTracks together.
|
2012-04-30 07:11:34 +04:00
|
|
|
*/
|
2019-07-31 10:58:17 +03:00
|
|
|
class DOMMediaStream : public DOMEventTargetHelper,
|
|
|
|
public RelativeTimeline,
|
|
|
|
public SupportsWeakPtr<DOMMediaStream> {
|
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;
|
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
|
|
|
|
2019-07-03 12:09:40 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(DOMMediaStream)
|
|
|
|
|
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
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
virtual void 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
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
virtual void 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(){};
|
2019-09-02 16:53:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the DOMMediaStream has become audible.
|
|
|
|
*/
|
|
|
|
virtual void NotifyAudible(){};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the DOMMediaStream has become inaudible.
|
|
|
|
*/
|
|
|
|
virtual void NotifyInaudible(){};
|
2015-09-30 04:32:06 +03:00
|
|
|
};
|
2013-05-03 09:02:55 +04:00
|
|
|
|
2018-11-23 18:02:03 +03:00
|
|
|
explicit DOMMediaStream(nsPIDOMWindowInner* aWindow);
|
2012-04-30 07:11:34 +04:00
|
|
|
|
2014-10-03 12:18:00 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
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 { 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);
|
|
|
|
|
2017-10-23 20:09:47 +03:00
|
|
|
static already_AddRefed<dom::Promise> CountUnderlyingStreams(
|
|
|
|
const dom::GlobalObject& aGlobal, ErrorResult& aRv);
|
|
|
|
|
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;
|
2018-10-11 18:36:11 +03:00
|
|
|
void GetAudioTracks(nsTArray<RefPtr<MediaStreamTrack>>& aTracks) const;
|
2015-10-18 08:24:48 +03:00
|
|
|
void GetVideoTracks(nsTArray<RefPtr<VideoStreamTrack>>& aTracks) const;
|
2018-10-11 18:36:11 +03:00
|
|
|
void GetVideoTracks(nsTArray<RefPtr<MediaStreamTrack>>& aTracks) const;
|
2015-10-18 08:24:48 +03:00
|
|
|
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);
|
2016-01-22 11:51:37 +03:00
|
|
|
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)
|
2017-12-20 21:36:19 +03:00
|
|
|
IMPL_EVENT_HANDLER(removetrack)
|
2016-05-31 10:29:52 +03:00
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
// NON-WebIDL
|
|
|
|
|
2019-11-14 01:39:53 +03:00
|
|
|
// Returns true if this stream contains a live audio track.
|
|
|
|
bool Audible() const;
|
|
|
|
|
2015-09-30 04:31:54 +03:00
|
|
|
/**
|
2019-07-31 10:58:17 +03:00
|
|
|
* Returns true if this DOMMediaStream has aTrack in mTracks.
|
2015-09-30 04:31:54 +03:00
|
|
|
*/
|
2014-08-14 05:40:54 +04:00
|
|
|
bool HasTrack(const MediaStreamTrack& aTrack) const;
|
2013-04-17 09:18:37 +04:00
|
|
|
|
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.
|
|
|
|
*/
|
2019-07-31 10:58:17 +03:00
|
|
|
already_AddRefed<nsIPrincipal> GetPrincipal();
|
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; }
|
|
|
|
|
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);
|
|
|
|
|
2019-11-20 18:24:10 +03:00
|
|
|
/**
|
|
|
|
* Removes a MediaStreamTrack from mTracks and fires "removetrack" if it
|
|
|
|
* was removed.
|
|
|
|
*
|
|
|
|
* Note that "removetrack" 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.
|
|
|
|
*/
|
|
|
|
void RemoveTrackInternal(MediaStreamTrack* aTrack);
|
|
|
|
|
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
|
|
|
|
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:32:06 +03:00
|
|
|
|
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();
|
|
|
|
|
2019-09-02 16:53:50 +03:00
|
|
|
// Dispatches NotifyAudible() to all registered track listeners.
|
|
|
|
void NotifyAudible();
|
|
|
|
|
|
|
|
// Dispatches NotifyInaudible() to all registered track listeners.
|
|
|
|
void NotifyInaudible();
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
2019-07-31 10:58:17 +03:00
|
|
|
// MediaStreamTracks contained by this DOMMediaStream.
|
|
|
|
nsTArray<RefPtr<MediaStreamTrack>> mTracks;
|
2016-03-16 18:00:34 +03:00
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
// Listener tracking when live MediaStreamTracks in mTracks end.
|
2019-07-31 10:58:17 +03:00
|
|
|
class PlaybackTrackListener;
|
2016-09-23 18:03:13 +03:00
|
|
|
RefPtr<PlaybackTrackListener> mPlaybackTrackListener;
|
|
|
|
|
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
|
|
|
|
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.
|
2019-09-02 16:53:50 +03:00
|
|
|
bool mActive = false;
|
|
|
|
|
|
|
|
// True if this stream has live audio tracks.
|
|
|
|
bool mAudible = false;
|
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)
|
|
|
|
|
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_ */
|