Skip to content

Commit

Permalink
Added 2 new unit tests for Clip's with a Timeline associated with the…
Browse files Browse the repository at this point in the history
…m, and FFmpegReaders with a Clip/Timeline associated with them.
  • Loading branch information
jonoomph committed Oct 23, 2020
1 parent bba1260 commit e556d0f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Clip.cpp
Expand Up @@ -161,6 +161,8 @@ Clip::Clip(ReaderBase* new_reader) : resampler(NULL), reader(new_reader), alloca
if (reader) {
End(reader->info.duration);
reader->ParentClip(this);
// Init reader info struct and cache size
init_reader_settings();
}
}

Expand Down Expand Up @@ -220,7 +222,8 @@ Clip::Clip(std::string path) : resampler(NULL), reader(NULL), allocated_reader(N
reader->ParentClip(this);
allocated_reader = reader;
// Init reader info struct and cache size
init_reader_settings(); }
init_reader_settings();
}
}

// Destructor
Expand Down
5 changes: 5 additions & 0 deletions src/Timeline.cpp
Expand Up @@ -246,6 +246,11 @@ void Timeline::AddClip(Clip* clip)
// Assign timeline to clip
clip->ParentTimeline(this);

// Clear cache of clip and nested reader (if any)
clip->cache.Clear();
if (clip->Reader() && clip->Reader()->GetCache())
clip->Reader()->GetCache()->Clear();

// All clips should be converted to the frame rate of this timeline
if (auto_map_clips)
// Apply framemapper (or update existing framemapper)
Expand Down
22 changes: 22 additions & 0 deletions tests/Clip_Tests.cpp
Expand Up @@ -232,5 +232,27 @@ TEST(Effects)
CHECK_EQUAL(2, (int)c10.Effects().size());
}

TEST(Verify_Parent_Timeline)
{
Timeline t1(640, 480, Fraction(30,1), 44100, 2, LAYOUT_STEREO);

// Load clip with video
std::stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
Clip c1(path.str());
c1.Open();

// Check size of frame image
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->width(), 1280);
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->height(), 720);

// Add clip to timeline
t1.AddClip(&c1);

// Check size of frame image (with an associated timeline)
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->width(), 640);
CHECK_EQUAL(c1.GetFrame(1)->GetImage()->height(), 480);
}

} // SUITE

30 changes: 30 additions & 0 deletions tests/FFmpegReader_Tests.cpp
Expand Up @@ -241,5 +241,35 @@ TEST(Multiple_Open_and_Close)
r.Close();
}

TEST(Verify_Parent_Timeline)
{
// Create a reader
stringstream path;
path << TEST_MEDIA_PATH << "sintel_trailer-720p.mp4";
FFmpegReader r(path.str());
r.Open();

// Check size of frame image
CHECK_EQUAL(r.GetFrame(1)->GetImage()->width(), 1280);
CHECK_EQUAL(r.GetFrame(1)->GetImage()->height(), 720);
r.GetFrame(1)->GetImage()->save("reader-1.png", "PNG");

// Create a Clip associated with this reader
Clip c1(&r);
c1.Open();

// Check size of frame image (should still be the same)
CHECK_EQUAL(r.GetFrame(1)->GetImage()->width(), 1280);
CHECK_EQUAL(r.GetFrame(1)->GetImage()->height(), 720);

// Create Timeline
Timeline t1(640, 480, Fraction(30,1), 44100, 2, LAYOUT_STEREO);
t1.AddClip(&c1);

// Check size of frame image (it should now match the parent timeline)
CHECK_EQUAL(r.GetFrame(1)->GetImage()->width(), 640);
CHECK_EQUAL(r.GetFrame(1)->GetImage()->height(), 360);
}

} // SUITE(FFmpegReader)

0 comments on commit e556d0f

Please sign in to comment.