2013-03-27 05:32:51 +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 MEDIASTREAMTRACK_H_
|
|
|
|
#define MEDIASTREAMTRACK_H_
|
|
|
|
|
2015-09-21 01:45:57 +03:00
|
|
|
#include "MediaTrackConstraints.h"
|
2016-01-22 06:24:16 +03:00
|
|
|
#include "PrincipalChangeObserver.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "StreamTracks.h"
|
|
|
|
#include "mozilla/CORSMode.h"
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2015-11-14 07:27:39 +03:00
|
|
|
#include "mozilla/dom/MediaStreamTrackBinding.h"
|
|
|
|
#include "mozilla/dom/MediaTrackSettingsBinding.h"
|
2015-11-19 06:17:09 +03:00
|
|
|
#include "mozilla/media/MediaUtils.h"
|
2017-10-10 21:48:58 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2017-06-20 18:56:55 +03:00
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2013-03-27 05:32:51 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2013-09-06 00:25:17 +04:00
|
|
|
|
|
|
|
class DOMMediaStream;
|
2016-04-06 15:46:56 +03:00
|
|
|
class MediaEnginePhotoCallback;
|
2016-01-05 05:16:27 +03:00
|
|
|
class MediaInputPort;
|
2016-01-05 05:16:22 +03:00
|
|
|
class MediaStream;
|
2016-01-05 05:16:23 +03:00
|
|
|
class MediaStreamGraph;
|
2016-03-18 16:21:51 +03:00
|
|
|
class MediaStreamGraphImpl;
|
2016-03-03 19:27:59 +03:00
|
|
|
class MediaStreamTrackListener;
|
2016-04-29 06:45:25 +03:00
|
|
|
class DirectMediaStreamTrackListener;
|
2016-01-15 07:48:51 +03:00
|
|
|
class PeerConnectionImpl;
|
2016-03-18 16:21:51 +03:00
|
|
|
class PeerConnectionMedia;
|
2016-01-05 05:16:28 +03:00
|
|
|
class PeerIdentity;
|
2016-01-05 05:16:22 +03:00
|
|
|
class ProcessedMediaStream;
|
2016-02-01 17:48:05 +03:00
|
|
|
class RemoteSourceStreamInfo;
|
2016-05-23 18:22:01 +03:00
|
|
|
class SourceStreamInfo;
|
2013-09-06 00:25:17 +04:00
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class AudioStreamTrack;
|
|
|
|
class VideoStreamTrack;
|
2015-11-19 06:17:09 +03:00
|
|
|
class MediaStreamError;
|
2017-02-01 23:43:38 +03:00
|
|
|
enum class CallerType : uint32_t;
|
2013-03-27 05:32:51 +04:00
|
|
|
|
2016-04-06 15:46:56 +03:00
|
|
|
/**
|
|
|
|
* Common interface through which a MediaStreamTrack can communicate with its
|
|
|
|
* producer on the main thread.
|
|
|
|
*
|
|
|
|
* Kept alive by a strong ref in all MediaStreamTracks (original and clones)
|
|
|
|
* sharing this source.
|
|
|
|
*/
|
|
|
|
class MediaStreamTrackSource : public nsISupports
|
|
|
|
{
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(MediaStreamTrackSource)
|
|
|
|
|
|
|
|
public:
|
2017-11-06 20:04:27 +03:00
|
|
|
class Sink : public SupportsWeakPtr<Sink>
|
2016-01-22 07:28:57 +03:00
|
|
|
{
|
|
|
|
public:
|
2017-11-06 20:04:27 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaStreamTrackSource::Sink)
|
2017-11-10 17:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must be constant throughout the Sink's lifetime.
|
|
|
|
*
|
|
|
|
* Return true to keep the MediaStreamTrackSource where this sink is
|
|
|
|
* registered alive.
|
|
|
|
* Return false to allow the source to stop.
|
|
|
|
*
|
|
|
|
* Typically MediaStreamTrack::Sink returns true and other Sinks
|
|
|
|
* (like HTMLMediaElement::StreamCaptureTrackSource) return false.
|
|
|
|
*/
|
|
|
|
virtual bool KeepsSourceAlive() const = 0;
|
|
|
|
|
2017-11-10 17:55:42 +03:00
|
|
|
/**
|
|
|
|
* Return true to ensure that the MediaStreamTrackSource where this Sink is
|
|
|
|
* registered is kept turned on and active.
|
|
|
|
* Return false to allow the source to pause, and any underlying devices to
|
|
|
|
* temporarily stop.
|
|
|
|
*
|
|
|
|
* When the underlying enabled state of the sink changes,
|
|
|
|
* call MediaStreamTrackSource::SinkEnabledStateChanged().
|
|
|
|
*
|
|
|
|
* Typically MediaStreamTrack returns the track's enabled state and other
|
|
|
|
* Sinks (like HTMLMediaElement::StreamCaptureTrackSource) return false so
|
|
|
|
* control over device state remains with tracks and their enabled state.
|
|
|
|
*/
|
|
|
|
virtual bool Enabled() const = 0;
|
|
|
|
|
2016-01-22 07:28:57 +03:00
|
|
|
virtual void PrincipalChanged() = 0;
|
2017-11-06 21:03:52 +03:00
|
|
|
virtual void MutedChanged(bool aNewState) = 0;
|
2016-01-22 07:28:57 +03:00
|
|
|
};
|
|
|
|
|
2016-01-22 11:27:37 +03:00
|
|
|
MediaStreamTrackSource(nsIPrincipal* aPrincipal,
|
|
|
|
const nsString& aLabel)
|
2016-01-22 07:28:57 +03:00
|
|
|
: mPrincipal(aPrincipal),
|
2016-01-22 11:27:37 +03:00
|
|
|
mLabel(aLabel),
|
2016-01-22 07:28:57 +03:00
|
|
|
mStopped(false)
|
2016-04-06 15:46:56 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-09 12:52:53 +03:00
|
|
|
/**
|
|
|
|
* Use to clean up any resources that have to be cleaned before the
|
|
|
|
* destructor is called. It is often too late in the destructor because
|
|
|
|
* of garbage collection having removed the members already.
|
|
|
|
*/
|
|
|
|
virtual void Destroy() {}
|
|
|
|
|
2016-04-06 15:46:56 +03:00
|
|
|
/**
|
|
|
|
* Gets the source's MediaSourceEnum for usage by PeerConnections.
|
|
|
|
*/
|
|
|
|
virtual MediaSourceEnum GetMediaSource() const = 0;
|
|
|
|
|
2016-01-22 07:28:57 +03:00
|
|
|
/**
|
|
|
|
* Get this TrackSource's principal.
|
|
|
|
*/
|
|
|
|
nsIPrincipal* GetPrincipal() const { return mPrincipal; }
|
|
|
|
|
2016-01-05 05:16:27 +03:00
|
|
|
/**
|
|
|
|
* Get the source's current CORSMode. If not applicable CORS_NONE is returned.
|
|
|
|
* The sink will be notified of changes to our CORSMode through
|
2016-03-15 12:52:25 +03:00
|
|
|
* PrincipalChanged().
|
2016-01-05 05:16:27 +03:00
|
|
|
*/
|
|
|
|
virtual CORSMode GetCORSMode() const { return CORS_NONE; }
|
|
|
|
|
2016-01-05 05:16:28 +03:00
|
|
|
/**
|
|
|
|
* This is used in WebRTC. A peerIdentity constrained MediaStreamTrack cannot
|
|
|
|
* be sent across the network to anything other than a peer with the provided
|
|
|
|
* identity. If this is set, then GetPrincipal() should return an instance of
|
2017-03-22 13:38:40 +03:00
|
|
|
* NullPrincipal.
|
2016-01-05 05:16:28 +03:00
|
|
|
*
|
|
|
|
* A track's PeerIdentity is immutable and will not change during the track's
|
|
|
|
* lifetime.
|
|
|
|
*/
|
|
|
|
virtual const PeerIdentity* GetPeerIdentity() const { return nullptr; }
|
|
|
|
|
2016-01-22 11:27:37 +03:00
|
|
|
/**
|
|
|
|
* MediaStreamTrack::GetLabel (see spec) calls through to here.
|
|
|
|
*/
|
|
|
|
void GetLabel(nsAString& aLabel) { aLabel.Assign(mLabel); }
|
|
|
|
|
2016-04-06 15:46:56 +03:00
|
|
|
/**
|
|
|
|
* Forwards a photo request to backends that support it. Other backends return
|
|
|
|
* NS_ERROR_NOT_IMPLEMENTED to indicate that a MediaStreamGraph-based fallback
|
|
|
|
* should be used.
|
|
|
|
*/
|
|
|
|
virtual nsresult TakePhoto(MediaEnginePhotoCallback*) const { return NS_ERROR_NOT_IMPLEMENTED; }
|
|
|
|
|
2015-11-19 06:17:09 +03:00
|
|
|
typedef media::Pledge<bool, dom::MediaStreamError*> PledgeVoid;
|
|
|
|
|
2016-02-01 17:43:38 +03:00
|
|
|
/**
|
|
|
|
* We provide a fallback solution to ApplyConstraints() here.
|
|
|
|
* Sources that support ApplyConstraints() will have to override it.
|
|
|
|
*/
|
2015-11-19 06:17:09 +03:00
|
|
|
virtual already_AddRefed<PledgeVoid>
|
2016-02-01 17:43:38 +03:00
|
|
|
ApplyConstraints(nsPIDOMWindowInner* aWindow,
|
2017-02-01 23:43:38 +03:00
|
|
|
const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
CallerType aCallerType);
|
2016-02-01 17:43:38 +03:00
|
|
|
|
2016-06-20 07:38:25 +03:00
|
|
|
/**
|
|
|
|
* Same for GetSettings (no-op).
|
|
|
|
*/
|
|
|
|
virtual void
|
|
|
|
GetSettings(dom::MediaTrackSettings& aResult) {};
|
|
|
|
|
2016-04-06 15:46:56 +03:00
|
|
|
/**
|
2017-11-10 17:08:02 +03:00
|
|
|
* Called by the source interface when all registered sinks with
|
|
|
|
* KeepsSourceAlive() == true have unregistered.
|
2016-04-06 15:46:56 +03:00
|
|
|
*/
|
|
|
|
virtual void Stop() = 0;
|
|
|
|
|
2017-11-10 17:55:42 +03:00
|
|
|
/**
|
|
|
|
* Called by the source interface when all registered sinks with
|
|
|
|
* KeepsSourceAlive() == true become disabled.
|
|
|
|
*/
|
|
|
|
virtual void Disable() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the source interface when at least one registered sink with
|
|
|
|
* KeepsSourceAlive() == true become enabled.
|
|
|
|
*/
|
|
|
|
virtual void Enable() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a Sink's Enabled() state changed. Will iterate through all
|
|
|
|
* sinks and notify the source of the aggregated enabled state.
|
|
|
|
*
|
|
|
|
* Note that a Sink with KeepsSourceAlive() == false counts as disabled.
|
|
|
|
*/
|
|
|
|
void SinkEnabledStateChanged()
|
|
|
|
{
|
|
|
|
if (IsEnabled()) {
|
|
|
|
Enable();
|
|
|
|
} else {
|
|
|
|
Disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 15:46:56 +03:00
|
|
|
/**
|
|
|
|
* Called by each MediaStreamTrack clone on initialization.
|
|
|
|
*/
|
2016-01-22 07:28:57 +03:00
|
|
|
void RegisterSink(Sink* aSink)
|
2016-04-06 15:46:56 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mStopped) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-22 07:28:57 +03:00
|
|
|
mSinks.AppendElement(aSink);
|
2017-11-06 20:04:27 +03:00
|
|
|
while(mSinks.RemoveElement(nullptr)) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Sink was not explicitly removed");
|
|
|
|
}
|
2016-04-06 15:46:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-22 07:28:57 +03:00
|
|
|
* Called by each MediaStreamTrack clone on Stop() if supported by the
|
|
|
|
* source (us) or destruction.
|
2016-04-06 15:46:56 +03:00
|
|
|
*/
|
2016-01-22 07:28:57 +03:00
|
|
|
void UnregisterSink(Sink* aSink)
|
2016-04-06 15:46:56 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-11-06 20:04:27 +03:00
|
|
|
while(mSinks.RemoveElement(nullptr)) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Sink was not explicitly removed");
|
|
|
|
}
|
2017-11-10 17:08:02 +03:00
|
|
|
if (mSinks.RemoveElement(aSink) && !IsActive()) {
|
|
|
|
MOZ_ASSERT(!aSink->KeepsSourceAlive() || !mStopped,
|
|
|
|
"When the last sink keeping the source alive is removed, "
|
|
|
|
"we should still be live");
|
2016-04-06 15:46:56 +03:00
|
|
|
Stop();
|
|
|
|
mStopped = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~MediaStreamTrackSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-10 17:08:02 +03:00
|
|
|
bool IsActive()
|
|
|
|
{
|
|
|
|
for (const WeakPtr<Sink>& sink : mSinks) {
|
|
|
|
if (sink && sink->KeepsSourceAlive()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-10 17:55:42 +03:00
|
|
|
bool IsEnabled()
|
|
|
|
{
|
|
|
|
for (const WeakPtr<Sink>& sink : mSinks) {
|
|
|
|
if (sink && sink->KeepsSourceAlive() && sink->Enabled()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-22 07:28:57 +03:00
|
|
|
/**
|
|
|
|
* Called by a sub class when the principal has changed.
|
|
|
|
* Notifies all sinks.
|
|
|
|
*/
|
|
|
|
void PrincipalChanged()
|
|
|
|
{
|
2017-11-06 20:04:27 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsTArray<WeakPtr<Sink>> sinks(mSinks);
|
|
|
|
for (auto& sink : sinks) {
|
|
|
|
if (!sink) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Sink was not explicitly removed");
|
|
|
|
mSinks.RemoveElement(sink);
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-22 07:28:57 +03:00
|
|
|
sink->PrincipalChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-06 21:03:52 +03:00
|
|
|
/**
|
|
|
|
* Called by a sub class when the source's muted state has changed. Note that
|
|
|
|
* the source is responsible for making the content black/silent during mute.
|
|
|
|
* Notifies all sinks.
|
|
|
|
*/
|
|
|
|
void MutedChanged(bool aNewState)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
nsTArray<WeakPtr<Sink>> sinks(mSinks);
|
|
|
|
for (auto& sink : sinks) {
|
|
|
|
if (!sink) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Sink was not explicitly removed");
|
|
|
|
mSinks.RemoveElement(sink);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sink->MutedChanged(aNewState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-22 07:28:57 +03:00
|
|
|
// Principal identifying who may access the contents of this source.
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
|
|
|
// Currently registered sinks.
|
2017-11-06 20:04:27 +03:00
|
|
|
nsTArray<WeakPtr<Sink>> mSinks;
|
2016-04-06 15:46:56 +03:00
|
|
|
|
2016-01-22 11:27:37 +03:00
|
|
|
// The label of the track we are the source of per the MediaStreamTrack spec.
|
|
|
|
const nsString mLabel;
|
|
|
|
|
2016-09-12 16:59:58 +03:00
|
|
|
// True if all MediaStreamTrack users have unregistered from this source and
|
|
|
|
// Stop() has been called.
|
2016-04-06 15:46:56 +03:00
|
|
|
bool mStopped;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-09-16 16:19:28 +03:00
|
|
|
* Basic implementation of MediaStreamTrackSource that doesn't forward Stop().
|
2016-04-06 15:46:56 +03:00
|
|
|
*/
|
2016-09-16 16:19:28 +03:00
|
|
|
class BasicTrackSource : public MediaStreamTrackSource
|
2016-04-06 15:46:56 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-09-16 16:19:28 +03:00
|
|
|
explicit BasicTrackSource(nsIPrincipal* aPrincipal,
|
|
|
|
const MediaSourceEnum aMediaSource =
|
|
|
|
MediaSourceEnum::Other)
|
2016-09-12 16:59:58 +03:00
|
|
|
: MediaStreamTrackSource(aPrincipal, nsString())
|
2016-01-22 11:27:37 +03:00
|
|
|
, mMediaSource(aMediaSource)
|
|
|
|
{}
|
2016-04-06 15:46:56 +03:00
|
|
|
|
|
|
|
MediaSourceEnum GetMediaSource() const override { return mMediaSource; }
|
|
|
|
|
|
|
|
void Stop() override {}
|
2017-11-10 17:55:42 +03:00
|
|
|
void Disable() override {}
|
|
|
|
void Enable() override {}
|
2016-04-06 15:46:56 +03:00
|
|
|
|
|
|
|
protected:
|
2016-09-16 16:19:28 +03:00
|
|
|
~BasicTrackSource() {}
|
2016-04-06 15:46:56 +03:00
|
|
|
|
|
|
|
const MediaSourceEnum mMediaSource;
|
|
|
|
};
|
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
/**
|
|
|
|
* Base class that consumers of a MediaStreamTrack can use to get notifications
|
|
|
|
* about state changes in the track.
|
|
|
|
*/
|
2017-10-10 21:48:58 +03:00
|
|
|
class MediaStreamTrackConsumer
|
|
|
|
: public SupportsWeakPtr<MediaStreamTrackConsumer>
|
2016-09-23 18:03:13 +03:00
|
|
|
{
|
|
|
|
public:
|
2017-10-10 21:48:58 +03:00
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaStreamTrackConsumer)
|
2016-09-23 18:03:13 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the track's readyState transitions to "ended".
|
|
|
|
* Unlike the "ended" event exposed to script this is called for any reason,
|
|
|
|
* including MediaStreamTrack::Stop().
|
|
|
|
*/
|
|
|
|
virtual void NotifyEnded(MediaStreamTrack* aTrack) {};
|
|
|
|
};
|
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
/**
|
|
|
|
* Class representing a track in a DOMMediaStream.
|
|
|
|
*/
|
2016-01-22 07:28:57 +03:00
|
|
|
class MediaStreamTrack : public DOMEventTargetHelper,
|
|
|
|
public MediaStreamTrackSource::Sink
|
|
|
|
{
|
2016-03-16 18:08:43 +03:00
|
|
|
// DOMMediaStream owns MediaStreamTrack instances, and requires access to
|
|
|
|
// some internal state, e.g., GetInputStream(), GetOwnedStream().
|
|
|
|
friend class mozilla::DOMMediaStream;
|
|
|
|
|
2016-02-01 17:48:05 +03:00
|
|
|
// PeerConnection and friends need to know our owning DOMStream and track id.
|
2016-01-15 07:48:51 +03:00
|
|
|
friend class mozilla::PeerConnectionImpl;
|
2016-03-18 16:21:51 +03:00
|
|
|
friend class mozilla::PeerConnectionMedia;
|
2016-05-23 18:22:01 +03:00
|
|
|
friend class mozilla::SourceStreamInfo;
|
2016-02-01 17:48:05 +03:00
|
|
|
friend class mozilla::RemoteSourceStreamInfo;
|
2016-01-15 07:48:51 +03:00
|
|
|
|
2016-03-15 12:52:25 +03:00
|
|
|
class PrincipalHandleListener;
|
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* aTrackID is the MediaStreamGraph track ID for the track in the
|
|
|
|
* MediaStream owned by aStream.
|
|
|
|
*/
|
2016-04-06 15:46:56 +03:00
|
|
|
MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
|
2015-11-25 07:42:26 +03:00
|
|
|
TrackID aInputTrackID,
|
|
|
|
MediaStreamTrackSource* aSource,
|
|
|
|
const MediaTrackConstraints& aConstraints = MediaTrackConstraints());
|
2013-03-27 05:32:51 +04:00
|
|
|
|
2013-05-01 15:24:16 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamTrack,
|
|
|
|
DOMEventTargetHelper)
|
2013-03-27 05:32:51 +04:00
|
|
|
|
2016-02-01 17:48:05 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override = 0;
|
2013-03-27 05:32:51 +04:00
|
|
|
|
|
|
|
virtual AudioStreamTrack* AsAudioStreamTrack() { return nullptr; }
|
|
|
|
virtual VideoStreamTrack* AsVideoStreamTrack() { return nullptr; }
|
|
|
|
|
2016-02-01 17:43:38 +03:00
|
|
|
virtual const AudioStreamTrack* AsAudioStreamTrack() const { return nullptr; }
|
|
|
|
virtual const VideoStreamTrack* AsVideoStreamTrack() const { return nullptr; }
|
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
// WebIDL
|
|
|
|
virtual void GetKind(nsAString& aKind) = 0;
|
2014-12-10 22:17:09 +03:00
|
|
|
void GetId(nsAString& aID) const;
|
2017-10-13 06:57:25 +03:00
|
|
|
virtual void GetLabel(nsAString& aLabel, CallerType /* aCallerType */) { GetSource().GetLabel(aLabel); }
|
2017-11-10 17:55:42 +03:00
|
|
|
bool Enabled() const override { return mEnabled; }
|
2013-05-30 08:44:43 +04:00
|
|
|
void SetEnabled(bool aEnabled);
|
2017-11-06 21:03:52 +03:00
|
|
|
bool Muted() { return mMuted; }
|
2014-08-27 09:03:49 +04:00
|
|
|
void Stop();
|
2015-11-14 07:27:39 +03:00
|
|
|
void GetConstraints(dom::MediaTrackConstraints& aResult);
|
2017-10-13 06:57:25 +03:00
|
|
|
void GetSettings(dom::MediaTrackSettings& aResult, CallerType aCallerType);
|
2015-11-14 07:27:39 +03:00
|
|
|
|
2015-09-21 01:45:57 +03:00
|
|
|
already_AddRefed<Promise>
|
2017-02-01 23:43:38 +03:00
|
|
|
ApplyConstraints(const dom::MediaTrackConstraints& aConstraints,
|
|
|
|
CallerType aCallerType, ErrorResult &aRv);
|
2016-01-22 11:27:51 +03:00
|
|
|
already_AddRefed<MediaStreamTrack> Clone();
|
2016-05-10 18:03:37 +03:00
|
|
|
MediaStreamTrackState ReadyState() { return mReadyState; }
|
2013-03-27 05:32:51 +04:00
|
|
|
|
2017-11-06 21:03:52 +03:00
|
|
|
IMPL_EVENT_HANDLER(mute)
|
|
|
|
IMPL_EVENT_HANDLER(unmute)
|
2016-05-10 18:03:29 +03:00
|
|
|
IMPL_EVENT_HANDLER(ended)
|
|
|
|
|
2016-05-10 18:03:37 +03:00
|
|
|
/**
|
|
|
|
* Convenience (and legacy) method for when ready state is "ended".
|
|
|
|
*/
|
|
|
|
bool Ended() const { return mReadyState == MediaStreamTrackState::Ended; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forces the ready state to a particular value, for instance when we're
|
|
|
|
* cloning an already ended track.
|
|
|
|
*/
|
2016-08-22 19:28:10 +03:00
|
|
|
void SetReadyState(MediaStreamTrackState aState);
|
2016-05-10 18:03:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notified by the MediaStreamGraph, through our owning MediaStream on the
|
|
|
|
* main thread.
|
|
|
|
*
|
|
|
|
* Note that this sets the track to ended and raises the "ended" event
|
|
|
|
* synchronously.
|
|
|
|
*/
|
2016-09-08 12:06:21 +03:00
|
|
|
void OverrideEnded();
|
2013-03-27 05:32:51 +04:00
|
|
|
|
2016-01-22 06:24:16 +03:00
|
|
|
/**
|
|
|
|
* Get this track's principal.
|
|
|
|
*/
|
2016-03-15 12:52:25 +03:00
|
|
|
nsIPrincipal* GetPrincipal() const { return mPrincipal; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the PrincipalHandleListener when this track's PrincipalHandle changes on
|
|
|
|
* the MediaStreamGraph thread. When the PrincipalHandle matches the pending
|
|
|
|
* principal we know that the principal change has propagated to consumers.
|
|
|
|
*/
|
|
|
|
void NotifyPrincipalHandleChanged(const PrincipalHandle& aPrincipalHandle);
|
2016-01-22 06:24:16 +03:00
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
/**
|
|
|
|
* Called when this track's readyState transitions to "ended".
|
|
|
|
* Notifies all MediaStreamTrackConsumers that this track ended.
|
|
|
|
*/
|
|
|
|
void NotifyEnded();
|
|
|
|
|
2016-01-05 05:16:27 +03:00
|
|
|
/**
|
|
|
|
* Get this track's CORS mode.
|
|
|
|
*/
|
|
|
|
CORSMode GetCORSMode() const { return GetSource().GetCORSMode(); }
|
|
|
|
|
2016-01-05 05:16:28 +03:00
|
|
|
/**
|
|
|
|
* Get this track's PeerIdentity.
|
|
|
|
*/
|
|
|
|
const PeerIdentity* GetPeerIdentity() const { return GetSource().GetPeerIdentity(); }
|
|
|
|
|
2016-01-05 05:16:23 +03:00
|
|
|
MediaStreamGraph* Graph();
|
2016-03-18 16:21:51 +03:00
|
|
|
MediaStreamGraphImpl* GraphImpl();
|
2016-01-05 05:16:23 +03:00
|
|
|
|
2016-04-06 15:46:56 +03:00
|
|
|
MediaStreamTrackSource& GetSource() const
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(mSource, "The track source is only removed on destruction");
|
|
|
|
return *mSource;
|
|
|
|
}
|
|
|
|
|
2014-12-10 22:17:09 +03:00
|
|
|
// Webrtc allows the remote side to name tracks whatever it wants, and we
|
|
|
|
// need to surface this to content.
|
|
|
|
void AssignId(const nsAString& aID) { mID = aID; }
|
|
|
|
|
2016-01-22 07:28:57 +03:00
|
|
|
// Implementation of MediaStreamTrackSource::Sink
|
2017-11-10 17:08:02 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep the track source alive. This track and any clones are controlling the
|
|
|
|
* lifetime of the source by being registered as its sinks.
|
|
|
|
*/
|
|
|
|
bool KeepsSourceAlive() const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-22 07:28:57 +03:00
|
|
|
void PrincipalChanged() override;
|
2017-11-10 17:08:02 +03:00
|
|
|
|
2017-11-06 21:03:52 +03:00
|
|
|
/**
|
|
|
|
* 4.3.1 Life-cycle and Media flow - Media flow
|
|
|
|
* To set a track's muted state to newState, the User Agent MUST run the
|
|
|
|
* following steps:
|
|
|
|
* 1. Let track be the MediaStreamTrack in question.
|
|
|
|
* 2. Set track's muted attribute to newState.
|
|
|
|
* 3. If newState is true let eventName be mute, otherwise unmute.
|
|
|
|
* 4. Fire a simple event named eventName on track.
|
|
|
|
*/
|
|
|
|
void MutedChanged(bool aNewState) override;
|
2016-01-22 07:28:57 +03:00
|
|
|
|
2016-01-22 06:24:16 +03:00
|
|
|
/**
|
|
|
|
* Add a PrincipalChangeObserver to this track.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
bool AddPrincipalChangeObserver(PrincipalChangeObserver<MediaStreamTrack>* aObserver);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an added PrincipalChangeObserver from this track.
|
|
|
|
*
|
|
|
|
* Returns true if it was successfully removed.
|
|
|
|
*/
|
|
|
|
bool RemovePrincipalChangeObserver(PrincipalChangeObserver<MediaStreamTrack>* aObserver);
|
|
|
|
|
2016-09-23 18:03:13 +03:00
|
|
|
/**
|
|
|
|
* Add a MediaStreamTrackConsumer to this track.
|
|
|
|
*
|
|
|
|
* Adding the same consumer multiple times is prohibited.
|
|
|
|
*/
|
|
|
|
void AddConsumer(MediaStreamTrackConsumer* aConsumer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an added MediaStreamTrackConsumer from this track.
|
|
|
|
*/
|
|
|
|
void RemoveConsumer(MediaStreamTrackConsumer* aConsumer);
|
|
|
|
|
2016-03-03 19:27:59 +03:00
|
|
|
/**
|
|
|
|
* Adds a MediaStreamTrackListener to the MediaStreamGraph representation of
|
|
|
|
* this track.
|
|
|
|
*/
|
2017-01-10 17:57:16 +03:00
|
|
|
virtual void AddListener(MediaStreamTrackListener* aListener);
|
2016-03-03 19:27:59 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a MediaStreamTrackListener from the MediaStreamGraph representation
|
|
|
|
* of this track.
|
|
|
|
*/
|
|
|
|
void RemoveListener(MediaStreamTrackListener* aListener);
|
|
|
|
|
2016-03-03 19:28:37 +03:00
|
|
|
/**
|
|
|
|
* Attempts to add a direct track listener to this track.
|
|
|
|
* Callers must listen to the NotifyInstalled event to know if installing
|
|
|
|
* the listener succeeded (tracks originating from SourceMediaStreams) or
|
|
|
|
* failed (e.g., WebAudio originated tracks).
|
|
|
|
*/
|
2017-01-10 17:57:16 +03:00
|
|
|
virtual void AddDirectListener(DirectMediaStreamTrackListener *aListener);
|
2016-04-29 06:45:25 +03:00
|
|
|
void RemoveDirectListener(DirectMediaStreamTrackListener *aListener);
|
2016-03-03 19:28:37 +03:00
|
|
|
|
2016-01-05 05:16:27 +03:00
|
|
|
/**
|
|
|
|
* Sets up a MediaInputPort from the underlying track that this
|
|
|
|
* MediaStreamTrack represents, to aStream, and returns it.
|
|
|
|
*/
|
2016-07-06 11:37:28 +03:00
|
|
|
already_AddRefed<MediaInputPort> ForwardTrackContentsTo(ProcessedMediaStream* aStream,
|
|
|
|
TrackID aDestinationTrackID = TRACK_ANY);
|
2016-01-05 05:16:27 +03:00
|
|
|
|
2016-01-05 05:16:29 +03:00
|
|
|
/**
|
|
|
|
* Returns true if this track is connected to aPort and forwarded to aPort's
|
|
|
|
* output stream.
|
|
|
|
*/
|
|
|
|
bool IsForwardedThrough(MediaInputPort* aPort);
|
|
|
|
|
2016-05-10 12:02:15 +03:00
|
|
|
void SetMediaStreamSizeListener(DirectMediaStreamTrackListener* aListener);
|
|
|
|
|
2017-11-30 23:47:13 +03:00
|
|
|
// Returns the original DOMMediaStream's underlying input stream.
|
|
|
|
MediaStream* GetInputStream();
|
|
|
|
|
|
|
|
TrackID GetInputTrackId() const
|
|
|
|
{
|
|
|
|
return mInputTrackID;
|
|
|
|
}
|
|
|
|
|
2013-03-27 05:32:51 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~MediaStreamTrack();
|
|
|
|
|
2017-11-06 21:03:52 +03:00
|
|
|
/**
|
|
|
|
* Sets this track's muted state without raising any events.
|
|
|
|
*/
|
|
|
|
void SetMuted(bool aMuted) { mMuted = aMuted; }
|
|
|
|
|
2016-03-15 12:52:25 +03:00
|
|
|
void Destroy();
|
|
|
|
|
2016-01-05 05:16:22 +03:00
|
|
|
// Returns the owning DOMMediaStream's underlying owned stream.
|
|
|
|
ProcessedMediaStream* GetOwnedStream();
|
|
|
|
|
|
|
|
// Returns the original DOMMediaStream. If this track is a clone,
|
|
|
|
// the original track's owning DOMMediaStream is returned.
|
|
|
|
DOMMediaStream* GetInputDOMStream();
|
|
|
|
|
2016-03-15 12:52:25 +03:00
|
|
|
/**
|
|
|
|
* Sets the principal and notifies PrincipalChangeObservers if it changes.
|
|
|
|
*/
|
|
|
|
void SetPrincipal(nsIPrincipal* aPrincipal);
|
|
|
|
|
2016-01-22 11:27:51 +03:00
|
|
|
/**
|
|
|
|
* Creates a new MediaStreamTrack with the same type, input track ID and
|
|
|
|
* source as this MediaStreamTrack.
|
|
|
|
* aTrackID is the TrackID the new track will have in its owned stream.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<MediaStreamTrack> CloneInternal(DOMMediaStream* aOwningStream,
|
|
|
|
TrackID aTrackID) = 0;
|
|
|
|
|
2016-01-22 06:24:16 +03:00
|
|
|
nsTArray<PrincipalChangeObserver<MediaStreamTrack>*> mPrincipalChangeObservers;
|
|
|
|
|
2017-10-10 21:48:58 +03:00
|
|
|
nsTArray<WeakPtr<MediaStreamTrackConsumer>> mConsumers;
|
2016-09-23 18:03:13 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMMediaStream> mOwningStream;
|
2013-03-27 05:32:51 +04:00
|
|
|
TrackID mTrackID;
|
2016-04-06 15:46:56 +03:00
|
|
|
TrackID mInputTrackID;
|
|
|
|
RefPtr<MediaStreamTrackSource> mSource;
|
2016-01-05 05:16:21 +03:00
|
|
|
RefPtr<MediaStreamTrack> mOriginalTrack;
|
2016-03-15 12:52:25 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPendingPrincipal;
|
|
|
|
RefPtr<PrincipalHandleListener> mPrincipalHandleListener;
|
2016-05-10 12:02:15 +03:00
|
|
|
// Keep tracking MediaStreamTrackListener and DirectMediaStreamTrackListener,
|
|
|
|
// so we can remove them in |Destory|.
|
|
|
|
nsTArray<RefPtr<MediaStreamTrackListener>> mTrackListeners;
|
|
|
|
nsTArray<RefPtr<DirectMediaStreamTrackListener>> mDirectTrackListeners;
|
2014-12-10 22:17:09 +03:00
|
|
|
nsString mID;
|
2016-05-10 18:03:37 +03:00
|
|
|
MediaStreamTrackState mReadyState;
|
2013-05-30 08:44:43 +04:00
|
|
|
bool mEnabled;
|
2017-11-06 21:03:52 +03:00
|
|
|
bool mMuted;
|
2015-11-14 07:27:39 +03:00
|
|
|
dom::MediaTrackConstraints mConstraints;
|
2013-03-27 05:32:51 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-03-27 05:32:51 +04:00
|
|
|
|
|
|
|
#endif /* MEDIASTREAMTRACK_H_ */
|