From 8227a91502a9bbea5651fc479dc5b6b4898fa56a Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Wed, 31 Mar 2021 19:35:58 -0400 Subject: [PATCH] Timeline: Add constructor accepting ReaderInfo --- examples/Example.cpp | 20 ++++++++++++-------- src/Timeline.cpp | 14 ++++++++++++++ src/Timeline.h | 25 ++++++++++++------------- tests/Timeline_Tests.cpp | 25 +++++++++++++++++++++---- 4 files changed, 59 insertions(+), 25 deletions(-) diff --git a/examples/Example.cpp b/examples/Example.cpp index a11bb5aba..52a307434 100644 --- a/examples/Example.cpp +++ b/examples/Example.cpp @@ -31,8 +31,10 @@ #include #include #include -#include "OpenShot.h" -#include "CrashHandler.h" +#include "Clip.h" +#include "Frame.h" +#include "FFmpegReader.h" +#include "Timeline.h" using namespace openshot; @@ -53,16 +55,17 @@ int main(int argc, char* argv[]) { const auto time1 = std::chrono::high_resolution_clock::now(); std::shared_ptr f = r9.GetFrame(frame); const auto time2 = std::chrono::high_resolution_clock::now(); - std::cout << "FFmpegReader: " << frame << " (" << double_ms(time2 - time1).count() << " ms)" << std::endl; + std::cout << "FFmpegReader: " << frame + << " (" << double_ms(time2 - time1).count() << " ms)\n"; } const auto total_2 = std::chrono::high_resolution_clock::now(); auto total_sec = std::chrono::duration_cast(total_2 - total_1); - std::cout << "FFmpegReader TOTAL: " << total_sec.count() << " ms" << std::endl; + std::cout << "FFmpegReader TOTAL: " << total_sec.count() << " ms\n"; r9.Close(); // Timeline Reader performance test - Timeline tm(r9.info.width, r9.info.height, r9.info.fps, r9.info.sample_rate, r9.info.channels, r9.info.channel_layout); + Timeline tm(r9.info); Clip *c = new Clip(&r9); tm.AddClip(c); tm.Open(); @@ -73,14 +76,15 @@ int main(int argc, char* argv[]) { const auto time1 = std::chrono::high_resolution_clock::now(); std::shared_ptr f = tm.GetFrame(frame); const auto time2 = std::chrono::high_resolution_clock::now(); - std::cout << "Timeline: " << frame << " (" << double_ms(time2 - time1).count() << " ms)" << std::endl; + std::cout << "Timeline: " << frame + << " (" << double_ms(time2 - time1).count() << " ms)\n"; } const auto total_4 = std::chrono::high_resolution_clock::now(); total_sec = std::chrono::duration_cast(total_4 - total_3); - std::cout << "Timeline TOTAL: " << total_sec.count() << " ms" << std::endl; + std::cout << "Timeline TOTAL: " << total_sec.count() << " ms\n"; tm.Close(); - std::cout << "Completed successfully!" << std::endl; + std::cout << "Completed successfully!\n"; return 0; } diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 0f0b06efd..e48b94c73 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -29,8 +29,17 @@ */ #include "Timeline.h" + +#include "CacheBase.h" +#include "CacheDisk.h" +#include "CacheMemory.h" +#include "CrashHandler.h" +#include "FrameMapper.h" #include "Exceptions.h" +#include +#include + using namespace openshot; // Default Constructor for the timeline (which sets the canvas width and height) @@ -78,6 +87,11 @@ Timeline::Timeline(int width, int height, Fraction fps, int sample_rate, int cha SetMaxSize(info.width, info.height); } +// Delegating constructor that copies parameters from a provided ReaderInfo +Timeline::Timeline(const ReaderInfo info) : + Timeline::Timeline(info.width, info.height, info.fps, info.sample_rate, + info.channels, info.channel_layout) {}; + // Constructor for the timeline (which loads a JSON structure from a file path, and initializes a timeline) Timeline::Timeline(const std::string& projectPath, bool convert_absolute_paths) : is_open(false), auto_map_clips(true), managed_cache(true), path(projectPath), diff --git a/src/Timeline.h b/src/Timeline.h index 8d90f5770..0e5432401 100644 --- a/src/Timeline.h +++ b/src/Timeline.h @@ -38,28 +38,23 @@ #include #include #include -#include "CacheBase.h" -#include "CacheDisk.h" -#include "CacheMemory.h" +#include "TimelineBase.h" +#include "ReaderBase.h" + #include "Color.h" #include "Clip.h" -#include "CrashHandler.h" -#include "Point.h" #include "EffectBase.h" -#include "Effects.h" -#include "EffectInfo.h" #include "Fraction.h" #include "Frame.h" -#include "FrameMapper.h" #include "KeyFrame.h" -#include "OpenMPUtilities.h" -#include "ReaderBase.h" -#include "Settings.h" -#include "TimelineBase.h" namespace openshot { + // Forward decls + class FrameMapper; + class CacheBase; + /// Comparison method for sorting clip pointers (by Layer and then Position). Clips are sorted /// from lowest layer to top layer (since that is the sequence they need to be combined), and then /// by position (left to right). @@ -222,7 +217,7 @@ namespace openshot { public: - /// @brief Default Constructor for the timeline (which configures the default frame properties) + /// @brief Constructor for the timeline (which configures the default frame properties) /// @param width The image width of generated openshot::Frame objects /// @param height The image height of generated openshot::Frame objects /// @param fps The frame rate of the generated video @@ -231,6 +226,10 @@ namespace openshot { /// @param channel_layout The channel layout (i.e. mono, stereo, 3 point surround, etc...) Timeline(int width, int height, openshot::Fraction fps, int sample_rate, int channels, openshot::ChannelLayout channel_layout); + /// @brief Constructor which takes a ReaderInfo struct to configure parameters + /// @param info The reader parameters to configure the new timeline with + Timeline(ReaderInfo info); + /// @brief Project-file constructor for the timeline /// /// Loads a JSON structure from a file path, and diff --git a/tests/Timeline_Tests.cpp b/tests/Timeline_Tests.cpp index 2a9cd632e..c35ef8b9e 100644 --- a/tests/Timeline_Tests.cpp +++ b/tests/Timeline_Tests.cpp @@ -50,7 +50,6 @@ SUITE(Timeline) TEST(Constructor) { - // Create a default fraction (should be 1/1) Fraction fps(30000,1000); Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO); @@ -58,7 +57,6 @@ TEST(Constructor) CHECK_EQUAL(640, t1.info.width); CHECK_EQUAL(480, t1.info.height); - // Create a default fraction (should be 1/1) Timeline t2(300, 240, fps, 44100, 2, LAYOUT_STEREO); // Check values @@ -66,9 +64,29 @@ TEST(Constructor) CHECK_EQUAL(240, t2.info.height); } +TEST(ReaderInfo_Constructor) +{ + // Create a reader + stringstream path; + path << TEST_MEDIA_PATH << "test.mp4"; + Clip clip_video(path.str()); + clip_video.Open(); + const auto r1 = clip_video.Reader(); + + // Configure a Timeline with the same parameters + Timeline t1(r1->info); + + CHECK_EQUAL(r1->info.width, t1.info.width); + CHECK_EQUAL(r1->info.height, t1.info.height); + CHECK_EQUAL(r1->info.fps.num, t1.info.fps.num); + CHECK_EQUAL(r1->info.fps.den, t1.info.fps.den); + CHECK_EQUAL(r1->info.sample_rate, t1.info.sample_rate); + CHECK_EQUAL(r1->info.channels, t1.info.channels); + CHECK_EQUAL(r1->info.channel_layout, t1.info.channel_layout); +} + TEST(Width_and_Height_Functions) { - // Create a default fraction (should be 1/1) Fraction fps(30000,1000); Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO); @@ -93,7 +111,6 @@ TEST(Width_and_Height_Functions) TEST(Framerate) { - // Create a default fraction (should be 1/1) Fraction fps(24,1); Timeline t1(640, 480, fps, 44100, 2, LAYOUT_STEREO);