Bug 1208373 - Implement MediaStreamTrack.readyState. r=smaug,jib

MozReview-Commit-ID: EoMaG0R3Dpp

--HG--
extra : rebase_source : 96ffe09a577f951b1d960434aa3b2de9d4aa2c4b
extra : intermediate-source : 2b5684b6362e51af2e90115e2b855662358b51b4
extra : source : eb945c96027405effd2138a069eabd68f192f15c
This commit is contained in:
Andreas Pehrson 2016-05-10 17:03:37 +02:00
parent 416244b4cf
commit bc991593cb
4 changed files with 34 additions and 10 deletions

View File

@ -1035,6 +1035,15 @@ DOMMediaStream::CloneDOMTrack(MediaStreamTrack& aTrack,
NotifyTrackAdded(newTrack); NotifyTrackAdded(newTrack);
newTrack->SetEnabled(aTrack.Enabled()); newTrack->SetEnabled(aTrack.Enabled());
newTrack->SetReadyState(aTrack.ReadyState());
if (aTrack.Ended()) {
// For extra suspenders, make sure that we don't forward data by mistake
// to the clone when the original has already ended.
RefPtr<Pledge<bool, nsresult>> blockingPledge =
inputPort->BlockSourceTrackId(inputTrackID);
Unused << blockingPledge;
}
return newTrack.forget(); return newTrack.forget();
} }

View File

@ -115,7 +115,8 @@ MediaStreamTrack::MediaStreamTrack(DOMMediaStream* aStream, TrackID aTrackID,
: mOwningStream(aStream), mTrackID(aTrackID), : mOwningStream(aStream), mTrackID(aTrackID),
mInputTrackID(aInputTrackID), mSource(aSource), mInputTrackID(aInputTrackID), mSource(aSource),
mPrincipal(aSource->GetPrincipal()), mPrincipal(aSource->GetPrincipal()),
mEnded(false), mEnabled(true), mRemote(aSource->IsRemote()), mStopped(false) mReadyState(MediaStreamTrackState::Live),
mEnabled(true), mRemote(aSource->IsRemote())
{ {
if (!gMediaStreamTrackLog) { if (!gMediaStreamTrackLog) {
@ -216,8 +217,8 @@ MediaStreamTrack::Stop()
{ {
LOG(LogLevel::Info, ("MediaStreamTrack %p Stop()", this)); LOG(LogLevel::Info, ("MediaStreamTrack %p Stop()", this));
if (mStopped) { if (Ended()) {
LOG(LogLevel::Warning, ("MediaStreamTrack %p Already stopped", this)); LOG(LogLevel::Warning, ("MediaStreamTrack %p Already ended", this));
return; return;
} }
@ -239,7 +240,7 @@ MediaStreamTrack::Stop()
RefPtr<Pledge<bool>> p = port->BlockSourceTrackId(mInputTrackID); RefPtr<Pledge<bool>> p = port->BlockSourceTrackId(mInputTrackID);
Unused << p; Unused << p;
mStopped = true; mReadyState = MediaStreamTrackState::Ended;
} }
already_AddRefed<Promise> already_AddRefed<Promise>
@ -355,13 +356,13 @@ MediaStreamTrack::NotifyEnded()
{ {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
if (mEnded) { if (Ended()) {
return; return;
} }
LOG(LogLevel::Info, ("MediaStreamTrack %p ended", this)); LOG(LogLevel::Info, ("MediaStreamTrack %p ended", this));
mEnded = true; mReadyState = MediaStreamTrackState::Ended;
DispatchTrustedEvent(NS_LITERAL_STRING("ended")); DispatchTrustedEvent(NS_LITERAL_STRING("ended"));
} }

View File

@ -266,10 +266,20 @@ public:
already_AddRefed<Promise> already_AddRefed<Promise>
ApplyConstraints(const dom::MediaTrackConstraints& aConstraints, ErrorResult &aRv); ApplyConstraints(const dom::MediaTrackConstraints& aConstraints, ErrorResult &aRv);
already_AddRefed<MediaStreamTrack> Clone(); already_AddRefed<MediaStreamTrack> Clone();
MediaStreamTrackState ReadyState() { return mReadyState; }
IMPL_EVENT_HANDLER(ended) IMPL_EVENT_HANDLER(ended)
bool Ended() const { return mEnded; } /**
* 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.
*/
void SetReadyState(MediaStreamTrackState aState) { mReadyState = aState; }
/** /**
* Notified by the MediaStreamGraph, through our owning MediaStream on the * Notified by the MediaStreamGraph, through our owning MediaStream on the
@ -407,10 +417,9 @@ protected:
nsCOMPtr<nsIPrincipal> mPendingPrincipal; nsCOMPtr<nsIPrincipal> mPendingPrincipal;
RefPtr<PrincipalHandleListener> mPrincipalHandleListener; RefPtr<PrincipalHandleListener> mPrincipalHandleListener;
nsString mID; nsString mID;
bool mEnded; MediaStreamTrackState mReadyState;
bool mEnabled; bool mEnabled;
const bool mRemote; const bool mRemote;
bool mStopped;
}; };
} // namespace dom } // namespace dom

View File

@ -63,6 +63,11 @@ dictionary MediaTrackConstraints : MediaTrackConstraintSet {
sequence<MediaTrackConstraintSet> advanced; sequence<MediaTrackConstraintSet> advanced;
}; };
enum MediaStreamTrackState {
"live",
"ended"
};
[Exposed=Window] [Exposed=Window]
interface MediaStreamTrack : EventTarget { interface MediaStreamTrack : EventTarget {
readonly attribute DOMString kind; readonly attribute DOMString kind;
@ -74,7 +79,7 @@ interface MediaStreamTrack : EventTarget {
// attribute EventHandler onunmute; // attribute EventHandler onunmute;
// readonly attribute boolean _readonly; // readonly attribute boolean _readonly;
// readonly attribute boolean remote; // readonly attribute boolean remote;
// readonly attribute MediaStreamTrackState readyState; readonly attribute MediaStreamTrackState readyState;
attribute EventHandler onended; attribute EventHandler onended;
MediaStreamTrack clone (); MediaStreamTrack clone ();
void stop (); void stop ();