Bug 580876 - Ensure WAV playing events can fire when decode has finished but playback hasn't. r=kinetik a=roc

This commit is contained in:
Chris Pearce 2010-11-05 13:44:33 +13:00
Родитель 45061380d8
Коммит fa6d1152be
1 изменённых файлов: 12 добавлений и 2 удалений

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

@ -371,6 +371,10 @@ private:
// True if paused. Tracks only the play/paused state. // True if paused. Tracks only the play/paused state.
PRPackedBool mPaused; PRPackedBool mPaused;
// True if playback of the audio stream has finished, and the audio stream
// has been drained. This means playback of the file has ended.
PRPackedBool mPlaybackEnded;
}; };
nsWaveStateMachine::nsWaveStateMachine(nsWaveDecoder* aDecoder, nsWaveStateMachine::nsWaveStateMachine(nsWaveDecoder* aDecoder,
@ -395,7 +399,8 @@ nsWaveStateMachine::nsWaveStateMachine(nsWaveDecoder* aDecoder,
mSeekTime(0.0f), mSeekTime(0.0f),
mMetadataValid(PR_FALSE), mMetadataValid(PR_FALSE),
mPositionChangeQueued(PR_FALSE), mPositionChangeQueued(PR_FALSE),
mPaused(mNextState == STATE_PAUSED) mPaused(mNextState == STATE_PAUSED),
mPlaybackEnded(PR_FALSE)
{ {
mMonitor = nsAutoMonitor::NewMonitor("nsWaveStateMachine"); mMonitor = nsAutoMonitor::NewMonitor("nsWaveStateMachine");
} }
@ -416,6 +421,7 @@ nsWaveStateMachine::Play()
{ {
nsAutoMonitor monitor(mMonitor); nsAutoMonitor monitor(mMonitor);
mPaused = PR_FALSE; mPaused = PR_FALSE;
mPlaybackEnded = PR_FALSE;
if (mState == STATE_ENDED) { if (mState == STATE_ENDED) {
Seek(0); Seek(0);
return; return;
@ -454,6 +460,7 @@ void
nsWaveStateMachine::Seek(float aTime) nsWaveStateMachine::Seek(float aTime)
{ {
nsAutoMonitor monitor(mMonitor); nsAutoMonitor monitor(mMonitor);
mPlaybackEnded = PR_FALSE;
mSeekTime = aTime; mSeekTime = aTime;
if (mSeekTime < 0.0f) { if (mSeekTime < 0.0f) {
mSeekTime = 0.0f; mSeekTime = 0.0f;
@ -511,7 +518,7 @@ PRBool
nsWaveStateMachine::IsEnded() nsWaveStateMachine::IsEnded()
{ {
nsAutoMonitor monitor(mMonitor); nsAutoMonitor monitor(mMonitor);
return mState == STATE_ENDED || mState == STATE_SHUTDOWN; return mPlaybackEnded;
} }
nsHTMLMediaElement::NextFrameStatus nsHTMLMediaElement::NextFrameStatus
@ -789,6 +796,8 @@ nsWaveStateMachine::Run()
CloseAudioStream(); CloseAudioStream();
} }
mPlaybackEnded = PR_TRUE;
if (mState == STATE_ENDED) { if (mState == STATE_ENDED) {
nsCOMPtr<nsIRunnable> event = nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(mDecoder, &nsWaveDecoder::PlaybackEnded); NS_NewRunnableMethod(mDecoder, &nsWaveDecoder::PlaybackEnded);
@ -818,6 +827,7 @@ nsWaveStateMachine::Run()
break; break;
case STATE_SHUTDOWN: case STATE_SHUTDOWN:
mPlaybackEnded = PR_TRUE;
CloseAudioStream(); CloseAudioStream();
return NS_OK; return NS_OK;
} }