Bug 827007: Implement Stop for UserMediaStreams; add NotifyRemoved for MediaStream listeners r=roc

This commit is contained in:
Randell Jesup 2013-01-06 21:31:30 -05:00
Родитель bd79e289a0
Коммит 08fd4e2d72
3 изменённых файлов: 40 добавлений и 4 удалений

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

@ -1776,9 +1776,21 @@ MediaStream::FinishOnGraphThread()
GraphImpl()->FinishStream(this);
}
void
MediaStream::RemoveAllListenersImpl()
{
for (int32_t i = mListeners.Length() - 1; i >= 0; --i) {
nsRefPtr<MediaStreamListener> listener = mListeners[i].forget();
listener->NotifyRemoved(GraphImpl());
}
mListeners.Clear();
}
void
MediaStream::DestroyImpl()
{
RemoveAllListenersImpl();
for (int32_t i = mConsumers.Length() - 1; i >= 0; --i) {
mConsumers[i]->Disconnect();
}
@ -1961,6 +1973,15 @@ MediaStream::AddListener(MediaStreamListener* aListener)
GraphImpl()->AppendMessage(new Message(this, aListener));
}
void
MediaStream::RemoveListenerImpl(MediaStreamListener* aListener)
{
// wouldn't need this if we could do it in the opposite order
nsRefPtr<MediaStreamListener> listener(aListener);
mListeners.RemoveElement(aListener);
listener->NotifyRemoved(GraphImpl());
}
void
MediaStream::RemoveListener(MediaStreamListener* aListener)
{

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

@ -143,6 +143,12 @@ public:
*/
virtual void NotifyFinished(MediaStreamGraph* aGraph) {}
/**
* Notify that your listener has been removed, either due to RemoveListener(),
* or due to the stream being destroyed. You will get no further notifications.
*/
virtual void NotifyRemoved(MediaStreamGraph* aGraph) {}
enum {
TRACK_EVENT_CREATED = 0x01,
TRACK_EVENT_ENDED = 0x02
@ -363,10 +369,9 @@ public:
mExplicitBlockerCount.SetAtAndAfter(aTime, mExplicitBlockerCount.GetAt(aTime) + aDelta);
}
void AddListenerImpl(already_AddRefed<MediaStreamListener> aListener);
void RemoveListenerImpl(MediaStreamListener* aListener)
{
mListeners.RemoveElement(aListener);
}
void RemoveListenerImpl(MediaStreamListener* aListener);
void RemoveAllListenersImpl();
void AddConsumer(MediaInputPort* aPort)
{
mConsumers.AppendElement(aPort);

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

@ -241,6 +241,8 @@ public:
virtual ~nsDOMUserMediaStream()
{
Stop();
if (mPort) {
mPort->Destroy();
}
@ -249,6 +251,14 @@ public:
}
}
NS_IMETHODIMP Stop()
{
if (mSourceStream) {
mSourceStream->EndAllTrackAndFinish();
}
return NS_OK;
}
// The actual MediaStream is a TrackUnionStream. But these resources need to be
// explicitly destroyed too.
nsRefPtr<SourceMediaStream> mSourceStream;