mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1208316 - Implement MediaStream.active. r=jib, r=smaug
MozReview-Commit-ID: Fzk5vepqQ35 --HG-- extra : rebase_source : 1ddf804e4ca8604b36cf0e8b4752f638c45c9561
This commit is contained in:
parent
c77e4ec01c
commit
456866fe62
@ -366,7 +366,8 @@ DOMMediaStream::DOMMediaStream(nsPIDOMWindowInner* aWindow,
|
||||
: mLogicalStreamStartTime(0), mWindow(aWindow),
|
||||
mInputStream(nullptr), mOwnedStream(nullptr), mPlaybackStream(nullptr),
|
||||
mTracksPendingRemoval(0), mTrackSourceGetter(aTrackSourceGetter),
|
||||
mTracksCreated(false), mNotifiedOfMediaStreamGraphShutdown(false)
|
||||
mTracksCreated(false), mNotifiedOfMediaStreamGraphShutdown(false),
|
||||
mActive(false)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
||||
@ -618,13 +619,13 @@ DOMMediaStream::RemoveTrack(MediaStreamTrack& aTrack)
|
||||
// cases blocking the underlying track should be avoided.
|
||||
if (!aTrack.Ended()) {
|
||||
BlockPlaybackTrack(toRemove);
|
||||
|
||||
bool removed = mTracks.RemoveElement(toRemove);
|
||||
if (removed) {
|
||||
NotifyTrackRemoved(&aTrack);
|
||||
}
|
||||
}
|
||||
|
||||
DebugOnly<bool> removed = mTracks.RemoveElement(toRemove);
|
||||
MOZ_ASSERT(removed);
|
||||
|
||||
NotifyTrackRemoved(&aTrack);
|
||||
|
||||
LOG(LogLevel::Debug, ("DOMMediaStream %p Removed track %p", this, &aTrack));
|
||||
}
|
||||
|
||||
@ -730,6 +731,12 @@ DOMMediaStream::CloneInternal(TrackForwardingOption aForwarding)
|
||||
return newStream.forget();
|
||||
}
|
||||
|
||||
bool
|
||||
DOMMediaStream::Active() const
|
||||
{
|
||||
return mActive;
|
||||
}
|
||||
|
||||
MediaStreamTrack*
|
||||
DOMMediaStream::GetTrackById(const nsAString& aId) const
|
||||
{
|
||||
@ -1179,6 +1186,28 @@ DOMMediaStream::NotifyTracksCreated()
|
||||
CheckTracksAvailable();
|
||||
}
|
||||
|
||||
void
|
||||
DOMMediaStream::NotifyActive()
|
||||
{
|
||||
LOG(LogLevel::Info, ("DOMMediaStream %p NotifyActive(). ", this));
|
||||
|
||||
MOZ_ASSERT(mActive);
|
||||
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
||||
mTrackListeners[i]->NotifyActive();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DOMMediaStream::NotifyInactive()
|
||||
{
|
||||
LOG(LogLevel::Info, ("DOMMediaStream %p NotifyInactive(). ", this));
|
||||
|
||||
MOZ_ASSERT(!mActive);
|
||||
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
||||
mTrackListeners[i]->NotifyInactive();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DOMMediaStream::CheckTracksAvailable()
|
||||
{
|
||||
@ -1243,6 +1272,24 @@ DOMMediaStream::NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack)
|
||||
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
||||
mTrackListeners[i]->NotifyTrackAdded(aTrack);
|
||||
}
|
||||
|
||||
if (mActive) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we became active.
|
||||
bool active = false;
|
||||
for (auto port : mTracks) {
|
||||
if (!port->GetTrack()->Ended()) {
|
||||
active = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (active) {
|
||||
mActive = true;
|
||||
NotifyActive();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -1254,11 +1301,31 @@ DOMMediaStream::NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack)
|
||||
|
||||
for (int32_t i = mTrackListeners.Length() - 1; i >= 0; --i) {
|
||||
mTrackListeners[i]->NotifyTrackRemoved(aTrack);
|
||||
|
||||
}
|
||||
|
||||
// Don't call RecomputePrincipal here as the track may still exist in the
|
||||
// playback stream in the MediaStreamGraph. It will instead be called when the
|
||||
// track has been confirmed removed by the graph. See BlockPlaybackTrack().
|
||||
|
||||
if (!mActive) {
|
||||
NS_ASSERTION(false, "Shouldn't remove a live track if already inactive");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we became inactive.
|
||||
bool active = false;
|
||||
for (auto port : mTracks) {
|
||||
if (!port->GetTrack()->Ended()) {
|
||||
active = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!active) {
|
||||
mActive = false;
|
||||
NotifyInactive();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -226,18 +226,30 @@ public:
|
||||
virtual ~TrackListener() {}
|
||||
|
||||
/**
|
||||
* Called when the DOMMediaStream has a new track added, either by
|
||||
* JS (addTrack()) or the source creating one.
|
||||
* Called when the DOMMediaStream has a live track added, either by
|
||||
* script (addTrack()) or the source creating one.
|
||||
*/
|
||||
virtual void
|
||||
NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack) {};
|
||||
|
||||
/**
|
||||
* Called when the DOMMediaStream removes a track, either by
|
||||
* JS (removeTrack()) or the source ending it.
|
||||
* Called when the DOMMediaStream removes a live track from playback, either
|
||||
* by script (removeTrack(), track.stop()) or the source ending it.
|
||||
*/
|
||||
virtual void
|
||||
NotifyTrackRemoved(const RefPtr<MediaStreamTrack>& aTrack) {};
|
||||
|
||||
/**
|
||||
* Called when the DOMMediaStream has become active.
|
||||
*/
|
||||
virtual void
|
||||
NotifyActive() {};
|
||||
|
||||
/**
|
||||
* Called when the DOMMediaStream has become inactive.
|
||||
*/
|
||||
virtual void
|
||||
NotifyInactive() {};
|
||||
};
|
||||
|
||||
/**
|
||||
@ -363,6 +375,8 @@ public:
|
||||
/** Identical to CloneInternal(TrackForwardingOption::EXPLICIT) */
|
||||
already_AddRefed<DOMMediaStream> Clone();
|
||||
|
||||
bool Active() const;
|
||||
|
||||
IMPL_EVENT_HANDLER(addtrack)
|
||||
|
||||
// NON-WebIDL
|
||||
@ -599,6 +613,12 @@ protected:
|
||||
// created.
|
||||
void NotifyTracksCreated();
|
||||
|
||||
// Dispatches NotifyActive() to all registered track listeners.
|
||||
void NotifyActive();
|
||||
|
||||
// Dispatches NotifyInactive() to all registered track listeners.
|
||||
void NotifyInactive();
|
||||
|
||||
// Dispatches NotifyTrackAdded() to all registered track listeners.
|
||||
void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& aTrack);
|
||||
|
||||
@ -699,6 +719,9 @@ protected:
|
||||
// The track listeners subscribe to changes in this stream's track set.
|
||||
nsTArray<TrackListener*> mTrackListeners;
|
||||
|
||||
// True if this stream has live tracks.
|
||||
bool mActive;
|
||||
|
||||
private:
|
||||
void NotifyPrincipalChanged();
|
||||
// Principal identifying who may access the collected contents of this stream.
|
||||
|
@ -36,9 +36,7 @@ interface MediaStream : EventTarget {
|
||||
void addTrack (MediaStreamTrack track);
|
||||
void removeTrack (MediaStreamTrack track);
|
||||
MediaStream clone ();
|
||||
// readonly attribute boolean active;
|
||||
// attribute EventHandler onactive;
|
||||
// attribute EventHandler oninactive;
|
||||
readonly attribute boolean active;
|
||||
attribute EventHandler onaddtrack;
|
||||
// attribute EventHandler onremovetrack;
|
||||
readonly attribute double currentTime;
|
||||
|
Loading…
Reference in New Issue
Block a user