Bug 513144. Hoist nsMediaStream creation up into nsHTMLMediaElement, out of the decoders. Pass the stream as the parameter to nsMediaDecoder::Load. r=doublec

--HG--
extra : rebase_source : f418076a0d534d528dbded66b2d49d8fe908de4b
This commit is contained in:
Robert O'Callahan 2009-09-15 14:30:43 +12:00
Родитель e3c99e5d57
Коммит c0750a055b
6 изменённых файлов: 25 добавлений и 24 удалений

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

@ -70,6 +70,7 @@
#include "nsHTMLMediaError.h"
#include "nsICategoryManager.h"
#include "nsCommaSeparatedTokenizer.h"
#include "nsMediaStream.h"
#include "nsIContentPolicy.h"
#include "nsContentPolicyUtils.h"
@ -1206,12 +1207,16 @@ nsresult nsHTMLMediaElement::InitializeDecoderForChannel(nsIChannel *aChannel,
mNetworkState = nsIDOMHTMLMediaElement::NETWORK_LOADING;
nsresult rv = mDecoder->Load(aChannel, aListener);
nsMediaStream* stream = nsMediaStream::Create(mDecoder, aChannel);
if (!stream)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = mDecoder->Load(stream, aListener);
if (NS_FAILED(rv))
return rv;
// Decoder successfully created, its nsMediaStream now has responsibility
// for the channel, and the owning reference.
// Decoder successfully created, the decoder now owns the nsMediaStream
// which owns the channel.
mChannel = nsnull;
mDecoder->SetVolume(mMuted ? 0.0 : mVolume);

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

@ -109,11 +109,12 @@ public:
// called.
virtual nsresult Play() = 0;
// Start downloading the video. Decode the downloaded data up to the
// Start downloading the media. Decode the downloaded data up to the
// point of the first frame of data.
// aChannel and aListener must not be null.
// aStream is the media stream to use. Ownership of aStream passes to
// the decoder, even if Load returns an error.
// This is called at most once per decoder, after Init().
virtual nsresult Load(nsIChannel* aChannel,
virtual nsresult Load(nsMediaStream* aStream,
nsIStreamListener **aListener) = 0;
// Draw the latest video data. This is done

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

@ -1965,31 +1965,26 @@ nsOggDecoder::~nsOggDecoder()
nsAutoMonitor::DestroyMonitor(mMonitor);
}
nsresult nsOggDecoder::Load(nsIChannel* aChannel,
nsresult nsOggDecoder::Load(nsMediaStream* aStream,
nsIStreamListener** aStreamListener)
{
NS_ASSERTION(aChannel, "A channel is required");
NS_ASSERTION(aStreamListener, "A listener should be requested here");
*aStreamListener = nsnull;
nsAutoPtr<nsMediaStream> stream;
stream = nsMediaStream::Create(this, aChannel);
if (!stream) {
return NS_ERROR_OUT_OF_MEMORY;
}
{
// Hold the lock while we do this to set proper lock ordering
// expectations for dynamic deadlock detectors: decoder lock(s)
// should be grabbed before the cache lock
nsAutoMonitor mon(mMonitor);
nsresult rv = stream->Open(aStreamListener);
if (NS_FAILED(rv))
nsresult rv = aStream->Open(aStreamListener);
if (NS_FAILED(rv)) {
delete aStream;
return rv;
}
mReader->Init(stream.forget());
mReader->Init(aStream);
}
nsresult rv = NS_NewThread(getter_AddRefs(mDecodeThread));

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

@ -310,8 +310,8 @@ class nsOggDecoder : public nsMediaDecoder
virtual float GetCurrentTime();
virtual nsresult Load(nsIChannel* aChannel,
nsIStreamListener **aListener);
virtual nsresult Load(nsMediaStream* aStream,
nsIStreamListener** aListener);
// Start playback of a video. 'Load' must have previously been
// called.

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

@ -1282,15 +1282,14 @@ nsWaveDecoder::Stop()
}
nsresult
nsWaveDecoder::Load(nsIChannel* aChannel, nsIStreamListener** aStreamListener)
nsWaveDecoder::Load(nsMediaStream* aStream, nsIStreamListener** aStreamListener)
{
NS_ASSERTION(aChannel, "A channel is required");
NS_ASSERTION(aStream, "A stream should be provided");
NS_ASSERTION(aStreamListener, "A listener should be requested here");
*aStreamListener = nsnull;
mStream = nsMediaStream::Create(this, aChannel);
NS_ENSURE_TRUE(mStream, NS_ERROR_OUT_OF_MEMORY);
mStream = aStream;
nsresult rv = mStream->Open(aStreamListener);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -176,7 +176,8 @@ class nsWaveDecoder : public nsMediaDecoder
// Start downloading the media at the specified URI. The media's metadata
// will be parsed and made available as the load progresses.
virtual nsresult Load(nsIChannel* aChannel, nsIStreamListener** aStreamListener);
virtual nsresult Load(nsMediaStream* aStream,
nsIStreamListener** aStreamListener);
// Called by mStream (and possibly the nsChannelToPipeListener used
// internally by mStream) when the stream has completed loading.