Bug 759908. Create MediaStreamListener::NotifyConsumptionChanged. r=jesup

--HG--
extra : rebase_source : f9479b836ec92170782eb01ea8b97004b057ceb7
This commit is contained in:
Robert O'Callahan 2012-06-01 18:26:17 +12:00
Родитель 45ed5414b5
Коммит 09176f2085
2 изменённых файлов: 43 добавлений и 3 удалений

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

@ -205,6 +205,11 @@ public:
* will take effect.
*/
void ChooseActionTime();
/**
* Update the consumption state of aStream to reflect whether its data
* is needed or not.
*/
void UpdateConsumptionState(SourceMediaStream* aStream);
/**
* Extract any state updates pending in aStream, and apply them.
*/
@ -612,6 +617,22 @@ MediaStreamGraphImpl::ChooseActionTime()
mLastActionTime = GetEarliestActionTime();
}
void
MediaStreamGraphImpl::UpdateConsumptionState(SourceMediaStream* aStream)
{
bool isConsumed = !aStream->mAudioOutputs.IsEmpty() ||
!aStream->mVideoOutputs.IsEmpty();
MediaStreamListener::Consumption state = isConsumed ? MediaStreamListener::CONSUMED
: MediaStreamListener::NOT_CONSUMED;
if (state != aStream->mLastConsumptionState) {
aStream->mLastConsumptionState = state;
for (PRUint32 j = 0; j < aStream->mListeners.Length(); ++j) {
MediaStreamListener* l = aStream->mListeners[j];
l->NotifyConsumptionChanged(this, state);
}
}
}
void
MediaStreamGraphImpl::ExtractPendingInput(SourceMediaStream* aStream)
{
@ -1267,6 +1288,7 @@ MediaStreamGraphImpl::RunThread()
for (PRUint32 i = 0; i < mStreams.Length(); ++i) {
SourceMediaStream* is = mStreams[i]->AsSourceStream();
if (is) {
UpdateConsumptionState(is);
ExtractPendingInput(is);
}
}

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

@ -94,12 +94,24 @@ public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaStreamListener)
enum Consumption {
CONSUMED,
NOT_CONSUMED
};
/**
* Notify that the stream is hooked up and we'd like to start or stop receiving
* data on it. Only fires on SourceMediaStreams.
* The initial state is assumed to be NOT_CONSUMED.
*/
virtual void NotifyConsumptionChanged(MediaStreamGraph* aGraph, Consumption aConsuming) {}
enum Blocking {
BLOCKED,
UNBLOCKED
};
/**
* Notify that the blocking status of the stream changed.
* Notify that the blocking status of the stream changed. The initial state
* is assumed to be BLOCKED.
*/
virtual void NotifyBlockingChanged(MediaStreamGraph* aGraph, Blocking aBlocked) {}
@ -371,8 +383,11 @@ protected:
class SourceMediaStream : public MediaStream {
public:
SourceMediaStream(nsDOMMediaStream* aWrapper) :
MediaStream(aWrapper), mMutex("mozilla::media::SourceMediaStream"),
mUpdateKnownTracksTime(0), mUpdateFinished(false), mDestroyed(false)
MediaStream(aWrapper),
mLastConsumptionState(MediaStreamListener::NOT_CONSUMED),
mMutex("mozilla::media::SourceMediaStream"),
mUpdateKnownTracksTime(0),
mUpdateFinished(false), mDestroyed(false)
{}
virtual SourceMediaStream* AsSourceStream() { return this; }
@ -471,6 +486,9 @@ protected:
return nsnull;
}
// Media stream graph thread only
MediaStreamListener::Consumption mLastConsumptionState;
// This must be acquired *before* MediaStreamGraphImpl's lock, if they are
// held together.
Mutex mMutex;