commit a8c2ffa3f7c13ce6533bc06c5bbe7ecb0bc7f90f
parent 1a970ccb483397c434bd9f2a3d566d72b2444c82
Author: Andreas Pehrson <apehrson@mozilla.com>
Date: Tue, 11 Nov 2025 08:21:04 +0000
Bug 1931328 - Test the interpolated GetPosition in DecodedStream. r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D238753
Diffstat:
1 file changed, 41 insertions(+), 0 deletions(-)
diff --git a/dom/media/gtest/TestDecodedStream.cpp b/dom/media/gtest/TestDecodedStream.cpp
@@ -237,4 +237,45 @@ TEST_F(TestDecodedStreamA, LastOutputSystemTime) {
mDecodedStream->Stop();
}
+
+TEST_F(TestDecodedStreamA, InterpolatedPosition) {
+ BlankAudioDataCreator creator(2, kRate);
+ auto raw = MakeRefPtr<MediaRawData>();
+ raw->mDuration = TimeUnit(kRate, kRate);
+ mAudioQueue.Push(RefPtr(creator.Create(raw))->As<AudioData>());
+
+ mDecodedStream->Start(TimeUnit::Zero(), CreateMediaInfo());
+ mDecodedStream->SetPlaying(true);
+ NS_ProcessPendingEvents(nullptr);
+ mMockCubebStream->ManualDataCallback(0);
+
+ auto now = TimeStamp::Now();
+ auto awakeNow = AwakeTimeStamp::Now();
+ TimeStamp outNow;
+ TimeUnit pos = mDecodedStream->GetPositionImpl(now, awakeNow, &outNow);
+ EXPECT_EQ(now, outNow);
+ EXPECT_EQ(pos, TimeUnit::Zero()) << pos.ToMilliseconds();
+
+ mMockCubebStream->ManualDataCallback(512);
+ NS_ProcessPendingEvents(nullptr);
+
+ now += TimeDuration::FromSeconds(
+ (mDecodedStream->LastOutputSystemTime() - awakeNow).ToSeconds());
+ awakeNow = mDecodedStream->LastOutputSystemTime();
+ pos = mDecodedStream->GetPositionImpl(now, awakeNow);
+ EXPECT_EQ(pos.ToMicroseconds(), TimeUnit(512, kRate).ToMicroseconds());
+
+ // Check that the position is interpolated based on wall clock time since last
+ // output notification.
+ now += TimeDuration::FromSeconds(
+ (mDecodedStream->LastOutputSystemTime() - awakeNow).ToSeconds()) +
+ TimeDuration::FromMilliseconds(10);
+ awakeNow = mDecodedStream->LastOutputSystemTime() +
+ AwakeTimeDuration::FromMilliseconds(10);
+ pos = mDecodedStream->GetPositionImpl(now, awakeNow);
+ EXPECT_EQ(pos.ToMicroseconds(),
+ (TimeUnit(512, kRate) + TimeUnit(10, 1000)).ToMicroseconds());
+
+ mDecodedStream->Stop();
+}
} // namespace mozilla