bug 1257718 look for new events as time advances r?padenot
|bailout| is reset for each aTime, so that the appropriate events for that
time can be found.
The |eventIndex| loop is adjusted so that, when it is re-entered, it keeps
the current set of events if they are appropriate (instead of advancing
every time it is entered).
|previous| and |next| are now advanced even when passing the last event,
removing the special case when past all events.
MozReview-Commit-ID: 8ZSIzKKGQbd
--- a/dom/media/webaudio/AudioEventTimeline.cpp
+++ b/dom/media/webaudio/AudioEventTimeline.cpp
@@ -146,52 +146,59 @@ AudioEventTimeline::GetValuesAtTimeHelpe
MOZ_ASSERT(aSize);
auto TimeOf = [](const AudioTimelineEvent& aEvent) -> TimeType {
return aEvent.template Time<TimeType>();
};
size_t eventIndex = 0;
const AudioTimelineEvent* previous = nullptr;
- const AudioTimelineEvent* next = nullptr;
- bool bailOut = false;
// Let's remove old events except the last one: we need it to calculate some curves.
while (mEvents.Length() > 1 &&
aTime > TimeOf(mEvents[1])) {
mEvents.RemoveElementAt(0);
}
for (size_t bufferIndex = 0; bufferIndex < aSize; ++bufferIndex, ++aTime) {
- for (; !bailOut && eventIndex < mEvents.Length(); ++eventIndex) {
+
+ bool bailOut = false;
+ const AudioTimelineEvent* next;
+ for (; ; ++eventIndex) {
+
+ if (eventIndex >= mEvents.Length()) {
+ next = nullptr;
+ break;
+ }
+
+ next = &mEvents[eventIndex];
+ if (aTime < TimeOf(*next)) {
+ bailOut = true;
+ break;
+ }
#ifdef DEBUG
- const AudioTimelineEvent* current = &mEvents[eventIndex];
- MOZ_ASSERT(current->mType == AudioTimelineEvent::SetValueAtTime ||
- current->mType == AudioTimelineEvent::SetTarget ||
- current->mType == AudioTimelineEvent::LinearRamp ||
- current->mType == AudioTimelineEvent::ExponentialRamp ||
- current->mType == AudioTimelineEvent::SetValueCurve);
+ MOZ_ASSERT(next->mType == AudioTimelineEvent::SetValueAtTime ||
+ next->mType == AudioTimelineEvent::SetTarget ||
+ next->mType == AudioTimelineEvent::LinearRamp ||
+ next->mType == AudioTimelineEvent::ExponentialRamp ||
+ next->mType == AudioTimelineEvent::SetValueCurve);
#endif
- if (TimesEqual(aTime, TimeOf(mEvents[eventIndex]))) {
+ if (TimesEqual(aTime, TimeOf(*next))) {
mLastComputedValue = mComputedValue;
// Find the last event with the same time
while (eventIndex < mEvents.Length() - 1 &&
TimesEqual(aTime, TimeOf(mEvents[eventIndex + 1]))) {
++eventIndex;
}
break;
}
previous = next;
- next = &mEvents[eventIndex];
- if (aTime < TimeOf(mEvents[eventIndex])) {
- bailOut = true;
- }
}
if (!bailOut && eventIndex < mEvents.Length()) {
// The time matches one of the events exactly.
MOZ_ASSERT(TimesEqual(aTime, TimeOf(mEvents[eventIndex])));
// SetTarget nodes can be handled no matter what their next node is (if they have one)
if (mEvents[eventIndex].mType == AudioTimelineEvent::SetTarget) {
@@ -212,22 +219,17 @@ AudioEventTimeline::GetValuesAtTimeHelpe
continue;
}
// For other event types
aBuffer[bufferIndex] = mEvents[eventIndex].mValue;
continue;
}
- // Handle the case where the time is past all of the events
- if (!bailOut) {
- aBuffer[bufferIndex] = GetValuesAtTimeHelperInternal(aTime, next, nullptr);
- } else {
- aBuffer[bufferIndex] = GetValuesAtTimeHelperInternal(aTime, previous, next);
- }
+ aBuffer[bufferIndex] = GetValuesAtTimeHelperInternal(aTime, previous, next);
}
}
template void
AudioEventTimeline::GetValuesAtTimeHelper(double aTime, float* aBuffer,
const size_t aSize);
template void
AudioEventTimeline::GetValuesAtTimeHelper(int64_t aTime, float* aBuffer,
const size_t aSize);