Bug 822952 - Dispatch events from UpdateReadyState only when the state has changed. r=roc

This commit is contained in:
Matthew Gregan 2012-12-19 17:48:32 +13:00
parent fcc899a9db
commit a3df31fa18
3 changed files with 17 additions and 16 deletions

View File

@ -126,7 +126,9 @@ public:
// is paused while it buffers up data
NEXT_FRAME_UNAVAILABLE_BUFFERING,
// The next frame of audio/video is unavailable for some other reasons
NEXT_FRAME_UNAVAILABLE
NEXT_FRAME_UNAVAILABLE,
// Sentinel value
NEXT_FRAME_UNINITIALIZED
};
// Called by the decoder when some data has been downloaded or

View File

@ -386,7 +386,8 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mDidThrottleAudioDecoding(false),
mDidThrottleVideoDecoding(false),
mRequestedNewDecodeThread(false),
mEventManager(aDecoder)
mEventManager(aDecoder),
mLastFrameStatus(MediaDecoderOwner::NEXT_FRAME_UNINITIALIZED)
{
MOZ_COUNT_CTOR(MediaDecoderStateMachine);
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
@ -555,11 +556,11 @@ void MediaDecoderStateMachine::SendStreamAudio(AudioData* aAudio,
aStream->mAudioFramesWritten += aAudio->mFrames - int32_t(offset);
}
static void WriteVideoToMediaStream(mozilla::layers::Image* aImage,
static void WriteVideoToMediaStream(layers::Image* aImage,
int64_t aDuration, const gfxIntSize& aIntrinsicSize,
VideoSegment* aOutput)
{
nsRefPtr<mozilla::layers::Image> image = aImage;
nsRefPtr<layers::Image> image = aImage;
aOutput->AppendFrame(image.forget(), aDuration, aIntrinsicSize);
}
@ -2469,8 +2470,14 @@ VideoData* MediaDecoderStateMachine::FindStartTime()
void MediaDecoderStateMachine::UpdateReadyState() {
mDecoder->GetReentrantMonitor().AssertCurrentThreadIn();
MediaDecoderOwner::NextFrameStatus nextFrameStatus = GetNextFrameStatus();
if (nextFrameStatus == mLastFrameStatus) {
return;
}
mLastFrameStatus = nextFrameStatus;
nsCOMPtr<nsIRunnable> event;
switch (GetNextFrameStatus()) {
switch (nextFrameStatus) {
case MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING:
event = NS_NewRunnableMethod(mDecoder, &MediaDecoder::NextFrameUnavailableBuffering);
break;
@ -2614,10 +2621,6 @@ void MediaDecoderStateMachine::TimeoutExpired()
// going to run anyway.
}
nsresult MediaDecoderStateMachine::ScheduleStateMachine() {
return ScheduleStateMachine(0);
}
void MediaDecoderStateMachine::ScheduleStateMachineWithLockAndWakeDecoder() {
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
mon.NotifyAll();

View File

@ -280,12 +280,6 @@ public:
// Returns the shared state machine thread.
static nsIThread* GetStateMachineThread();
// Schedules the shared state machine thread to run the state machine.
// If the state machine thread is the currently running the state machine,
// we wait until that has completely finished before running the state
// machine again.
nsresult ScheduleStateMachine();
// Calls ScheduleStateMachine() after taking the decoder lock. Also
// notifies the decoder thread in case it's waiting on the decoder lock.
void ScheduleStateMachineWithLockAndWakeDecoder();
@ -293,7 +287,7 @@ public:
// Schedules the shared state machine thread to run the state machine
// in aUsecs microseconds from now, if it's not already scheduled to run
// earlier, in which case the request is discarded.
nsresult ScheduleStateMachine(int64_t aUsecs);
nsresult ScheduleStateMachine(int64_t aUsecs = 0);
// Creates and starts a new decode thread. Don't call this directly,
// request a new decode thread by calling
@ -797,6 +791,8 @@ private:
VideoInfo mInfo;
mozilla::MediaMetadataManager mMetadataManager;
MediaDecoderOwner::NextFrameStatus mLastFrameStatus;
};
} // namespace mozilla;