Bug 1226569. Part 1 - Use MediaEventSource to publish MetadataLoaded and FirstFrameLoaded events. r=jya.

This commit is contained in:
JW Wang 2015-11-23 10:35:18 +08:00
Родитель b194bb0f80
Коммит 328ebd72a1
7 изменённых файлов: 47 добавлений и 100 удалений

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

@ -98,9 +98,6 @@ public:
virtual VideoFrameContainer* GetVideoFrameContainer() = 0;
virtual mozilla::layers::ImageContainer* GetImageContainer() = 0;
virtual void MetadataLoaded(nsAutoPtr<MediaInfo> aInfo, nsAutoPtr<MetadataTags> aTags, MediaDecoderEventVisibility aEventVisibility) = 0;
virtual void FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo, MediaDecoderEventVisibility aEventVisibility) = 0;
// Returns the owner of this media decoder. The owner should only be used
// on the main thread.
virtual MediaDecoderOwner* GetOwner() = 0;
@ -134,58 +131,6 @@ public:
{ MOZ_CRASH("Forbidden method"); return NS_OK; }
};
class MetadataContainer
{
protected:
MetadataContainer(AbstractMediaDecoder* aDecoder,
nsAutoPtr<MediaInfo> aInfo,
nsAutoPtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility)
: mDecoder(aDecoder),
mInfo(aInfo),
mTags(aTags),
mEventVisibility(aEventVisibility)
{}
RefPtr<AbstractMediaDecoder> mDecoder;
nsAutoPtr<MediaInfo> mInfo;
nsAutoPtr<MetadataTags> mTags;
MediaDecoderEventVisibility mEventVisibility;
};
class MetadataEventRunner : public nsRunnable, private MetadataContainer
{
public:
MetadataEventRunner(AbstractMediaDecoder* aDecoder,
nsAutoPtr<MediaInfo> aInfo,
nsAutoPtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable)
: MetadataContainer(aDecoder, aInfo, aTags, aEventVisibility)
{}
NS_IMETHOD Run() override
{
mDecoder->MetadataLoaded(mInfo, mTags, mEventVisibility);
return NS_OK;
}
};
class FirstFrameLoadedEventRunner : public nsRunnable, private MetadataContainer
{
public:
FirstFrameLoadedEventRunner(AbstractMediaDecoder* aDecoder,
nsAutoPtr<MediaInfo> aInfo,
MediaDecoderEventVisibility aEventVisibility = MediaDecoderEventVisibility::Observable)
: MetadataContainer(aDecoder, aInfo, nsAutoPtr<MetadataTags>(nullptr), aEventVisibility)
{}
NS_IMETHOD Run() override
{
mDecoder->FirstFrameLoaded(mInfo, mEventVisibility);
return NS_OK;
}
};
} // namespace mozilla
#endif

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

@ -610,6 +610,8 @@ MediaDecoder::Shutdown()
if (mDecoderStateMachine) {
mDecoderStateMachine->DispatchShutdown();
mTimedMetadataListener.Disconnect();
mMetadataLoadedListener.Disconnect();
mFirstFrameLoadedListener.Disconnect();
}
// Force any outstanding seek and byterange requests to complete
@ -689,6 +691,10 @@ MediaDecoder::SetStateMachineParameters()
}
mTimedMetadataListener = mDecoderStateMachine->TimedMetadataEvent().Connect(
AbstractThread::MainThread(), this, &MediaDecoder::OnMetadataUpdate);
mMetadataLoadedListener = mDecoderStateMachine->MetadataLoadedEvent().Connect(
AbstractThread::MainThread(), this, &MediaDecoder::MetadataLoaded);
mFirstFrameLoadedListener = mDecoderStateMachine->FirstFrameLoadedEvent().Connect(
AbstractThread::MainThread(), this, &MediaDecoder::FirstFrameLoaded);
}
void

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

@ -610,17 +610,6 @@ private:
// change. Call on the main thread only.
virtual void ChangeState(PlayState aState);
// Called when the metadata from the media file has been loaded by the
// state machine. Call on the main thread only.
virtual void MetadataLoaded(nsAutoPtr<MediaInfo> aInfo,
nsAutoPtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility) override;
// Called when the first audio and/or video from the media file has been loaded
// by the state machine. Call on the main thread only.
virtual void FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
MediaDecoderEventVisibility aEventVisibility) override;
// Called from MetadataLoaded(). Creates audio tracks and adds them to its
// owner's audio track list, and implies to video tracks respectively.
// Call on the main thread only.
@ -750,6 +739,12 @@ private:
protected:
virtual ~MediaDecoder();
// Called when the first audio and/or video from the media file has been loaded
// by the state machine. Call on the main thread only.
virtual void FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
MediaDecoderEventVisibility aEventVisibility);
void SetStateMachineParameters();
static void DormantTimerExpired(nsITimer *aTimer, void *aClosure);
@ -815,6 +810,12 @@ protected:
RefPtr<MediaResource> mResource;
private:
// Called when the metadata from the media file has been loaded by the
// state machine. Call on the main thread only.
void MetadataLoaded(nsAutoPtr<MediaInfo> aInfo,
nsAutoPtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility);
MediaEventSource<void>*
DataArrivedEvent() override { return &mDataArrivedEvent; }
@ -936,6 +937,9 @@ protected:
// A listener to receive metadata updates from MDSM.
MediaEventListener mTimedMetadataListener;
MediaEventListener mMetadataLoadedListener;
MediaEventListener mFirstFrameLoadedListener;
protected:
// Whether the state machine is shut down.
Mirror<bool> mStateMachineIsShutdown;

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

