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.
This commit is contained in:
Thomas Goyne 2012-03-11 23:05:08 +00:00
parent ebe32890fb
commit 77e755d109
2 changed files with 27 additions and 3 deletions

View File

@ -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;
}

View File

@ -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<int>(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<int>(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));
}