зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1208378 - Implement MediaStreamTrack's muted state and events. r=jib,smaug
MozReview-Commit-ID: 1Sp9utMnWXI --HG-- extra : rebase_source : f2d1036ab37ed9882c0bb9aa1d7b7d68eb7799e4
This commit is contained in:
Родитель
2b9f5cc3cc
Коммит
167e43c316
|
@ -726,6 +726,7 @@ GK_ATOM(moz_action_hint, "mozactionhint")
|
|||
GK_ATOM(x_moz_errormessage, "x-moz-errormessage")
|
||||
GK_ATOM(multicol, "multicol")
|
||||
GK_ATOM(multiple, "multiple")
|
||||
GK_ATOM(mute, "mute")
|
||||
GK_ATOM(muted, "muted")
|
||||
GK_ATOM(name, "name")
|
||||
GK_ATOM(_namespace, "namespace")
|
||||
|
@ -946,6 +947,7 @@ GK_ATOM(onmapgetmessagereq, "onmapgetmessagereq")
|
|||
GK_ATOM(onmapsetmessagestatusreq, "onmapsetmessagestatusreq")
|
||||
GK_ATOM(onmapsendmessagereq, "onmapsendmessagereq")
|
||||
GK_ATOM(onmapmessageupdatereq, "onmapmessageupdatereq")
|
||||
GK_ATOM(onmute, "onmute")
|
||||
GK_ATOM(onnewrdsgroup, "onnewrdsgroup")
|
||||
GK_ATOM(onnotificationclick, "onnotificationclick")
|
||||
GK_ATOM(onnotificationclose, "onnotificationclose")
|
||||
|
@ -1037,6 +1039,7 @@ GK_ATOM(ontransitionrun, "ontransitionrun")
|
|||
GK_ATOM(ontransitionstart, "ontransitionstart")
|
||||
GK_ATOM(onunderflow, "onunderflow")
|
||||
GK_ATOM(onunload, "onunload")
|
||||
GK_ATOM(onunmute, "onunmute")
|
||||
GK_ATOM(onupdatefound, "onupdatefound")
|
||||
GK_ATOM(onupdateready, "onupdateready")
|
||||
GK_ATOM(onupgradeneeded, "onupgradeneeded")
|
||||
|
@ -1388,6 +1391,7 @@ GK_ATOM(ul, "ul")
|
|||
GK_ATOM(underflow, "underflow")
|
||||
GK_ATOM(undetermined, "undetermined")
|
||||
GK_ATOM(unload, "unload")
|
||||
GK_ATOM(unmute, "unmute")
|
||||
GK_ATOM(unparsedEntityUri, "unparsed-entity-uri")
|
||||
GK_ATOM(upperAlpha, "upper-alpha")
|
||||
GK_ATOM(upperFirst, "upper-first")
|
||||
|
|
|
@ -3209,6 +3209,16 @@ public:
|
|||
MediaStreamTrackSource::PrincipalChanged();
|
||||
}
|
||||
|
||||
void MutedChanged(bool aNewState) override
|
||||
{
|
||||
if (!mCapturedTrackSource) {
|
||||
// This could happen during shutdown.
|
||||
return;
|
||||
}
|
||||
|
||||
MediaStreamTrackSource::MutedChanged(aNewState);
|
||||
}
|
||||
|
||||
private:
|
||||
virtual ~StreamCaptureTrackSource() {}
|
||||
|
||||
|
|
|
@ -1204,6 +1204,7 @@ DOMMediaStream::CloneDOMTrack(MediaStreamTrack& aTrack,
|
|||
NotifyTrackAdded(newTrack);
|
||||
|
||||
newTrack->SetEnabled(aTrack.Enabled());
|
||||
newTrack->SetMuted(aTrack.Muted());
|
||||
newTrack->SetReadyState(aTrack.ReadyState());
|
||||
|
||||
if (aTrack.Ended()) {
|
||||
|
|
|
@ -124,7 +124,7 @@ MediaStreamTrack::MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
|
|||
mInputTrackID(aInputTrackID), mSource(aSource),
|
||||
mPrincipal(aSource->GetPrincipal()),
|
||||
mReadyState(MediaStreamTrackState::Live),
|
||||
mEnabled(true), mConstraints(aConstraints)
|
||||
mEnabled(true), mMuted(false), mConstraints(aConstraints)
|
||||
{
|
||||
GetSource().RegisterSink(this);
|
||||
|
||||
|
@ -373,6 +373,25 @@ MediaStreamTrack::NotifyPrincipalHandleChanged(const PrincipalHandle& aNewPrinci
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
MediaStreamTrack::MutedChanged(bool aNewState)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (mMuted == aNewState) {
|
||||
MOZ_ASSERT_UNREACHABLE("Muted state didn't actually change");
|
||||
return;
|
||||
}
|
||||
|
||||
LOG(LogLevel::Info, ("MediaStreamTrack %p became %s",
|
||||
this, aNewState ? "muted" : "unmuted"));
|
||||
|
||||
mMuted = aNewState;
|
||||
nsString eventName =
|
||||
aNewState ? NS_LITERAL_STRING("mute") : NS_LITERAL_STRING("unmute");
|
||||
DispatchTrustedEvent(eventName);
|
||||
}
|
||||
|
||||
void
|
||||
MediaStreamTrack::NotifyEnded()
|
||||
{
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
public:
|
||||
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(MediaStreamTrackSource::Sink)
|
||||
virtual void PrincipalChanged() = 0;
|
||||
virtual void MutedChanged(bool aNewState) = 0;
|
||||
};
|
||||
|
||||
MediaStreamTrackSource(nsIPrincipal* aPrincipal,
|
||||
|
@ -196,6 +197,25 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
// Principal identifying who may access the contents of this source.
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
|
||||
|
@ -298,6 +318,7 @@ public:
|
|||
virtual void GetLabel(nsAString& aLabel, CallerType /* aCallerType */) { GetSource().GetLabel(aLabel); }
|
||||
bool Enabled() { return mEnabled; }
|
||||
void SetEnabled(bool aEnabled);
|
||||
bool Muted() { return mMuted; }
|
||||
void Stop();
|
||||
void GetConstraints(dom::MediaTrackConstraints& aResult);
|
||||
void GetSettings(dom::MediaTrackSettings& aResult, CallerType aCallerType);
|
||||
|
@ -308,6 +329,8 @@ public:
|
|||
already_AddRefed<MediaStreamTrack> Clone();
|
||||
MediaStreamTrackState ReadyState() { return mReadyState; }
|
||||
|
||||
IMPL_EVENT_HANDLER(mute)
|
||||
IMPL_EVENT_HANDLER(unmute)
|
||||
IMPL_EVENT_HANDLER(ended)
|
||||
|
||||
/**
|
||||
|
@ -373,6 +396,16 @@ public:
|
|||
|
||||
// Implementation of MediaStreamTrackSource::Sink
|
||||
void PrincipalChanged() override;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Add a PrincipalChangeObserver to this track.
|
||||
|
@ -442,6 +475,11 @@ public:
|
|||
protected:
|
||||
virtual ~MediaStreamTrack();
|
||||
|
||||
/**
|
||||
* Sets this track's muted state without raising any events.
|
||||
*/
|
||||
void SetMuted(bool aMuted) { mMuted = aMuted; }
|
||||
|
||||
void Destroy();
|
||||
|
||||
// Returns the original DOMMediaStream's underlying input stream.
|
||||
|
@ -486,6 +524,7 @@ protected:
|
|||
nsString mID;
|
||||
MediaStreamTrackState mReadyState;
|
||||
bool mEnabled;
|
||||
bool mMuted;
|
||||
dom::MediaTrackConstraints mConstraints;
|
||||
};
|
||||
|
||||
|
|
|
@ -80,11 +80,9 @@ interface MediaStreamTrack : EventTarget {
|
|||
[NeedsCallerType]
|
||||
readonly attribute DOMString label;
|
||||
attribute boolean enabled;
|
||||
// readonly attribute boolean muted;
|
||||
// attribute EventHandler onmute;
|
||||
// attribute EventHandler onunmute;
|
||||
// readonly attribute boolean _readonly;
|
||||
// readonly attribute boolean remote;
|
||||
readonly attribute boolean muted;
|
||||
attribute EventHandler onmute;
|
||||
attribute EventHandler onunmute;
|
||||
readonly attribute MediaStreamTrackState readyState;
|
||||
attribute EventHandler onended;
|
||||
MediaStreamTrack clone ();
|
||||
|
|
Загрузка…
Ссылка в новой задаче