Bug 909187: Part 2 - Allow DOM MediaStreams to intercept SetTrackEnabled calls r=roc

This commit is contained in:
Randell Jesup 2013-08-26 02:07:19 -04:00
parent bcd3b7a8e1
commit 7b81d69b21
6 changed files with 42 additions and 4 deletions

View File

@ -240,6 +240,14 @@ DOMMediaStream::CreateTrackUnionStream(nsIDOMWindow* aWindow, TrackTypeHints aHi
return stream.forget();
}
void
DOMMediaStream::SetTrackEnabled(TrackID aTrackID, bool aEnabled)
{
if (mStream) {
mStream->SetTrackEnabled(aTrackID, aEnabled);
}
}
bool
DOMMediaStream::CombineWithPrincipal(nsIPrincipal* aPrincipal)
{

View File

@ -84,6 +84,12 @@ public:
virtual bool AddDirectListener(MediaStreamDirectListener *aListener) { return false; }
virtual void RemoveDirectListener(MediaStreamDirectListener *aListener) {}
/**
* Overridden in DOMLocalMediaStreams to allow getUserMedia to disable
* media at the SourceMediaStream.
*/
virtual void SetTrackEnabled(TrackID aTrackID, bool aEnabled);
bool IsFinished();
/**
* Returns a principal indicating who may access this stream. The stream contents

View File

@ -942,6 +942,11 @@ public:
virtual void ProduceOutput(GraphTime aFrom, GraphTime aTo) = 0;
void SetAutofinishImpl(bool aAutofinish) { mAutofinish = aAutofinish; }
/**
* Forward SetTrackEnabled() to the input MediaStream(s) and translate the ID
*/
virtual void ForwardTrackEnabled(TrackID aOutputID, bool aEnabled) {};
protected:
// This state is all accessed only on the media graph thread.

View File

@ -52,10 +52,7 @@ void
MediaStreamTrack::SetEnabled(bool aEnabled)
{
mEnabled = aEnabled;
MediaStream* stream = mStream->GetStream();
if (stream) {
stream->SetTrackEnabled(mTrackID, aEnabled);
}
mStream->SetTrackEnabled(mTrackID, aEnabled);
}
}

View File

@ -115,6 +115,17 @@ public:
mFilterCallback = aCallback;
}
// Forward SetTrackEnabled(output_track_id, enabled) to the Source MediaStream,
// translating the output track ID into the correct ID in the source.
virtual void ForwardTrackEnabled(TrackID aOutputID, bool aEnabled) {
for (int32_t i = mTrackMap.Length() - 1; i >= 0; --i) {
if (mTrackMap[i].mOutputTrackID == aOutputID) {
mTrackMap[i].mInputPort->GetSource()->
SetTrackEnabled(mTrackMap[i].mInputTrackID, aEnabled);
}
}
}
protected:
TrackIDFilterCallback mFilterCallback;

View File

@ -312,6 +312,17 @@ public:
}
}
// let us intervene for direct listeners when someone does track.enabled = false
virtual void SetTrackEnabled(TrackID aID, bool aEnabled) MOZ_OVERRIDE
{
// We encapsulate the SourceMediaStream and TrackUnion into one entity, so
// we can handle the disabling at the SourceMediaStream
// We need to find the input track ID for output ID aID, so we let the TrackUnion
// forward the request to the source and translate the ID
GetStream()->AsProcessedStream()->ForwardTrackEnabled(aID, aEnabled);
}
// The actual MediaStream is a TrackUnionStream. But these resources need to be
// explicitly destroyed too.
nsRefPtr<SourceMediaStream> mSourceStream;