Bug 856361. Part 6: Make MediaStreamAudioSourceNode keep its DOMMediaStream alive, and make the DOMMediaStream keep the MediaStreamAudioSourceNode alive. r=ehsan

--HG--
extra : rebase_source : b7172f79fbf0cacaaf10f812444444ba17ad00e9
This commit is contained in:
Robert O'Callahan 2013-07-25 14:07:34 +12:00
parent 824c0706bb
commit ec2d522eff
7 changed files with 67 additions and 6 deletions

View File

@ -28,11 +28,13 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMMediaStream)
tmp->Destroy();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWindow)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTracks)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mConsumersToKeepAlive)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMMediaStream)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTracks)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConsumersToKeepAlive)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(DOMMediaStream)
@ -285,6 +287,16 @@ DOMMediaStream::NotifyMediaStreamGraphShutdown()
// to prevent leaks.
mNotifiedOfMediaStreamGraphShutdown = true;
mRunOnTracksAvailable.Clear();
mConsumersToKeepAlive.Clear();
}
void
DOMMediaStream::NotifyStreamStateChanged()
{
if (IsFinished()) {
mConsumersToKeepAlive.Clear();
}
}
void

View File

@ -95,6 +95,10 @@ public:
* will only be called during a forced shutdown due to application exit.
*/
void NotifyMediaStreamGraphShutdown();
/**
* Called when the main-thread state of the MediaStream changed.
*/
void NotifyStreamStateChanged();
// Indicate what track types we eventually expect to add to this stream
enum {
@ -147,6 +151,17 @@ public:
// Takes ownership of aCallback.
void OnTracksAvailable(OnTracksAvailableCallback* aCallback);
/**
* Add an nsISupports object that this stream will keep alive as long as
* the stream is not finished.
*/
void AddConsumerToKeepAlive(nsISupports* aConsumer)
{
if (!IsFinished() && !mNotifiedOfMediaStreamGraphShutdown) {
mConsumersToKeepAlive.AppendElement(aConsumer);
}
}
protected:
void Destroy();
void InitSourceStream(nsIDOMWindow* aWindow, TrackTypeHints aHintContents);
@ -175,6 +190,9 @@ protected:
nsTArray<nsAutoPtr<OnTracksAvailableCallback> > mRunOnTracksAvailable;
// Keep these alive until the stream finishes
nsTArray<nsCOMPtr<nsISupports> > mConsumersToKeepAlive;
// Indicate what track types we eventually expect to add to this stream
uint8_t mHintContents;
// Indicate what track types have been added to this stream

View File

@ -1220,6 +1220,9 @@ MediaStreamGraphImpl::ApplyStreamUpdate(StreamUpdate* aUpdate)
stream->mMainThreadCurrentTime = aUpdate->mNextMainThreadCurrentTime;
stream->mMainThreadFinished = aUpdate->mNextMainThreadFinished;
if (stream->mWrapper) {
stream->mWrapper->NotifyStreamStateChanged();
}
for (int32_t i = stream->mMainThreadListeners.Length() - 1; i >= 0; --i) {
stream->mMainThreadListeners[i]->NotifyMainThreadStateChanged();
}

View File

@ -255,7 +255,7 @@ AudioContext::CreateAnalyser()
}
already_AddRefed<MediaStreamAudioSourceNode>
AudioContext::CreateMediaStreamSource(const DOMMediaStream& aMediaStream,
AudioContext::CreateMediaStreamSource(DOMMediaStream& aMediaStream,
ErrorResult& aRv)
{
if (mIsOffline) {

View File

@ -163,7 +163,7 @@ public:
}
already_AddRefed<MediaStreamAudioSourceNode>
CreateMediaStreamSource(const DOMMediaStream& aMediaStream, ErrorResult& aRv);
CreateMediaStreamSource(DOMMediaStream& aMediaStream, ErrorResult& aRv);
already_AddRefed<DelayNode>
CreateDelay(double aMaxDelayTime, ErrorResult& aRv);

View File

@ -13,18 +13,38 @@
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(MediaStreamAudioSourceNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInputStream)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(AudioNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(MediaStreamAudioSourceNode, AudioNode)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mInputStream)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(MediaStreamAudioSourceNode)
NS_INTERFACE_MAP_END_INHERITING(MediaStreamAudioSourceNode)
NS_IMPL_ADDREF_INHERITED(MediaStreamAudioSourceNode, AudioNode)
NS_IMPL_RELEASE_INHERITED(MediaStreamAudioSourceNode, AudioNode)
MediaStreamAudioSourceNode::MediaStreamAudioSourceNode(AudioContext* aContext,
const DOMMediaStream* aMediaStream)
DOMMediaStream* aMediaStream)
: AudioNode(aContext,
2,
ChannelCountMode::Max,
ChannelInterpretation::Speakers)
ChannelInterpretation::Speakers),
mInputStream(aMediaStream)
{
AudioNodeEngine* engine = new AudioNodeEngine(this);
mStream = aContext->Graph()->CreateAudioNodeExternalInputStream(engine);
ProcessedMediaStream* outputStream = static_cast<ProcessedMediaStream*>(mStream.get());
mInputPort = outputStream->AllocateInputPort(aMediaStream->GetStream(),
MediaInputPort::FLAG_BLOCK_INPUT);
mInputStream->AddConsumerToKeepAlive(this);
}
MediaStreamAudioSourceNode::~MediaStreamAudioSourceNode()
{
}
void

View File

@ -10,12 +10,20 @@
#include "AudioNode.h"
namespace mozilla {
class DOMMediaStream;
namespace dom {
class MediaStreamAudioSourceNode : public AudioNode
{
public:
MediaStreamAudioSourceNode(AudioContext* aContext, const DOMMediaStream* aMediaStream);
MediaStreamAudioSourceNode(AudioContext* aContext, DOMMediaStream* aMediaStream);
// Define consturctor out-of-line so we can forward-declare DOMMediaStream
virtual ~MediaStreamAudioSourceNode();
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaStreamAudioSourceNode, AudioNode)
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
@ -25,10 +33,10 @@ public:
private:
nsRefPtr<MediaInputPort> mInputPort;
nsRefPtr<DOMMediaStream> mInputStream;
};
}
}
#endif