Bug 1053674 - Remove subclass of StateMachine and use task queue directly. r=cpearce

This commit is contained in:
Matthew Gregan 2014-08-17 23:29:00 +12:00
Родитель c45b49542e
Коммит f4ad6bfcad
4 изменённых файлов: 12 добавлений и 64 удалений

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

@ -29,45 +29,6 @@ namespace mozilla {
class SubBufferDecoder;
class MediaSourceStateMachine : public MediaDecoderStateMachine
{
public:
MediaSourceStateMachine(MediaDecoder* aDecoder,
MediaDecoderReader* aReader,
bool aRealTime = false)
: MediaDecoderStateMachine(aDecoder, aReader, aRealTime)
{
}
already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType,
MediaSourceDecoder* aParentDecoder) {
if (!mReader) {
return nullptr;
}
MediaSourceReader* reader = static_cast<MediaSourceReader*>(mReader.get());
return reader->CreateSubDecoder(aType, aParentDecoder, mDecodeTaskQueue);
}
nsresult EnqueueDecoderInitialization() {
AssertCurrentThreadInMonitor();
if (!mReader) {
return NS_ERROR_FAILURE;
}
RefPtr<nsIRunnable> task =
NS_NewRunnableMethod(this, &MediaSourceStateMachine::InitializePendingDecoders);
return mDecodeTaskQueue->Dispatch(task);
}
private:
void InitializePendingDecoders() {
if (!mReader) {
return;
}
MediaSourceReader* reader = static_cast<MediaSourceReader*>(mReader.get());
reader->InitializePendingDecoders();
}
};
MediaSourceDecoder::MediaSourceDecoder(dom::HTMLMediaElement* aElement)
: mMediaSource(nullptr)
{
@ -84,7 +45,8 @@ MediaSourceDecoder::Clone()
MediaDecoderStateMachine*
MediaSourceDecoder::CreateStateMachine()
{
return new MediaSourceStateMachine(this, new MediaSourceReader(this, mMediaSource));
mReader = new MediaSourceReader(this, mMediaSource);
return new MediaDecoderStateMachine(this, mReader);
}
nsresult
@ -148,21 +110,7 @@ MediaSourceDecoder::DetachMediaSource()
already_AddRefed<SubBufferDecoder>
MediaSourceDecoder::CreateSubDecoder(const nsACString& aType)
{
if (!mDecoderStateMachine) {
return nullptr;
}
MediaSourceStateMachine* sm = static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get());
return sm->CreateSubDecoder(aType, this);
}
nsresult
MediaSourceDecoder::EnqueueDecoderInitialization()
{
if (!mDecoderStateMachine) {
return NS_ERROR_FAILURE;
}
MediaSourceStateMachine* sm = static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get());
return sm->EnqueueDecoderInitialization();
return mReader->CreateSubDecoder(aType, this);
}
} // namespace mozilla

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

@ -18,6 +18,7 @@ namespace mozilla {
class MediaResource;
class MediaDecoderStateMachine;
class MediaSourceReader;
class SubBufferDecoder;
namespace dom {
@ -44,13 +45,12 @@ public:
already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType);
nsresult EnqueueDecoderInitialization();
private:
// The owning MediaSource holds a strong reference to this decoder, and
// calls Attach/DetachMediaSource on this decoder to set and clear
// mMediaSource.
dom::MediaSource* mMediaSource;
nsRefPtr<MediaSourceReader> mReader;
};
} // namespace mozilla

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

@ -299,8 +299,7 @@ CreateReaderForType(const nsACString& aType, AbstractMediaDecoder* aDecoder)
already_AddRefed<SubBufferDecoder>
MediaSourceReader::CreateSubDecoder(const nsACString& aType,
MediaSourceDecoder* aParentDecoder,
MediaTaskQueue* aTaskQueue)
MediaSourceDecoder* aParentDecoder)
{
// XXX: Why/when is mDecoder null here, since it should be equal to aParentDecoder?!
nsRefPtr<SubBufferDecoder> decoder =
@ -313,16 +312,18 @@ MediaSourceReader::CreateSubDecoder(const nsACString& aType,
// This reader will then forward them onto the state machine via this
// reader's callback.
RefPtr<MediaDataDecodedListener<MediaSourceReader>> callback =
new MediaDataDecodedListener<MediaSourceReader>(this, aTaskQueue);
new MediaDataDecodedListener<MediaSourceReader>(this, GetTaskQueue());
reader->SetCallback(callback);
reader->SetTaskQueue(aTaskQueue);
reader->SetTaskQueue(GetTaskQueue());
reader->Init(nullptr);
ReentrantMonitorAutoEnter mon(aParentDecoder->GetReentrantMonitor());
MSE_DEBUG("MediaSourceReader(%p)::CreateSubDecoder subdecoder %p subreader %p",
this, decoder.get(), reader.get());
decoder->SetReader(reader);
mPendingDecoders.AppendElement(decoder);
if (NS_FAILED(static_cast<MediaSourceDecoder*>(mDecoder)->EnqueueDecoderInitialization())) {
RefPtr<nsIRunnable> task =
NS_NewRunnableMethod(this, &MediaSourceReader::InitializePendingDecoders);
if (NS_FAILED(GetTaskQueue()->Dispatch(task))) {
MSE_DEBUG("MediaSourceReader(%p): Failed to enqueue decoder initialization task", this);
return nullptr;
}

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

@ -71,8 +71,7 @@ public:
nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime,
int64_t aCurrentTime) MOZ_OVERRIDE;
already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType,
MediaSourceDecoder* aParentDecoder,
MediaTaskQueue* aTaskQueue);
MediaSourceDecoder* aParentDecoder);
void Shutdown();