Bug 1299515 - Plumb MediaStreamTrack enabled state to sources. r=jib

MozReview-Commit-ID: Eg1g9JtLmOz

--HG--
extra : rebase_source : 73057e1093d487736f69addca346b05c48d8d280
This commit is contained in:
Andreas Pehrson 2017-11-10 15:55:42 +01:00
Родитель aa75f0c28e
Коммит 85ded5b958
8 изменённых файлов: 236 добавлений и 1 удалений

Просмотреть файл

@ -720,6 +720,14 @@ public:
mCaptureStream->StopCapture();
}
void Disable() override
{
}
void Enable() override
{
}
private:
virtual ~CanvasCaptureTrackSource() {}

Просмотреть файл

@ -3248,6 +3248,22 @@ public:
return false;
}
/**
* Do not keep the track source on. It is controlled by its associated tracks.
*/
bool Enabled() const override
{
return false;
}
void Disable() override
{
}
void Enable() override
{
}
void PrincipalChanged() override
{
if (!mCapturedTrackSource) {
@ -3341,6 +3357,14 @@ public:
// based on MediaStreams during capture.
}
void Disable() override
{
}
void Enable() override
{
}
void NotifyDecoderPrincipalChanged() override
{
nsCOMPtr<nsIPrincipal> newPrincipal = mElement->GetCurrentPrincipal();

Просмотреть файл

@ -187,6 +187,19 @@ public:
*/
void StopTrack(TrackID aTrackID);
/**
* Posts a task to disable the device associated with aTrackID and notifies
* the associated window listener that a track has been disabled.
*/
void DisableTrack(TrackID aTrackID);
/**
* Posts a task to enable the device associated with aTrackID and notifies
* the associated window listener that a track has been enabled.
*/
void EnableTrack(TrackID aTrackID);
/**
* Stops all screen/app/window/audioCapture sharing, but not camera or
* microphone.
@ -1119,6 +1132,20 @@ public:
}
}
void Disable() override
{
if (mListener) {
mListener->DisableTrack(mTrackID);
}
}
void Enable() override
{
if (mListener) {
mListener->EnableTrack(mTrackID);
}
}
protected:
~LocalTrackSource() {}
@ -3810,6 +3837,102 @@ SourceListener::StopTrack(TrackID aTrackID)
mWindowListener->NotifySourceTrackStopped();
}
void
SourceListener::DisableTrack(TrackID aTrackID)
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
if (!Activated()) {
MOZ_ASSERT(false, "No device to disable");
return;
}
RefPtr<MediaDevice> device;
switch (aTrackID) {
case kAudioTrack: {
LOG(("SourceListener %p disabling audio track %d", this, aTrackID));
if (!mAudioDevice) {
NS_ASSERTION(false, "Can't disable audio. No device.");
return;
}
if (mAudioStopped) {
// Audio stopped. Disabling is pointless.
return;
}
device = mAudioDevice;
break;
}
case kVideoTrack: {
LOG(("SourceListener %p disabling video track %d", this, aTrackID));
if (!mVideoDevice) {
NS_ASSERTION(false, "Can't disable video. No device.");
return;
}
if (mVideoStopped) {
// Video stopped. Disabling is pointless.
return;
}
device = mVideoDevice;
break;
}
default: {
MOZ_ASSERT(false, "Unknown track id");
return;
}
}
// XXX Later patch
}
void
SourceListener::EnableTrack(TrackID aTrackID)
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread");
if (!Activated()) {
MOZ_ASSERT(false, "No device to enable");
return;
}
RefPtr<MediaDevice> device;
switch (aTrackID) {
case kAudioTrack: {
LOG(("SourceListener %p enabling audio track %d", this, aTrackID));
if (!mAudioDevice) {
NS_ASSERTION(false, "Can't enable audio. No device.");
return;
}
if (mAudioStopped) {
// Audio stopped. Enabling is pointless.
return;
}
device = mAudioDevice;
break;
}
case kVideoTrack: {
LOG(("SourceListener %p enabling video track %d", this, aTrackID));
if (!mVideoDevice) {
NS_ASSERTION(false, "Can't enable video. No device.");
return;
}
if (mVideoStopped) {
// Video stopped. Enabling is pointless.
return;
}
device = mVideoDevice;
break;
}
default: {
MOZ_ASSERT(false, "Unknown track id");
return;
}
}
// XXX Later patch
}
void
SourceListener::StopSharing()
{

Просмотреть файл

@ -222,6 +222,7 @@ MediaStreamTrack::SetEnabled(bool aEnabled)
mEnabled = aEnabled;
GetOwnedStream()->SetTrackEnabled(mTrackID, mEnabled ? DisabledTrackMode::ENABLED
: DisabledTrackMode::SILENCE_BLACK);
GetSource().SinkEnabledStateChanged();
}
void

Просмотреть файл

@ -74,6 +74,21 @@ public:
*/
virtual bool KeepsSourceAlive() const = 0;
/**
* 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;
virtual void PrincipalChanged() = 0;
virtual void MutedChanged(bool aNewState) = 0;
};
@ -156,6 +171,33 @@ public:
*/
virtual void Stop() = 0;
/**
* 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();
}
}
/**
* Called by each MediaStreamTrack clone on initialization.
*/
@ -205,6 +247,16 @@ protected:
return false;
}
bool IsEnabled()
{
for (const WeakPtr<Sink>& sink : mSinks) {
if (sink && sink->KeepsSourceAlive() && sink->Enabled()) {
return true;
}
}
return false;
}
/**
* Called by a sub class when the principal has changed.
* Notifies all sinks.
@ -272,6 +324,8 @@ public:
MediaSourceEnum GetMediaSource() const override { return mMediaSource; }
void Stop() override {}
void Disable() override {}
void Enable() override {}
protected:
~BasicTrackSource() {}
@ -342,7 +396,7 @@ public:
virtual void GetKind(nsAString& aKind) = 0;
void GetId(nsAString& aID) const;
virtual void GetLabel(nsAString& aLabel, CallerType /* aCallerType */) { GetSource().GetLabel(aLabel); }
bool Enabled() { return mEnabled; }
bool Enabled() const override { return mEnabled; }
void SetEnabled(bool aEnabled);
bool Muted() { return mMuted; }
void Stop();

Просмотреть файл

@ -49,6 +49,14 @@ public:
Destroy();
}
void Disable() override
{
}
void Enable() override
{
}
private:
~AudioDestinationTrackSource() = default;

Просмотреть файл

@ -72,6 +72,15 @@ public:
return mozilla::dom::MediaSourceEnum::Microphone;
}
virtual void Disable() override
{
}
virtual void Enable() override
{
}
virtual void Stop() override
{
}

Просмотреть файл

@ -40,6 +40,14 @@ public:
// clarity in the spec.
}
void Disable() override
{
}
void Enable() override
{
}
void SetPrincipal(nsIPrincipal* aPrincipal)
{
mPrincipal = aPrincipal;