@ -2013,14 +2013,12 @@ void
MediaDecoderStateMachine::EnqueueLoadedMetadataEvent()
{
MOZ_ASSERT(OnTaskQueue());
nsAutoPtr<MediaInfo> info(new MediaInfo());
*info = mInfo;
MediaDecoderEventVisibility visibility = mSentLoadedMetadataEvent?
MediaDecoderEventVisibility::Suppressed :
MediaDecoderEventVisibility::Observable;
nsCOMPtr<nsIRunnable> metadataLoadedEvent =
new MetadataEventRunner(mDecoder, info, mMetadataTags, visibility);
AbstractThread::MainThread()->Dispatch(metadataLoadedEvent.forget());
MediaDecoderEventVisibility visibility =
mSentLoadedMetadataEvent ? MediaDecoderEventVisibility::Suppressed
: MediaDecoderEventVisibility::Observable;
mMetadataLoadedEvent.Notify(nsAutoPtr<MediaInfo>(new MediaInfo(mInfo)),
Move(mMetadataTags),
Move(visibility));
mSentLoadedMetadataEvent = true;
}
@ -2028,14 +2026,11 @@ void
MediaDecoderStateMachine::EnqueueFirstFrameLoadedEvent()
{
MOZ_ASSERT(OnTaskQueue());
nsAutoPtr<MediaInfo> info(new MediaInfo());
*info = mInfo;
MediaDecoderEventVisibility visibility = mSentFirstFrameLoadedEvent?
MediaDecoderEventVisibility::Suppressed :
MediaDecoderEventVisibility::Observable;
nsCOMPtr<nsIRunnable> event =
new FirstFrameLoadedEventRunner(mDecoder, info, visibility);
AbstractThread::MainThread()->Dispatch(event.forget());
MediaDecoderEventVisibility visibility =
mSentFirstFrameLoadedEvent ? MediaDecoderEventVisibility::Suppressed
: MediaDecoderEventVisibility::Observable;
mFirstFrameLoadedEvent.Notify(nsAutoPtr<MediaInfo>(new MediaInfo(mInfo)),
Move(visibility));
mSentFirstFrameLoadedEvent = true;
}

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

@ -224,6 +224,15 @@ public:
return mMetadataManager.TimedMetadataEvent();
}
MediaEventSourceExc<nsAutoPtr<MediaInfo>,
nsAutoPtr<MetadataTags>,
MediaDecoderEventVisibility>&
MetadataLoadedEvent() { return mMetadataLoadedEvent; }
MediaEventSourceExc<nsAutoPtr<MediaInfo>,
MediaDecoderEventVisibility>&
FirstFrameLoadedEvent() { return mFirstFrameLoadedEvent; }
// Immutable after construction - may be called on any thread.
bool IsRealTime() const { return mRealTime; }
@ -1186,6 +1195,12 @@ private:
MediaEventListener mAudioQueueListener;
MediaEventListener mVideoQueueListener;
MediaEventProducerExc<nsAutoPtr<MediaInfo>,
nsAutoPtr<MetadataTags>,
MediaDecoderEventVisibility> mMetadataLoadedEvent;
MediaEventProducerExc<nsAutoPtr<MediaInfo>,
MediaDecoderEventVisibility> mFirstFrameLoadedEvent;
// True if audio is offloading.
// Playback will not start when audio is offloading.
bool mAudioOffloading;

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

@ -66,18 +66,6 @@ BufferDecoder::GetImageContainer()
return nullptr;
}
void
BufferDecoder::MetadataLoaded(nsAutoPtr<MediaInfo> aInfo, nsAutoPtr<MetadataTags> aTags, MediaDecoderEventVisibility aEventVisibility)
{
// ignore
}
void
BufferDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo, MediaDecoderEventVisibility aEventVisibility)
{
// ignore
}
MediaDecoderOwner*
BufferDecoder::GetOwner()
{

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

@ -41,12 +41,6 @@ public:
virtual VideoFrameContainer* GetVideoFrameContainer() final override;
virtual layers::ImageContainer* GetImageContainer() final override;
virtual void MetadataLoaded(nsAutoPtr<MediaInfo> aInfo,
nsAutoPtr<MetadataTags> aTags,
MediaDecoderEventVisibility aEventVisibility) final override;
virtual void FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
MediaDecoderEventVisibility aEventVisibility) final override;
virtual MediaDecoderOwner* GetOwner() final override;
private: