Bug 1172778 - Update readyState when audio samples are popped by AudioSink. r=cpearce.

This commit is contained in:
JW Wang 2015-06-10 10:55:56 +08:00
parent 03e5fe651c
commit c2ca93a152
2 changed files with 23 additions and 30 deletions

View File

@ -272,6 +272,14 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
// timeEndPeriod() call.
timeBeginPeriod(1);
#endif
AudioQueue().AddPopListener(
NS_NewRunnableMethod(this, &MediaDecoderStateMachine::OnAudioPopped),
mTaskQueue);
VideoQueue().AddPopListener(
NS_NewRunnableMethod(this, &MediaDecoderStateMachine::OnVideoPopped),
mTaskQueue);
}
MediaDecoderStateMachine::~MediaDecoderStateMachine()
@ -581,7 +589,7 @@ void MediaDecoderStateMachine::SendStreamData()
// the decoding speed.
if (a && a->mTime <= clockTime) {
OnAudioEndTimeUpdate(std::max(mAudioEndTime, a->GetEndTime()));
nsRefPtr<AudioData> releaseMe = PopAudio();
nsRefPtr<AudioData> releaseMe = AudioQueue().PopFront();
continue;
}
break;
@ -905,22 +913,25 @@ MediaDecoderStateMachine::PushFront(VideoData* aSample)
UpdateNextFrameStatus();
}
already_AddRefed<AudioData>
MediaDecoderStateMachine::PopAudio()
void
MediaDecoderStateMachine::OnAudioPopped()
{
MOZ_ASSERT(OnTaskQueue());
nsRefPtr<AudioData> sample = AudioQueue().PopFront();
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
UpdateNextFrameStatus();
return sample.forget();
DispatchAudioDecodeTaskIfNeeded();
}
already_AddRefed<VideoData>
MediaDecoderStateMachine::PopVideo()
void
MediaDecoderStateMachine::OnVideoPopped()
{
MOZ_ASSERT(OnTaskQueue());
nsRefPtr<VideoData> sample = VideoQueue().PopFront();
ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
UpdateNextFrameStatus();
return sample.forget();
DispatchVideoDecodeTaskIfNeeded();
// Notify the decode thread that the video queue's buffers may have
// free'd up space for more frames.
mDecoder->GetReentrantMonitor().NotifyAll();
}
void
@ -2283,17 +2294,6 @@ MediaDecoderStateMachine::DecodeFirstFrame()
MOZ_ASSERT(mState == DECODER_STATE_DECODING_FIRSTFRAME);
DECODER_LOG("DecodeFirstFrame started");
if (HasAudio()) {
RefPtr<nsIRunnable> decodeTask(
NS_NewRunnableMethod(this, &MediaDecoderStateMachine::DispatchAudioDecodeTaskIfNeeded));
AudioQueue().AddPopListener(decodeTask, TaskQueue());
}
if (HasVideo()) {
RefPtr<nsIRunnable> decodeTask(
NS_NewRunnableMethod(this, &MediaDecoderStateMachine::DispatchVideoDecodeTaskIfNeeded));
VideoQueue().AddPopListener(decodeTask, TaskQueue());
}
if (IsRealTime()) {
SetStartTime(0);
nsresult res = FinishDecodeFirstFrame();
@ -2925,10 +2925,7 @@ void MediaDecoderStateMachine::AdvanceFrame()
currentFrame->mTime, clock_time, ++droppedFrames);
}
currentFrame = frame;
nsRefPtr<VideoData> releaseMe = PopVideo();
// Notify the decode thread that the video queue's buffers may have
// free'd up space for more frames.
mDecoder->GetReentrantMonitor().NotifyAll();
nsRefPtr<VideoData> releaseMe = VideoQueue().PopFront();
OnPlaybackOffsetUpdate(frame->mOffset);
if (VideoQueue().GetSize() == 0)
break;

View File

@ -420,12 +420,8 @@ protected:
void PushFront(AudioData* aSample);
void PushFront(VideoData* aSample);
// Pops MediaData* samples from their respective MediaQueues.
// Note that the audio queue is also drained on the audio thread,
// which we can't easily react to - This should be fixed when we
// remove the audio thread in bug 750596.
already_AddRefed<AudioData> PopAudio();
already_AddRefed<VideoData> PopVideo();
void OnAudioPopped();
void OnVideoPopped();
void VolumeChanged();
void LogicalPlaybackRateChanged();