Bug 1350837. P1 - add AMPLE_AUDIO_THRESHOLD and use it to replace AMPLE_AUDIO_USECS.
Note we can't simply change the type of AMPLE_AUDIO_USECS to TimeUnit because it is
used in a static_assert and TimeUnit::ToMicroseconds() is not a const expression.
There is no easy way to change it because CheckedInt::value() calls MOZ_ASSERT which
can't be a const expression.
MozReview-Commit-ID: 17qaTFOOLpL
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -95,16 +95,18 @@ namespace detail {
static constexpr auto LOW_AUDIO_THRESHOLD = TimeUnit::FromMicroseconds(300000);
// If more than this many usecs of decoded audio is queued, we'll hold off
// decoding more audio. If we increase the low audio threshold (see
// LOW_AUDIO_THRESHOLD above) we'll also increase this value to ensure it's not
// less than the low audio threshold.
static const int64_t AMPLE_AUDIO_USECS = 2000000;
+static constexpr auto AMPLE_AUDIO_THRESHOLD = TimeUnit::FromMicroseconds(AMPLE_AUDIO_USECS);
+
} // namespace detail
// If we have fewer than LOW_VIDEO_FRAMES decoded frames, and
// we're not "prerolling video", we'll skip the video up to the next keyframe
// which is at or after the current playback position.
static const uint32_t LOW_VIDEO_FRAMES = 2;
// Threshold in usecs that used to check if we are low on decoded video.
@@ -2590,17 +2592,17 @@ MediaDecoderStateMachine::MediaDecoderSt
mCurrentFrameID(0),
INIT_WATCHABLE(mObservedDuration, TimeUnit()),
mFragmentEndTime(-1),
mReader(new MediaDecoderReaderWrapper(mTaskQueue, aReader)),
mDecodedAudioEndTime(0),
mDecodedVideoEndTime(0),
mPlaybackRate(1.0),
mLowAudioThreshold(detail::LOW_AUDIO_THRESHOLD),
- mAmpleAudioThresholdUsecs(detail::AMPLE_AUDIO_USECS),
+ mAmpleAudioThresholdUsecs(detail::AMPLE_AUDIO_THRESHOLD.ToMicroseconds()),
mAudioCaptured(false),
mMinimizePreroll(aDecoder->GetMinimizePreroll()),
mSentLoadedMetadataEvent(false),
mSentFirstFrameLoadedEvent(false),
mVideoDecodeSuspended(false),
mVideoDecodeSuspendTimer(mTaskQueue),
mOutputStreamManager(new OutputStreamManager()),
mResource(aDecoder->GetResource()),
@@ -3783,17 +3785,17 @@ MediaDecoderStateMachine::SetAudioCaptur
// Restore playback parameters.
mMediaSink->SetPlaybackParams(params);
mAudioCaptured = aCaptured;
// Don't buffer as much when audio is captured because we don't need to worry
// about high latency audio devices.
mAmpleAudioThresholdUsecs =
- mAudioCaptured ? detail::AMPLE_AUDIO_USECS / 2 : detail::AMPLE_AUDIO_USECS;
+ (mAudioCaptured ? detail::AMPLE_AUDIO_THRESHOLD / 2 : detail::AMPLE_AUDIO_THRESHOLD).ToMicroseconds();
mStateObj->HandleAudioCaptured();
}
uint32_t MediaDecoderStateMachine::GetAmpleVideoFrames() const
{
MOZ_ASSERT(OnTaskQueue());
return (mReader->IsAsync() && mReader->VideoIsHardwareAccelerated())