Bug 1163223 - Use AwaitStartTime to handle metadata end time. r=jww

This commit is contained in:
Bobby Holley 2015-06-06 14:48:07 -07:00
parent 06087fe59c
commit 7f9474887a
3 changed files with 14 additions and 8 deletions

View File

@ -1423,8 +1423,6 @@ void MediaDecoderStateMachine::RecomputeDuration()
fireDurationChanged = true;
} else if (mInfo.mMetadataDuration.isSome()) {
duration = mInfo.mMetadataDuration.ref();
} else if (mInfo.mMetadataEndTime.isSome() && mStartTime >= 0) {
duration = mInfo.mMetadataEndTime.ref() - TimeUnit::FromMicroseconds(mStartTime);
} else {
return;
}
@ -2172,6 +2170,7 @@ MediaDecoderStateMachine::OnMetadataRead(MetadataHolder* aMetadata)
mDecoder->SetMediaSeekable(mReader->IsMediaSeekable());
mInfo = aMetadata->mInfo;
mMetadataTags = aMetadata->mTags.forget();
nsRefPtr<MediaDecoderStateMachine> self = this;
// Set up the start time rendezvous if it doesn't already exist (which is
// generally the case, unless we're coming out of dormant mode).
@ -2180,8 +2179,18 @@ MediaDecoderStateMachine::OnMetadataRead(MetadataHolder* aMetadata)
mReader->ForceZeroStartTime() || IsRealTime());
}
if (mInfo.mMetadataDuration.isSome() || mInfo.mMetadataEndTime.isSome()) {
if (mInfo.mMetadataDuration.isSome()) {
RecomputeDuration();
} else if (mInfo.mUnadjustedMetadataEndTime.isSome()) {
mStartTimeRendezvous->AwaitStartTime()->Then(TaskQueue(), __func__,
[self] () -> void {
NS_ENSURE_TRUE_VOID(!self->IsShutdown());
TimeUnit unadjusted = self->mInfo.mUnadjustedMetadataEndTime.ref();
TimeUnit adjustment = TimeUnit::FromMicroseconds(self->StartTime());
self->mInfo.mMetadataDuration.emplace(unadjusted - adjustment);
self->RecomputeDuration();
}, [] () -> void { NS_WARNING("Adjusting metadata end time failed"); }
);
}
if (HasVideo()) {
@ -3177,8 +3186,6 @@ void MediaDecoderStateMachine::SetStartTime(int64_t aStartTimeUsecs)
mAudioStartTime = mStartTime;
mStreamStartTime = mStartTime;
DECODER_LOG("Set media start time to %lld", mStartTime);
RecomputeDuration();
}
void MediaDecoderStateMachine::UpdateNextFrameStatus()
@ -3370,7 +3377,6 @@ void MediaDecoderStateMachine::PreservesPitchChanged()
bool MediaDecoderStateMachine::IsShutdown()
{
AssertCurrentThreadInMonitor();
return mState == DECODER_STATE_ERROR ||
mState == DECODER_STATE_SHUTDOWN;
}

View File

@ -355,7 +355,7 @@ public:
// The Ogg reader tries to kinda-sorta compute the duration by seeking to the
// end and determining the timestamp of the last frame. This isn't useful as
// a duration until we know the start time, so we need to track it separately.
media::NullableTimeUnit mMetadataEndTime;
media::NullableTimeUnit mUnadjustedMetadataEndTime;
EncryptionInfo mCrypto;
};

View File

@ -489,7 +489,7 @@ nsresult OggReader::ReadMetadata(MediaInfo* aInfo,
endTime = RangeEndTime(length);
}
if (endTime != -1) {
mInfo.mMetadataEndTime.emplace(TimeUnit::FromMicroseconds(endTime));
mInfo.mUnadjustedMetadataEndTime.emplace(TimeUnit::FromMicroseconds(endTime));
LOG(LogLevel::Debug, ("Got Ogg duration from seeking to end %lld", endTime));
}
}