From 77e755d109719ee103331c63755c35c0acb9ce6b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 11 Mar 2012 23:05:08 +0000 Subject: [PATCH] Allow duplicated timestamps as real files do have them; simply skip all but the last frame with the same timestamp Originally committed to SVN as r6566. --- aegisub/libaegisub/common/vfr.cpp | 5 ++--- aegisub/tests/libaegisub_vfr.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/aegisub/libaegisub/common/vfr.cpp b/aegisub/libaegisub/common/vfr.cpp index 8b10a6b8c..813367976 100644 --- a/aegisub/libaegisub/common/vfr.cpp +++ b/aegisub/libaegisub/common/vfr.cpp @@ -46,9 +46,8 @@ namespace agi { namespace vfr { static int is_increasing(int prev, int cur) { - if (prev >= cur) { - throw UnorderedTimecodes("Timecodes are out of order or too close together"); - } + if (prev > cur) + throw UnorderedTimecodes("Timecodes are out of order"); return cur; } diff --git a/aegisub/tests/libaegisub_vfr.cpp b/aegisub/tests/libaegisub_vfr.cpp index 9e6bc51c7..80ecc272f 100644 --- a/aegisub/tests/libaegisub_vfr.cpp +++ b/aegisub/tests/libaegisub_vfr.cpp @@ -420,3 +420,28 @@ TEST(lagi_vfr, no_intermediate_overflow) { EXPECT_EQ(last_frame * 1000, fps.TimeAtFrame(last_frame, EXACT)); EXPECT_EQ(last_frame, fps.FrameAtTime(last_frame * 1000, EXACT)); } + +TEST(lagi_vfr, duplicate_timestamps) { + Framerate fps; + ASSERT_NO_THROW(fps = Framerate(make_vector(6, 0, 0, 1, 2, 2, 3))); + + EXPECT_EQ(1, fps.FrameAtTime(0, EXACT)); + EXPECT_EQ(2, fps.FrameAtTime(1, EXACT)); + EXPECT_EQ(4, fps.FrameAtTime(2, EXACT)); + EXPECT_EQ(5, fps.FrameAtTime(3, EXACT)); + + EXPECT_EQ(0, fps.TimeAtFrame(0, EXACT)); + EXPECT_EQ(0, fps.TimeAtFrame(1, EXACT)); + EXPECT_EQ(1, fps.TimeAtFrame(2, EXACT)); + EXPECT_EQ(2, fps.TimeAtFrame(3, EXACT)); + EXPECT_EQ(2, fps.TimeAtFrame(4, EXACT)); + EXPECT_EQ(3, fps.TimeAtFrame(5, EXACT)); + + ASSERT_NO_THROW(fps = Framerate(make_vector(5, 0, 100, 100, 200, 300))); + + EXPECT_EQ(0, fps.FrameAtTime(0, EXACT)); + EXPECT_EQ(0, fps.FrameAtTime(99, EXACT)); + EXPECT_EQ(2, fps.FrameAtTime(100, EXACT)); + EXPECT_EQ(2, fps.FrameAtTime(199, EXACT)); + EXPECT_EQ(3, fps.FrameAtTime(200, EXACT)); +}